header-right.component.ts 3.07 KB
Newer Older
1
2
import { Component, OnInit, ViewChild } from '@angular/core';
import { HttpClient } from '@angular/common/http';
3
import { TranslateService } from '@ngx-translate/core';
4
import { HeaderService } from '@service/header.service';
5
6
import { MatDialog, MatDialogRef } from '@angular/material/dialog';
import { MatInput } from '@angular/material/input';
Alex ORLUC's avatar
Alex ORLUC committed
7
8
import { IndexingGroupModalComponent } from '../menu/menu-shortcut.component';
import { Router } from '@angular/router';
9
10
11
12
import { AppService } from '@service/app.service';
import { PrivilegeService } from '@service/privileges.service';
import { FunctionsService } from '@service/functions.service';
import { AuthService } from '@service/auth.service';
13
14
import { RegisteredMailImportComponent } from '@appRoot/registeredMail/import/registered-mail-import.component';

Alex ORLUC's avatar
Alex ORLUC committed
15

Alex ORLUC's avatar
Alex ORLUC committed
16
@Component({
17
    selector: 'app-header-right',
Alex ORLUC's avatar
Alex ORLUC committed
18
    styleUrls: ['header-right.component.scss'],
19
    templateUrl: 'header-right.component.html',
Alex ORLUC's avatar
Alex ORLUC committed
20
21
22
})
export class HeaderRightComponent implements OnInit {

23
24
    @ViewChild('searchInput', { static: false }) searchInput: MatInput;

25
26
    dialogRef: MatDialogRef<any>;
    config: any = {};
27
    menus: any = [];
28
    searchTarget: string = '';
Alex ORLUC's avatar
Alex ORLUC committed
29

30
    hideSearch: boolean = true;
31

32
    constructor(
33
        public translate: TranslateService,
34
        public http: HttpClient,
35
        public router: Router,
36
        public dialog: MatDialog,
37
        public authService: AuthService,
38
39
        public appService: AppService,
        public headerService: HeaderService,
40
        public functions: FunctionsService,
41
        public privilegeService: PrivilegeService) { }
Alex ORLUC's avatar
Alex ORLUC committed
42

43
44
45
    ngOnInit(): void {
        this.menus = this.privilegeService.getCurrentUserMenus();
    }
Alex ORLUC's avatar
Alex ORLUC committed
46

47
    gotToMenu(shortcut: any) {
48
        if (shortcut.id === 'indexing' && shortcut.groups.length > 1) {
49
            this.config = { panelClass: 'maarch-modal', data: { indexingGroups: shortcut.groups, link: shortcut.route } };
Alex ORLUC's avatar
Alex ORLUC committed
50
            this.dialogRef = this.dialog.open(IndexingGroupModalComponent, this.config);
51
        } else {
52
53
54
            const component = shortcut.route.split('__');

            if (component.length === 2) {
55
56
57
58
59
60
61
62
                if (component[0] === 'RegisteredMailImportComponent') {
                    this.dialog.open(RegisteredMailImportComponent, {
                        disableClose: true,
                        width: '99vw',
                        maxWidth: '99vw',
                        panelClass: 'maarch-full-height-modal'
                    });
                }
63
64
65
            } else {
                this.router.navigate([shortcut.route]);
            }
Alex ORLUC's avatar
Alex ORLUC committed
66
67
        }
    }
Alex ORLUC's avatar
Alex ORLUC committed
68
69
70
71

    showSearchInput() {
        this.hideSearch = !this.hideSearch;
        setTimeout(() => {
72
            this.searchInput.focus();
Alex ORLUC's avatar
Alex ORLUC committed
73
74
        }, 200);
    }
75
76
77
78
79

    hideSearchBar() {
        return this.router.url.split('?')[0] !== '/search';
    }

80
    showLogout() {
81
        return ['sso', 'azure_saml'].indexOf(this.authService.authMode) > -1 && this.functions.empty(this.authService.authUri) ? false : true;
82
83
    }

84
    goTo() {
85
        this.router.navigate(['/search'], { queryParams: { value: this.searchTarget } });
86
    }
Damien's avatar
Damien committed
87
}