profile-home.component.ts 1.19 KB
import {StateConfig, Component, Inject, provide} from 'ng-forward';

import {ProfileService} from "../../lib/ng-noosfero-api/http/profile.service";

@Component({
    selector: 'profile-home',
    template: "<div></div>",
    providers: [provide('profileService', { useClass: ProfileService })]
})
@Inject(ProfileService, "$state")
export class ProfileHomeComponent {

    profile: noosfero.Profile;

    constructor(profileService: ProfileService, $state: ng.ui.IStateService) {
        profileService.getCurrentProfile().then((profile: noosfero.Profile) => {
            this.profile = profile;
            return profileService.getHomePage(<number>this.profile.id, { fields: 'path' });
        }).then((response: restangular.IResponse) => {
            if (response.data.article) {
                this.profile.homepage = response.data.article.path;
                $state.transitionTo('main.profile.page', { page: response.data.article.path, profile: this.profile.identifier }, { location: false });
            } else {
                this.profile.homepage = null;
                $state.transitionTo('main.profile.info', { profile: this.profile.identifier }, { location: false });
            }
        });
    }
}