/
header.component.ts
149 lines (116 loc) · 4.51 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import { Component, 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 { NavigationStart, Router } from '@angular/router';
import { Subscription } from 'rxjs';
import { AppInitService } from 'src/app/app-init.service';
import { DialogComponent } from 'src/app/main/dialog/dialog.component';
import { ComponentCommunicationEventService, Events } from 'src/app/main/services/component-communication-event.service';
import { SearchParams } from 'src/app/workspace/results/list-view/list-view.component';
import { DspConfig } from '../declarations/dsp-config';
import { NotificationService } from '../services/notification.service';
import { SessionService } from '../services/session.service';
@Component({
selector: 'app-header',
templateUrl: './header.component.html',
styleUrls: ['./header.component.scss']
})
export class HeaderComponent implements OnInit, OnDestroy {
session = false;
show = false;
searchParams: SearchParams;
dsp: DspConfig;
componentCommsSubscription: Subscription;
constructor(
private _appInitService: AppInitService,
private _componentCommsService: ComponentCommunicationEventService,
private _dialog: MatDialog,
private _domSanitizer: DomSanitizer,
private _matIconRegistry: MatIconRegistry,
private _notification: NotificationService,
private _router: Router,
private _session: SessionService
) {
// create tool icons to use them in mat-icons
this._matIconRegistry.addSvgIcon(
'dasch_icon_black',
this._domSanitizer.bypassSecurityTrustResourceUrl('/assets/images/dasch-icon-black.svg')
);
// logged-in user? show user menu or login button
this._router.events.forEach((event) => {
if (event instanceof NavigationStart) {
this._session.isSessionValid().subscribe((response) => {
this.session = response;
});
}
});
this.dsp = this._appInitService.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 = '/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: mode, title: name, id: iri }
};
const dialogRef = this._dialog.open(
DialogComponent,
dialogConfig
);
dialogRef.afterClosed().subscribe(() => {
// do something
});
}
openNewResourceForm(mode: string, name?: string): void {
const dialogConfig: MatDialogConfig = {
width: '840px',
maxHeight: '80vh',
position: {
top: '112px'
},
data: { mode: mode, title: 'New resource', subtitle: 'Create new resource' },
disableClose: true
};
const dialogRef = this._dialog.open(
DialogComponent,
dialogConfig
);
dialogRef.afterClosed().subscribe(() => {
});
}
}