diff --git a/src/app/pages/inicio/inicio.controller.js b/src/app/pages/inicio/inicio.controller.js
index 4a9ba6c..beeafa9 100644
--- a/src/app/pages/inicio/inicio.controller.js
+++ b/src/app/pages/inicio/inicio.controller.js
@@ -33,14 +33,18 @@
vm.query = null;
vm.search = vm.$location.search();
- if(vm.search && vm.search.tema){
+ if (vm.search.tema) {
vm._filtredByThemeSlug = vm.search.tema;
}
- if(vm.search && vm.search.filtro){
+ if (vm.search.filtro) {
vm._filtredByQuery = vm.search.filtro;
}
+ if (vm.search.tema || vm.search.filtro) {
+ vm.loadingFilter = true;
+ }
+
vm.error = null;
vm.loadData();
@@ -50,7 +54,6 @@
InicioPageController.prototype.loadData = function() {
var vm = this;
-
// Load main content
vm.loading = true;
vm.DialogaService.getHome(function(data) {
@@ -85,6 +88,8 @@
vm.DialogaService.getThemes(function(data) {
vm.themes = data;
vm.loadingThemes = false;
+
+ vm.filter();
}, function(error) {
vm.$log.error('Error on getThemes.', error);
});
@@ -95,31 +100,37 @@
vm.programs = vm.article.children;
vm.filtredPrograms = data.articles;
vm.loadingPrograms = false;
+
+ vm.filter();
}, function(error) {
vm.$log.error('Error on getPrograms.', error);
});
-
- vm.filter();
}
};
InicioPageController.prototype.attachListeners = function() {
var vm = this;
- vm.$scope.$on('change-selectedCategory', function (event, selectedCategory) {
+ vm.$scope.$on('change-selectedCategory', function(event, selectedCategory) {
vm.selectedTheme = selectedCategory;
});
vm.$scope.$watch('pageInicio.selectedTheme', function(newValue/*, oldValue*/) {
vm.search.tema = newValue ? newValue.slug : null;
vm.$location.search('tema', vm.search.tema);
- vm.filtredPrograms = vm.getFiltredPrograms();
+
+ if (!vm.loadingFilter) {
+ vm.filtredPrograms = vm.getFiltredPrograms();
+ }
});
vm.$scope.$watch('pageInicio.query', function(newValue/*, oldValue*/) {
vm.search.filtro = newValue ? newValue : null;
vm.$location.search('filtro', vm.search.filtro);
- vm.filtredPrograms = vm.getFiltredPrograms();
+
+ if (!vm.loadingFilter) {
+ vm.filtredPrograms = vm.getFiltredPrograms();
+ }
});
};
@@ -144,13 +155,17 @@
InicioPageController.prototype.filter = function() {
var vm = this;
- // if (vm.search && vm.search.tema) {
+ if (vm.loadingThemes || vm.loadingPrograms) {
+ vm.$log.info('No programs or themes loaded yet. Abort.');
+ return;
+ }
+
if (vm._filtredByThemeSlug) {
var slug = vm._filtredByThemeSlug;
- vm.DialogaService.getThemeBySlug(slug, function(theme){
+ vm.DialogaService.getThemeBySlug(slug, function(theme) {
vm.selectedTheme = theme;
- }, function(error){
+ }, function(error) {
vm.$log.error('Error when try to "getThemeBySlug"', error);
});
}
@@ -158,6 +173,11 @@
if (vm._filtredByQuery) {
vm.query = vm._filtredByQuery;
}
+
+ if (vm._filtredByThemeSlug || vm._filtredByQuery) {
+ vm.filtredPrograms = vm.getFiltredPrograms();
+ vm.loadingFilter = false;
+ }
};
InicioPageController.prototype.showAllPrograms = function($event) {
@@ -179,7 +199,7 @@
InicioPageController.prototype.getFiltredPrograms = function() {
var vm = this;
- if(!vm.programs){
+ if (!vm.programs) {
vm.$log.warn('No programs loaded yet. Abort.');
return null;
}
@@ -199,7 +219,7 @@
output = filter(output, query, false);
}
- if(!query && !selectedTheme){
+ if (!query && !selectedTheme) {
output = _balanceByCategory(output);
}
diff --git a/src/app/pages/inicio/inicio.html b/src/app/pages/inicio/inicio.html
index 9e9966b..ac7c082 100644
--- a/src/app/pages/inicio/inicio.html
+++ b/src/app/pages/inicio/inicio.html
@@ -80,7 +80,7 @@
-