Commit 8700980c53fb6a43163a47ed73ef08c0e4987636

Authored by Victor Costa
1 parent f5c8bc74

Create service for noosfero api

src/app/components/noosfero/noosfero.service.js
1 (function() { 1 (function() {
2 'use strict'; 2 'use strict';
3 3
4 - angular.module('angular').service('noosfero', noosfero);  
5 -  
6 - function noosfero() {  
7 - this.communities = communities;  
8 - this.articles = articles;  
9 - function communities() {  
10 - // return $resource('/api/v1/communities/:id');  
11 - }  
12 - function articles() {  
13 - // return $resource('/api/v1/articles/:id'); 4 + angular.module('angular').factory('noosfero', function(Restangular) {
  5 + return {
  6 + communities: Restangular.service('communities')
14 } 7 }
15 - } 8 + });
16 })(); 9 })();
src/app/content-viewer/content-viewer.controller.js
@@ -7,13 +7,14 @@ @@ -7,13 +7,14 @@
7 7
8 8
9 /** @ngInject */ 9 /** @ngInject */
10 - function ContentViewerController(noosfero, $log, $stateParams, Restangular, $state) { 10 + function ContentViewerController(noosfero, $log, $stateParams, $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 - Restangular.one('communities', $state.current.data.profile.id).one('articles').get({path: $stateParams.page}).then(function(articles) { 16 + console.log($state.current.data);
  17 + noosfero.communities.one($state.current.data.profile.id).one('articles').get({path: $stateParams.page}).then(function(articles) {
17 $log.log(articles); 18 $log.log(articles);
18 vm.content = articles.article; 19 vm.content = articles.article;
19 }); 20 });
src/app/profile/profile.controller.js
@@ -7,13 +7,13 @@ @@ -7,13 +7,13 @@
7 7
8 8
9 /** @ngInject */ 9 /** @ngInject */
10 - function ProfileController(noosfero, $log, $stateParams, $state, Restangular) { 10 + function ProfileController(noosfero, $log, $stateParams, $state) {
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 - Restangular.one('communities').get({private_token: '1b00325e5f769a0c38550bd35b3f1d64', identifier: $stateParams.profile}).then(function(communities) { 16 + noosfero.communities.one().get({private_token: '1b00325e5f769a0c38550bd35b3f1d64', identifier: $stateParams.profile}).then(function(communities) {
17 $log.log(communities); 17 $log.log(communities);
18 vm.owner = communities.communities[0]; 18 vm.owner = communities.communities[0];
19 $state.current.data.profile = vm.owner; 19 $state.current.data.profile = vm.owner;