Commit c7fa6720ed1a3179896012fe6f3186423d19c13a

Authored by Caio Almeida
1 parent 73af9b92

After successful login, load list of discussions. Right now, it loads all discus…

…sions if configuration noosferoCommunity is not set, or only discussions from that community, otherwise.
ConfJuvApp/www/html/_discussions_list.html 0 → 100644
@@ -0,0 +1,5 @@ @@ -0,0 +1,5 @@
  1 +<ion-list>
  2 + <ion-item ng-repeat="discussion in discussionsList">
  3 + {{discussion.title}}
  4 + </ion-item>
  5 +</ion-list>
ConfJuvApp/www/html/_header.html
1 <ion-header-bar class="bar-assertive" align-title="left" id="header"> 1 <ion-header-bar class="bar-assertive" align-title="left" id="header">
2 - <h1 class="title">3ª Conferência Nacional de Juventude</h1> 2 + <h1 class="title">ConfJuv</h1>
3 3
4 <div class="buttons"> 4 <div class="buttons">
5 <button class="button" ng-click="openModal()">Entrar</button> 5 <button class="button" ng-click="openModal()">Entrar</button>
ConfJuvApp/www/html/_proposal_list.html
@@ -1,5 +0,0 @@ @@ -1,5 +0,0 @@
1 -<ion-list>  
2 - <ion-item ng-repeat="proposal in proposalList">  
3 - {{proposal.title}}  
4 - </ion-item>  
5 -</ion-list>  
ConfJuvApp/www/index.html
@@ -26,7 +26,7 @@ @@ -26,7 +26,7 @@
26 26
27 <!-- Main content --> 27 <!-- Main content -->
28 <ion-content> 28 <ion-content>
29 - <ng-include src="'html/_proposal_list.html'"></ng-include> 29 + <ng-include src="'html/_discussions_list.html'"></ng-include>
30 </ion-content> 30 </ion-content>
31 </ion-pane> 31 </ion-pane>
32 </body> 32 </body>
ConfJuvApp/www/js/config.js.example
1 var ConfJuvAppConfig = { 1 var ConfJuvAppConfig = {
2 - noosferoApiHost: '',  
3 - noosferoApiVersion: '',  
4 - noosferoApiPrivateToken: '' 2 + noosferoApiHost: 'http://juventude.gov.br',
  3 + noosferoApiVersion: 'v1',
  4 + noosferoCommunity: 95425
5 }; 5 };
ConfJuvApp/www/js/controllers.js
@@ -4,14 +4,7 @@ angular.module(&#39;confjuvapp.controllers&#39;, []) @@ -4,14 +4,7 @@ angular.module(&#39;confjuvapp.controllers&#39;, [])
4 $scope.loading = false; 4 $scope.loading = false;
5 5
6 // FIXME: This list should come from the server 6 // FIXME: This list should come from the server
7 - $scope.proposalList = [  
8 - {  
9 - title: 'Diminuir os juros do FIES'  
10 - },  
11 - {  
12 - title: 'Desmilitarizar a polícia'  
13 - }  
14 - ]; 7 + $scope.discussionsList = [];
15 8
16 // Login modal 9 // Login modal
17 10
@@ -56,9 +49,11 @@ angular.module(&#39;confjuvapp.controllers&#39;, []) @@ -56,9 +49,11 @@ angular.module(&#39;confjuvapp.controllers&#39;, [])
56 $http.post(ConfJuvAppUtils.pathTo('login'), jQuery.param(data), config) 49 $http.post(ConfJuvAppUtils.pathTo('login'), jQuery.param(data), config)
57 .then(function(resp) { 50 .then(function(resp) {
58 $scope.closeModal(); 51 $scope.closeModal();
59 - $ionicPopup.alert({ title: 'Login', template: 'Login efetuado com sucesso!' }); 52 + var popup = $ionicPopup.alert({ title: 'Login', template: 'Login efetuado com sucesso!' });
60 ConfJuvAppUtils.loggedIn = true; 53 ConfJuvAppUtils.loggedIn = true;
61 - $scope.loading = false; 54 + popup.then(function() {
  55 + $scope.loadDiscussions(resp.data.private_token);
  56 + });
62 }, function(err) { 57 }, function(err) {
63 $scope.closeModal(); 58 $scope.closeModal();
64 var popup = $ionicPopup.alert({ title: 'Login', template: 'Erro ao efetuar login. Verifique usuário e senha e conexão com a internet.' }); 59 var popup = $ionicPopup.alert({ title: 'Login', template: 'Erro ao efetuar login. Verifique usuário e senha e conexão com a internet.' });
@@ -70,4 +65,26 @@ angular.module(&#39;confjuvapp.controllers&#39;, []) @@ -70,4 +65,26 @@ angular.module(&#39;confjuvapp.controllers&#39;, [])
70 }); 65 });
71 }; 66 };
72 67
  68 + $scope.loadDiscussions = function(token) {
  69 + $scope.discussionsList = [];
  70 +
  71 + var path = '?private_token=' + token + '&fields=title&content_type=ProposalsDiscussionPlugin::Discussion';
  72 +
  73 + if (ConfJuvAppConfig.noosferoCommunity == '') {
  74 + path = 'articles' + path;
  75 + }
  76 + else {
  77 + path = 'communities/' + ConfJuvAppConfig.noosferoCommunity + '/articles' + path;
  78 + }
  79 +
  80 + $http.get(ConfJuvAppUtils.pathTo(path))
  81 + .then(function(resp) {
  82 + $scope.loading = false;
  83 + $scope.discussionsList = resp.data.articles;
  84 + }, function(err) {
  85 + var popup = $ionicPopup.alert({ title: 'Discussões', template: 'Não foi possível carregar as discussões' });
  86 + $scope.loading = false;
  87 + });
  88 + };
  89 +
73 }); // Ends controller 90 }); // Ends controller