Commit 43da07e5eeb20fe1ede116f49e3f9aeff35708da
Exists in
master
and in
8 other branches
Merge branch 'merlin' into rafael
Showing
15 changed files
with
415 additions
and
46 deletions
Show diff stats
gulp/build.js
| @@ -43,6 +43,7 @@ gulp.task('html', ['inject', 'partials'], function () { | @@ -43,6 +43,7 @@ gulp.task('html', ['inject', 'partials'], function () { | ||
| 43 | .pipe(assets = $.useref.assets()) | 43 | .pipe(assets = $.useref.assets()) |
| 44 | .pipe($.rev()) | 44 | .pipe($.rev()) |
| 45 | .pipe(jsFilter) | 45 | .pipe(jsFilter) |
| 46 | + .pipe($.replace('$logProvider.debugEnabled(true);', '$logProvider.debugEnabled(false);')) | ||
| 46 | .pipe($.ngAnnotate()) | 47 | .pipe($.ngAnnotate()) |
| 47 | .pipe($.uglify({ preserveComments: $.uglifySaveLicense })).on('error', conf.errorHandler('Uglify')) | 48 | .pipe($.uglify({ preserveComments: $.uglifySaveLicense })).on('error', conf.errorHandler('Uglify')) |
| 48 | .pipe(jsFilter.restore()) | 49 | .pipe(jsFilter.restore()) |
| @@ -68,16 +69,26 @@ gulp.task('html', ['inject', 'partials'], function () { | @@ -68,16 +69,26 @@ gulp.task('html', ['inject', 'partials'], function () { | ||
| 68 | 69 | ||
| 69 | // Only applies for fonts from bower dependencies | 70 | // Only applies for fonts from bower dependencies |
| 70 | // Custom fonts are handled by the "other" task | 71 | // Custom fonts are handled by the "other" task |
| 71 | -gulp.task('fonts', function () { | 72 | +gulp.task('fonts', ['fonts-bootstrap', 'fonts-opensans']); |
| 73 | + | ||
| 74 | +gulp.task('fonts-bootstrap', function () { | ||
| 72 | return gulp.src([ | 75 | return gulp.src([ |
| 73 | - $.mainBowerFiles().concat('bower_components/bootstrap-sass-official/assets/fonts/bootstrap/*'), | ||
| 74 | - $.mainBowerFiles().concat('bower_components/open-sans-fontface/fonts/*') | 76 | + 'bower_components/bootstrap-sass-official/assets/fonts/bootstrap/**/*' |
| 75 | ]) | 77 | ]) |
| 76 | .pipe($.filter('**/*.{eot,svg,ttf,woff,woff2}')) | 78 | .pipe($.filter('**/*.{eot,svg,ttf,woff,woff2}')) |
| 77 | .pipe($.flatten()) | 79 | .pipe($.flatten()) |
| 78 | .pipe(gulp.dest(path.join(conf.paths.dist, '/fonts/'))); | 80 | .pipe(gulp.dest(path.join(conf.paths.dist, '/fonts/'))); |
| 79 | }); | 81 | }); |
| 80 | 82 | ||
| 83 | +gulp.task('fonts-opensans', function () { | ||
| 84 | + return gulp.src([ | ||
| 85 | + 'bower_components/open-sans-fontface/fonts/**/*' | ||
| 86 | + ]) | ||
| 87 | + .pipe($.filter('**/*.{eot,svg,ttf,woff,woff2}')) | ||
| 88 | + // .pipe($.flatten()) | ||
| 89 | + .pipe(gulp.dest(path.join(conf.paths.dist, '/styles/fonts/'))); | ||
| 90 | +}); | ||
| 91 | + | ||
| 81 | gulp.task('other', function () { | 92 | gulp.task('other', function () { |
| 82 | var fileFilter = $.filter(function (file) { | 93 | var fileFilter = $.filter(function (file) { |
| 83 | return file.stat.isFile(); | 94 | return file.stat.isFile(); |
src/app/components/article-service/article.service.js
| @@ -70,7 +70,7 @@ | @@ -70,7 +70,7 @@ | ||
| 70 | 70 | ||
| 71 | function getTopics (params, cbSuccess, cbError) { | 71 | function getTopics (params, cbSuccess, cbError) { |
| 72 | // Ex.: /api/v1/articles/103358/children?fields= | 72 | // Ex.: /api/v1/articles/103358/children?fields= |
| 73 | - getTopicById(API.articleId.home); | 73 | + getTopicById(API.articleId.home, params, cbSuccess, cbError); |
| 74 | } | 74 | } |
| 75 | 75 | ||
| 76 | function getTopicById (topicId, params, cbSuccess, cbError) { | 76 | function getTopicById (topicId, params, cbSuccess, cbError) { |
| @@ -79,11 +79,11 @@ | @@ -79,11 +79,11 @@ | ||
| 79 | var url = service.apiArticles + topicId + '/children'; | 79 | var url = service.apiArticles + topicId + '/children'; |
| 80 | var paramsExtended = angular.extend({ | 80 | var paramsExtended = angular.extend({ |
| 81 | 'fields[]': ['id', 'categories'] | 81 | 'fields[]': ['id', 'categories'] |
| 82 | + // 'fields[]': ['id', 'title', 'body', 'slug', 'abstract', 'categories', 'setting', 'children_count', 'hits'] | ||
| 82 | }, params); | 83 | }, params); |
| 83 | 84 | ||
| 84 | - UtilService.get(url, {params: { | ||
| 85 | - 'fields[]': ['id', 'title', 'body', 'slug', 'abstract', 'categories', 'setting', 'children_count', 'hits'] | ||
| 86 | - }}).then(function(data){ | 85 | + UtilService.get(url, {params: paramsExtended}) |
| 86 | + .then(function(data){ | ||
| 87 | cbSuccess(data); | 87 | cbSuccess(data); |
| 88 | }).catch(function(error){ | 88 | }).catch(function(error){ |
| 89 | cbError(error); | 89 | cbError(error); |
| @@ -121,13 +121,14 @@ | @@ -121,13 +121,14 @@ | ||
| 121 | var url = service.apiArticles + topicId + '/children'; | 121 | var url = service.apiArticles + topicId + '/children'; |
| 122 | 122 | ||
| 123 | var paramsExtended = angular.extend({ | 123 | var paramsExtended = angular.extend({ |
| 124 | - 'fields[]': ['id', 'title', 'abstract', 'children', 'children_count', 'ranking_position', 'hits', 'votes_for', 'votes_against'], | ||
| 125 | - 'limit':'20', | ||
| 126 | - 'page':'1', | 124 | + // 'fields[]': ['id', 'title', 'abstract', 'children', 'children_count', 'ranking_position', 'hits', 'votes_for', 'votes_against'], |
| 125 | + // 'limit':'20', | ||
| 126 | + // 'page':'1', | ||
| 127 | 'content_type':'ProposalsDiscussionPlugin::Proposal' | 127 | 'content_type':'ProposalsDiscussionPlugin::Proposal' |
| 128 | }, params); | 128 | }, params); |
| 129 | 129 | ||
| 130 | UtilService.get(url, {params: paramsExtended}).then(function(data){ | 130 | UtilService.get(url, {params: paramsExtended}).then(function(data){ |
| 131 | + _pipeInjectSlugIntoParentProgram(data); | ||
| 131 | cbSuccess(data); | 132 | cbSuccess(data); |
| 132 | }).catch(function(error){ | 133 | }).catch(function(error){ |
| 133 | cbError(error); | 134 | cbError(error); |
| @@ -180,5 +181,15 @@ | @@ -180,5 +181,15 @@ | ||
| 180 | cbError(error); | 181 | cbError(error); |
| 181 | }); | 182 | }); |
| 182 | } | 183 | } |
| 184 | + | ||
| 185 | + function _pipeInjectSlugIntoParentProgram(data){ | ||
| 186 | + var proposals = data.articles; | ||
| 187 | + for (var i = proposals.length - 1; i >= 0; i--) { | ||
| 188 | + var proposal = proposals[i]; | ||
| 189 | + if(proposal.parent && !proposal.parent.slug){ | ||
| 190 | + proposal.parent.slug = Slug.slugify(proposal.parent.title); | ||
| 191 | + } | ||
| 192 | + } | ||
| 193 | + } | ||
| 183 | } | 194 | } |
| 184 | })(); | 195 | })(); |
src/app/components/dialoga-service/dialoga.service.js
| @@ -16,6 +16,7 @@ | @@ -16,6 +16,7 @@ | ||
| 16 | extendedService.getAbout = getAbout; | 16 | extendedService.getAbout = getAbout; |
| 17 | extendedService.getTerms = getTerms; | 17 | extendedService.getTerms = getTerms; |
| 18 | extendedService.getThemes = getThemes; | 18 | extendedService.getThemes = getThemes; |
| 19 | + extendedService.getThemeBySlug = getThemeBySlug; | ||
| 19 | extendedService.getPrograms = getPrograms; | 20 | extendedService.getPrograms = getPrograms; |
| 20 | extendedService.getProgramBySlug = getProgramBySlug; | 21 | extendedService.getProgramBySlug = getProgramBySlug; |
| 21 | extendedService.getProgramsRandom = getProgramsRandom; | 22 | extendedService.getProgramsRandom = getProgramsRandom; |
| @@ -88,6 +89,28 @@ | @@ -88,6 +89,28 @@ | ||
| 88 | },cbError); | 89 | },cbError); |
| 89 | } | 90 | } |
| 90 | } | 91 | } |
| 92 | + function getThemeBySlug (slug, cbSuccess, cbError) { | ||
| 93 | + if( !!CACHE.themes ){ | ||
| 94 | + _getThemeBySlug(CACHE.themes); | ||
| 95 | + }else{ | ||
| 96 | + getThemes(_getThemeBySlug, cbError); | ||
| 97 | + } | ||
| 98 | + | ||
| 99 | + function _getThemeBySlug () { | ||
| 100 | + var result = null; | ||
| 101 | + | ||
| 102 | + for (var i = CACHE.themes.length - 1; i >= 0; i--) { | ||
| 103 | + var theme = CACHE.themes[i]; | ||
| 104 | + | ||
| 105 | + if(theme && theme.slug && theme.slug === slug){ | ||
| 106 | + result = theme; | ||
| 107 | + break; | ||
| 108 | + } | ||
| 109 | + } | ||
| 110 | + | ||
| 111 | + cbSuccess(result); | ||
| 112 | + } | ||
| 113 | + } | ||
| 91 | 114 | ||
| 92 | function getPrograms (cbSuccess, cbError) { | 115 | function getPrograms (cbSuccess, cbError) { |
| 93 | if( !!CACHE.programs ){ | 116 | if( !!CACHE.programs ){ |
src/app/components/proposal-box/proposal-box.directive.js
| @@ -23,15 +23,15 @@ | @@ -23,15 +23,15 @@ | ||
| 23 | 23 | ||
| 24 | var vm = this; | 24 | var vm = this; |
| 25 | 25 | ||
| 26 | - if (!vm.vote) { vm.vote = false}; | 26 | + if (!vm.vote) { vm.vote = false; } |
| 27 | 27 | ||
| 28 | }; | 28 | }; |
| 29 | 29 | ||
| 30 | - ProposalBoxController.prototype.showContent = function (program) { | 30 | + ProposalBoxController.prototype.showContent2 = function (topic) { |
| 31 | var vm = this; | 31 | var vm = this; |
| 32 | 32 | ||
| 33 | vm.$state.go('programa-conteudo', { | 33 | vm.$state.go('programa-conteudo', { |
| 34 | - slug: program.slug | 34 | + slug: topic.slug |
| 35 | }, { | 35 | }, { |
| 36 | location: true | 36 | location: true |
| 37 | }); | 37 | }); |
src/app/components/proposal-box/proposal-box.html
| 1 | -<div class="proposal-box" ng-class="{'focus':vm.isFocused}"> | 1 | +<div class="proposal-box" ng-class="[{'focus': vm.isFocused}, vm.category.slug]"> |
| 2 | <div class="proposal-box--top"> | 2 | <div class="proposal-box--top"> |
| 3 | <div class="proposal-box--theme color-theme-bg-darker">{{::vm.category.name}}</div> | 3 | <div class="proposal-box--theme color-theme-bg-darker">{{::vm.category.name}}</div> |
| 4 | <div class="proposal-box--program color-theme-bg">{{::vm.topic.title}}</div> | 4 | <div class="proposal-box--program color-theme-bg">{{::vm.topic.title}}</div> |
| @@ -7,10 +7,10 @@ | @@ -7,10 +7,10 @@ | ||
| 7 | <div class="proposal-box--content"> | 7 | <div class="proposal-box--content"> |
| 8 | <div class="proposal-box--content-inner" ng-bind-html="vm.proposal.abstract"></div> | 8 | <div class="proposal-box--content-inner" ng-bind-html="vm.proposal.abstract"></div> |
| 9 | </div> | 9 | </div> |
| 10 | - <div ng-if="vm.vote==false" class="proposal-box--join"> | ||
| 11 | - <button class="btn btn-link" ng-click="vm.showContent(vm.topic)">Participe</button> | 10 | + <div ng-show="!vm.vote" class="proposal-box--join"> |
| 11 | + <button class="btn btn-link" ng-click="vm.showContent2(vm.topic)">Participe</button> | ||
| 12 | </div> | 12 | </div> |
| 13 | - <div ng-if="vm.vote==true"class="proposal-box--actions text-center"> | 13 | + <div ng-show="vm.vote"class="proposal-box--actions text-center"> |
| 14 | <div class="row"> | 14 | <div class="row"> |
| 15 | <div class="col-xs-4"> | 15 | <div class="col-xs-4"> |
| 16 | <div class="action vote_for"> | 16 | <div class="action vote_for"> |
src/app/components/proposal-grid/proposal-grid.html
| 1 | <div class="proposal-grid row"> | 1 | <div class="proposal-grid row"> |
| 2 | <div ng-repeat="proposal in vm.proposals as results"> | 2 | <div ng-repeat="proposal in vm.proposals as results"> |
| 3 | - <proposal-box proposal="proposal" category="proposal.categories[0]" class="col-xs-12 col-sm-6"></proposal-box> | 3 | + <proposal-box proposal="proposal" topic="proposal.parent" category="proposal.parent.categories[0]" class="col-xs-12 col-sm-6"></proposal-box> |
| 4 | <div ng-if="$odd" class="clearfix"></div> | 4 | <div ng-if="$odd" class="clearfix"></div> |
| 5 | </div> | 5 | </div> |
| 6 | <div class="animate-repeat" ng-if="results.length == 0"> | 6 | <div class="animate-repeat" ng-if="results.length == 0"> |
src/app/components/show-message/show-message.directive.js
| @@ -10,10 +10,8 @@ | @@ -10,10 +10,8 @@ | ||
| 10 | 10 | ||
| 11 | /** @ngInject */ | 11 | /** @ngInject */ |
| 12 | function ShowMessageController($log) { | 12 | function ShowMessageController($log) { |
| 13 | + // var vm = this; | ||
| 13 | $log.debug('ShowMessageController'); | 14 | $log.debug('ShowMessageController'); |
| 14 | - | ||
| 15 | - var vm = this; | ||
| 16 | - | ||
| 17 | } | 15 | } |
| 18 | 16 | ||
| 19 | var directive = { | 17 | var directive = { |
src/app/components/validation-messages/validation-messages.directive.js
| @@ -23,10 +23,10 @@ | @@ -23,10 +23,10 @@ | ||
| 23 | // async values | 23 | // async values |
| 24 | var vm = this; | 24 | var vm = this; |
| 25 | 25 | ||
| 26 | - if (!vm.required) {vm.required = "Ops, o campo é obrigatório."}; | ||
| 27 | - if (!vm.minlength) {vm.minlength = "O campo deve ser maior."}; | ||
| 28 | - if (!vm.maxlength) {vm.maxlength = "O campo deve ser menor"}; | ||
| 29 | - if (!vm.email) {vm.email = "O endereço de e-mail deve ser válido"}; | 26 | + if (!vm.required) {vm.required = 'Ops, o campo é obrigatório.';} |
| 27 | + if (!vm.minlength) {vm.minlength = 'O campo deve ser maior.';} | ||
| 28 | + if (!vm.maxlength) {vm.maxlength = 'O campo deve ser menor';} | ||
| 29 | + if (!vm.email) {vm.email = 'O endereço de e-mail deve ser válido';} | ||
| 30 | 30 | ||
| 31 | }; | 31 | }; |
| 32 | 32 |
src/app/index.route.js
| @@ -9,7 +9,7 @@ | @@ -9,7 +9,7 @@ | ||
| 9 | function routeConfig($stateProvider, $urlRouterProvider) { | 9 | function routeConfig($stateProvider, $urlRouterProvider) { |
| 10 | $stateProvider | 10 | $stateProvider |
| 11 | .state('inicio', { | 11 | .state('inicio', { |
| 12 | - url: '/?limite&tema', | 12 | + url: '/?tema&query', |
| 13 | ncyBreadcrumb: {label: 'Home'}, | 13 | ncyBreadcrumb: {label: 'Home'}, |
| 14 | reloadOnSearch: false, | 14 | reloadOnSearch: false, |
| 15 | views: { | 15 | views: { |
src/app/pages/inicio/inicio.controller.js
| @@ -7,12 +7,14 @@ | @@ -7,12 +7,14 @@ | ||
| 7 | .controller('InicioPageController', InicioPageController); | 7 | .controller('InicioPageController', InicioPageController); |
| 8 | 8 | ||
| 9 | /** @ngInject */ | 9 | /** @ngInject */ |
| 10 | - function InicioPageController(DialogaService, $scope, $sce, $log) { | 10 | + function InicioPageController(DialogaService, $scope, $location, $filter, $sce, $log) { |
| 11 | var vm = this; | 11 | var vm = this; |
| 12 | 12 | ||
| 13 | // aliases | 13 | // aliases |
| 14 | vm.DialogaService = DialogaService; | 14 | vm.DialogaService = DialogaService; |
| 15 | vm.$scope = $scope; | 15 | vm.$scope = $scope; |
| 16 | + vm.$location = $location; | ||
| 17 | + vm.$filter = $filter; | ||
| 16 | vm.$sce = $sce; | 18 | vm.$sce = $sce; |
| 17 | vm.$log = $log; | 19 | vm.$log = $log; |
| 18 | 20 | ||
| @@ -29,6 +31,7 @@ | @@ -29,6 +31,7 @@ | ||
| 29 | vm.programs = null; | 31 | vm.programs = null; |
| 30 | vm.filtredPrograms = null; | 32 | vm.filtredPrograms = null; |
| 31 | vm.query = null; | 33 | vm.query = null; |
| 34 | + vm.search = vm.$location.search(); | ||
| 32 | 35 | ||
| 33 | vm.error = null; | 36 | vm.error = null; |
| 34 | 37 | ||
| @@ -39,12 +42,9 @@ | @@ -39,12 +42,9 @@ | ||
| 39 | InicioPageController.prototype.loadData = function() { | 42 | InicioPageController.prototype.loadData = function() { |
| 40 | var vm = this; | 43 | var vm = this; |
| 41 | 44 | ||
| 42 | - vm.loading = true; | ||
| 43 | - vm.loadingEvents = true; | ||
| 44 | - vm.loadingThemes = true; | ||
| 45 | - vm.loadingPrograms = true; | ||
| 46 | 45 | ||
| 47 | // Load main content | 46 | // Load main content |
| 47 | + vm.loading = true; | ||
| 48 | vm.DialogaService.getHome(function(data) { | 48 | vm.DialogaService.getHome(function(data) { |
| 49 | vm.article = data.article; | 49 | vm.article = data.article; |
| 50 | 50 | ||
| @@ -52,7 +52,7 @@ | @@ -52,7 +52,7 @@ | ||
| 52 | hideBackground(2000); | 52 | hideBackground(2000); |
| 53 | } | 53 | } |
| 54 | 54 | ||
| 55 | - loadAfterHome(); | 55 | + _loadAfterHome(); |
| 56 | 56 | ||
| 57 | vm.loading = false; | 57 | vm.loading = false; |
| 58 | }, function(error) { | 58 | }, function(error) { |
| @@ -60,6 +60,7 @@ | @@ -60,6 +60,7 @@ | ||
| 60 | }); | 60 | }); |
| 61 | 61 | ||
| 62 | // Load event list | 62 | // Load event list |
| 63 | + vm.loadingEvents = true; | ||
| 63 | vm.DialogaService.getEvents({}, function(events) { | 64 | vm.DialogaService.getEvents({}, function(events) { |
| 64 | vm.events = events; | 65 | vm.events = events; |
| 65 | vm.loadingEvents = false; | 66 | vm.loadingEvents = false; |
| @@ -69,9 +70,10 @@ | @@ -69,9 +70,10 @@ | ||
| 69 | vm.eventsError = true; | 70 | vm.eventsError = true; |
| 70 | }); | 71 | }); |
| 71 | 72 | ||
| 72 | - function loadAfterHome () { | 73 | + function _loadAfterHome () { |
| 73 | 74 | ||
| 74 | // Load theme list | 75 | // Load theme list |
| 76 | + vm.loadingThemes = true; | ||
| 75 | vm.DialogaService.getThemes(function(data) { | 77 | vm.DialogaService.getThemes(function(data) { |
| 76 | vm.themes = data; | 78 | vm.themes = data; |
| 77 | vm.loadingThemes = false; | 79 | vm.loadingThemes = false; |
| @@ -80,6 +82,7 @@ | @@ -80,6 +82,7 @@ | ||
| 80 | }); | 82 | }); |
| 81 | 83 | ||
| 82 | // Load program list | 84 | // Load program list |
| 85 | + vm.loadingPrograms = true; | ||
| 83 | vm.DialogaService.getProgramsRandom({}, function(data) { | 86 | vm.DialogaService.getProgramsRandom({}, function(data) { |
| 84 | vm.programs = vm.article.children; | 87 | vm.programs = vm.article.children; |
| 85 | vm.filtredPrograms = data.articles; | 88 | vm.filtredPrograms = data.articles; |
| @@ -87,6 +90,8 @@ | @@ -87,6 +90,8 @@ | ||
| 87 | }, function(error) { | 90 | }, function(error) { |
| 88 | vm.$log.error('Error on getPrograms.', error); | 91 | vm.$log.error('Error on getPrograms.', error); |
| 89 | }); | 92 | }); |
| 93 | + | ||
| 94 | + vm.filter(); | ||
| 90 | } | 95 | } |
| 91 | 96 | ||
| 92 | }; | 97 | }; |
| @@ -112,11 +117,161 @@ | @@ -112,11 +117,161 @@ | ||
| 112 | InicioPageController.prototype.attachListeners = function() { | 117 | InicioPageController.prototype.attachListeners = function() { |
| 113 | var vm = this; | 118 | var vm = this; |
| 114 | 119 | ||
| 115 | - vm.$scope.$on('change-selectedCategory', function (selectedCategory) { | 120 | + vm.$scope.$on('change-selectedCategory', function (event, selectedCategory) { |
| 116 | vm.selectedTheme = selectedCategory; | 121 | vm.selectedTheme = selectedCategory; |
| 117 | }); | 122 | }); |
| 123 | + | ||
| 124 | + vm.$scope.$watch('pageInicio.selectedTheme', function(newValue/*, oldValue*/) { | ||
| 125 | + vm.search.tema = newValue ? newValue.slug : null; | ||
| 126 | + vm.$location.search('tema', vm.search.tema); | ||
| 127 | + vm.filtredPrograms = vm.getFiltredPrograms(); | ||
| 128 | + }); | ||
| 129 | + | ||
| 130 | + vm.$scope.$watch('pageInicio.query', function(newValue/*, oldValue*/) { | ||
| 131 | + vm.search.filtro = newValue ? newValue : null; | ||
| 132 | + vm.$location.search('filtro', vm.search.filtro); | ||
| 133 | + vm.filtredPrograms = vm.getFiltredPrograms(); | ||
| 134 | + }); | ||
| 135 | + }; | ||
| 136 | + | ||
| 137 | + InicioPageController.prototype.filter = function() { | ||
| 138 | + var vm = this; | ||
| 139 | + | ||
| 140 | + if (vm.search && vm.search.tema) { | ||
| 141 | + var slug = vm.search.tema; | ||
| 142 | + vm.$log.debug('filter by theme', slug); | ||
| 143 | + | ||
| 144 | + vm.DialogaService.getThemeBySlug(slug, function(theme){ | ||
| 145 | + vm.selectedTheme = theme; | ||
| 146 | + vm.$log.debug('getThemeBySlug.slug', slug); | ||
| 147 | + vm.$log.debug('getThemeBySlug.selectedTheme', theme); | ||
| 148 | + }, function(error){ | ||
| 149 | + vm.$log.error('Error when try to "getThemeBySlug"', error); | ||
| 150 | + }); | ||
| 151 | + } | ||
| 152 | + }; | ||
| 153 | + | ||
| 154 | + InicioPageController.prototype.showAllPrograms = function($event) { | ||
| 155 | + var vm = this; | ||
| 156 | + $event.stopPropagation(); | ||
| 157 | + | ||
| 158 | + vm.resetFilterValues(); | ||
| 159 | + | ||
| 160 | + vm.filtredPrograms = vm.getFiltredPrograms(); | ||
| 161 | + }; | ||
| 162 | + | ||
| 163 | + InicioPageController.prototype.resetFilterValues = function() { | ||
| 164 | + var vm = this; | ||
| 165 | + | ||
| 166 | + vm.query = null; | ||
| 167 | + vm.selectedTheme = null; | ||
| 168 | + }; | ||
| 169 | + | ||
| 170 | + InicioPageController.prototype.getFiltredPrograms = function() { | ||
| 171 | + var vm = this; | ||
| 172 | + | ||
| 173 | + if(!vm.programs){ | ||
| 174 | + vm.$log.warn('No programs loaded yet. Abort.'); | ||
| 175 | + return null; | ||
| 176 | + } | ||
| 177 | + | ||
| 178 | + var input = vm.programs; | ||
| 179 | + var output = input; | ||
| 180 | + var query = vm.query; | ||
| 181 | + var selectedTheme = vm.selectedTheme; | ||
| 182 | + | ||
| 183 | + var filter = vm.$filter('filter'); | ||
| 184 | + | ||
| 185 | + if (selectedTheme) { | ||
| 186 | + output = _filterByCategory(output, selectedTheme); | ||
| 187 | + } | ||
| 188 | + | ||
| 189 | + if (query) { | ||
| 190 | + output = filter(output, query, false); | ||
| 191 | + } | ||
| 192 | + | ||
| 193 | + if(!query && !selectedTheme){ | ||
| 194 | + output = _balanceByCategory(output); | ||
| 195 | + } | ||
| 196 | + | ||
| 197 | + return output; | ||
| 118 | }; | 198 | }; |
| 119 | 199 | ||
| 200 | + function _filterByCategory (input, category) { | ||
| 201 | + input = input || []; | ||
| 202 | + | ||
| 203 | + if (!category) { | ||
| 204 | + // no filter | ||
| 205 | + return input; | ||
| 206 | + } | ||
| 207 | + | ||
| 208 | + var out = []; | ||
| 209 | + for (var i = 0; i < input.length; i++) { | ||
| 210 | + var program = input[i]; | ||
| 211 | + if (program.categories[0].slug === category.slug) { | ||
| 212 | + out.push(program); | ||
| 213 | + } | ||
| 214 | + } | ||
| 215 | + | ||
| 216 | + return out; | ||
| 217 | + } | ||
| 218 | + | ||
| 219 | + function _balanceByCategory (input) { | ||
| 220 | + var result = []; | ||
| 221 | + var resultByCategory = {}; | ||
| 222 | + | ||
| 223 | + // divide by categories | ||
| 224 | + for (var i = 0; i < input.length; i++) { | ||
| 225 | + var program = input[i]; | ||
| 226 | + var categorySlug = program.categories[0].slug; | ||
| 227 | + | ||
| 228 | + if (!resultByCategory[categorySlug]) { | ||
| 229 | + resultByCategory[categorySlug] = []; | ||
| 230 | + } | ||
| 231 | + | ||
| 232 | + resultByCategory[categorySlug].push(program); | ||
| 233 | + } | ||
| 234 | + | ||
| 235 | + // shuffle each array | ||
| 236 | + var prop = null; | ||
| 237 | + var categoryWithPrograms = null; | ||
| 238 | + // for (prop in resultByCategory) { | ||
| 239 | + // if (resultByCategory.hasOwnProperty(prop)) { | ||
| 240 | + // categoryWithPrograms = resultByCategory[prop]; | ||
| 241 | + // resultByCategory[prop] = shuffle(categoryWithPrograms); | ||
| 242 | + // } | ||
| 243 | + // } | ||
| 244 | + | ||
| 245 | + // Concat all into result array | ||
| 246 | + // > while has program at Lists on resultByCategory | ||
| 247 | + var hasProgram = true; | ||
| 248 | + while (hasProgram) { | ||
| 249 | + | ||
| 250 | + var foundProgram = false; | ||
| 251 | + // each categoryList with array of program | ||
| 252 | + prop = null; | ||
| 253 | + categoryWithPrograms = null; | ||
| 254 | + for (prop in resultByCategory) { | ||
| 255 | + | ||
| 256 | + if (resultByCategory.hasOwnProperty(prop)) { | ||
| 257 | + categoryWithPrograms = resultByCategory[prop]; | ||
| 258 | + | ||
| 259 | + if (categoryWithPrograms.length > 0) { | ||
| 260 | + var pivotProgram = categoryWithPrograms.pop(); | ||
| 261 | + result.push(pivotProgram); | ||
| 262 | + foundProgram = true; | ||
| 263 | + } | ||
| 264 | + } | ||
| 265 | + } | ||
| 266 | + | ||
| 267 | + if (!foundProgram) { | ||
| 268 | + hasProgram = false; | ||
| 269 | + } | ||
| 270 | + } | ||
| 271 | + | ||
| 272 | + return result; | ||
| 273 | + } | ||
| 274 | + | ||
| 120 | function injectIframeApiJs() { | 275 | function injectIframeApiJs() { |
| 121 | var tag = document.createElement('script'); | 276 | var tag = document.createElement('script'); |
| 122 | tag.src = 'https://www.youtube.com/iframe_api'; | 277 | tag.src = 'https://www.youtube.com/iframe_api'; |
src/app/pages/inicio/inicio.html
| @@ -66,8 +66,8 @@ | @@ -66,8 +66,8 @@ | ||
| 66 | <div class="row visible-xs"> | 66 | <div class="row visible-xs"> |
| 67 | <div class="col-xs-12"> | 67 | <div class="col-xs-12"> |
| 68 | <div class="input-group input-group-lg input-group-search"> | 68 | <div class="input-group input-group-lg input-group-search"> |
| 69 | - <label for="articleQueryFilter" class="control-label sr-only">Buscar programas:</label> | ||
| 70 | - <input id="articleQueryFilter" type="search" class="form-control input-search" ng-model="pageInicio.query" placeholder="Buscar programas" aria-label="Buscar programas" > | 69 | + <label for="articleQueryFilter1" class="control-label sr-only">Buscar programas:</label> |
| 70 | + <input id="articleQueryFilter1" type="search" class="form-control input-search" ng-model="pageInicio.query" placeholder="Buscar programas" aria-label="Buscar programas" > | ||
| 71 | <span class="input-group-btn"> | 71 | <span class="input-group-btn"> |
| 72 | <button type="button" class="btn btn-default" ng-click="pageInicio.search()"> | 72 | <button type="button" class="btn btn-default" ng-click="pageInicio.search()"> |
| 73 | <span class="icon-circle icon-small color-theme-common-bg"> | 73 | <span class="icon-circle icon-small color-theme-common-bg"> |
| @@ -98,8 +98,8 @@ | @@ -98,8 +98,8 @@ | ||
| 98 | <div class="row hidden-xs"> | 98 | <div class="row hidden-xs"> |
| 99 | <div class="col-xs-12"> | 99 | <div class="col-xs-12"> |
| 100 | <div class="input-group input-group-lg input-group-search"> | 100 | <div class="input-group input-group-lg input-group-search"> |
| 101 | - <label for="articleQueryFilter" class="control-label sr-only">Buscar programas:</label> | ||
| 102 | - <input id="articleQueryFilter" type="search" class="form-control input-search" ng-model="pageInicio.query" placeholder="Buscar programas" aria-label="Buscar programas" > | 101 | + <label for="articleQueryFilter2" class="control-label sr-only">Buscar programas:</label> |
| 102 | + <input id="articleQueryFilter2" type="search" class="form-control input-search" ng-model="pageInicio.query" placeholder="Buscar programas" aria-label="Buscar programas" > | ||
| 103 | <span class="input-group-btn"> | 103 | <span class="input-group-btn"> |
| 104 | <button type="button" class="btn btn-default" ng-click="pageInicio.search()"> | 104 | <button type="button" class="btn btn-default" ng-click="pageInicio.search()"> |
| 105 | <span class="icon-circle icon-small color-theme-common-bg"> | 105 | <span class="icon-circle icon-small color-theme-common-bg"> |
| @@ -115,7 +115,7 @@ | @@ -115,7 +115,7 @@ | ||
| 115 | <div class="col-sm-12"> | 115 | <div class="col-sm-12"> |
| 116 | <header class="header"> | 116 | <header class="header"> |
| 117 | <h2>Programas</h2> | 117 | <h2>Programas</h2> |
| 118 | - <button type="button" class="btn btn-link" ng-click="pageInicio.showAll($event)"> | 118 | + <button type="button" class="btn btn-link" ng-click="pageInicio.showAllPrograms($event)"> |
| 119 | <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span> Ver todos os {{::pageInicio.programs.length}} programas | 119 | <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span> Ver todos os {{::pageInicio.programs.length}} programas |
| 120 | </button> | 120 | </button> |
| 121 | </header> | 121 | </header> |
src/app/pages/programas/programa-content.controller.js
| @@ -39,6 +39,13 @@ | @@ -39,6 +39,13 @@ | ||
| 39 | 39 | ||
| 40 | // Get program by slug | 40 | // Get program by slug |
| 41 | var slug = vm.$state.params.slug; | 41 | var slug = vm.$state.params.slug; |
| 42 | + | ||
| 43 | + if(!slug){ | ||
| 44 | + vm.$log.error('slug not defined.'); | ||
| 45 | + vm.$log.info('Rollback to home page.'); | ||
| 46 | + vm.$state.go('inicio', {}, {location: true}); | ||
| 47 | + } | ||
| 48 | + | ||
| 42 | vm.DialogaService.getProgramBySlug(slug, function(article) { | 49 | vm.DialogaService.getProgramBySlug(slug, function(article) { |
| 43 | vm.article = article; | 50 | vm.article = article; |
| 44 | vm.category = vm.article.categories[0]; | 51 | vm.category = vm.article.categories[0]; |
src/app/pages/programas/programas.controller.js
| @@ -6,39 +6,42 @@ | @@ -6,39 +6,42 @@ | ||
| 6 | .controller('ProgramasPageController', ProgramasPageController); | 6 | .controller('ProgramasPageController', ProgramasPageController); |
| 7 | 7 | ||
| 8 | /** @ngInject */ | 8 | /** @ngInject */ |
| 9 | - function ProgramasPageController(DialogaService, $log) { | 9 | + function ProgramasPageController(DialogaService, $scope, $location, $filter, $log) { |
| 10 | var vm = this; | 10 | var vm = this; |
| 11 | 11 | ||
| 12 | vm.DialogaService = DialogaService; | 12 | vm.DialogaService = DialogaService; |
| 13 | + vm.$scope = $scope; | ||
| 14 | + vm.$location = $location; | ||
| 15 | + vm.$filter = $filter; | ||
| 13 | vm.$log = $log; | 16 | vm.$log = $log; |
| 14 | 17 | ||
| 15 | vm.init(); | 18 | vm.init(); |
| 19 | + vm.loadData(); | ||
| 20 | + vm.attachListeners(); | ||
| 21 | + | ||
| 16 | $log.debug('ProgramasPageController'); | 22 | $log.debug('ProgramasPageController'); |
| 17 | } | 23 | } |
| 18 | 24 | ||
| 19 | ProgramasPageController.prototype.init = function () { | 25 | ProgramasPageController.prototype.init = function () { |
| 20 | var vm = this; | 26 | var vm = this; |
| 21 | 27 | ||
| 22 | - vm.article = null; | ||
| 23 | vm.themes = null; | 28 | vm.themes = null; |
| 24 | vm.selectedTheme = null; | 29 | vm.selectedTheme = null; |
| 25 | vm.programs = null; | 30 | vm.programs = null; |
| 26 | vm.filtredPrograms = null; | 31 | vm.filtredPrograms = null; |
| 27 | vm.query = null; | 32 | vm.query = null; |
| 33 | + vm.search = vm.$location.search(); | ||
| 28 | 34 | ||
| 29 | vm.loading = null; | 35 | vm.loading = null; |
| 30 | vm.error = null; | 36 | vm.error = null; |
| 31 | - | ||
| 32 | - vm.loadData(); | ||
| 33 | }; | 37 | }; |
| 34 | 38 | ||
| 35 | - | ||
| 36 | ProgramasPageController.prototype.loadData = function () { | 39 | ProgramasPageController.prototype.loadData = function () { |
| 37 | var vm = this; | 40 | var vm = this; |
| 38 | 41 | ||
| 39 | vm.loading = true; | 42 | vm.loading = true; |
| 40 | 43 | ||
| 41 | - // load Programs | 44 | + // // load Programs |
| 42 | vm.loadingPrograms = true; | 45 | vm.loadingPrograms = true; |
| 43 | vm.DialogaService.getPrograms(function(programs){ | 46 | vm.DialogaService.getPrograms(function(programs){ |
| 44 | vm.programs = programs; | 47 | vm.programs = programs; |
| @@ -61,4 +64,165 @@ | @@ -61,4 +64,165 @@ | ||
| 61 | vm.loadingThemes = false; | 64 | vm.loadingThemes = false; |
| 62 | }); | 65 | }); |
| 63 | }; | 66 | }; |
| 67 | + | ||
| 68 | + ProgramasPageController.prototype.attachListeners = function() { | ||
| 69 | + var vm = this; | ||
| 70 | + | ||
| 71 | + vm.$scope.$on('change-selectedCategory', function (event, selectedCategory) { | ||
| 72 | + vm.selectedTheme = selectedCategory; | ||
| 73 | + vm.$log.debug('vm.selectedTheme', vm.selectedTheme); | ||
| 74 | + }); | ||
| 75 | + | ||
| 76 | + vm.$scope.$watch('pageProgramas.selectedTheme', function(newValue/*, oldValue*/) { | ||
| 77 | + vm.search.tema = newValue ? newValue.slug : null; | ||
| 78 | + vm.$location.search('tema', vm.search.tema); | ||
| 79 | + vm.filtredPrograms = vm.getFiltredPrograms(); | ||
| 80 | + }); | ||
| 81 | + | ||
| 82 | + vm.$scope.$watch('pageProgramas.query', function(newValue/*, oldValue*/) { | ||
| 83 | + vm.search.filtro = newValue ? newValue : null; | ||
| 84 | + vm.$location.search('filtro', vm.search.filtro); | ||
| 85 | + vm.filtredPrograms = vm.getFiltredPrograms(); | ||
| 86 | + }); | ||
| 87 | + }; | ||
| 88 | + | ||
| 89 | + ProgramasPageController.prototype.filter = function() { | ||
| 90 | + var vm = this; | ||
| 91 | + | ||
| 92 | + if (vm.search && vm.search.tema) { | ||
| 93 | + var slug = vm.search.tema; | ||
| 94 | + vm.$log.debug('filter by theme', slug); | ||
| 95 | + | ||
| 96 | + vm.DialogaService.getThemeBySlug(slug, function(theme){ | ||
| 97 | + vm.selectedTheme = theme; | ||
| 98 | + vm.$log.debug('getThemeBySlug.slug', slug); | ||
| 99 | + vm.$log.debug('getThemeBySlug.selectedTheme', theme); | ||
| 100 | + }, function(error){ | ||
| 101 | + vm.$log.error('Error when try to "getThemeBySlug"', error); | ||
| 102 | + }); | ||
| 103 | + } | ||
| 104 | + }; | ||
| 105 | + | ||
| 106 | + ProgramasPageController.prototype.showAllPrograms = function($event) { | ||
| 107 | + var vm = this; | ||
| 108 | + $event.stopPropagation(); | ||
| 109 | + | ||
| 110 | + vm.resetFilterValues(); | ||
| 111 | + | ||
| 112 | + vm._showAllFlag = true; | ||
| 113 | + | ||
| 114 | + vm.filtredPrograms = vm.getFiltredPrograms(); | ||
| 115 | + }; | ||
| 116 | + | ||
| 117 | + ProgramasPageController.prototype.resetFilterValues = function() { | ||
| 118 | + var vm = this; | ||
| 119 | + | ||
| 120 | + vm.query = null; | ||
| 121 | + vm.selectedTheme = null; | ||
| 122 | + }; | ||
| 123 | + | ||
| 124 | + ProgramasPageController.prototype.getFiltredPrograms = function() { | ||
| 125 | + var vm = this; | ||
| 126 | + | ||
| 127 | + if(!vm.programs){ | ||
| 128 | + vm.$log.warn('No programs loaded yet. Abort.'); | ||
| 129 | + return null; | ||
| 130 | + } | ||
| 131 | + | ||
| 132 | + var input = vm.programs; | ||
| 133 | + var output = input; | ||
| 134 | + var query = vm.query; | ||
| 135 | + var selectedTheme = vm.selectedTheme; | ||
| 136 | + | ||
| 137 | + var filter = vm.$filter('filter'); | ||
| 138 | + | ||
| 139 | + if (selectedTheme) { | ||
| 140 | + output = _filterByCategory(output, selectedTheme); | ||
| 141 | + } | ||
| 142 | + | ||
| 143 | + if (query) { | ||
| 144 | + output = filter(output, query, false); | ||
| 145 | + } | ||
| 146 | + | ||
| 147 | + if(!query && !selectedTheme && vm._showAllFlag){ | ||
| 148 | + output = _balanceByCategory(output); | ||
| 149 | + } | ||
| 150 | + | ||
| 151 | + return output; | ||
| 152 | + }; | ||
| 153 | + | ||
| 154 | + function _filterByCategory (input, category) { | ||
| 155 | + input = input || []; | ||
| 156 | + | ||
| 157 | + if (!category) { | ||
| 158 | + // no filter | ||
| 159 | + return input; | ||
| 160 | + } | ||
| 161 | + | ||
| 162 | + var out = []; | ||
| 163 | + for (var i = 0; i < input.length; i++) { | ||
| 164 | + var program = input[i]; | ||
| 165 | + if (program.categories[0].slug === category.slug) { | ||
| 166 | + out.push(program); | ||
| 167 | + } | ||
| 168 | + } | ||
| 169 | + | ||
| 170 | + return out; | ||
| 171 | + } | ||
| 172 | + | ||
| 173 | + function _balanceByCategory (input) { | ||
| 174 | + var result = []; | ||
| 175 | + var resultByCategory = {}; | ||
| 176 | + | ||
| 177 | + // divide by categories | ||
| 178 | + for (var i = 0; i < input.length; i++) { | ||
| 179 | + var program = input[i]; | ||
| 180 | + var categorySlug = program.categories[0].slug; | ||
| 181 | + | ||
| 182 | + if (!resultByCategory[categorySlug]) { | ||
| 183 | + resultByCategory[categorySlug] = []; | ||
| 184 | + } | ||
| 185 | + | ||
| 186 | + resultByCategory[categorySlug].push(program); | ||
| 187 | + } | ||
| 188 | + | ||
| 189 | + // shuffle each array | ||
| 190 | + var prop = null; | ||
| 191 | + var categoryWithPrograms = null; | ||
| 192 | + // for (prop in resultByCategory) { | ||
| 193 | + // if (resultByCategory.hasOwnProperty(prop)) { | ||
| 194 | + // categoryWithPrograms = resultByCategory[prop]; | ||
| 195 | + // resultByCategory[prop] = shuffle(categoryWithPrograms); | ||
| 196 | + // } | ||
| 197 | + // } | ||
| 198 | + | ||
| 199 | + // Concat all into result array | ||
| 200 | + // > while has program at Lists on resultByCategory | ||
| 201 | + var hasProgram = true; | ||
| 202 | + while (hasProgram) { | ||
| 203 | + | ||
| 204 | + var foundProgram = false; | ||
| 205 | + // each categoryList with array of program | ||
| 206 | + prop = null; | ||
| 207 | + categoryWithPrograms = null; | ||
| 208 | + for (prop in resultByCategory) { | ||
| 209 | + | ||
| 210 | + if (resultByCategory.hasOwnProperty(prop)) { | ||
| 211 | + categoryWithPrograms = resultByCategory[prop]; | ||
| 212 | + | ||
| 213 | + if (categoryWithPrograms.length > 0) { | ||
| 214 | + var pivotProgram = categoryWithPrograms.pop(); | ||
| 215 | + result.push(pivotProgram); | ||
| 216 | + foundProgram = true; | ||
| 217 | + } | ||
| 218 | + } | ||
| 219 | + } | ||
| 220 | + | ||
| 221 | + if (!foundProgram) { | ||
| 222 | + hasProgram = false; | ||
| 223 | + } | ||
| 224 | + } | ||
| 225 | + | ||
| 226 | + return result; | ||
| 227 | + } | ||
| 64 | })(); | 228 | })(); |
src/app/pages/programas/programas.html
| @@ -72,7 +72,7 @@ | @@ -72,7 +72,7 @@ | ||
| 72 | <div class="col-sm-12"> | 72 | <div class="col-sm-12"> |
| 73 | <header class="header"> | 73 | <header class="header"> |
| 74 | <h2>Conheça os programas</h2> | 74 | <h2>Conheça os programas</h2> |
| 75 | - <button type="button" class="btn btn-link" ng-click="pageProgramas.showAll($event)"> | 75 | + <button type="button" class="btn btn-link" ng-click="pageProgramas.showAllPrograms($event)"> |
| 76 | <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span> Ver todos os {{::pageProgramas.programs.length}} programas | 76 | <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span> Ver todos os {{::pageProgramas.programs.length}} programas |
| 77 | </button> | 77 | </button> |
| 78 | </header> | 78 | </header> |
src/assets/images/icons/sprite.png