Commit 4581f0f807b93955a9a3883d41f4244b1c997f78
1 parent
0aae6e92
Exists in
master
and in
38 other branches
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,20 +11,17 @@ | ||
| 11 | var vm = this; | 11 | var vm = this; |
| 12 | vm.article = {}; | 12 | vm.article = {}; |
| 13 | vm.profile = null; | 13 | vm.profile = null; |
| 14 | - activate(); | ||
| 15 | - | ||
| 16 | - function activate() { | ||
| 17 | - vm.profile = noosfero.currentProfile; | ||
| 18 | - } | ||
| 19 | 14 | ||
| 20 | vm.save = function() { | 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 | SweetAlert.swal({ | 25 | SweetAlert.swal({ |
| 29 | title: "Good job!", | 26 | title: "Good job!", |
| 30 | text: "Article saved!", | 27 | text: "Article saved!", |
src/app/components/noosfero/noosfero.service.js
| 1 | (function() { | 1 | (function() { |
| 2 | 'use strict'; | 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 | return { | 7 | return { |
| 8 | - currentProfile: currentProfile, | 8 | + currentProfile: currentProfile.promise, |
| 9 | + setCurrentProfile: function(profile) { currentProfile.resolve(profile) }, | ||
| 9 | profiles: Restangular.service('profiles'), | 10 | profiles: Restangular.service('profiles'), |
| 10 | articles: Restangular.service('articles'), | 11 | articles: Restangular.service('articles'), |
| 11 | profile: function(profileId) { | 12 | profile: function(profileId) { |
src/app/content-viewer/content-viewer-actions.controller.js
| @@ -14,11 +14,9 @@ | @@ -14,11 +14,9 @@ | ||
| 14 | activate(); | 14 | activate(); |
| 15 | 15 | ||
| 16 | function activate() { | 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,8 +14,10 @@ | ||
| 14 | activate(); | 14 | activate(); |
| 15 | 15 | ||
| 16 | function activate() { | 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 | vm.article = response.data.article; | 21 | vm.article = response.data.article; |
| 20 | }); | 22 | }); |
| 21 | } | 23 | } |
src/app/profile-info/profile-info.controller.js
| @@ -14,8 +14,10 @@ | @@ -14,8 +14,10 @@ | ||
| 14 | activate(); | 14 | activate(); |
| 15 | 15 | ||
| 16 | function activate() { | 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 | vm.activities = response.data.activities; | 21 | vm.activities = response.data.activities; |
| 20 | }); | 22 | }); |
| 21 | } | 23 | } |
src/app/profile/profile-home.controller.js
| @@ -12,8 +12,10 @@ | @@ -12,8 +12,10 @@ | ||
| 12 | activate(); | 12 | activate(); |
| 13 | 13 | ||
| 14 | function activate() { | 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 | if(response.data.article) { | 19 | if(response.data.article) { |
| 18 | $state.transitionTo('main.profile.page', {page: response.data.article.path, profile: vm.profile.identifier}, {location: false}); | 20 | $state.transitionTo('main.profile.page', {page: response.data.article.path, profile: vm.profile.identifier}, {location: false}); |
| 19 | } else { | 21 | } else { |
src/app/profile/profile.controller.js
| @@ -15,7 +15,7 @@ | @@ -15,7 +15,7 @@ | ||
| 15 | function activate() { | 15 | function activate() { |
| 16 | noosfero.profiles.one().get({identifier: $stateParams.profile}).then(function(response) { | 16 | noosfero.profiles.one().get({identifier: $stateParams.profile}).then(function(response) { |
| 17 | vm.profile = response.data[0]; | 17 | vm.profile = response.data[0]; |
| 18 | - noosfero.currentProfile = vm.profile; | 18 | + noosfero.setCurrentProfile(vm.profile); |
| 19 | return noosfero.boxes(vm.profile.id).one().get(); | 19 | return noosfero.boxes(vm.profile.id).one().get(); |
| 20 | }).then(function(response) { | 20 | }).then(function(response) { |
| 21 | vm.boxes = response.data.boxes; | 21 | vm.boxes = response.data.boxes; |