Commit 8f7ca864f5ddba9e4f621cb92ac48d1d3f01a17d
1 parent
ce47251c
Exists in
master
and in
8 other branches
Persist filter param at inicio page
Showing
2 changed files
with
35 additions
and
15 deletions
Show diff stats
src/app/pages/inicio/inicio.controller.js
| ... | ... | @@ -33,14 +33,18 @@ |
| 33 | 33 | vm.query = null; |
| 34 | 34 | vm.search = vm.$location.search(); |
| 35 | 35 | |
| 36 | - if(vm.search && vm.search.tema){ | |
| 36 | + if (vm.search.tema) { | |
| 37 | 37 | vm._filtredByThemeSlug = vm.search.tema; |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | - if(vm.search && vm.search.filtro){ | |
| 40 | + if (vm.search.filtro) { | |
| 41 | 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 | 48 | vm.error = null; |
| 45 | 49 | |
| 46 | 50 | vm.loadData(); |
| ... | ... | @@ -50,7 +54,6 @@ |
| 50 | 54 | InicioPageController.prototype.loadData = function() { |
| 51 | 55 | var vm = this; |
| 52 | 56 | |
| 53 | - | |
| 54 | 57 | // Load main content |
| 55 | 58 | vm.loading = true; |
| 56 | 59 | vm.DialogaService.getHome(function(data) { |
| ... | ... | @@ -85,6 +88,8 @@ |
| 85 | 88 | vm.DialogaService.getThemes(function(data) { |
| 86 | 89 | vm.themes = data; |
| 87 | 90 | vm.loadingThemes = false; |
| 91 | + | |
| 92 | + vm.filter(); | |
| 88 | 93 | }, function(error) { |
| 89 | 94 | vm.$log.error('Error on getThemes.', error); |
| 90 | 95 | }); |
| ... | ... | @@ -95,31 +100,37 @@ |
| 95 | 100 | vm.programs = vm.article.children; |
| 96 | 101 | vm.filtredPrograms = data.articles; |
| 97 | 102 | vm.loadingPrograms = false; |
| 103 | + | |
| 104 | + vm.filter(); | |
| 98 | 105 | }, function(error) { |
| 99 | 106 | vm.$log.error('Error on getPrograms.', error); |
| 100 | 107 | }); |
| 101 | - | |
| 102 | - vm.filter(); | |
| 103 | 108 | } |
| 104 | 109 | }; |
| 105 | 110 | |
| 106 | 111 | InicioPageController.prototype.attachListeners = function() { |
| 107 | 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 | 115 | vm.selectedTheme = selectedCategory; |
| 111 | 116 | }); |
| 112 | 117 | |
| 113 | 118 | vm.$scope.$watch('pageInicio.selectedTheme', function(newValue/*, oldValue*/) { |
| 114 | 119 | vm.search.tema = newValue ? newValue.slug : null; |
| 115 | 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 | 127 | vm.$scope.$watch('pageInicio.query', function(newValue/*, oldValue*/) { |
| 120 | 128 | vm.search.filtro = newValue ? newValue : null; |
| 121 | 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 | 155 | InicioPageController.prototype.filter = function() { |
| 145 | 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 | 163 | if (vm._filtredByThemeSlug) { |
| 149 | 164 | var slug = vm._filtredByThemeSlug; |
| 150 | 165 | |
| 151 | - vm.DialogaService.getThemeBySlug(slug, function(theme){ | |
| 166 | + vm.DialogaService.getThemeBySlug(slug, function(theme) { | |
| 152 | 167 | vm.selectedTheme = theme; |
| 153 | - }, function(error){ | |
| 168 | + }, function(error) { | |
| 154 | 169 | vm.$log.error('Error when try to "getThemeBySlug"', error); |
| 155 | 170 | }); |
| 156 | 171 | } |
| ... | ... | @@ -158,6 +173,11 @@ |
| 158 | 173 | if (vm._filtredByQuery) { |
| 159 | 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 | 183 | InicioPageController.prototype.showAllPrograms = function($event) { |
| ... | ... | @@ -179,7 +199,7 @@ |
| 179 | 199 | InicioPageController.prototype.getFiltredPrograms = function() { |
| 180 | 200 | var vm = this; |
| 181 | 201 | |
| 182 | - if(!vm.programs){ | |
| 202 | + if (!vm.programs) { | |
| 183 | 203 | vm.$log.warn('No programs loaded yet. Abort.'); |
| 184 | 204 | return null; |
| 185 | 205 | } |
| ... | ... | @@ -199,7 +219,7 @@ |
| 199 | 219 | output = filter(output, query, false); |
| 200 | 220 | } |
| 201 | 221 | |
| 202 | - if(!query && !selectedTheme){ | |
| 222 | + if (!query && !selectedTheme) { | |
| 203 | 223 | output = _balanceByCategory(output); |
| 204 | 224 | } |
| 205 | 225 | ... | ... |
src/app/pages/inicio/inicio.html
| ... | ... | @@ -80,7 +80,7 @@ |
| 80 | 80 | <br/> |
| 81 | 81 | </div> |
| 82 | 82 | </div> |
| 83 | - <div ng-if="pageInicio.themes"> | |
| 83 | + <div ng-if="pageInicio.themes && !vm.loadingFilter"> | |
| 84 | 84 | <category-list categories="pageInicio.themes" selected-category="pageInicio.selectedTheme"></category-list> |
| 85 | 85 | </div> |
| 86 | 86 | <div ng-if="!pageInicio.themes && pageInicio.loadingThemes"> |
| ... | ... | @@ -123,7 +123,7 @@ |
| 123 | 123 | </div> |
| 124 | 124 | |
| 125 | 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 | 127 | <article-grid articles="pageInicio.filtredPrograms"></article-grid> |
| 128 | 128 | </div> |
| 129 | 129 | <div ng-if="!pageInicio.programs && pageInicio.loadingPrograms"> | ... | ... |