/
board.component.ts
126 lines (105 loc) · 3.7 KB
/
board.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
import { Component, OnInit } from '@angular/core';
import { MatDialog, MatDialogConfig } from '@angular/material/dialog';
import { MatSnackBar } from '@angular/material/snack-bar';
import { Title } from '@angular/platform-browser';
import { ActivatedRoute, Params } from '@angular/router';
import {
ApiResponseError,
ReadProject
} from '@dasch-swiss/dsp-js';
import { DialogComponent } from 'src/app/main/dialog/dialog.component';
import { ErrorHandlerService } from 'src/app/main/error/error-handler.service';
import { Session, SessionService } from 'src/app/main/services/session.service';
import { CacheService } from '../../main/cache/cache.service';
export interface DatasetRadioOption {
name: string;
id: number;
checked: boolean;
}
@Component({
selector: 'app-board',
templateUrl: './board.component.html',
styleUrls: ['./board.component.scss']
})
export class BoardComponent implements OnInit {
// loading for progress indicator
loading: boolean;
// permissions of logged-in user
session: Session;
sysAdmin = false;
projectAdmin = false;
// project shortcode; as identifier in project cache service
projectCode: string;
// project data
project: ReadProject;
color = 'primary';
constructor(
private _cache: CacheService,
private _errorHandler: ErrorHandlerService,
private _session: SessionService,
private _dialog: MatDialog,
private _route: ActivatedRoute,
private _titleService: Title,
private _snackBar: MatSnackBar
) {
// get the shortcode of the current project
this._route.parent.paramMap.subscribe((params: Params) => {
this.projectCode = params.get('shortcode');
});
// set the page title
this._titleService.setTitle('Project ' + this.projectCode);
}
ngOnInit() {
this.loading = true;
// get information about the logged-in user, if one is logged-in
if (this._session.getSession()) {
this.session = this._session.getSession();
// is the logged-in user system admin?
this.sysAdmin = this.session.user.sysAdmin;
}
// get project info from backend
this.getProject();
}
getProject() {
// get the project data from cache
this._cache.get(this.projectCode).subscribe(
(response: ReadProject) => {
this.project = response;
// is logged-in user projectAdmin?
if (this._session.getSession()) {
this.projectAdmin = this.sysAdmin ? this.sysAdmin : this.session.user.projectAdmin.some(e => e === this.project.id);
}
this.loading = false;
},
(error: ApiResponseError) => {
this._errorHandler.showMessage(error);
}
);
this.loading = false;
}
// copy link to clipboard
copyToClipboard(msg: string) {
const message = 'Copied to clipboard!';
const action = msg;
this._snackBar.open(message, action, {
duration: 3000,
horizontalPosition: 'center',
verticalPosition: 'top'
});
}
openDialog(mode: string, name: string, id?: string): void {
const dialogConfig: MatDialogConfig = {
width: '560px',
maxHeight: '80vh',
position: {
top: '112px'
},
data: { mode: mode, title: name, project: id }
};
const dialogRef = this._dialog.open(DialogComponent, dialogConfig);
dialogRef.afterClosed().subscribe(response => {
// update the view
this.getProject();
});
}
}