proposal-list.directive.js
3.44 KB
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
(function() {
'use strict';
angular
.module('dialoga')
.directive('proposalList', proposalList);
/** @ngInject */
function proposalList() {
/** @ngInject */
function ProposalListController(ArticleService, $state, $scope, $element, $timeout, $log) {
$log.debug('ProposalListController');
var vm = this;
vm.ArticleService = ArticleService;
vm.$state = $state;
vm.$scope = $scope;
vm.$element = $element;
vm.$timeout = $timeout;
vm.$log = $log;
vm.init();
vm.loadData();
}
ProposalListController.prototype.init = function () {
// initial values
var vm = this;
if(!vm.proposals){
throw { name: 'NotDefined', message: 'The attribute "proposals" is undefined.'};
}
if(!vm.per_page){
vm.per_page = 5;
}
vm.currentPageIndex = 0;
vm.proposalsPerPage = vm.getProposalsPerPage(0);
vm.proposalsLength = vm.proposals.length;
if ((vm.proposalsLength % vm.per_page) == 0) {
vm.pages = vm.proposalsLength / vm.per_page;
} else{
vm.pages = (vm.proposalsLength / vm.per_page) +1;
};
vm.arraypages = new Array(Math.ceil(vm.pages));
};
ProposalListController.prototype.loadData = function () {
// async values
var vm = this;
// requeue to wait until DOM be created
vm.$timeout(function(){
attachPopover.call(vm);
}, 1000);
};
ProposalListController.prototype.getProposalsPerPage = function (pageIndex) {
var vm = this;
var initialIndex = pageIndex * vm.per_page;
var finalIndex = initialIndex + vm.per_page;
return vm.proposals.slice(initialIndex, finalIndex);
};
ProposalListController.prototype.showPage = function (pageIndex) {
var vm = this;
if (pageIndex < 0) {
pageIndex = 0;
}
if (pageIndex > (vm.arraypages.length-1)) {
pageIndex = vm.arraypages.length-1;
}
vm.proposalsPerPage = vm.getProposalsPerPage(pageIndex);
vm.currentPageIndex = pageIndex;
};
ProposalListController.prototype.showContent = function (proposal) {
var vm = this;
vm.$state.go('programa-conteudo', {
slug: proposal.parent.slug,
proposal_id: proposal.id
}, {
location: true
});
}
function attachPopover(){
var vm = this;
vm.popover = angular.element(vm.$element.find('.btn-question'));
vm.popover.popover({
html: true,
placement: 'bottom',
animation: true,
title: 'Regra de posição das propostas',
content: '<p>É calculada pelo saldo de interações das propostas (curtidas - não curtidas) dividido pela diferença de exibições entre elas.</p><p>O objetivo dessa correção é compensar o saldo de interações e a diferença de exibições das propostas que não tiveram muitas oportunidades de visualização ou das propostas que tiveram mais oportunidades de visualização que a média.</p><p>Com essa correção, é possível comparar propostas que entraram em diferentes momentos, durante todo o período da consulta.</p>'
});
}
var directive = {
restrict: 'E',
templateUrl: 'app/components/proposal-list/proposal-list.html',
scope: {
proposals: '=',
per_page: '='
},
controller: ProposalListController,
controllerAs: 'vm',
bindToController: true
};
return directive;
}
})();