Commit 4d6ba201ca07fb25bd0193d6136332c60f31ae10

Authored by Leonardo Merlin
1 parent 8842e145

Small improvements into event-list component

src/app/components/article-service/article.service.js
@@ -178,7 +178,7 @@ @@ -178,7 +178,7 @@
178 }); 178 });
179 } 179 }
180 180
181 - function getEvents (community_id, params, cbSuccess, cbError) { 181 + function getEvents (community_id, params) {
182 // Ex.: /api/v1/communities/19195/articles?categories_ids[]=' + cat_id + '&content_type=Event'; 182 // Ex.: /api/v1/communities/19195/articles?categories_ids[]=' + cat_id + '&content_type=Event';
183 // Ex.: /api/v1/communities/' + community_id + '/articles?categories_ids[]=' + cat_id + '&content_type=Event'; 183 // Ex.: /api/v1/communities/' + community_id + '/articles?categories_ids[]=' + cat_id + '&content_type=Event';
184 184
@@ -188,11 +188,9 @@ @@ -188,11 +188,9 @@
188 'content_type':'Event' 188 'content_type':'Event'
189 }, params); 189 }, params);
190 190
191 - UtilService.get(url, {params: paramsExtended}).then(function(data){  
192 - _pipeIsInThePast(data);  
193 - cbSuccess(data.articles);  
194 - }).catch(function(error){  
195 - cbError(error); 191 + return UtilService.get(url, {params: paramsExtended}).then(function(data){
  192 + _pipeRemoveOldEvents(data);
  193 + return data;
196 }); 194 });
197 } 195 }
198 196
@@ -210,21 +208,11 @@ @@ -210,21 +208,11 @@
210 // }); 208 // });
211 // } 209 // }
212 210
213 - function subscribeToEvent (event_id, params, cbSuccess, cbError) { 211 + function subscribeToEvent (event_id) {
  212 + var url = service.apiArticles + event_id + '/follow';
  213 + var encodedParams = 'private_token=' + $rootScope.currentUser.private_token;
214 214
215 - if(!$rootScope.currentUser){  
216 - cbError({message: 'Usuário não logado.'});  
217 -  
218 - }else{  
219 - var url = service.apiArticles + event_id + '/follow';  
220 - var encodedParams = 'private_token=' + $rootScope.currentUser.private_token;  
221 -  
222 - UtilService.post(url, encodedParams).then(function(response){  
223 - cbSuccess(response);  
224 - }).catch(function(error){  
225 - cbError(error);  
226 - });  
227 - } 215 + return UtilService.post(url, encodedParams);
228 } 216 }
229 217
230 function searchTopics (params, cbSuccess, cbError) { 218 function searchTopics (params, cbSuccess, cbError) {
@@ -282,14 +270,17 @@ @@ -282,14 +270,17 @@
282 }); 270 });
283 } 271 }
284 272
285 - function _pipeIsInThePast(data){ 273 + function _pipeRemoveOldEvents(data){
286 if(!data.articles && data.article){ 274 if(!data.articles && data.article){
287 data.articles = [data.article]; 275 data.articles = [data.article];
  276 + data.article = null;
288 } 277 }
  278 +
289 var now = (new Date()).getTime(); 279 var now = (new Date()).getTime();
290 var eventDate = null; 280 var eventDate = null;
291 var events = data.articles; 281 var events = data.articles;
292 282
  283 + var results = [];
293 for (var i = events.length - 1; i >= 0; i--) { 284 for (var i = events.length - 1; i >= 0; i--) {
294 var event = events[i]; 285 var event = events[i];
295 286
@@ -297,10 +288,16 @@ @@ -297,10 +288,16 @@
297 eventDate = new Date(event.end_date); 288 eventDate = new Date(event.end_date);
298 } 289 }
299 290
300 - if(eventDate.getTime() < now){  
301 - event.isOld = true; 291 + // if(eventDate.getTime() < now){
  292 + // event.isOld = true;
  293 + // }
  294 + if(eventDate.getTime() >= now){
  295 + results.push(event);
302 } 296 }
303 } 297 }
  298 +
  299 + data.articles = results;
304 } 300 }
  301 +
