Commit 5d0de01968043c0630c3a1567827dfaa9e7a5a47

Authored by Leonardo Merlin
1 parent 1ea912ba

Fix 'participe' at proposal-box

src/app/components/article-service/article.service.js
@@ -19,6 +19,7 @@ @@ -19,6 +19,7 @@
19 getTopics: getTopics, 19 getTopics: getTopics,
20 getTopicById: getTopicById, 20 getTopicById: getTopicById,
21 getProposals: getProposals, 21 getProposals: getProposals,
  22 + getProposalById: getProposalById,
22 getProposalsByTopicId: getProposalsByTopicId, 23 getProposalsByTopicId: getProposalsByTopicId,
23 getEvents: getEvents, 24 getEvents: getEvents,
24 subscribeToEvent: subscribeToEvent, 25 subscribeToEvent: subscribeToEvent,
@@ -108,26 +109,18 @@ @@ -108,26 +109,18 @@
108 // }); 109 // });
109 110
110 // 111 //
111 - searchTopics(params, cbSuccess, cbError); 112 + searchProposals({
  113 + query: ''
  114 + }, cbSuccess, cbError);
112 } 115 }
113 116
114 - /**  
115 - * Ex.: /api/v1/articles/[article_id]/children?[params]content_type=ProposalsDiscussionPlugin::Proposal  
116 - * Ex.: /api/v1/articles/103644/children?limit=20&fields=id,name,slug,abstract,created_by&content_type=ProposalsDiscussionPlugin::Proposal  
117 - *  
118 - * @param {Integer} topicId topic where has those proposals  
119 - * @param {Object} params params for pagination ant others  
120 - * @param {Function} cbSuccess callback for success  
121 - * @param {Function} cbError callback for error  
122 - * @return {Array} [description]  
123 - */  
124 - function getProposalsByTopicId (topicId, params, cbSuccess, cbError) {  
125 - var url = service.apiArticles + topicId + '/children'; 117 + function getProposalById (proposalId, params, cbSuccess, cbError) {
  118 + var url = service.apiArticles + proposalId;
126 119
127 var paramsExtended = angular.extend({ 120 var paramsExtended = angular.extend({
128 // 'fields[]': ['id', 'title', 'abstract', 'children', 'children_count', 'ranking_position', 'hits', 'votes_for', 'votes_against'], 121 // 'fields[]': ['id', 'title', 'abstract', 'children', 'children_count', 'ranking_position', 'hits', 'votes_for', 'votes_against'],
129 - // 'limit':'20',  
130 // 'per_page':'1', 122 // 'per_page':'1',
  123 + 'limit':'1',
131 'content_type':'ProposalsDiscussionPlugin::Proposal' 124 'content_type':'ProposalsDiscussionPlugin::Proposal'
132 }, params); 125 }, params);
133 126
@@ -137,6 +130,21 @@ @@ -137,6 +130,21 @@
137 }).catch(function(error){ 130 }).catch(function(error){
138 cbError(error); 131 cbError(error);
139 }); 132 });
  133 +
  134 + }
  135 +
  136 + /**
  137 + * Ex.: /api/v1/articles/[article_id]/children?[params]content_type=ProposalsDiscussionPlugin::Proposal
  138 + * Ex.: /api/v1/articles/103644/children?limit=20&fields=id,name,slug,abstract,created_by&content_type=ProposalsDiscussionPlugin::Proposal
  139 + *
  140 + * @param {Integer} topicId topic where has those proposals
  141 + * @param {Object} params params for pagination ant others
  142 + * @param {Function} cbSuccess callback for success
  143 + * @param {Function} cbError callback for error
  144 + * @return {Array} [description]
  145 + */
  146 + function getProposalsByTopicId (topicId, params, cbSuccess, cbError) {
  147 + getProposalById(topicId + '/children', params, cbSuccess, cbError);
140 } 148 }
141 149
142 function getEvents (community_id, params, cbSuccess, cbError) { 150 function getEvents (community_id, params, cbSuccess, cbError) {
@@ -205,11 +213,12 @@ @@ -205,11 +213,12 @@
205 // Ex.: /api/v1/search/article?type=ProposalsDiscussionPlugin::Proposal&query=cisternas 213 // Ex.: /api/v1/search/article?type=ProposalsDiscussionPlugin::Proposal&query=cisternas
206 var url = '/api/v1/search/article'; 214 var url = '/api/v1/search/article';
207 var paramsExtended = angular.extend({ 215 var paramsExtended = angular.extend({
208 - 'fields[]': ['id', 'title', 'slug', 'abstract', 'categories', 'setting', 'children_count', 'hits'], 216 + // 'fields[]': ['id', 'title', 'slug', 'abstract', 'categories', 'setting', 'children_count', 'hits'],
209 'type': 'ProposalsDiscussionPlugin::Proposal' 217 'type': 'ProposalsDiscussionPlugin::Proposal'
210 }, params); 218 }, params);
211 219
212 UtilService.get(url, {params: paramsExtended}).then(function(data){ 220 UtilService.get(url, {params: paramsExtended}).then(function(data){
  221 + _pipeInjectSlugIntoParentProgram(data);
213 cbSuccess(data); 222 cbSuccess(data);
214 }).catch(function(error){ 223 }).catch(function(error){
215 cbError(error); 224 cbError(error);
@@ -217,6 +226,9 @@ @@ -217,6 +226,9 @@
217 } 226 }
218 227
219 function _pipeInjectSlugIntoParentProgram(data){ 228 function _pipeInjectSlugIntoParentProgram(data){
  229 + if(!data.articles && data.article){
  230 + data.articles = [data.article];
  231 + }
220 var proposals = data.articles; 232 var proposals = data.articles;
221 for (var i = proposals.length - 1; i >= 0; i--) { 233 for (var i = proposals.length - 1; i >= 0; i--) {
222 var proposal = proposals[i]; 234 var proposal = proposals[i];
src/app/components/proposal-box/proposal-box.directive.js
@@ -27,11 +27,12 @@ @@ -27,11 +27,12 @@
27 27
28 }; 28 };
29 29
30 - ProposalBoxController.prototype.showContent2 = function (topic) { 30 + ProposalBoxController.prototype.showContent = function (slug) {
31 var vm = this; 31 var vm = this;
32 32
33 vm.$state.go('programa-conteudo', { 33 vm.$state.go('programa-conteudo', {
34 - slug: topic.slug 34 + slug: slug,
  35 + proposal_id: vm.proposal.id
35 }, { 36 }, {
36 location: true 37 location: true
37 }); 38 });
src/app/components/proposal-box/proposal-box.html
@@ -5,10 +5,13 @@ @@ -5,10 +5,13 @@
5 </div> 5 </div>
6 <div class="proposal-box--middle"> 6 <div class="proposal-box--middle">
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">{{::vm.proposal.abstract}}</div>
9 </div> 9 </div>
10 - <div ng-show="!vm.vote" class="proposal-box--join">  
11 - <button class="btn btn-link" ng-click="vm.showContent2(vm.topic)">Participe</button> 10 + <div ng-hide="vm.vote" class="proposal-box--join">
  11 + <button class="btn btn-link color-theme-common-fg" ng-click="vm.showContent(vm.topic.slug)">
  12 + Participe
  13 + <span class="glyphicon glyphicon-menu-right color-theme-common-fg" aria-hidde="true"></span>
  14 + </button>
12 </div> 15 </div>
13 <div ng-show="vm.vote"class="proposal-box--actions text-center"> 16 <div ng-show="vm.vote"class="proposal-box--actions text-center">
14 <div class="row"> 17 <div class="row">
src/app/components/proposal-box/proposal-box.scss
@@ -2,6 +2,7 @@ @@ -2,6 +2,7 @@
2 background-color: #f1f1f1; 2 background-color: #f1f1f1;
3 border-radius: 5px; 3 border-radius: 5px;
4 // overflow: hidden; 4 // overflow: hidden;
  5 + margin-bottom: 20px;
5 6
6 &.focus { 7 &.focus {
7 border: 7px solid #000; 8 border: 7px solid #000;
@@ -20,6 +21,14 @@ @@ -20,6 +21,14 @@
20 21
21 &--middle { 22 &--middle {
22 padding: 30px; 23 padding: 30px;
  24 + min-height: 180px;
  25 +
  26 + // position: relative;
  27 + // .proposal-box--join {
  28 + // position: absolute;
  29 + // bottom: 10px;
  30 + // left: 30px;
  31 + // }
23 } 32 }
24 33
25 &--bottom { 34 &--bottom {
@@ -56,17 +65,27 @@ @@ -56,17 +65,27 @@
56 margin-top: 10px; 65 margin-top: 10px;
57 } 66 }
58 67
  68 + .proposal-box--join {
  69 + .btn {
  70 + font-weight: bold;
  71 + }
  72 + }
  73 +
  74 + .action {
  75 + .glyphicon {
  76 + color: #fff;
  77 + }
  78 + }
  79 +
59 .dropdown { 80 .dropdown {
60 display: inline-block; 81 display: inline-block;
61 } 82 }
  83 +
62 .dropdown-menu { 84 .dropdown-menu {
63 padding: 0; 85 padding: 0;
64 margin: 0; 86 margin: 0;
65 } 87 }
66 88
67 - .glyphicon {  
68 - color: #fff;  
69 - }  
70 .icon-circle { 89 .icon-circle {
71 cursor: pointer; 90 cursor: pointer;
72 91
src/app/components/proposal-grid/proposal-grid.directive.js
@@ -22,7 +22,6 @@ @@ -22,7 +22,6 @@
22 vm.$location = $location; 22 vm.$location = $location;
23 vm.$filter = $filter; 23 vm.$filter = $filter;
24 vm.$log = $log; 24 vm.$log = $log;
25 - vm.defaultLimit = 6;  
26 25
27 // initialization 26 // initialization
28 vm.init(); 27 vm.init();
@@ -30,8 +29,7 @@ @@ -30,8 +29,7 @@
30 } 29 }
31 30
32 ProposalGridController.prototype.init = function() { 31 ProposalGridController.prototype.init = function() {
33 - // var vm = this;  
34 - // vm.programs = null; // scope var 32 + var vm = this;
35 }; 33 };
36 34
37 ProposalGridController.prototype.attachListeners = function() { 35 ProposalGridController.prototype.attachListeners = function() {
src/app/index.route.js
@@ -88,7 +88,7 @@ @@ -88,7 +88,7 @@
88 } 88 }
89 }) 89 })
90 .state('programa-conteudo', { 90 .state('programa-conteudo', {
91 - url: '/programa/:slug', 91 + url: '/programa/:slug?proposal_id',
92 ncyBreadcrumb: { 92 ncyBreadcrumb: {
93 label: '{{$parent.$root.contentTitle}}', 93 label: '{{$parent.$root.contentTitle}}',
94 parent: 'programas' 94 parent: 'programas'
src/app/pages/programas/programa-content.controller.js
@@ -6,13 +6,14 @@ @@ -6,13 +6,14 @@
6 .controller('ProgramaContentPageController', ProgramaContentPageController); 6 .controller('ProgramaContentPageController', ProgramaContentPageController);
7 7
8 /** @ngInject */ 8 /** @ngInject */
9 - function ProgramaContentPageController(DialogaService, $state, $scope, $rootScope, $element, $log) { 9 + function ProgramaContentPageController(DialogaService, $state, $location, $scope, $rootScope, $element, $log) {
10 $log.debug('ProgramaContentPageController'); 10 $log.debug('ProgramaContentPageController');
11 11
12 var vm = this; 12 var vm = this;
13 13
14 vm.DialogaService = DialogaService; 14 vm.DialogaService = DialogaService;
15 vm.$state = $state; 15 vm.$state = $state;
  16 + vm.$location = $location;
16 vm.$scope = $scope; 17 vm.$scope = $scope;
17 vm.$rootScope = $rootScope; 18 vm.$rootScope = $rootScope;
18 vm.$element = $element; 19 vm.$element = $element;
@@ -28,6 +29,7 @@ @@ -28,6 +29,7 @@
28 29
29 vm.article = null; 30 vm.article = null;
30 vm.category = null; 31 vm.category = null;
  32 + vm.search = vm.$location.search();
31 33
32 vm.error = false; 34 vm.error = false;
33 }; 35 };
@@ -68,15 +70,33 @@ @@ -68,15 +70,33 @@
68 vm.$log.error(error); 70 vm.$log.error(error);
69 }); 71 });
70 72
71 - // get random proposal  
72 - vm.DialogaService.getProposalsByTopicId(vm.article.id, {  
73 - 'order': 'random()',  
74 - 'limit': '1'  
75 - }, function(data){  
76 - vm.randomProposal = data.articles[0];  
77 - }, function (error) { 73 + if(vm.search.proposal_id){
  74 + var proposalUrlId = vm.search.proposal_id;
  75 + vm.DialogaService.getProposalById(proposalUrlId, {
  76 + 'limit': '1'
  77 + }, _handleSuccessGetProposal, _handleErrorGetProposal);
  78 +
  79 + }else{
  80 + // get random proposal
  81 + vm.DialogaService.getProposalsByTopicId(vm.article.id, {
  82 + 'order': 'random()',
  83 + 'limit': '1'
  84 + }, _handleSuccessGetProposal, _handleErrorGetProposal);
  85 + }
  86 +
  87 + function _handleSuccessGetProposal(data){
  88 + if(data && data.articles){
  89 + vm.randomProposal = data.articles[0];
  90 + }
  91 +
  92 + if(data && data.article){
  93 + vm.randomProposal = data.article;
  94 + }
  95 + }
  96 +
  97 + function _handleErrorGetProposal(error){
78 vm.$log.error(error); 98 vm.$log.error(error);
79 - }); 99 + }
80 100
81 vm.loading = false; 101 vm.loading = false;
82 }, function(error) { 102 }, function(error) {
src/app/pages/programas/programa.html
@@ -64,7 +64,7 @@ @@ -64,7 +64,7 @@
64 </div> 64 </div>
65 <div class="col-xs-12" ng-if="pageProgramaContent.randomProposal"> 65 <div class="col-xs-12" ng-if="pageProgramaContent.randomProposal">
66 <h3 class="color-theme-fg">Propostas nesse programa</h3> 66 <h3 class="color-theme-fg">Propostas nesse programa</h3>
67 - <proposal-box proposal="pageProgramaContent.randomProposal" topic="pageProgramaContent.article" category="pageProgramaContent.category" vote="false" ></proposal-box> 67 + <proposal-box proposal="pageProgramaContent.randomProposal" topic="pageProgramaContent.article" category="pageProgramaContent.category" vote="true" ></proposal-box>
68 </div> 68 </div>
69 <div class="col-xs-12" ng-if="!pageProgramaContent.randomProposal && !(pageProgramaContent.proposalsTopRated && pageProgramaContent.proposalsTopRated.length > 0)"> 69 <div class="col-xs-12" ng-if="!pageProgramaContent.randomProposal && !(pageProgramaContent.proposalsTopRated && pageProgramaContent.proposalsTopRated.length > 0)">
70 <h3>Programas sem propostas</h3> 70 <h3>Programas sem propostas</h3>
src/app/pages/programas/programas.scss
@@ -57,6 +57,10 @@ @@ -57,6 +57,10 @@
57 vertical-align: middle; 57 vertical-align: middle;
58 } 58 }
59 59
  60 + .program-preview--abstract h2 {
  61 + font-size: 40px;
  62 + }
  63 +
60 h2, 64 h2,
61 h3{ 65 h3{
62 font-weight: bold; 66 font-weight: bold;
src/app/pages/propostas/propostas.controller.js
@@ -11,33 +11,36 @@ @@ -11,33 +11,36 @@
11 .controller('PropostasPageController', PropostasPageController); 11 .controller('PropostasPageController', PropostasPageController);
12 12
13 /** @ngInject */ 13 /** @ngInject */
14 - function PropostasPageController(DialogaService, $log) { 14 + function PropostasPageController(DialogaService, $scope, $location, $filter, $log) {
15 var vm = this; 15 var vm = this;
16 16
17 vm.DialogaService = DialogaService; 17 vm.DialogaService = DialogaService;
  18 + vm.$scope = $scope;
  19 + vm.$location = $location;
  20 + vm.$filter = $filter;
18 vm.$log = $log; 21 vm.$log = $log;
19 22
20 vm.init(); 23 vm.init();
  24 + vm.loadData();
  25 + vm.attachListeners();
  26 +
21 $log.debug('PropostasPageController'); 27 $log.debug('PropostasPageController');
22 } 28 }
23 29
24 PropostasPageController.prototype.init = function () { 30 PropostasPageController.prototype.init = function () {
25 var vm = this; 31 var vm = this;
26 32
27 - vm.article = null;  
28 vm.themes = null; 33 vm.themes = null;
29 vm.selectedTheme = null; 34 vm.selectedTheme = null;
30 vm.proposals = null; 35 vm.proposals = null;
31 vm.filtredProposals = null; 36 vm.filtredProposals = null;
32 vm.query = null; 37 vm.query = null;
  38 + vm.search = vm.$location.search();
33 39
34 vm.loading = null; 40 vm.loading = null;
35 vm.error = null; 41 vm.error = null;
36 -  
37 - vm.loadData();  
38 }; 42 };
39 43
40 -  
41 PropostasPageController.prototype.loadData = function () { 44 PropostasPageController.prototype.loadData = function () {
42 var vm = this; 45 var vm = this;
43 46
@@ -49,10 +52,12 @@ @@ -49,10 +52,12 @@
49 vm.proposals = data.articles; 52 vm.proposals = data.articles;
50 vm.filtredProposals = vm.proposals; 53 vm.filtredProposals = vm.proposals;
51 vm.loadingProposals = false; 54 vm.loadingProposals = false;
  55 + vm.loading = false;
52 }, function (error) { 56 }, function (error) {
53 vm.error = error; 57 vm.error = error;
54 vm.$log.error(error); 58 vm.$log.error(error);
55 vm.loadingProposals = false; 59 vm.loadingProposals = false;
  60 + vm.loading = false;
56 }); 61 });
57 62
58 // load themes 63 // load themes
@@ -60,10 +65,40 @@ @@ -60,10 +65,40 @@
60 vm.DialogaService.getThemes(function(themes){ 65 vm.DialogaService.getThemes(function(themes){
61 vm.themes = themes; 66 vm.themes = themes;
62 vm.loadingThemes = false; 67 vm.loadingThemes = false;
  68 + vm.loading = false;
63 }, function (error) { 69 }, function (error) {
64 vm.error = error; 70 vm.error = error;
65 vm.$log.error(error); 71 vm.$log.error(error);
66 vm.loadingThemes = false; 72 vm.loadingThemes = false;
  73 + vm.loading = false;
67 }); 74 });
68 }; 75 };
  76 +
  77 + PropostasPageController.prototype.attachListeners = function() {
  78 + var vm = this;
  79 +
  80 + vm.$scope.$on('change-selectedCategory', function (event, selectedCategory) {
  81 + vm.selectedTheme = selectedCategory;
  82 + vm.$log.debug('vm.selectedTheme', vm.selectedTheme);
  83 + });
  84 +
  85 + vm.$scope.$watch('pagePropostas.selectedTheme', function(newValue/*, oldValue*/) {
  86 + vm.search.tema = newValue ? newValue.slug : null;
  87 + vm.$location.search('tema', vm.search.tema);
  88 + vm.filtredProposals = vm.getFiltredProposals();
  89 + });
  90 +
  91 + vm.$scope.$watch('pagePropostas.query', function(newValue/*, oldValue*/) {
  92 + vm.search.filtro = newValue ? newValue : null;
  93 + vm.$location.search('filtro', vm.search.filtro);
  94 + vm.filtredProposals = vm.getFiltredProposals();
  95 + });
  96 + };
  97 +
  98 + PropostasPageController.prototype.getFiltredProposals = function() {
  99 + var vm = this;
  100 +
  101 + return vm.proposals;
  102 + };
  103 +
69 })(); 104 })();
src/app/pages/propostas/propostas.html
@@ -7,7 +7,26 @@ @@ -7,7 +7,26 @@
7 </div> 7 </div>
8 8
9 <div class="page--propostas"> 9 <div class="page--propostas">
10 - <section class="section--info"> 10 +
  11 + <section class="section-info" ng-if="pagePropostas.loading || pagePropostas.error">
  12 + <div class="container">
  13 + <div class="row">
  14 + <div class="col-md-12">
  15 + <div ng-if="pagePropostas.loading && !pagePropostas.error">
  16 + <div class="alert alert-info" role="alert">Carregando conteúdo...</div>
  17 + </div>
  18 +
  19 + <div ng-if="pagePropostas.error">
  20 + <div class="alert alert-danger" role="alert">
  21 + Erro ao carregar o conteúdo principal.
  22 + </div>
  23 + </div>
  24 + </div>
  25 + </div>
  26 + </div>
  27 + </section>
  28 +
  29 + <section class="section--header" ng-if="pagePropostas.proposals || pagePropostas.themes">
