From dda032f8bb161d54eb1f59de2b4a3efb774fc4d1 Mon Sep 17 00:00:00 2001 From: "ITSERVICES\\rb7147" Date: Mon, 8 May 2017 22:20:44 -0400 Subject: Policy 1707 Second commit Change-Id: I18f5b142238733d17280cf17c3d1dd28204d34e9 Signed-off-by: ITSERVICES\rb7147 --- .../Editor/js/controllers/policyManager.js | 60 +----- .../Editor/js/controllers/policySearchManager.js | 204 +++++++++++++++++++++ .../policy-models/Editor/js/entities/item.js | 7 +- .../policy-models/Editor/js/providers/config.js | 1 + .../Editor/js/services/policynavigator.js | 72 +++++--- 5 files changed, 260 insertions(+), 84 deletions(-) create mode 100644 POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/js/controllers/policySearchManager.js (limited to 'POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/js') diff --git a/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/js/controllers/policyManager.js b/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/js/controllers/policyManager.js index 869d26ba3..d471f2763 100644 --- a/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/js/controllers/policyManager.js +++ b/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/js/controllers/policyManager.js @@ -208,55 +208,12 @@ app.controller('PolicyManagerController', [ } }); }; - - $scope.search = function(search){ - var deferred = $q.defer(); - var uuu = "searchPolicy"; - var postData = {searchdata : search}; - $.ajax({ - type : 'POST', - url : uuu, - dataType: 'json', - contentType: 'application/json', - data: JSON.stringify(postData), - success : function(data){ - $scope.$apply(function(){ - $scope.searchdata=data.result;}); - if($scope.searchdata[0].error != undefined){ - Notification.info($scope.searchdata[0].error); - }else{ - var j = data; - $scope.data = JSON.stringify(data.result); - $scope.searchDatas = JSON.parse($scope.data); - var searchString = "Policies List" + "
"; - var i; - for(i = 0 ; i < $scope.searchDatas.length; i++){ - searchString += $scope.searchDatas[i].name + ".xml" + "
"; - } - var myWindow = window.open("", "MsgWindow", "width=500,height=500"); - myWindow.document.write("

Search List

"); - myWindow.document.write("

"+searchString+"

"); - } - }, - error : function(data){ - alert("Error while Searching."); - } - }); - }; - - - /* $scope.describePolicy = function(item){ - item.describePolicy().then(function(){ - $scope.modal('describePolicy', true); - }); - }; - - $scope.exportPolicy = function(item){ - item.exportPolicy().then(function(){ - $scope.modal('exportPolicy', true); - }); - };*/ + + $scope.refresh = function(){ + $scope.policyNavigator.refresh(); + }; + $scope.switchVersion = function(item){ if ($scope.policyNavigator.fileNameExists(item.tempModel.content.activeVersion)) { item.error = 'Invalid filename or already exists, specify another name'; @@ -268,13 +225,6 @@ app.controller('PolicyManagerController', [ }); }; - - /* $scope.viewPolicy = function(item){ - item.viewPolicy().then(function(){ - $scope.modal('createNewPolicy', true); - }); - };*/ - $scope.copy = function(item) { var samePath = item.tempModel.path.join() === item.model.path.join(); if (samePath && $scope.policyNavigator.fileNameExists(item.tempModel.name)) { diff --git a/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/js/controllers/policySearchManager.js b/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/js/controllers/policySearchManager.js new file mode 100644 index 000000000..83c3820a6 --- /dev/null +++ b/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/js/controllers/policySearchManager.js @@ -0,0 +1,204 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +app.controller('PolicySearchController', [ + '$scope', '$q', '$window', '$cookies', 'policyManagerConfig', 'item', 'policyNavigator', 'policyUploader', 'Notification','PolicyAppService', + function($scope, $q, $Window, $cookies, policyManagerConfig, Item, PolicyNavigator, PolicyUploader, Notification, PolicyAppService ) { + + $scope.isDisabled = true; + $scope.superAdminId = false; + $scope.exportPolicyId = false; + $scope.importPolicyId = false; + $scope.createScopeId = false; + $scope.deleteScopeId = false; + $scope.renameId = false; + $scope.createPolicyId = false; + $scope.cloneId = false; + $scope.editPolicyId = false; + $scope.switchVersionId = false; + $scope.describePolicyId = false; + $scope.viewPolicyId = false; + $scope.deletePolicyId = false; + PolicyAppService.getData('get_LockDownData').then(function(data){ + var j = data; + $scope.data = JSON.parse(j.data); + $scope.lockdowndata = JSON.parse($scope.data.lockdowndata); + if($scope.lockdowndata[0].lockdown == true){ + $scope.isDisabled = true; + }else{ + $scope.isDisabled = false; + } + console.log($scope.data); + },function(error){ + console.log("failed"); + }); + + PolicyAppService.getData('getDictionary/get_DescriptiveScopeByName').then(function(data){ + var j = data; + $scope.data = JSON.parse(j.data); + console.log($scope.data); + $scope.descriptiveScopeDictionaryDatas = JSON.parse($scope.data.descriptiveScopeDictionaryDatas); + }, function (error) { + console.log("failed"); + }); + + PolicyAppService.getData('getDictionary/get_EcompNameDataByName').then(function(data){ + var j = data; + $scope.data = JSON.parse(j.data); + console.log($scope.data); + $scope.ecompNameDictionaryDatas = JSON.parse($scope.data.ecompNameDictionaryDatas); + }, function (error) { + console.log("failed"); + }); + + PolicyAppService.getData('getDictionary/get_VSCLActionDataByName').then(function(data){ + var j = data; + $scope.data = JSON.parse(j.data); + console.log($scope.data); + $scope.vsclActionDictionaryDatas = JSON.parse($scope.data.vsclActionDictionaryDatas); + }, function (error) { + console.log("failed"); + }); + + PolicyAppService.getData('getDictionary/get_VNFTypeDataByName').then(function(data){ + var j = data; + $scope.data = JSON.parse(j.data); + console.log($scope.data); + $scope.vnfTypeDictionaryDatas = JSON.parse($scope.data.vnfTypeDictionaryDatas); + }, function (error) { + console.log("failed"); + }); + + + PolicyAppService.getData('get_UserRolesData').then(function (data) { + var j = data; + $scope.data = JSON.parse(j.data); + console.log($scope.data); + $scope.userRolesDatas = JSON.parse($scope.data.userRolesDatas); + console.log($scope.userRolesDatas); + if($scope.userRolesDatas[0] == 'super-admin'){ + $scope.superAdminId = true; + $scope.createPolicyId = true; + $scope.editPolicyId = true; + $scope.describePolicyId = true; + $scope.viewPolicyId = true; + }else if($scope.userRolesDatas[0] == 'super-editor' || $scope.userRolesDatas[0] == 'editor' || $scope.userRolesDatas[0] == 'admin'){ + $scope.editPolicyId = true; + $scope.createPolicyId = true; + $scope.describePolicyId = true; + $scope.viewPolicyId = true; + }else if($scope.userRolesDatas[0] == 'super-guest' || $scope.userRolesDatas[0] == 'guest'){ + $scope.describePolicyId = true; + $scope.viewPolicyId = true; + } + }, function (error) { + console.log("failed"); + }); + + $scope.config = policyManagerConfig; + $scope.reverse = false; + $scope.predicate = ['model.type', 'model.name']; + $scope.order = function(predicate) { + $scope.reverse = ($scope.predicate[1] === predicate) ? !$scope.reverse : false; + $scope.predicate[1] = predicate; + }; + + $scope.query = ''; + $scope.temp = new Item(); + $scope.policyNavigator = new PolicyNavigator(); + + $scope.setTemplate = function(name) { + $scope.viewTemplate = $cookies.viewTemplate = name; + }; + + $scope.touch = function(item) { + item = item instanceof Item ? item : new Item(); + item.revert(); + $scope.temp = item; + }; + + $scope.smartClick = function(item) { + if (item.isFolder()) { + return $scope.policyNavigator.folderClick(item); + } + if (item.isEditable()) { + return $scope.openEditItem(item); + } + }; + + $scope.openEditItem = function(item) { + item.getContent(); + $scope.modal('createNewPolicy'); + return $scope.touch(item); + }; + + $scope.modal = function(id, hide) { + return $('#' + id).modal(hide ? 'hide' : 'show'); + }; + + $scope.isInThisPath = function(path) { + var currentPath = $scope.policyNavigator.currentPath.join('/'); + return currentPath.indexOf(path) !== -1; + }; + + $scope.searchPolicy = function(searchContent){ + var deferred = $q.defer(); + var uuu = "searchPolicy"; + var postData = {searchdata : searchContent}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){ + var searchdata = data.result; + if(searchdata.length > 0){ + $scope.policyNavigator.searchrefresh(searchdata); + }else{ + Notification.info("No Matches Found with your Search"); + } + }); + }, + error : function(data){ + alert("Error while Searching."); + } + }); + }; + + $scope.refresh = function(searchData){ + $scope.policyNavigator.searchrefresh(null); + }; + + $scope.getQueryParam = function(param) { + var found; + window.location.search.substr(1).split('&').forEach(function(item) { + if (param === item.split('=')[0]) { + found = item.split('=')[1]; + return false; + } + }); + return found; + }; + + $scope.isWindows = $scope.getQueryParam('server') === 'Windows'; + $scope.policyNavigator.searchrefresh(null); + $scope.policyNavigator.setSearchModalActiveStatus(); + }]); diff --git a/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/js/entities/item.js b/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/js/entities/item.js index 2b1fd3469..21762ce77 100644 --- a/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/js/entities/item.js +++ b/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/js/entities/item.js @@ -170,7 +170,7 @@ angular.module('abs').factory('item', ['$http', '$q', 'policyManagerConfig', fun }; - Item.prototype.getContent = function() { + Item.prototype.getContent = function(policyNavigator) { var self = this; var deferred = $q.defer(); var data = {params: { @@ -185,6 +185,7 @@ angular.module('abs').factory('item', ['$http', '$q', 'policyManagerConfig', fun var json = data.result; var policy = JSON.parse(json); self.policy = policy; + self.itemContent = policyNavigator; console.log(policy); self.deferredHandler(data, deferred); }).error(function(data) { @@ -339,9 +340,5 @@ angular.module('abs').factory('item', ['$http', '$q', 'policyManagerConfig', fun return !this.isFolder() && policyManagerConfig.isEditableFilePattern.test(this.model.name); }; - /*Item.prototype.isImage = function() { - return policyManagerConfig.isImageFilePattern.test(this.model.name); - };*/ - return Item; }]); diff --git a/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/js/providers/config.js b/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/js/providers/config.js index 72fd84d53..6afabe136 100644 --- a/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/js/providers/config.js +++ b/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/js/providers/config.js @@ -42,6 +42,7 @@ addSubScopeUrl : 'fm/addSubScopeUrl', switchVersionUrl : 'fm/switchVersionUrl', exportUrl : 'fm/exportUrl', + searchListUrl : 'fm/searchListUrl', sidebar: true, breadcrumb: true, diff --git a/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/js/services/policynavigator.js b/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/js/services/policynavigator.js index bb76dd9d5..1435afe8a 100644 --- a/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/js/services/policynavigator.js +++ b/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/js/services/policynavigator.js @@ -30,8 +30,13 @@ this.currentPath = []; this.history = []; this.error = ''; + this.searchModalActive = false; }; + PolicyNavigator.prototype.setSearchModalActiveStatus = function(){ + this.searchModalActive = true; + }; + PolicyNavigator.prototype.deferredHandler = function(data, deferred, defaultMsg) { if (!data || typeof data !== 'object') { this.error = 'Bridge response error, please check the docs'; @@ -99,29 +104,49 @@ PolicyNavigator.prototype.refresh = function() { var self = this; var path = self.currentPath.join('/'); - return self.list().then(function(data) { - self.fileList = (data.result || []).map(function(file) { - return new Item(file, self.currentPath); - }); - self.buildTree(path); - }); + if(self.searchModalActive){ + return self.searchlist(null).then(function(data) { + self.fileList = (data.result || []).map(function(file) { + return new Item(file, self.currentPath); + }); + self.buildTree(path); + }); + }else{ + return self.list().then(function(data) { + self.fileList = (data.result || []).map(function(file) { + return new Item(file, self.currentPath); + }); + self.buildTree(path); + }); + } }; - PolicyNavigator.prototype.policylist = function(finalpath) { + PolicyNavigator.prototype.searchlist = function(policyList) { var self = this; var deferred = $q.defer(); - var path = finalpath; - var data = {params: { - mode: 'LIST', - onlyFolders: false, - path: '/' + path - }}; + var path = self.currentPath.join('/'); + var data; + if(policyList == null){ + data = {params: { + mode: 'SEARCHLIST', + onlyFolders: false, + path: '/' + path + }}; + }else{ + data = {params: { + mode: 'SEARCHLIST', + onlyFolders: false, + path: '/' + path, + policyList : policyList + }}; + } + self.requesting = true; self.fileList = []; self.error = ''; - $http.post(policyManagerConfig.listUrl, data).success(function(data) { + $http.post(policyManagerConfig.searchListUrl, data).success(function(data) { self.deferredHandler(data, deferred); }).error(function(data) { self.deferredHandler(data, deferred, 'Unknown error listing, check the response'); @@ -131,16 +156,15 @@ return deferred.promise; }; - PolicyNavigator.prototype.policyrefresh = function(finalpath) { - var self = this; - var path = finalpath; - self.currentPath = path; - return self.policylist(finalpath).then(function(data) { - self.fileList = (data.result || []).map(function(file) { - return new Item(file, self.currentPath); - }); - self.buildTree(path); - }); + PolicyNavigator.prototype.searchrefresh = function(policyList) { + var self = this; + var path = self.currentPath.join('/'); + return self.searchlist(policyList).then(function(data) { + self.fileList = (data.result || []).map(function(file) { + return new Item(file, self.currentPath); + }); + self.buildTree(path); + }); }; -- cgit 1.2.3-korg