fix filling of choices in consultation component after refacto of poll's data in pollService

This commit is contained in:
Tykayn 2021-11-14 17:25:57 +01:00 committed by tykayn
parent fc1859719a
commit 989208faa5
4 changed files with 28 additions and 37 deletions

View File

@ -84,10 +84,6 @@ export class PollService implements Resolve<Poll> {
* 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<Poll> {
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<Poll> {
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 {

View File

@ -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));
// }
}
}
}

View File

@ -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());
}
}

View File

@ -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);
});
}
});