Commit 511ec3223b76c8baae06c4a9ef82c013f74148b5

Authored by Leonardo Merlin
2 parents f8d90a9d 7449c6db

Merge branch 'merlin' of gitlab.com:participa/discussion-app into merlin

gulp/images.js
... ... @@ -18,7 +18,8 @@ gulp.task('sprites', function () {
18 18 return sprity.src({
19 19 src: src,
20 20 style: 'sprite.css',
21   - cssPath: '../assets/images/icons/'
  21 + cssPath: '../assets/images/icons/',
  22 + cachebuster: true
22 23 })
23 24 .pipe(gulpif('*.png', gulp.dest(destImg), gulp.dest(destCss)));
24 25 });
... ...
src/app/components/dialoga-service/dialoga.service.js
... ... @@ -25,6 +25,8 @@
25 25 extendedService.getQuestions = getQuestions;
26 26 extendedService.searchPrograms = searchPrograms;
27 27 extendedService.searchProposals = searchProposals;
  28 + extendedService.filterProposalsByCategorySlug = filterProposalsByCategorySlug;
  29 + extendedService.filterProposalsByProgramId = filterProposalsByProgramId;
28 30  
29 31 var CACHE = {};
30 32  
... ... @@ -230,6 +232,52 @@
230 232 ArticleService.searchProposals(params, cbSuccess, cbError);
231 233 }
232 234  
  235 + function filterProposalsByCategorySlug (input, categorySlug) {
  236 +
  237 + if(!angular.isArray(input)){
  238 + $log.error('Input is not a Array.');
  239 + return [];
  240 + }
  241 +
  242 + // Use native array filter
  243 + return input.filter(function(value/*, index, arr*/) {
  244 +
  245 + if (!value.parent) {
  246 + $log.warn('Proposal without a parent.');
  247 + return false;
  248 + }
  249 +
  250 + if (!value.parent.categories || value.parent.categories.length === 0) {
  251 + $log.warn('Proposal parent has no categories.');
  252 + return false;
  253 + }
  254 +
  255 + // match?!
  256 + return value.parent.categories[0].slug === categorySlug;
  257 + });
  258 + }
  259 +
  260 + function filterProposalsByProgramId (input, program_id) {
  261 + var vm = this;
  262 +
  263 + if(!angular.isArray(input)){
  264 + $log.error('Input is not a Array.');
  265 + return [];
  266 + }
  267 +
  268 + // Use native array filter
  269 + return input.filter(function(value) {
  270 + if (!value.parent || !value.parent.id) {
  271 + $log.warn('Proposal has no parent.');
  272 +
  273 + return false;
  274 + }
  275 +
  276 + // match?!
  277 + return value.parent.id === program_id;
  278 + });
  279 + }
  280 +
233 281 function _pipeHandleYoutube (data) {
234 282 var abstract = data.article.abstract;
235 283  
... ...
src/app/pages/inicio/inicio.controller.js
... ... @@ -276,7 +276,7 @@
276 276 }
277 277  
278 278 return out;
279   - }
  279 + };
280 280  
281 281 function _balanceByCategory (input) {
282 282 var result = [];
... ...
src/app/pages/programas/programas.controller.js
... ... @@ -212,7 +212,7 @@
212 212 }
213 213  
214 214 return out;
215   - }
  215 + };
216 216  
217 217 ProgramasPageController.prototype._balanceByCategory = function (input) {
218 218 var vm = this;
... ... @@ -276,5 +276,5 @@
276 276 }
277 277  
278 278 return result;
279   - }
  279 + };
