From 989208faa5a2c4ebed2bc1e12babe014fc619899 Mon Sep 17 00:00:00 2001 From: Tykayn Date: Sun, 14 Nov 2021 17:25:57 +0100 Subject: [PATCH] fix filling of choices in consultation component after refacto of poll's data in pollService --- src/app/core/services/poll.service.ts | 30 +++++++++---------- src/app/core/services/storage.service.ts | 22 ++++++-------- .../consultation/consultation.component.ts | 5 ---- .../consultation/consultation.component.ts | 8 ++--- 4 files changed, 28 insertions(+), 37 deletions(-) diff --git a/src/app/core/services/poll.service.ts b/src/app/core/services/poll.service.ts index c6cf37cd..e5ec3eba 100644 --- a/src/app/core/services/poll.service.ts +++ b/src/app/core/services/poll.service.ts @@ -84,10 +84,6 @@ export class PollService implements Resolve { * add example values to the form for demo env */ setDemoValues(): void { - this.addChoice('orange'); - this.addChoice('raisin'); - this.addChoice('abricot'); - this.form.patchValue({ title: 'mon titre de sondage du ' + this.DateUtilitiesService.formateDateToInputStringNg(new Date()), description: 'répondez SVP <3 ! *-* ', @@ -268,17 +264,21 @@ export class PollService implements Resolve { public updateCurrentPoll(poll: Poll): Poll { console.log('this.storageService.vote_stack.id', this.storageService.vote_stack.id); - if (!this.storageService.vote_stack.id || this.storageService.vote_stack.poll_custom_url !== poll.custom_url) { - console.log('set base choices', poll.choices); - // set the choices only the first time the poll loads, or if we changed the poll - console.log( - 'this.storageService.vote_stack.poll_custom_url', - this.storageService.vote_stack.poll_custom_url - ); - // this.storageService.setChoicesForVoteStack(poll.choices); - } + // if (!this.storageService.vote_stack.id || this.storageService.vote_stack.poll_custom_url !== poll.custom_url) { + // console.log('set base choices', poll.choices); + // // set the choices only the first time the poll loads, or if we changed the poll + // console.log( + // 'this.storageService.vote_stack.poll_custom_url', + // this.storageService.vote_stack.poll_custom_url + // ); + // this.storageService.setChoicesForVoteStack(poll.choices); + // } this._poll.next(poll); + console.log('next poll', poll); + + this.storageService.setChoicesForVoteStack(poll.choices); + this.toastService.display(`sondage ${poll.title} bien mis à jour`, 'success'); return poll; } @@ -591,9 +591,9 @@ export class PollService implements Resolve { public getAdministrationUrlFromForm(): string { // admin_key is filled after creation - // example http://localhost:4200/#/administration/8Ubcg2YI99f69xz946cn4O64bQAeb + // example http://localhost:4200/#/administration/key/8Ubcg2YI99f69xz946cn4O64bQAeb - return `${environment.frontDomain}#/administration/${this.admin_key}`; + return `${environment.frontDomain}#/administration/key/${this.admin_key}`; } public getParticipationUrl(): string { diff --git a/src/app/core/services/storage.service.ts b/src/app/core/services/storage.service.ts index eceb828b..ac2c8148 100644 --- a/src/app/core/services/storage.service.ts +++ b/src/app/core/services/storage.service.ts @@ -47,17 +47,12 @@ export class StorageService { constructor(public dateUtilities: DateUtilitiesService, private toastService: ToastService) { if (environment.autofill_participation) { - // this.toastService.display('autofill des sondages utilisateur'); this.userPolls.push(new Poll(new Owner(), 'Démo: Anniversaire de tonton Patrick', 'aujourdhui-ou-demain')); this.userPolls.push(new Poll(new Owner(), 'Démo: Atelier cuisine du quartier', 'aujourdhui-ou-demain')); this.userPolls.push( new Poll(new Owner(), 'Démo: Réunion du département des chatons', 'aujourdhui-ou-demain') ); } - - if (!this.dateChoices.length) { - this.dateChoices = this.dateUtilities.makeDefaultDateChoices(); - } } /** @@ -70,15 +65,16 @@ export class StorageService { if (!this.vote_stack.id) { this.vote_stack = new Stack(); + console.log('choices_list', choices_list); for (const choice of choices_list) { - if (environment.autofill_participation) { - 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)); - } + // if (environment.autofill_participation) { + // 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/administration/consultation/consultation.component.ts b/src/app/features/administration/consultation/consultation.component.ts index 150d5c42..19a4c025 100644 --- a/src/app/features/administration/consultation/consultation.component.ts +++ b/src/app/features/administration/consultation/consultation.component.ts @@ -34,7 +34,6 @@ export class AdminConsultationComponent implements OnInit { this.apiService.getPollByAdminKey(this.admin_key).then( (res) => { this.pollService.updateCurrentPoll(res.poll); - this.patchFormLoadedWithPoll(); this.form = this.pollService.form; this.poll = this.pollService._poll.getValue(); console.log('formulaire patché', this.pollService.form, this.pollService.poll); @@ -47,8 +46,4 @@ export class AdminConsultationComponent implements OnInit { ); }); } - - patchFormLoadedWithPoll() { - this.pollService.patchFormWithPoll(this.pollService._poll.getValue()); - } } diff --git a/src/app/features/consultation/consultation.component.ts b/src/app/features/consultation/consultation.component.ts index e9ce1fb5..63195644 100644 --- a/src/app/features/consultation/consultation.component.ts +++ b/src/app/features/consultation/consultation.component.ts @@ -61,17 +61,17 @@ export class ConsultationComponent implements OnInit, OnDestroy { console.log('this.pass_hash ', this.pass_hash); if (this.pass_hash) { this.pollService.loadPollByCustomUrlWithPasswordHash(this.pollSlug, this.pass_hash).then((resp) => { - console.log('resp', resp); + console.log('loadPollByCustomUrlWithPasswordHash resp', resp); this.fetching = false; this.storageService.vote_stack.id = null; - this.storageService.setChoicesForVoteStack(this.pollService.form.value.choices); + this.storageService.setChoicesForVoteStack(this.pollService._poll.getValue().choices); }); } else { this.pollService.loadPollByCustomUrl(this.pollSlug).then((resp) => { - console.log('resp', resp); + console.log('loadPollByCustomUrl resp', resp); this.fetching = false; this.storageService.vote_stack.id = null; - this.storageService.setChoicesForVoteStack(this.pollService.form.value.choices); + this.storageService.setChoicesForVoteStack(this.pollService._poll.getValue().choices); }); } });