diff options
Diffstat (limited to 'portal-FE-common/src/app/pages/role/add-role')
4 files changed, 392 insertions, 0 deletions
diff --git a/portal-FE-common/src/app/pages/role/add-role/add-role.component.html b/portal-FE-common/src/app/pages/role/add-role/add-role.component.html new file mode 100644 index 00000000..e3393a81 --- /dev/null +++ b/portal-FE-common/src/app/pages/role/add-role/add-role.component.html @@ -0,0 +1,95 @@ +<!-- + ============LICENSE_START========================================== + ONAP Portal + =================================================================== + 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============================================ + + + --> + + <div class="container"> + <div class="modal-header"> + <h4 class="modal-title">{{title}}</h4> + <button type="button" class="close" aria-label="Close" (click)="activeModal.dismiss('Cross')"> + <span aria-hidden="true">×</span> + </button> + </div> + <div class="modal-body"> + <span class="onap-spinner" *ngIf="showSpinner"></span> + <div class="input-group"> + <div class="input-group-prepend"> + <span class="input-group-text">Name</span> + </div> + <input type="text" aria-label="name" maxlength="300" [(ngModel)]="role.name" placeholder="Enter name..." + [value]="role.name" class="form-control"> + </div> + + <div class="input-group"> + <div class="input-group-prepend"> + <span class="input-group-text">Priority</span> + </div> + <input type="text" aria-label="priority" maxlength="300" [(ngModel)]="role.priority" [value]="role.priority" + placeholder="Enter priority..." class="form-control"> + </div> + <br> + <div *ngIf="showGlobalRole" class="form-check" style="text-align:right;"> + <mat-checkbox class="example-margin" [(ngModel)]="isGlobalRoleChecked.isChecked"> Global Role </mat-checkbox> + </div> + <div class="role-function-list" *ngIf="dialogState === 2"> + <table mat-table [dataSource]="roleFunctionsDataSource"> + <!-- Active Column --> + <ng-container matColumnDef="active"> + <th id="col3" mat-header-cell *matHeaderCellDef> </th> + <td id="rowheader_t1_{{i}}-userId" mat-cell *matCellDef="let element; let i=index;"> + <mat-slide-toggle [(ngModel)]="element.selected" (change)="toggleRoleFunction(element)"></mat-slide-toggle> + </td> + </ng-container> + + <!-- Function Name Column --> + <ng-container matColumnDef="name"> + <th id="col2" mat-header-cell *matHeaderCellDef > Function Name </th> + <td id="rowheader_t1_{{i}}-lastName" mat-cell *matCellDef="let element; let i=index;"> + {{element.name}} + </td> + </ng-container> + + <tr mat-header-row *matHeaderRowDef="displayedColumns; sticky: true"></tr> + <tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr> + </table> + </div> + </div> + <div class="modal-footer"> + <button type="submit" class="btn btn-primary" [disabled]="!role.name || showSpinner" + (click)="saveRole()">Save</button> + <button type="button" class="btn btn-primary" (click)="activeModal.close('Close')">Cancel</button> + </div> +</div>
\ No newline at end of file diff --git a/portal-FE-common/src/app/pages/role/add-role/add-role.component.scss b/portal-FE-common/src/app/pages/role/add-role/add-role.component.scss new file mode 100644 index 00000000..54f59fcd --- /dev/null +++ b/portal-FE-common/src/app/pages/role/add-role/add-role.component.scss @@ -0,0 +1,45 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal + * =================================================================== + * 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============================================ + * + * + */ +.onap-spinner { + z-index: 9999; +} + +.role-function-list{ + overflow-y: auto; + height: 500px; +}
\ No newline at end of file diff --git a/portal-FE-common/src/app/pages/role/add-role/add-role.component.spec.ts b/portal-FE-common/src/app/pages/role/add-role/add-role.component.spec.ts new file mode 100644 index 00000000..1104010d --- /dev/null +++ b/portal-FE-common/src/app/pages/role/add-role/add-role.component.spec.ts @@ -0,0 +1,62 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal + * =================================================================== + * 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 { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { AddRoleComponent } from './add-role.component'; + +describe('AddRoleComponent', () => { + let component: AddRoleComponent; + let fixture: ComponentFixture<AddRoleComponent>; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ AddRoleComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(AddRoleComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/portal-FE-common/src/app/pages/role/add-role/add-role.component.ts b/portal-FE-common/src/app/pages/role/add-role/add-role.component.ts new file mode 100644 index 00000000..5c0a376e --- /dev/null +++ b/portal-FE-common/src/app/pages/role/add-role/add-role.component.ts @@ -0,0 +1,190 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal + * =================================================================== + * 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 } from '@angular/core'; +import { NgbActiveModal, NgbModal } from '@ng-bootstrap/ng-bootstrap'; +import { RoleService } from 'src/app/shared/services'; +import { environment } from 'src/environments/environment'; +import { HttpClient, HttpErrorResponse } from '@angular/common/http'; +import { ConfirmationModalComponent } from 'src/app/modals/confirmation-modal/confirmation-modal.component'; +import { Role } from 'src/app/shared/model'; +import { MatTableDataSource } from '@angular/material'; +import { InformationModalComponent } from 'src/app/modals/information-modal/information-modal.component'; + +@Component({ + selector: 'app-add-role', + templateUrl: './add-role.component.html', + styleUrls: ['./add-role.component.scss'] +}) +export class AddRoleComponent implements OnInit { + + @Input() title: string; + @Input() appId: string; + @Input() dialogState: number; + @Input() availableRole: any; + @Input() appRoleFunctions: any; + @Output() passBackAddRolePopup: EventEmitter<any> = new EventEmitter(); + availableRoleFunctions: any; + isGlobalRoleChecked = { + isChecked: false + } + role: Role; + roleFunctions: any; + showGlobalRole: boolean; + api = environment.api; + showSpinner: boolean; + displayedColumns: string[] = ['active', 'name']; + roleFunctionsDataSource = new MatTableDataSource(this.roleFunctions); + finalSelectedRoleFunctions: any; + constructor(public activeModal: NgbActiveModal, public ngbModal: NgbModal, private roleService: RoleService, public http: HttpClient) { } + + ngOnInit() { + this.role = new Role; + this.finalSelectedRoleFunctions = []; + if (this.appId == '1') + this.showGlobalRole = true; + if (this.dialogState === 2) { + this.isGlobalRoleChecked.isChecked = (this.availableRole.name.includes('global_')) ? true : false; + this.availableRoleFunctions = []; + this.role = this.availableRole; + this.roleFunctionsDataSource = new MatTableDataSource(this.setSelectedRoleFucntions()); + } + } + + setSelectedRoleFucntions() { + for (var i = 0; i < this.appRoleFunctions.length; i++) { + var availableRoleFunction = this.appRoleFunctions[i]; + availableRoleFunction['selected'] = false; + for (var j = 0; j < this.availableRole.roleFunctions.length; j++) { + if (availableRoleFunction.code === this.availableRole.roleFunctions[j].code + && availableRoleFunction.type === this.availableRole.roleFunctions[j].type + && availableRoleFunction.action === this.availableRole.roleFunctions[j].action) { + availableRoleFunction.selected = true; + console.log(availableRoleFunction.selected); + } + } + this.availableRoleFunctions.push(availableRoleFunction); + } + return this.availableRoleFunctions; + } + + toggleRoleFunction(_element) { + if (this.appRoleFunctions) { + for (var i = 0; i < this.appRoleFunctions.length; i++) { + var availableRoleFunction = this.appRoleFunctions[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); + } + } + } + } + + + + saveRole() { + var uuu = this.api.saveRole.replace(':appId', this.appId); + if (this.isGlobalRoleChecked.isChecked) { + this.role.name = (this.role.name.indexOf('global_') == -1) ? ('global_' + this.role.name) : (this.role.name); + this.saveOrUpdateRole(uuu); + } else { + var roleName = this.role.name.toLowerCase(); + if (roleName.includes('global_')) { + const modalInfoRef = this.ngbModal.open(ConfirmationModalComponent); + modalInfoRef.componentInstance.title = 'Confirmation'; + modalInfoRef.componentInstance.message = 'Global prefix:"global_" can only be used when the global flag is checked for the role name:' + this.role.name + '. Please try again!'; + } else { + this.role.childRoles = []; + this.role.roleFunctions = []; + this.saveOrUpdateRole(uuu); + } + } + } + + saveOrUpdateRole(uuu) { + var confirmMessage = (this.dialogState === 2) ? 'You are about to update the role/role functions. Do you want to continue?' : 'You are about to create the role `' + this.role.name + '` . Do you want to continue?'; + const modalInfoRef = this.ngbModal.open(InformationModalComponent); + modalInfoRef.componentInstance.title = 'Confirmation'; + modalInfoRef.componentInstance.message = confirmMessage; + modalInfoRef.result.then((_res) => { + if (_res === 'Ok') { + //overriding the final list of rolefunctions to role + if (this.finalSelectedRoleFunctions.length > 0) + this.role.roleFunctions = this.finalSelectedRoleFunctions; + var postData = { + role: this.role, + childRoles: this.role.childRoles, + roleFunctions: this.role.roleFunctions + }; + this.showSpinner = true + this.http.post(uuu, postData).toPromise().then((res: any) => { + this.showSpinner = false; + if (res && res.role) { + const modalInfoRef = this.ngbModal.open(ConfirmationModalComponent); + modalInfoRef.componentInstance.title = 'Success'; + modalInfoRef.componentInstance.message = 'Update Successful.'; + this.passBackAddRolePopup.emit(this.appId); + + } + else { + const modalInfoRef = this.ngbModal.open(ConfirmationModalComponent); + modalInfoRef.componentInstance.title = 'Error'; + modalInfoRef.componentInstance.message = res.error; + } + }, (res: HttpErrorResponse) => { + this.showSpinner = false; + const modalInfoRef = this.ngbModal.open(ConfirmationModalComponent); + modalInfoRef.componentInstance.title = 'Error'; + modalInfoRef.componentInstance.message = 'Error while saving.' + res.status; + } + ); + } + }, (_dismiss) => { + + }) + } + +} |