305 } 302 }
306 })(); 303 })();
src/app/components/auth/auth.service.js
@@ -53,7 +53,7 @@ @@ -53,7 +53,7 @@
53 } 53 }
54 54
55 function activate (code) { 55 function activate (code) {
56 - var url = '/api/v1/activate'; 56 + var url = PATH.host +'/api/v1/activate';
57 // var data = { 57 // var data = {
58 // private_token: API.token, 58 // private_token: API.token,
59 // activation_code: code 59 // activation_code: code
@@ -77,7 +77,7 @@ @@ -77,7 +77,7 @@
77 } 77 }
78 78
79 function changePassword (code, newPassword, newPasswordConfirmation){ 79 function changePassword (code, newPassword, newPasswordConfirmation){
80 - var url = '/api/v1/new_password'; 80 + var url = PATH.host +'/api/v1/new_password';
81 // var data = { 81 // var data = {
82 // code: code, 82 // code: code,
83 // password: newPassword, 83 // password: newPassword,
@@ -103,7 +103,7 @@ @@ -103,7 +103,7 @@
103 } 103 }
104 104
105 function forgotPassword (data){ 105 function forgotPassword (data){
106 - var url = 'http://hom.login.dialoga.gov.br/api/v1/forgot_password'; 106 + var url = PATH.host +'/api/v1/forgot_password';
107 var encodedData = ([ 107 var encodedData = ([
108 'value=' + data.login, 108 'value=' + data.login,
109 'captcha_text=' + data.captcha_text, 109 'captcha_text=' + data.captcha_text,
@@ -129,8 +129,7 @@ @@ -129,8 +129,7 @@
129 } 129 }
130 130
131 function login (credentials) { 131 function login (credentials) {
132 - var hostProd = 'http://login.dialoga.gov.br';  
133 - var url = hostProd + '/api/v1/login'; 132 + var url = PATH.host + '/api/v1/login';
134 var encodedData = 'login=' + credentials.username + '&password=' + credentials.password; 133 var encodedData = 'login=' + credentials.username + '&password=' + credentials.password;
135 134
136 return $http 135 return $http
src/app/components/dialoga-service/dialoga.service.js
@@ -205,10 +205,10 @@ @@ -205,10 +205,10 @@
205 } 205 }
206 } 206 }
207 207
208 - function getEvents (params, cbSuccess, cbError) { 208 + function getEvents (params) {
209 var paramsExtended = angular.extend({}, params); 209 var paramsExtended = angular.extend({}, params);
210 210
211 - ArticleService.getEvents(API.communityId, paramsExtended, cbSuccess, cbError); 211 + return ArticleService.getEvents(API.communityId, paramsExtended);
212 } 212 }
213 213
214 // TODO: implement 214 // TODO: implement
src/app/components/event-list/event-list.directive.js
@@ -23,48 +23,62 @@ @@ -23,48 +23,62 @@
23 // vm.attachListeners(); 23 // vm.attachListeners();
24 } 24 }
25 25
26 - EventListController.prototype.init = function () { 26 + EventListController.prototype.init = function() {
27 var vm = this; 27 var vm = this;
28 28
29 - if(!vm.events){ 29 + if (!vm.events) {
30 throw { name: 'NotDefined', message: 'The attribute "events" is undefined.'}; 30 throw { name: 'NotDefined', message: 'The attribute "events" is undefined.'};
31 } 31 }
32 32
33 - if(!vm.isCollapsed){ 33 + if (!vm.isCollapsed) {
34 vm.isCollapsed = true; 34 vm.isCollapsed = true;
35 } 35 }
36 }; 36 };
37 37
38 - EventListController.prototype.toggleView = function () { 38 + EventListController.prototype.toggleView = function() {
39 var vm = this; 39 var vm = this;
40 vm.isCollapsed = !vm.isCollapsed; 40 vm.isCollapsed = !vm.isCollapsed;
41 }; 41 };
42 42
43 - EventListController.prototype.subscribe = function (event) { 43 + EventListController.prototype.subscribe = function(event) {
44 var vm = this; 44 var vm = this;
45 45
46 - if(event.isOld){  
47 - vm.$log.debug('Event already happened. Abort.');  
48 - return;  
49 - }  
50 -  
51 var event_id = event.id; 46 var event_id = event.id;
52 - vm.$log.debug('event_id', event_id);  
53 47
54 - if(!vm.$rootScope.currentUser){ 48 + // must be authenticated
  49 + if (!vm.$rootScope.currentUser) {
55 vm.$log.info('User is not logged in. Redirect to Auth page.'); 50 vm.$log.info('User is not logged in. Redirect to Auth page.');
56 - vm.$state.go('entrar',{ 51 + vm.$state.go('entrar', {
57 redirect_uri: 'state=inicio&task=subscribe&event_id=' + event_id 52 redirect_uri: 'state=inicio&task=subscribe&event_id=' + event_id
58 - },{ 53 + }, {
59 location: true 54 location: true
60 }); 55 });
61 - }else{  
62 - vm.ArticleService.subscribeToEvent(event_id, {}, function(response){  
63 - vm.$log.debug('response', response);  
64 - }, function(error){  
65 - vm.$log.debug('error', error);  
66 - }); 56 +
  57 + return;
67 } 58 }
  59 +
  60 + // do the subscription
  61 + event._loading = true;
  62 + vm.ArticleService.subscribeToEvent(event_id).then(function (data) {
  63 + vm.$log.debug('success', data);
  64 +
  65 + if(data.success === true){
  66 + // subscribed with success
  67 + event.already_follow = true;
  68 + }
  69 +
  70 + if(data.success === false && data.already_follow === true){
  71 + // already subscribed
  72 + event.already_follow = true;
  73 + }
  74 + }, function (data) {
  75 + vm.$log.debug('error', data);
  76 + }, function (data){
  77 + vm.$log.debug('update', data);
  78 + }).finally(function(data){
  79 + vm.$log.debug('finally', data);
  80 + event._loading = false;
  81 + });
68 }; 82 };
69 83
70 var directive = { 84 var directive = {
src/app/components/event-list/event-list.html
@@ -40,11 +40,8 @@ @@ -40,11 +40,8 @@
40 </span> 40 </span>
41 </div> 41 </div>
42 <div class="col-xs-12 col-sm-4 col-md-5 vcenter"> 42 <div class="col-xs-12 col-sm-4 col-md-5 vcenter">
43 - <span class="description">{{::event.title.split('-')[0]}}</span> 43 + <span class="description">{{::event.setting.presenter}}</span>
44 </div> 44 </div>
45 - <!-- <div class="col-xs-12 col-sm-4 col-md-3 text-center vcenter">  
46 - <span class="theme">{{::event.categories[0].name}}</span>  
47 - </div> -->  
48 <div class="col-xs-12 col-sm-4 col-md-4 text-right vcenter" style="padding-right: 20px;"> 45 <div class="col-xs-12 col-sm-4 col-md-4 text-right vcenter" style="padding-right: 20px;">
49 <div class="row"> 46 <div class="row">
50 <div class="col-xs-6 text-right"> 47 <div class="col-xs-6 text-right">
@@ -55,10 +52,19 @@ @@ -55,10 +52,19 @@
55 </div> 52 </div>
56 </div> 53 </div>
57 <div class="col-xs-6"> 54 <div class="col-xs-6">
58 - <button type="button" class="btn color-theme-common-bg btn-disabled" disabled ng-click="vm.subscribe(event)">  
59 - Inscreva-se  
60 - <span class="sr-only">no bate-papo com (ministro) no dia {event.start_date | date : "dd/MM/yyyy"}} as {{event.start_date | date : "HH:mm"}} horas</span>  
61 - </button> 55 + <div ng-show="!event.already_follow">
  56 + <button type="button" class="btn btn-subscribe" ng-click="vm.subscribe(event)">
  57 + Inscreva-se
  58 + <span class="sr-only">no bate-papo com (ministro) no dia {event.start_date | date : "dd/MM/yyyy"}} as {{event.start_date | date : "HH:mm"}} horas</span>
  59 + </button>
  60 + </div>
  61 + <div ng-show="event.already_follow">
  62 + <button type="button" class="btn btn-subscribed disabled" disabled="disabled">
  63 + <span class="glyphicon glyphicon-ok" aria-hidden="true"></span>
  64 + Inscrito
  65 + <span class="sr-only">Você já está inscrito neste evento.</span>
  66 + </button>
  67 + </div>
