display a table of answers

This commit is contained in:
Baptiste Lemoine 2020-01-29 17:30:39 +01:00
parent 0369d934bd
commit 43ea524c26
5 changed files with 356 additions and 160 deletions

View File

@ -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": [

View File

@ -1,35 +1,38 @@
<div class="poll" >
<nav class='sections-nav' >
<ul >
<li >
<a href='#title' >
{{config.currentPoll.poll.title}}
</a >
</li >
<li >
<a href='#table' >
{{config.currentPoll.stacks.length}}
votes
</a >
</li >
<li >
<a href='#graph' >
Graphique
</a >
</li >
<li >
<a href='#comments' >
<i class='fa fa-comments' ></i >
<span
*ngIf='config.currentPoll && config.currentPoll.comments'
class='comments-count' >
{{config.currentPoll.comments.length}}
</span >
commentaires
</a >
</li >
</ul >
</nav >
<div id='table' >
<framadate-voting-summary ></framadate-voting-summary >
</div >
<!-- <nav class='sections-nav' >-->
<!-- <ul >-->
<!-- <li >-->
<!-- <a href='#title' >-->
<!-- {{config.currentPoll.poll.title}}-->
<!-- </a >-->
<!-- </li >-->
<!-- <li >-->
<!-- <a href='#table' >-->
<!-- {{config.currentPoll.stacks.length}}-->
<!-- votes-->
<!-- </a >-->
<!-- </li >-->
<!-- <li >-->
<!-- <a href='#graph' >-->
<!-- Graphique-->
<!-- </a >-->
<!-- </li >-->
<!-- <li >-->
<!-- <a href='#comments' >-->
<!-- <i class='fa fa-comments' ></i >-->
<!-- <span-->
<!-- *ngIf='config.currentPoll && config.currentPoll.comments'-->
<!-- class='comments-count' >-->
<!-- {{config.currentPoll.comments.length}}-->
<!-- </span >-->
<!-- commentaires-->
<!-- </a >-->
<!-- </li >-->
<!-- </ul >-->
<!-- </nav >-->
<div class='heading' >
<div class='col-xs-6' >
<h1 id='title' >{{config.currentPoll.poll.title}}</h1 >
@ -85,7 +88,7 @@
[ngClass]='{"btn--primary" : config.myTempVoteStack } '
*ngIf='!config.myVoteStack || !config.myVoteStack.id' >
<i class='fa fa-paper-plane' ></i > Envoyer
<!-- ( {{config.myTempVoteStack}} )-->
</button >
<button
class='btn btn--primary btn-block submit-votestack update'
@ -98,9 +101,7 @@
<!--<framadate-voting-graph ></framadate-voting-graph >-->
</div >
<div id='table' >
<!--<framadate-voting-summary ></framadate-voting-summary >-->
</div >
<div
class="comments"
id='comments' >

View File

@ -6,23 +6,33 @@
{{preferred}}
</span >
</div >
<div
class='line vote-stack'
*ngFor='let voteStack of pollconfig.stacks' >
<div class='vs' >
<div class='person' >
<table >
<thead >
<tr >
<td >
Pseudo
</td >
<td *ngFor='let choice of config.currentPoll.choices' >
<!-- {{choice.id}})-->
{{choice.text}}
</td >
</tr >
</thead >
<tbody >
<tr
class='votes-of-the-person'
*ngFor='let voteStack of pollconfig.stacks'
>
<td >
{{voteStack.pseudo}}
</div >
<div class='votes-of-the-person' >
<div
class='vote'
*ngFor='let v of voteStack.votes' >
<div class='id' >
{{v.id}}
{{v.answer}}
</div >
</div >
</div >
</div >
</div >
</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 >
</tbody >
</table >

View File

@ -6,3 +6,12 @@
font-weight: 700;
font-size: 1.5em;
}
thead {
font-size: 1.25em;
font-weight: 700;
}
tbody {
text-align: right;
}

View File

@ -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)
}