From e0addf5b588a1244f9679becd90999dfcb4c3a94 Mon Sep 17 00:00:00 2001 From: "ITSERVICES\\rb7147" Date: Tue, 25 Apr 2017 11:46:00 -0400 Subject: Policy 1707 commit to LF Change-Id: Ibe6f01d92f9a434c040abb05d5386e89d675ae65 Signed-off-by: ITSERVICES\rb7147 --- .../app/policyApp/policy-models/Editor/js/app.js | 58 ++++ .../Editor/js/controllers/policyManager.js | 385 +++++++++++++++++++++ .../Editor/js/controllers/selector-controller.js | 46 +++ .../Editor/js/directives/directives.js | 52 +++ .../policy-models/Editor/js/entities/item.js | 347 +++++++++++++++++++ .../policy-models/Editor/js/filters/filters.js | 40 +++ .../policy-models/Editor/js/providers/config.js | 78 +++++ .../Editor/js/services/RolesService.js | 37 ++ .../Editor/js/services/policynavigator.js | 235 +++++++++++++ .../Editor/js/services/policyuploader.js | 72 ++++ 10 files changed, 1350 insertions(+) create mode 100644 POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/js/app.js create mode 100644 POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/js/controllers/policyManager.js create mode 100644 POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/js/controllers/selector-controller.js create mode 100644 POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/js/directives/directives.js create mode 100644 POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/js/entities/item.js create mode 100644 POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/js/filters/filters.js create mode 100644 POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/js/providers/config.js create mode 100644 POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/js/services/RolesService.js create mode 100644 POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/js/services/policynavigator.js create mode 100644 POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/js/services/policyuploader.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/app.js b/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/js/app.js new file mode 100644 index 000000000..476da957d --- /dev/null +++ b/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/js/app.js @@ -0,0 +1,58 @@ +/*- + * ============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========================================================= + */ +(function(window, angular, $) { + 'use strict'; + angular.module('abs').requires.push('ngRoute', 'modalServices', 'pascalprecht.translate', 'ngCookies', 'ngSanitize', 'ui-notification', + 'ui.grid','ui.grid.pagination','ui.grid.selection', 'ui.grid.exporter', 'ui.grid.edit', 'ui.grid.autoResize','b2b.att', + 'ui.grid.resizeColumns', 'ui.grid.treeView'); + var app = appDS2; + + app.config(['policyManagerConfigProvider', function (config) { + var defaults = config.$get(); + config.set({ + appName: 'Policy Editor', + cache: false, + allowedActions: angular.extend(defaults.allowedActions, { + remove: true + }) + }); + }]); + /** + * jQuery inits + */ + $(window.document).on('shown.bs.modal', '.modal', function() { + window.setTimeout(function() { + $('[autofocus]', this).focus(); + }.bind(this), 100); + }); + + $(window.document).on('click', function() { + $('#context-menu').hide(); + }); + + $(window.document).on('contextmenu', '.main-navigation .table-files td:first-child, .iconset a.thumbnail', function(e) { + $('#context-menu').hide().css({ + left: e.pageX, + top: e.pageY + }).show(); + e.preventDefault(); + }); + +})(window, angular, jQuery); 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 new file mode 100644 index 000000000..869d26ba3 --- /dev/null +++ b/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/js/controllers/policyManager.js @@ -0,0 +1,385 @@ +/*- + * ============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('PolicyManagerController', [ + '$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.exportPolicyId = true; + $scope.importPolicyId = true; + $scope.createScopeId = true; + $scope.deleteScopeId = true; + $scope.renameId = true; + $scope.createPolicyId = true; + $scope.cloneId = true; + $scope.editPolicyId = true; + $scope.switchVersionId = true; + $scope.describePolicyId = true; + $scope.viewPolicyId = true; + $scope.deletePolicyId = true; + }else if($scope.userRolesDatas[0] == 'super-editor' || $scope.userRolesDatas[0] == 'editor'){ + $scope.exportPolicyId = true; + $scope.importPolicyId = true; + $scope.cloneId = true; + $scope.editPolicyId = true; + $scope.createPolicyId = true; + $scope.cloneId = true; + $scope.editPolicyId = true; + $scope.switchVersionId = true; + $scope.describePolicyId = true; + $scope.viewPolicyId = true; + $scope.deletePolicyId = true; + }else if($scope.userRolesDatas[0] == 'super-guest' || $scope.userRolesDatas[0] == 'guest'){ + $scope.describePolicyId = true; + $scope.viewPolicyId = true; + }else if($scope.userRolesDatas[0] == 'admin'){ + $scope.exportPolicyId = true; + $scope.importPolicyId = true; + $scope.createScopeId = true; + $scope.renameId = true; + $scope.createPolicyId = true; + $scope.cloneId = true; + $scope.editPolicyId = true; + $scope.switchVersionId = true; + $scope.describePolicyId = true; + $scope.viewPolicyId = true; + $scope.deletePolicyId = 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.policyUploader = PolicyUploader; + $scope.uploadFileList = []; + + $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.watch = function(item){ + var uuu = "watchPolicy"; + var data = {name : item.model.name, + path : item.model.path}; + var postData={watchData: data}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){ + $scope.watchData=data.watchData;}); + Notification.success($scope.watchData); + console.log($scope.watchData); + }, + error : function(data){ + alert("Error while saving."); + } + }); + }; + + $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.switchVersion = function(item){ + if ($scope.policyNavigator.fileNameExists(item.tempModel.content.activeVersion)) { + item.error = 'Invalid filename or already exists, specify another name'; + return false; + } + item.getSwitchVersionContent().then(function(){ + $scope.policyNavigator.refresh(); + $scope.modal('switchVersion', true); + }); + }; + + + /* $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)) { + item.error = 'Invalid filename or already exists, specify another name'; + return false; + } + item.copy().then(function() { + $scope.policyNavigator.refresh(); + $scope.modal('copy', true); + }); + }; + + $scope.remove = function(item) { + item.remove().then(function() { + $scope.policyNavigator.refresh(); + $scope.modal('delete', true); + }); + }; + + $scope.removePolicy = function(item) { + item.removePolicy().then(function() { + $scope.policyNavigator.refresh(); + $scope.modal('deletePolicy', true); + }); + }; + + $scope.rename = function(item) { + var samePath = item.tempModel.path.join() === item.model.path.join(); + if (samePath && $scope.policyNavigator.fileNameExists(item.tempModel.name)) { + item.error = 'Invalid filename or already exists, specify another name'; + return false; + } + item.rename().then(function() { + $scope.policyNavigator.refresh(); + $scope.modal('rename', true); + }); + }; + + $scope.move = function(item) { + var samePath = item.tempModel.path.join() === item.model.path.join(); + if (samePath && $scope.policyNavigator.fileNameExists(item.tempModel.name)) { + item.error = 'Invalid filename or already exists, specify another name'; + return false; + } + item.move().then(function() { + $scope.policyNavigator.refresh(); + $scope.modal('move', true); + }); + }; + + $scope.createFolder = function(item) { + var name = item.tempModel.name && item.tempModel.name.trim(); + item.tempModel.type = 'dir'; + item.tempModel.path = $scope.policyNavigator.currentPath; + if (name && !$scope.policyNavigator.fileNameExists(name)) { + item.createFolder().then(function() { + $scope.policyNavigator.refresh(); + $scope.modal('newfolder', true); + }); + } else { + item.error = 'Invalid filename or already exists, specify another name'; + return false; + } + }; + + $scope.subScopeFolder = function(item) { + var name = item.tempModel.name +"\\" + item.tempModel.subScopename && item.tempModel.name.trim() + "\\"+item.tempModel.subScopename.trim() ; + item.tempModel.type = 'dir'; + item.tempModel.path = $scope.policyNavigator.currentPath; + if (name && !$scope.policyNavigator.fileNameExists(name)) { + item.getScopeContent().then(function() { + $scope.policyNavigator.refresh(); + $scope.modal('addSubScope', true); + }); + } else { + item.error = 'Invalid filename or already exists, specify another name'; + return false; + } + }; + + $scope.closefunction = function(fianlPath){ + $scope.policyNavigator.policyrefresh(fianlPath); + }; + + $scope.uploadFiles = function() { + $scope.policyUploader.upload($scope.uploadFileList, $scope.policyNavigator.currentPath).then(function() { + $scope.policyNavigator.refresh(); + $scope.modal('uploadfile', true); + }, function(data) { + var errorMsg = data.result && data.result.error || 'Error Occured while Uploading....'; + $scope.temp.error = errorMsg; + }); + }; + + $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.refresh(); + }]); diff --git a/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/js/controllers/selector-controller.js b/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/js/controllers/selector-controller.js new file mode 100644 index 000000000..438036341 --- /dev/null +++ b/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/js/controllers/selector-controller.js @@ -0,0 +1,46 @@ +/*- + * ============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========================================================= + */ +(function(angular, $) { + 'use strict'; + angular.module('abs').controller('PolicyManagerModalCtrl', + ['$scope', '$rootScope', 'policyNavigator', + function($scope, $rootScope, PolicyNavigator) { + + $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.policyNavigator = new PolicyNavigator(); + $rootScope.select = function(item, temp) { + temp.tempModel.path = item.model.fullPath().split('/'); + $('#selector').modal('hide'); + }; + + $rootScope.openNavigator = function(item) { + $scope.policyNavigator.currentPath = item.model.path.slice(); + $scope.policyNavigator.refresh(); + $('#selector').modal('show'); + }; + + }]); +})(angular, jQuery); \ No newline at end of file diff --git a/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/js/directives/directives.js b/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/js/directives/directives.js new file mode 100644 index 000000000..308a634db --- /dev/null +++ b/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/js/directives/directives.js @@ -0,0 +1,52 @@ +/*- + * ============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========================================================= + */ +(function(angular) { + 'use strict'; + var app = appDS2; + + app.directive('ngFile', ['$parse', function($parse) { + return { + restrict: 'A', + link: function(scope, element, attrs) { + var model = $parse(attrs.ngFile); + var modelSetter = model.assign; + + element.bind('change', function() { + scope.$apply(function() { + modelSetter(scope, element[0].files); + }); + }); + } + }; + }]); + + app.directive('ngRightClick', ['$parse', function($parse) { + return function(scope, element, attrs) { + var fn = $parse(attrs.ngRightClick); + element.bind('contextmenu', function(event) { + scope.$apply(function() { + event.preventDefault(); + fn(scope, {$event: event}); + }); + }); + }; + }]); + +})(angular); 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 new file mode 100644 index 000000000..2b1fd3469 --- /dev/null +++ b/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/js/entities/item.js @@ -0,0 +1,347 @@ +/*- + * ============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========================================================= + */ +angular.module('abs').factory('item', ['$http', '$q', 'policyManagerConfig', function($http, $q, policyManagerConfig) { + + var Item = function(model, path) { + var rawModel = { + name: model && model.name || '', + subScopename: model && model.subScopename || '', + path: path || [], + type: model && model.type || 'file', + size: model && parseInt(model.size || 0), + date: parseMySQLDate(model && model.date), + version: model && model.version || '', + createdBy: model && model.createdBy || '', + modifiedBy: model && model.modifiedBy || '', + content: model && model.content || '', + recursive: false, + sizeKb: function() { + return Math.round(this.size / 1024, 1); + }, + fullPath: function() { + if(this.version == ""){ + return ('/' + this.path.join('/') + '/' + this.name).replace(/\/\//, '/'); + }else{ + return ('/' + this.path.join('/') + '/' + this.name + '.' + this.version + '.xml').replace(/\/\//, '/'); + } + } + }; + + this.error = ''; + this.inprocess = false; + + this.model = angular.copy(rawModel); + this.tempModel = angular.copy(rawModel); + + function parseMySQLDate(mysqlDate) { + var d = (mysqlDate || '').toString().split(/[- :]/); + return new Date(d[0], d[1] - 1, d[2], d[3], d[4], d[5]); + } + }; + + Item.prototype.update = function() { + angular.extend(this.model, angular.copy(this.tempModel)); + }; + + Item.prototype.revert = function() { + angular.extend(this.tempModel, angular.copy(this.model)); + this.error = ''; + }; + + Item.prototype.deferredHandler = function(data, deferred, defaultMsg) { + if (!data || typeof data !== 'object') { + this.error = 'Bridge response error, please check the docs'; + } + if (data.result && data.result.error) { + this.error = data.result.error; + } + if (!this.error && data.error) { + this.error = data.error.message; + } + if (!this.error && defaultMsg) { + this.error = defaultMsg; + } + if (this.error) { + return deferred.reject(data); + } + this.update(); + return deferred.resolve(data); + }; + + Item.prototype.createFolder = function() { + var self = this; + var deferred = $q.defer(); + var data = {params: { + mode: 'ADDFOLDER', + path: self.tempModel.path.join('/'), + name: self.tempModel.name + }}; + + self.inprocess = true; + self.error = ''; + $http.post(policyManagerConfig.createFolderUrl, data).success(function(data) { + self.deferredHandler(data, deferred); + }).error(function(data) { + self.deferredHandler(data, deferred, 'Error Occured While Creating Scope'); + })['finally'](function() { + self.inprocess = false; + }); + + return deferred.promise; + }; + + Item.prototype.rename = function() { + var self = this; + var deferred = $q.defer(); + var data = {params: { + mode: 'RENAME', + path: self.model.fullPath(), + newPath: self.tempModel.fullPath() + }}; + self.inprocess = true; + self.error = ''; + $http.post(policyManagerConfig.renameUrl, data).success(function(data) { + self.deferredHandler(data, deferred); + }).error(function(data) { + self.deferredHandler(data, deferred, 'Error Occured While Renaming'); + })['finally'](function() { + self.inprocess = false; + }); + return deferred.promise; + }; + + + Item.prototype.move = function() { + var self = this; + var deferred = $q.defer(); + var data = {params: { + mode: 'RENAME', + path: self.model.fullPath(), + newPath: self.tempModel.fullPath() + }}; + self.inprocess = true; + self.error = ''; + $http.post(policyManagerConfig.renameUrl, data).success(function(data) { + self.deferredHandler(data, deferred); + }).error(function(data) { + self.deferredHandler(data, deferred, 'Error Occured While Moving'); + })['finally'](function() { + self.inprocess = false; + }); + return deferred.promise; + }; + + Item.prototype.copy = function() { + var self = this; + var deferred = $q.defer(); + var data = {params: { + mode: 'COPY', + path: self.model.fullPath(), + newPath: self.tempModel.fullPath() + }}; + + self.inprocess = true; + self.error = ''; + $http.post(policyManagerConfig.copyUrl, data).success(function(data) { + self.deferredHandler(data, deferred); + }).error(function(data) { + self.deferredHandler(data, deferred, 'Error Occured While Cloning'); + })['finally'](function() { + self.inprocess = false; + }); + return deferred.promise; + }; + + + Item.prototype.getContent = function() { + var self = this; + var deferred = $q.defer(); + var data = {params: { + mode: 'EDITFILE', + path: self.tempModel.fullPath() + }}; + + self.inprocess = true; + self.error = ''; + $http.post(policyManagerConfig.getContentUrl, data).success(function(data) { + self.tempModel.content = self.model.content = data.result; + var json = data.result; + var policy = JSON.parse(json); + self.policy = policy; + console.log(policy); + self.deferredHandler(data, deferred); + }).error(function(data) { + self.deferredHandler(data, deferred, 'Error Occured While retrieving the Policy Data'); + })['finally'](function() { + self.inprocess = false; + }); + return deferred.promise; + }; + + Item.prototype.getViewPolicyContent = function() { + var self = this; + var deferred = $q.defer(); + var data = {params: { + mode: 'VIEWPOLICY', + path: self.tempModel.fullPath() + }}; + + self.inprocess = true; + self.error = ''; + $http.post(policyManagerConfig.viewPolicyUrl, data).success(function(data) { + self.tempModel.content = self.model.content = data.result; + var json = data.result; + var policy = JSON.parse(json); + self.policy = policy; + console.log(data.result); + console.log(policy); + self.deferredHandler(data, deferred); + }).error(function(data) { + self.deferredHandler(data, deferred, 'Error Occured While retrieving the Policy Data'); + })['finally'](function() { + self.inprocess = false; + }); + return deferred.promise; + }; + + Item.prototype.getSwitchVersionContent = function() { + var self = this; + var deferred = $q.defer(); + var data = {params: { + mode: 'SWITCHVERSION', + path: self.tempModel.fullPath(), + activeVersion : self.tempModel.content.activeVersion, + highestVersion : self.tempModel.content.highestVersion + }}; + + self.inprocess = true; + self.error = ''; + $http.post(policyManagerConfig.switchVersionUrl, data).success(function(data) { + self.tempModel.content = self.model.content = data; + self.deferredHandler(data, deferred); + }).error(function(data) { + self.deferredHandler(data, deferred, 'Error Occured While retrieving the Switch Version Data'); + })['finally'](function() { + self.inprocess = false; + }); + return deferred.promise; + }; + + Item.prototype.getDescribePolicyContent = function() { + var self = this; + var deferred = $q.defer(); + var data = {params: { + mode: 'DESCRIBEPOLICYFILE', + path: self.tempModel.fullPath() + }}; + + self.inprocess = true; + self.error = ''; + $http.post(policyManagerConfig.describePolicyUrl, data).success(function(data) { + self.tempModel.content = self.model.content = data.html; + var describeTemplate = self.tempModel.content; + + self.deferredHandler(data, deferred); + }).error(function(data) { + self.deferredHandler(data, deferred, 'Error Occured While retrieving the Policy Data to Describe'); + })['finally'](function() { + self.inprocess = false; + }); + return deferred.promise; + }; + + Item.prototype.getScopeContent = function() { + var self = this; + var deferred = $q.defer(); + var data = {params: { + mode: 'ADDSUBSCOPE', + name: self.tempModel.name, + subScopename: self.tempModel.subScopename, + path: self.tempModel.fullPath() + }}; + + self.inprocess = true; + self.error = ''; + $http.post(policyManagerConfig.addSubScopeUrl, data).success(function(data) { + self.deferredHandler(data, deferred); + }).error(function(data) { + self.deferredHandler(data, deferred, 'Error Occured While Creating the Sub Scope'); + })['finally'](function() { + self.inprocess = false; + }); + return deferred.promise; + }; + + Item.prototype.remove = function() { + var self = this; + var deferred = $q.defer(); + var data = {params: { + mode: 'DELETE', + path: self.tempModel.fullPath(), + deleteVersion : self.model.versions + }}; + + self.inprocess = true; + self.error = ''; + $http.post(policyManagerConfig.removeUrl, data).success(function(data) { + self.deferredHandler(data, deferred); + }).error(function(data) { + self.deferredHandler(data, deferred, 'Error Occured While retrieving the Deleting Scope'); + })['finally'](function() { + self.inprocess = false; + }); + return deferred.promise; + }; + + Item.prototype.removePolicy = function() { + var self = this; + var deferred = $q.defer(); + var data = {params: { + mode: 'DELETE', + path: self.tempModel.fullPath(), + deleteVersion : self.model.versions + }}; + + self.inprocess = true; + self.error = ''; + $http.post(policyManagerConfig.removeUrl, data).success(function(data) { + self.deferredHandler(data, deferred); + }).error(function(data) { + self.deferredHandler(data, deferred, 'Error Occured While retrieving the Deleting Policy'); + })['finally'](function() { + self.inprocess = false; + }); + return deferred.promise; + }; + + Item.prototype.isFolder = function() { + return this.model.type === 'dir'; + }; + + Item.prototype.isEditable = function() { + 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/filters/filters.js b/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/js/filters/filters.js new file mode 100644 index 000000000..4d897c9c0 --- /dev/null +++ b/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/js/filters/filters.js @@ -0,0 +1,40 @@ +/*- + * ============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========================================================= + */ +(function(angular) { + 'use strict'; + var app = angular.module('abs'); + + app.filter('strLimit', ['$filter', function($filter) { + return function(input, limit) { + if (input.length <= limit) { + return input; + } + return $filter('limitTo')(input, limit) + '...'; + }; + }]); + + app.filter('formatDate', ['$filter', function() { + return function(input) { + return input instanceof Date ? + input.toISOString().substring(0, 19).replace('T', ' ') : + (input.toLocaleString || input.toString).apply(input); + }; + }]); +})(angular); 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 new file mode 100644 index 000000000..72fd84d53 --- /dev/null +++ b/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/js/providers/config.js @@ -0,0 +1,78 @@ +/*- + * ============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========================================================= + */ +(function(angular) { + 'use strict'; + + angular.module('abs').provider('policyManagerConfig', function() { + + var values = { + appName: 'Policy Editor', + defaultLang: 'en', + listUrl: 'fm/listUrl', + uploadUrl: 'fm/uploadUrl', + renameUrl: 'fm/renameUrl', + copyUrl: 'fm/copyUrl', + removeUrl: 'fm/removeUrl', + editUrl: 'fm/editUrl', + getContentUrl: 'fm/getContentUrl', + createFolderUrl: 'fm/createFolderUrl', + downloadFileUrl: 'fm/downloadFileUrl', + compressUrl: 'fm/compressUrl', + extractUrl: 'fm/extractUrl', + permissionsUrl: 'fm/permissionsUrl', + describePolicyUrl : 'fm/describePolicyUrl', + viewPolicyUrl : 'fm/viewPolicyUrl', + addSubScopeUrl : 'fm/addSubScopeUrl', + switchVersionUrl : 'fm/switchVersionUrl', + exportUrl : 'fm/exportUrl', + + sidebar: true, + breadcrumb: true, + allowedActions: { + upload: true, + rename: true, + copy: true, + edit: true, + describePolicy: true, + createNewPolicy: true, + viewPolicy: true, + download: true, + preview: true, + remove: true, + addSubScope : true, + switchVersion : true, + exportPolicy : true, + removePolicy : true + }, + + tplPath: 'app/policyApp/policy-models/Editor/templates' + }; + + return { + $get: function() { + return values; + }, + set: function (constants) { + angular.extend(values, constants); + } + }; + + }); +})(angular); diff --git a/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/js/services/RolesService.js b/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/js/services/RolesService.js new file mode 100644 index 000000000..2d3426fc3 --- /dev/null +++ b/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/js/services/RolesService.js @@ -0,0 +1,37 @@ +/*- + * ============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========================================================= + */ +angular.module("abs").factory('RolesService', function ($http, $q) { + return { + getRolesData: function() { + return $http.get('get_UserRolesData') + .then(function(response) { + if (typeof response.data === 'object') { + return response.data; + } else { + return $q.reject(response.data); + } + + }, function(response) { + // something went wrong + return $q.reject(response.data); + }); + } + }; +}); \ No newline at end of file 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 new file mode 100644 index 000000000..bb76dd9d5 --- /dev/null +++ b/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/js/services/policynavigator.js @@ -0,0 +1,235 @@ +/*- + * ============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========================================================= + */ +(function(angular) { + 'use strict'; + angular.module('abs').service('policyNavigator', [ + '$http', '$q', 'policyManagerConfig', 'item', function ($http, $q, policyManagerConfig, Item) { + + $http.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest'; + + var PolicyNavigator = function() { + this.requesting = false; + this.fileList = []; + this.currentPath = []; + this.history = []; + this.error = ''; + }; + + PolicyNavigator.prototype.deferredHandler = function(data, deferred, defaultMsg) { + if (!data || typeof data !== 'object') { + this.error = 'Bridge response error, please check the docs'; + } + if (!this.error && data.result && data.result.error) { + this.error = data.result.error; + } + if (!this.error && data.error) { + this.error = data.error.message; + } + if (!this.error && defaultMsg) { + this.error = defaultMsg; + } + if (this.error) { + return deferred.reject(data); + } + return deferred.resolve(data); + }; + + PolicyNavigator.prototype.deferredSearchHandler = function(data, deferred, defaultMsg) { + self.fileList = []; + self.error = ''; + if (!data || typeof data !== 'object') { + this.error = 'Bridge response error, please check the docs'; + } + if (!this.error && data.result && data.result.error) { + this.error = data.result.error; + } + if (!this.error && data.error) { + this.error = data.error.message; + } + if (!this.error && defaultMsg) { + this.error = defaultMsg; + } + if (this.error) { + return deferred.reject(data); + } + return deferred.resolve(data); + }; + + PolicyNavigator.prototype.list = function() { + var self = this; + var deferred = $q.defer(); + var path = self.currentPath.join('/'); + var data = {params: { + mode: 'LIST', + onlyFolders: false, + path: '/' + path + }}; + + self.requesting = true; + self.fileList = []; + self.error = ''; + + $http.post(policyManagerConfig.listUrl, data).success(function(data) { + self.deferredHandler(data, deferred); + }).error(function(data) { + self.deferredHandler(data, deferred, 'Unknown error listing, check the response'); + })['finally'](function() { + self.requesting = false; + }); + return deferred.promise; + }; + + 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); + }); + }; + + PolicyNavigator.prototype.policylist = function(finalpath) { + var self = this; + var deferred = $q.defer(); + var path = finalpath; + var data = {params: { + mode: 'LIST', + onlyFolders: false, + path: '/' + path + }}; + + self.requesting = true; + self.fileList = []; + self.error = ''; + + $http.post(policyManagerConfig.listUrl, data).success(function(data) { + self.deferredHandler(data, deferred); + }).error(function(data) { + self.deferredHandler(data, deferred, 'Unknown error listing, check the response'); + })['finally'](function() { + self.requesting = false; + }); + 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.buildTree = function(path) { + var flatNodes = [], selectedNode = {}; + + function recursive(parent, item, path) { + var absName = path ? (path + '/' + item.model.name) : item.model.name; + if (parent.name.trim() && path.trim().indexOf(parent.name) !== 0) { + parent.nodes = []; + } + if (parent.name !== path) { + for (var i in parent.nodes) { + recursive(parent.nodes[i], item, path); + } + } else { + for (var e in parent.nodes) { + if (parent.nodes[e].name === absName) { + return; + } + } + parent.nodes.push({item: item, name: absName, nodes: []}); + } + parent.nodes = parent.nodes.sort(function(a, b) { + return a.name.toLowerCase() < b.name.toLowerCase() ? -1 : a.name.toLowerCase() === b.name.toLowerCase() ? 0 : 1; + }); + } + + function flatten(node, array) { + array.push(node); + for (var n in node.nodes) { + flatten(node.nodes[n], array); + } + } + + function findNode(data, path) { + return data.filter(function (n) { + return n.name === path; + })[0]; + } + + !this.history.length && this.history.push({name: '', nodes: []}); + flatten(this.history[0], flatNodes); + selectedNode = findNode(flatNodes, path); + selectedNode.nodes = []; + + for (var o in this.fileList) { + var item = this.fileList[o]; + item.isFolder() && recursive(this.history[0], item, path); + } + }; + + PolicyNavigator.prototype.folderClick = function(item) { + this.currentPath = []; + if (item && item.isFolder()) { + this.currentPath = item.model.fullPath().split('/').splice(1); + } + this.refresh(); + }; + + PolicyNavigator.prototype.upDir = function() { + if (this.currentPath[0]) { + this.currentPath = this.currentPath.slice(0, -1); + this.refresh(); + } + }; + + PolicyNavigator.prototype.goTo = function(index) { + this.currentPath = this.currentPath.slice(0, index + 1); + this.refresh(); + }; + + PolicyNavigator.prototype.fileNameExists = function(fileName) { + for (var item in this.fileList) { + item = this.fileList[item]; + if (fileName.trim && item.model.name.trim() === fileName.trim()) { + return true; + } + } + }; + + PolicyNavigator.prototype.listHasFolders = function() { + for (var item in this.fileList) { + if (this.fileList[item].model.type === 'dir') { + return true; + } + } + }; + + return PolicyNavigator; + }]); +})(angular); \ No newline at end of file diff --git a/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/js/services/policyuploader.js b/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/js/services/policyuploader.js new file mode 100644 index 000000000..de7d4c15e --- /dev/null +++ b/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/js/services/policyuploader.js @@ -0,0 +1,72 @@ +/*- + * ============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========================================================= + */ +(function(window, angular) { + 'use strict'; + angular.module('abs').service('policyUploader', ['$http', '$q', 'policyManagerConfig', function ($http, $q, policyManagerConfig) { + + function deferredHandler(data, deferred, errorMessage) { + if (!data || typeof data !== 'object') { + return deferred.reject('Bridge response error, please check the docs'); + } + if (data.result && data.result.error) { + return deferred.reject(data); + } + if (data.error) { + return deferred.reject(data); + } + if (errorMessage) { + return deferred.reject(errorMessage); + } + deferred.resolve(data); + } + + this.requesting = false; + this.upload = function(fileList, path) { + if (! window.FormData) { + throw new Error('Unsupported browser version'); + } + var self = this; + var form = new window.FormData(); + var deferred = $q.defer(); + form.append('destination', '/' + path.join('/')); + + for (var i = 0; i < fileList.length; i++) { + var fileObj = fileList.item(i); + fileObj instanceof window.File && form.append('file-' + i, fileObj); + } + + self.requesting = true; + $http.post(policyManagerConfig.uploadUrl, form, { + transformRequest: angular.identity, + headers: { + 'Content-Type': undefined + } + }).success(function(data) { + deferredHandler(data, deferred); + }).error(function(data) { + deferredHandler(data, deferred, 'Unknown error uploading files'); + })['finally'](function() { + self.requesting = false; + }); + + return deferred.promise; + }; + }]); +})(window, angular); \ No newline at end of file -- cgit 1.2.3-korg