62 </div> 68 </div>
63 </div> 69 </div>
64 </div> 70 </div>
src/app/components/event-list/event-list.scss
@@ -10,6 +10,7 @@ @@ -10,6 +10,7 @@
10 } 10 }
11 11
12 .event-list--panel { 12 .event-list--panel {
  13 + color: #484848;
13 width: 100%; 14 width: 100%;
14 height: 240px; 15 height: 240px;
15 margin: 8px 0; 16 margin: 8px 0;
@@ -24,9 +25,22 @@ @@ -24,9 +25,22 @@
24 } 25 }
25 26
26 .btn { 27 .btn {
27 - color: #e1e1e1;  
28 text-transform: uppercase; 28 text-transform: uppercase;
29 - font-weight: bold; 29 + // font-weight: bold;
  30 +
  31 + &.btn-subscribe {
  32 + color: #fff;
  33 + background-color: $defaultblue;
  34 + }
  35 +
  36 + &.btn-subscribed {
  37 + color: $defaultblue;
  38 + border: 1px solid $defaultblue;
  39 +
  40 + .glyphicon {
  41 + color: #4eca74;
  42 + }
  43 + }
30 } 44 }
31 45
32 .row-level-1 { 46 .row-level-1 {
@@ -45,6 +59,20 @@ @@ -45,6 +59,20 @@
45 height: auto; 59 height: auto;
46 overflow: visible; 60 overflow: visible;
47 } 61 }
  62 +
  63 +
  64 + .date-wrapper {margin-left: 16px; }
  65 + .time-wrapper {margin-left: 22px; }
  66 + // .description {margin-left: 22px; }
  67 +
  68 + .date-wrapper .glyphicon,
  69 + .time-wrapper .glyphicon {
  70 + color: $defaultblue;
  71 + font-size: 18px;
  72 + font-size: 1.8rem;
  73 + position: relative;
  74 + top: 3px;
  75 + }
