Commit 98f2f8f7e257268e8a9a27c54e10876f7222d3ff
1 parent
3ea656df
Exists in
master
and in
4 other branches
Fixes #139. Show selected theme when the list is collapsed
Showing
3 changed files
with
66 additions
and
40 deletions
Show diff stats
src/app/components/category-list/category-list.directive.js
| ... | ... | @@ -28,19 +28,18 @@ |
| 28 | 28 | CategoryListController.prototype.init = function() { |
| 29 | 29 | var vm = this; |
| 30 | 30 | |
| 31 | - vm.pathUrl = vm.$location.path(); | |
| 32 | - | |
| 33 | - vm.showCloseBtn = true; | |
| 31 | + vm.isRankingPage = (vm.$location.path() === '/ranking'); | |
| 34 | 32 | |
| 35 | 33 | // Disable button 'remove' of page ranking |
| 36 | - if (vm.pathUrl === '/ranking') { | |
| 34 | + vm.showCloseBtn = true; | |
| 35 | + if (vm.isRankingPage) { | |
| 37 | 36 | vm.showCloseBtn = false; |
| 38 | 37 | } |
| 39 | 38 | |
| 40 | 39 | // Default values |
| 41 | - if (!vm.isCollapsed) { | |
| 42 | - vm.isCollapsed = false; | |
| 43 | - } | |
| 40 | + vm.isCollapsed = false; | |
| 41 | + | |
| 42 | + // vm.$element.find('.js-selected-category').hide(); | |
| 44 | 43 | |
| 45 | 44 | }; |
| 46 | 45 | |
| ... | ... | @@ -63,7 +62,11 @@ |
| 63 | 62 | if (category !== vm.selectedCategory) { |
| 64 | 63 | vm.selectedCategory = category; |
| 65 | 64 | |
| 66 | - }else { | |
| 65 | + if (vm.isRankingPage) { | |
| 66 | + vm._getListGroup().slideUp(); | |
| 67 | + vm.isCollapsed = true; | |
| 68 | + } | |
| 69 | + } else { | |
| 67 | 70 | |
| 68 | 71 | if (vm._disableUnselect()) { |
| 69 | 72 | vm.$log.info('Unselect is disabled.'); |
| ... | ... | @@ -80,10 +83,23 @@ |
| 80 | 83 | CategoryListController.prototype.toogleList = function() { |
| 81 | 84 | var vm = this; |
| 82 | 85 | |
| 86 | + if (vm.isCollapsed) { | |
| 87 | + vm._getListGroup().slideDown(); | |
| 88 | + } else { | |
| 89 | + vm._getListGroup().slideUp(); | |
| 90 | + } | |
| 91 | + vm.isCollapsed = !vm.isCollapsed; | |
| 92 | + }; | |
| 93 | + | |
| 94 | + CategoryListController.prototype._getListGroup = function() { | |
| 95 | + var vm = this; | |
| 96 | + | |
| 83 | 97 | if (!vm._listGroup) { |
| 84 | - vm._listGroup = vm.$element.find('.list-group'); | |
| 98 | + vm._listGroup = vm.$element.find('.js-list-group'); | |
| 85 | 99 | } |
| 86 | - vm._listGroup.slideToggle(); | |
| 100 | + | |
| 101 | + return vm._listGroup; | |
| 102 | + | |
| 87 | 103 | }; |
| 88 | 104 | |
| 89 | 105 | var directive = { | ... | ... |
src/app/components/category-list/category-list.html
| 1 | -<div class="category-list"> | |
| 1 | +<div class="category-list" ng-class="vm.selectedCategory.slug"> | |
| 2 | 2 | <nav class="navigation"> |
| 3 | 3 | <h3 class="category-list--title" ng-click="vm.toogleList()"> |
| 4 | 4 | <!-- <span class="hidden-xs"><b>Programas</b> por Tema</span> --> |
| 5 | 5 | <!-- <span class="visible-xs"><b>Filtrar</b> por Tema <span class="glyphicon glyphicon-filter pull-right"></span></span> --> |
| 6 | 6 | <b>Filtrar</b> por Tema <span class="glyphicon glyphicon-filter pull-right"></span> |
| 7 | 7 | </h3> |
| 8 | - <!-- <div class="list-group ng-hide" ng-show="!vm.isCollapsed" ng-class="vm.selectedCategory.slug"> --> | |
| 9 | - <div class="list-group is-mobile" ng-class="vm.selectedCategory.slug"> | |
| 8 | + | |
| 9 | + <div class="list-group is-mobile js-list-group"> | |
| 10 | 10 | <button type="button" class="list-group-item category-list--item" |
| 11 | 11 | ng-repeat="category in vm.categories" |
| 12 | 12 | ng-class="{active: vm.selectedCategory.slug === category.slug}" |
| ... | ... | @@ -22,5 +22,17 @@ |
| 22 | 22 | </div> |
| 23 | 23 | </button> |
| 24 | 24 | </div> |
| 25 | + | |
| 26 | + <div class="list-group is-mobile js-selected-category"> | |
| 27 | + <button type="button" class="list-group-item category-list--item active" ng-if="vm.isCollapsed"> | |
| 28 | + <span class="category-list--icon-circle" aria-hidden="true" ng-class="vm.selectedCategory.slug"></span> | |
| 29 | + <span class="category-list--icon icon" aria-hidden="true" ng-class="'icon-tema-' + vm.selectedCategory.slug + '-small'"></span> | |
| 30 | + <span class="category-list--label">{{vm.selectedCategory.name}}</span> | |
| 31 | + <span class="category-list--icon--right glyphicon glyphicon-chevron-right hidden-xs"></span> | |
| 32 | + <div ng-if="vm.selectedCategory.archived" class="category-list--icon-archived"> | |
| 33 | + <span class="glyphicon glyphicon-ok" aria-hidden="true"></span> | |
| 34 | + </div> | |
| 35 | + </button> | |
| 36 | + </div> | |
| 25 | 37 | </nav> |
| 26 | 38 | </div> |
| 27 | 39 | \ No newline at end of file | ... | ... |
src/app/pages/ranking/ranking.controller.js
| ... | ... | @@ -24,7 +24,7 @@ |
| 24 | 24 | $log.debug('RankingPageController'); |
| 25 | 25 | } |
| 26 | 26 | |
| 27 | - RankingPageController.prototype.init = function () { | |
| 27 | + RankingPageController.prototype.init = function() { | |
| 28 | 28 | var vm = this; |
| 29 | 29 | |
| 30 | 30 | vm.page = 1; |
| ... | ... | @@ -39,7 +39,6 @@ |
| 39 | 39 | //Remove "X" from the theme at the ranking page |
| 40 | 40 | vm.slug = vm.$location.$$path; |
| 41 | 41 | |
| 42 | - | |
| 43 | 42 | if (vm.search.tema) { |
| 44 | 43 | vm._filtredByThemeSlug = vm.search.tema; |
| 45 | 44 | } |
| ... | ... | @@ -56,7 +55,7 @@ |
| 56 | 55 | vm.error = null; |
| 57 | 56 | }; |
| 58 | 57 | |
| 59 | - RankingPageController.prototype.loadData = function () { | |
| 58 | + RankingPageController.prototype.loadData = function() { | |
| 60 | 59 | var vm = this; |
| 61 | 60 | |
| 62 | 61 | vm.loading = true; |
| ... | ... | @@ -71,40 +70,39 @@ |
| 71 | 70 | |
| 72 | 71 | // 1. Load themes |
| 73 | 72 | vm.loadingThemes = true; |
| 74 | - vm.DialogaService.getThemes(function(themes){ | |
| 73 | + vm.DialogaService.getThemes(function(themes) { | |
| 75 | 74 | vm.themes = themes; |
| 76 | 75 | vm.loadingThemes = false; |
| 77 | 76 | |
| 78 | 77 | // 2. Select a Random Theme (T) |
| 79 | 78 | var selectedTheme = null; |
| 80 | - if(vm.search.tema || vm._filtredByThemeSlug){ | |
| 79 | + if (vm.search.tema || vm._filtredByThemeSlug) { | |
| 81 | 80 | |
| 82 | 81 | // vanilla filter |
| 83 | - var results = vm.themes.filter(function(t){ | |
| 82 | + var results = vm.themes.filter(function(t) { | |
| 84 | 83 | return (t.slug === vm.search.tema || (t.slug === vm._filtredByThemeSlug)); |
| 85 | 84 | }); |
| 86 | 85 | |
| 87 | - if(results && results.length > 0){ | |
| 86 | + if (results && results.length > 0) { | |
| 88 | 87 | selectedTheme = results[0]; |
| 89 | 88 | vm.selectedTheme = selectedTheme; |
| 90 | 89 | } |
| 91 | 90 | |
| 92 | - | |
| 93 | 91 | } |
| 94 | 92 | |
| 95 | - if(!selectedTheme){ | |
| 93 | + if (!selectedTheme) { | |
| 96 | 94 | vm.selectedTheme = vm.themes[Math.floor(Math.random() * vm.themes.length)]; |
| 97 | 95 | } |
| 98 | 96 | |
| 99 | 97 | // 3. Load programs of T |
| 100 | 98 | // (AND 4) |
| 101 | 99 | var themeId = vm.selectedTheme.id; |
| 102 | - vm.loadPrograms(themeId, function(){ | |
| 100 | + vm.loadPrograms(themeId, function() { | |
| 103 | 101 | // vm.loadProposals(); |
| 104 | 102 | vm.loading = false; |
| 105 | 103 | vm.loadingFilter = false; |
| 106 | 104 | }); |
| 107 | - }, function (error) { | |
| 105 | + }, function(error) { | |
| 108 | 106 | vm.error = error; |
| 109 | 107 | vm.$log.error(error); |
| 110 | 108 | vm.loadingThemes = false; |
| ... | ... | @@ -112,38 +110,38 @@ |
| 112 | 110 | }); |
| 113 | 111 | }; |
| 114 | 112 | |
| 115 | - RankingPageController.prototype.loadPrograms = function (themeId, cb) { | |
| 113 | + RankingPageController.prototype.loadPrograms = function(themeId, cb) { | |
| 116 | 114 | var vm = this; |
| 117 | 115 | |
| 118 | - vm.DialogaService.getProgramsByThemeId(themeId, function (programs){ | |
| 116 | + vm.DialogaService.getProgramsByThemeId(themeId, function(programs) { | |
| 119 | 117 | |
| 120 | 118 | vm.filtredPrograms = programs; |
| 121 | 119 | |
| 122 | 120 | // 4. Select a random program of T |
| 123 | 121 | var selectedProgram = null; |
| 124 | - if(vm.search.programa || vm._filtredByProgramSlug){ | |
| 122 | + if (vm.search.programa || vm._filtredByProgramSlug) { | |
| 125 | 123 | |
| 126 | 124 | // vanilla filter |
| 127 | - var results = vm.filtredPrograms.filter(function(p){ | |
| 125 | + var results = vm.filtredPrograms.filter(function(p) { | |
| 128 | 126 | return (p.slug === vm.search.programa || (p.slug === vm._filtredByProgramSlug)); |
| 129 | 127 | }); |
| 130 | 128 | |
| 131 | - if(results && results.length > 0){ | |
| 129 | + if (results && results.length > 0) { | |
| 132 | 130 | selectedProgram = results[0]; |
| 133 | 131 | vm.selectedProgram = selectedProgram; |
| 134 | 132 | } |
| 135 | 133 | } |
| 136 | 134 | |
| 137 | - if(!selectedProgram){ | |
| 135 | + if (!selectedProgram) { | |
| 138 | 136 | vm.selectedProgram = vm.filtredPrograms[Math.floor(Math.random() * vm.filtredPrograms.length)]; |
| 139 | 137 | } |
| 140 | 138 | |
| 141 | - if(cb){ | |
| 139 | + if (cb) { | |
| 142 | 140 | cb(); |
| 143 | 141 | } |
| 144 | - }, function(error){ | |
| 142 | + }, function(error) { | |
| 145 | 143 | vm.$log.error(error); |
| 146 | - if(cb){ | |
| 144 | + if (cb) { | |
| 147 | 145 | cb(); |
| 148 | 146 | } |
| 149 | 147 | }); |
| ... | ... | @@ -152,7 +150,7 @@ |
| 152 | 150 | RankingPageController.prototype.attachListeners = function() { |
| 153 | 151 | var vm = this; |
| 154 | 152 | |
| 155 | - vm.$scope.$on('change-selectedCategory', function (event, selectedCategory) { | |
| 153 | + vm.$scope.$on('change-selectedCategory', function(event, selectedCategory) { | |
| 156 | 154 | vm.selectedTheme = selectedCategory; |
| 157 | 155 | }); |
| 158 | 156 | |
| ... | ... | @@ -160,14 +158,14 @@ |
| 160 | 158 | vm.search.tema = newValue ? newValue.slug : null; |
| 161 | 159 | vm.$location.search('tema', vm.search.tema); |
| 162 | 160 | |
| 163 | - if(!vm.loadingFilter && vm.selectedTheme && vm.selectedTheme.id){ | |
| 164 | - vm.loadPrograms(vm.selectedTheme.id, function(){ | |
| 161 | + if (!vm.loadingFilter && vm.selectedTheme && vm.selectedTheme.id) { | |
| 162 | + vm.loadPrograms(vm.selectedTheme.id, function() { | |
| 165 | 163 | vm.filterProposals(); |
| 166 | 164 | }); |
| 167 | 165 | } |
| 168 | 166 | }); |
| 169 | 167 | |
| 170 | - vm.$scope.$on('change-selectedTopic', function (event, selectedTopic) { | |
| 168 | + vm.$scope.$on('change-selectedTopic', function(event, selectedTopic) { | |
| 171 | 169 | vm.selectedProgram = selectedTopic; |
| 172 | 170 | }); |
| 173 | 171 | |
| ... | ... | @@ -207,7 +205,7 @@ |
| 207 | 205 | RankingPageController.prototype.filterProposals = function(_page, _per_page) { |
| 208 | 206 | var vm = this; |
| 209 | 207 | |
| 210 | - if (vm.loadingProposals){ | |
| 208 | + if (vm.loadingProposals) { | |
| 211 | 209 | vm.$log.debug('Content is not loaded yet.'); |
| 212 | 210 | return; |
| 213 | 211 | } |
| ... | ... | @@ -228,11 +226,11 @@ |
| 228 | 226 | if (query) {params.query = query; } |
| 229 | 227 | |
| 230 | 228 | vm.loadingProposals = true; |
| 231 | - vm.DialogaService.searchProposals(params, function(data){ | |
| 229 | + vm.DialogaService.searchProposals(params, function(data) { | |
| 232 | 230 | vm.total_proposals = parseInt(data._obj.headers('total')); |
| 233 | 231 | vm.filtredProposals = data.articles; |
| 234 | 232 | vm.loadingProposals = false; |
| 235 | - }, function (error) { | |
| 233 | + }, function(error) { | |
| 236 | 234 | vm.error = error; |
| 237 | 235 | vm.$log.error(error); |
| 238 | 236 | vm.loadingProposals = false; | ... | ... |