11 <div class="container"> 30 <div class="container">
12 <div class="row"> 31 <div class="row">
13 <div class="col-sm-12"> 32 <div class="col-sm-12">
@@ -16,7 +35,8 @@ @@ -16,7 +35,8 @@
16 </div> 35 </div>
17 </div> 36 </div>
18 </section> 37 </section>
19 - <section class="section--articles section-gray section-space-up" ng-if="pagePropostas.proposals"> 38 +
  39 + <section class="section--articles section-gray section-space-up" ng-if="pagePropostas.proposals || pagePropostas.themes">
20 <div class="container"> 40 <div class="container">
21 <div id="lista-de-propostas" class="row"> 41 <div id="lista-de-propostas" class="row">
22 <div class="col-sm-4 col-md-3"> 42 <div class="col-sm-4 col-md-3">
@@ -52,7 +72,7 @@ @@ -52,7 +72,7 @@
52 </div> 72 </div>
53 </div> 73 </div>
54 <div class="col-sm-8 col-md-9"> 74 <div class="col-sm-8 col-md-9">
55 - <div class="row hidden-xs"> 75 + <div class="row hidden-xs" ng-if="pagePropostas.proposals">
56 <div class="col-xs-12"> 76 <div class="col-xs-12">
57 <div class="input-group input-group-lg input-group-search"> 77 <div class="input-group input-group-lg input-group-search">
58 <label for="articleQueryFilter" class="control-label sr-only">Buscar propostas:</label> 78 <label for="articleQueryFilter" class="control-label sr-only">Buscar propostas:</label>
@@ -68,10 +88,11 @@ @@ -68,10 +88,11 @@
68 </div> 88 </div>
69 </div> 89 </div>
70 </div> 90 </div>
71 - <div class="row"> 91 +
  92 + <div class="row" ng-if="pagePropostas.proposals">
72 <div class="col-sm-12"> 93 <div class="col-sm-12">
73 <header class="header"> 94 <header class="header">
74 - <h2>Total de Propostas as propostas: "<span>{{::pagePropostas.proposals.length}} propostas</span>"</h2> 95 + <h2>Total de Propostas: "<b>{{::pagePropostas.proposals.length}} propostas</b>"</h2>
75 </header> 96 </header>
76 </div> 97 </div>
77 </div> 98 </div>
src/app/pages/propostas/propostas.scss 0 → 100644
@@ -0,0 +1,5 @@ @@ -0,0 +1,5 @@
  1 +.page--propostas {
  2 + .proposal-box--middle {
  3 + background-color: #fff;
  4 + }
  5 +}