Commit dd3ef4b89c06bbd17c0a71d58da4cf300de66397
1 parent
766b4430
Exists in
master
and in
35 other branches
Migrate profile home controller
Showing
5 changed files
with
38 additions
and
37 deletions
Show diff stats
src/app/index.route.ts
... | ... | @@ -6,15 +6,6 @@ export function routeConfig($stateProvider, $urlRouterProvider) { |
6 | 6 | .state("main.profile.settings", { |
7 | 7 | url: "^/myprofile/:profile" |
8 | 8 | }) |
9 | - .state("main.profile.home", { | |
10 | - url: "", | |
11 | - views: { | |
12 | - "mainBlockContent": { | |
13 | - controller: "ProfileHomeController", | |
14 | - controllerAs: "vm" | |
15 | - } | |
16 | - } | |
17 | - }) | |
18 | 9 | .state("main.profile.page", { |
19 | 10 | url: "/{page:any}", |
20 | 11 | views: { | ... | ... |
src/app/index.ts
... | ... | @@ -9,6 +9,7 @@ import {routeConfig} from "./index.route"; |
9 | 9 | import {ContentViewer as noosferoContentViewer} from "./content-viewer/content-viewer.component"; |
10 | 10 | import {Profile as noosferoProfile} from "./profile/profile.component"; |
11 | 11 | import {ProfileInfo as noosferoProfileInfo} from "./profile-info/profile-info.component"; |
12 | +import {ProfileHome as noosferoProfileHome} from "./profile/profile-home.component"; | |
12 | 13 | import {Cms as noosferoCms} from "./cms/cms.component"; |
13 | 14 | |
14 | 15 | import {Main} from "./main/main.component"; |
... | ... | @@ -52,10 +53,10 @@ require("./components/noosfero/noosfero-template.filter.js"); |
52 | 53 | require("./components/noosfero/noosfero.service.js"); |
53 | 54 | require("./components/noosfero/profile-image/profile-image.component.js"); |
54 | 55 | require("./content-viewer/content-viewer-actions.controller.js"); |
55 | -require("./profile/profile-home.controller.js"); | |
56 | 56 | |
57 | 57 | NoosferoApp.addController("ContentViewerController", noosferoContentViewer); |
58 | 58 | NoosferoApp.addController("ProfileController", noosferoProfile); |
59 | +NoosferoApp.addController("ProfileHomeController", noosferoProfileHome); | |
59 | 60 | NoosferoApp.addController("ProfileInfoController", noosferoProfileInfo); |
60 | 61 | NoosferoApp.addController("CmsController", noosferoCms); |
61 | 62 | ... | ... |
... | ... | @@ -0,0 +1,24 @@ |
1 | +import {StateConfig, Component, Inject} from 'ng-forward'; | |
2 | + | |
3 | +@Component({ | |
4 | + selector: 'profile-home', | |
5 | + template: "<div></div>" | |
6 | +}) | |
7 | +@Inject("noosfero", "$log", "$stateParams", "$scope", "$state") | |
8 | +export class ProfileHome { | |
9 | + | |
10 | + profile: any; | |
11 | + | |
12 | + constructor(noosfero, $log, $stateParams, $scope, $state) { | |
13 | + noosfero.currentProfile.then((profile) => { | |
14 | + this.profile = profile; | |
15 | + return noosfero.profile(this.profile.id).customGET('home_page', { fields: 'path' }); | |
16 | + }).then((response) => { | |
17 | + if (response.data.article) { | |
18 | + $state.transitionTo('main.profile.page', { page: response.data.article.path, profile: this.profile.identifier }, { location: false }); | |
19 | + } else { | |
20 | + $state.transitionTo('main.profile.info', { profile: this.profile.identifier }, { location: false }); | |
21 | + } | |
22 | + }); | |
23 | + } | |
24 | +} | ... | ... |
src/app/profile/profile-home.controller.js
... | ... | @@ -1,27 +0,0 @@ |
1 | -(function() { | |
2 | - 'use strict'; | |
3 | - | |
4 | - angular | |
5 | - .module('noosferoApp') | |
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 | - 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) { | |
19 | - if(response.data.article) { | |
20 | - $state.transitionTo('main.profile.page', {page: response.data.article.path, profile: vm.profile.identifier}, {location: false}); | |
21 | - } else { | |
22 | - $state.transitionTo('main.profile.info', {profile: vm.profile.identifier}, {location: false}); | |
23 | - } | |
24 | - }); | |
25 | - } | |
26 | - } | |
27 | -})(); |
src/app/profile/profile.component.ts
1 | 1 | import {StateConfig, Component, Inject} from 'ng-forward'; |
2 | 2 | import {ProfileInfo} from '../profile-info/profile-info.component' |
3 | +import {ProfileHome} from '../profile/profile-home.component' | |
3 | 4 | import {Cms} from '../cms/cms.component' |
4 | 5 | |
5 | 6 | @Component({ |
... | ... | @@ -31,6 +32,17 @@ import {Cms} from '../cms/cms.component' |
31 | 32 | } |
32 | 33 | } |
33 | 34 | }, |
35 | + { | |
36 | + name: 'main.profile.home', | |
37 | + url: "", | |
38 | + component: ProfileHome, | |
39 | + views: { | |
40 | + "mainBlockContent": { | |
41 | + controller: "ProfileHomeController", | |
42 | + controllerAs: "vm" | |
43 | + } | |
44 | + } | |
45 | + }, | |
34 | 46 | ]) |
35 | 47 | @Inject("noosfero", "$log", "$stateParams") |
36 | 48 | export class Profile { | ... | ... |