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) {
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)
149 templateUrl: 'app/views/functionalMenu/functionalMenu-dialog/menu-details.modal.html',
150 controller: 'MenuDetailsModalCtrl',
151 controllerAs: 'functionalMenuDetails',
153 }).closePromise.then(needUpdate => {
154 if(needUpdate.value === true){
155 $log.debug('FunctionalMenuCtrl::openMenuDetailsModal: updating table data...');
156 if(source==="edit") {
165 $scope.createNewMenuItem = (selectedItem,source) => {
167 if(selectedItem != null && selectedItem.getLevel() >= 4){
168 confirmBoxService.showInformation('You are not allowed to have a menu item at a level greater than 4.').then(isConfirmed => {
175 let selectedMenuDetails = null;
176 functionalMenuService.getMenuDetails(selectedItem.menuId)
177 .then(function( resp ){
178 selectedMenuDetails = resp;
180 if((selectedItem.children===null || !selectedItem.children.length>0) &&
181 (!!selectedMenuDetails.url || !!selectedMenuDetails.appid || !!selectedMenuDetails.roles)){
182 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 => {
188 menuItem: {menu: _.clone(selectedItem)},
190 title: getDialogTitle(source)
195 templateUrl: 'app/views/functionalMenu/functionalMenu-dialog/menu-details.modal.html',
196 controller: 'MenuDetailsModalCtrl',
197 controllerAs: 'functionalMenuDetails',
199 }).closePromise.then(needUpdate => {
200 if(needUpdate.value === true){
201 $log.debug('FunctionalMenuCtrl::getMenuDetails: updating table data...');
203 //getOnboardingWidgets();
210 $scope.deleteMenuItem = (selectedItem,source) => {
211 $log.info('FunctionalMenuCtrl:deleteMenuItem:: delete selectedItem: ', selectedItem);
213 if(selectedItem.children!=null && selectedItem.children.length>0){
214 confirmBoxService.showInformation('You are not allowed to delete a menu item that has children. You can only delete leaf menu items.').then(isConfirmed => {
218 confirmBoxService.deleteItem(selectedItem.name).then(isConfirmed => {
220 $log.info('FunctionalMenuCtrl:deleteMenuItem:: Deleting Menu Item :: name: '+selectedItem.name+'; menuId: '+selectedItem.menuId);
221 $log.info('FunctionalMenuCtrl:deleteMenuItem:: selectedItem: ', selectedItem);
223 functionalMenuService.deleteMenuItem(selectedItem.menuId).then(() => {
224 //TODO:Have to splice menu item
225 //this.widgetsList.splice(this.widgetsList.indexOf(widget), 1);
226 $log.info('FunctionalMenuCtrl:deleteMenuItem:: Removed Menu Item :: '+selectedItem.name);
241 FunctionalMenuCtrl.$inject = ['$log', 'functionalMenuService','$scope', 'ngDialog', 'confirmBoxService'];
242 angular.module('ecompApp').controller('FunctionalMenuCtrl', FunctionalMenuCtrl);
244 angular.module('ecompApp').directive('jqTree', ['functionalMenuService','$log','confirmBoxService',function(functionalMenuService,$log,confirmBoxService){
246 templateUrl: 'jqtree-tmpl.html',
247 link: function(scope, el, attrs){
249 var $jqTree = el.find('#jqTree').tree({
250 data: scope.treedata,
253 onCreateLi: function(node, $li) {
254 $li.attr('id', node.id.replace(/\s+/g,'_'));
258 el.find('#jqTree').bind('tree.move', function(event){
259 event.preventDefault();
260 console.log('moved_node', event.move_info.moved_node);
261 console.log('target_node', event.move_info.target_node);
262 console.log('position', event.move_info.position);
263 console.log('previous_parent', event.move_info.previous_parent);
267 if(event.move_info.target_node != null &&
268 ((event.move_info.position === 'after' && event.move_info.target_node.getLevel() > 4) ||
269 (event.move_info.position === 'inside' && event.move_info.target_node.getLevel() > 3))){
270 confirmBoxService.showInformation('You are not allowed to have a menu item at a level greater than 4.').then(isConfirmed => {
276 var confMsg = 'Are you sure you want to move "'+event.move_info.moved_node.name+'" ?';
277 if ((event.move_info.position === "inside") && (event.move_info.target_node.url != "")) {
278 // If we are moving UNDER a node that has a url associated with it, warn the user
279 // that all the app information will be removed if they do this.
280 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.';
282 confirmBoxService.moveMenuItem(confMsg).then(isConfirmed => {
295 The menuId for the menu item being moved
296 The column it is being moved to
297 The parentMenuId for the parent it is being moved under
300 // The target_node is the node before the position we are
301 // moving to. If we are moving to a lower column number, or
302 // to a new parent, we must adjust the column to be after
304 var new_column = event.move_info.target_node.column;
305 var old_column = event.move_info.moved_node.column;
306 if ((event.move_info.moved_node.parentMenuId !=
307 event.move_info.target_node.parentMenuId) ||
308 (new_column < old_column)
312 var activeMenuItem = {
313 menuId:event.move_info.moved_node.menuId,
316 parentMenuId:event.move_info.target_node.parentMenuId,
321 // When position is "inside", this is a special case,
322 // where you are moving to the first column under
323 // a parent. The target_node is the parent node.
324 // So we need to set the column to 1, and the parentMenuId to the menuId of
326 if (event.move_info.position === "inside") {
327 console.log("special case: target_node is parent");
328 activeMenuItem.column = 1;
329 activeMenuItem.parentMenuId = event.move_info.target_node.menuId;
333 functionalMenuService.saveEditedMenuItem(activeMenuItem)
335 $log.debug(' Menu Item moved');
336 scope.reloadTreeStructure();
346 //event.move_info.do_move();
350 $jqTree.jqTreeContextMenu(el.find('ul.dropdown-menu'), {
351 "view": function (node) {scope.openMenuDetailsModal(node,'view'); },
352 "edit": function (node) {scope.openMenuDetailsModal(node,'edit'); },
353 "delete": function (node) { scope.deleteMenuItem(node,'delete') },
354 "add": function (node) { scope.createNewMenuItem(node,'add') }
357 scope.$watch('treedata', function(oldValue, newValue){
358 if(oldValue !== newValue){
359 console.log('FunctionalMenuCtrl:: Tree value has changed in some way');
360 $jqTree.tree('loadData', scope.treedata);
361 $jqTree.tree('reload', function() {
362 console.log('FunctionalMenuCtrl:: Tree is reloaded');