confirm before reinit

This commit is contained in:
Tykayn 2021-11-07 21:08:38 +01:00 committed by tykayn
parent d726eb3668
commit 938a8e72d9
7 changed files with 66 additions and 24 deletions

View File

@ -16,6 +16,8 @@ const apiBaseHref = environment.api.version[apiVersion].baseHref;
const apiEndpoints = environment.api.endpoints;
class PollDTO {}
@Injectable({
providedIn: 'root',
})
@ -78,7 +80,7 @@ export class ApiService {
};
}
public async createPoll(poll: Poll): Promise<Subscription> {
public async createPoll(poll: PollDTO): Promise<Subscription> {
// this.loaderService.setStatus(true);
console.log('createPoll config', poll);
return this.axiosInstance.post(

View File

@ -23,7 +23,7 @@ import { Stack } from '../models/stack.model';
providedIn: 'root',
})
export class PollService implements Resolve<Poll> {
private _poll: BehaviorSubject<Poll | undefined> = new BehaviorSubject<Poll | undefined>(undefined);
public _poll: BehaviorSubject<Poll | undefined> = new BehaviorSubject<Poll | undefined>(undefined);
public readonly poll: Observable<Poll | undefined> = this._poll.asObservable();
public form: FormGroup;
public startDateInterval: string;
@ -38,7 +38,8 @@ export class PollService implements Resolve<Poll> {
public step_max: number = 5;
public round: Function;
public pass_hash: string;
public urlPrefix: string = window.location.origin + '/participation/';
public admin_key: string;
public urlPrefix: string = window.location.origin;
public advancedDisplayEnabled = false;
public showDateInterval = false;
public allowSeveralHours = false;

View File

@ -4,7 +4,7 @@
{{ 'creation.title' | translate }}
</h2>
</header>
<section class="step-container min-height">
<section class="step-container min-height padded">
<router-outlet>
<app-step-one [form]="form"></app-step-one>
</router-outlet>

View File

@ -0,0 +1,10 @@
@import '../../../../styles/variables';
.admin-form {
padding: 1em;
}
textarea {
border: solid 1px $border-color;
width: 100%;
display: block;
}

View File

@ -1,9 +1,7 @@
<app-stepper [step_current]="5" [step_max]="5"></app-stepper>
<div class="content">
<h1 class="title is-1">
Félicitations, votre sondage "<strong>
{{ pollService.form.value.title }} </strong
>" est créé
Félicitations, votre sondage "<strong> {{ pollService.form.value.title }} </strong>" est créé
</h1>
Un récapitulatif par email vous a été envoyé. Partagez-le au monde avec ce lien: Administrez-le avec cet autre lien:
@ -30,8 +28,8 @@
Pour accéder au sondage et à tous ses paramètres :
<a href="{{ pollService.form.value.urlAdmin }}">{{ pollService.form.value.urlAdmin }} </a>
</p>
<app-copy-text [textToCopy]="pollService.form.value.urlAdmin"></app-copy-text>
<a href="{{ pollService.form.value.urlAdmin }}">
<app-copy-text [textToCopy]="pollService.urlPrefix + '/#/admin/' + pollService.admin_key"></app-copy-text>
<a href="{{ pollService.urlPrefix + '/#/admin/' + pollService.admin_key }}">
Voir le sondage coté administrateur·ice
</a>
<p class="note">
@ -43,16 +41,20 @@
<h2 i18n>{{ 'resume.users' | translate }}</h2>
<p>
Pour accéder au sondage :
<a href="{{ pollService.form.value.urlPublic }}">{{ pollService.form.value.urlPublic }} </a>
<a href="{{ pollService.urlPrefix + '/#/poll/' + pollService.form.value.custom_url + '/consultation' }}"
>{{ pollService.urlPrefix + '/#/poll/' + pollService.form.value.custom_url + '/consultation' }}
</a>
</p>
<app-copy-text [textToCopy]="pollService.form.value.urlPublic"></app-copy-text>
<a href="{{ pollService.form.value.urlPublic }}">
<app-copy-text
[textToCopy]="pollService.urlPrefix + '/#/poll/' + pollService.form.value.custom_url + '/consultation'"
></app-copy-text>
<a href="{{ pollService.urlPrefix + '/#/poll/' + pollService.form.value.custom_url + '/consultation' }}">
Voir le sondage
</a>
</section>
<section class="mail">
<h2 i18n>{{ 'resume.links_mail' | translate }}</h2>
<a href="{{ pollService.form.value.urlPublic }}">
<a href="{{ pollService.urlPrefix + '/#/poll/' + pollService.form.value.custom_url + '/consultation' }}">
Voir le sondage
</a>
</section>
@ -60,7 +62,25 @@
<div class="columns">
<div class="column"></div>
<div class="column">
<button class="btn is-primary" (click)="createPoll()" [disabled]="!form.valid || !form.valid">
<button
class="btn is-primary"
(click)="createPoll()"
[disabled]="!pollService.form.valid || !pollService.form.valid"
>
<i class="fa fa-save"></i>
Enregistrer le sondage
</button>
</div>
</div>
<div class="columns">
<div class="column">
<button class="button is-secondary is-fullwidth" [routerLink]="['/administration/step/4']">
précédent
</button>
</div>
<div class="column">
<button class="btn is-success" (click)="createPoll()">
<i class="fa fa-save"></i>
Enregistrer le sondage
</button>
@ -73,20 +93,17 @@
<i class="fa fa-refresh"></i>
Tout réinitialiser
</button>
<button class="btn is-success" (click)="createPoll()">
<i class="fa fa-save"></i>
Enregistrer le sondage
</button>
<button class="btn is-default" (click)="pollService.automaticSlug()">
<i class="fa fa-save"></i>
Slug automatique
</button>
<div class="well">
{{ poll.custom_url }}
{{ pollService.form.value.custom_url }}
</div>
<div class="has-background-danger" *ngIf="!form.valid">
<div class="has-background-danger" *ngIf="!pollService.form.valid">
le formulaire est invalide
<pre> {{ form.errors | json }}</pre>
<pre> {{ pollService.form.errors | json }}</pre>
</div>
</section>

View File

@ -1,6 +1,7 @@
import { Component, Input, OnInit } from '@angular/core';
import { FormGroup } from '@angular/forms';
import { PollService } from '../../../../../core/services/poll.service';
import { ApiService } from '../../../../../core/services/api.service';
@Component({
selector: 'app-step-five',
@ -11,12 +12,19 @@ export class StepFiveComponent implements OnInit {
@Input() step_max: any;
@Input() public form: FormGroup;
poll: any;
constructor(public pollService: PollService) {}
constructor(public pollService: PollService, private apiService: ApiService) {}
ngOnInit(): void {}
askInitFormDefault() {}
askInitFormDefault() {
if (window.confirm('réinitialiser le formulaire ?')) {
this.pollService.askInitFormDefault();
}
}
createPoll() {}
createPoll() {
let apiData = this.pollService.newPollFromForm(this.pollService._poll);
this.apiService.createPoll(apiData);
}
automaticSlug() {}
}

View File

@ -7,3 +7,7 @@ html {
main {
min-height: 90vh;
}
.content {
padding: 1em;
}