-
Notifications
You must be signed in to change notification settings - Fork 6
/
header.component.ts
104 lines (88 loc) · 3.27 KB
/
header.component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import { Component, Inject, OnDestroy, OnInit } from '@angular/core';
import { MatDialog, MatDialogConfig } from '@angular/material/dialog';
import { MatIconRegistry } from '@angular/material/icon';
import { DomSanitizer } from '@angular/platform-browser';
import { Router } from '@angular/router';
import { AppConfigService, RouteConstants, DspConfig } from '@dasch-swiss/vre/shared/app-config';
import { NotificationService } from '@dasch-swiss/vre/shared/app-notification';
import { DialogComponent } from '@dsp-app/src/app/main/dialog/dialog.component';
import {
ComponentCommunicationEventService,
Events,
} from '@dsp-app/src/app/main/services/component-communication-event.service';
import { SearchParams } from '@dsp-app/src/app/workspace/results/list-view/list-view.component';
import { Subscription } from 'rxjs';
@Component({
selector: 'app-header',
templateUrl: './header.component.html',
styleUrls: ['./header.component.scss'],
})
export class HeaderComponent implements OnInit, OnDestroy {
session = false;
show = false;
searchParams: SearchParams;
helpLink = RouteConstants.help;
dsp: DspConfig;
componentCommsSubscription: Subscription;
homeLink = RouteConstants.home;
constructor(
private _appConfigService: AppConfigService,
private _componentCommsService: ComponentCommunicationEventService,
private _dialog: MatDialog,
private _domSanitizer: DomSanitizer,
private _matIconRegistry: MatIconRegistry,
private _notification: NotificationService,
private _router: Router
) {
// create own logo icon to use them in mat-icons
this._matIconRegistry.addSvgIcon(
'dasch_mosaic_icon_color',
this._domSanitizer.bypassSecurityTrustResourceUrl('/assets/images/dasch-mosaic-icon-color.svg')
);
this.dsp = this._appConfigService.dspConfig;
}
ngOnInit() {
this.componentCommsSubscription = this._componentCommsService.on(Events.loginSuccess, () => {
this._notification.openSnackBar('Login successful');
});
}
ngOnDestroy() {
// unsubscribe from the ValueOperationEventService when component is destroyed
if (this.componentCommsSubscription !== undefined) {
this.componentCommsSubscription.unsubscribe();
}
}
/**
* show or hide search bar in phone version
*/
showSearchBar() {
this.show = !this.show;
}
doSearch(search: SearchParams) {
// reset search params
this.searchParams = undefined;
// we can do the routing here or send the search param
// to (resource) list view directly
this.searchParams = search;
if (this.searchParams.mode && this.searchParams.query) {
let doSearchRoute = `/${RouteConstants.search}/${this.searchParams.mode}/${encodeURIComponent(
this.searchParams.query
)}`;
if (this.searchParams.filter && this.searchParams.filter.limitToProject) {
doSearchRoute += `/${encodeURIComponent(this.searchParams.filter.limitToProject)}`;
}
this._router.navigate([doSearchRoute]);
}
}
openDialog(mode: string, name?: string, iri?: string): void {
const dialogConfig: MatDialogConfig = {
width: '840px',
maxHeight: '80vh',
position: {
top: '112px',
},
data: { mode, title: name, id: iri },
};
this._dialog.open(DialogComponent, dialogConfig);
}
}