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,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 | var paramsExtended = angular.extend({ | 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 | }, params); | 164 | }, params); |
164 | 165 | ||
165 | - UtilService.post(url, {params: paramsExtended}).then(function(data){ | 166 | + UtilService.get(url, {params: paramsExtended}).then(function(data){ |
166 | cbSuccess(data.articles); | 167 | cbSuccess(data.articles); |
167 | }).catch(function(error){ | 168 | }).catch(function(error){ |
168 | cbError(error); | 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 | function searchTopics (params, cbSuccess, cbError) { | 189 | function searchTopics (params, cbSuccess, cbError) { |
173 | // Ex.: /api/v1/search/article?type=ProposalsDiscussionPlugin::Topic&query=cisternas | 190 | // Ex.: /api/v1/search/article?type=ProposalsDiscussionPlugin::Topic&query=cisternas |
174 | var url = '/api/v1/search/article'; | 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,6 +130,7 @@ | ||
130 | $log.debug('AuthService.login [SUCCESS] response', response); | 130 | $log.debug('AuthService.login [SUCCESS] response', response); |
131 | 131 | ||
132 | var currentUser = Session.create(response.data); | 132 | var currentUser = Session.create(response.data); |
133 | + $rootScope.currentUser = currentUser; | ||
133 | 134 | ||
134 | $rootScope.$broadcast(AUTH_EVENTS.loginSuccess, currentUser); | 135 | $rootScope.$broadcast(AUTH_EVENTS.loginSuccess, currentUser); |
135 | return currentUser; | 136 | return currentUser; |
@@ -142,7 +143,7 @@ | @@ -142,7 +143,7 @@ | ||
142 | function logout () { | 143 | function logout () { |
143 | 144 | ||
144 | Session.destroy(); | 145 | Session.destroy(); |
145 | - | 146 | + $rootScope.currentUser = null; |
146 | $rootScope.$broadcast(AUTH_EVENTS.logoutSuccess); | 147 | $rootScope.$broadcast(AUTH_EVENTS.logoutSuccess); |
147 | } | 148 | } |
148 | 149 |
src/app/components/event-list/event-list.directive.js
@@ -8,11 +8,12 @@ | @@ -8,11 +8,12 @@ | ||
8 | /** @ngInject */ | 8 | /** @ngInject */ |
9 | function eventList() { | 9 | function eventList() { |
10 | /** @ngInject */ | 10 | /** @ngInject */ |
11 | - function EventListController($scope, $rootScope, $state, $log) { | 11 | + function EventListController(ArticleService, $scope, $rootScope, $state, $log) { |
12 | $log.debug('EventListController'); | 12 | $log.debug('EventListController'); |
13 | 13 | ||
14 | var vm = this; | 14 | var vm = this; |
15 | 15 | ||
16 | + vm.ArticleService = ArticleService; | ||
16 | vm.$scope = $scope; | 17 | vm.$scope = $scope; |
17 | vm.$rootScope = $rootScope; | 18 | vm.$rootScope = $rootScope; |
18 | vm.$state = $state; | 19 | vm.$state = $state; |
@@ -39,10 +40,26 @@ | @@ -39,10 +40,26 @@ | ||
39 | vm.isCollapsed = !vm.isCollapsed; | 40 | vm.isCollapsed = !vm.isCollapsed; |
40 | }; | 41 | }; |
41 | 42 | ||
42 | - EventListController.prototype.subscribe = function (data) { | 43 | + EventListController.prototype.subscribe = function (event_id) { |
43 | var vm = this; | 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 | var directive = { | 65 | var directive = { |
src/app/components/event-list/event-list.html
@@ -59,12 +59,14 @@ | @@ -59,12 +59,14 @@ | ||
59 | <span class="theme">{{::event.categories[0].name}}</span> | 59 | <span class="theme">{{::event.categories[0].name}}</span> |
60 | </td> | 60 | </td> |
61 | <td align="right"> | 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 | </td> | 67 | </td> |
66 | <td align="left"> | 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 | Inscreva-se | 70 | Inscreva-se |
69 | <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> | 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 | </button> | 72 | </button> |
src/app/index.route.js
@@ -23,7 +23,7 @@ | @@ -23,7 +23,7 @@ | ||
23 | } | 23 | } |
24 | }) | 24 | }) |
25 | .state('entrar', { | 25 | .state('entrar', { |
26 | - url: '/entrar', | 26 | + url: '/entrar?redirect_uri', |
27 | ncyBreadcrumb: {label: 'Entrar'}, | 27 | ncyBreadcrumb: {label: 'Entrar'}, |
28 | views: { | 28 | views: { |
29 | 'header': { templateUrl: 'app/pages/header/header.html' }, | 29 | 'header': { templateUrl: 'app/pages/header/header.html' }, |
src/app/pages/article/article.html
@@ -26,9 +26,15 @@ | @@ -26,9 +26,15 @@ | ||
26 | <article> | 26 | <article> |
27 | <header class="container"> | 27 | <header class="container"> |
28 | <div class="row"> | 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 | </div> | 32 | </div> |
31 | </header> | 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 | </article> | 39 | </article> |
34 | </div> | 40 | </div> |
src/app/pages/auth/auth.controller.js
@@ -6,13 +6,13 @@ | @@ -6,13 +6,13 @@ | ||
6 | .controller('AuthPageController', AuthPageController); | 6 | .controller('AuthPageController', AuthPageController); |
7 | 7 | ||
8 | /** @ngInject */ | 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 | var vm = this; | 10 | var vm = this; |
13 | 11 | ||
14 | - vm.$rootScope = $rootScope; | ||
15 | vm.$scope = $scope; | 12 | vm.$scope = $scope; |
13 | + vm.$rootScope = $rootScope; | ||
14 | + vm.$location = $location; | ||
15 | + vm.$state = $state; | ||
16 | vm.AUTH_EVENTS = AUTH_EVENTS; | 16 | vm.AUTH_EVENTS = AUTH_EVENTS; |
17 | vm.AuthService = AuthService; | 17 | vm.AuthService = AuthService; |
18 | vm.DialogaService = DialogaService; | 18 | vm.DialogaService = DialogaService; |
@@ -21,6 +21,8 @@ | @@ -21,6 +21,8 @@ | ||
21 | 21 | ||
22 | vm.init(); | 22 | vm.init(); |
23 | vm.loadData(); | 23 | vm.loadData(); |
24 | + | ||
25 | + vm.$log.debug('AuthPageController'); | ||
24 | } | 26 | } |
25 | 27 | ||
26 | AuthPageController.prototype.init = function() { | 28 | AuthPageController.prototype.init = function() { |
@@ -32,6 +34,12 @@ | @@ -32,6 +34,12 @@ | ||
32 | vm.terms = null; | 34 | vm.terms = null; |
33 | vm.loadingTerms = null; | 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 | // attach events | 43 | // attach events |
36 | vm.currentUser = vm.Session.getCurrentUser(); | 44 | vm.currentUser = vm.Session.getCurrentUser(); |
37 | 45 | ||
@@ -78,6 +86,8 @@ | @@ -78,6 +86,8 @@ | ||
78 | // 'Cadastro efetuado com sucesso.' | 86 | // 'Cadastro efetuado com sucesso.' |
79 | // 'Verifique seu email para confirmar o cadastro.' | 87 | // 'Verifique seu email para confirmar o cadastro.' |
80 | 88 | ||
89 | + // TODO: show messagens and redirect timeout | ||
90 | + vm.redirectBack(); | ||
81 | }, function(response){ | 91 | }, function(response){ |
82 | vm.$log.debug('register error.response', response); | 92 | vm.$log.debug('register error.response', response); |
83 | 93 | ||
@@ -92,9 +102,28 @@ | @@ -92,9 +102,28 @@ | ||
92 | vm.AuthService.login(credentials).then(function(user) { | 102 | vm.AuthService.login(credentials).then(function(user) { |
93 | // handle view | 103 | // handle view |
94 | vm.$log.debug('user', user); | 104 | vm.$log.debug('user', user); |
105 | + vm.redirectBack(); | ||
95 | }, function() { | 106 | }, function() { |
96 | // handle view | 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 | })(); |