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; const apiEndpoints = environment.api.endpoints;
class PollDTO {}
@Injectable({ @Injectable({
providedIn: 'root', 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); // this.loaderService.setStatus(true);
console.log('createPoll config', poll); console.log('createPoll config', poll);
return this.axiosInstance.post( return this.axiosInstance.post(

View File

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

View File

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

View File

@ -1,6 +1,7 @@
import { Component, Input, OnInit } from '@angular/core'; import { Component, Input, OnInit } from '@angular/core';
import { FormGroup } from '@angular/forms'; import { FormGroup } from '@angular/forms';
import { PollService } from '../../../../../core/services/poll.service'; import { PollService } from '../../../../../core/services/poll.service';
import { ApiService } from '../../../../../core/services/api.service';
@Component({ @Component({
selector: 'app-step-five', selector: 'app-step-five',
@ -11,12 +12,19 @@ export class StepFiveComponent implements OnInit {
@Input() step_max: any; @Input() step_max: any;
@Input() public form: FormGroup; @Input() public form: FormGroup;
poll: any; poll: any;
constructor(public pollService: PollService) {} constructor(public pollService: PollService, private apiService: ApiService) {}
ngOnInit(): void {} 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() {} automaticSlug() {}
} }

View File

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