Commit 8f7ca864f5ddba9e4f621cb92ac48d1d3f01a17d

Authored by Leonardo Merlin
1 parent ce47251c

Persist filter param at inicio page

src/app/pages/inicio/inicio.controller.js
@@ -33,14 +33,18 @@ @@ -33,14 +33,18 @@
33 vm.query = null; 33 vm.query = null;
34 vm.search = vm.$location.search(); 34 vm.search = vm.$location.search();
35 35
36 - if(vm.search && vm.search.tema){ 36 + if (vm.search.tema) {
37 vm._filtredByThemeSlug = vm.search.tema; 37 vm._filtredByThemeSlug = vm.search.tema;
38 } 38 }
39 39
40 - if(vm.search && vm.search.filtro){ 40 + if (vm.search.filtro) {
41 vm._filtredByQuery = vm.search.filtro; 41 vm._filtredByQuery = vm.search.filtro;
42 } 42 }
43 43
  44 + if (vm.search.tema || vm.search.filtro) {
  45 + vm.loadingFilter = true;
  46 + }
  47 +
44 vm.error = null; 48 vm.error = null;
45 49
46 vm.loadData(); 50 vm.loadData();
@@ -50,7 +54,6 @@ @@ -50,7 +54,6 @@
50 InicioPageController.prototype.loadData = function() { 54 InicioPageController.prototype.loadData = function() {
51 var vm = this; 55 var vm = this;
52 56
53 -  
54 // Load main content 57 // Load main content
55 vm.loading = true; 58 vm.loading = true;
56 vm.DialogaService.getHome(function(data) { 59 vm.DialogaService.getHome(function(data) {
@@ -85,6 +88,8 @@ @@ -85,6 +88,8 @@
85 vm.DialogaService.getThemes(function(data) { 88 vm.DialogaService.getThemes(function(data) {
86 vm.themes = data; 89 vm.themes = data;
87 vm.loadingThemes = false; 90 vm.loadingThemes = false;
  91 +
  92 + vm.filter();
88 }, function(error) { 93 }, function(error) {
89 vm.$log.error('Error on getThemes.', error); 94 vm.$log.error('Error on getThemes.', error);
90 }); 95 });
@@ -95,31 +100,37 @@ @@ -95,31 +100,37 @@
95 vm.programs = vm.article.children; 100 vm.programs = vm.article.children;
96 vm.filtredPrograms = data.articles; 101 vm.filtredPrograms = data.articles;
97 vm.loadingPrograms = false; 102 vm.loadingPrograms = false;
  103 +
  104 + vm.filter();
98 }, function(error) { 105 }, function(error) {
99 vm.$log.error('Error on getPrograms.', error); 106 vm.$log.error('Error on getPrograms.', error);
100 }); 107 });
101 -  
102 - vm.filter();  
103 } 108 }
104 }; 109 };
105 110
106 InicioPageController.prototype.attachListeners = function() { 111 InicioPageController.prototype.attachListeners = function() {
107 var vm = this; 112 var vm = this;
108 113
109 - vm.$scope.$on('change-selectedCategory', function (event, selectedCategory) { 114 + vm.$scope.$on('change-selectedCategory', function(event, selectedCategory) {
110 vm.selectedTheme = selectedCategory; 115 vm.selectedTheme = selectedCategory;
111 }); 116 });
112 117
113 vm.$scope.$watch('pageInicio.selectedTheme', function(newValue/*, oldValue*/) { 118 vm.$scope.$watch('pageInicio.selectedTheme', function(newValue/*, oldValue*/) {
114 vm.search.tema = newValue ? newValue.slug : null; 119 vm.search.tema = newValue ? newValue.slug : null;
115 vm.$location.search('tema', vm.search.tema); 120 vm.$location.search('tema', vm.search.tema);
116 - vm.filtredPrograms = vm.getFiltredPrograms(); 121 +
  122 + if (!vm.loadingFilter) {
  123 + vm.filtredPrograms = vm.getFiltredPrograms();
  124 + }
117 }); 125 });
118 126
119 vm.$scope.$watch('pageInicio.query', function(newValue/*, oldValue*/) { 127 vm.$scope.$watch('pageInicio.query', function(newValue/*, oldValue*/) {
120 vm.search.filtro = newValue ? newValue : null; 128 vm.search.filtro = newValue ? newValue : null;
121 vm.$location.search('filtro', vm.search.filtro); 129 vm.$location.search('filtro', vm.search.filtro);
122 - vm.filtredPrograms = vm.getFiltredPrograms(); 130 +
  131 + if (!vm.loadingFilter) {
  132 + vm.filtredPrograms = vm.getFiltredPrograms();
  133 + }
123 }); 134 });
124 }; 135 };
125 136
@@ -144,13 +155,17 @@ @@ -144,13 +155,17 @@
144 InicioPageController.prototype.filter = function() { 155 InicioPageController.prototype.filter = function() {
145 var vm = this; 156 var vm = this;
146 157
147 - // if (vm.search && vm.search.tema) { 158 + if (vm.loadingThemes || vm.loadingPrograms) {
  159 + vm.$log.info('No programs or themes loaded yet. Abort.');
  160 + return;
  161 + }
  162 +
148 if (vm._filtredByThemeSlug) { 163 if (vm._filtredByThemeSlug) {
149 var slug = vm._filtredByThemeSlug; 164 var slug = vm._filtredByThemeSlug;
150 165
151 - vm.DialogaService.getThemeBySlug(slug, function(theme){ 166 + vm.DialogaService.getThemeBySlug(slug, function(theme) {
152 vm.selectedTheme = theme; 167 vm.selectedTheme = theme;
153 - }, function(error){ 168 + }, function(error) {
154 vm.$log.error('Error when try to "getThemeBySlug"', error); 169 vm.$log.error('Error when try to "getThemeBySlug"', error);
155 }); 170 });
156 } 171 }
@@ -158,6 +173,11 @@ @@ -158,6 +173,11 @@
158 if (vm._filtredByQuery) { 173 if (vm._filtredByQuery) {
159 vm.query = vm._filtredByQuery; 174 vm.query = vm._filtredByQuery;
160 } 175 }
  176 +
  177 + if (vm._filtredByThemeSlug || vm._filtredByQuery) {
  178 + vm.filtredPrograms = vm.getFiltredPrograms();
  179 + vm.loadingFilter = false;
  180 + }
161 }; 181 };
162 182
163 InicioPageController.prototype.showAllPrograms = function($event) { 183 InicioPageController.prototype.showAllPrograms = function($event) {
@@ -179,7 +199,7 @@ @@ -179,7 +199,7 @@
179 InicioPageController.prototype.getFiltredPrograms = function() { 199 InicioPageController.prototype.getFiltredPrograms = function() {
180 var vm = this; 200 var vm = this;
181 201
182 - if(!vm.programs){ 202 + if (!vm.programs) {
183 vm.$log.warn('No programs loaded yet. Abort.'); 203 vm.$log.warn('No programs loaded yet. Abort.');
184 return null; 204 return null;
185 } 205 }
@@ -199,7 +219,7 @@ @@ -199,7 +219,7 @@
199 output = filter(output, query, false); 219 output = filter(output, query, false);
200 } 220 }
201 221
202 - if(!query && !selectedTheme){ 222 + if (!query && !selectedTheme) {
203 output = _balanceByCategory(output); 223 output = _balanceByCategory(output);
204 } 224 }
205 225
src/app/pages/inicio/inicio.html
@@ -80,7 +80,7 @@ @@ -80,7 +80,7 @@
80 <br/> 80 <br/>
81 </div> 81 </div>
82 </div> 82 </div>
83 - <div ng-if="pageInicio.themes"> 83 + <div ng-if="pageInicio.themes && !vm.loadingFilter">
84 <category-list categories="pageInicio.themes" selected-category="pageInicio.selectedTheme"></category-list> 84 <category-list categories="pageInicio.themes" selected-category="pageInicio.selectedTheme"></category-list>
85 </div> 85 </div>
86 <div ng-if="!pageInicio.themes && pageInicio.loadingThemes"> 86 <div ng-if="!pageInicio.themes && pageInicio.loadingThemes">
@@ -123,7 +123,7 @@ @@ -123,7 +123,7 @@
123 </div> 123 </div>
124 124
125 <div class="row"> 125 <div class="row">
126 - <div class="col-sm-12" ng-if="pageInicio.programs"> 126 + <div class="col-sm-12" ng-if="pageInicio.filtredPrograms && !vm.loadingFilter">
127 <article-grid articles="pageInicio.filtredPrograms"></article-grid> 127 <article-grid articles="pageInicio.filtredPrograms"></article-grid>
128 </div> 128 </div>
129 <div ng-if="!pageInicio.programs && pageInicio.loadingPrograms"> 129 <div ng-if="!pageInicio.programs && pageInicio.loadingPrograms">