header-right.component.ts 1.98 KB
Newer Older
Alex ORLUC's avatar
Alex ORLUC committed
1
import { Component, OnInit, ViewChild }    from '@angular/core';
Alex ORLUC's avatar
Alex ORLUC committed
2
3
4
import { HttpClient }           from '@angular/common/http';
import { LANG }                 from '../translate.component';
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';
Alex ORLUC's avatar
Alex ORLUC committed
11

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

    lang        : any       = LANG;

    dialogRef   : MatDialogRef<any>;
    config      : any       = {};
23
    menus: any = [];
Alex ORLUC's avatar
Alex ORLUC committed
24

25
26
    hideSearch : boolean = true;

27
    @ViewChild('searchInput', { static: true }) searchInput: MatInput;
Alex ORLUC's avatar
Alex ORLUC committed
28

29
30
31
32
    constructor(
        public http: HttpClient, 
        private router: Router,
        public dialog: MatDialog,
33
34
35
        public appService: AppService,
        public headerService: HeaderService,
        private privilegeService: PrivilegeService) {}
Alex ORLUC's avatar
Alex ORLUC committed
36

37
38
39
    ngOnInit(): void {
        this.menus = this.privilegeService.getCurrentUserMenus();
    }
Alex ORLUC's avatar
Alex ORLUC committed
40
41

    gotToMenu(shortcut:any) {
Damien's avatar
Damien committed
42
        if (shortcut.id == 'indexing' && shortcut.groups.length > 1) {
Alex ORLUC's avatar
Alex ORLUC committed
43
            this.config = { data: { indexingGroups: shortcut.groups, link:shortcut.route } };
Alex ORLUC's avatar
Alex ORLUC committed
44
            this.dialogRef = this.dialog.open(IndexingGroupModalComponent, this.config);
Alex ORLUC's avatar
Alex ORLUC committed
45
46
        } else if (shortcut.angular === true) {
            this.router.navigate([shortcut.route]);
Alex ORLUC's avatar
Alex ORLUC committed
47
        } else {
Alex ORLUC's avatar
Alex ORLUC committed
48
            location.href = shortcut.route;
Alex ORLUC's avatar
Alex ORLUC committed
49
50
        }
    }
Alex ORLUC's avatar
Alex ORLUC committed
51
52
53
54
55
56
57

    showSearchInput() {
        this.hideSearch = !this.hideSearch;
        setTimeout(() => {
            this.searchInput.focus(); 
        }, 200);
    }
Alex ORLUC's avatar
Alex ORLUC committed
58
}