diff options
Diffstat (limited to 'POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/js/services')
3 files changed, 344 insertions, 0 deletions
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 |