Commit 1ea912ba0b74c0b47854502d0276ea14cbc98f65
1 parent
43b414b9
Exists in
master
and in
8 other branches
Add initial internal redirect handler
Showing
8 changed files
with
91 additions
and
20 deletions
Show diff stats
src/app/components/article-service/article.service.js
... | ... | @@ -156,19 +156,36 @@ |
156 | 156 | }); |
157 | 157 | } |
158 | 158 | |
159 | - function subscribeToEvent (event_id, params, cbSuccess, cbError) { | |
160 | - var url = service.apiArticles + event_id + '/follow'; | |
159 | + function getSubscribers (event_id, params, cbSuccess, cbError) { | |
160 | + var url = service.apiArticles + event_id + '/followers?_=' + new Date().getTime(); | |
161 | 161 | var paramsExtended = angular.extend({ |
162 | - private_token: API.token | |
162 | + // 'fields[]': ['id', 'slug', 'title', 'abstract', 'body', 'categories', 'created_at', 'start_date', 'end_date', 'hits'], | |
163 | + 'content_type':'Event' | |
163 | 164 | }, params); |
164 | 165 | |
165 | - UtilService.post(url, {params: paramsExtended}).then(function(data){ | |
166 | + UtilService.get(url, {params: paramsExtended}).then(function(data){ | |
166 | 167 | cbSuccess(data.articles); |
167 | 168 | }).catch(function(error){ |
168 | 169 | cbError(error); |
169 | 170 | }); |
170 | 171 | } |
171 | 172 | |
173 | + function subscribeToEvent (event_id, params, cbSuccess, cbError) { | |
174 | + | |
175 | + if(!$rootScope.currentUser){ | |
176 | + cbError({message: 'Usuário não logado.'}); | |
177 | + } | |
178 | + | |
179 | + var url = service.apiArticles + event_id + '/follow'; | |
180 | + var encodedParams = 'private_token=' + $rootScope.currentUser.private_token; | |
181 | + | |
182 | + UtilService.post(url, encodedParams).then(function(response){ | |
183 | + cbSuccess(response); | |
184 | + }).catch(function(error){ | |
185 | + cbError(error); | |
186 | + }); | |
187 | + } | |
188 | + | |
172 | 189 | function searchTopics (params, cbSuccess, cbError) { |
173 | 190 | // Ex.: /api/v1/search/article?type=ProposalsDiscussionPlugin::Topic&query=cisternas |
174 | 191 | var url = '/api/v1/search/article'; | ... | ... |
src/app/components/auth-user/auth-user.directive.js
src/app/components/auth/auth.service.js
... | ... | @@ -130,6 +130,7 @@ |
130 | 130 | $log.debug('AuthService.login [SUCCESS] response', response); |
131 | 131 | |
132 | 132 | var currentUser = Session.create(response.data); |
133 | + $rootScope.currentUser = currentUser; | |
133 | 134 | |
134 | 135 | $rootScope.$broadcast(AUTH_EVENTS.loginSuccess, currentUser); |
135 | 136 | return currentUser; |
... | ... | @@ -142,7 +143,7 @@ |
142 | 143 | function logout () { |
143 | 144 | |
144 | 145 | Session.destroy(); |
145 | - | |
146 | + $rootScope.currentUser = null; | |
146 | 147 | $rootScope.$broadcast(AUTH_EVENTS.logoutSuccess); |
147 | 148 | } |
148 | 149 | ... | ... |
src/app/components/event-list/event-list.directive.js
... | ... | @@ -8,11 +8,12 @@ |
8 | 8 | /** @ngInject */ |
9 | 9 | function eventList() { |
10 | 10 | /** @ngInject */ |
11 | - function EventListController($scope, $rootScope, $state, $log) { | |
11 | + function EventListController(ArticleService, $scope, $rootScope, $state, $log) { | |
12 | 12 | $log.debug('EventListController'); |
13 | 13 | |
14 | 14 | var vm = this; |
15 | 15 | |
16 | + vm.ArticleService = ArticleService; | |
16 | 17 | vm.$scope = $scope; |
17 | 18 | vm.$rootScope = $rootScope; |
18 | 19 | vm.$state = $state; |
... | ... | @@ -39,10 +40,26 @@ |
39 | 40 | vm.isCollapsed = !vm.isCollapsed; |
40 | 41 | }; |
41 | 42 | |
42 | - EventListController.prototype.subscribe = function (data) { | |
43 | + EventListController.prototype.subscribe = function (event_id) { | |
43 | 44 | var vm = this; |
44 | 45 | |
45 | - vm.$log.debug('data', data); | |
46 | + vm.$log.debug('event_id', event_id); | |
47 | + | |
48 | + if(!vm.$rootScope.currentUser){ | |
49 | + vm.$log.warn('User is not logged in. Redirect to Auth page.'); | |
50 | + vm.$state.go('entrar',{ | |
51 | + redirect_uri: 'state=inicio&task=subscribe&event_id=' + event_id | |
52 | + },{ | |
53 | + location: true | |
54 | + }); | |
55 | + }else{ | |
56 | + vm.ArticleService.subscribeToEvent(event_id, {}, function(response){ | |
57 | + vm.$log.debug('response', response); | |
58 | + }, function(error){ | |
59 | + vm.$log.debug('error', error); | |
60 | + }) | |
61 | + } | |
62 | + | |
46 | 63 | }; |
47 | 64 | |
48 | 65 | var directive = { | ... | ... |
src/app/components/event-list/event-list.html
... | ... | @@ -59,12 +59,14 @@ |
59 | 59 | <span class="theme">{{::event.categories[0].name}}</span> |
60 | 60 | </td> |
61 | 61 | <td align="right"> |
62 | - <b>(?)</b> | |
63 | - <br/> | |
64 | - <span>Inscritos</span> | |
62 | + <div ng-if="!event.subscribers_count"> | |
63 | + <b>(?)</b> | |
64 | + <br/> | |
65 | + <span>Inscritos</span> | |
66 | + </div> | |
65 | 67 | </td> |
66 | 68 | <td align="left"> |
67 | - <button type="button" class="btn color-theme-common-bg" ng-click="vm.subscribe('EVENT_ID')"> | |
69 | + <button type="button" class="btn color-theme-common-bg" ng-click="vm.subscribe(event.id)"> | |
68 | 70 | Inscreva-se |
69 | 71 | <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> |
70 | 72 | </button> | ... | ... |
src/app/index.route.js
src/app/pages/article/article.html
... | ... | @@ -26,9 +26,15 @@ |
26 | 26 | <article> |
27 | 27 | <header class="container"> |
28 | 28 | <div class="row"> |
29 | - <h1>{{::pageArticle.article.title}}</h1> | |
29 | + <div class="col-sm-12"> | |
30 | + <h1>{{::pageArticle.article.title}}</h1> | |
31 | + </div> | |
30 | 32 | </div> |
31 | 33 | </header> |
32 | - <div ng-bind-html="pageArticle.article.body"></div> | |
34 | + <article> | |
35 | + <div class="container"> | |
36 | + <div ng-bind-html="pageArticle.article.body"></div> | |
37 | + </div> | |
38 | + </article> | |
33 | 39 | </article> |
34 | 40 | </div> | ... | ... |
src/app/pages/auth/auth.controller.js
... | ... | @@ -6,13 +6,13 @@ |
6 | 6 | .controller('AuthPageController', AuthPageController); |
7 | 7 | |
8 | 8 | /** @ngInject */ |
9 | - function AuthPageController($scope, $rootScope, AUTH_EVENTS, AuthService, DialogaService, Session, $log) { | |
10 | - $log.debug('AuthPageController'); | |
11 | - | |
9 | + function AuthPageController($scope, $rootScope, $location, $state, AUTH_EVENTS, AuthService, DialogaService, Session, $log) { | |
12 | 10 | var vm = this; |
13 | 11 | |
14 | - vm.$rootScope = $rootScope; | |
15 | 12 | vm.$scope = $scope; |
13 | + vm.$rootScope = $rootScope; | |
14 | + vm.$location = $location; | |
15 | + vm.$state = $state; | |
16 | 16 | vm.AUTH_EVENTS = AUTH_EVENTS; |
17 | 17 | vm.AuthService = AuthService; |
18 | 18 | vm.DialogaService = DialogaService; |
... | ... | @@ -21,6 +21,8 @@ |
21 | 21 | |
22 | 22 | vm.init(); |
23 | 23 | vm.loadData(); |
24 | + | |
25 | + vm.$log.debug('AuthPageController'); | |
24 | 26 | } |
25 | 27 | |
26 | 28 | AuthPageController.prototype.init = function() { |
... | ... | @@ -32,6 +34,12 @@ |
32 | 34 | vm.terms = null; |
33 | 35 | vm.loadingTerms = null; |
34 | 36 | |
37 | + vm.search = vm.$location.search(); | |
38 | + var redirect = vm.search.redirect_uri || ''; | |
39 | + if(redirect && redirect.length > 0){ | |
40 | + vm.params = JSON.parse('{"' + decodeURI(redirect).replace(/"/g, '\\"').replace(/&/g, '","').replace(/=/g,'":"') + '"}'); | |
41 | + } | |
42 | + | |
35 | 43 | // attach events |
36 | 44 | vm.currentUser = vm.Session.getCurrentUser(); |
37 | 45 | |
... | ... | @@ -78,6 +86,8 @@ |
78 | 86 | // 'Cadastro efetuado com sucesso.' |
79 | 87 | // 'Verifique seu email para confirmar o cadastro.' |
80 | 88 | |
89 | + // TODO: show messagens and redirect timeout | |
90 | + vm.redirectBack(); | |
81 | 91 | }, function(response){ |
82 | 92 | vm.$log.debug('register error.response', response); |
83 | 93 | |
... | ... | @@ -92,9 +102,28 @@ |
92 | 102 | vm.AuthService.login(credentials).then(function(user) { |
93 | 103 | // handle view |
94 | 104 | vm.$log.debug('user', user); |
105 | + vm.redirectBack(); | |
95 | 106 | }, function() { |
96 | 107 | // handle view |
97 | 108 | }); |
98 | 109 | }; |
99 | 110 | |
111 | + AuthPageController.prototype.redirectBack = function(){ | |
112 | + var vm = this; | |
113 | + | |
114 | + if(!vm.params){ | |
115 | + vm.$log.warn('No redirect params defined.'); | |
116 | + return; | |
117 | + } | |
118 | + var state = vm.params.state; | |
119 | + switch(state){ | |
120 | + case 'inicio': | |
121 | + vm.$state.go(state, { | |
122 | + event_id: vm.params.event_id, | |
123 | + task: vm.params.task | |
124 | + }); | |
125 | + break; | |
126 | + } | |
127 | + } | |
128 | + | |
100 | 129 | })(); | ... | ... |