From c122d66fb64a8cb76dcaf59293f76794b65e5f90 Mon Sep 17 00:00:00 2001 From: Nicolas Constant Date: Wed, 5 Jun 2019 00:06:29 -0400 Subject: [PATCH] displaying result percentages #93 --- .../stream/status/poll/poll.component.html | 32 ++++++++++++------- .../stream/status/poll/poll.component.scss | 21 ++++++++++++ .../stream/status/poll/poll.component.ts | 30 +++++++++++------ 3 files changed, 61 insertions(+), 22 deletions(-) diff --git a/src/app/components/stream/status/poll/poll.component.html b/src/app/components/stream/status/poll/poll.component.html index 02892c5d..059cbeff 100644 --- a/src/app/components/stream/status/poll/poll.component.html +++ b/src/app/components/stream/status/poll/poll.component.html @@ -1,17 +1,25 @@
-
- - - +
+
+ +
+
+
+
+
+ {{ o.percentage }}% {{o.title}} +
+
- -
{{poll.votes_count}} votes - X days left
+ + refresh +
· {{poll.votes_count}} votes · X days left
\ No newline at end of file diff --git a/src/app/components/stream/status/poll/poll.component.scss b/src/app/components/stream/status/poll/poll.component.scss index 6c6eb46f..1b7bde85 100644 --- a/src/app/components/stream/status/poll/poll.component.scss +++ b/src/app/components/stream/status/poll/poll.component.scss @@ -4,6 +4,8 @@ @import "buttons"; .poll { + color: white; + color: rgb(228, 228, 228); &__btn-vote { margin: 0 10px 0 0; @@ -24,6 +26,11 @@ margin-top: 10px; } + &__refresh { + font-size: 0.8em; + color: rgb(101, 121, 160); + } + &__container { display: block; position: relative; @@ -108,6 +115,20 @@ background: white; } } + + &__result { + margin: 0 0 5px 5px; + + &--percentage { + // font-weight: bold; + // font-weight: 600; + // font-style: italic; + color: rgb(228, 228, 228); + color: white; + display: inline; + margin-right: 10px; + } + } } .noselect { diff --git a/src/app/components/stream/status/poll/poll.component.ts b/src/app/components/stream/status/poll/poll.component.ts index 1016ece8..8e19d3f2 100644 --- a/src/app/components/stream/status/poll/poll.component.ts +++ b/src/app/components/stream/status/poll/poll.component.ts @@ -11,7 +11,7 @@ import { NotificationService } from '../../../../services/notification.service'; styleUrls: ['./poll.component.scss'] }) export class PollComponent implements OnInit { - pollName: string; + pollName: string; choiceType: string; private pollSelection: number[] = []; @@ -26,18 +26,18 @@ export class PollComponent implements OnInit { ngOnInit() { this.pollName = this.poll.id; - + //this.poll.multiple = true; - if(this.poll.multiple){ + if (this.poll.multiple) { this.choiceType = 'checkbox'; } else { this.choiceType = 'radio'; } let i = 0; - for(let opt of this.poll.options){ - let optWrapper = new PollOptionWrapper(i, opt); + for (let opt of this.poll.options) { + let optWrapper = new PollOptionWrapper(i, opt, this.poll.votes_count); this.options.push(optWrapper); i++; } @@ -56,10 +56,10 @@ export class PollComponent implements OnInit { return false; } - onSelectionChange(entry: PollOptionWrapper){ + onSelectionChange(entry: PollOptionWrapper) { let index = entry.id; - if(this.poll.multiple){ - if(this.pollSelection.includes(index)){ + if (this.poll.multiple) { + if (this.pollSelection.includes(index)) { this.pollSelection = this.pollSelection.filter(x => x !== index); } else { this.pollSelection.push(index); @@ -73,13 +73,23 @@ export class PollComponent implements OnInit { } class PollOptionWrapper implements PollOption { - constructor(index: number, option: PollOption){ + constructor(index: number, option: PollOption, totalVotes: number) { this.id = index; this.title = option.title; this.votes_count = option.votes_count; + console.log(this.votes_count); + console.log(totalVotes); + console.log(this.votes_count / totalVotes); + console.log( (this.votes_count / totalVotes) * 100); + if (totalVotes === 0) { + this.percentage = '0'; + } else { + this.percentage = ((this.votes_count / totalVotes) * 100).toFixed(0); + } } id: number; - title: string; + title: string; votes_count: number; + percentage: string; } \ No newline at end of file