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 this.getFunctionCDselectData();
138 this.getParentData();
142 this.showSpinner = true;
143 this.adminService.getParentData()
144 .subscribe( _data => {
147 this.parentListSelectData= _data; // data from server
148 let menuItems = this.parentListSelectData;
149 var heirarchicalMenuItems = [];
151 for ( var i=0; i<menuItems.length; i++){
152 for(var j=0; j<menuItems.length; j++){
153 if(menuItems[j][2]==menuItems[i][0])
156 menuId: menuItems[j][0],
157 label: menuItems[j][1]
161 if(children.length!=0){
162 heirarchicalMenuItems.push(
164 menuId: menuItems[i][0],
165 label: menuItems[i][1],
166 children: children.sort(this.sortItems("label"))
173 heirarchicalMenuItems.sort(this.sortItems("label"));
174 this.childListSelectData = heirarchicalMenuItems;
177 this.showSpinner = false;
183 return function(a, b) {
184 if (a[prop] > b[prop]) {
186 } else if (a[prop] < b[prop]) {
193 getParentLabel(parentId, parentListSelectData){
195 element = parentListSelectData[0];
196 for (var i=0; i<parentListSelectData.length; i++){
197 element = parentListSelectData[i];
198 if (element[0] == parentId)
205 this.showSpinner = true;
206 if( this.menu && this.menu.imageSrc == "" ) this.menu.imageSrc = "N/A";
207 if( this.menu && this.menu.target == "" ) this.menu.target = "N/A";
208 if( this.menu && this.menu.externalUrl == "" ) this.menu.externalUrl = "N/A";
209 if( this.menu && this.menu.queryString == "" ) this.menu.queryString = "N/A";
210 if( this.menu && this.menu.servlet == "" ) this.menu.servlet = "N/A";
212 let validationRule = /^\S{3,}$/;
213 let selectedFunction = this.menu.functionCd;
214 var selectedFunctionText = this.menu.functionCd; //selectedFunction.options[selectedFunction.selectedIndex].text;
216 if((this.menu.label == null || this.menu.label == "" || (this.menu.label && this.menu.label.trim().length == 0) ) ||
217 this.menu.parentId == null || this.menu.parentId == "" || this.menu.action == null || this.menu.action == "" ||
218 selectedFunctionText == null || selectedFunctionText == "" || this.menu.sortOrder == null || this.menu.sortOrder == "" ||
219 this.menu.menuSetCode == null ||this.menu.menuSetCode == ""){
221 this.openConfirmationModal('','Please provide all the mandatory (*) fields inputs !');
224 this.menu.parentId=parseFloat(this.menu.parentId);
225 let data ={availableFnMenuItem: this.menu};
226 let postData = JSON.stringify(data);
227 this.adminService.updateFnMenuItem(postData)
228 .subscribe( _data => {
230 this.passEntry.emit(this.result);
231 this.ngmodel.dismissAll();
233 this.showSpinner = false;
235 this.openConfirmationModal("Error",error);
237 this.getLeftMenuItems();
243 let sidebarComponent = new SidebarComponent(this.router, this.sidebarService,this.cookieService);
244 sidebarComponent.ngOnInit();
247 getFunctionCDselectData = function(){
248 this.adminService.getFunctionCdList()
249 .subscribe( _data => {
252 this.functionCDselectData = _data;
255 this.showSpinner = false;
257 this.openConfirmationModal("","Function Code Data not available !");
261 openConfirmationModal(_title: string, _message: string) {
262 const modalInfoRef = this.ngmodel.open(ConfirmationModalComponent);
263 modalInfoRef.componentInstance.title = _title;
264 modalInfoRef.componentInstance.message = _message;