280 280 })();
... ...
src/app/pages/propostas/propostas.controller.js
... ... @@ -22,7 +22,7 @@
22 22 $log.debug('PropostasPageController');
23 23 }
24 24  
25   - PropostasPageController.prototype.init = function () {
  25 + PropostasPageController.prototype.init = function() {
26 26 var vm = this;
27 27  
28 28 vm.themes = null;
... ... @@ -38,7 +38,7 @@
38 38 vm.error = null;
39 39 };
40 40  
41   - PropostasPageController.prototype.loadData = function () {
  41 + PropostasPageController.prototype.loadData = function() {
42 42 var vm = this;
43 43  
44 44 vm.loading = true;
... ... @@ -50,15 +50,15 @@
50 50  
51 51 // 1. Load themes
52 52 vm.loadingThemes = true;
53   - vm.DialogaService.getThemes(function(themes){
  53 + vm.DialogaService.getThemes(function(themes) {
54 54 vm.themes = themes;
55 55 vm.loadingThemes = false;
56 56 vm.loading = false;
57 57  
58   - vm.loadProposals(function (){
  58 + vm.loadProposals(function() {
59 59 vm.attachListeners();
60 60 });
61   - }, function (error) {
  61 + }, function(error) {
62 62 vm.error = error;
63 63 vm.$log.error(error);
64 64 vm.loadingThemes = false;
... ... @@ -66,21 +66,21 @@
66 66 });
67 67 };
68 68  
69   - PropostasPageController.prototype.loadProposals = function (cb) {
  69 + PropostasPageController.prototype.loadProposals = function(cb) {
70 70 var vm = this;
71 71  
72 72 // load Proposals
73 73 vm.loadingProposals = true;
74   - vm.DialogaService.getProposals({}, function(data){
  74 + vm.DialogaService.getProposals({}, function(data) {
75 75 vm.proposals = data.articles;
76 76 vm.filtredProposals = vm.proposals;
77 77 vm.loadingProposals = false;
78 78 vm.loading = false;
79 79  
80   - if(cb){
  80 + if (cb) {
81 81 cb();
82 82 }
83   - }, function (error) {
  83 + }, function(error) {
84 84 vm.error = error;
85 85 vm.$log.error(error);
86 86 vm.loadingProposals = false;
... ... @@ -91,21 +91,21 @@
91 91 PropostasPageController.prototype.attachListeners = function() {
92 92 var vm = this;
93 93  
94   - vm.$scope.$on('change-selectedCategory', function (event, selectedCategory) {
  94 + vm.$scope.$on('change-selectedCategory', function(event, selectedCategory) {
95 95 vm.selectedTheme = selectedCategory;
96 96 });
97 97  
98   - vm.$scope.$watch('pagePropostas.selectedTheme', function(newValue, oldValue) {
  98 + vm.$scope.$watch('pagePropostas.selectedTheme', function(newValue/*, oldValue*/) {
99 99 vm.search.tema = newValue ? newValue.slug : null;
100 100 vm.$location.search('tema', vm.search.tema);
101 101 vm.filtredProposals = vm.getFiltredProposals();
102 102 });
103 103  
104   - vm.$scope.$on('change-selectedTopic', function (event, selectedTopic) {
  104 + vm.$scope.$on('change-selectedTopic', function(event, selectedTopic) {
105 105 vm.selectedProgram = selectedTopic;
106 106 });
107 107  
108   - vm.$scope.$watch('pagePropostas.selectedProgram', function(newValue, oldValue) {
  108 + vm.$scope.$watch('pagePropostas.selectedProgram', function(newValue/*, oldValue*/) {
109 109 vm.search.programa = newValue ? newValue.slug : null;
110 110 vm.$location.search('programa', vm.search.programa);
111 111 vm.filtredProposals = vm.getFiltredProposals();
... ... @@ -128,7 +128,7 @@
128 128 PropostasPageController.prototype.getFiltredProposals = function() {
129 129 var vm = this;
130 130  
131   - if(!vm.proposals){
  131 + if (!vm.proposals) {
132 132 vm.$log.info('No proposals loaded yet. Abort.');
133 133 return null;
134 134 }
... ... @@ -142,64 +142,18 @@
142 142 var filter = vm.$filter('filter');
143 143  
144 144 if (selectedTheme) {
145   - output = vm._filterByCategory(output, selectedTheme);
  145 + output = vm.DialogaService.filterProposalsByCategorySlug(output, selectedTheme.slug);
146 146 }
147 147  
148 148 if (selectedProgram) {
149   - output = vm._filterByProgram(output, selectedProgram);
  149 + output = vm.DialogaService.filterProposalsByProgramId(output, selectedProgram.id);
150 150 }
151 151  
152 152 if (query) {
153 153 output = filter(output, query, false);
154 154 }
155 155  
156   - // if(!query && !selectedTheme && vm._showAllFlag){
157   - // output = _balanceByCategory(output);
158   - // }
159   -
160 156 return output;
161 157 };
162 158  
163   - PropostasPageController.prototype._filterByCategory = function (input, category) {
164   - var vm = this;
165   -
166   - input = input || [];
167   -
168   - if (!category) {
169   - // no filter
170   - return input;
171   - }
172   -
173   - var out = [];
174   - for (var i = 0; i < input.length; i++) {
175   - var proposal = input[i];
176   - if (proposal.parent.categories[0].slug === category.slug) {
177   - out.push(proposal);
178   - }
179   - }
180   -
181   - return out;
182   - }
183   -
184   - PropostasPageController.prototype._filterByProgram = function (input, program) {
185   - var vm = this;
186   -
187   - input = input || [];
188   -
189   - if (!program) {
190   - // no filter
191   - return input;
192   - }
193   -
194   - var out = [];
195   - for (var i = 0; i < input.length; i++) {
196   - var proposal = input[i];
197   - if (proposal.parent.id === program.id) {
198   - out.push(proposal);
199   - }
200   - }
201   -
202   - return out;
203   - }
204   -
205 159 })();
... ...