funky-framadate-front/src/app/features/administration/form/date-select/date-select.component.ts

81 lines
2.6 KiB
TypeScript
Raw Normal View History

2021-02-04 16:14:07 +01:00
import { ChangeDetectorRef, Component, Inject, Input, OnInit } from '@angular/core';
import { FormArray, UntypedFormBuilder, UntypedFormGroup, Validators } from '@angular/forms';
2021-02-04 16:14:07 +01:00
import { UuidService } from '../../../../core/services/uuid.service';
import { ToastService } from '../../../../core/services/toast.service';
import { PollService } from '../../../../core/services/poll.service';
2021-04-29 10:45:22 +02:00
import { DateUtilitiesService } from '../../../../core/services/date.utilities.service';
2021-02-04 16:14:07 +01:00
import { ApiService } from '../../../../core/services/api.service';
import { Router } from '@angular/router';
import { DOCUMENT } from '@angular/common';
import { DateChoice, defaultTimeOfDay, TimeSlices } from '../../../../../../mocks/old-stuff/config/defaultConfigs';
import { TranslateService } from '@ngx-translate/core';
2021-04-30 12:37:04 +02:00
import { StorageService } from '../../../../core/services/storage.service';
import { environment } from '../../../../../environments/environment';
2021-02-04 16:14:07 +01:00
@Component({
selector: 'app-date-select',
templateUrl: './date-select.component.html',
styleUrls: ['./date-select.component.scss'],
})
export class DateSelectComponent implements OnInit {
@Input()
form: UntypedFormGroup;
2021-02-04 16:14:07 +01:00
displaySeveralHoursChoice = true;
allowSeveralHours = true;
today = new Date();
2021-02-04 16:14:07 +01:00
endDateInterval: string;
2021-05-17 15:25:22 +02:00
intervalDaysDefault = environment.interval_days_default;
dateChoices: DateChoice[] = []; // sets of dateChoices as strings, config to set identical time for dateChoices in a special dateChoices poll
2021-05-18 12:12:08 +02:00
timeSlices: TimeSlices[] = []; // ranges of time expressed as strings
2021-05-17 15:25:22 +02:00
2021-02-09 12:10:10 +01:00
selectionKind = 'range';
2021-05-20 13:34:14 +02:00
display: any;
2021-02-04 16:14:07 +01:00
constructor(
private fb: UntypedFormBuilder,
2021-02-04 16:14:07 +01:00
private cd: ChangeDetectorRef,
private uuidService: UuidService,
private toastService: ToastService,
private pollService: PollService,
private apiService: ApiService,
2021-04-30 12:37:04 +02:00
private storageService: StorageService,
2021-02-04 16:14:07 +01:00
private router: Router,
private translateService: TranslateService,
2021-02-04 16:14:07 +01:00
@Inject(DOCUMENT) private document: any
2021-04-30 12:37:04 +02:00
) {
this.dateChoices = this.storageService.dateChoices;
2021-05-18 12:12:08 +02:00
this.timeSlices = this.storageService.timeSlices;
2021-04-30 12:37:04 +02:00
}
2021-02-04 16:14:07 +01:00
2021-05-17 15:25:22 +02:00
ngOnInit(): void {}
2021-02-04 16:14:07 +01:00
/**
* change time spans
*/
addTime() {
2021-05-18 12:12:08 +02:00
this.timeSlices.push({
2021-02-04 16:14:07 +01:00
literal: '',
});
}
removeAllTimes() {
2021-05-18 12:12:08 +02:00
this.timeSlices = [];
this.dateChoices.map((elem) => (elem.timeSlices = []));
2021-05-17 15:25:22 +02:00
2021-05-03 15:47:27 +02:00
this.toastService.display('périodes horaires vidées');
2021-02-04 16:14:07 +01:00
}
resetTimes(slices = Object.create(defaultTimeOfDay)) {
2021-05-18 12:12:08 +02:00
this.timeSlices = slices;
this.dateChoices.map((elem) => (elem.timeSlices = Object.create(slices)));
2021-05-03 15:47:27 +02:00
this.toastService.display('périodes horaires réinitialisées');
2021-02-04 16:14:07 +01:00
}
2021-05-20 13:34:14 +02:00
openSimple() {
this.display = !this.display;
}
2021-02-04 16:14:07 +01:00
}