2 * ================================================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ================================================================================
22 class FunctionalMenuCtrl {
23 constructor($log, functionalMenuService, $scope,ngDialog, confirmBoxService,$modal) {
24 $log.info('FunctionalMenuCtrl init');
26 $scope.invokeDialog = () => {
27 // alert("click dialog");
30 this.regenerateFunctionalMenuAncestors = () => {
31 functionalMenuService.regenerateFunctionalMenuAncestors().then(res => {
32 $log.debug("FunctionalMenuCtrl:regenerateFunctionalMenuAncestors::returned from regenerateFunctionalMenuAncestors API call");
33 confirmBoxService.showInformation('You have successfully regenerated the menu.').then(isConfirmed => {
35 })['catch'](function (err) {
36 $log.error("FunctionalMenuCtrl:regenerateFunctionalMenuAncestors:: error: " + err);
37 confirmBoxService.showInformation('There was an error while regenerating the menu.').then(isConfirmed => {
42 let getFunctionalMenu = () => {
43 this.isLoadingTable = true;
44 functionalMenuService.getManagedFunctionalMenu().then(res => {
48 //Adding children and label attribute to all objects in res
49 for(let i = 0; i < res.length; i++){
51 res[i].label=res[i].text;
52 res[i].id=res[i].text;
55 //Adding actual child items to children array in res objects
56 for(let i = 0; i < res.length; i++){
58 let parentId=res[i].menuId;
59 for(let j = 0; j < res.length; j++){
60 let childId=res[j].parentMenuId;
61 if(parentId===childId){
62 res[i].children.push(res[j]);
68 // Sort the top-level menu items in order based on the column
69 res.sort(function(a, b) {
70 return a.column-b.column;
73 // Sort all the children in order based on the column
74 for(let i = 0; i < res.length; i++){
75 res[i].children.sort(function(a, b){
76 return a.column-b.column;
80 //Forming actual parent items
81 for(let i = 0; i < res.length; i++){
82 let parentId=res[i].parentMenuId;
84 actualData.push(res[i]);
88 $scope.treedata = actualData;
91 $log.error('FunctionalMenuCtrl:getFunctionalMenu:: error ',err);
93 this.isLoadingTable = false;
100 this.isLoadingTable = false;
101 this.functionalMenu = [];
103 this.searchString = '';
108 this.filterByDropdownValue = item => {
109 if(this.filterByApp.value === ''){
112 return item.appName === this.filterByApp.value;
115 let getDialogTitle = (source) => {
118 return "Functional Menu - Edit";
120 return "Functional Menu - View";
122 return "Functional Menu - Add";
124 return "Functional Menu";
128 $scope.reloadTreeStructure = (selectedItem,source) => {
131 $scope.openMenuDetailsModal = (selectedItem,source) => {
133 let selectedMenuDetails = null;
134 console.log('selectedItem: ', selectedItem);
136 functionalMenuService.getMenuDetails(selectedItem.menuId)
137 .then(function( resp ){
138 selectedMenuDetails = resp;
139 $log.info('FunctionalMenuCtrl::openMenuDetailsModal: getMenuDetails: ', resp );
143 menuItem: {menu: _.clone(selectedItem),menuDetails:_.clone(selectedMenuDetails)},
145 title: getDialogTitle(source)
148 var modalInstance = $modal.open({
149 templateUrl: 'app/views/functionalMenu/functionalMenu-dialog/menu-details.modal.html',
150 controller: 'MenuDetailsModalCtrl as functionalMenuDetails',
151 sizeClass: 'modal-large',
159 modalInstance.result.finally(function (needUpdate){
160 if(needUpdate.value === true){
161 $log.debug('FunctionalMenuCtrl::openMenuDetailsModal: updating table data...');
162 if(source==="edit") {
172 $scope.createNewMenuItem = (selectedItem,source) => {
174 if(selectedItem != null && selectedItem.getLevel() >= 4){
175 confirmBoxService.showInformation('You are not allowed to have a menu item at a level greater than 4.').then(isConfirmed => {
182 let selectedMenuDetails = null;
183 functionalMenuService.getMenuDetails(selectedItem.menuId)
184 .then(function( resp ){
185 selectedMenuDetails = resp;
187 if((selectedItem.children===null || !selectedItem.children.length>0) &&
188 (!!selectedMenuDetails.url || !!selectedMenuDetails.appid || !!selectedMenuDetails.roles)){
189 confirmBoxService.showInformation('Warning: the child menu item "' + selectedItem.name + '" is already configured with an application. You can create a new mid-level menu item, and move this item under it.').then(isConfirmed => {
195 menuItem: {menu: _.clone(selectedItem)},
197 title: getDialogTitle(source)
201 var modalInstance = $modal.open({
202 templateUrl: 'app/views/functionalMenu/functionalMenu-dialog/menu-details.modal.html',
203 controller: 'MenuDetailsModalCtrl as functionalMenuDetails',
204 sizeClass: 'modal-large',
212 modalInstance.result.finally(function (needUpdate){
213 if(needUpdate.value === true){
214 $log.debug('FunctionalMenuCtrl::getMenuDetails: updating table data...');
216 //getOnboardingWidgets();
224 $scope.deleteMenuItem = (selectedItem,source) => {
225 $log.info('FunctionalMenuCtrl:deleteMenuItem:: delete selectedItem: ', selectedItem);
227 if(selectedItem.children!=null && selectedItem.children.length>0){
228 confirmBoxService.showInformation('You are not allowed to delete a menu item that has children. You can only delete leaf menu items.').then(isConfirmed => {
232 confirmBoxService.deleteItem(selectedItem.name).then(isConfirmed => {
234 $log.info('FunctionalMenuCtrl:deleteMenuItem:: Deleting Menu Item :: name: '+selectedItem.name+'; menuId: '+selectedItem.menuId);
235 $log.info('FunctionalMenuCtrl:deleteMenuItem:: selectedItem: ', selectedItem);
237 functionalMenuService.deleteMenuItem(selectedItem.menuId).then(() => {
238 //TODO:Have to splice menu item
239 //this.widgetsList.splice(this.widgetsList.indexOf(widget), 1);
240 $log.info('FunctionalMenuCtrl:deleteMenuItem:: Removed Menu Item :: '+selectedItem.name);
255 FunctionalMenuCtrl.$inject = ['$log', 'functionalMenuService','$scope', 'ngDialog', 'confirmBoxService','$modal'];
256 angular.module('ecompApp').controller('FunctionalMenuCtrl', FunctionalMenuCtrl);
258 angular.module('ecompApp').directive('jqTree', ['functionalMenuService','$log','confirmBoxService',function(functionalMenuService,$log,confirmBoxService){
260 templateUrl: 'jqtree-tmpl.html',
261 link: function(scope, el, attrs){
263 var $jqTree = el.find('#jqTree').tree({
264 data: scope.treedata,
267 onCreateLi: function(node, $li) {
268 $li.attr('id', node.id.replace(/\s+/g,'_'));
272 el.find('#jqTree').bind('tree.move', function(event){
273 event.preventDefault();
274 console.log('moved_node', event.move_info.moved_node);
275 console.log('target_node', event.move_info.target_node);
276 console.log('position', event.move_info.position);
277 console.log('previous_parent', event.move_info.previous_parent);
281 if(event.move_info.target_node != null &&
282 ((event.move_info.position === 'after' && event.move_info.target_node.getLevel() > 4) ||
283 (event.move_info.position === 'inside' && event.move_info.target_node.getLevel() > 3))){
284 confirmBoxService.showInformation('You are not allowed to have a menu item at a level greater than 4.').then(isConfirmed => {
290 var confMsg = 'Are you sure you want to move "'+event.move_info.moved_node.name+'" ?';
291 if ((event.move_info.position === "inside") && (event.move_info.target_node.url != "")) {
292 // If we are moving UNDER a node that has a url associated with it, warn the user
293 // that all the app information will be removed if they do this.
294 confMsg = 'Warning: You are moving "'+event.move_info.moved_node.name+'" under "'+event.move_info.target_node.name+'", which has application information associated with it. This will cause all the application information from "'+event.move_info.target_node.name+'" to be deleted.';
296 confirmBoxService.moveMenuItem(confMsg).then(isConfirmed => {
309 The menuId for the menu item being moved
310 The column it is being moved to
311 The parentMenuId for the parent it is being moved under
314 // The target_node is the node before the position we are
315 // moving to. If we are moving to a lower column number, or
316 // to a new parent, we must adjust the column to be after
318 var new_column = event.move_info.target_node.column;
319 var old_column = event.move_info.moved_node.column;
320 if ((event.move_info.moved_node.parentMenuId !=
321 event.move_info.target_node.parentMenuId) ||
322 (new_column < old_column)
326 var activeMenuItem = {
327 menuId:event.move_info.moved_node.menuId,
330 parentMenuId:event.move_info.target_node.parentMenuId,
335 // When position is "inside", this is a special case,
336 // where you are moving to the first column under
337 // a parent. The target_node is the parent node.
338 // So we need to set the column to 1, and the parentMenuId to the menuId of
340 if (event.move_info.position === "inside") {
341 console.log("special case: target_node is parent");
342 activeMenuItem.column = 1;
343 activeMenuItem.parentMenuId = event.move_info.target_node.menuId;
347 functionalMenuService.saveEditedMenuItem(activeMenuItem)
349 $log.debug(' Menu Item moved');
350 scope.reloadTreeStructure();
360 //event.move_info.do_move();
364 $jqTree.jqTreeContextMenu(el.find('ul.dropdown-menu'), {
365 "view": function (node) {scope.openMenuDetailsModal(node,'view'); },
366 "edit": function (node) {scope.openMenuDetailsModal(node,'edit'); },
367 "delete": function (node) { scope.deleteMenuItem(node,'delete') },
368 "add": function (node) { scope.createNewMenuItem(node,'add') }
371 scope.$watch('treedata', function(oldValue, newValue){
372 if(oldValue !== newValue){
373 console.log('FunctionalMenuCtrl:: Tree value has changed in some way');
374 $jqTree.tree('loadData', scope.treedata);
375 $jqTree.tree('reload', function() {
376 console.log('FunctionalMenuCtrl:: Tree is reloaded');