2021-11-22 15:30:23 +01:00
|
|
|
import { Component, Inject, Input, OnInit } from '@angular/core';
|
2021-11-07 14:52:49 +01:00
|
|
|
import { PollService } from '../../../../../core/services/poll.service';
|
2021-11-12 12:50:21 +01:00
|
|
|
import { environment } from '../../../../../../environments/environment';
|
2021-11-12 15:59:44 +01:00
|
|
|
import { Router } from '@angular/router';
|
2021-11-22 15:30:23 +01:00
|
|
|
import { DateUtilitiesService } from '../../../../../core/services/date.utilities.service';
|
|
|
|
import { DOCUMENT } from '@angular/common';
|
|
|
|
import { StorageService } from '../../../../../core/services/storage.service';
|
|
|
|
import { DateChoice, TimeSlices, timeSlicesProposals } from '../../../../../core/models/dateChoice.model';
|
|
|
|
import { ToastService } from '../../../../../core/services/toast.service';
|
2021-11-07 14:52:49 +01:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-step-four',
|
|
|
|
templateUrl: './step-four.component.html',
|
|
|
|
styleUrls: ['./step-four.component.scss'],
|
|
|
|
})
|
|
|
|
export class StepFourComponent implements OnInit {
|
|
|
|
urlPrefix: any;
|
2021-11-12 12:50:21 +01:00
|
|
|
advancedDisplayEnabled: boolean = environment.advanced_options_display;
|
2021-11-07 14:52:49 +01:00
|
|
|
@Input()
|
|
|
|
step_max: any;
|
|
|
|
@Input()
|
|
|
|
form: any;
|
2021-11-22 15:30:23 +01:00
|
|
|
showSameTimeSlices: boolean = false;
|
|
|
|
timeSlicesProposals: TimeSlices[] = timeSlicesProposals;
|
2021-11-16 16:16:30 +01:00
|
|
|
|
2021-11-22 15:30:23 +01:00
|
|
|
constructor(
|
|
|
|
private dateUtilitiesService: DateUtilitiesService,
|
|
|
|
private router: Router,
|
|
|
|
private toastService: ToastService,
|
|
|
|
@Inject(DOCUMENT) private document: any,
|
|
|
|
private storageService: StorageService,
|
|
|
|
public pollService: PollService
|
|
|
|
) {
|
2021-11-16 16:16:30 +01:00
|
|
|
this.pollService.step_current = 4;
|
|
|
|
}
|
2021-11-07 14:52:49 +01:00
|
|
|
|
|
|
|
ngOnInit(): void {}
|
2021-11-22 15:30:23 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* toggle hasSeveralHours to show an other form section
|
|
|
|
* so that the user can choose between time slices applying equally to all days in her form,
|
|
|
|
* or have the ability to define different times lices for each day
|
|
|
|
*/
|
|
|
|
toggleHasSeveralHours() {
|
|
|
|
this.pollService.form.patchValue({
|
|
|
|
hasSeveralHours: !this.pollService.form.value.hasSeveralHours,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
addChoiceForDay(dayChoice: DateChoice): void {
|
|
|
|
let lastDateChoice = this.pollService.dateChoiceList[this.pollService.dateChoiceList.length];
|
|
|
|
console.log('lastDateChoice', lastDateChoice);
|
|
|
|
let lastDateChoiceObject = this.dateUtilitiesService.addDaysToDate(
|
|
|
|
this.pollService.dateChoiceList.length,
|
|
|
|
new Date()
|
|
|
|
);
|
|
|
|
|
|
|
|
if (lastDateChoice && lastDateChoice.date_object) {
|
|
|
|
lastDateChoiceObject = lastDateChoice.date_object;
|
|
|
|
} else {
|
|
|
|
lastDateChoiceObject = new Date();
|
|
|
|
}
|
|
|
|
dayChoice.timeSlices.push({
|
|
|
|
literal: '',
|
|
|
|
});
|
|
|
|
dayChoice.timeSlices.sort((a: any, b: any) => {
|
|
|
|
return a.date_object - b.date_object;
|
|
|
|
});
|
|
|
|
this.focusOnChoice(this.storageService.dateChoices.length - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
focusOnChoice(index): void {
|
|
|
|
const selector = '#choice_label_' + index;
|
|
|
|
const elem = this.document.querySelector(selector);
|
|
|
|
if (elem) {
|
|
|
|
elem.focus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
addPreselect(literal: string) {
|
|
|
|
if (
|
|
|
|
!this.pollService.timeList.find((elem) => {
|
|
|
|
return elem.literal === literal;
|
|
|
|
})
|
|
|
|
) {
|
|
|
|
this.pollService.timeList.push({ literal });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
applyTimeSlicesToDateChoices() {
|
|
|
|
let timeSlicesToApply = this.pollService.timeList;
|
|
|
|
this.pollService.dateChoiceList.forEach((elem) => {
|
|
|
|
return (elem.timeSlices = timeSlicesToApply);
|
|
|
|
});
|
|
|
|
this.toastService.display(`time slices appliquées avec succès`);
|
|
|
|
}
|
2021-11-07 14:52:49 +01:00
|
|
|
}
|