Skip to content
Snippets Groups Projects
app.component.ts 1.79 KiB
Newer Older
  • Learn to ignore specific revisions
  • /**
     * 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 } from '@angular/core';
    
    import { Store } from '@ngrx/store';
    
    François Agneray's avatar
    François Agneray committed
    import { Observable } from 'rxjs';
    import { map } from 'rxjs/operators';
    
    import * as fromAuth from '../../auth/auth.reducer';
    
    François Agneray's avatar
    François Agneray committed
    import * as authActions from '../../auth/auth.actions';
    
    François Agneray's avatar
    François Agneray committed
    import * as authSelector from '../../auth/auth.selector';
    import { UserProfile } from '../../auth/user-profile.model';
    
    import { AppConfigService } from '../../app-config.service';
    
    
    @Component({
      selector: 'app-root',
    
      templateUrl: './app.component.html'
    
    })
    export class AppComponent {
    
    François Agneray's avatar
    François Agneray committed
        public anisClientVersion: string = '3.6.0';
        public year = (new Date()).getFullYear();
        public isAuthenticated: Observable<boolean>;
        public userProfile: Observable<UserProfile>;
        public userRoles: Observable<string[]>;
    
    
        constructor(private store: Store<{ auth: fromAuth.State }>, private config: AppConfigService) {
    
    François Agneray's avatar
    François Agneray committed
            this.isAuthenticated = store.select(authSelector.selectIsAuthenticated);
            this.userProfile = store.select(authSelector.selectUserProfile);
            this.userRoles = store.select(authSelector.selectUserRoles);
        }
    
        authenticationEnabled(): boolean {
    
            return this.config.authenticationEnabled;
    
    François Agneray's avatar
    François Agneray committed
        }
    
        login(): void {
            this.store.dispatch(authActions.login());
        }
    
        logout(): void {
            this.store.dispatch(authActions.logout());
        }
    
        openEditProfile(): void {
            this.store.dispatch(authActions.openEditProfile());
        }
    
        isAnisAdmin() {
            return this.userRoles.pipe(
                map(roles => roles.includes('anis_admin'))
            );
        }