import { Component, Input, OnInit } from '@angular/core'; import { FormBuilder, FormGroup, Validators } from '@angular/forms'; import { Poll } from '../../../core/models/poll.model'; import { UuidService } from '../../../core/services/uuid.service'; import { DateService } from '../../../core/services/date.service'; @Component({ selector: 'app-stepper', templateUrl: './stepper.component.html', styleUrls: ['./stepper.component.scss'], }) export class StepperComponent implements OnInit { @Input() public poll?: Poll; public pollFormGroup: FormGroup; public configurationFormGroup: FormGroup; public choicesFormGroup: FormGroup; public urlPrefix = '/participation/'; constructor(private fb: FormBuilder, private uuidService: UuidService) {} ngOnInit(): void { this.pollFormGroup = this.fb.group({ question: [this.poll ? this.poll.title : '', [Validators.required]], slug: [this.poll ? this.poll.custom_url : this.uuidService.getUUID(), [Validators.required]], description: [this.poll ? this.poll.description : ''], }); this.configurationFormGroup = this.fb.group({ title: [this.poll ? this.poll : false, [Validators.required]], isAboutDate: [this.poll ? this.poll.kind === 'date' : false, [Validators.required]], isProtectedByPassword: [this.poll ? this.poll.password.length : false, [Validators.required]], isOwnerNotifiedByEmailOnNewVote: [ this.poll ? this.poll.isOwnerNotifiedByEmailOnNewVote : false, [Validators.required], ], isOwnerNotifiedByEmailOnNewComment: [ this.poll ? this.poll.isOwnerNotifiedByEmailOnNewComment : false, [Validators.required], ], areResultsPublic: [this.poll ? this.poll.areResultsPublic : true, [Validators.required]], expiracyNumberOfDays: [this.poll ? this.poll.default_expiracy_days_from_now : '60', [Validators.required]], }); } public savePoll(): void { if (this.pollFormGroup.valid && this.configurationFormGroup.valid) { console.log('Le sondage est correctement rempli, prêt à enregistrer.'); // TODO : save the poll } } }