diff options
Diffstat (limited to 'portal-FE-common/src/app/pages/admins/new-admin')
4 files changed, 444 insertions, 0 deletions
diff --git a/portal-FE-common/src/app/pages/admins/new-admin/new-admin.component.html b/portal-FE-common/src/app/pages/admins/new-admin/new-admin.component.html new file mode 100644 index 00000000..c43e4ba1 --- /dev/null +++ b/portal-FE-common/src/app/pages/admins/new-admin/new-admin.component.html @@ -0,0 +1,96 @@ +<!-- + ============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" *ngIf="dialogState===1"> + <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"> + <app-search-users [searchTitle]="searchTitleText" [placeHolder]="placeholderText" (passBackSelectedUser)='changeSelectedUser($event)'></app-search-users> + <span class="onap-spinner" *ngIf="isLoading"></span> + </div> + <div class="modal-footer"> + <button type="submit" class="btn btn-primary" [disabled]='!changedSelectedUser' + (click)="getAdminAppsRoles()">Next</button> + <button type="button" class="btn btn-primary" (click)="activeModal.close('Close')">Close</button> + </div> +</div> +<div class="container" *ngIf="dialogState===2"> + <div class="modal-header"> + <h4 class="modal-title">{{userTitle}}</h4> + <button type="button" class="close" aria-label="Close" (click)="activeModal.dismiss('Cross')"> + <span aria-hidden="true">×</span> + </button> + </div> + <div class="modal-body adminApps"> + <div ngbDropdown class="d-inline-block"> + <h4>Administrates:</h4> + <button class="btn btn-outline-primary" id="dropdownBasic1" ngbDropdownToggle>Select Application</button> + <div ngbDropdownMenu aria-labelledby="dropdownBasic1"> + <button *ngFor="let app of adminDropdownApps" (click)="updateDropdown(app, true)" + ngbDropdownItem>{{app.appName}}</button> + </div> + </div> + <!-- User admins list --> + <div class="container adminApps" *ngIf="adminAppsRoles.length > 0"> + <table mat-table [dataSource]="adminsAppsSource"> + <!-- Search Result Column--> + <ng-container matColumnDef="applications"> + <th id="rowheader-result" mat-header-cell *matHeaderCellDef> Applications <span id="i-delete-application" + class="span-remove-title"> Delete </span></th> + <td id="table-data-{{i}}" mat-cell *matCellDef="let element; let i = index;"> + {{element.appName}} <span id="i-delete-application" class="span-remove-admin" + (click)="removeAdminApp(element)"><i class="icon ion-md-trash"></i></span> + </td> + </ng-container> + <tr mat-header-row *matHeaderRowDef="displayedColumns; sticky: true"></tr> + <tr mat-row id="table-row-{{i}}" *matRowDef="let row; columns: displayedColumns; let i = index;"></tr> + </table> + </div> + </div> + <div class="modal-footer"> + <button [hidden]="disableBack" type="submit" class="btn btn-primary" [disabled]='!changedSelectedUser' + (click)="navigateBack()">Back</button> + <button type="submit" class="btn btn-primary" [disabled]='!newAppSelected' + (click)="updateAdminAppsRoles(adminAppsScreen)">Save</button> + <button type="button" class="btn btn-primary" (click)="activeModal.close('Close')">Close</button> + </div> +</div>
\ No newline at end of file diff --git a/portal-FE-common/src/app/pages/admins/new-admin/new-admin.component.scss b/portal-FE-common/src/app/pages/admins/new-admin/new-admin.component.scss new file mode 100644 index 00000000..eb6db14c --- /dev/null +++ b/portal-FE-common/src/app/pages/admins/new-admin/new-admin.component.scss @@ -0,0 +1,58 @@ +/*- + * ============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============================================ + * + * + */ +.container.adminApps { + overflow-y: auto; + height: 250px; +} + +.dropdown-menu.show { + overflow-y: auto !important; + height: 250px !important; +} +.span-remove-title { + float: right; +} +.span-remove-admin { + float: right; + cursor: pointer; + font-size: 20px; +} + +.onap-spinner{ + z-index: 9999; +}
\ No newline at end of file diff --git a/portal-FE-common/src/app/pages/admins/new-admin/new-admin.component.spec.ts b/portal-FE-common/src/app/pages/admins/new-admin/new-admin.component.spec.ts new file mode 100644 index 00000000..4040b0d3 --- /dev/null +++ b/portal-FE-common/src/app/pages/admins/new-admin/new-admin.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 { NewAdminComponent } from './new-admin.component'; + +describe('NewAdminComponent', () => { + let component: NewAdminComponent; + let fixture: ComponentFixture<NewAdminComponent>; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ NewAdminComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(NewAdminComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/portal-FE-common/src/app/pages/admins/new-admin/new-admin.component.ts b/portal-FE-common/src/app/pages/admins/new-admin/new-admin.component.ts new file mode 100644 index 00000000..8f80138e --- /dev/null +++ b/portal-FE-common/src/app/pages/admins/new-admin/new-admin.component.ts @@ -0,0 +1,228 @@ +/*- + * ============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, Output, EventEmitter, Input } from '@angular/core'; +import { AdminsService } from 'src/app/shared/services'; +import { HttpErrorResponse } from '@angular/common/http'; +import { ConfirmationModalComponent } from 'src/app/modals/confirmation-modal/confirmation-modal.component'; +import { NgbModal, NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'; +import { PortalAdmin } from 'src/app/shared/model'; +import { MatTableDataSource } from '@angular/material'; +import { InformationModalComponent } from 'src/app/modals/information-modal/information-modal.component'; +import { Router } from '@angular/router'; + +@Component({ + selector: 'app-new-admin', + templateUrl: './new-admin.component.html', + styleUrls: ['./new-admin.component.scss'] +}) +export class NewAdminComponent implements OnInit { + + @Input() dialogState: number; + @Input() userTitle: string; + @Input() disableBack: boolean; + @Input() adminModalData: any; + @Output() passBackNewAdminPopup: EventEmitter<any> = new EventEmitter(); + searchTitleText = 'Enter First Name, Last Name or Org User Id'; + placeholderText = 'Search'; + changedSelectedUser: PortalAdmin; + adminAppsRoles: any; + adminDropdownApps: any; + isLoading: boolean; + newAppSelected: boolean; + adminAppSelectAndUnselectData: any; + displayedColumns: string[] = ['applications']; + adminsAppsSource = new MatTableDataSource(this.adminAppsRoles); + constructor(public router: Router, private adminsService: AdminsService, public ngModal: NgbModal, public activeModal: NgbActiveModal) { } + + ngOnInit() { + this.adminAppsRoles = []; + this.changedSelectedUser = null; + if (this.disableBack){ + this.changedSelectedUser = this.adminModalData; + this.getAdminAppsRoles(); + } + this.adminDropdownApps = []; + this.adminAppSelectAndUnselectData = []; + } + + changeSelectedUser(user: PortalAdmin) { + this.changedSelectedUser = user; + this.userTitle = `${this.changedSelectedUser.firstName}, ` + ` ${this.changedSelectedUser.lastName} ` + ` (${this.changedSelectedUser.orgUserId})`; + } + + getAdminAppsRoles() { + this.isLoading = true; + this.adminsService.getAdminAppsRoles(this.changedSelectedUser.orgUserId).subscribe((_res: any) => { + JSON.stringify(_res); + if (!_res.appsRoles) { + return; + } + this.adminAppsRoles = []; + for (var i = 0; i < _res.appsRoles.length; i++) { + if (!_res.appsRoles[i].restrictedApp && _res.appsRoles[i].isAdmin) { + this.adminAppsRoles.push({ + id: _res.appsRoles[i].id, + appName: _res.appsRoles[i].appName, + isAdmin: _res.appsRoles[i].isAdmin, + restrictedApp: _res.appsRoles[i].restrictedApp + }); + } else if (!_res.appsRoles[i].restrictedApp) { + this.adminDropdownApps.push({ + id: _res.appsRoles[i].id, + appName: _res.appsRoles[i].appName, + isAdmin: _res.appsRoles[i].isAdmin, + restrictedApp: _res.appsRoles[i].restrictedApp + }); + } + } + this.isLoading = false; + this.newAppSelected = false; + this.dialogState = 2; + this.adminsAppsSource = new MatTableDataSource(this.adminAppsRoles); + }); + } + + navigateBack() { + this.dialogState = 1; + } + + removeAdminApp(app: any) { + const modalRef = this.ngModal.open(InformationModalComponent); + modalRef.componentInstance.title = "Confirmation"; + modalRef.componentInstance.message = `Are you sure you want to delete ${app.appName}?`; + modalRef.result.then((result) => { + if (result === 'Ok') { + this.adminAppsRoles.forEach((item: any, index: any) => { + if (item === app) this.adminAppsRoles.splice(index, 1); + }); + //call from delete admin app + this.updateDropdown(app, false); + this.adminsAppsSource = new MatTableDataSource(this.adminAppsRoles); + } + }, (resut) => { + return; + }) + } + + updateDropdown(_newValue: any, isDropdownCall: boolean) { + // app is selected from dropdown + if (isDropdownCall) { + this.adminDropdownApps.forEach((item: any, index: any) => { + if (item === _newValue) this.adminDropdownApps.splice(index, 1); + }); + this.getadminAppSelectAndUnselectedData(_newValue); + _newValue.isAdmin = true; + this.adminAppsRoles.push(_newValue); + this.adminsAppsSource = new MatTableDataSource(this.adminAppsRoles); + } else { // app is removed from the admin list + this.getadminAppSelectAndUnselectedData(_newValue); + _newValue.isAdmin = false; + this.adminDropdownApps.push(_newValue); + } + + // disable save button if nothing new in the admin list + if (this.adminAppSelectAndUnselectData.length > 0) + this.newAppSelected = true; + else + this.newAppSelected = false; + + } + + private getadminAppSelectAndUnselectedData(_newValue: any) { + const index: number = this.adminAppSelectAndUnselectData.indexOf(_newValue); + if (index !== -1) { + this.adminAppSelectAndUnselectData.splice(index, 1); // if found, remove selected app from dropdown in the list + } + else { + this.adminAppSelectAndUnselectData.push(_newValue); + } + } + + remindToAddUserIfNecessary() { + let adminAddedToNewApp = true; + if ((this.adminAppsRoles != null) && (this.adminAppsRoles.length > 0)) { + for (var i = 0; i < this.adminAppSelectAndUnselectData.length; i++) { + var foundApp = false; + for (var j = 0; j < this.adminAppsRoles.length; j++) { + if (this.adminAppsRoles[j] === this.adminAppSelectAndUnselectData[i]) { + foundApp = true; + } + } + if (foundApp === false) { + adminAddedToNewApp = true; + break; + } + } + } else { + adminAddedToNewApp = true; + } + if (adminAddedToNewApp === true) { + const modalRef = this.ngModal.open(InformationModalComponent); + modalRef.componentInstance.title = "Confirmation"; + modalRef.componentInstance.message = 'Add this person as an application user? This allows them to access the application from ONAP Portal. Press OK to go to the Add Users page.'; + modalRef.result.then((_res) => { + if (_res === 'Ok') { + this.router.navigate(['/users']); + } + }); + } + } + + updateAdminAppsRoles() { + const modalRef = this.ngModal.open(InformationModalComponent); + modalRef.componentInstance.title = "Admin Update"; + modalRef.componentInstance.message = 'Are you sure you want to make these admin changes?'; + modalRef.result.then((result) => { + if (result === 'Ok') { + this.adminsService.updateAdminAppsRoles({ orgUserId: this.changedSelectedUser.orgUserId, appsRoles: this.adminAppsRoles }).subscribe(_data => { + this.passBackNewAdminPopup.emit(_data); + this.remindToAddUserIfNecessary(); + }, (_err: HttpErrorResponse) => { + this.passBackNewAdminPopup.emit(_err); + const modalErrorRef = this.ngModal.open(ConfirmationModalComponent); + modalErrorRef.componentInstance.title = "Error"; + if (_err.status) { + modalErrorRef.componentInstance.message = "There was a unknown problem while adding admin to selected application(s)." + "Please try again later. Error Status: " + _err.status; + } + }); + } + }, (reason) => { + return; + }); + } +} |