3b97be517e98eea93ff53b3ee2d6f6b0c6222c22
[portal/sdk.git] /
1 /*-
2  * ============LICENSE_START==========================================
3  * ONAP Portal SDK
4  * ===================================================================
5  * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6  * ===================================================================
7  *
8  * Unless otherwise specified, all software contained herein is licensed
9  * under the Apache License, Version 2.0 (the "License");
10  * you may not use this software except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *             http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  * Unless otherwise specified, all documentation contained herein is licensed
22  * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
23  * you may not use this documentation except in compliance with the License.
24  * You may obtain a copy of the License at
25  *
26  *             https://creativecommons.org/licenses/by/4.0/
27  *
28  * Unless required by applicable law or agreed to in writing, documentation
29  * distributed under the License is distributed on an "AS IS" BASIS,
30  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31  * See the License for the specific language governing permissions and
32  * limitations under the License.
33  *
34  * ============LICENSE_END============================================
35  *
36  * 
37  */
38
39 import { Component, OnInit, Directive, Input, Output, EventEmitter, ViewChildren, QueryList, PipeTransform, ViewChild } from '@angular/core';
40 import { AdminService } from '../admin.service';
41 import {UserService} from '../../shared/services/user/user.service'
42 import { User } from 'src/app/shared/services/user/user';
43 import { of, Observable } from 'rxjs';
44 import { RoleFunction } from './role-function';
45 import { MatTableDataSource } from '@angular/material/table';
46 import { MatPaginator } from '@angular/material/paginator';
47 import { MatSort } from '@angular/material/sort';
48 import { InformationModalComponent } from 'src/app/modals/information-modal/information-modal.component';
49 import { NgbModal, ModalDismissReasons } from '@ng-bootstrap/ng-bootstrap';
50 import { NewRoleFunctionComponent } from './new-role-function/new-role-function.component';
51 import { Column, DataTableSettings, ColumnTypes } from 'portalsdk-tag-lib';
52 import { RoleFunctionsService } from './role-functions.service';
53
54 @Component({
55   selector: 'app-role-functions',
56   templateUrl: './role-functions.component.html',
57   styleUrls: ['./role-functions.component.scss']
58 })
59 export class RoleFunctionsComponent implements OnInit {
60
61   tableData: Array<RoleFunction> = [];
62   response: any;
63   result: any;
64   function: RoleFunction;
65   isEditMode: boolean = false;
66   availableRoleFunctions: any;
67   showSpinner: boolean;
68
69   isAppCentralized: any;
70   user: User;
71   closeResult: string;
72
73   roleFunctionHeaders = ["name", "code", "type", "action", "edit", "delete"];
74   dataSource: MatTableDataSource<RoleFunction>;
75
76   constructor(public adminService: AdminService,
77     public userService: UserService,
78     private ngModal: NgbModal,
79     private roleFunctionService: RoleFunctionsService) { }
80
81   @ViewChild(MatPaginator, {}) paginator: MatPaginator;
82   @ViewChild(MatSort, {}) sort: MatSort;
83
84   public settings;
85   public columns: any = [];
86   typeOptions: string[] = ['menu', 'url', 'other'];
87
88   ngOnInit() {
89     this.showSpinner = false;
90     this.availableRoleFunctions = [];
91     this.getRoleFunctions();
92     let result = this.userService.getFunctionalMenuStaticDetailSession();
93     result.subscribe(user => {
94       this.user = user;
95       this.isAppCentralized = this.user.isAppCentralized;
96     });
97   }
98
99   getRoleFunctions() {
100     this.showSpinner = true;
101     let response;
102     this.response = this.adminService.getRoleFunctionList();
103     this.response.subscribe(data => {
104       response = data;
105       this.result = JSON.parse(response.data);
106       this.availableRoleFunctions = this.result.availableRoleFunctions;
107       this.tableData = JSON.parse(this.result.availableRoleFunctions);
108       //console.log("Table data : ", this.tableData);
109       this.columns.push(new Column("name", "Name", ColumnTypes.TEXT, true, null));
110       this.columns.push(new Column("code", "Code", ColumnTypes.TEXT, true, null));
111       this.columns.push(new Column("type", "Type", ColumnTypes.RADIO, true, this.typeOptions));
112       this.columns.push(new Column("action", "Action", ColumnTypes.TEXT, true, null));
113
114       this.settings = new DataTableSettings()
115       this.settings.columns = this.columns;
116       this.settings.isPaginationEnabled = true;
117       this.settings.paginationsSize = "5";
118       this.settings.isReadOnly = false;
119       this.settings.isTableSearchEnabled = true;
120       this.settings.applicationService = this.roleFunctionService;
121       this.showSpinner = false;
122
123     });
124
125   }
126 }