2021-04-25 12:05:17 +02:00
|
|
|
import { ChangeDetectorRef, Component, Inject, Input } from '@angular/core';
|
2021-02-04 16:14:07 +01:00
|
|
|
import { ToastService } from '../../../../core/services/toast.service';
|
2021-02-05 17:02:52 +01:00
|
|
|
import { FormBuilder, FormGroup } from '@angular/forms';
|
2021-02-04 16:14:07 +01:00
|
|
|
import { UuidService } from '../../../../core/services/uuid.service';
|
|
|
|
import { PollService } from '../../../../core/services/poll.service';
|
|
|
|
import { ApiService } from '../../../../core/services/api.service';
|
|
|
|
import { Router } from '@angular/router';
|
|
|
|
import { DOCUMENT } from '@angular/common';
|
|
|
|
import { Poll } from '../../../../core/models/poll.model';
|
2021-04-25 12:05:17 +02:00
|
|
|
import { environment } from '../../../../../environments/environment';
|
2021-04-30 10:59:46 +02:00
|
|
|
import { PollUtilitiesService } from '../../../../core/services/poll.utilities.service';
|
2021-02-04 16:14:07 +01:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-base-config',
|
|
|
|
templateUrl: './base-config.component.html',
|
|
|
|
styleUrls: ['./base-config.component.scss'],
|
|
|
|
})
|
2021-02-05 17:02:52 +01:00
|
|
|
export class BaseConfigComponent {
|
2021-02-04 16:14:07 +01:00
|
|
|
@Input()
|
|
|
|
public poll?: Poll;
|
2021-02-04 19:04:20 +01:00
|
|
|
@Input()
|
2021-02-04 16:14:07 +01:00
|
|
|
public form: FormGroup;
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
private fb: FormBuilder,
|
|
|
|
private cd: ChangeDetectorRef,
|
|
|
|
private uuidService: UuidService,
|
|
|
|
private toastService: ToastService,
|
|
|
|
private pollService: PollService,
|
2021-04-30 10:59:46 +02:00
|
|
|
private utilitiesService: PollUtilitiesService,
|
2021-02-04 16:14:07 +01:00
|
|
|
private apiService: ApiService,
|
|
|
|
private router: Router,
|
|
|
|
@Inject(DOCUMENT) private document: Document
|
|
|
|
) {}
|
|
|
|
|
|
|
|
askInitFormDefault(): void {
|
2021-04-30 11:27:54 +02:00
|
|
|
this.toastService.display('formulaire réinitialisé', 'info');
|
2021-02-04 16:14:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public updateSlug(): void {
|
2021-04-30 10:59:46 +02:00
|
|
|
const newValueFormatted = this.pollService.makecustom_url(this.poll);
|
2021-04-30 11:27:54 +02:00
|
|
|
this.form.patchValue({ custom_url: newValueFormatted });
|
2021-02-04 16:14:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-04-30 10:59:46 +02:00
|
|
|
* set the poll custom_url from other data of the poll
|
2021-02-04 16:14:07 +01:00
|
|
|
*/
|
2021-04-30 11:27:54 +02:00
|
|
|
automaticSlug(): void {
|
|
|
|
this.form.patchValue({ custom_url: this.utilitiesService.makeUuid() });
|
2021-02-05 15:34:00 +01:00
|
|
|
}
|
2021-02-04 16:14:07 +01:00
|
|
|
}
|