Commit 7f726e4d5323866c62f98543de440554f566eb01
1 parent
9c2e3b8c
Exists in
master
and in
38 other branches
Redirect to profile home page
Showing
3 changed files
with
36 additions
and
3 deletions
Show diff stats
src/app/components/noosfero/noosfero.service.js
| @@ -4,6 +4,9 @@ | @@ -4,6 +4,9 @@ | ||
| 4 | angular.module('angular').factory('noosfero', function(Restangular) { | 4 | angular.module('angular').factory('noosfero', function(Restangular) { |
| 5 | return { | 5 | return { |
| 6 | profiles: Restangular.service('profiles'), | 6 | profiles: Restangular.service('profiles'), |
| 7 | + profile: function(profileId) { | ||
| 8 | + return Restangular.one('profiles', profileId); | ||
| 9 | + }, | ||
| 7 | members: function(profile) { | 10 | members: function(profile) { |
| 8 | return Restangular.service('members', profile); | 11 | return Restangular.service('members', profile); |
| 9 | }, | 12 | }, |
src/app/index.route.js
| @@ -6,10 +6,9 @@ | @@ -6,10 +6,9 @@ | ||
| 6 | .config(routeConfig); | 6 | .config(routeConfig); |
| 7 | 7 | ||
| 8 | function routeConfig($stateProvider, $urlRouterProvider) { | 8 | function routeConfig($stateProvider, $urlRouterProvider) { |
| 9 | - $urlRouterProvider.when('/:profile', '/profile/:profile'); | ||
| 10 | $stateProvider | 9 | $stateProvider |
| 11 | .state('main', { | 10 | .state('main', { |
| 12 | - url: '/', | 11 | + url: '', |
| 13 | templateUrl: 'app/main/main.html', | 12 | templateUrl: 'app/main/main.html', |
| 14 | controller: 'MainController', | 13 | controller: 'MainController', |
| 15 | controllerAs: 'vm', | 14 | controllerAs: 'vm', |
| @@ -20,9 +19,15 @@ | @@ -20,9 +19,15 @@ | ||
| 20 | } | 19 | } |
| 21 | }) | 20 | }) |
| 22 | .state('main.profile', { | 21 | .state('main.profile', { |
| 23 | - url: ':profile', | 22 | + url: '/:profile', |
| 24 | templateUrl: 'app/profile/profile.html', | 23 | templateUrl: 'app/profile/profile.html', |
| 25 | controller: 'ProfileController', | 24 | controller: 'ProfileController', |
| 25 | + controllerAs: 'vm', | ||
| 26 | + abstract: true | ||
| 27 | + }) | ||
| 28 | + .state('main.profile.home', { | ||
| 29 | + url: '', | ||
| 30 | + controller: 'ProfileHomeController', | ||
| 26 | controllerAs: 'vm' | 31 | controllerAs: 'vm' |
| 27 | }) | 32 | }) |
| 28 | .state('main.profile.info', { | 33 | .state('main.profile.info', { |
| @@ -0,0 +1,25 @@ | @@ -0,0 +1,25 @@ | ||
| 1 | +(function() { | ||
| 2 | + 'use strict'; | ||
| 3 | + | ||
| 4 | + angular | ||
| 5 | + .module('angular') | ||
| 6 | + .controller('ProfileHomeController', ProfileHomeController); | ||
| 7 | + | ||
| 8 | + | ||
| 9 | + /** @ngInject */ | ||
| 10 | + function ProfileHomeController(noosfero, $log, $stateParams, $scope, $state) { | ||
| 11 | + var vm = this; | ||
| 12 | + activate(); | ||
| 13 | + | ||
| 14 | + function activate() { | ||
| 15 | + vm.profile = $scope.vm.owner; | ||
| 16 | + noosfero.profile(vm.profile.id).customGET('home_page', {fields: 'path'}).then(function(result) { | ||
| 17 | + if(result.article) { | ||
| 18 | + $state.transitionTo('main.profile.page', {page: result.article.path, profile: vm.profile.identifier}); | ||
| 19 | + } else { | ||
| 20 | + $state.transitionTo('main.profile.info', {profile: vm.profile.identifier}); | ||
| 21 | + } | ||
| 22 | + }); | ||
| 23 | + } | ||
| 24 | + } | ||
| 25 | +})(); |