diff --git a/src/app/components/noosfero/noosfero.service.js b/src/app/components/noosfero/noosfero.service.js index 3a22840..e2b3062 100644 --- a/src/app/components/noosfero/noosfero.service.js +++ b/src/app/components/noosfero/noosfero.service.js @@ -4,6 +4,9 @@ angular.module('angular').factory('noosfero', function(Restangular) { return { profiles: Restangular.service('profiles'), + profile: function(profileId) { + return Restangular.one('profiles', profileId); + }, members: function(profile) { return Restangular.service('members', profile); }, diff --git a/src/app/index.route.js b/src/app/index.route.js index 288d2e9..2dc2f03 100644 --- a/src/app/index.route.js +++ b/src/app/index.route.js @@ -6,10 +6,9 @@ .config(routeConfig); function routeConfig($stateProvider, $urlRouterProvider) { - $urlRouterProvider.when('/:profile', '/profile/:profile'); $stateProvider .state('main', { - url: '/', + url: '', templateUrl: 'app/main/main.html', controller: 'MainController', controllerAs: 'vm', @@ -20,9 +19,15 @@ } }) .state('main.profile', { - url: ':profile', + url: '/:profile', templateUrl: 'app/profile/profile.html', controller: 'ProfileController', + controllerAs: 'vm', + abstract: true + }) + .state('main.profile.home', { + url: '', + controller: 'ProfileHomeController', controllerAs: 'vm' }) .state('main.profile.info', { diff --git a/src/app/profile/profile-home.controller.js b/src/app/profile/profile-home.controller.js new file mode 100644 index 0000000..1c69e1e --- /dev/null +++ b/src/app/profile/profile-home.controller.js @@ -0,0 +1,25 @@ +(function() { + 'use strict'; + + angular + .module('angular') + .controller('ProfileHomeController', ProfileHomeController); + + + /** @ngInject */ + function ProfileHomeController(noosfero, $log, $stateParams, $scope, $state) { + var vm = this; + activate(); + + function activate() { + vm.profile = $scope.vm.owner; + noosfero.profile(vm.profile.id).customGET('home_page', {fields: 'path'}).then(function(result) { + if(result.article) { + $state.transitionTo('main.profile.page', {page: result.article.path, profile: vm.profile.identifier}); + } else { + $state.transitionTo('main.profile.info', {profile: vm.profile.identifier}); + } + }); + } + } +})(); -- libgit2 0.21.2