Commit a140a68dc0354cd9134d3e1fd4f62cf2a1eb0d81
1 parent
4ff60ea5
Exists in
master
and in
6 other branches
Add page 'Respostas' (issue #52)
Showing
5 changed files
with
326 additions
and
0 deletions
Show diff stats
src/app/components/app-navbar/app-navbar.html
... | ... | @@ -32,6 +32,7 @@ |
32 | 32 | <li ui-sref-active="active"><a ui-sref="propostas">Propostas</a></li> |
33 | 33 | <li ui-sref-active="active"><a ui-sref="ranking">Ranking</a></li> |
34 | 34 | <li ui-sref-active="active"><a ui-sref="duvidas">Dúvidas</a></li> |
35 | + <li ui-sref-active="active"><a ui-sref="respostas">Respostas</a></li> | |
35 | 36 | <li role="separator" class="divider hidden-xs hidden-sm"><span>|</span></li> |
36 | 37 | <li class="dropdown" style="border: none;"> |
37 | 38 | <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Compartilhar <span aria-hidden="true" class="icon icon-social-share-small"></span></a> | ... | ... |
src/app/index.route.js
... | ... | @@ -148,6 +148,18 @@ |
148 | 148 | } |
149 | 149 | } |
150 | 150 | }) |
151 | + .state('respostas', { | |
152 | + url: '/respostas?tema&filtro&task', | |
153 | + reloadOnSearch: false, | |
154 | + ncyBreadcrumb: {label: 'Respostas'}, | |
155 | + views: { | |
156 | + 'main': { | |
157 | + templateUrl: 'app/pages/respostas/respostas.html', | |
158 | + controller: 'RespostasPageController', | |
159 | + controllerAs: 'pageRespostas' | |
160 | + } | |
161 | + } | |
162 | + }) | |
151 | 163 | .state('sobre', { |
152 | 164 | url: '/sobre', |
153 | 165 | ncyBreadcrumb: {label: 'Sobre'}, | ... | ... |
... | ... | @@ -0,0 +1,180 @@ |
1 | +(function() { | |
2 | + 'use strict'; | |
3 | + | |
4 | + angular | |
5 | + .module('dialoga') | |
6 | + .controller('RespostasPageController', RespostasPageController); | |
7 | + | |
8 | + /** @ngInject */ | |
9 | + function RespostasPageController(DialogaService, $scope, $rootScope, $location, $filter, $log) { | |
10 | + var vm = this; | |
11 | + | |
12 | + vm.DialogaService = DialogaService; | |
13 | + vm.$scope = $scope; | |
14 | + vm.$rootScope = $rootScope; | |
15 | + vm.$location = $location; | |
16 | + vm.$filter = $filter; | |
17 | + vm.$log = $log; | |
18 | + | |
19 | + vm.init(); | |
20 | + vm.loadData(); | |
21 | + // vm.attachListeners(); // attach listeners after load data (SYNC) | |
22 | + vm.$rootScope.focusMainContent(); | |
23 | + | |
24 | + $log.debug('RespostasPageController'); | |
25 | + } | |
26 | + | |
27 | + RespostasPageController.prototype.init = function() { | |
28 | + var vm = this; | |
29 | + | |
30 | + vm.page = 1; | |
31 | + vm.per_page = 10; | |
32 | + vm.themes = null; | |
33 | + vm.selectedTheme = null; | |
34 | + vm.filtredPrograms = null; | |
35 | + vm.filtredProposals = null; | |
36 | + vm.query = null; | |
37 | + vm.search = vm.$location.search(); | |
38 | + | |
39 | + vm.loading = null; | |
40 | + vm.error = null; | |
41 | + }; | |
42 | + | |
43 | + RespostasPageController.prototype.loadData = function() { | |
44 | + var vm = this; | |
45 | + | |
46 | + vm.loading = true; | |
47 | + | |
48 | + // Behaviour: | |
49 | + // 1. Load themes | |
50 | + // 1. Load Proposals per_page | |
51 | + // END. | |
52 | + | |
53 | + // 1. Load themes | |
54 | + vm.loadingThemes = true; | |
55 | + vm.DialogaService.getThemes(function(themes) { | |
56 | + vm.themes = themes; | |
57 | + vm.loadingThemes = false; | |
58 | + vm.loading = false; | |
59 | + | |
60 | + // REMOVED: function called twice. | |
61 | + // vm.loadProposals(function() { | |
62 | + // vm.attachListeners(); | |
63 | + // }); | |
64 | + vm.attachListeners(); | |
65 | + }, function(error) { | |
66 | + vm.error = error; | |
67 | + vm.$log.error(error); | |
68 | + vm.loadingThemes = false; | |
69 | + vm.loading = false; | |
70 | + }); | |
71 | + }; | |
72 | + | |
73 | + // RespostasPageController.prototype.loadProposals = function(cb) { | |
74 | + // var vm = this; | |
75 | + | |
76 | + // // load Proposals | |
77 | + // vm.loadingProposals = true; | |
78 | + // vm.DialogaService.searchProposals({ | |
79 | + // page: vm.page, | |
80 | + // per_page: vm.per_page | |
81 | + // }, function(data) { | |
82 | + // vm.filtredProposals = data.articles; | |
83 | + // vm.total_proposals = parseInt(data._obj.headers('total')); | |
84 | + | |
85 | + // vm.loadingProposals = false; | |
86 | + | |
87 | + // if (cb) { | |
88 | + // cb(); | |
89 | + // } | |
90 | + // }, function(error) { | |
91 | + // vm.error = error; | |
92 | + // vm.$log.error(error); | |
93 | + // vm.loadingProposals = false; | |
94 | + // }); | |
95 | + // }; | |
96 | + | |
97 | + RespostasPageController.prototype.attachListeners = function() { | |
98 | + var vm = this; | |
99 | + | |
100 | + vm.$scope.$on('change-selectedCategory', function(event, selectedCategory) { | |
101 | + vm.selectedTheme = selectedCategory; | |
102 | + }); | |
103 | + | |
104 | + vm.$scope.$watch('pagePropostas.selectedTheme', function(newValue/*, oldValue*/) { | |
105 | + vm.search.tema = newValue ? newValue.slug : null; | |
106 | + vm.$location.search('tema', vm.search.tema); | |
107 | + vm.filterProposals(); | |
108 | + }); | |
109 | + | |
110 | + vm.$scope.$watch('pagePropostas.query', function(newValue/*, oldValue*/) { | |
111 | + vm.search.filtro = newValue ? newValue : null; | |
112 | + vm.$location.search('filtro', vm.search.filtro); | |
113 | + vm.filterProposals(); | |
114 | + }); | |
115 | + }; | |
116 | + | |
117 | + RespostasPageController.prototype.resetFilterValues = function() { | |
118 | + var vm = this; | |
119 | + | |
120 | + vm.query = null; | |
121 | + vm.selectedTheme = null; | |
122 | + }; | |
123 | + | |
124 | + RespostasPageController.prototype.changePage = function(pageIndex) { | |
125 | + var vm = this; | |
126 | + | |
127 | + vm.page = pageIndex; | |
128 | + vm.filterProposals(pageIndex); | |
129 | + }; | |
130 | + | |
131 | + RespostasPageController.prototype.filterProposals = function(_page, _per_page) { | |
132 | + var vm = this; | |
133 | + | |
134 | + if (vm.loadingProposals){ | |
135 | + vm.$log.debug('Content is not loaded yet.'); | |
136 | + return; | |
137 | + } | |
138 | + | |
139 | + var page = _page || vm.page; | |
140 | + var per_page = _per_page || vm.per_page; | |
141 | + var query = vm.query; | |
142 | + var params = { | |
143 | + page: page, | |
144 | + per_page: per_page, | |
145 | + }; | |
146 | + | |
147 | + if (vm.selectedTheme) { | |
148 | + params.category_ids = vm.selectedTheme.id; | |
149 | + } | |
150 | + | |
151 | + if (query) {params.query = query; } | |
152 | + | |
153 | + vm.loadingProposals = true; | |
154 | + vm.DialogaService.searchProposals(params, function(data){ | |
155 | + vm.total_proposals = parseInt(data._obj.headers('total')); | |
156 | + vm.filtredProposals = data.articles; | |
157 | + vm.loadingProposals = false; | |
158 | + }, function (error) { | |
159 | + vm.error = error; | |
160 | + vm.$log.error(error); | |
161 | + vm.loadingProposals = false; | |
162 | + }); | |
163 | + }; | |
164 | + | |
165 | + RespostasPageController.prototype.submitSearch = function() { | |
166 | + var vm = this; | |
167 | + | |
168 | + vm.loadingFilter = true; | |
169 | + | |
170 | + // scroll to result grid | |
171 | + var $searchResult = angular.element('#search-result'); | |
172 | + if ($searchResult && $searchResult.length > 0) { | |
173 | + angular.element('html,body').animate({scrollTop: $searchResult.offset().top}, 'fast'); | |
174 | + vm.filterProposals(); | |
175 | + }else { | |
176 | + vm.$log.warn('#search-result element not found.'); | |
177 | + } | |
178 | + }; | |
179 | + | |
180 | +})(); | ... | ... |
... | ... | @@ -0,0 +1,124 @@ |
1 | +<div class="container"> | |
2 | + <div class="row"> | |
3 | + <div class="col-sm-12"> | |
4 | + <div ncy-breadcrumb></div> | |
5 | + </div> | |
6 | + </div> | |
7 | +</div> | |
8 | + | |
9 | +<div class="page--respostas" role="main"> | |
10 | + <section class="section-info" ng-if="pageRespostas.loading || pageRespostas.error"> | |
11 | + <div class="container"> | |
12 | + <div class="row"> | |
13 | + <div class="col-md-12"> | |
14 | + <div ng-if="pageRespostas.loading && !pageRespostas.error"> | |
15 | + <div class="alert alert-info" role="alert">Carregando conteúdo...</div> | |
16 | + </div> | |
17 | + | |
18 | + <div ng-if="pageRespostas.error"> | |
19 | + <div class="alert alert-danger" role="alert"> | |
20 | + Erro ao carregar o conteúdo principal. | |
21 | + </div> | |
22 | + </div> | |
23 | + </div> | |
24 | + </div> | |
25 | + </div> | |
26 | + </section> | |
27 | + | |
28 | + <section class="section--header" ng-if="pageRespostas.filtredProposals || pageRespostas.themes"> | |
29 | + <div class="container"> | |
30 | + <div class="row"> | |
31 | + <div class="col-sm-12"> | |
32 | + <h1>Respostas</h1> | |
33 | + </div> | |
34 | + </div> | |
35 | + </div> | |
36 | + </section> | |
37 | + | |
38 | + <section class="section--articles section-gray section-space-up" ng-if="pageRespostas.filtredProposals || pageRespostas.themes"> | |
39 | + <div class="container"> | |
40 | + <div id="lista-de-respostas" class="row"> | |
41 | + <div class="col-sm-4 col-md-3"> | |
42 | + <div class="row visible-xs"> | |
43 | + <div class="col-xs-12"> | |
44 | + <div class="input-group input-group-lg input-group-search"> | |
45 | + <label for="articleQueryFilter" class="control-label sr-only">Buscar respostas:</label> | |
46 | + <input id="articleQueryFilter" type="search" class="form-control input-search" ng-model="pageRespostas.query" placeholder="Buscar respostas" aria-label="Buscar respostas"> | |
47 | + <span class="input-group-btn"> | |
48 | + <button type="button" class="btn btn-default" ng-click="pageRespostas.submitSearch()"> | |
49 | + <span class="icon-circle icon-small color-theme-common-bg"> | |
50 | + <span class="glyphicon glyphicon-search"></span> | |
51 | + </span> | |
52 | + <span class="sr-only">Buscar</span> | |
53 | + </button> | |
54 | + </span> | |
55 | + </div> | |
56 | + <br/> | |
57 | + </div> | |
58 | + </div> | |
59 | + <div ng-if="pageRespostas.themes"> | |
60 | + <category-list categories="pageRespostas.themes" selected-category="pageRespostas.selectedTheme"></category-list> | |
61 | + </div> | |
62 | + <div ng-if="!pageRespostas.themes && pageRespostas.loadingThemes"> | |
63 | + <div class="alert alert-info" role="alert"> | |
64 | + Carregando temas. | |
65 | + </div> | |
66 | + </div> | |
67 | + <div ng-if="!pageRespostas.themes && pageRespostas.themesError"> | |
68 | + <div class="alert alert-danger" role="alert"> | |
69 | + Não foi possível carregar a lista de temas neste momento. | |
70 | + </div> | |
71 | + </div> | |
72 | + </div> | |
73 | + <div class="col-sm-8 col-md-9"> | |
74 | + <div class="row hidden-xs" ng-if="pageRespostas.filtredProposals"> | |
75 | + <div class="col-xs-12"> | |
76 | + <div class="input-group input-group-lg input-group-search"> | |
77 | + <label for="articleQueryFilter" class="control-label sr-only">Buscar respostas:</label> | |
78 | + <input id="articleQueryFilter" type="search" class="form-control input-search" ng-model="pageRespostas.query" placeholder="Buscar respostas" aria-label="Buscar respostas"> | |
79 | + <span class="input-group-btn"> | |
80 | + <button type="button" class="btn btn-default" ng-click="pageRespostas.submitSearch()"> | |
81 | + <span class="icon-circle icon-small color-theme-common-bg"> | |
82 | + <span class="glyphicon glyphicon-search"></span> | |
83 | + </span> | |
84 | + <span class="sr-only">Buscar</span> | |
85 | + </button> | |
86 | + </span> | |
87 | + </div> | |
88 | + </div> | |
89 | + </div> | |
90 | + | |
91 | + <div id="search-result" class="row" ng-if="pageRespostas.filtredProposals"> | |
92 | + <div class="col-sm-12"> | |
93 | + <header class="header"> | |
94 | + <h2>Total de Respostas: "<b>{{pageRespostas.total_proposals}} respostas</b>"</h2> | |
95 | + </header> | |
96 | + </div> | |
97 | + </div> | |
98 | + | |
99 | + <div class="row"> | |
100 | + <div class="col-sm-12" ng-if="!pageRespostas.loadingProposals && pageRespostas.filtredProposals && pageRespostas.total_proposals"> | |
101 | + <proposal-grid proposals="pageRespostas.filtredProposals"></proposal-grid> | |
102 | + <app-paginator | |
103 | + page="pageRespostas.page" | |
104 | + per-page="pageRespostas.per_page" | |
105 | + total="pageRespostas.total_proposals" | |
106 | + change-page="pageRespostas.changePage(pageIndex)" | |
107 | + ></app-paginator> | |
108 | + </div> | |
109 | + <div ng-if="pageRespostas.loadingProposals"> | |
110 | + <div class="alert alert-info" role="alert"> | |
111 | + Carregando respostas. | |
112 | + </div> | |
113 | + </div> | |
114 | + <div ng-if="!pageRespostas.loadingProposals && pageRespostas.proposalsError"> | |
115 | + <div class="alert alert-danger" role="alert"> | |
116 | + Não foi possível carregar a lista de respostas neste momento. | |
117 | + </div> | |
118 | + </div> | |
119 | + </div> | |
120 | + </div> | |
121 | + </div> | |
122 | + </div> | |
123 | + </section> | |
124 | +</div> | ... | ... |