diff options
Diffstat (limited to 'ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/user-profile/profile/self/self.component.ts')
-rw-r--r-- | ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/user-profile/profile/self/self.component.ts | 342 |
1 files changed, 342 insertions, 0 deletions
diff --git a/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/user-profile/profile/self/self.component.ts b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/user-profile/profile/self/self.component.ts new file mode 100644 index 00000000..7396b23c --- /dev/null +++ b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/user-profile/profile/self/self.component.ts @@ -0,0 +1,342 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 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 } from '@angular/core'; +import { UserService } from 'src/app/shared/services/user/user.service'; +import { User } from 'src/app/shared/services/user/user'; +import { ProfileService } from '../profile.service'; +import { MatTableDataSource } from '@angular/material'; +import { NgbModal, ModalDismissReasons } from '@ng-bootstrap/ng-bootstrap'; +import { InformationModalComponent } from 'src/app/modals/information-modal/information-modal.component'; +import { ErrorModalComponent } from 'src/app/modals/error-modal/error-modal.component'; +import { ConfirmationModalComponent } from 'src/app/modals/confirmation-modal/confirmation-modal.component'; +import { Column, ColumnTypes, DataTableSettings } from 'portalsdk-tag-lib'; +import { ActivatedRoute } from '@angular/router'; + +@Component({ + selector: 'app-self', + templateUrl: './self.component.html', + styleUrls: ['./self.component.scss'] +}) +export class SelfComponent implements OnInit { + + constructor(public userService: UserService, + public profileService: ProfileService, + private ngModal: NgbModal, + private route: ActivatedRoute) { } + + user: User; + isAppCentralized; + response; + result; + postData: { + profile: any, + selectedCountry: any, + selectedState: any, + selectedTimeZone: any + } = { profile: "", selectedCountry: "", selectedState: "", selectedTimeZone: "" }; + + profile: { + lastName: any, firstName: any, orgUserId: any, orgManagerUserId: any, loginId: any,loginPwd: any,phone: any,fax: any,cellular: any, + email: any;address1: any,address2: any,city: any,state :any,zipCode: any,country: any,timeZoneId: any,id: any,roles: any + } = { + lastName: "", firstName: "", orgUserId: "", orgManagerUserId: "", loginId: "",loginPwd: "",phone: "",fax: "", + cellular: "", email: "",address1: "",address2: "",city: "",state:"" ,zipCode: "",country: "",timeZoneId: "",id: "",roles: "" + }; + + oriProfile; + profileId; + ociavailableRoles; + ociTimeZones; + ociCountries; + stateList; + isUserSystemAdmin; + availableRoles: Array<any> = []; + dataSource: MatTableDataSource<any>; + showSpinner:boolean; + + userRolesHeader = ["name", "active"]; + closeResult: string; + selectedCountry; + selectedState; + selectedTimeZone; + finalSelectedRoles: any; + + public settings; + public columns: any = []; + + + ngOnInit() { + this.profileId = ""; + //console.log("ngOnInit called ",this.profileId); + if(this.route.snapshot.queryParams['profile_id']){ + this.profileId = this.route.snapshot.queryParams['profile_id']; + } + this.showSpinner = false; + this.finalSelectedRoles = []; + let result = this.userService.getFunctionalMenuStaticDetailSession(); + let user; + result.subscribe(user => { + this.user = user; + this.isAppCentralized = this.user.isAppCentralized; + }); + if (this.profileId != undefined && this.profileId != "") { + this.getProfileById(this.profileId); + } else { + this.getSelfProfileDetail(); + } + } + + /** + * Get Self Profile Details + */ + getSelfProfileDetail() { + this.showSpinner = true; + this.response = this.profileService.getSelfProfile(); + this.response.subscribe(data => { + this.assignProfileDetails(data); + }); + this.showSpinner = false; + } + + /** + * Get Profile Details by ProfileId + */ + getProfileById(profileId) { + this.showSpinner = true; + this.profileService.getProfileById(profileId).subscribe(response => { + this.assignProfileDetails(response); + }) + this.showSpinner = false; + } + + assignProfileDetails(data) { + let res; + res = data; + this.result = JSON.parse(res.data); + + this.profile = JSON.parse(this.result.profile); + this.oriProfile = JSON.parse(this.result.profile); /*original value*/ + + this.profileId = this.profile.id; + this.ociavailableRoles = this.profile.roles; + //console.log("Profile specific roles : ", this.ociavailableRoles); + this.ociTimeZones = JSON.parse(this.result.timeZones); + this.ociCountries = JSON.parse(this.result.countries); + this.stateList = JSON.parse(this.result.stateList); + + for (let state of this.stateList) { + if (state.value == this.profile.state) { + this.profile.state = state.value; + } + } + + for (let country of this.ociCountries) { + if (country.value == this.profile.country) { + this.profile.country = country.value; + } + } + + for (let timeZone of this.ociTimeZones) { + if (timeZone.value == this.profile.timeZoneId) { + this.profile.timeZoneId = timeZone.value; + } + } + + this.columns.push(new Column("name", "Name", ColumnTypes.TEXT, false, null)); + this.settings = new DataTableSettings() + this.settings.columns = this.columns; + this.settings.isPaginationEnabled = false; + this.settings.isReadOnly = true; + this.settings.isTableSearchEnabled = false; + this.settings.isToggleEnabled = true; + + if (this.ociavailableRoles != null) { + for (let role of this.ociavailableRoles) { + role.selected = false; + for (let profileRole of this.profile.roles) { + if (profileRole.id === role.id) { + role.selected = true; + } + if (role.id === 1) { + this.isUserSystemAdmin = true; + } + } + this.availableRoles.push(role); + } + } + } + + /** + * Remove Role + * @param role + */ + removeRole(role: any) { + const modalRef = this.ngModal.open(InformationModalComponent); + modalRef.componentInstance.title = 'Confirmation'; + modalRef.componentInstance.message = `Are you sure you want to remove ${role.name} ?`; + modalRef.result.then((result) => { + if (result === 'Ok') { + this.profileService.removeRole(role, this.profileId).subscribe(data => { + this.getSelfProfileDetail(); + }) + } + }, (reason) => { + this.closeResult = `Dismissed ${this.getDismissReason(reason)}`; + }); + } + + /** + * Add User Role + * @param role + */ + addUserRole(role: any) { + const modalRef = this.ngModal.open(InformationModalComponent); + modalRef.componentInstance.title = 'Confirmation'; + modalRef.componentInstance.message = `Are you sure you want to add ${role.name} ?`; + modalRef.result.then((result) => { + if (result === 'Ok') { + this.profileService.addUserRole(role, this.profileId).subscribe(data => { + this.getSelfProfileDetail(); + }) + } + }, (reason) => { + this.closeResult = `Dismissed ${this.getDismissReason(reason)}`; + }); + } + + private getDismissReason(reason: any): string { + if (reason === ModalDismissReasons.ESC) { + return 'by pressing ESC'; + } else if (reason === ModalDismissReasons.BACKDROP_CLICK) { + return 'by clicking on a backdrop'; + } else { + return `with: ${reason}`; + } + + } + + /** + * Save User Profile + */ + saveProfile() { + + if (this.oriProfile.loginId != this.profile.loginId) { + const modalRef = this.ngModal.open(ErrorModalComponent); + modalRef.componentInstance.message = `Login ID cannot be changed?`; + return; + } + if (this.oriProfile.loginPwd != this.profile.loginPwd) { + const modalRef = this.ngModal.open(ErrorModalComponent); + modalRef.componentInstance.message = `Login pwd cannot be changed?`; + return; + } + + this.postData.profile = this.profile; + this.postData.selectedCountry = this.profile.country != null ? this.profile.country : ""; + this.postData.selectedState = this.profile.state != null ? this.profile.state : ""; + this.postData.selectedTimeZone = this.profile.timeZoneId != null ? this.profile.timeZoneId : ""; + + + for( let state of this.stateList) + { + if(state.value == this.profile.state){ + this.postData.selectedState = state.value; + } + } + + for( let country of this.ociCountries) + { + if(country.value == this.profile.country){ + this.postData.selectedCountry = country.value; + } + } + for( let timeZone of this.ociTimeZones) + { + if(timeZone.value == this.profile.timeZoneId){ + this.postData.selectedTimeZone = timeZone.value; + } + } + + + this.response = this.profileService.saveProfile(this.postData, this.profileId); + this.response.subscribe(data => { + const modalRef = this.ngModal.open(ConfirmationModalComponent); + let response; + modalRef.componentInstance.message = `Profile got saved Successfully`; + modalRef.result.then((result) => { + if (result === 'Close') { + this.getSelfProfileDetail(); + } + }, (reason) => { + this.closeResult = `Dismissed ${this.getDismissReason(reason)}`; + }); + + }); + } + + /** + * toggleRoles + * @param _element + */ + toggleRoles(_element) { + if (this.ociavailableRoles) { + for (var i = 0; i < this.ociavailableRoles.length; i++) { + var availableRole = this.ociavailableRoles[i]; + if (availableRole.selected && !this.finalSelectedRoles.includes(availableRole)) { + this.finalSelectedRoles.push(availableRole); + } + } + } + + if (!_element.selected) { + for (var i = 0; i < this.finalSelectedRoles.length; i++) { + var availableRole = this.finalSelectedRoles[i]; + if (availableRole.id == _element.id + && availableRole.name == _element.name) { + this.finalSelectedRoles.splice(i, 1); + } + } + } + if(_element.selected){ + this.addUserRole(_element); + }else{ + this.removeRole(_element); + } + } +} |