From 748eb4812537918ed5c56f2e4ae488dab7eb77eb Mon Sep 17 00:00:00 2001 From: Tykayn Date: Mon, 7 Jun 2021 12:16:56 +0200 Subject: [PATCH] keep stack of vote after creation --- src/app/core/services/api.service.ts | 2 +- src/app/core/services/storage.service.ts | 23 +++++++++---------- .../consultation/consultation.component.html | 9 +++----- .../consultation/consultation.component.ts | 4 +++- src/environments/endpoints.ts | 8 +++---- src/environments/environment.prod.ts | 1 + 6 files changed, 23 insertions(+), 24 deletions(-) diff --git a/src/app/core/services/api.service.ts b/src/app/core/services/api.service.ts index 5a19a830..c737a2c0 100644 --- a/src/app/core/services/api.service.ts +++ b/src/app/core/services/api.service.ts @@ -206,7 +206,7 @@ export class ApiService { public async sendUpdateVoteStack(vote_stack: Stack) { try { return await this.axiosInstance.patch( - `${this.baseHref}/vote-stack/${vote_stack.id}/token/${vote_stack.owner.modifier_token}/`, + `${this.baseHref}/vote-stack/${vote_stack.id}/token/${vote_stack.owner.modifier_token}`, vote_stack ); } catch (error) { diff --git a/src/app/core/services/storage.service.ts b/src/app/core/services/storage.service.ts index 03fd6cc7..4a37ee61 100644 --- a/src/app/core/services/storage.service.ts +++ b/src/app/core/services/storage.service.ts @@ -45,11 +45,7 @@ export class StorageService { @LocalStorage() public choices: Choice[] = []; - constructor( - public dateUtilities: DateUtilitiesService, - - private toastService: ToastService - ) { + constructor(public dateUtilities: DateUtilitiesService, private toastService: ToastService) { if (environment.autofill) { this.toastService.display('autofill des sondages utilisateur'); this.userPolls.push(new Poll(new Owner(), 'Démo: Anniversaire de tonton Patrick', 'aujourdhui-ou-demain')); @@ -68,13 +64,16 @@ export class StorageService { this.vote_stack.votes = []; // text choices - for (const choice of choices_list) { - if (environment.autofill) { - this.toastService.display('autofill au hasard des votes à ce sondage'); - const defaultvalue = Math.random() > 0.75 ? 'yes' : ''; - this.vote_stack.votes.push(new Vote(choice.id, defaultvalue)); - } else { - this.vote_stack.votes.push(new Vote(choice.id)); + if (!this.vote_stack.id) { + for (const choice of choices_list) { + if (environment.autofill) { + console.log('autofill au hasard des votes à ce sondage'); + this.toastService.display('autofill au hasard des votes à ce sondage'); + const defaultvalue = Math.random() > 0.75 ? 'yes' : ''; + this.vote_stack.votes.push(new Vote(choice.id, defaultvalue)); + } else { + this.vote_stack.votes.push(new Vote(choice.id)); + } } } } diff --git a/src/app/features/consultation/consultation.component.html b/src/app/features/consultation/consultation.component.html index 5ef24a44..570bc090 100644 --- a/src/app/features/consultation/consultation.component.html +++ b/src/app/features/consultation/consultation.component.html @@ -102,10 +102,12 @@ *ngIf="!storageService.vote_stack || !storageService.vote_stack.id" > Envoyer + + {{ storageService.vote_stack.votes.length }} réponses