Permalink
Browse files

Cap nomination counts at required nomination number

  • Loading branch information...
kochman committed Mar 29, 2017
1 parent de05722 commit 7737229f4cc9f756d990952897917c0630b38be3
@@ -38,7 +38,8 @@ app.controller('CandidateController', ['$scope', '$route', '$routeParams', '$sho
office_name: responses[0].data[i].office_name,
nominations: responses[0].data[i].nominations,
overridden: responses[0].data[i].nominations > 0,
- office_nominations_required: responses[0].data[i].office_nominations_required
+ office_nominations_required: responses[0].data[i].office_nominations_required,
+ nominations_capped: 0
});
}
@@ -66,6 +67,15 @@ app.controller('CandidateController', ['$scope', '$route', '$routeParams', '$sho
$scope.candidate.offices.forEach(function (o_elem) {
if(n_elem.office_id === o_elem.office_id && !o_elem.overridden) {
o_elem.nominations = n_elem.nominations;
+
+ // cap displayed nominations count at the nomination threshold
+ if (n_elem.nominations > o_elem.office_nominations_required) {
+ console.log('first');
+ o_elem.nominations_capped = o_elem.office_nominations_required;
+ console.log(o_elem.nominations_capped);
+ } else {
+ o_elem.nominations_capped = n_elem.nominations;
+ }
}
});
});
@@ -86,6 +86,13 @@ app.controller('OfficesController', ['$scope', '$route', '$routeParams', '$locat
console.log(n_elem.rcs_id + ", " + c_elem.rcsId + ", " + c_elem.overridden);
if(n_elem.rcs_id === c_elem.rcsId && !c_elem.overridden) {
c_elem.nominations = n_elem.nominations;
+
+ // cap displayed nominations count at the nomination threshold
+ if (c_elem.nominations > o_elem.nominationsRequired) {
+ c_elem.nominations_capped = o_elem.nominationsRequired;
+ } else {
+ c_elem.nominations_capped = c_elem.nominations;
+ }
}
});
}
@@ -73,28 +73,28 @@ <h4 class="text-center text-muted" style="margin-top:5px">
<h3>
Nominations
<span class="text-muted pull-right" ng-if="candidate.offices.length === 1">
- {{candidate.offices[0].nominations}}/{{candidate.office_nominations_required}}
+ {{candidate.offices[0].nominations_capped}}/{{candidate.office_nominations_required}}
</span>
</h3>
<div class="progress" ng-if="candidate.offices.length === 1">
- <div class="progress-bar" role="progressbar" aria-valuenow="{{candidate.offices[0].nominations}}" aria-valuemin="0"
+ <div class="progress-bar" role="progressbar" aria-valuenow="{{candidate.offices[0].nominations_capped}}" aria-valuemin="0"
aria-valuemax="{{candidate.office_nominations_required}}"
- ng-class="{'progress-bar-success': candidate.offices[0].nominations >= candidate.office_nominations_required}"
- ng-style="{'width': nominationPercentage(candidate.offices[0].nominations, candidate.office_nominations_required)}">
+ ng-class="{'progress-bar-success': candidate.offices[0].nominations_capped >= candidate.office_nominations_required}"
+ ng-style="{'width': nominationPercentage(candidate.offices[0].nominations_capped, candidate.office_nominations_required)}">
</div>
</div>
<h4 ng-if="candidate.offices.length > 1" ng-repeat-start="o in candidate.offices">
{{o.office_name}}
<span class="text-muted pull-right">
- {{o.nominations}}/{{o.office_nominations_required}}
+ {{o.nominations_capped}}/{{o.office_nominations_required}}
</span>
</h4>
<div class="progress" ng-if="candidate.offices.length > 1" ng-repeat-end>
- <div class="progress-bar" role="progressbar" aria-valuenow="{{o.nominations}}" aria-valuemin="0"
+ <div class="progress-bar" role="progressbar" aria-valuenow="{{o.nominations_capped}}" aria-valuemin="0"
aria-valuemax="{{o.office_nominations_required}}"
ng-class="{'progress-bar-success': o.nominations >= o.office_nominations_required}"
- ng-style="{'width': nominationPercentage(o.nominations, o.office_nominations_required)}">
+ ng-style="{'width': nominationPercentage(o.nominations_capped, o.office_nominations_required)}">
</div>
</div>
@@ -78,17 +78,17 @@ <h5><a ng-href="mailto:{{c.rcsId}}@rpi.edu">
nominations required</h5>
<div class="progress text-center" ng-if="o.nominationsRequired > 0">
- <span ng-if="c.nominations/o.nominationsRequired < .33"
- ng-bind="c.nominations + '/' + o.nominationsRequired"></span>
- <span ng-if="c.nominations === undefined && o.nominationsRequired !== undefined"
+ <span ng-if="c.nominations_capped/o.nominationsRequired < .33"
+ ng-bind="c.nominations_capped + '/' + o.nominationsRequired"></span>
+ <span ng-if="c.nominations_capped === undefined && o.nominationsRequired !== undefined"
ng-bind="'0/' + o.nominationsRequired"></span>
- <div class="progress-bar" role="progressbar" aria-valuenow="{{c.nominations}}"
+ <div class="progress-bar" role="progressbar" aria-valuenow="{{c.nominations_capped}}"
aria-valuemin="0" aria-valuemax="{{o.nominationsRequired}}" ng-if="o.nominationsRequired > 0"
- ng-class="{'progress-bar-success': c.nominations >= o.nominationsRequired}"
- ng-style="{'width': nominationPercentage(c.nominations, o.nominationsRequired)}">
- <span ng-if="c.nominations/o.nominationsRequired >= .33"
- ng-bind="c.nominations + '/' + o.nominationsRequired"></span>
+ ng-class="{'progress-bar-success': c.nominations_capped >= o.nominationsRequired}"
+ ng-style="{'width': nominationPercentage(c.nominations_capped, o.nominationsRequired)}">
+ <span ng-if="c.nominations_capped/o.nominationsRequired >= .33"
+ ng-bind="c.nominations_capped + '/' + o.nominationsRequired"></span>
</div>
</div>
</div>

0 comments on commit 7737229

Please sign in to comment.