2020-06-16 18:40:48 +02:00
|
|
|
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';
|
2020-05-01 19:10:17 +02:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-stepper',
|
|
|
|
templateUrl: './stepper.component.html',
|
|
|
|
styleUrls: ['./stepper.component.scss'],
|
|
|
|
})
|
|
|
|
export class StepperComponent implements OnInit {
|
2020-06-16 18:40:48 +02:00
|
|
|
@Input()
|
|
|
|
public poll?: Poll;
|
|
|
|
|
|
|
|
public pollFormGroup: FormGroup;
|
|
|
|
public configurationFormGroup: FormGroup;
|
|
|
|
public choicesFormGroup: FormGroup;
|
|
|
|
|
2021-04-30 22:49:55 +02:00
|
|
|
public urlPrefix = '/participation/';
|
2020-06-16 18:40:48 +02:00
|
|
|
|
|
|
|
constructor(private fb: FormBuilder, private uuidService: UuidService) {}
|
2020-05-01 19:10:17 +02:00
|
|
|
|
|
|
|
ngOnInit(): void {
|
2020-06-16 18:40:48 +02:00
|
|
|
this.pollFormGroup = this.fb.group({
|
2020-10-29 18:43:19 +01:00
|
|
|
question: [this.poll ? this.poll.title : '', [Validators.required]],
|
2021-04-30 11:27:54 +02:00
|
|
|
slug: [this.poll ? this.poll.custom_url : this.uuidService.getUUID(), [Validators.required]],
|
2020-06-16 18:40:48 +02:00
|
|
|
description: [this.poll ? this.poll.description : ''],
|
|
|
|
});
|
|
|
|
|
|
|
|
this.configurationFormGroup = this.fb.group({
|
2020-10-29 18:43:19 +01:00
|
|
|
title: [this.poll ? this.poll.configuration : false, [Validators.required]],
|
2020-06-16 18:40:48 +02:00
|
|
|
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: [
|
2021-02-05 23:03:49 +01:00
|
|
|
this.poll ? DateService.diffInDays(new Date(), this.poll.configuration.expiracyDate) : 60,
|
2020-06-16 18:40:48 +02:00
|
|
|
[Validators.required],
|
|
|
|
],
|
|
|
|
});
|
|
|
|
}
|
2020-05-01 19:10:17 +02:00
|
|
|
|
2020-06-16 18:40:48 +02:00
|
|
|
public savePoll(): void {
|
|
|
|
if (this.pollFormGroup.valid && this.configurationFormGroup.valid) {
|
|
|
|
console.log('Le sondage est correctement rempli, prêt à enregistrer.');
|
|
|
|
// TODO : save the poll
|
|
|
|
}
|
2020-05-01 19:10:17 +02:00
|
|
|
}
|
|
|
|
}
|