From 43ea524c2604891095940da3827ecd7c0003a10b Mon Sep 17 00:00:00 2001 From: Baptiste Lemoine Date: Wed, 29 Jan 2020 17:30:39 +0100 Subject: [PATCH] display a table of answers --- src/app/config/mocks/mock-poll3.ts | 353 ++++++++++++++---- .../poll-display/poll-display.component.html | 71 ++-- .../voting-summary.component.html | 48 ++- .../voting-summary.component.scss | 9 + .../voting-summary.component.ts | 35 +- 5 files changed, 356 insertions(+), 160 deletions(-) diff --git a/src/app/config/mocks/mock-poll3.ts b/src/app/config/mocks/mock-poll3.ts index bd17c8e1..d8edb432 100644 --- a/src/app/config/mocks/mock-poll3.ts +++ b/src/app/config/mocks/mock-poll3.ts @@ -47,22 +47,37 @@ export const mockPoll3 = { "timezone_type": 3, "timezone": "Europe/Berlin" }, - "votes": [ - { + "votes": { + "5": { + "choice_id": 5 + }, + "6": { + "id": 3, + "vote_id": 5, + "value": "maybe", + "choice_id": 6, + "text": "Boumbo petite automobile" + }, + "7": { "id": 3, "vote_id": 4, "value": "yes", "choice_id": 7, "text": "Les mystérieuses cités d'or" }, - { - "id": 3, - "vote_id": 5, - "value": "maybe", - "choice_id": 6, - "text": "Boumbo petite automobile" + "8": { + "choice_id": 8 + }, + "9": { + "choice_id": 9 + }, + "10": { + "choice_id": 10 + }, + "11": { + "choice_id": 11 } - ] + } }, { "id": 4, @@ -72,29 +87,37 @@ export const mockPoll3 = { "timezone_type": 3, "timezone": "Europe/Berlin" }, - "votes": [ - { + "votes": { + "5": { + "choice_id": 5 + }, + "6": { "id": 4, "vote_id": 6, "value": "yes", "choice_id": 6, "text": "Boumbo petite automobile" }, - { - "id": 4, - "vote_id": 7, - "value": "yes", - "choice_id": 7, - "text": "Les mystérieuses cités d'or" - }, - { + "7": { "id": 4, "vote_id": 8, "value": "no", "choice_id": 7, "text": "Les mystérieuses cités d'or" + }, + "8": { + "choice_id": 8 + }, + "9": { + "choice_id": 9 + }, + "10": { + "choice_id": 10 + }, + "11": { + "choice_id": 11 } - ] + } }, { "id": 5, @@ -104,29 +127,41 @@ export const mockPoll3 = { "timezone_type": 3, "timezone": "Europe/Berlin" }, - "votes": [ - { + "votes": { + "5": { "id": 5, "vote_id": 9, "value": "no", "choice_id": 5, "text": "Vic le viking" }, - { + "6": { "id": 5, "vote_id": 10, "value": "maybe", "choice_id": 6, "text": "Boumbo petite automobile" }, - { + "7": { "id": 5, "vote_id": 11, "value": "yes", "choice_id": 7, "text": "Les mystérieuses cités d'or" + }, + "8": { + "choice_id": 8 + }, + "9": { + "choice_id": 9 + }, + "10": { + "choice_id": 10 + }, + "11": { + "choice_id": 11 } - ] + } }, { "id": 6, @@ -136,29 +171,41 @@ export const mockPoll3 = { "timezone_type": 3, "timezone": "Europe/Berlin" }, - "votes": [ - { + "votes": { + "5": { "id": 6, "vote_id": 12, "value": "no", "choice_id": 5, "text": "Vic le viking" }, - { + "6": { "id": 6, "vote_id": 13, "value": "maybe", "choice_id": 6, "text": "Boumbo petite automobile" }, - { + "7": { "id": 6, "vote_id": 14, "value": "yes", "choice_id": 7, "text": "Les mystérieuses cités d'or" + }, + "8": { + "choice_id": 8 + }, + "9": { + "choice_id": 9 + }, + "10": { + "choice_id": 10 + }, + "11": { + "choice_id": 11 } - ] + } }, { "id": 7, @@ -168,29 +215,41 @@ export const mockPoll3 = { "timezone_type": 3, "timezone": "Europe/Berlin" }, - "votes": [ - { + "votes": { + "5": { "id": 7, "vote_id": 15, "value": "no", "choice_id": 5, "text": "Vic le viking" }, - { + "6": { "id": 7, "vote_id": 16, "value": "maybe", "choice_id": 6, "text": "Boumbo petite automobile" }, - { + "7": { "id": 7, "vote_id": 17, "value": "yes", "choice_id": 7, "text": "Les mystérieuses cités d'or" + }, + "8": { + "choice_id": 8 + }, + "9": { + "choice_id": 9 + }, + "10": { + "choice_id": 10 + }, + "11": { + "choice_id": 11 } - ] + } }, { "id": 8, @@ -200,29 +259,41 @@ export const mockPoll3 = { "timezone_type": 3, "timezone": "Europe/Berlin" }, - "votes": [ - { + "votes": { + "5": { "id": 8, "vote_id": 18, "value": "no", "choice_id": 5, "text": "Vic le viking" }, - { + "6": { "id": 8, "vote_id": 19, "value": "maybe", "choice_id": 6, "text": "Boumbo petite automobile" }, - { + "7": { "id": 8, "vote_id": 20, "value": "yes", "choice_id": 7, "text": "Les mystérieuses cités d'or" + }, + "8": { + "choice_id": 8 + }, + "9": { + "choice_id": 9 + }, + "10": { + "choice_id": 10 + }, + "11": { + "choice_id": 11 } - ] + } }, { "id": 9, @@ -232,29 +303,41 @@ export const mockPoll3 = { "timezone_type": 3, "timezone": "Europe/Berlin" }, - "votes": [ - { + "votes": { + "5": { "id": 9, "vote_id": 21, "value": "no", "choice_id": 5, "text": "Vic le viking" }, - { + "6": { "id": 9, "vote_id": 22, "value": "maybe", "choice_id": 6, "text": "Boumbo petite automobile" }, - { + "7": { "id": 9, "vote_id": 23, "value": "yes", "choice_id": 7, "text": "Les mystérieuses cités d'or" + }, + "8": { + "choice_id": 8 + }, + "9": { + "choice_id": 9 + }, + "10": { + "choice_id": 10 + }, + "11": { + "choice_id": 11 } - ] + } }, { "id": 10, @@ -264,29 +347,41 @@ export const mockPoll3 = { "timezone_type": 3, "timezone": "Europe/Berlin" }, - "votes": [ - { + "votes": { + "5": { "id": 10, "vote_id": 24, "value": "no", "choice_id": 5, "text": "Vic le viking" }, - { + "6": { "id": 10, "vote_id": 25, "value": "maybe", "choice_id": 6, "text": "Boumbo petite automobile" }, - { + "7": { "id": 10, "vote_id": 26, "value": "yes", "choice_id": 7, "text": "Les mystérieuses cités d'or" + }, + "8": { + "choice_id": 8 + }, + "9": { + "choice_id": 9 + }, + "10": { + "choice_id": 10 + }, + "11": { + "choice_id": 11 } - ] + } }, { "id": 11, @@ -296,29 +391,41 @@ export const mockPoll3 = { "timezone_type": 3, "timezone": "Europe/Berlin" }, - "votes": [ - { + "votes": { + "5": { "id": 11, "vote_id": 27, "value": "no", "choice_id": 5, "text": "Vic le viking" }, - { + "6": { "id": 11, "vote_id": 28, "value": "maybe", "choice_id": 6, "text": "Boumbo petite automobile" }, - { + "7": { "id": 11, "vote_id": 29, "value": "yes", "choice_id": 7, "text": "Les mystérieuses cités d'or" + }, + "8": { + "choice_id": 8 + }, + "9": { + "choice_id": 9 + }, + "10": { + "choice_id": 10 + }, + "11": { + "choice_id": 11 } - ] + } }, { "id": 12, @@ -328,29 +435,41 @@ export const mockPoll3 = { "timezone_type": 3, "timezone": "Europe/Berlin" }, - "votes": [ - { + "votes": { + "5": { "id": 12, "vote_id": 30, "value": "no", "choice_id": 5, "text": "Vic le viking" }, - { + "6": { "id": 12, "vote_id": 31, "value": "maybe", "choice_id": 6, "text": "Boumbo petite automobile" }, - { + "7": { "id": 12, "vote_id": 32, "value": "yes", "choice_id": 7, "text": "Les mystérieuses cités d'or" + }, + "8": { + "choice_id": 8 + }, + "9": { + "choice_id": 9 + }, + "10": { + "choice_id": 10 + }, + "11": { + "choice_id": 11 } - ] + } }, { "id": 13, @@ -360,15 +479,36 @@ export const mockPoll3 = { "timezone_type": 3, "timezone": "Europe/Berlin" }, - "votes": [ - { + "votes": { + "5": { + "choice_id": 5 + }, + "6": { + "choice_id": 6 + }, + "7": { + "choice_id": 7 + }, + "8": { + "choice_id": 8 + }, + "9": { + "choice_id": 9 + }, + "10": { + "choice_id": 10 + }, + "11": { + "choice_id": 11 + }, + "2": { "id": 13, "vote_id": 33, "value": "yes", "choice_id": 2, "text": null } - ] + } }, { "id": 14, @@ -378,15 +518,36 @@ export const mockPoll3 = { "timezone_type": 3, "timezone": "Europe/Berlin" }, - "votes": [ - { + "votes": { + "5": { + "choice_id": 5 + }, + "6": { + "choice_id": 6 + }, + "7": { + "choice_id": 7 + }, + "8": { + "choice_id": 8 + }, + "9": { + "choice_id": 9 + }, + "10": { + "choice_id": 10 + }, + "11": { + "choice_id": 11 + }, + "2": { "id": 14, "vote_id": 34, "value": "yes", "choice_id": 2, "text": null } - ] + } }, { "id": 15, @@ -396,15 +557,36 @@ export const mockPoll3 = { "timezone_type": 3, "timezone": "Europe/Berlin" }, - "votes": [ - { + "votes": { + "5": { + "choice_id": 5 + }, + "6": { + "choice_id": 6 + }, + "7": { + "choice_id": 7 + }, + "8": { + "choice_id": 8 + }, + "9": { + "choice_id": 9 + }, + "10": { + "choice_id": 10 + }, + "11": { + "choice_id": 11 + }, + "2": { "id": 15, "vote_id": 35, "value": "yes", "choice_id": 2, "text": null } - ] + } }, { "id": 16, @@ -414,22 +596,43 @@ export const mockPoll3 = { "timezone_type": 3, "timezone": "Europe/Berlin" }, - "votes": [ - { + "votes": { + "5": { + "choice_id": 5 + }, + "6": { + "choice_id": 6 + }, + "7": { + "choice_id": 7 + }, + "8": { + "choice_id": 8 + }, + "9": { + "choice_id": 9 + }, + "10": { + "choice_id": 10 + }, + "11": { + "choice_id": 11 + }, + "1": { "id": 16, "vote_id": 36, "value": "no", "choice_id": 1, "text": "orange" }, - { + "2": { "id": 16, "vote_id": 37, "value": "yes", "choice_id": 2, "text": null } - ] + } } ], "choices_count": { @@ -545,10 +748,6 @@ export const mockPoll3 = { ] } } - }, - "people": { - "voting_people_TEST": "yes", - "tk_TEST": "yes" } }, "choices": [ diff --git a/src/app/pages/poll-display/poll-display.component.html b/src/app/pages/poll-display/poll-display.component.html index 58d4a591..3a6ae413 100644 --- a/src/app/pages/poll-display/poll-display.component.html +++ b/src/app/pages/poll-display/poll-display.component.html @@ -1,35 +1,38 @@
- +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

{{config.currentPoll.poll.title}}

@@ -85,7 +88,7 @@ [ngClass]='{"btn--primary" : config.myTempVoteStack } ' *ngIf='!config.myVoteStack || !config.myVoteStack.id' > Envoyer - +
-
- -
+
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 b7eb966c..eb2e2951 100644 --- a/src/app/pages/voting/voting-summary/voting-summary.component.html +++ b/src/app/pages/voting/voting-summary/voting-summary.component.html @@ -6,23 +6,33 @@ {{preferred}}
-
- -
-
+ + + + + + + + + + + + + +
+ Pseudo + + + {{choice.text}} +
{{voteStack.pseudo}} - -
-
-
- {{v.id}} - {{v.answer}} -
-
-
- - +
+ + + + {{voteStack.votes[v].value}} + +
diff --git a/src/app/pages/voting/voting-summary/voting-summary.component.scss b/src/app/pages/voting/voting-summary/voting-summary.component.scss index bd79cf58..f549a110 100644 --- a/src/app/pages/voting/voting-summary/voting-summary.component.scss +++ b/src/app/pages/voting/voting-summary/voting-summary.component.scss @@ -6,3 +6,12 @@ font-weight: 700; font-size: 1.5em; } + +thead { + font-size: 1.25em; + font-weight: 700; +} + +tbody { + text-align: right; +} 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 3e2ff185..60d73082 100644 --- a/src/app/pages/voting/voting-summary/voting-summary.component.ts +++ b/src/app/pages/voting/voting-summary/voting-summary.component.ts @@ -11,6 +11,8 @@ 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; @@ -22,43 +24,18 @@ export class VotingSummaryComponent implements OnInit { this.computePreferred(); } + getKeys(obj) { + return Object.keys(obj) + } + /** * find the most "yes" */ computePreferred() { - let maximumYesCount = 0; - let choice_id_max = 0; - let winners_id = []; this.pollconfig.stacks.forEach(stack => { - - stack.votes.map(vote => { - let choice_id = vote.choice_id; - let answer = vote.text; - if (!this.counters["choice_" + choice_id]) { - this.counters["choice_" + choice_id] = { - yes: 0, - maybe: 0, - no: 0, - } - } - this.counters["choice_" + choice_id][answer]++; - if (this.counters["choice_" + choice_id]['yes'] > maximumYesCount) { - choice_id_max = choice_id; - } - }) - - // find the favourite }); - console.log('choice_id_max', choice_id_max); - console.log(' this.pollconfig.choices', this.pollconfig.choices); - let choiceTitleFound = this.pollconfig.choices.find(elem => { - console.log('elem', elem); - return elem.id == choice_id_max - }); - this.preferred = choiceTitleFound.text; - console.log('choiceTitleFound', choiceTitleFound) }