funky-framadate-front/src/app/features/administration/form/base-config/base-config.component.ts

77 lines
2.3 KiB
TypeScript
Raw Normal View History

2021-02-05 15:34:00 +01:00
import { ChangeDetectorRef, Component, EventEmitter, Inject, Input, OnInit, Output } from '@angular/core';
2021-02-04 16:14:07 +01:00
import { ToastService } from '../../../../core/services/toast.service';
import { FormArray, FormBuilder, FormGroup, Validators } from '@angular/forms';
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';
@Component({
selector: 'app-base-config',
templateUrl: './base-config.component.html',
styleUrls: ['./base-config.component.scss'],
})
export class BaseConfigComponent implements OnInit {
@Input()
public poll?: Poll;
@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,
private apiService: ApiService,
private router: Router,
@Inject(DOCUMENT) private document: Document
) {}
2021-02-05 15:34:00 +01:00
ngOnInit(): void {}
2021-02-04 16:14:07 +01:00
askInitFormDefault(): void {
2021-02-05 15:34:00 +01:00
// this.initFormDefault(false);
2021-02-04 16:14:07 +01:00
this.toastService.display('formulaire réinitialisé');
}
public createPoll(): void {
console.log('this.form', this.form);
const newpoll = this.pollService.newPollFromForm(this.form);
console.log('newpoll', newpoll);
const router = this.router;
this.apiService.createPoll(newpoll).then((resp) => {
console.log('resp', resp);
router.navigate(['success']);
});
// this.router
// if (this.form.valid) {
// console.log('Le sondage est correctement rempli, prêt à enregistrer.');
// const newpoll = this.pollService.newPollFromForm(this.form);
// // TODO : save the poll
// this.apiService.createPoll(newpoll);
// } else {
// this.toastService.display('invalid form');
// }
}
public updateSlug(): void {
const newValueFormatted = 'TODO';
this.form.patchValue({ slug: newValueFormatted });
}
/**
* set the poll slug from other data of the poll
*/
automaticSlug() {
this.form.patchValue({ slug: this.pollService.makeSlug(this.poll) });
}
2021-02-05 15:34:00 +01:00
formUpdate() {
this.formChange.emit(this.form);
}
2021-02-04 16:14:07 +01:00
}