--- /dev/null
+/*-\r
+ * ================================================================================\r
+ * ECOMP Portal\r
+ * ================================================================================\r
+ * Copyright (C) 2017 AT&T Intellectual Property\r
+ * ================================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ================================================================================\r
+ */\r
+'use strict';\r
+(function () {\r
+ class FunctionalMenuCtrl {\r
+ constructor($log, functionalMenuService, $scope,ngDialog, confirmBoxService) {\r
+ $log.info('FunctionalMenuCtrl init');\r
+\r
+ $scope.invokeDialog = () => {\r
+ // alert("click dialog");\r
+ };\r
+\r
+ this.regenerateFunctionalMenuAncestors = () => {\r
+ functionalMenuService.regenerateFunctionalMenuAncestors().then(res => {\r
+ $log.debug("FunctionalMenuCtrl:regenerateFunctionalMenuAncestors::returned from regenerateFunctionalMenuAncestors API call");\r
+ confirmBoxService.showInformation('You have successfully regenerated the menu.').then(isConfirmed => {\r
+ });\r
+ })['catch'](function (err) {\r
+ $log.error("FunctionalMenuCtrl:regenerateFunctionalMenuAncestors:: error: " + err);\r
+ confirmBoxService.showInformation('There was an error while regenerating the menu.').then(isConfirmed => {\r
+ });\r
+ });\r
+ };\r
+\r
+ let getFunctionalMenu = () => {\r
+ this.isLoadingTable = true;\r
+ functionalMenuService.getManagedFunctionalMenu().then(res => {\r
+\r
+ let actualData=[];\r
+\r
+ //Adding children and label attribute to all objects in res\r
+ for(let i = 0; i < res.length; i++){\r
+ res[i].children=[];\r
+ res[i].label=res[i].text;\r
+ res[i].id=res[i].text;\r
+\r
+ }\r
+ //Adding actual child items to children array in res objects\r
+ for(let i = 0; i < res.length; i++){\r
+\r
+ let parentId=res[i].menuId;\r
+ for(let j = 0; j < res.length; j++){\r
+ let childId=res[j].parentMenuId;\r
+ if(parentId===childId){\r
+ res[i].children.push(res[j]);\r
+\r
+ }\r
+ }\r
+ }\r
+\r
+ // Sort the top-level menu items in order based on the column\r
+ res.sort(function(a, b) {\r
+ return a.column-b.column;\r
+ });\r
+\r
+ // Sort all the children in order based on the column\r
+ for(let i = 0; i < res.length; i++){\r
+ res[i].children.sort(function(a, b){\r
+ return a.column-b.column;\r
+ });\r
+ }\r
+\r
+ //Forming actual parent items\r
+ for(let i = 0; i < res.length; i++){\r
+ let parentId=res[i].parentMenuId;\r
+ if(parentId===null){\r
+ actualData.push(res[i]);\r
+ }\r
+ }\r
+\r
+ $scope.treedata = actualData;\r
+\r
+ }).catch(err => {\r
+ $log.error('FunctionalMenuCtrl:getFunctionalMenu:: error ',err);\r
+ }).finally(()=> {\r
+ this.isLoadingTable = false;\r
+ });\r
+\r
+ };\r
+\r
+\r
+ let init = () => {\r
+ this.isLoadingTable = false;\r
+ this.functionalMenu = [];\r
+ getFunctionalMenu();\r
+ this.searchString = '';\r
+\r
+\r
+ };\r
+\r
+ this.filterByDropdownValue = item => {\r
+ if(this.filterByApp.value === ''){\r
+ return true;\r
+ }\r
+ return item.appName === this.filterByApp.value;\r
+ };\r
+\r
+ let getDialogTitle = (source) => {\r
+ switch (source) {\r
+ case 'edit':\r
+ return "Functional Menu - Edit";\r
+ case 'view':\r
+ return "Functional Menu - View";\r
+ case 'add':\r
+ return "Functional Menu - Add";\r
+ default:\r
+ return "Functional Menu";\r
+ };\r
+ };\r
+\r
+ $scope.reloadTreeStructure = (selectedItem,source) => {\r
+ getFunctionalMenu();\r
+ };\r
+ $scope.openMenuDetailsModal = (selectedItem,source) => {\r
+ let data = null;\r
+ let selectedMenuDetails = null;\r
+ console.log('selectedItem: ', selectedItem);\r
+\r
+ functionalMenuService.getMenuDetails(selectedItem.menuId)\r
+ .then(function( resp ){\r
+ selectedMenuDetails = resp;\r
+ $log.info('FunctionalMenuCtrl::openMenuDetailsModal: getMenuDetails: ', resp );\r
+\r
+ if(selectedItem){\r
+ data = {\r
+ menuItem: {menu: _.clone(selectedItem),menuDetails:_.clone(selectedMenuDetails)},\r
+ source: source,\r
+ title: getDialogTitle(source)\r
+ };\r
+ }\r
+ ngDialog.open({\r
+ templateUrl: 'app/views/functionalMenu/functionalMenu-dialog/menu-details.modal.html',\r
+ controller: 'MenuDetailsModalCtrl',\r
+ controllerAs: 'functionalMenuDetails',\r
+ data: data\r
+ }).closePromise.then(needUpdate => {\r
+ if(needUpdate.value === true){\r
+ $log.debug('FunctionalMenuCtrl::openMenuDetailsModal: updating table data...');\r
+ if(source==="edit") {\r
+ init();\r
+ }\r
+ }\r
+ });\r
+ });\r
+ };\r
+\r
+\r
+ $scope.createNewMenuItem = (selectedItem,source) => {\r
+\r
+ if(selectedItem != null && selectedItem.getLevel() >= 4){\r
+ confirmBoxService.showInformation('You are not allowed to have a menu item at a level greater than 4.').then(isConfirmed => {\r
+\r
+ });\r
+ return ;\r
+ }\r
+\r
+ let data = null;\r
+ let selectedMenuDetails = null;\r
+ functionalMenuService.getMenuDetails(selectedItem.menuId)\r
+ .then(function( resp ){\r
+ selectedMenuDetails = resp;\r
+\r
+ if((selectedItem.children===null || !selectedItem.children.length>0) &&\r
+ (!!selectedMenuDetails.url || !!selectedMenuDetails.appid || !!selectedMenuDetails.roles)){\r
+ 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 => {\r
+ return;\r
+ });\r
+ }else{\r
+ if(selectedItem){\r
+ data = {\r
+ menuItem: {menu: _.clone(selectedItem)},\r
+ source:source,\r
+ title: getDialogTitle(source)\r
+ };\r
+ }\r
+\r
+ ngDialog.open({\r
+ templateUrl: 'app/views/functionalMenu/functionalMenu-dialog/menu-details.modal.html',\r
+ controller: 'MenuDetailsModalCtrl',\r
+ controllerAs: 'functionalMenuDetails',\r
+ data: data\r
+ }).closePromise.then(needUpdate => {\r
+ if(needUpdate.value === true){\r
+ $log.debug('FunctionalMenuCtrl::getMenuDetails: updating table data...');\r
+ init();\r
+ //getOnboardingWidgets();\r
+ }\r
+ });\r
+ }\r
+ });\r
+ };\r
+\r
+ $scope.deleteMenuItem = (selectedItem,source) => {\r
+ $log.info('FunctionalMenuCtrl:deleteMenuItem:: delete selectedItem: ', selectedItem);\r
+\r
+ if(selectedItem.children!=null && selectedItem.children.length>0){\r
+ confirmBoxService.showInformation('You are not allowed to delete a menu item that has children. You can only delete leaf menu items.').then(isConfirmed => {\r
+\r
+ });\r
+ }else{\r
+ confirmBoxService.deleteItem(selectedItem.name).then(isConfirmed => {\r
+ if(isConfirmed){\r
+ $log.info('FunctionalMenuCtrl:deleteMenuItem:: Deleting Menu Item :: name: '+selectedItem.name+'; menuId: '+selectedItem.menuId);\r
+ $log.info('FunctionalMenuCtrl:deleteMenuItem:: selectedItem: ', selectedItem);\r
+\r
+ functionalMenuService.deleteMenuItem(selectedItem.menuId).then(() => {\r
+ //TODO:Have to splice menu item\r
+ //this.widgetsList.splice(this.widgetsList.indexOf(widget), 1);\r
+ $log.info('FunctionalMenuCtrl:deleteMenuItem:: Removed Menu Item :: '+selectedItem.name);\r
+ init();\r
+ }).catch(err => {\r
+ $log.error(err);\r
+ });\r
+ }\r
+ }).catch(err => {\r
+ $log.error(err);\r
+ });\r
+ }\r
+ };\r
+\r
+ init();\r
+ }\r
+ }\r
+ FunctionalMenuCtrl.$inject = ['$log', 'functionalMenuService','$scope', 'ngDialog', 'confirmBoxService'];\r
+ angular.module('ecompApp').controller('FunctionalMenuCtrl', FunctionalMenuCtrl);\r
+\r
+ angular.module('ecompApp').directive('jqTree', ['functionalMenuService','$log','confirmBoxService',function(functionalMenuService,$log,confirmBoxService){\r
+ return {\r
+ templateUrl: 'jqtree-tmpl.html',\r
+ link: function(scope, el, attrs){\r
+\r
+ var $jqTree = el.find('#jqTree').tree({\r
+ data: scope.treedata,\r
+ autoOpen: false,\r
+ dragAndDrop: true,\r
+ onCreateLi: function(node, $li) {\r
+ $li.attr('id', node.id.replace(/\s+/g,'_'));\r
+ }\r
+ });\r
+\r
+ el.find('#jqTree').bind('tree.move', function(event){\r
+ event.preventDefault();\r
+ console.log('moved_node', event.move_info.moved_node);\r
+ console.log('target_node', event.move_info.target_node);\r
+ console.log('position', event.move_info.position);\r
+ console.log('previous_parent', event.move_info.previous_parent);\r
+\r
+\r
+\r
+ if(event.move_info.target_node != null &&\r
+ ((event.move_info.position === 'after' && event.move_info.target_node.getLevel() > 4) ||\r
+ (event.move_info.position === 'inside' && event.move_info.target_node.getLevel() > 3))){\r
+ confirmBoxService.showInformation('You are not allowed to have a menu item at a level greater than 4.').then(isConfirmed => {\r
+\r
+ });\r
+ return ;\r
+ }\r
+\r
+ var confMsg = 'Are you sure you want to move "'+event.move_info.moved_node.name+'" ?';\r
+ if ((event.move_info.position === "inside") && (event.move_info.target_node.url != "")) {\r
+ // If we are moving UNDER a node that has a url associated with it, warn the user\r
+ // that all the app information will be removed if they do this.\r
+ 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.';\r
+ }\r
+ confirmBoxService.moveMenuItem(confMsg).then(isConfirmed => {\r
+ if(isConfirmed){\r
+ /*\r
+ {\r
+ "menuId": 129,\r
+ "column": 3,\r
+ "text": "",\r
+ "parentMenuId": 37,\r
+ "url": "",\r
+ "appid": null,\r
+ "roles": null\r
+ }\r
+\r
+ The menuId for the menu item being moved\r
+ The column it is being moved to\r
+ The parentMenuId for the parent it is being moved under\r
+ */\r
+\r
+ // The target_node is the node before the position we are\r
+ // moving to. If we are moving to a lower column number, or\r
+ // to a new parent, we must adjust the column to be after\r
+ // the target_node.\r
+ var new_column = event.move_info.target_node.column;\r
+ var old_column = event.move_info.moved_node.column;\r
+ if ((event.move_info.moved_node.parentMenuId !=\r
+ event.move_info.target_node.parentMenuId) ||\r
+ (new_column < old_column)\r
+ ) {\r
+ new_column += 1;\r
+ }\r
+ var activeMenuItem = {\r
+ menuId:event.move_info.moved_node.menuId,\r
+ column:new_column,\r
+ text:"",\r
+ parentMenuId:event.move_info.target_node.parentMenuId,\r
+ url:"",\r
+ appid: null,\r
+ roles:null\r
+ };\r
+ // When position is "inside", this is a special case,\r
+ // where you are moving to the first column under\r
+ // a parent. The target_node is the parent node.\r
+ // So we need to set the column to 1, and the parentMenuId to the menuId of\r
+ // the target move.\r
+ if (event.move_info.position === "inside") {\r
+ console.log("special case: target_node is parent");\r
+ activeMenuItem.column = 1;\r
+ activeMenuItem.parentMenuId = event.move_info.target_node.menuId;\r
+ }\r
+\r
+\r
+ functionalMenuService.saveEditedMenuItem(activeMenuItem)\r
+ .then(() => {\r
+ $log.debug(' Menu Item moved');\r
+ scope.reloadTreeStructure();\r
+ }).catch(err => {\r
+ $log.error(err);\r
+ }).finally(()=>{\r
+ });\r
+ }\r
+ }).catch(err => {\r
+ $log.error(err);\r
+ });\r
+\r
+ //event.move_info.do_move();\r
+ });\r
+\r
+\r
+ $jqTree.jqTreeContextMenu(el.find('ul.dropdown-menu'), {\r
+ "view": function (node) {scope.openMenuDetailsModal(node,'view'); },\r
+ "edit": function (node) {scope.openMenuDetailsModal(node,'edit'); },\r
+ "delete": function (node) { scope.deleteMenuItem(node,'delete') },\r
+ "add": function (node) { scope.createNewMenuItem(node,'add') }\r
+ });\r
+\r
+ scope.$watch('treedata', function(oldValue, newValue){\r
+ if(oldValue !== newValue){\r
+ console.log('FunctionalMenuCtrl:: Tree value has changed in some way');\r
+ $jqTree.tree('loadData', scope.treedata);\r
+ $jqTree.tree('reload', function() {\r
+ console.log('FunctionalMenuCtrl:: Tree is reloaded');\r
+ });\r
+ }\r
+ });\r
+ }\r
+ };\r
+ }]);\r
+\r
+})();\r
+\r
+\r