|
|
|
@ -7,6 +7,7 @@ import { ToastService } from '../../../core/services/toast.service';
|
|
|
|
|
import { PollService } from '../../../core/services/poll.service';
|
|
|
|
|
import { DateUtilities } from '../../old-stuff/config/DateUtilities';
|
|
|
|
|
import { DOCUMENT } from '@angular/common';
|
|
|
|
|
import { DateChoice, otherDefaultDates } from '../../old-stuff/config/defaultConfigs';
|
|
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'app-admin-form',
|
|
|
|
@ -21,11 +22,13 @@ export class FormComponent implements OnInit {
|
|
|
|
|
public urlPrefix: string = window.location.origin + '/participation/';
|
|
|
|
|
public advancedDisplayEnabled = false;
|
|
|
|
|
public showDateInterval = true;
|
|
|
|
|
startDateInterval: any;
|
|
|
|
|
public allowSeveralHours = true;
|
|
|
|
|
startDateInterval: string;
|
|
|
|
|
endDateInterval: string;
|
|
|
|
|
intervalDays: any;
|
|
|
|
|
intervalDaysDefault = 7;
|
|
|
|
|
endDateInterval: any;
|
|
|
|
|
dateList: any[];
|
|
|
|
|
dateList: any = otherDefaultDates; // sets of days as strings, config to set identical time for days in a special days poll
|
|
|
|
|
timeList: DateChoice[] = otherDefaultDates; // ranges of time expressed as strings
|
|
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
|
private fb: FormBuilder,
|
|
|
|
@ -43,6 +46,7 @@ export class FormComponent implements OnInit {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public createPoll(): void {
|
|
|
|
|
console.log('this.form', this.form);
|
|
|
|
|
if (this.form.valid && this.form.valid) {
|
|
|
|
|
console.log('Le sondage est correctement rempli, prêt à enregistrer.');
|
|
|
|
|
const newpoll = this.pollService.newPollFromForm(this.form);
|
|
|
|
@ -74,7 +78,12 @@ export class FormComponent implements OnInit {
|
|
|
|
|
this.choices.push(newControlGroup);
|
|
|
|
|
this.cd.detectChanges();
|
|
|
|
|
console.log('this.choices.length', this.choices.length);
|
|
|
|
|
const selector = '#choice_label_' + (this.choices.length - 1);
|
|
|
|
|
|
|
|
|
|
this.focusOnChoice(this.choices.length - 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
focusOnChoice(index) {
|
|
|
|
|
const selector = '#choice_label_' + index;
|
|
|
|
|
const elem = this.document.querySelector(selector);
|
|
|
|
|
if (elem) {
|
|
|
|
|
elem.focus();
|
|
|
|
@ -99,6 +108,8 @@ export class FormComponent implements OnInit {
|
|
|
|
|
slug: [this.uuidService.getUUID(), [Validators.required]],
|
|
|
|
|
description: ['', [Validators.required]],
|
|
|
|
|
choices: new FormArray([]),
|
|
|
|
|
whoModifiesAnswers: ['', [Validators.required]],
|
|
|
|
|
whoCanChangeAnswers: ['', [Validators.required]],
|
|
|
|
|
isAboutDate: [true, [Validators.required]],
|
|
|
|
|
startDateInterval: ['', [Validators.required]],
|
|
|
|
|
endDateInterval: ['', [Validators.required]],
|
|
|
|
@ -132,6 +143,7 @@ export class FormComponent implements OnInit {
|
|
|
|
|
startDateInterval: this.startDateInterval,
|
|
|
|
|
endDateInterval: this.endDateInterval,
|
|
|
|
|
});
|
|
|
|
|
this.countDays();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -148,8 +160,9 @@ export class FormComponent implements OnInit {
|
|
|
|
|
slug: this.uuidService.getUUID(),
|
|
|
|
|
creatorPseudo: 'Chuck Norris',
|
|
|
|
|
creatorEmail: '',
|
|
|
|
|
choices: ['matin', 'midi'],
|
|
|
|
|
isAboutDate: true,
|
|
|
|
|
whoModifiesAnswers: 'everybody',
|
|
|
|
|
whoCanChangeAnswers: 'everybody',
|
|
|
|
|
isProtectedByPassword: false,
|
|
|
|
|
isOwnerNotifiedByEmailOnNewVote: false,
|
|
|
|
|
isOwnerNotifiedByEmailOnNewComment: false,
|
|
|
|
@ -165,14 +178,23 @@ export class FormComponent implements OnInit {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
countDays(): void {
|
|
|
|
|
this.intervalDays = this.dateUtilities.countDays(this.startDateInterval, this.endDateInterval);
|
|
|
|
|
this.intervalDays = this.dateUtilities.countDays(
|
|
|
|
|
this.dateUtilities.parseInputDateToDateObject(this.startDateInterval),
|
|
|
|
|
this.dateUtilities.parseInputDateToDateObject(this.endDateInterval)
|
|
|
|
|
);
|
|
|
|
|
this.toastService.display('intervalle de ' + this.intervalDays + ' jours');
|
|
|
|
|
this.cd.detectChanges();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* add all the dates between the start and end dates in the interval section
|
|
|
|
|
*/
|
|
|
|
|
addIntervalOfDates(): void {
|
|
|
|
|
const newIntervalArray = this.dateUtilities.getDatesInRange(this.startDateInterval, this.endDateInterval, 1);
|
|
|
|
|
const newIntervalArray = this.dateUtilities.getDatesInRange(
|
|
|
|
|
this.dateUtilities.parseInputDateToDateObject(this.startDateInterval),
|
|
|
|
|
this.dateUtilities.parseInputDateToDateObject(this.endDateInterval),
|
|
|
|
|
1
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const converted = [];
|
|
|
|
|
newIntervalArray.forEach((element) => {
|
|
|
|
@ -187,12 +209,23 @@ export class FormComponent implements OnInit {
|
|
|
|
|
console.log('this.dateList', this.dateList);
|
|
|
|
|
this.showDateInterval = false;
|
|
|
|
|
|
|
|
|
|
this.form.patchValue({ choices: this.dateList });
|
|
|
|
|
// this.dateList.forEach(elem=>{
|
|
|
|
|
// const newControlGroup = this.fb.group({
|
|
|
|
|
// label: this.fb.control('', [Validators.required]),
|
|
|
|
|
// imageUrl: ['', [Validators.required]],
|
|
|
|
|
// });
|
|
|
|
|
//
|
|
|
|
|
// this.choices.push(newControlGroup);
|
|
|
|
|
// })
|
|
|
|
|
|
|
|
|
|
this.toastService.display(`les dates ont été ajoutées aux réponses possibles.`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* handle keyboard shortcuts
|
|
|
|
|
* @param $event
|
|
|
|
|
* @param choice_number
|
|
|
|
|
*/
|
|
|
|
|
keyOnChoice($event: KeyboardEvent, choice_number: number): void {
|
|
|
|
|
$event.preventDefault();
|
|
|
|
@ -207,11 +240,7 @@ export class FormComponent implements OnInit {
|
|
|
|
|
console.log('$event', $event);
|
|
|
|
|
|
|
|
|
|
if ($event.key == 'ArrowUp' && choice_number > 0) {
|
|
|
|
|
const selector = '#choice_label_' + (choice_number - 1);
|
|
|
|
|
const elem = this.document.querySelector(selector);
|
|
|
|
|
if (elem) {
|
|
|
|
|
elem.focus();
|
|
|
|
|
}
|
|
|
|
|
this.focusOnChoice(choice_number - 1);
|
|
|
|
|
}
|
|
|
|
|
if ($event.key == 'ArrowDown') {
|
|
|
|
|
// add a field if we are on the last choice
|
|
|
|
@ -219,22 +248,14 @@ export class FormComponent implements OnInit {
|
|
|
|
|
this.addChoice();
|
|
|
|
|
this.toastService.display('choix ajouté par raccourci "flèche bas"');
|
|
|
|
|
} else {
|
|
|
|
|
const selector = '#choice_label_' + (choice_number + 1);
|
|
|
|
|
const elem = this.document.querySelector(selector);
|
|
|
|
|
if (elem) {
|
|
|
|
|
elem.focus();
|
|
|
|
|
}
|
|
|
|
|
this.focusOnChoice(choice_number + 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ($event.ctrlKey && $event.key == 'Backspace') {
|
|
|
|
|
this.deleteChoiceField(choice_number);
|
|
|
|
|
this.toastService.display('choix supprimé par raccourci "Ctrl + retour"');
|
|
|
|
|
this.cd.detectChanges();
|
|
|
|
|
const selector = '#choice_label_' + Math.min(choice_number - 1, 0);
|
|
|
|
|
const elem = this.document.querySelector(selector);
|
|
|
|
|
if (elem) {
|
|
|
|
|
elem.focus();
|
|
|
|
|
}
|
|
|
|
|
this.focusOnChoice(Math.min(choice_number - 1, 0));
|
|
|
|
|
}
|
|
|
|
|
if ($event.ctrlKey && $event.key == 'Enter') {
|
|
|
|
|
// go to other fields
|
|
|
|
@ -244,4 +265,39 @@ export class FormComponent implements OnInit {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* change time spans
|
|
|
|
|
*/
|
|
|
|
|
addTime() {
|
|
|
|
|
this.timeList.push({
|
|
|
|
|
literal: '',
|
|
|
|
|
timeList: [],
|
|
|
|
|
date_object: new Date(),
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
removeAllTimes() {
|
|
|
|
|
this.timeList = [];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resetTimes() {
|
|
|
|
|
this.timeList = otherDefaultDates;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* add a time period to a specific date choice,
|
|
|
|
|
* focus on the new input
|
|
|
|
|
* @param config
|
|
|
|
|
* @param id
|
|
|
|
|
*/
|
|
|
|
|
addTimeToDate(config: any, id: number) {
|
|
|
|
|
this.timeList.push({ literal: '' });
|
|
|
|
|
const selector = '[ng-reflect-choice_label="dateTime_' + id + '_Choices_' + (this.timeList.length - 1) + '"]';
|
|
|
|
|
this.cd.detectChanges();
|
|
|
|
|
const elem = this.document.querySelector(selector);
|
|
|
|
|
if (elem) {
|
|
|
|
|
elem.focus();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|