Skip to content
Snippets Groups Projects
main-header.component.ts 2.53 KiB
Newer Older
  • Learn to ignore specific revisions
  • Damien's avatar
    Damien committed
    import { Component, OnInit, NgZone } from '@angular/core';
    import { LANG }                 from '../translate.component';
    
    import { MatDialog, MatDialogRef } from '@angular/material/dialog';
    import { MatSidenav } from '@angular/material/sidenav';
    
    Damien's avatar
    Damien committed
    import { HttpClient }           from '@angular/common/http';
    import { Router }               from '@angular/router';
    
    import { IndexingGroupModalComponent }  from './menu-shortcut.component';
    
    Damien's avatar
    Damien committed
    import { HeaderService }        from '../../service/header.service';
    
    import { AppService } from '../../service/app.service';
    
    
    declare function $j(selector: any) : any;
    
    @Component({
        selector    : "main-header",
    
        templateUrl : "main-header.component.html",
        providers: [AppService],
    
    })
    export class MainHeaderComponent implements OnInit {
    
    
    Damien's avatar
    Damien committed
        lang            : any       = LANG;
        user            : any       = {firstname : "",lastname : ""};
    
        dialogRef   : MatDialogRef<any>;
        config      : any       = {};
    
    Damien's avatar
    Damien committed
        titleHeader     : string;
        router          : any;
    
        snav            : MatSidenav;
        snav2           : MatSidenav;
    
        constructor(
            public http: HttpClient, 
            private zone: NgZone, 
            private _router: Router, 
            public headerService: HeaderService, 
            public dialog: MatDialog,
            public appService: AppService
        ) {
    
    Alex ORLUC's avatar
    Alex ORLUC committed
            this.router = _router;
    
            window['MainHeaderComponent'] = {
                refreshTitle: (value: string) => this.setTitle(value),
                setSnav: (value: MatSidenav) => this.getSnav(value),
                setSnavRight: (value: MatSidenav) => this.getSnavRight(value),
            };
        }
    
    
        ngOnInit(): void { }
    
    
        setTitle(title: string) {
            this.zone.run(() => this.titleHeader = title);
        }
    
        getSnav(snav:MatSidenav) {
            this.zone.run(() => this.snav = snav);
        }
    
        getSnavRight(snav2:MatSidenav) {
    
            if (snav2 == null) {
                $j('#snav2Button').hide();
            }else {
                $j('#snav2Button').show();
                this.zone.run(() => this.snav2 = snav2);
            }
    
            if (shortcut.id == 'index_mlb' && this.headerService.user.indexingGroups.length > 1) {
    
                this.config = { data: { indexingGroups:this.headerService.user.indexingGroups, link:shortcut.servicepage } };
    
                this.dialogRef = this.dialog.open(IndexingGroupModalComponent, this.config);
            } else if (shortcut.angular == 'true') {
                this.router.navigate([shortcut.servicepage]);
            } else {
                location.href = shortcut.servicepage;
    
    Alex ORLUC's avatar
    Alex ORLUC committed
            }
        }