forked from tykayn/funky-framadate-front
fix filling of choices in consultation component after refacto of poll's data in pollService
This commit is contained in:
parent
fc1859719a
commit
989208faa5
@ -84,10 +84,6 @@ export class PollService implements Resolve<Poll> {
|
|||||||
* add example values to the form for demo env
|
* add example values to the form for demo env
|
||||||
*/
|
*/
|
||||||
setDemoValues(): void {
|
setDemoValues(): void {
|
||||||
this.addChoice('orange');
|
|
||||||
this.addChoice('raisin');
|
|
||||||
this.addChoice('abricot');
|
|
||||||
|
|
||||||
this.form.patchValue({
|
this.form.patchValue({
|
||||||
title: 'mon titre de sondage du ' + this.DateUtilitiesService.formateDateToInputStringNg(new Date()),
|
title: 'mon titre de sondage du ' + this.DateUtilitiesService.formateDateToInputStringNg(new Date()),
|
||||||
description: 'répondez SVP <3 ! *-* ',
|
description: 'répondez SVP <3 ! *-* ',
|
||||||
@ -268,17 +264,21 @@ export class PollService implements Resolve<Poll> {
|
|||||||
public updateCurrentPoll(poll: Poll): Poll {
|
public updateCurrentPoll(poll: Poll): Poll {
|
||||||
console.log('this.storageService.vote_stack.id', this.storageService.vote_stack.id);
|
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) {
|
// if (!this.storageService.vote_stack.id || this.storageService.vote_stack.poll_custom_url !== poll.custom_url) {
|
||||||
console.log('set base choices', poll.choices);
|
// console.log('set base choices', poll.choices);
|
||||||
// set the choices only the first time the poll loads, or if we changed the poll
|
// // set the choices only the first time the poll loads, or if we changed the poll
|
||||||
console.log(
|
// console.log(
|
||||||
'this.storageService.vote_stack.poll_custom_url',
|
// 'this.storageService.vote_stack.poll_custom_url',
|
||||||
this.storageService.vote_stack.poll_custom_url
|
// this.storageService.vote_stack.poll_custom_url
|
||||||
);
|
// );
|
||||||
// this.storageService.setChoicesForVoteStack(poll.choices);
|
// this.storageService.setChoicesForVoteStack(poll.choices);
|
||||||
}
|
// }
|
||||||
|
|
||||||
this._poll.next(poll);
|
this._poll.next(poll);
|
||||||
|
console.log('next poll', poll);
|
||||||
|
|
||||||
|
this.storageService.setChoicesForVoteStack(poll.choices);
|
||||||
|
|
||||||
this.toastService.display(`sondage ${poll.title} bien mis à jour`, 'success');
|
this.toastService.display(`sondage ${poll.title} bien mis à jour`, 'success');
|
||||||
return poll;
|
return poll;
|
||||||
}
|
}
|
||||||
@ -591,9 +591,9 @@ export class PollService implements Resolve<Poll> {
|
|||||||
|
|
||||||
public getAdministrationUrlFromForm(): string {
|
public getAdministrationUrlFromForm(): string {
|
||||||
// admin_key is filled after creation
|
// 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 {
|
public getParticipationUrl(): string {
|
||||||
|
@ -47,17 +47,12 @@ export class StorageService {
|
|||||||
|
|
||||||
constructor(public dateUtilities: DateUtilitiesService, private toastService: ToastService) {
|
constructor(public dateUtilities: DateUtilitiesService, private toastService: ToastService) {
|
||||||
if (environment.autofill_participation) {
|
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: 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: Atelier cuisine du quartier', 'aujourdhui-ou-demain'));
|
||||||
this.userPolls.push(
|
this.userPolls.push(
|
||||||
new Poll(new Owner(), 'Démo: Réunion du département des chatons', 'aujourdhui-ou-demain')
|
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) {
|
if (!this.vote_stack.id) {
|
||||||
this.vote_stack = new Stack();
|
this.vote_stack = new Stack();
|
||||||
|
|
||||||
|
console.log('choices_list', choices_list);
|
||||||
for (const choice of choices_list) {
|
for (const choice of choices_list) {
|
||||||
if (environment.autofill_participation) {
|
// if (environment.autofill_participation) {
|
||||||
console.log('autofill au hasard des votes à ce sondage');
|
// console.log('autofill au hasard des votes à ce sondage');
|
||||||
this.toastService.display('autofill au hasard des votes à ce sondage');
|
// this.toastService.display('autofill au hasard des votes à ce sondage');
|
||||||
const defaultvalue = Math.random() > 0.75 ? 'yes' : '';
|
// const defaultvalue = Math.random() > 0.75 ? 'yes' : '';
|
||||||
this.vote_stack.votes.push(new Vote(choice.id, defaultvalue));
|
// this.vote_stack.votes.push(new Vote(choice.id, defaultvalue));
|
||||||
} else {
|
// } else {
|
||||||
this.vote_stack.votes.push(new Vote(choice.id));
|
this.vote_stack.votes.push(new Vote(choice.id));
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,6 @@ export class AdminConsultationComponent implements OnInit {
|
|||||||
this.apiService.getPollByAdminKey(this.admin_key).then(
|
this.apiService.getPollByAdminKey(this.admin_key).then(
|
||||||
(res) => {
|
(res) => {
|
||||||
this.pollService.updateCurrentPoll(res.poll);
|
this.pollService.updateCurrentPoll(res.poll);
|
||||||
this.patchFormLoadedWithPoll();
|
|
||||||
this.form = this.pollService.form;
|
this.form = this.pollService.form;
|
||||||
this.poll = this.pollService._poll.getValue();
|
this.poll = this.pollService._poll.getValue();
|
||||||
console.log('formulaire patché', this.pollService.form, this.pollService.poll);
|
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());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -61,17 +61,17 @@ export class ConsultationComponent implements OnInit, OnDestroy {
|
|||||||
console.log('this.pass_hash ', this.pass_hash);
|
console.log('this.pass_hash ', this.pass_hash);
|
||||||
if (this.pass_hash) {
|
if (this.pass_hash) {
|
||||||
this.pollService.loadPollByCustomUrlWithPasswordHash(this.pollSlug, this.pass_hash).then((resp) => {
|
this.pollService.loadPollByCustomUrlWithPasswordHash(this.pollSlug, this.pass_hash).then((resp) => {
|
||||||
console.log('resp', resp);
|
console.log('loadPollByCustomUrlWithPasswordHash resp', resp);
|
||||||
this.fetching = false;
|
this.fetching = false;
|
||||||
this.storageService.vote_stack.id = null;
|
this.storageService.vote_stack.id = null;
|
||||||
this.storageService.setChoicesForVoteStack(this.pollService.form.value.choices);
|
this.storageService.setChoicesForVoteStack(this.pollService._poll.getValue().choices);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
this.pollService.loadPollByCustomUrl(this.pollSlug).then((resp) => {
|
this.pollService.loadPollByCustomUrl(this.pollSlug).then((resp) => {
|
||||||
console.log('resp', resp);
|
console.log('loadPollByCustomUrl resp', resp);
|
||||||
this.fetching = false;
|
this.fetching = false;
|
||||||
this.storageService.vote_stack.id = null;
|
this.storageService.vote_stack.id = null;
|
||||||
this.storageService.setChoicesForVoteStack(this.pollService.form.value.choices);
|
this.storageService.setChoicesForVoteStack(this.pollService._poll.getValue().choices);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user