Commit 279252435487987f981b3cf1d89ed63269ee5444

Authored by Caio Almeida
1 parent 07cb7dcb

Ticket #56: Get full list of followed proposals

Showing 1 changed file with 9 additions and 6 deletions   Show diff stats
www/js/controllers.js
@@ -1125,14 +1125,16 @@ angular.module('confjuvapp.controllers', []) @@ -1125,14 +1125,16 @@ angular.module('confjuvapp.controllers', [])
1125 timeout: 10000 1125 timeout: 10000
1126 }; 1126 };
1127 1127
1128 - $http.get(ConfJuvAppUtils.pathTo('/articles/followed_by_me?fields=id&private_token=' + $scope.token + '&_=' + new Date().getTime()), config) 1128 + $http.get(ConfJuvAppUtils.pathTo('/articles/followed_by_me?private_token=' + $scope.token + '&_=' + new Date().getTime()), config)
1129 .then(function(resp) { 1129 .then(function(resp) {
1130 - $scope.loading = false;  
1131 $scope.following = []; 1130 $scope.following = [];
  1131 + $scope.followingIds = [];
1132 var followed = resp.data.articles; 1132 var followed = resp.data.articles;
1133 for (var i = 0; i < followed.length; i++) { 1133 for (var i = 0; i < followed.length; i++) {
1134 - $scope.following.push(followed[i].id); 1134 + $scope.following.push(followed[i]);
  1135 + $scope.followingIds.push(followed[i].id);
1135 } 1136 }
  1137 + $scope.loading = false;
1136 }, function(err) { 1138 }, function(err) {
1137 $scope.loading = false; 1139 $scope.loading = false;
1138 $ionicPopup.alert({ title: 'Propostas seguidas', template: 'Erro ao carregar propostas seguidas' }); 1140 $ionicPopup.alert({ title: 'Propostas seguidas', template: 'Erro ao carregar propostas seguidas' });
@@ -1140,8 +1142,8 @@ angular.module(&#39;confjuvapp.controllers&#39;, []) @@ -1140,8 +1142,8 @@ angular.module(&#39;confjuvapp.controllers&#39;, [])
1140 }; 1142 };
1141 1143
1142 $scope.isFollowing = function(proposal) { 1144 $scope.isFollowing = function(proposal) {
1143 - if ($scope.hasOwnProperty('following')) {  
1144 - return ($scope.following.indexOf(proposal.id) > -1); 1145 + if ($scope.hasOwnProperty('followingIds')) {
  1146 + return ($scope.followingIds.indexOf(proposal.id) > -1);
1145 } 1147 }
1146 else { 1148 else {
1147 return false; 1149 return false;
@@ -1161,7 +1163,8 @@ angular.module(&#39;confjuvapp.controllers&#39;, []) @@ -1161,7 +1163,8 @@ angular.module(&#39;confjuvapp.controllers&#39;, [])
1161 $http.post(ConfJuvAppUtils.pathTo('articles/' + proposal.id + '/follow'), jQuery.param({ private_token: $scope.token }), config) 1163 $http.post(ConfJuvAppUtils.pathTo('articles/' + proposal.id + '/follow'), jQuery.param({ private_token: $scope.token }), config)
1162 .then(function(resp) { 1164 .then(function(resp) {
1163 $ionicPopup.alert({ title: 'Seguir proposta', template: 'Pronto! Você pode acompanhar suas propostas seguidas através do menu lateral esquerdo.' }); 1165 $ionicPopup.alert({ title: 'Seguir proposta', template: 'Pronto! Você pode acompanhar suas propostas seguidas através do menu lateral esquerdo.' });
1164 - $scope.following.push(proposal.id); 1166 + $scope.following.push(proposal);
  1167 + $scope.followingIds.push(proposal.id);
1165 $scope.loading = false; 1168 $scope.loading = false;
1166 }, function(err) { 1169 }, function(err) {
1167 $ionicPopup.alert({ title: 'Seguir proposta', template: 'Erro ao seguir proposta.' }); 1170 $ionicPopup.alert({ title: 'Seguir proposta', template: 'Erro ao seguir proposta.' });