2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright (C) 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============================================
38 import { Component, OnInit } from '@angular/core';
39 import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
40 import { FunctionalMenuService } from 'src/app/shared/services';
41 import { ConfirmationModalComponent } from 'src/app/modals/confirmation-modal/confirmation-modal.component';
42 import { FunctionalMenuDialogComponent } from './functional-menu-dialog/functional-menu-dialog.component';
46 selector: 'app-functional-menu',
47 templateUrl: './functional-menu.component.html',
48 styleUrls: ['./functional-menu.component.scss']
50 export class FunctionalMenuComponent implements OnInit {
53 functionalMenu: any = [];
56 operationName: string;
58 constructor(public functionalMenuService : FunctionalMenuService, public ngbModal: NgbModal) { }
62 this.functionalMenu = [];
63 this.getFunctionalMenu();
68 * regenerateFunctionalMenuAncestors
70 regenerateFunctionalMenuAncestors(){
71 this.functionalMenuService.regenerateFunctionalMenuAncestors()
75 const modalRef = this.ngbModal.open(ConfirmationModalComponent);
76 modalRef.componentInstance.title = "";
77 modalRef.componentInstance.message = 'You have successfully regenerated the menu.';
78 modalRef.result.then((result) => { }, (resut) => {return;});
79 this.getFunctionalMenu();
83 const modalRef = this.ngbModal.open(ConfirmationModalComponent);
84 modalRef.componentInstance.title = "";
85 modalRef.componentInstance.message = 'There was an error while regenerating the menu.';
86 modalRef.result.then((result) => { }, (resut) => {return;});
95 this.functionalMenuService.getManagedFunctionalMenu()
99 for(let i = 0; i < this.result.length; i++){
100 this.result[i].children=[];
101 this.result[i].label= this.result[i].text;
102 this.result[i].id= this.result[i].text;
104 //Adding actual child items to children array in res objects
105 for(let i = 0; i < this.result.length; i++){
106 let parentId=this.result[i].menuId;
107 for(let j = 0; j < this.result.length; j++){
108 let childId=this.result[j].parentMenuId;
109 if(parentId===childId){
110 this.result[i].children.push(this.result[j]);
114 // Sort the top-level menu items in order based on the column
115 this.result.sort(function(a, b) {
116 return a.column-b.column;
119 // Sort all the children in order based on the column
120 for(let i = 0; i < this.result.length; i++){
121 this.result[i].children.sort(function(a, b){
122 return a.column-b.column;
126 //Forming actual parent items
127 for(let i = 0; i < this.result.length; i++){
128 let parentId= this.result[i].parentMenuId;
130 actualData.push( this.result[i]);
134 this.treedata = actualData;
135 //console.log("this.treedata :: ",this.treedata);
138 this.buildTree(this.treedata,this.ngbModal, this.self);
150 * @param treedataarray
153 buildTree(treedataarray,ngbModal: NgbModal , _self){
154 console.log("treedataarray>>>>",treedataarray);
156 (<any>$('#jqTree')).tree('loadData', treedataarray);
157 (<any>$('#jqTree')).tree({
161 onCreateLi: function(node, $li) {
162 ////console.log("node >>",node);
166 function(event:any) {
167 // The clicked node is 'event.node'
168 var node = event.node;
169 openMenuDetailsModal(node, "view");
173 var openMenuDetailsModal = function(node: any, actionName: string ){
174 const modalRef = ngbModal.open(FunctionalMenuDialogComponent, { size: 'lg' });
175 modalRef.componentInstance.title = 'Functional Menu ',actionName;
176 if(node != 'undefined' && node){
177 modalRef.componentInstance.nodedata = node;
178 modalRef.componentInstance.operationName = actionName;
180 modalRef.componentInstance.nodedata = {};
182 modalRef.componentInstance.passEntry.subscribe((receivedEntry: any) => {
183 //console.log("receivedEntry>>>>",receivedEntry);
184 ngbModal.dismissAll();
185 if(receivedEntry.httpStatusCode===200){
186 _self.getFunctionalMenu();