update current answers with a previous vote

This commit is contained in:
Baptiste Lemoine 2020-01-30 10:07:03 +01:00
parent f976d65d20
commit 9cf368f550
5 changed files with 46 additions and 14 deletions

View File

@ -33,7 +33,7 @@ export class PollConfig {
myComment: string = 'wouah trop bien framadate!'; myComment: string = 'wouah trop bien framadate!';
isAdmin: boolean = true; isAdmin: boolean = true;
myVoteStack: any; myVoteStack: any;
myTempVoteStack =0; myTempVoteStack = 0;
myEmail: string = "tktest@tktest.com"; myEmail: string = "tktest@tktest.com";
myPolls: any = [];// list of retrieved polls from the backend api myPolls: any = [];// list of retrieved polls from the backend api
// date specific poll, we have the choice to setup different hours (timeList) for all possible dates (dateList), or use the same hours for all dates // date specific poll, we have the choice to setup different hours (timeList) for all possible dates (dateList), or use the same hours for all dates
@ -43,6 +43,7 @@ export class PollConfig {
voteChoices = 'only_yes'; // possible answers to a vote choice: only "yes", "yes, maybe, no" voteChoices = 'only_yes'; // possible answers to a vote choice: only "yes", "yes, maybe, no"
creationDate = new Date(); creationDate = new Date();
expirationDate = ''; // expiracy date expirationDate = ''; // expiracy date
voteStackId = null; // id of the vote stack to update
pollId = null; // id of the current poll when created. data given by the backend api pollId = null; // id of the current poll when created. data given by the backend api
pollSlug = null; // id of the current poll when created. data given by the backend api pollSlug = null; // id of the current poll when created. data given by the backend api
currentPoll; // current poll selected with createPoll or getPoll of ConfigService currentPoll; // current poll selected with createPoll or getPoll of ConfigService

View File

@ -26,7 +26,7 @@ export const mockPoll3 = {
"allowedAnswers": [ "allowedAnswers": [
"yes" "yes"
], ],
"modificationPolicy": "self", "modificationPolicy": "everybody",
"mailOnComment": null, "mailOnComment": null,
"mailOnVote": null, "mailOnVote": null,
"hideResults": null, "hideResults": null,
@ -965,4 +965,4 @@ export const mockPoll3 = {
} }
], ],
"comments_count": 14 "comments_count": 14
} };

View File

@ -35,16 +35,24 @@
*ngFor='let voteStack of pollconfig.stacks' *ngFor='let voteStack of pollconfig.stacks'
> >
<td > <td >
<button
(click)='config.loadVoteStack(voteStack)'
*ngIf="config.currentPoll.poll.modificationPolicy === 'everybody'"
class='btn btn--primary pull-left btn--small'
>
<i class='fa fa-pencil' ></i >
</button >
{{voteStack.pseudo}} {{voteStack.pseudo}}
</td > </td >
<td *ngFor='let v of getKeys(voteStack.votes)' > <td *ngFor='let v of getKeys(voteStack.votes)' >
<!-- {{voteStack.votes[v].choice_id}}-->
<span *ngIf='voteStack.votes[v].value' > <span *ngIf='voteStack.votes[v].value' >
{{voteStack.votes[v].value}} {{voteStack.votes[v].value}}
</span > </span >
</td > </td >
</tr > </tr >
<!-- bottom line shows each answer details-->
<tr class='details' > <tr class='details' >
<td > <td >
<i class='fa fa-eye' ></i > <i class='fa fa-eye' ></i >

View File

@ -10,9 +10,6 @@ import {mockPoll3} from "../../../config/mocks/mock-poll3";
export class VotingSummaryComponent implements OnInit { export class VotingSummaryComponent implements OnInit {
preferred: string = 'rien'; preferred: string = 'rien';
counters: any = {};
orderedListOfChoices: any = {};
enrichedStacks: any = []; // a list of vote stacks with the missing ids of what has not been voted
@Input() pollconfig = mockPoll3; @Input() pollconfig = mockPoll3;

View File

@ -290,6 +290,32 @@ export class ConfigService extends PollConfig {
this.urlAdmin = this.baseHref + '#/admin/' + res.admin_key; this.urlAdmin = this.baseHref + '#/admin/' + res.admin_key;
} }
/**
* update current answers with a previous vote
* @param voteStack
*/
loadVoteStack(voteStack: any) {
// load the pseudo and email
this.myName = voteStack.pseudo;
this.myEmail = voteStack.pseudo;
this.voteStackId = voteStack.id;
this.myVoteStack = voteStack;
let votesId = Object.keys(voteStack.votes);
votesId.map((id) => {
let voteItem = voteStack.votes[id];
if (voteItem.choice_id && voteItem.value) {
let foundChoiceToModify = this.currentPoll.choices.find(choicesItem => {
return voteItem.choice_id == choicesItem.id
});
if (foundChoiceToModify) {
foundChoiceToModify.answer = voteItem.value;
}
}
})
}
/** /**
* POST * POST
* /api/v1/poll/{id}/poll * /api/v1/poll/{id}/poll
@ -297,7 +323,7 @@ export class ConfigService extends PollConfig {
*/ */
createPollFromConfig(config: any) { createPollFromConfig(config: any) {
this.loading = true; this.loading = true;
console.log('config', config) console.log('config', config);
return this.http.post(`${this.baseHref}/poll`, return this.http.post(`${this.baseHref}/poll`,
config, config,
this.makeHeaders()) this.makeHeaders())
@ -410,17 +436,17 @@ export class ConfigService extends PollConfig {
text: this.myComment, text: this.myComment,
} }
} }
console.log('comment', comment) console.log('comment', comment);
this.http.post( this.http.post(
`${this.baseHref}/poll/${this.pollId}/comment`, `${this.baseHref}/poll/${this.pollId}/comment`,
comment, comment,
this.makeHeaders()) this.makeHeaders())
.subscribe((res: any) => { .subscribe((res: any) => {
this.messageService.add({ this.messageService.add({
severity: 'success', severity: 'success',
summary: 'Commentaire Créé', summary: 'Commentaire Créé',
detail: comment.text detail: comment.text
}); });
// empty comment after success // empty comment after success
this.myComment = ''; this.myComment = '';
comment.date = { comment.date = {