diff --git a/src/app/config/PollConfig.ts b/src/app/config/PollConfig.ts index 8a6c7ffd..12e3bfe2 100644 --- a/src/app/config/PollConfig.ts +++ b/src/app/config/PollConfig.ts @@ -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 diff --git a/src/app/config/mocks/mock-poll3.ts b/src/app/config/mocks/mock-poll3.ts index d8edb432..eecaa053 100644 --- a/src/app/config/mocks/mock-poll3.ts +++ b/src/app/config/mocks/mock-poll3.ts @@ -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 -} +}; diff --git a/src/app/pages/voting/voting-summary/voting-summary.component.html b/src/app/pages/voting/voting-summary/voting-summary.component.html index 1dbaeb82..60302511 100644 --- a/src/app/pages/voting/voting-summary/voting-summary.component.html +++ b/src/app/pages/voting/voting-summary/voting-summary.component.html @@ -35,16 +35,24 @@ *ngFor='let voteStack of pollconfig.stacks' > + + {{voteStack.pseudo}} - {{voteStack.votes[v].value}} + diff --git a/src/app/pages/voting/voting-summary/voting-summary.component.ts b/src/app/pages/voting/voting-summary/voting-summary.component.ts index c2cee954..0f9b9778 100644 --- a/src/app/pages/voting/voting-summary/voting-summary.component.ts +++ b/src/app/pages/voting/voting-summary/voting-summary.component.ts @@ -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; diff --git a/src/app/services/config.service.ts b/src/app/services/config.service.ts index e7f0806e..cc789fc9 100644 --- a/src/app/services/config.service.ts +++ b/src/app/services/config.service.ts @@ -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 = {