header-right.component.ts 2.91 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
import { AppService } from '../../service/app.service';
10
import { PrivilegeService } from '../../service/privileges.service';
11
import { FunctionsService } from '../../service/functions.service';
12
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
17
18
@Component({
    selector: 'header-right',
    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
    dialogRef: MatDialogRef<any>;
    config: any = {};
25
    menus: any = [];
26
    searchTarget: string = '';
Alex ORLUC's avatar
Alex ORLUC committed
27

28
    hideSearch: boolean = true;
29

30
    @ViewChild('searchInput', { static: false }) searchInput: MatInput;
Alex ORLUC's avatar
Alex ORLUC committed
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);
Alex ORLUC's avatar
Alex ORLUC committed
51
        } else if (shortcut.angular === true) {
52
53
54
55
56
57
58
59
60
61
62
63
            const component = shortcut.route.split('__');

            if (component.length === 2) {
                this.dialog.open(RegisteredMailImportComponent, {
                    disableClose: true,
                    width: '99vw',
                    maxWidth: '99vw',
                    panelClass: 'maarch-full-height-modal'
                });
            } else {
                this.router.navigate([shortcut.route]);
            }
Alex ORLUC's avatar
Alex ORLUC committed
64
        } else {
Alex ORLUC's avatar
Alex ORLUC committed
65
            location.href = 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
80
81
82

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

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