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!';
isAdmin: boolean = true;
myVoteStack: any;
myTempVoteStack =0;
myTempVoteStack = 0;
myEmail: string = "tktest@tktest.com";
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
@ -43,6 +43,7 @@ export class PollConfig {
voteChoices = 'only_yes'; // possible answers to a vote choice: only "yes", "yes, maybe, no"
creationDate = new 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
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

View File

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

View File

@ -35,16 +35,24 @@
*ngFor='let voteStack of pollconfig.stacks'
>
<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}}
</td >
<td *ngFor='let v of getKeys(voteStack.votes)' >
<!-- {{voteStack.votes[v].choice_id}}-->
<span *ngIf='voteStack.votes[v].value' >
{{voteStack.votes[v].value}}
</span >
</td >
</tr >
<!-- bottom line shows each answer details-->
<tr class='details' >
<td >
<i class='fa fa-eye' ></i >

View File

@ -10,9 +10,6 @@ import {mockPoll3} from "../../../config/mocks/mock-poll3";
export class VotingSummaryComponent implements OnInit {
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;

View File

@ -290,6 +290,32 @@ export class ConfigService extends PollConfig {
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
* /api/v1/poll/{id}/poll
@ -297,7 +323,7 @@ export class ConfigService extends PollConfig {
*/
createPollFromConfig(config: any) {
this.loading = true;
console.log('config', config)
console.log('config', config);
return this.http.post(`${this.baseHref}/poll`,
config,
this.makeHeaders())
@ -410,17 +436,17 @@ export class ConfigService extends PollConfig {
text: this.myComment,
}
}
console.log('comment', comment)
console.log('comment', comment);
this.http.post(
`${this.baseHref}/poll/${this.pollId}/comment`,
comment,
this.makeHeaders())
.subscribe((res: any) => {
this.messageService.add({
severity: 'success',
summary: 'Commentaire Créé',
detail: comment.text
});
this.messageService.add({
severity: 'success',
summary: 'Commentaire Créé',
detail: comment.text
});
// empty comment after success
this.myComment = '';
comment.date = {