Commit 4581f0f807b93955a9a3883d41f4244b1c997f78
1 parent
0aae6e92
Exists in
master
and in
1 other branch
Refactor current profile from noosfero service
Showing
7 changed files
with
29 additions
and
27 deletions
Show diff stats
src/app/cms/cms.controller.js
... | ... | @@ -11,20 +11,17 @@ |
11 | 11 | var vm = this; |
12 | 12 | vm.article = {}; |
13 | 13 | vm.profile = null; |
14 | - activate(); | |
15 | - | |
16 | - function activate() { | |
17 | - vm.profile = noosfero.currentProfile; | |
18 | - } | |
19 | 14 | |
20 | 15 | vm.save = function() { |
21 | - noosfero.profiles.one(vm.profile.id).customPOST( | |
22 | - {article: vm.article}, | |
23 | - 'articles', | |
24 | - {}, | |
25 | - {'Content-Type':'application/json'} | |
26 | - ).then(function(response) { | |
27 | - $state.transitionTo('main.profile.page', {page: response.data.article.path, profile: vm.profile.identifier}); | |
16 | + noosfero.currentProfile.then(function(profile) { | |
17 | + return noosfero.profiles.one(profile.id).customPOST( | |
18 | + {article: vm.article}, | |
19 | + 'articles', | |
20 | + {}, | |
21 | + {'Content-Type':'application/json'} | |
22 | + ) | |
23 | + }).then(function(response) { | |
24 | + $state.transitionTo('main.profile.page', {page: response.data.article.path, profile: response.data.article.profile.identifier}); | |
28 | 25 | SweetAlert.swal({ |
29 | 26 | title: "Good job!", |
30 | 27 | text: "Article saved!", | ... | ... |
src/app/components/noosfero/noosfero.service.js
1 | 1 | (function() { |
2 | 2 | 'use strict'; |
3 | 3 | |
4 | - angular.module('angular').factory('noosfero', function(Restangular) { | |
5 | - var currentProfile; | |
4 | + angular.module('angular').factory('noosfero', function(Restangular, $q) { | |
5 | + var currentProfile = $q.defer(); | |
6 | 6 | |
7 | 7 | return { |
8 | - currentProfile: currentProfile, | |
8 | + currentProfile: currentProfile.promise, | |
9 | + setCurrentProfile: function(profile) { currentProfile.resolve(profile) }, | |
9 | 10 | profiles: Restangular.service('profiles'), |
10 | 11 | articles: Restangular.service('articles'), |
11 | 12 | profile: function(profileId) { | ... | ... |
src/app/content-viewer/content-viewer-actions.controller.js
... | ... | @@ -14,11 +14,9 @@ |
14 | 14 | activate(); |
15 | 15 | |
16 | 16 | function activate() { |
17 | - $scope.$watch(function() { return noosfero.currentProfile }, | |
18 | - function() { | |
19 | - vm.profile = noosfero.currentProfile; | |
20 | - } | |
21 | - ); | |
17 | + noosfero.currentProfile.then(function(profile) { | |
18 | + vm.profile = profile; | |
19 | + }); | |
22 | 20 | } |
23 | 21 | } |
24 | 22 | })(); | ... | ... |
src/app/content-viewer/content-viewer.controller.js
... | ... | @@ -14,8 +14,10 @@ |
14 | 14 | activate(); |
15 | 15 | |
16 | 16 | function activate() { |
17 | - vm.profile = noosfero.currentProfile; | |
18 | - noosfero.profiles.one(vm.profile.id).one('articles').get({path: $stateParams.page}).then(function(response) { | |
17 | + noosfero.currentProfile.then(function(profile) { | |
18 | + vm.profile = profile; | |
19 | + return noosfero.profiles.one(vm.profile.id).one('articles').get({path: $stateParams.page}); | |
20 | + }).then(function(response) { | |
19 | 21 | vm.article = response.data.article; |
20 | 22 | }); |
21 | 23 | } | ... | ... |
src/app/profile-info/profile-info.controller.js
... | ... | @@ -14,8 +14,10 @@ |
14 | 14 | activate(); |
15 | 15 | |
16 | 16 | function activate() { |
17 | - vm.profile = noosfero.currentProfile; | |
18 | - noosfero.profiles.one(vm.profile.id).one('activities').get().then(function(response) { | |
17 | + noosfero.currentProfile.then(function(profile) { | |
18 | + vm.profile = profile; | |
19 | + return noosfero.profiles.one(vm.profile.id).one('activities').get(); | |
20 | + }).then(function(response) { | |
19 | 21 | vm.activities = response.data.activities; |
20 | 22 | }); |
21 | 23 | } | ... | ... |
src/app/profile/profile-home.controller.js
... | ... | @@ -12,8 +12,10 @@ |
12 | 12 | activate(); |
13 | 13 | |
14 | 14 | function activate() { |
15 | - vm.profile = noosfero.currentProfile; | |
16 | - noosfero.profile(vm.profile.id).customGET('home_page', {fields: 'path'}).then(function(response) { | |
15 | + noosfero.currentProfile.then(function(profile) { | |
16 | + vm.profile = profile; | |
17 | + return noosfero.profile(vm.profile.id).customGET('home_page', {fields: 'path'}); | |
18 | + }).then(function(response) { | |
17 | 19 | if(response.data.article) { |
18 | 20 | $state.transitionTo('main.profile.page', {page: response.data.article.path, profile: vm.profile.identifier}, {location: false}); |
19 | 21 | } else { | ... | ... |
src/app/profile/profile.controller.js
... | ... | @@ -15,7 +15,7 @@ |
15 | 15 | function activate() { |
16 | 16 | noosfero.profiles.one().get({identifier: $stateParams.profile}).then(function(response) { |
17 | 17 | vm.profile = response.data[0]; |
18 | - noosfero.currentProfile = vm.profile; | |
18 | + noosfero.setCurrentProfile(vm.profile); | |
19 | 19 | return noosfero.boxes(vm.profile.id).one().get(); |
20 | 20 | }).then(function(response) { |
21 | 21 | vm.boxes = response.data.boxes; | ... | ... |