Commit 5dbbddc9ff58bbfe306d903b41fae9e1cd14bcbd

Authored by Victor Costa
1 parent f338d0b4

Use restangular to get data from api

@@ -8,7 +8,7 @@ @@ -8,7 +8,7 @@
8 "angular-sanitize": "~1.4.2", 8 "angular-sanitize": "~1.4.2",
9 "angular-messages": "~1.4.2", 9 "angular-messages": "~1.4.2",
10 "angular-aria": "~1.4.2", 10 "angular-aria": "~1.4.2",
11 - "angular-resource": "~1.4.2", 11 + "restangular": "~1.5.1",
12 "angular-ui-router": "~0.2.15", 12 "angular-ui-router": "~0.2.15",
13 "bootstrap-sass": "~3.3.5", 13 "bootstrap-sass": "~3.3.5",
14 "angular-bootstrap": "~0.13.4", 14 "angular-bootstrap": "~0.13.4",
src/app/components/noosfero/noosfero.service.js
@@ -3,14 +3,14 @@ @@ -3,14 +3,14 @@
3 3
4 angular.module('angular').service('noosfero', noosfero); 4 angular.module('angular').service('noosfero', noosfero);
5 5
6 - function noosfero($resource) { 6 + function noosfero() {
7 this.communities = communities; 7 this.communities = communities;
8 this.articles = articles; 8 this.articles = articles;
9 function communities() { 9 function communities() {
10 - return $resource('/api/v1/communities/:id'); 10 + // return $resource('/api/v1/communities/:id');
11 } 11 }
12 function articles() { 12 function articles() {
13 - return $resource('/api/v1/articles/:id'); 13 + // return $resource('/api/v1/articles/:id');
14 } 14 }
15 } 15 }
16 })(); 16 })();
src/app/content-viewer/content-viewer.controller.js
@@ -7,17 +7,15 @@ @@ -7,17 +7,15 @@
7 7
8 8
9 /** @ngInject */ 9 /** @ngInject */
10 - function ContentViewerController(noosfero, $log, $stateParams) { 10 + function ContentViewerController(noosfero, $log, $stateParams, Restangular, $state) {
11 var vm = this; 11 var vm = this;
12 vm.article = null; 12 vm.article = null;
13 activate(); 13 activate();
14 14
15 function activate() { 15 function activate() {
16 - $log.log($stateParams.page);  
17 - noosfero.articles().get({path: $stateParams.page, private_token: '1b00325e5f769a0c38550bd35b3f1d64'}).$promise.then(function (article) {  
18 - //FIXME  
19 - vm.content = article.articles[0];  
20 - console.log(vm.content); 16 + Restangular.one('communities', $state.current.data.profile.id).one('articles').get({path: $stateParams.page}).then(function(articles) {
  17 + $log.log(articles);
  18 + vm.content = articles.article;
21 }); 19 });
22 } 20 }
23 } 21 }
src/app/index.config.js
@@ -6,11 +6,10 @@ @@ -6,11 +6,10 @@
6 .config(config); 6 .config(config);
7 7
8 /** @ngInject */ 8 /** @ngInject */
9 - function config($logProvider, $locationProvider) {  
10 - // Enable log 9 + function config($logProvider, $locationProvider, RestangularProvider) {
11 $logProvider.debugEnabled(true); 10 $logProvider.debugEnabled(true);
12 -  
13 $locationProvider.html5Mode({enabled: true}); 11 $locationProvider.html5Mode({enabled: true});
  12 + RestangularProvider.setBaseUrl('/api/v1');
14 } 13 }
15 14
16 })(); 15 })();
src/app/index.module.js
@@ -2,6 +2,6 @@ @@ -2,6 +2,6 @@
2 'use strict'; 2 'use strict';
3 3
4 angular 4 angular
5 - .module('angular', ['ngAnimate', 'ngCookies', 'ngTouch', 'ngSanitize', 'ngMessages', 'ngAria', 'ngResource', 'ui.router', 'ui.bootstrap', 'toastr']); 5 + .module('angular', ['ngAnimate', 'ngCookies', 'ngTouch', 'ngSanitize', 'ngMessages', 'ngAria', 'restangular', 'ui.router', 'ui.bootstrap', 'toastr']);
6 6
7 })(); 7 })();
src/app/index.route.js
@@ -13,7 +13,10 @@ @@ -13,7 +13,10 @@
13 url: '/:profile', 13 url: '/:profile',
14 templateUrl: 'app/profile/profile.html', 14 templateUrl: 'app/profile/profile.html',
15 controller: 'ProfileController', 15 controller: 'ProfileController',
16 - controllerAs: 'vm' 16 + controllerAs: 'vm',
  17 + data: {
  18 + profile: null
  19 + }
17 }) 20 })
18 .state('profile.page', { 21 .state('profile.page', {
19 url: '/{page:.*}', 22 url: '/{page:.*}',
src/app/profile/profile.controller.js
@@ -7,15 +7,16 @@ @@ -7,15 +7,16 @@
7 7
8 8
9 /** @ngInject */ 9 /** @ngInject */
10 - function ProfileController(noosfero, $log, $stateParams) { 10 + function ProfileController(noosfero, $log, $stateParams, $state, Restangular) {
11 var vm = this; 11 var vm = this;
12 vm.boxes = []; 12 vm.boxes = [];
13 activate(); 13 activate();
14 14
15 function activate() { 15 function activate() {
16 - noosfero.communities().get({identifier: $stateParams.profile, private_token: '1b00325e5f769a0c38550bd35b3f1d64'}).$promise.then(function (profile) {  
17 - $log.log(profile);  
18 - vm.owner = profile.communities[0]; 16 + Restangular.one('communities').get({private_token: '1b00325e5f769a0c38550bd35b3f1d64', identifier: $stateParams.profile}).then(function(communities) {
  17 + $log.log(communities);
  18 + vm.owner = communities.communities[0];
  19 + $state.current.data.profile = vm.owner;
19 }); 20 });
20 } 21 }
21 22