Skip to content
Snippets Groups Projects
portal-home.component.ts 3.31 KiB
Newer Older
  • Learn to ignore specific revisions
  • François Agneray's avatar
    WIP
    François Agneray committed
    /**
     * 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.
     */
    
    
    François Agneray's avatar
    François Agneray committed
    import { Component, OnInit } from '@angular/core';
    
    import { Observable, Subscription } from 'rxjs';
    
    François Agneray's avatar
    WIP
    François Agneray committed
    import { Store } from '@ngrx/store';
    
    import { UserProfile } from 'src/app/auth/user-profile.model';
    
    import { Instance, InstanceGroup } from 'src/app/metamodel/models';
    
    François Agneray's avatar
    François Agneray committed
    import * as authActions from 'src/app/auth/auth.actions';
    
    François Agneray's avatar
    WIP
    François Agneray committed
    import * as authSelector from 'src/app/auth/auth.selector';
    
    import * as instanceSelector from 'src/app/metamodel/selectors/instance.selector';
    
    import * as instanceGroupSelector from 'src/app/metamodel/selectors/instance-group.selector';
    
    import { AppConfigService } from 'src/app/app-config.service';
    
    François Agneray's avatar
    François Agneray committed
    import { StyleService } from 'src/app/shared/services/style.service';
    
    François Agneray's avatar
    WIP
    François Agneray committed
    
    /**
     * @class
     * @classdesc Portal home container.
     *
     * @implements OnInit
    
     * @implements OnDestroy
    
    François Agneray's avatar
    WIP
    François Agneray committed
     */
    
    @Component({
        selector: 'app-portal-home',
        templateUrl: 'portal-home.component.html'
    })
    
    François Agneray's avatar
    François Agneray committed
    export class PortalHomeComponent implements OnInit {
    
        public favIcon: HTMLLinkElement = document.querySelector('#favicon');
    
        public body: HTMLBodyElement = document.querySelector('body');
    
    François Agneray's avatar
    WIP
    François Agneray committed
        public isAuthenticated: Observable<boolean>;
        public userProfile: Observable<UserProfile>;
        public userRoles: Observable<string[]>;
        public instanceList: Observable<Instance[]>;
    
        public instanceGroupList: Observable<InstanceGroup[]>;
    
        public userRolesSubscription: Subscription;
    
    
    François Agneray's avatar
    François Agneray committed
        constructor(private store: Store<{ }>, private config: AppConfigService, private style: StyleService) {
    
    François Agneray's avatar
    WIP
    François Agneray committed
            this.isAuthenticated = store.select(authSelector.selectIsAuthenticated);
            this.userProfile = store.select(authSelector.selectUserProfile);
            this.userRoles = store.select(authSelector.selectUserRoles);
            this.instanceList = store.select(instanceSelector.selectAllInstances);
    
            this.instanceGroupList = store.select(instanceGroupSelector.selectAllInstanceGroups);
    
    François Agneray's avatar
    WIP
    François Agneray committed
        }
    
        ngOnInit() {
    
    Tifenn Guillas's avatar
    Tifenn Guillas committed
            this.favIcon.href = 'favicon.ico';
    
            this.body.style.backgroundColor = 'white';
    
    François Agneray's avatar
    François Agneray committed
            this.style.setStyles('.footer', {
                'background-color': '#F8F9FA',
                'border-top': 'none',
                'color': 'black',
            });
    
    François Agneray's avatar
    WIP
    François Agneray committed
        }
    
    
        /**
         * Checks if authentication is enabled.
         *
         * @return boolean
         */
        getAuthenticationEnabled(): boolean {
    
            return this.config.authenticationEnabled;
        }
    
        /**
         * Returns admin roles list
         * 
         * @returns string[]
         */
    
    François Agneray's avatar
    François Agneray committed
        getAdminRoles(): string[] {
            return this.config.adminRoles;
        }
    
    
        /**
         * Returns ANIS Server API URL
         * 
         * @returns string
         */
    
    François Agneray's avatar
    François Agneray committed
        getApiUrl(): string {
            return this.config.apiUrl;
        }
    
    
        /**
         * Dispatches action to log in.
         */
    
    François Agneray's avatar
    WIP
    François Agneray committed
        login(): void {
    
            this.store.dispatch(authActions.login({ redirectUri: window.location.toString() }));
    
    François Agneray's avatar
    WIP
    François Agneray committed
        }
    
    
        /**
         * Dispatches action to log out.
         */
    
    François Agneray's avatar
    WIP
    François Agneray committed
        logout(): void {
            this.store.dispatch(authActions.logout());
        }
    
    
        /**
         * Dispatches action to open profile editor.
         */
    
    François Agneray's avatar
    WIP
    François Agneray committed
        openEditProfile(): void {
            this.store.dispatch(authActions.openEditProfile());
        }
    }