diff options
Diffstat (limited to 'ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/admin/menus/new-menu')
4 files changed, 640 insertions, 0 deletions
diff --git a/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/admin/menus/new-menu/new-menu.component.html b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/admin/menus/new-menu/new-menu.component.html new file mode 100644 index 00000000..6a5426a8 --- /dev/null +++ b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/admin/menus/new-menu/new-menu.component.html @@ -0,0 +1,137 @@ +<!-- + ============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============================================ + +--> + +<div class="container"> + <!--Modal Headers--> + <div class="modal-header"> + <h4 class="modal-title">{{(isEditMode) ? 'Edit Menu Item' : 'Add New Menu Item'}}</h4> + <button type="button" class="close" aria-label="Close" (click)="activeModal.dismiss('Cross')"> + <span aria-hidden="true">×</span> + </button> + </div> + + <!--Modal Body goes here--> + <div class="modal-body"> + <div class="elementsContainer"> + <div class="groupItem"> + <label class="item-label">*Label:</label><br> + <input [(ngModel)]="menu.label" type="text" name="label" id="label"> + </div> + <div class="groupItem"> + <label class="item-label">*Parent:</label><br> + <!-- <input [(ngModel)]="menu.parentId" type="text" name="parentId" id="parent"> --> + <select class="form-field" name="parentSelect" id="parentSelect" [(ngModel)]="menu.parentId"> + <option>{{getParentLabel(menu.parentId, parentListSelectData)}}</option> + <option *ngFor="let option of parentListSelectData" value="{{option[0]}}">{{option[1]}}</option> + </select> + </div> + <div class="groupItem"> + <label class="item-label">*Sort Order</label><br> + <input [(ngModel)]="menu.sortOrder" type="text" name="sortOrder" id="sortOrder"> + </div> + <div class="groupItem"> + <label class="item-label">*Action</label><br> + <input [(ngModel)]="menu.action" type="text" name="action" id="action"> + </div> + </div> + + <br> + + <div class="elementsContainer"> + <div class="groupItem"> + <label class="item-label"><b>*</b>Function:</label><br> + <select class="form-field" name="repeatSelect" id="repeatSelect" [(ngModel)]="menu.functionCd"> + <option>{{menu.functionCd}}</option> + <option *ngFor="let item of functionCDselectData" value="{{item}}" >{{item}}</option> + </select> + </div> + <div class="groupItem"> + <label class="item-label"><b>*</b>Active:</label><br> + <select class="form-field" name="selectActive" ng-model="menu.active"> + <option *ngFor="let active of activeStatusOptions" value="{{active.value}}">{{active.title}}</option> + </select> + </div> + <div class="groupItem"> + <label class="item-label">Servlet:</label><br> + <input [(ngModel)]="menu.servlet" type="text" name="servlet" id="servlet"> + </div> + <div class="groupItem"> + <label class="item-label">Query String:</label><br> + <input [(ngModel)]="menu.queryString" type="text" name="queryString" id="queryString"> + </div> + </div> + + <br> + + <div class="elementsContainer"> + <div class="groupItem"> + <label class="item-label">External URL:</label><br> + <input [(ngModel)]="menu.externalUrl" type="text" name="externalURL" id="externalURL"> + </div> + <div class="groupItem"> + <label class="item-label">Target:</label><br> + <input [(ngModel)]="menu.target" type="text" name="target" id="target"> + </div> + <div class="groupItem"> + <label class="item-label"><b>*</b>Menu Set Code:</label><br> + <input [(ngModel)]="menu.menuSetCode" type="text" name="menuSetCode" id="menuSetCode"> + </div> + <div class="groupItem"> + <label class="item-label"><b>*</b>Separator:</label><br> + <select class="form-field" name="select" ng-model="menu.separator"> + <option *ngFor="let separator of separatorStatusOptions" value="{{separator.value}}">{{separator.title}}</option> + </select> + </div> + </div> + + <br> + + <div class="elementsContainer"> + <div class="groupItem"> + <label class="item-label">Image Source:</label><br> + <input [(ngModel)]="menu.imageSrc" type="text" name="imageSource" id="imageSource"> + </div> + </div> + + </div> + <!--Modal Footer goes Here--> + <div class="modal-footer"> + <button type="button" class="btn btn-primary" (click)="updateFnMenu()">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/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/admin/menus/new-menu/new-menu.component.scss b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/admin/menus/new-menu/new-menu.component.scss new file mode 100644 index 00000000..a8b5f966 --- /dev/null +++ b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/admin/menus/new-menu/new-menu.component.scss @@ -0,0 +1,71 @@ +/* + * ============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============================================ + * + * + */ + +::ng-deep .modal-dialog { + max-width: 1200px; + width: 883px; + overflow-x: auto; + overflow-y: auto; +} + +table { + width: 100%; +} + +body { + font-family: Roboto, Arial, sans-serif; + margin: 0; +} + +.elementsContainer{ + display: inline-flex; +} + +.groupItem{ + margin-right: 11px; + margin-bottom: 10px; +} + +.form-field{ + height: 30px; + width: 198px +} + +.item-label{ + margin-bottom: 1px; +} diff --git a/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/admin/menus/new-menu/new-menu.component.spec.ts b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/admin/menus/new-menu/new-menu.component.spec.ts new file mode 100644 index 00000000..650f09a6 --- /dev/null +++ b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/admin/menus/new-menu/new-menu.component.spec.ts @@ -0,0 +1,165 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2019 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * * Modification Copyright © 2020 IBM. + * =================================================================== + + * 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 {FormsModule} from '@angular/forms'; +import { NewMenuComponent } from './new-menu.component'; +import { HttpClientTestingModule } from '@angular/common/http/testing'; +import { NgbActiveModal, NgbModalModule } from '@ng-bootstrap/ng-bootstrap'; +import { RouterTestingModule } from '@angular/router/testing'; +import { CookieService } from 'ngx-cookie-service'; +import { AdminService } from '../../admin.service'; +import 'rxjs/add/operator/toPromise'; +import { ConfirmationModalComponent } from 'src/app/modals/confirmation-modal/confirmation-modal.component'; +import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; +import 'rxjs/add/observable/of'; +import { Observable } from 'rxjs/Observable'; +import 'rxjs/add/operator/catch'; +import 'rxjs/add/observable/throw'; +import { BrowserDynamicTestingModule } from '@angular/platform-browser-dynamic/testing'; + + +describe('NewMenuComponent', () => { + let component: NewMenuComponent; + let fixture: ComponentFixture<NewMenuComponent>; + let adminService:AdminService; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ NewMenuComponent,ConfirmationModalComponent ], + imports:[ + FormsModule, + HttpClientTestingModule, + RouterTestingModule, + NgbModalModule, + BrowserAnimationsModule + ], + providers:[ + AdminService, + NgbActiveModal, + CookieService + ], + }) + TestBed.overrideModule(BrowserDynamicTestingModule,{ + set:{ + entryComponents:[ConfirmationModalComponent ] + } + }) + .compileComponents(); + + })); + + beforeEach(() => { + fixture = TestBed.createComponent(NewMenuComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + adminService=TestBed.get(AdminService); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); + + it('testing ngOnInit method for if condition',()=>{ + component.selectedMenu=1; + component.ngOnInit(); + expect(component.menu).toEqual(component.selectedMenu); + }) + + it('testing ngOnInit method for else condition',()=>{ + component.selectedMenu=0; + component.ngOnInit(); + expect(component.menu.menuSetCode).toEqual('APP'); + }) + + it('testing sortItems method',()=>{ + let prop: any; + component.sortItems(prop); + + }) + + it('testing getParentLabel method',()=>{ + component.getParentLabel(1,"data"); + }) + + + it('should test getParentData method1 ',()=>{ + const children="children"; + let spy=spyOn(adminService,'getParentData').and.returnValue(Observable.of('you object')); + component.getParentData(); + expect(spy).toHaveBeenCalled(); + }) + + it('should test getParentData method2 error part ',()=>{ + const children="children"; + let spy=spyOn(adminService,'getParentData').and.returnValue(Observable.throw({status:404})); + component.getParentData(); + expect(spy).toHaveBeenCalled(); + }) + + describe('should test getLeftMenuItems',()=>{ + it('testing getLeftMenuItems',()=>{ + component.getLeftMenuItems(); + }) + }) + + it('testing getFunctionCDselectData method1',()=>{ + let spy=spyOn(adminService,'getFunctionCdList').and.returnValue(Observable.of('your object')); + component.getFunctionCDselectData(); + expect(spy).toHaveBeenCalled(); + expect(component.result).toEqual('your object'); + expect(component.functionCDselectData).toEqual('your object'); + }) + + describe('should test getFunctionCDselectData method2',()=>{ + it('testing getFunctionCDselectData',()=>{ + let spy= spyOn(adminService,'getFunctionCdList').and.returnValue(Observable.throw({status:404})) + component.getFunctionCDselectData(); + expect(spy).toHaveBeenCalled(); + expect(component.showSpinner).toEqual(false); + }) + }) + + it('should test updateFnMenu method',()=>{ + component.menu.label!=null; + component.updateFnMenu(); + }) + +}); diff --git a/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/admin/menus/new-menu/new-menu.component.ts b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/admin/menus/new-menu/new-menu.component.ts new file mode 100644 index 00000000..6e5b0c1a --- /dev/null +++ b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/admin/menus/new-menu/new-menu.component.ts @@ -0,0 +1,267 @@ +/* + * ============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, Input, Output, EventEmitter } from '@angular/core'; +import { NgbActiveModal, NgbModal } from '@ng-bootstrap/ng-bootstrap'; +import { AdminService } from '../../admin.service'; +import { SidebarComponent } from 'src/app/layout/components/sidebar/sidebar.component'; +import { Router } from '@angular/router'; +import { SidebarService } from 'src/app/shared/services'; +import { ConfirmationModalComponent } from 'src/app/modals/confirmation-modal/confirmation-modal.component'; +import { CookieService } from 'ngx-cookie-service'; + +@Component({ + selector: 'app-new-menu', + templateUrl: './new-menu.component.html', + styleUrls: ['./new-menu.component.scss'] +}) +export class NewMenuComponent implements OnInit { + + menu = { + action: null, + active: false, + activeAsString: "false", + auditTrail: null, + auditUserId: null, + childMenus: [], + created: null, + createdId: null, + externalUrl: null, + functionCd: null, + id: null, + imageSrc: null, + label: null, + menuLevel: null, + menuSetCode: null, + modified: null, + modifiedId: null, + parentId: null, + parentIdAsString: null, + parentMenu: null, + queryString: null, + rowNum: null, + separator: false, + separatorAsString: false, + servlet: null, + sortOrder: null, + target: null + } + showSpinner: boolean; + result: any; + //menu: any; + @Input() selectedMenu: any; + @Input() isEditMode: boolean; + @Output() passEntry: EventEmitter<any> = new EventEmitter(); + + statusOptions = [ + {index: 0, value: 'true', title: 'Y'}, + {index: 1, value: 'false', title: 'N'} + ]; + selectedValue = this.statusOptions[0]; + separator = { + availableOptions:[ + {value: 'true', name: 'Y'}, + {value: 'false', name: 'N'} + ], + selectedOption: {value: 'true', name: 'Y'} + } + + activeStatusOptions = [ + {index: 0, value: 'true', title: 'Y'}, + {index: 1, value: 'false', title: 'N'} + ]; + activeSelectedValue = this.activeStatusOptions[0]; + + separatorStatusOptions = [ + {index: 0, value: 'true', title: 'Y'}, + {index: 1, value: 'false', title: 'N'} + ]; + separatorSelectedValue = this.separatorStatusOptions[1]; + + active = { + availableOptions:[ + {value: 'true', name: 'Y'}, + {value: 'false', name: 'N'} + ], + selectedOption: {value: 'true', name: 'Y'} + }; + + functionCDselectData = []; + parentListSelectData = []; + childListSelectData = []; + + constructor(public adminService: AdminService, public activeModal: NgbActiveModal, + public ngmodel: NgbModal, public router: Router, public sidebarService: SidebarService,public cookieService:CookieService) { } + + ngOnInit() { + if(this.selectedMenu){ + this.menu = this.selectedMenu; + }else{ + this.menu.menuSetCode='APP'; + } + this.getFunctionCDselectData(); + this.getParentData(); + } + + getParentData(){ + this.showSpinner = true; + this.adminService.getParentData() + .subscribe( _data => { + this.result = _data; + if(_data){ + this.parentListSelectData= _data; // data from server + let menuItems = this.parentListSelectData; + var heirarchicalMenuItems = []; + var children = []; + for ( var i=0; i<menuItems.length; i++){ + for(var j=0; j<menuItems.length; j++){ + if(menuItems[j][2]==menuItems[i][0]) + children.push( + { + menuId: menuItems[j][0], + label: menuItems[j][1] + } + ); + } + if(children.length!=0){ + heirarchicalMenuItems.push( + { + menuId: menuItems[i][0], + label: menuItems[i][1], + children: children.sort(this.sortItems("label")) + } + + ); + } + children = []; + } + heirarchicalMenuItems.sort(this.sortItems("label")); + this.childListSelectData = heirarchicalMenuItems; + } + }, error => { + this.showSpinner = false; + console.log(error); + }); + } + + sortItems(prop){ + return function(a, b) { + if (a[prop] > b[prop]) { + return 1; + } else if (a[prop] < b[prop]) { + return -1; + } + return 0; + } + } + + getParentLabel(parentId, parentListSelectData){ + var element; + element = parentListSelectData[0]; + for (var i=0; i<parentListSelectData.length; i++){ + element = parentListSelectData[i]; + if (element[0] == parentId) + return element[1]; + else "---"; + } + } + + updateFnMenu(){ + this.showSpinner = true; + if( this.menu && this.menu.imageSrc == "" ) this.menu.imageSrc = "N/A"; + if( this.menu && this.menu.target == "" ) this.menu.target = "N/A"; + if( this.menu && this.menu.externalUrl == "" ) this.menu.externalUrl = "N/A"; + if( this.menu && this.menu.queryString == "" ) this.menu.queryString = "N/A"; + if( this.menu && this.menu.servlet == "" ) this.menu.servlet = "N/A"; + + let validationRule = /^\S{3,}$/; + let selectedFunction = this.menu.functionCd; + var selectedFunctionText = this.menu.functionCd; //selectedFunction.options[selectedFunction.selectedIndex].text; + + if((this.menu.label == null || this.menu.label == "" || (this.menu.label && this.menu.label.trim().length == 0) ) || + this.menu.parentId == null || this.menu.parentId == "" || this.menu.action == null || this.menu.action == "" || + selectedFunctionText == null || selectedFunctionText == "" || this.menu.sortOrder == null || this.menu.sortOrder == "" || + this.menu.menuSetCode == null ||this.menu.menuSetCode == ""){ + + this.openConfirmationModal('','Please provide all the mandatory (*) fields inputs !'); + return; + }else{ + this.menu.parentId=parseFloat(this.menu.parentId); + let data ={availableFnMenuItem: this.menu}; + let postData = JSON.stringify(data); + this.adminService.updateFnMenuItem(postData) + .subscribe( _data => { + this.result = _data; + this.passEntry.emit(this.result); + this.ngmodel.dismissAll(); + }, error => { + this.showSpinner = false; + console.log(error); + this.openConfirmationModal("Error",error); + }); + this.getLeftMenuItems(); + } + + } + + getLeftMenuItems(){ + let sidebarComponent = new SidebarComponent(this.router, this.sidebarService,this.cookieService); + sidebarComponent.ngOnInit(); + } + + getFunctionCDselectData = function(){ + this.adminService.getFunctionCdList() + .subscribe( _data => { + this.result = _data; + if(_data){ + this.functionCDselectData = _data; + } + }, error => { + this.showSpinner = false; + console.log(error); + this.openConfirmationModal("","Function Code Data not available !"); + }); + } + + openConfirmationModal(_title: string, _message: string) { + const modalInfoRef = this.ngmodel.open(ConfirmationModalComponent); + modalInfoRef.componentInstance.title = _title; + modalInfoRef.componentInstance.message = _message; + } + +} |