-
Notifications
You must be signed in to change notification settings - Fork 2
/
resultado_votacao.html
132 lines (113 loc) · 6.38 KB
/
resultado_votacao.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<!DOCTYPE html>
<html ng-app="voteResultApp">
<head>
<meta charset="UTF-8">
<title>ITDP BRT Map - Resultado da Votação</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>
<script src="https://cdn.firebase.com/js/client/2.2.4/firebase.js"></script>
<script src="https://cdn.firebase.com/libs/angularfire/1.1.1/angularfire.min.js"></script>
<script src="js/estudo.js"></script>
<style type="text/css">
.sortorder:after {
content: '\25b2';
}
.sortorder.reverse:after {
content: '\25bc';
}
</style>
</head>
<body ng-controller="VoteResultCtrl">
<table class="table table-hover">
<tr>
<th><a href="" ng-click="order('voteCode')">Código</a> <span class="sortorder" ng-show="predicate === 'voteCode'" ng-class="{reverse:reverse}"></span></th>
<th><a href="" ng-click="order('votePlace')">Localização</a> <span class="sortorder" ng-show="predicate === 'votePlace'" ng-class="{reverse:reverse}"></span></th>
<th><a href="" ng-click="order('voteCorridor')">Corredor</a> <span class="sortorder" ng-show="predicate === 'voteCorridor'" ng-class="{reverse:reverse}"></span></th>
<th><a href="" ng-click="order('voteCategory')">Categoria</a> <span class="sortorder" ng-show="predicate === 'voteCategory'" ng-class="{reverse:reverse}"></span></th>
<th><a href="" ng-click="order('voteLevel')">Nível</a> <span class="sortorder" ng-show="predicate === 'voteLevel'" ng-class="{reverse:reverse}"></span></th>
<th><a href="" ng-click="order('voteName')">Nome</a> <span class="sortorder" ng-show="predicate === 'voteName'" ng-class="{reverse:reverse}"></span></th>
<th class="text-center" style="width: 50px"><span class="glyphicon glyphicon-star"></span></th>
<th class="text-center" style="width: 50px"><span class="glyphicon glyphicon-star"></span><span class="glyphicon glyphicon-star"></span></th>
<th class="text-center" style="width: 50px"><span class="glyphicon glyphicon-star"></span><span class="glyphicon glyphicon-star"></span><span class="glyphicon glyphicon-star"></span></th>
<th class="text-center" style="width: 70px"><span class="glyphicon glyphicon-star"></span><span class="glyphicon glyphicon-star"></span><span class="glyphicon glyphicon-star"></span><span class="glyphicon glyphicon-star"></span></th>
<th class="text-center" style="width: 70px"><span class="glyphicon glyphicon-star"></span><span class="glyphicon glyphicon-star"></span><span class="glyphicon glyphicon-star"></span><span class="glyphicon glyphicon-star"></span><span class="glyphicon glyphicon-star"></span></th>
<th><a href="" ng-click="order('total')">Total de Votos</a> <span class="sortorder" ng-show="predicate === 'total'" ng-class="{reverse:reverse}"></span></th>
<th><a href="" ng-click="order('average')">Média</a> <span class="sortorder" ng-show="predicate === 'average'" ng-class="{reverse:reverse}"></span></th>
<th style="text-align: center"><a href="" ng-click="order('weight')">Soma das <span class="glyphicon glyphicon-star"></span></a> <span class="sortorder" ng-show="predicate === 'weight'" ng-class="{reverse:reverse}"></span></th>
</tr>
<tr ng-repeat="vote in voteArray | orderBy:predicate:reverse">
<td>{{vote.voteCode}}</td>
<td>{{vote.votePlace}}</td>
<td>{{vote.voteCorridor}}</td>
<td>{{vote.voteCategory}}</td>
<td>{{vote.voteLevel}}</td>
<td>{{vote.voteName}}</td>
<td class="text-center"><span ng-if="vote['1']">{{vote['1']}}</span><span ng-if="!vote['1']">0</span></td>
<td class="text-center"><span ng-if="vote['2']">{{vote['2']}}</span><span ng-if="!vote['2']">0</span></td>
<td class="text-center"><span ng-if="vote['3']">{{vote['3']}}</span><span ng-if="!vote['3']">0</span></td>
<td class="text-center"><span ng-if="vote['4']">{{vote['4']}}</span><span ng-if="!vote['4']">0</span></td>
<td class="text-center"><span ng-if="vote['5']">{{vote['5']}}</span><span ng-if="!vote['5']">0</span></td>
<td class="text-center">{{vote.total}}</td>
<td class="text-center">{{vote.average | number:2}}</td>
<td class="text-center">{{vote.weight}}</td>
</tr>
</table>
<script>
var app = angular.module("voteResultApp", ["firebase"]);
app.controller("VoteResultCtrl", function($scope, $firebaseArray) {
var ref = new Firebase("https://itdp-brt-map.firebaseio.com/");
var obj = $firebaseArray(ref);
obj.$loaded().then(function(){
$scope.voteArray = obj;
for(var i=0, l=$scope.voteArray.length; i<l; i++){
var _study = study($scope.voteArray[i].$id);
var _level = _study.properties.Level;
var _levelStr;
var _total = 0;
var _weight = 0;
var _avg;
if(_level == 'low')
_levelStr = 'Baixo';
else if(_level == 'mid')
_levelStr = 'Médio';
else if(_level == 'high')
_levelStr = 'Alto';
var _v1 = $scope.voteArray[i]['1'] || 0,
_v2 = $scope.voteArray[i]['2'] || 0,
_v3 = $scope.voteArray[i]['3'] || 0,
_v4 = $scope.voteArray[i]['4'] || 0,
_v5 = $scope.voteArray[i]['5'] || 0;
_total = _v1 + _v2 + _v3 + _v4 + _v5;
_weight = _v1*1 + _v2*2 + _v3*3 + _v4*4 + _v5*5;
_avg = _weight / _total;
$scope.voteArray[i].voteCode = _study.properties.VoteCode;
$scope.voteArray[i].voteName = _study.properties.Name.replace(/ /gi, ' ');
$scope.voteArray[i].voteCorridor = _study.properties.Corridor;
$scope.voteArray[i].voteCategory = _study.properties.Category;
$scope.voteArray[i].votePlace = _study.properties.Place;
$scope.voteArray[i].voteLevel = _levelStr;
$scope.voteArray[i].total = _total;
$scope.voteArray[i].average = _avg;
$scope.voteArray[i].weight = _weight;
}
console.log($scope.voteArray);
});
var study = function(code){
var strStudyArr = code.substr(0,2) + '_' + code.substr(2,2) + '_' + code.substr(4,2);
var studyArr = window[strStudyArr];
var studyName;
for(var i=0, l=studyArr.length; i<l; i++){
if(code === studyArr[i].properties.VoteCode){
return studyArr[i];
}
}
return null;
};
$scope.order = function(predicate) {
$scope.reverse = ($scope.predicate === predicate) ? !$scope.reverse : false;
$scope.predicate = predicate;
};
});
</script>
</body>
</html>