/
permission.component.ts
117 lines (90 loc) · 3.26 KB
/
permission.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
import { Component, Inject, OnInit, ViewChild } from '@angular/core';
import { Title } from '@angular/platform-browser';
import { ActivatedRoute, Params } from '@angular/router';
import {
ApiResponseData,
ApiResponseError,
KnoraApiConnection,
ProjectResponse,
ReadGroup,
ReadProject
} from '@dasch-swiss/dsp-js';
import { DspApiConnectionToken, Session, SessionService } from '@dasch-swiss/dsp-ui';
import { CacheService } from 'src/app/main/cache/cache.service';
import { ErrorHandlerService } from 'src/app/main/error/error-handler.service';
import { AddGroupComponent } from './add-group/add-group.component';
@Component({
selector: 'app-permission',
templateUrl: './permission.component.html',
styleUrls: ['./permission.component.scss']
})
export class PermissionComponent implements OnInit {
@ViewChild('addGroupComponent') addGroup: AddGroupComponent;
// loading for progess 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;
// project members
projectGroups: ReadGroup[] = [];
constructor(
@Inject(DspApiConnectionToken) private _dspApiConnection: KnoraApiConnection,
private _cache: CacheService,
private _errorHandler: ErrorHandlerService,
private _route: ActivatedRoute,
private _session: SessionService,
private _titleService: Title) {
// 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 + ' | Permission Groups');
}
ngOnInit() {
// get information about the logged-in user
this.session = this._session.getSession();
// is the logged-in user system admin?
this.sysAdmin = this.session.user.sysAdmin;
// is the logged-in user system admin?
this.sysAdmin = this.session.user.sysAdmin;
// get the project data from cache
this._cache.get(this.projectcode).subscribe(
(response: ReadProject) => {
this.project = response;
// is logged-in user projectAdmin?
this.projectAdmin = this.sysAdmin ? this.sysAdmin : this.session.user.projectAdmin.some(e => e === this.project.id);
this.initList();
this.loading = false;
},
(error: ApiResponseError) => {
this._errorHandler.showMessage(error);
this.loading = false;
}
);
}
/**
* build the list of members
*/
initList(): void {
}
/**
* refresh list of members after adding a new user to the team
*/
refresh(): void {
// referesh the component
this.loading = true;
// update the cache
this._cache.del('members_of_' + this.projectcode);
this.initList();
// refresh child component: add user
if (this.addGroup) {
this.addGroup.buildForm();
}
}
}