Add multi-layer RIC instance selector
[portal/ric-dashboard.git] / dashboard / webapp-frontend / src / app / user / user.component.ts
1 /*-
2  * ========================LICENSE_START=================================
3  * O-RAN-SC
4  * %%
5  * Copyright (C) 2019 AT&T Intellectual Property
6  * %%
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ========================LICENSE_END===================================
19  */
20 import { Component, OnInit, ViewChild } from '@angular/core';
21 import { MatDialog } from '@angular/material/dialog';
22 import { MatSort } from '@angular/material/sort';
23 import { DashboardService } from '../services/dashboard/dashboard.service';
24 import { ErrorDialogService } from '../services/ui/error-dialog.service';
25 import { EcompUser } from './../interfaces/dashboard.types';
26 import { NotificationService } from './../services/ui/notification.service';
27 import { UserDataSource } from './user.datasource';
28 import { AddDashboardUserDialogComponent } from './add-dashboard-user-dialog/add-dashboard-user-dialog.component';
29 import { EditDashboardUserDialogComponent } from './edit-dashboard-user-dialog/edit-dashboard-user-dialog.component';
30 import { UiService } from '../services/ui/ui.service';
31
32 @Component({
33   selector: 'rd-user',
34   templateUrl: './user.component.html',
35   styleUrls: ['./user.component.scss']
36 })
37
38 export class UserComponent implements OnInit {
39
40   darkMode: boolean;
41   panelClass: string;
42   displayedColumns: string[] = ['loginId', 'firstName', 'lastName', 'active', 'action'];
43   dataSource: UserDataSource;
44   @ViewChild(MatSort, {static: true}) sort: MatSort;
45
46   constructor(
47     private dashboardSvc: DashboardService,
48     private errorService: ErrorDialogService,
49     private notificationService: NotificationService,
50     public dialog: MatDialog,
51     public ui: UiService) { }
52
53   ngOnInit() {
54     this.dataSource = new UserDataSource(this.dashboardSvc, this.sort, this.notificationService);
55     this.dataSource.loadTable();
56     this.ui.darkModeState.subscribe((isDark) => {
57       this.darkMode = isDark;
58     });
59   }
60
61   editUser(user: EcompUser) {
62     if (this.darkMode) {
63       this.panelClass = 'dark-theme';
64     } else {
65       this.panelClass = '';
66     }
67     const dialogRef = this.dialog.open(EditDashboardUserDialogComponent, {
68       panelClass: this.panelClass,
69       width: '450px',
70       data: user
71     });
72     dialogRef.afterClosed().subscribe(result => {
73       this.dataSource.loadTable();
74     });
75   }
76
77   deleteUser() {
78     const aboutError = 'Not implemented (yet).';
79     this.errorService.displayError(aboutError);
80   }
81
82   addUser() {
83     if (this.darkMode) {
84       this.panelClass = 'dark-theme';
85     } else {
86       this.panelClass = '';
87     }
88     const dialogRef = this.dialog.open(AddDashboardUserDialogComponent, {
89       panelClass: this.panelClass,
90       width: '450px'
91     });
92     dialogRef.afterClosed().subscribe(result => {
93       this.dataSource.loadTable();
94     });
95   }
96 }
97