2021-12-02 15:52:08 +01:00
|
|
|
import { Component, Input, OnInit } from '@angular/core';
|
2021-12-02 16:09:36 +01:00
|
|
|
import { Router } from '@angular/router';
|
|
|
|
import { PollService } from '../../../core/services/poll.service';
|
2022-03-21 15:40:08 +01:00
|
|
|
import { ToastService } from 'src/app/core/services/toast.service';
|
2021-12-02 15:52:08 +01:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-nav-steps',
|
|
|
|
templateUrl: './nav-steps.component.html',
|
|
|
|
styleUrls: ['./nav-steps.component.scss'],
|
|
|
|
})
|
|
|
|
export class NavStepsComponent implements OnInit {
|
|
|
|
@Input()
|
|
|
|
display_next_button = true;
|
|
|
|
@Input()
|
|
|
|
previous_step_number = 1;
|
|
|
|
@Input()
|
2021-12-02 16:09:36 +01:00
|
|
|
next_step_number = 2;
|
2021-12-02 15:52:08 +01:00
|
|
|
@Input()
|
|
|
|
display_previous_button = true;
|
|
|
|
@Input()
|
|
|
|
is_finish_step = false;
|
2021-12-13 15:30:00 +01:00
|
|
|
/**
|
|
|
|
* some action to perform before changing route
|
|
|
|
*/
|
|
|
|
@Input()
|
|
|
|
actionBeforeNextStep: Function;
|
2022-02-14 11:13:49 +01:00
|
|
|
@Input()
|
|
|
|
next_is_disabled: any = false;
|
2021-12-02 15:52:08 +01:00
|
|
|
|
2022-03-21 15:40:08 +01:00
|
|
|
constructor(private router: Router, private toastService: ToastService, public pollService: PollService) {}
|
2021-12-02 15:52:08 +01:00
|
|
|
|
|
|
|
ngOnInit(): void {}
|
|
|
|
|
2021-12-13 15:30:00 +01:00
|
|
|
/**
|
|
|
|
* launch custom function before next step
|
|
|
|
*/
|
|
|
|
runNextAction() {
|
|
|
|
if (this.actionBeforeNextStep) {
|
|
|
|
this.actionBeforeNextStep();
|
|
|
|
}
|
2021-12-02 16:09:36 +01:00
|
|
|
if (this.is_finish_step) {
|
|
|
|
this.createPoll();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
createPoll() {
|
|
|
|
this.pollService.createPoll().then(
|
|
|
|
(resp) => {
|
2022-03-21 15:40:08 +01:00
|
|
|
console.log('resp', resp);
|
|
|
|
this.router.navigate(['/administration/success/']);
|
2022-02-14 10:37:38 +01:00
|
|
|
this.pollService.step_current = null;
|
2021-12-02 16:09:36 +01:00
|
|
|
},
|
2022-03-21 15:40:08 +01:00
|
|
|
(err: any) => {
|
2021-12-02 16:09:36 +01:00
|
|
|
console.error('oops err', err);
|
2022-03-21 15:40:08 +01:00
|
|
|
this.toastService.display(err.message);
|
2021-12-02 16:09:36 +01:00
|
|
|
}
|
|
|
|
);
|
2021-12-02 15:52:08 +01:00
|
|
|
}
|
|
|
|
}
|