summaryrefslogtreecommitdiffstats
path: root/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/admin/roles/new-role/new-role.component.ts
diff options
context:
space:
mode:
Diffstat (limited to 'ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/admin/roles/new-role/new-role.component.ts')
-rw-r--r--ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/admin/roles/new-role/new-role.component.ts250
1 files changed, 250 insertions, 0 deletions
diff --git a/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/admin/roles/new-role/new-role.component.ts b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/admin/roles/new-role/new-role.component.ts
new file mode 100644
index 00000000..6b1470fa
--- /dev/null
+++ b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/admin/roles/new-role/new-role.component.ts
@@ -0,0 +1,250 @@
+/*-
+ * ============LICENSE_START==========================================
+ * ONAP Portal SDK
+ * ===================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * ===================================================================
+ *
+ * Unless otherwise specified, all software contained herein is licensed
+ * under the Apache License, Version 2.0 (the "License");
+ * you may not use this software except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Unless otherwise specified, all documentation contained herein is licensed
+ * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+ * you may not use this documentation except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://creativecommons.org/licenses/by/4.0/
+ *
+ * Unless required by applicable law or agreed to in writing, documentation
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============LICENSE_END============================================
+ *
+ *
+ */
+
+import { Component, OnInit, Input, Output, EventEmitter, ViewChild } from '@angular/core';
+import { NgbActiveModal, NgbModal } from '@ng-bootstrap/ng-bootstrap';
+import { AdminService } from '../../admin.service';
+import { UserService } from 'src/app/shared/services/user/user.service';
+import { MatSort } from '@angular/material/sort';
+import { MatPaginator } from '@angular/material/paginator';
+import { MatTableDataSource } from '@angular/material';
+import { InformationModalComponent } from 'src/app/modals/information-modal/information-modal.component';
+import { ConfirmationModalComponent } from 'src/app/modals/confirmation-modal/confirmation-modal.component';
+
+
+@Component({
+ selector: 'app-new-role',
+ templateUrl: './new-role.component.html',
+ styleUrls: ['./new-role.component.scss']
+})
+export class NewRoleComponent implements OnInit {
+
+ showSpinner: boolean;
+ result: any;
+ @Input() role: any;
+ @Input() isEditMode: boolean;
+ @Input() availableRoles : any;
+ @Input() ociavailableRoleFunctions: any;
+ roleFunctionTableHeaders: Array<string> = [];
+ roleFunctions: Array<Object> = [];
+ roleFunctionsLenght: any;
+ finalSelectedRoleFunctions: any;
+ availableRoleFunctions: any;
+ @Output() passEntry: EventEmitter<any> = new EventEmitter();
+ @ViewChild(MatPaginator, {}) paginator: MatPaginator;
+ @ViewChild(MatSort, {}) sort: MatSort;
+ roleFunctionDataSource = new MatTableDataSource(this.roleFunctions);
+
+ constructor(public adminService:AdminService, public userService: UserService, public activeModal: NgbActiveModal, public ngbModal: NgbModal) { }
+
+ ngOnInit() {
+ this.roleFunctionTableHeaders = ["roleFunctionName","active"];
+ this.finalSelectedRoleFunctions = [];
+ this.availableRoleFunctions = [];
+ if(this.isEditMode && this.ociavailableRoleFunctions && this.ociavailableRoleFunctions.length > 0){
+ this.availableRoleFunctions = this.setSelectedRoleFucntions(this.ociavailableRoleFunctions);
+ this.populateTableData(this.availableRoleFunctions)
+ }
+ }
+
+ setSelectedRoleFucntions(ociavailableRoleFunctions: any) {
+ for (var i = 0; i < this.ociavailableRoleFunctions.length; i++) {
+ var availableRoleFunction = this.ociavailableRoleFunctions[i];
+ availableRoleFunction['selected'] = false;
+ for (var j = 0; j < this.role.roleFunctions.length; j++) {
+ if (availableRoleFunction.code === this.role.roleFunctions[j].code
+ && availableRoleFunction.type === this.role.roleFunctions[j].type
+ && availableRoleFunction.action === this.role.roleFunctions[j].action) {
+ availableRoleFunction.selected = true;
+ }
+ }
+ this.availableRoleFunctions.push(availableRoleFunction);
+ }
+ return this.availableRoleFunctions;
+ }
+
+
+ toggleRoleFunction(_element) {
+ if (this.ociavailableRoleFunctions) {
+ for (var i = 0; i < this.ociavailableRoleFunctions.length; i++) {
+ var availableRoleFunction = this.ociavailableRoleFunctions[i];
+ if (availableRoleFunction.selected && !this.finalSelectedRoleFunctions.includes(availableRoleFunction)) {
+ this.finalSelectedRoleFunctions.push(availableRoleFunction);
+ }
+ }
+ }
+ if (!_element.selected) {
+ for (var i = 0; i < this.finalSelectedRoleFunctions.length; i++) {
+ var availableRoleFunction = this.finalSelectedRoleFunctions[i];
+ if (availableRoleFunction.code == _element.code
+ && availableRoleFunction.type == _element.type
+ && availableRoleFunction.action == _element.action) {
+ this.finalSelectedRoleFunctions.splice(i, 1);
+ }
+ }
+ }
+ }
+
+ delRoleFunctionConfirmPopUp(roleFunction: any, roleId: any){
+ const modalRef = this.ngbModal.open(InformationModalComponent);
+ modalRef.componentInstance.title = "Confirmation";
+ modalRef.componentInstance.message = 'You are about to delete this Role Function : ' + roleFunction.name+ '. Click OK to continue.';
+ modalRef.result.then((result) => {
+ if (result === 'Ok') {
+ let temproleFunctions = this.role.roleFunctions;
+ let index = 0;
+ for(let i=0; i<temproleFunctions.length; i++){
+ if(temproleFunctions[i].code == roleFunction.code){
+ break;
+ }
+ index = index + 1;
+ };
+ temproleFunctions.splice(index,1);
+ this.populateTableData(temproleFunctions);
+ this.adminService.removeRoleFunction(roleFunction , roleId)
+ .subscribe(_data => {
+ this.result = _data
+ this.passEntry.emit(this.result);
+ }, error =>{
+ this.openConfirmationModal('Error', error.message);
+ });
+ }
+ }, (resut) => {
+ this.openConfirmationModal('Error', resut);
+ return;
+ })
+ }
+
+ populateTableData(roleFunctionsList: any){
+ this.roleFunctionDataSource = new MatTableDataSource(roleFunctionsList);
+ this.roleFunctionDataSource.sort = this.sort;
+ this.roleFunctionDataSource.paginator = this.paginator;
+ }
+
+ //Add Or Update Account.
+ saveChanges(){
+ if(this.isEditMode){
+ if (this.role.priority && this.role.priority != '' && isNaN(parseInt(this.role.priority))) {
+ let errorMsg = 'Priority must be an integer.';
+ this.openConfirmationModal('Error', errorMsg);
+ }
+ //update the role object
+ this.showSpinner = true
+ this.role.roleFunctions = this.finalSelectedRoleFunctions;
+ let postData={
+ role: this.role,
+ childRoles: this.role.childRoles,
+ roleFunctions : this.role.roleFunctions
+ };
+ this.adminService.saveRole(postData, this.role.id)
+ .subscribe(_data => {
+ this.showSpinner = false;
+ this.result = _data
+ this.passEntry.emit(this.result);
+ this.ngbModal.dismissAll();
+ }, error =>{
+ this.openConfirmationModal('Error', error.message);
+ });
+ }else{
+ //create new Role Object
+ if (this.role.priority && this.role.priority != '' && isNaN(parseInt(this.role.priority))) {
+ let errorMsg = 'Priority must be an integer.';
+ this.openConfirmationModal('Error', errorMsg);
+ }
+ let newRoleObj = {
+ 'id':null,
+ 'created':null,
+ 'modified':null,
+ 'createdId':null,
+ 'modifiedId':null,
+ 'rowNum':null,
+ 'auditUserId':null,
+ 'auditTrail':null,
+ 'name':this.role.name,
+ 'active':true,
+ 'priority':this.role.priority,
+ 'roleFunctions':null,
+ 'childRoles':null,
+ 'toggleActiveAltText':"Click to Activate Role ",
+ 'toggleActiveImage':" / static fusion images inactive.png ",
+ 'editUrl':" role.htm ? role_id = null",
+ };
+ if(this.isRoleAlreadyExist(this.role.name)){
+ //msg Role already exit
+ let errorMsg = "Role Name " + this.role.name +" is already present."
+ this.openConfirmationModal('Error', errorMsg);
+ }else{
+ this.showSpinner = true
+ newRoleObj.childRoles = [];
+ newRoleObj.roleFunctions = [];
+ let postData={
+ role: newRoleObj,
+ childRoles: newRoleObj.childRoles,
+ roleFunctions : newRoleObj.roleFunctions
+ };
+ this.adminService.saveRole(postData, newRoleObj.id)
+ .subscribe(_data => {
+ this.showSpinner = false;
+ this.result = _data
+ this.passEntry.emit(this.result);
+ this.ngbModal.dismissAll();
+ }, error =>{
+ this.openConfirmationModal('Error', error.message);
+ });
+ }
+ }
+ }
+
+ isRoleAlreadyExist(currentRoleName: any){
+ let roles = this.availableRoles;
+ if(roles && roles.length > 0){
+ for(let i=0; i<roles.length; i++){
+ if(roles[i].name === currentRoleName){
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ openConfirmationModal(_title: string, _message: string) {
+ const modalInfoRef = this.ngbModal.open(ConfirmationModalComponent);
+ modalInfoRef.componentInstance.title = _title;
+ modalInfoRef.componentInstance.message = _message;
+ }
+}