rework admin table
[portal/ric-dashboard.git] / webapp-frontend / src / app / admin / user.component.ts
1 /*-
2  * ========================LICENSE_START=================================
3  * O-RAN-SC
4  * %%
5  * Copyright (C) 2019 AT&T Intellectual Property and Nokia
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 { DashboardUser } from './../interfaces/dashboard.types';
26 import { ConfirmDialogService } from './../services/ui/confirm-dialog.service';
27 import { NotificationService } from './../services/ui/notification.service';
28 import { UserDataSource } from './user.datasource';
29 import { AddDashboardUserDialogComponent } from './add-dashboard-user-dialog/add-dashboard-user-dialog.component';
30 import { EditDashboardUserDialogComponent } from './edit-dashboard-user-dialog/edit-dashboard-user-dialog.component';
31
32 @Component({
33   selector: 'app-user',
34   templateUrl: './user.component.html',
35   styleUrls: ['./user.component.css']
36 })
37
38 export class UserComponent implements OnInit {
39
40   displayedColumns: string[] = ['id', 'firstName', 'lastName', 'status','action'];
41   dataSource: UserDataSource;
42   @ViewChild(MatSort) sort: MatSort;
43
44   constructor(
45     private dashboardSvc: DashboardService,
46     private confirmDialogService: ConfirmDialogService,
47     private errorService: ErrorDialogService,
48     private notification: NotificationService,
49     public dialog: MatDialog) { }
50
51   ngOnInit() {
52     this.dataSource = new UserDataSource(this.dashboardSvc, this.sort);
53     this.dataSource.loadTable();
54   }
55
56   editUser(user: DashboardUser) {
57     const dialogRef = this.dialog.open(EditDashboardUserDialogComponent, {
58       width: '450px',
59       data: user
60     });
61     dialogRef.afterClosed().subscribe(result => {
62       this.dataSource.loadTable();
63     });
64   }
65     
66
67   deleteUser() {
68     const aboutError = 'Not implemented yet';
69     this.errorService.displayError(aboutError);
70   }
71
72   addUser() {
73     const dialogRef = this.dialog.open(AddDashboardUserDialogComponent, {
74       width: '450px'
75     });
76     dialogRef.afterClosed().subscribe(result => {
77       this.dataSource.loadTable();
78     });
79   }
80 }
81