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 for(let i = 0; i < res.length; i++){
50 res[i].label=res[i].text;
51 res[i].id=res[i].text;
55 for(let i = 0; i < res.length; i++){
57 let parentId=res[i].menuId;
58 for(let j = 0; j < res.length; j++){
59 let childId=res[j].parentMenuId;
60 if(parentId==childId){
61 res[i].children.push(res[j]);
67 res.sort(function(a, b) {
68 return a.column-b.column;
71 for(let i = 0; i < res.length; i++){
72 res[i].children.sort(function(a, b){
73 return a.column-b.column;
77 for(let i = 0; i < res.length; i++){
78 let parentId=res[i].parentMenuId;
80 actualData.push(res[i]);
84 $scope.treedata = actualData;
87 $log.error('FunctionalMenuCtrl:getFunctionalMenu:: error ',err);
89 this.isLoadingTable = false;
96 this.isLoadingTable = false;
97 this.functionalMenu = [];
99 this.searchString = '';
102 this.filterByDropdownValue = item => {
103 if(this.filterByApp.value === ''){
106 return item.appName === this.filterByApp.value;
109 let getDialogTitle = (source) => {
112 return "Functional Menu - Edit";
114 return "Functional Menu - View";
116 return "Functional Menu - Add";
118 return "Functional Menu";
122 $scope.reloadTreeStructure = (selectedItem,source) => {
125 $scope.openMenuDetailsModal = (selectedItem,source) => {
127 let selectedMenuDetails = null;
128 console.log('selectedItem: ', selectedItem);
130 functionalMenuService.getMenuDetails(selectedItem.menuId)
131 .then(function( resp ){
132 selectedMenuDetails = resp;
133 $log.info('FunctionalMenuCtrl::openMenuDetailsModal: getMenuDetails: ', resp );
137 menuItem: {menu: _.clone(selectedItem),menuDetails:_.clone(selectedMenuDetails)},
139 title: getDialogTitle(source)
143 templateUrl: 'app/views/functionalMenu/functionalMenu-dialog/menu-details.modal.html',
144 controller: 'MenuDetailsModalCtrl',
145 controllerAs: 'functionalMenuDetails',
147 }).closePromise.then(needUpdate => {
148 if(needUpdate.value === true){
149 $log.debug('FunctionalMenuCtrl::openMenuDetailsModal: updating table data...');
158 $scope.createNewMenuItem = (selectedItem,source) => {
160 if(selectedItem != null && selectedItem.getLevel() >= 4){
161 confirmBoxService.showInformation('You are not allowed to have a menu item at a level greater than 4.').then(isConfirmed => {
168 let selectedMenuDetails = null;
169 functionalMenuService.getMenuDetails(selectedItem.menuId)
170 .then(function( resp ){
171 selectedMenuDetails = resp;
173 if((selectedItem.children==null || !selectedItem.children.length>0) &&
174 (!!selectedMenuDetails.url || !!selectedMenuDetails.appid || !!selectedMenuDetails.roles)){
175 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 => {
181 menuItem: {menu: _.clone(selectedItem)},
183 title: getDialogTitle(source)
188 templateUrl: 'app/views/functionalMenu/functionalMenu-dialog/menu-details.modal.html',
189 controller: 'MenuDetailsModalCtrl',
190 controllerAs: 'functionalMenuDetails',
192 }).closePromise.then(needUpdate => {
193 if(needUpdate.value === true){
194 $log.debug('FunctionalMenuCtrl::getMenuDetails: updating table data...');
202 $scope.deleteMenuItem = (selectedItem,source) => {
203 $log.info('FunctionalMenuCtrl:deleteMenuItem:: delete selectedItem: ', selectedItem);
205 if(selectedItem.children!=null && selectedItem.children.length>0){
206 confirmBoxService.showInformation('You are not allowed to delete a menu item that has children. You can only delete leaf menu items.').then(isConfirmed => {
210 confirmBoxService.deleteItem(selectedItem.name).then(isConfirmed => {
212 $log.info('FunctionalMenuCtrl:deleteMenuItem:: Deleting Menu Item :: name: '+selectedItem.name+'; menuId: '+selectedItem.menuId);
213 $log.info('FunctionalMenuCtrl:deleteMenuItem:: selectedItem: ', selectedItem);
215 functionalMenuService.deleteMenuItem(selectedItem.menuId).then(() => {
216 $log.info('FunctionalMenuCtrl:deleteMenuItem:: Removed Menu Item :: '+selectedItem.name);
231 FunctionalMenuCtrl.$inject = ['$log', 'functionalMenuService','$scope', 'ngDialog', 'confirmBoxService'];
232 angular.module('ecompApp').controller('FunctionalMenuCtrl', FunctionalMenuCtrl);
234 angular.module('ecompApp').directive('jqTree', ['functionalMenuService','$log','confirmBoxService',function(functionalMenuService,$log,confirmBoxService){
236 templateUrl: 'jqtree-tmpl.html',
237 link: function(scope, el, attrs){
239 var $jqTree = el.find('#jqTree').tree({
240 data: scope.treedata,
243 onCreateLi: function(node, $li) {
244 $li.attr('id', node.id.replace(/\s+/g,"_"));
248 el.find('#jqTree').bind('tree.move', function(event){
249 event.preventDefault();
250 console.log('moved_node', event.move_info.moved_node);
251 console.log('target_node', event.move_info.target_node);
252 console.log('position', event.move_info.position);
253 console.log('previous_parent', event.move_info.previous_parent);
257 if(event.move_info.target_node != null &&
258 ((event.move_info.position == 'after' && event.move_info.target_node.getLevel() > 4) ||
259 (event.move_info.position == 'inside' && event.move_info.target_node.getLevel() > 3))){
260 confirmBoxService.showInformation('You are not allowed to have a menu item at a level greater than 4.').then(isConfirmed => {
266 var confMsg = 'Are you sure you want to move "'+event.move_info.moved_node.name+'" ?';
267 if ((event.move_info.position == "inside") && (event.move_info.target_node.url != "")) {
268 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.';
270 confirmBoxService.moveMenuItem(confMsg).then(isConfirmed => {
272 var new_column = event.move_info.target_node.column;
273 var old_column = event.move_info.moved_node.column;
274 if ((event.move_info.moved_node.parentMenuId !=
275 event.move_info.target_node.parentMenuId) ||
276 (new_column < old_column)
280 var activeMenuItem = {
281 menuId:event.move_info.moved_node.menuId,
284 parentMenuId:event.move_info.target_node.parentMenuId,
290 if (event.move_info.position == "inside") {
291 console.log("special case: target_node is parent");
292 activeMenuItem.column = 1;
293 activeMenuItem.parentMenuId = event.move_info.target_node.menuId;
296 functionalMenuService.saveEditedMenuItem(activeMenuItem)
298 $log.debug(' Menu Item moved');
299 scope.reloadTreeStructure();
311 $jqTree.jqTreeContextMenu(el.find('ul.dropdown-menu'), {
312 "view": function (node) {scope.openMenuDetailsModal(node,'view'); },
313 "edit": function (node) {scope.openMenuDetailsModal(node,'edit'); },
314 "delete": function (node) { scope.deleteMenuItem(node,'delete') },
315 "add": function (node) { scope.createNewMenuItem(node,'add') }
318 scope.$watch('treedata', function(oldValue, newValue){
319 if(oldValue !== newValue){
320 console.log('FunctionalMenuCtrl:: Tree value has changed in some way');
321 $jqTree.tree('loadData', scope.treedata);
322 $jqTree.tree('reload', function() {
323 console.log('FunctionalMenuCtrl:: Tree is reloaded');