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: string = window.location.origin + '/participation/'; constructor(private fb: FormBuilder, private uuidService: UuidService) {} ngOnInit(): void { this.pollFormGroup = this.fb.group({ question: [this.poll ? this.poll.question : '', [Validators.required]], slug: [this.poll ? this.poll.slug : this.uuidService.getUUID(), [Validators.required]], description: [this.poll ? this.poll.description : ''], }); this.configurationFormGroup = this.fb.group({ isAboutDate: [this.poll ? this.poll.configuration.isAboutDate : false, [Validators.required]], isProtectedByPassword: [ this.poll ? this.poll.configuration.isProtectedByPassword : false, [Validators.required], ], isOwnerNotifiedByEmailOnNewVote: [ this.poll ? this.poll.configuration.isOwnerNotifiedByEmailOnNewVote : false, [Validators.required], ], isOwnerNotifiedByEmailOnNewComment: [ this.poll ? this.poll.configuration.isOwnerNotifiedByEmailOnNewComment : false, [Validators.required], ], isMaybeAnswerAvailable: [ this.poll ? this.poll.configuration.isMaybeAnswerAvailable : false, [Validators.required], ], areResultsPublic: [this.poll ? this.poll.configuration.areResultsPublic : true, [Validators.required]], expiracyNumberOfDays: [ this.poll ? DateService.diffInDays(new Date(), this.poll.configuration.expires) : 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 } } }