Skip to content
Snippets Groups Projects
portal-home.component.ts 2.29 KiB
/**
 * This file is part of Anis Client.
 *
 * @copyright Laboratoire d'Astrophysique de Marseille / CNRS
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

import { Component, OnInit } from '@angular/core';
import { Observable } from 'rxjs';
import { Store } from '@ngrx/store';

import { UserProfile } from 'src/app/auth/user-profile.model';
import { Instance } from 'src/app/metamodel/models';
import * as authActions from 'src/app/auth/auth.actions';
import * as authSelector from 'src/app/auth/auth.selector';
import * as instanceActions from 'src/app/metamodel/actions/instance.actions';
import * as instanceSelector from 'src/app/metamodel/selectors/instance.selector';

@Component({
    selector: 'app-portal-home',
    templateUrl: 'portal-home.component.html'
})
/**
 * @class
 * @classdesc Portal home container.
 *
 * @implements OnInit
 */
export class PortalHomeComponent implements OnInit {
    public links = [
        { label: 'Home', icon: 'fas fa-home', routerLink: '/portal' },
        { label: 'Admin', icon: 'fas fa-tools', routerLink: '/admin' }
    ];
    public isAuthenticated: Observable<boolean>;
    public userProfile: Observable<UserProfile>;
    public userRoles: Observable<string[]>;
    public instanceListIsLoading: Observable<boolean>;
    public instanceListIsLoaded: Observable<boolean>;
    public instanceList: Observable<Instance[]>;

    constructor(private store: Store<{ }>) {
        this.isAuthenticated = store.select(authSelector.selectIsAuthenticated);
        this.userProfile = store.select(authSelector.selectUserProfile);
        this.userRoles = store.select(authSelector.selectUserRoles);
        this.instanceListIsLoading = store.select(instanceSelector.selectInstanceListIsLoading);
        this.instanceListIsLoaded = store.select(instanceSelector.selectInstanceListIsLoaded);
        this.instanceList = store.select(instanceSelector.selectAllInstances);
    }

    ngOnInit() {
        this.store.dispatch(instanceActions.loadInstanceList());
    }

    login(): void {
        this.store.dispatch(authActions.login());
    }

    logout(): void {
        this.store.dispatch(authActions.logout());
    }

    openEditProfile(): void {
        this.store.dispatch(authActions.openEditProfile());
    }
}