2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright © 2019 AT&T Intellectual Property. All rights reserved.
6 * ===================================================================
8 * Unless otherwise specified, all software contained herein is licensed
9 * under the Apache License, Version 2.0 (the "License");
10 * you may not use this software except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * Unless otherwise specified, all documentation contained herein is licensed
22 * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
23 * you may not use this documentation except in compliance with the License.
24 * You may obtain a copy of the License at
26 * https://creativecommons.org/licenses/by/4.0/
28 * Unless required by applicable law or agreed to in writing, documentation
29 * distributed under the License is distributed on an "AS IS" BASIS,
30 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 * See the License for the specific language governing permissions and
32 * limitations under the License.
34 * ============LICENSE_END============================================
39 import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
40 import { NgbActiveModal, NgbModal } from '@ng-bootstrap/ng-bootstrap';
41 import { AdminService } from '../../admin.service';
42 import { SidebarComponent } from 'src/app/layout/components/sidebar/sidebar.component';
43 import { Router } from '@angular/router';
44 import { SidebarService } from 'src/app/shared/services';
45 import { ConfirmationModalComponent } from 'src/app/modals/confirmation-modal/confirmation-modal.component';
46 import { CookieService } from 'ngx-cookie-service';
49 selector: 'app-new-menu',
50 templateUrl: './new-menu.component.html',
51 styleUrls: ['./new-menu.component.scss']
53 export class NewMenuComponent implements OnInit {
58 activeAsString: "false",
74 parentIdAsString: null,
79 separatorAsString: false,
87 @Input() selectedMenu: any;
88 @Input() isEditMode: boolean;
89 @Output() passEntry: EventEmitter<any> = new EventEmitter();
92 {index: 0, value: 'true', title: 'Y'},
93 {index: 1, value: 'false', title: 'N'}
95 selectedValue = this.statusOptions[0];
98 {value: 'true', name: 'Y'},
99 {value: 'false', name: 'N'}
101 selectedOption: {value: 'true', name: 'Y'}
104 activeStatusOptions = [
105 {index: 0, value: 'true', title: 'Y'},
106 {index: 1, value: 'false', title: 'N'}
108 activeSelectedValue = this.activeStatusOptions[0];
110 separatorStatusOptions = [
111 {index: 0, value: 'true', title: 'Y'},
112 {index: 1, value: 'false', title: 'N'}
114 separatorSelectedValue = this.separatorStatusOptions[1];
118 {value: 'true', name: 'Y'},
119 {value: 'false', name: 'N'}
121 selectedOption: {value: 'true', name: 'Y'}
124 functionCDselectData = [];
125 parentListSelectData = [];
126 childListSelectData = [];
128 constructor(public adminService: AdminService, public activeModal: NgbActiveModal,
129 public ngmodel: NgbModal, public router: Router, public sidebarService: SidebarService,public cookieService:CookieService) { }
132 if(this.selectedMenu){
133 this.menu = this.selectedMenu;
135 this.menu.menuSetCode='APP';
137 //console.log("selected menu >>>>",this.menu);
138 this.getFunctionCDselectData();
139 this.getParentData();
143 this.showSpinner = true;
144 this.adminService.getParentData()
145 .subscribe( _data => {
146 //console.log("getParentData :: _data ",_data);
149 this.parentListSelectData= _data; // data from server
150 let menuItems = this.parentListSelectData;
151 var heirarchicalMenuItems = [];
153 for ( var i=0; i<menuItems.length; i++){
154 for(var j=0; j<menuItems.length; j++){
155 if(menuItems[j][2]==menuItems[i][0])
158 menuId: menuItems[j][0],
159 label: menuItems[j][1]
163 if(children.length!=0){
164 heirarchicalMenuItems.push(
166 menuId: menuItems[i][0],
167 label: menuItems[i][1],
168 children: children.sort(this.sortItems("label"))
175 heirarchicalMenuItems.sort(this.sortItems("label"));
176 this.childListSelectData = heirarchicalMenuItems;
177 //console.log("childListSelectData ::: ",this.childListSelectData);
178 //console.log("heirarchicalMenuItems ::: ",heirarchicalMenuItems);
179 //console.log("parentListSelectData ::: ",this.parentListSelectData);
182 this.showSpinner = false;
188 return function(a, b) {
189 if (a[prop] > b[prop]) {
191 } else if (a[prop] < b[prop]) {
198 getParentLabel(parentId, parentListSelectData){
200 element = parentListSelectData[0];
201 for (var i=0; i<parentListSelectData.length; i++){
202 element = parentListSelectData[i];
203 if (element[0] == parentId)
210 this.showSpinner = true;
211 //console.log("updateFnMenu Changes Called..",this.menu);
212 if( this.menu && this.menu.imageSrc == "" ) this.menu.imageSrc = "N/A";
213 if( this.menu && this.menu.target == "" ) this.menu.target = "N/A";
214 if( this.menu && this.menu.externalUrl == "" ) this.menu.externalUrl = "N/A";
215 if( this.menu && this.menu.queryString == "" ) this.menu.queryString = "N/A";
216 if( this.menu && this.menu.servlet == "" ) this.menu.servlet = "N/A";
218 let validationRule = /^\S{3,}$/;
219 let selectedFunction = this.menu.functionCd;
220 var selectedFunctionText = this.menu.functionCd; //selectedFunction.options[selectedFunction.selectedIndex].text;
222 if((this.menu.label == null || this.menu.label == "" || (this.menu.label && this.menu.label.trim().length == 0) ) ||
223 this.menu.parentId == null || this.menu.parentId == "" || this.menu.action == null || this.menu.action == "" ||
224 selectedFunctionText == null || selectedFunctionText == "" || this.menu.sortOrder == null || this.menu.sortOrder == "" ||
225 this.menu.menuSetCode == null ||this.menu.menuSetCode == ""){
227 this.openConfirmationModal('','Please provide all the mandatory (*) fields inputs !');
230 this.menu.parentId=parseFloat(this.menu.parentId);
231 let data ={availableFnMenuItem: this.menu};
232 let postData = JSON.stringify(data);
233 //console.log("postData >>>>>>",postData);
234 this.adminService.updateFnMenuItem(postData)
235 .subscribe( _data => {
237 this.passEntry.emit(this.result);
238 this.ngmodel.dismissAll();
240 this.showSpinner = false;
242 this.openConfirmationModal("Error",error);
244 this.getLeftMenuItems();
250 //console.log("getLeftMenuItems called after update menu");
251 let sidebarComponent = new SidebarComponent(this.router, this.sidebarService,this.cookieService);
252 sidebarComponent.ngOnInit();
255 getFunctionCDselectData = function(){
256 this.adminService.getFunctionCdList()
257 .subscribe( _data => {
260 this.functionCDselectData = _data;
263 this.showSpinner = false;
265 this.openConfirmationModal("","Function Code Data not available !");
269 openConfirmationModal(_title: string, _message: string) {
270 const modalInfoRef = this.ngmodel.open(ConfirmationModalComponent);
271 modalInfoRef.componentInstance.title = _title;
272 modalInfoRef.componentInstance.message = _message;