Commit 7f726e4d5323866c62f98543de440554f566eb01

Authored by Victor Costa
1 parent 9c2e3b8c

Redirect to profile home page

src/app/components/noosfero/noosfero.service.js
... ... @@ -4,6 +4,9 @@
4 4 angular.module('angular').factory('noosfero', function(Restangular) {
5 5 return {
6 6 profiles: Restangular.service('profiles'),
  7 + profile: function(profileId) {
  8 + return Restangular.one('profiles', profileId);
  9 + },
7 10 members: function(profile) {
8 11 return Restangular.service('members', profile);
9 12 },
... ...
src/app/index.route.js
... ... @@ -6,10 +6,9 @@
6 6 .config(routeConfig);
7 7  
8 8 function routeConfig($stateProvider, $urlRouterProvider) {
9   - $urlRouterProvider.when('/:profile', '/profile/:profile');
10 9 $stateProvider
11 10 .state('main', {
12   - url: '/',
  11 + url: '',
13 12 templateUrl: 'app/main/main.html',
14 13 controller: 'MainController',
15 14 controllerAs: 'vm',
... ... @@ -20,9 +19,15 @@
20 19 }
21 20 })
22 21 .state('main.profile', {
23   - url: ':profile',
  22 + url: '/:profile',
24 23 templateUrl: 'app/profile/profile.html',
25 24 controller: 'ProfileController',
  25 + controllerAs: 'vm',
  26 + abstract: true
  27 + })
  28 + .state('main.profile.home', {
  29 + url: '',
  30 + controller: 'ProfileHomeController',
26 31 controllerAs: 'vm'
27 32 })
28 33 .state('main.profile.info', {
... ...
src/app/profile/profile-home.controller.js 0 → 100644
... ... @@ -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 +})();
... ...