48 } 76 }
49 77
50 &--table{ 78 &--table{
@@ -110,12 +138,6 @@ @@ -110,12 +138,6 @@
110 } 138 }
111 } 139 }
112 140
113 - .event-list--panel {  
114 - .date-wrapper {margin-left: 16px; }  
115 - .time-wrapper {margin-left: 22px; }  
116 - // .description {margin-left: 22px; }  
117 - }  
118 -  
119 .event-tab--icon { 141 .event-tab--icon {
120 font-size: 25px; 142 font-size: 25px;
121 } 143 }
src/app/pages/inicio/inicio.controller.js
@@ -76,13 +76,18 @@ @@ -76,13 +76,18 @@
76 76
77 // Load event list 77 // Load event list
78 vm.loadingEvents = true; 78 vm.loadingEvents = true;
79 - vm.DialogaService.getEvents({}, function(events) {  
80 - vm.events = events;  
81 - vm.loadingEvents = false; 79 + vm.DialogaService.getEvents().then(function(data) {
  80 + vm.$log.debug('getEvents.success', data);
  81 + vm.events = data.articles;
  82 +
82 }, function(error) { 83 }, function(error) {
83 - vm.$log.error('Error on getEvents.', error);  
84 - vm.loadingEvents = false; 84 + vm.$log.debug('Error on getEvents.', error);
85 vm.eventsError = error; 85 vm.eventsError = error;
  86 + }, function(data) {
  87 + vm.$log.debug('{UPDATE}', data);
  88 + }).finally(function(data){
  89 + vm.$log.debug('{FINALLY}', data);
  90 + vm.loadingEvents = false;
86 }); 91 });
87 92
88 function _loadAfterHome () { 93 function _loadAfterHome () {
@@ -167,10 +172,10 @@ @@ -167,10 +172,10 @@
167 172
168 // scroll to result grid 173 // scroll to result grid
169 var $searchResult = angular.element('#search-result'); 174 var $searchResult = angular.element('#search-result');
170 - if($searchResult && $searchResult.length > 0){ 175 + if ($searchResult && $searchResult.length > 0) {
171 angular.element('body').animate({scrollTop: $searchResult.offset().top}, 'fast'); 176 angular.element('body').animate({scrollTop: $searchResult.offset().top}, 'fast');
172 vm.filtredPrograms = vm.getFiltredPrograms(); 177 vm.filtredPrograms = vm.getFiltredPrograms();
173 - }else{ 178 + }else {
174 vm.$log.warn('#search-result element not found.'); 179 vm.$log.warn('#search-result element not found.');
175 } 180 }
176 }; 181 };
@@ -251,7 +256,7 @@ @@ -251,7 +256,7 @@
251 return output; 256 return output;
252 }; 257 };
253 258
254 - InicioPageController.prototype._filterByCategory = function (input, category) { 259 + InicioPageController.prototype._filterByCategory = function(input, category) {
255 var vm = this; 260 var vm = this;
256 261
257 input = input || []; 262 input = input || [];
@@ -265,7 +270,7 @@ @@ -265,7 +270,7 @@
265 for (var i = 0; i < input.length; i++) { 270 for (var i = 0; i < input.length; i++) {
266 var program = input[i]; 271 var program = input[i];
267 272
268 - if(!program.categories || program.categories.length === 0){ 273 + if (!program.categories || program.categories.length === 0) {
269 vm.$log.warn('Program without theme (category)', program.slug); 274 vm.$log.warn('Program without theme (category)', program.slug);
270 continue; 275 continue;
271 } 276 }