From 031f1a41e846e02dc5156988e97daf5d03aa2a77 Mon Sep 17 00:00:00 2001 From: Christoph Kappestein Date: Sat, 21 Jan 2017 19:07:34 +0100 Subject: [PATCH] add js files --- public/fusio/app/controller/account/index.js | 14 ++ public/fusio/app/controller/action/create.js | 72 +++++++ public/fusio/app/controller/action/delete.js | 29 +++ public/fusio/app/controller/action/execute.js | 58 +++++ public/fusio/app/controller/action/index.js | 20 ++ public/fusio/app/controller/action/update.js | 91 ++++++++ public/fusio/app/controller/rate/create.js | 160 ++++++++++++++ public/fusio/app/controller/rate/delete.js | 29 +++ public/fusio/app/controller/rate/update.js | 204 ++++++++++++++++++ public/fusio/app/controller/routes/create.js | 113 ++++++++++ public/fusio/app/controller/routes/delete.js | 29 +++ public/fusio/app/controller/routes/update.js | 133 ++++++++++++ public/fusio/app/controller/schema/create.js | 39 ++++ public/fusio/app/controller/schema/delete.js | 29 +++ public/fusio/app/controller/schema/update.js | 79 +++++++ public/fusio/app/controller/scope/create.js | 62 ++++++ public/fusio/app/controller/scope/delete.js | 29 +++ public/fusio/app/controller/scope/update.js | 94 ++++++++ public/fusio/app/controller/user/create.js | 66 ++++++ public/fusio/app/controller/user/delete.js | 29 +++ public/fusio/app/controller/user/update.js | 86 ++++++++ 21 files changed, 1465 insertions(+) create mode 100644 public/fusio/app/controller/account/index.js create mode 100644 public/fusio/app/controller/action/create.js create mode 100644 public/fusio/app/controller/action/delete.js create mode 100644 public/fusio/app/controller/action/execute.js create mode 100644 public/fusio/app/controller/action/index.js create mode 100644 public/fusio/app/controller/action/update.js create mode 100644 public/fusio/app/controller/rate/create.js create mode 100644 public/fusio/app/controller/rate/delete.js create mode 100644 public/fusio/app/controller/rate/update.js create mode 100644 public/fusio/app/controller/routes/create.js create mode 100644 public/fusio/app/controller/routes/delete.js create mode 100644 public/fusio/app/controller/routes/update.js create mode 100644 public/fusio/app/controller/schema/create.js create mode 100644 public/fusio/app/controller/schema/delete.js create mode 100644 public/fusio/app/controller/schema/update.js create mode 100644 public/fusio/app/controller/scope/create.js create mode 100644 public/fusio/app/controller/scope/delete.js create mode 100644 public/fusio/app/controller/scope/update.js create mode 100644 public/fusio/app/controller/user/create.js create mode 100644 public/fusio/app/controller/user/delete.js create mode 100644 public/fusio/app/controller/user/update.js diff --git a/public/fusio/app/controller/account/index.js b/public/fusio/app/controller/account/index.js new file mode 100644 index 00000000..19dcb657 --- /dev/null +++ b/public/fusio/app/controller/account/index.js @@ -0,0 +1,14 @@ +'use strict'; + +var angular = require('angular'); + +angular.module('fusioApp.account', ['ngRoute']) + +.config(['$routeProvider', function($routeProvider) { + $routeProvider.when('/account/change_password', { + templateUrl: 'app/controller/account/change_password.html', + controller: 'ChangePasswordCtrl' + }); +}]) + +.controller('ChangePasswordCtrl', require('./change_password')); diff --git a/public/fusio/app/controller/action/create.js b/public/fusio/app/controller/action/create.js new file mode 100644 index 00000000..950c1403 --- /dev/null +++ b/public/fusio/app/controller/action/create.js @@ -0,0 +1,72 @@ +'use strict'; + +module.exports = function($scope, $http, $uibModalInstance, formBuilder, fusio) { + + $scope.action = { + name: "", + class: "", + config: {} + }; + $scope.elements = []; + $scope.config = {}; + $scope.actions = []; + + $scope.create = function(action) { + var data = angular.copy(action); + + if (angular.isObject($scope.config)) { + data.config = formBuilder.postProcessModel($scope.config, $scope.elements); + } + + $http.post(fusio.baseUrl + 'backend/action', data) + .then(function(response) { + var data = response.data; + $scope.response = data; + if (data.success === true) { + $uibModalInstance.close(data); + } + }) + .catch(function(response) { + $scope.response = response.data; + }); + }; + + $http.get(fusio.baseUrl + 'backend/action/list') + .then(function(response) { + var data = response.data; + $scope.actions = data.actions; + + if (data.actions[0]) { + $scope.action.class = data.actions[0].class; + $scope.loadConfig(); + } + }); + + $scope.close = function() { + $uibModalInstance.dismiss('cancel'); + }; + + $scope.closeResponse = function() { + $scope.response = null; + }; + + $scope.loadConfig = function() { + if ($scope.action.class) { + $http.get(fusio.baseUrl + 'backend/action/form?class=' + encodeURIComponent($scope.action.class)) + .then(function(response) { + var data = response.data; + var containerEl = angular.element(document.querySelector('#config-form')); + containerEl.children().remove(); + + $scope.elements = data.element; + $scope.config = formBuilder.preProcessModel($scope.action.config, $scope.elements); + var linkFn = formBuilder.buildHtml($scope.elements, 'config'); + if (angular.isFunction(linkFn)) { + var el = linkFn($scope); + containerEl.append(el); + } + }); + } + }; + +}; diff --git a/public/fusio/app/controller/action/delete.js b/public/fusio/app/controller/action/delete.js new file mode 100644 index 00000000..4fb05b3f --- /dev/null +++ b/public/fusio/app/controller/action/delete.js @@ -0,0 +1,29 @@ +'use strict'; + +module.exports = function($scope, $http, $uibModalInstance, action, fusio) { + + $scope.action = action; + + $scope.delete = function(action) { + $http.delete(fusio.baseUrl + 'backend/action/' + action.id) + .then(function(response) { + var data = response.data; + $scope.response = data; + if (data.success === true) { + $uibModalInstance.close(data); + } + }) + .catch(function(response) { + $scope.response = response.data; + }); + }; + + $scope.close = function() { + $uibModalInstance.dismiss('cancel'); + }; + + $scope.closeResponse = function() { + $scope.response = null; + }; + +}; diff --git a/public/fusio/app/controller/action/execute.js b/public/fusio/app/controller/action/execute.js new file mode 100644 index 00000000..ba695216 --- /dev/null +++ b/public/fusio/app/controller/action/execute.js @@ -0,0 +1,58 @@ +'use strict'; + +module.exports = function($scope, $http, $uibModalInstance, action, fusio) { + + $scope.action = action; + $scope.methods = ['GET', 'POST', 'PUT', 'DELETE']; + $scope.request = { + method: 'GET', + uriFragments: '', + parameters: '', + body: '{}' + }; + $scope.response = null; + + $scope.requestOpen = false; + $scope.responseOpen = true; + + $scope.execute = function(action, request) { + var body = JSON.parse(request.body); + if (!angular.isObject(body)) { + body = {}; + } + var data = { + method: request.method, + uriFragments: request.uriFragments, + parameters: request.parameters, + body: body + }; + + $http.post(fusio.baseUrl + 'backend/action/execute/' + action.id, data) + .then(function(response) { + var data = response.data; + // in case we have no body property we have probably a general error + // message in this case we simply show the complete response as body + var resp = {}; + if (!data.body) { + resp.statusCode = 500; + resp.headers = {}; + resp.body = data; + } else { + resp = data; + } + + $scope.response = { + statusCode: resp.statusCode, + headers: resp.headers, + body: JSON.stringify(resp.body, null, 4) + }; + }); + }; + + $scope.close = function() { + $uibModalInstance.dismiss('cancel'); + }; + + $scope.execute(action, $scope.request); + +}; diff --git a/public/fusio/app/controller/action/index.js b/public/fusio/app/controller/action/index.js new file mode 100644 index 00000000..85fb1337 --- /dev/null +++ b/public/fusio/app/controller/action/index.js @@ -0,0 +1,20 @@ +'use strict'; + +var angular = require('angular'); + +angular.module('fusioApp.action', ['ngRoute', 'ui.ace']) + +.config(['$routeProvider', function($routeProvider) { + $routeProvider.when('/action', { + templateUrl: 'app/controller/action/index.html', + controller: 'ActionCtrl' + }); +}]) + +.controller('ActionCtrl', require('./action')) +.controller('ActionCreateCtrl', require('./create')) +.controller('ActionUpdateCtrl', require('./update')) +.controller('ActionDeleteCtrl', require('./delete')) +.controller('ActionExecuteCtrl', require('./execute')) + +; diff --git a/public/fusio/app/controller/action/update.js b/public/fusio/app/controller/action/update.js new file mode 100644 index 00000000..8f68f365 --- /dev/null +++ b/public/fusio/app/controller/action/update.js @@ -0,0 +1,91 @@ +'use strict'; + +module.exports = function($scope, $http, $uibModalInstance, $uibModal, action, formBuilder, $timeout, fusio) { + + $scope.action = action; + $scope.elements = []; + $scope.config = {}; + $scope.actions = []; + + $scope.update = function(action) { + var data = angular.copy(action); + + if (angular.isObject($scope.config)) { + data.config = formBuilder.postProcessModel($scope.config, $scope.elements); + } + + $http.put(fusio.baseUrl + 'backend/action/' + action.id, data) + .then(function(response) { + var data = response.data; + $scope.response = data; + if (data.success === true) { + $uibModalInstance.close(data); + } + }) + .catch(function(response) { + $scope.response = response.data; + }); + }; + + $scope.close = function() { + $uibModalInstance.dismiss('cancel'); + }; + + $scope.closeResponse = function() { + $scope.response = null; + }; + + $scope.loadConfig = function() { + if ($scope.action.class) { + $http.get(fusio.baseUrl + 'backend/action/form?class=' + encodeURIComponent($scope.action.class)) + .then(function(response) { + var data = response.data; + var containerEl = angular.element(document.querySelector('#config-form')); + containerEl.children().remove(); + + $scope.elements = data.element; + $scope.config = formBuilder.preProcessModel($scope.action.config, $scope.elements); + var linkFn = formBuilder.buildHtml($scope.elements, 'config'); + if (angular.isFunction(linkFn)) { + var el = linkFn($scope); + containerEl.append(el); + } + }); + } + }; + + $scope.execute = function(action) { + $http.put(fusio.baseUrl + 'backend/action/' + action.id, action) + .then(function(response) { + var data = response.data; + $scope.response = data; + if (data.success === true) { + var modalInstance = $uibModal.open({ + size: 'lg', + backdrop: 'static', + templateUrl: 'app/controller/action/execute.html', + controller: 'ActionExecuteCtrl', + resolve: { + action: function() { + return action; + } + } + }); + + modalInstance.result.then(function(response) { + }, function() { + }); + } + }) + .catch(function(response) { + $scope.response = response.data; + }); + }; + + $http.get(fusio.baseUrl + 'backend/action/' + action.id) + .then(function(response) { + $scope.action = response.data; + $scope.loadConfig(); + }); + +} diff --git a/public/fusio/app/controller/rate/create.js b/public/fusio/app/controller/rate/create.js new file mode 100644 index 00000000..67891fe5 --- /dev/null +++ b/public/fusio/app/controller/rate/create.js @@ -0,0 +1,160 @@ +'use strict'; + +module.exports = function($scope, $http, $uibModalInstance, fusio) { + + $scope.rate = { + priority: 0, + name: '', + rateLimit: 1800, + timespan: '', + allocation: [{ + routeId: null, + appId: null, + authenticated: null, + parameters: null + }] + }; + + $scope.timespan = { + value: 1, + unit: 'hour' + }; + + $scope.intervals = [{ + key: 'minute', + value: 'minute' + }, { + key: 'hour', + value: 'hour' + }, { + key: 'day', + value: 'day' + }, { + key: 'week', + value: 'week' + }, { + key: 'month', + value: 'month' + }]; + + $scope.status = [{ + key: null, + value: 'Yes/No' + }, { + key: true, + value: 'Yes' + }, { + key: false, + value: 'No' + }]; + + $scope.routes = []; + $scope.apps = []; + + $scope.create = function(rate) { + var data = angular.copy(rate); + data.timespan = $scope.getTimespan($scope.timespan); + data.allocation = $scope.removeNullValuesFromAllocation(rate.allocation); + + $http.post(fusio.baseUrl + 'backend/rate', data) + .then(function(response) { + var data = response.data; + $scope.response = data; + if (data.success === true) { + $uibModalInstance.close(data); + } + }) + .catch(function(response) { + $scope.response = response.data; + }); + }; + + $scope.close = function() { + $uibModalInstance.dismiss('cancel'); + }; + + $scope.closeResponse = function() { + $scope.response = null; + }; + + $scope.getRoutes = function() { + $http.get(fusio.baseUrl + 'backend/routes') + .then(function(response) { + var data = response.data; + if (angular.isArray(data.entry)) { + var routes = data.entry; + routes.unshift({ + id: null, + path: 'Every route' + }); + $scope.routes = routes; + } + }); + }; + + $scope.getApps = function() { + $http.get(fusio.baseUrl + 'backend/app') + .then(function(response) { + var data = response.data; + if (angular.isArray(data.entry)) { + var apps = data.entry; + apps.unshift({ + id: null, + name: 'Every app' + }); + $scope.apps = apps; + } + }); + }; + + $scope.addAllocation = function() { + $scope.rate.allocation.push({ + routeId: null, + appId: null, + authenticated: true, + parameters: null + }); + }; + + $scope.removeAllocation = function(index) { + var allocation = $scope.rate.allocation; + allocation.splice(index, 1); + $scope.rate.allocation = allocation; + }; + + $scope.removeNullValuesFromAllocation = function(allocation) { + var data = []; + for (var i = 0; i < allocation.length; i++) { + data.push($scope.removeNullValuesFromObject(allocation[i])); + } + return data; + }; + + $scope.removeNullValuesFromObject = function(object) { + var row = {}; + for (var key in object) { + if (object.hasOwnProperty(key) && object[key] !== null) { + row[key] = object[key]; + } + } + return row; + }; + + $scope.getTimespan = function(timespan) { + if (timespan.unit == 'minute') { + return 'PT' + timespan.value + 'M'; + } else if (timespan.unit == 'hour') { + return 'PT' + timespan.value + 'H'; + } else if (timespan.unit == 'day') { + return 'P' + timespan.value + 'D'; + } else if (timespan.unit == 'week') { + return 'P' + timespan.value + 'W'; + } else if (timespan.unit == 'month') { + return 'P' + timespan.value + 'M'; + } + }; + + $scope.getRoutes(); + //$scope.getApps(); + +}; diff --git a/public/fusio/app/controller/rate/delete.js b/public/fusio/app/controller/rate/delete.js new file mode 100644 index 00000000..de671fff --- /dev/null +++ b/public/fusio/app/controller/rate/delete.js @@ -0,0 +1,29 @@ +'use strict'; + +module.exports = function($scope, $http, $uibModalInstance, rate, fusio) { + + $scope.rate = rate; + + $scope.delete = function(rate) { + $http.delete(fusio.baseUrl + 'backend/rate/' + rate.id) + .then(function(response) { + var data = response.data; + $scope.response = data; + if (data.success === true) { + $uibModalInstance.close(data); + } + }) + .catch(function(response) { + $scope.response = response.data; + }); + }; + + $scope.close = function() { + $uibModalInstance.dismiss('cancel'); + }; + + $scope.closeResponse = function() { + $scope.response = null; + }; + +}; diff --git a/public/fusio/app/controller/rate/update.js b/public/fusio/app/controller/rate/update.js new file mode 100644 index 00000000..d2c623a3 --- /dev/null +++ b/public/fusio/app/controller/rate/update.js @@ -0,0 +1,204 @@ +'use strict'; + +module.exports = function($scope, $http, $uibModalInstance, rate, fusio) { + + $scope.rate = rate; + + $scope.timespan = { + value: 1, + unit: 'hour' + }; + + $scope.intervals = [{ + key: 'minute', + value: 'minute' + }, { + key: 'hour', + value: 'hour' + }, { + key: 'day', + value: 'day' + }, { + key: 'week', + value: 'week' + }, { + key: 'month', + value: 'month' + }]; + + $scope.status = [{ + key: null, + value: 'Yes/No' + }, { + key: true, + value: 'Yes' + }, { + key: false, + value: 'No' + }]; + + $scope.routes = []; + $scope.apps = []; + + $scope.update = function(rate) { + var data = angular.copy(rate); + data.timespan = $scope.getTimespan($scope.timespan); + data.allocation = $scope.removeNullValuesFromAllocation(rate.allocation); + + $http.put(fusio.baseUrl + 'backend/rate/' + rate.id, data) + .then(function(response) { + var data = response.data; + $scope.response = data; + if (data.success === true) { + $uibModalInstance.close(data); + } + }) + .catch(function(response) { + $scope.response = response.data; + }); + }; + + $http.get(fusio.baseUrl + 'backend/rate/' + rate.id) + .then(function(response) { + var data = response.data; + $scope.parseTimespan(data.timespan); + data.allocation = $scope.addNullValuesToAllocation(data.allocation); + $scope.rate = data; + }); + + $scope.close = function() { + $uibModalInstance.dismiss('cancel'); + }; + + $scope.closeResponse = function() { + $scope.response = null; + }; + + $scope.getRoutes = function() { + $http.get(fusio.baseUrl + 'backend/routes') + .then(function(response) { + var data = response.data; + if (angular.isArray(data.entry)) { + var routes = data.entry; + routes.unshift({ + id: null, + path: 'Every route' + }); + $scope.routes = routes; + } + }); + }; + + $scope.getApps = function() { + $http.get(fusio.baseUrl + 'backend/app') + .then(function(response) { + var data = response.data; + if (angular.isArray(data.entry)) { + var apps = data.entry; + apps.unshift({ + id: null, + name: 'Every app' + }); + $scope.apps = apps; + } + }); + }; + + $scope.addAllocation = function() { + $scope.rate.allocation.push({ + routeId: null, + appId: null, + authenticated: true, + parameters: null + }); + }; + + $scope.removeAllocation = function(index) { + var allocation = $scope.rate.allocation; + allocation.splice(index, 1); + $scope.rate.allocation = allocation; + }; + + $scope.removeNullValuesFromAllocation = function(allocation) { + var data = []; + for (var i = 0; i < allocation.length; i++) { + data.push($scope.removeNullValuesFromObject(allocation[i])); + } + return data; + }; + + $scope.removeNullValuesFromObject = function(object) { + var row = {}; + for (var key in object) { + if (object.hasOwnProperty(key) && object[key] !== null) { + row[key] = object[key]; + } + } + return row; + }; + + $scope.addNullValuesToAllocation = function(allocation) { + var data = []; + for (var i = 0; i < allocation.length; i++) { + var row = allocation[i]; + if (!row.hasOwnProperty('routeId')) { + row.routeId = null; + } + if (!row.hasOwnProperty('appId')) { + row.appId = null; + } + if (!row.hasOwnProperty('authenticated')) { + row.authenticated = null; + } + if (!row.hasOwnProperty('parameters')) { + row.parameters = null; + } + data.push(row); + } + return data; + }; + + $scope.getTimespan = function(timespan) { + if (timespan.unit == 'minute') { + return 'PT' + timespan.value + 'M'; + } else if (timespan.unit == 'hour') { + return 'PT' + timespan.value + 'H'; + } else if (timespan.unit == 'day') { + return 'P' + timespan.value + 'D'; + } else if (timespan.unit == 'week') { + return 'P' + timespan.value + 'W'; + } else if (timespan.unit == 'month') { + return 'P' + timespan.value + 'M'; + } + }; + + $scope.parseTimespan = function(timespan) { + var value = 1; + var unit = 'hour'; + if (timespan.indexOf('T') !== -1) { + if (timespan.indexOf('H') !== -1) { + unit = 'hour'; + } else if (timespan.indexOf('M') !== -1) { + unit = 'minute'; + } + value = parseInt(timespan.substr(2)); + } else { + if (timespan.indexOf('M') !== -1) { + unit = 'month'; + } else if (timespan.indexOf('W') !== -1) { + unit = 'week'; + } else if (timespan.indexOf('D') !== -1) { + unit = 'day'; + } + value = parseInt(timespan.substr(1)); + } + + $scope.timespan = { + value: value, + unit: unit + }; + }; + + $scope.getRoutes(); + +}; diff --git a/public/fusio/app/controller/routes/create.js b/public/fusio/app/controller/routes/create.js new file mode 100644 index 00000000..e324d11e --- /dev/null +++ b/public/fusio/app/controller/routes/create.js @@ -0,0 +1,113 @@ +'use strict'; + +module.exports = function($scope, $http, $uibModalInstance, fusio) { + + $scope.route = { + path: '', + config: [] + }; + + $scope.methods = ['GET', 'POST', 'PUT', 'DELETE']; + $scope.schemas = []; + $scope.actions = []; + + $scope.statuuus = [{ + key: 4, + value: "Development" + }, { + key: 1, + value: "Production" + }, { + key: 2, + value: "Deprecated" + }, { + key: 3, + value: "Closed" + }]; + + $scope.create = function(route) { + var data = angular.copy(route); + + // remove active key + if (angular.isObject(data.config)) { + for (var i = 0; i < data.config.length; i++) { + if (data.config[i].hasOwnProperty('active')) { + delete data.config[i].active; + } + } + } + + $http.post(fusio.baseUrl + 'backend/routes', data) + .then(function(response) { + var data = response.data; + $scope.response = data; + if (data.success === true) { + $uibModalInstance.close(data); + } + }) + .catch(function(response) { + $scope.response = response.data; + }); + }; + + $http.get(fusio.baseUrl + 'backend/action') + .then(function(response) { + $scope.actions = response.data.entry; + }); + + $http.get(fusio.baseUrl + 'backend/schema') + .then(function(response) { + $scope.schemas = response.data.entry; + }); + + $scope.close = function() { + $uibModalInstance.dismiss('cancel'); + }; + + $scope.closeResponse = function() { + $scope.response = null; + }; + + $scope.addVersion = function() { + var versions = []; + for (var i = 0; i < $scope.route.config.length; i++) { + var version = $scope.route.config[i]; + version.active = false; + + versions.push(version); + } + + versions.push($scope.newVersion()); + + $scope.route.config = versions; + }; + + $scope.newVersion = function() { + var version = { + version: $scope.getLatestVersion() + 1, + active: true, + status: 4, + methods: {} + }; + + for (var i = 0; i < $scope.methods.length; i++) { + version.methods[$scope.methods[i]] = {}; + } + + return version; + }; + + $scope.getLatestVersion = function() { + var version = 0; + for (var i = 0; i < $scope.route.config.length; i++) { + var ver = parseInt($scope.route.config[i].version); + if (ver > version) { + version = ver; + } + } + return version; + }; + + $scope.addVersion(); + +}; diff --git a/public/fusio/app/controller/routes/delete.js b/public/fusio/app/controller/routes/delete.js new file mode 100644 index 00000000..9e8635e5 --- /dev/null +++ b/public/fusio/app/controller/routes/delete.js @@ -0,0 +1,29 @@ +'use strict'; + +module.exports = function($scope, $http, $uibModalInstance, fusio, route) { + + $scope.route = route; + + $scope.delete = function(route) { + $http.delete(fusio.baseUrl + 'backend/routes/' + route.id) + .then(function(response) { + var data = response.data; + $scope.response = data; + if (data.success === true) { + $uibModalInstance.close(data); + } + }) + .catch(function(response) { + $scope.response = response.data; + }); + }; + + $scope.close = function() { + $uibModalInstance.dismiss('cancel'); + }; + + $scope.closeResponse = function() { + $scope.response = null; + }; + +}; diff --git a/public/fusio/app/controller/routes/update.js b/public/fusio/app/controller/routes/update.js new file mode 100644 index 00000000..a1a01866 --- /dev/null +++ b/public/fusio/app/controller/routes/update.js @@ -0,0 +1,133 @@ +'use strict'; + +module.exports = function($scope, $http, $uibModalInstance, fusio, route) { + + $scope.route = route; + + $scope.methods = ['GET', 'POST', 'PUT', 'DELETE']; + $scope.schemas = []; + $scope.actions = []; + + $scope.statuuus = [{ + key: 4, + value: "Development" + }, { + key: 1, + value: "Production" + }, { + key: 2, + value: "Deprecated" + }, { + key: 3, + value: "Closed" + }]; + + $scope.update = function(route) { + var data = angular.copy(route); + + // remove active key + if (angular.isObject(data.config)) { + for (var i = 0; i < data.config.length; i++) { + if (data.config[i].hasOwnProperty('active')) { + delete data.config[i].active; + } + } + } + + $http.put(fusio.baseUrl + 'backend/routes/' + route.id, data) + .then(function(response) { + var data = response.data; + $scope.response = data; + if (data.success === true) { + $uibModalInstance.close(data); + } + }) + .catch(function(response) { + $scope.response = response.data; + }); + }; + + $http.get(fusio.baseUrl + 'backend/routes/' + route.id) + .then(function(response) { + var data = response.data; + // check and add missing methods + if (data.config) { + var config = []; + for (var version in data.config) { + var ver = data.config[version]; + var methods = {}; + for (var i = 0; i < $scope.methods.length; i++) { + if (ver.methods.hasOwnProperty($scope.methods[i])) { + methods[$scope.methods[i]] = ver.methods[$scope.methods[i]]; + } else { + methods[$scope.methods[i]] = {}; + } + } + ver.methods = methods; + config.push(ver); + } + data.config = config; + } + + $scope.route = data; + }); + + $http.get(fusio.baseUrl + 'backend/action') + .then(function(response) { + $scope.actions = response.data.entry; + }); + + $http.get(fusio.baseUrl + 'backend/schema') + .then(function(response) { + $scope.schemas = response.data.entry; + }); + + $scope.close = function() { + $uibModalInstance.dismiss('cancel'); + }; + + $scope.closeResponse = function() { + $scope.response = null; + }; + + $scope.addVersion = function() { + var versions = []; + for (var i = 0; i < $scope.route.config.length; i++) { + var version = $scope.route.config[i]; + version.active = false; + + versions.push(version); + } + + versions.push($scope.newVersion()); + + $scope.route.config = versions; + }; + + $scope.newVersion = function() { + var version = { + version: $scope.getLatestVersion() + 1, + active: true, + status: 4, + methods: {} + }; + + for (var i = 0; i < $scope.methods.length; i++) { + version.methods[$scope.methods[i]] = {}; + } + + return version; + }; + + $scope.getLatestVersion = function() { + var version = 0; + for (var i = 0; i < $scope.route.config.length; i++) { + var ver = parseInt($scope.route.config[i].version); + if (ver > version) { + version = ver; + } + } + return version; + }; + +}; diff --git a/public/fusio/app/controller/schema/create.js b/public/fusio/app/controller/schema/create.js new file mode 100644 index 00000000..94896fad --- /dev/null +++ b/public/fusio/app/controller/schema/create.js @@ -0,0 +1,39 @@ +'use strict'; + +module.exports = function($scope, $http, $uibModalInstance, fusio) { + + $scope.schema = { + name: '', + source: '' + }; + + $scope.create = function(schema) { + var data = angular.copy(schema); + + // convert string to json + if (angular.isString(data.source)) { + data.source = JSON.parse(data.source); + } + + $http.post(fusio.baseUrl + 'backend/schema', data) + .then(function(response) { + var data = response.data; + $scope.response = data; + if (data.success === true) { + $uibModalInstance.close(data); + } + }) + .catch(function(response) { + $scope.response = response.data; + }); + }; + + $scope.close = function() { + $uibModalInstance.dismiss('cancel'); + }; + + $scope.closeResponse = function() { + $scope.response = null; + }; + +}; diff --git a/public/fusio/app/controller/schema/delete.js b/public/fusio/app/controller/schema/delete.js new file mode 100644 index 00000000..41b73d97 --- /dev/null +++ b/public/fusio/app/controller/schema/delete.js @@ -0,0 +1,29 @@ +'use strict'; + +module.exports = function($scope, $http, $uibModalInstance, fusio, schema) { + + $scope.schema = schema; + + $scope.delete = function(schema) { + $http.delete(fusio.baseUrl + 'backend/schema/' + schema.id) + .then(function(response) { + var data = response.data; + $scope.response = data; + if (data.success === true) { + $uibModalInstance.close(data); + } + }) + .catch(function(response) { + $scope.response = response.data; + }); + }; + + $scope.close = function() { + $uibModalInstance.dismiss('cancel'); + }; + + $scope.closeResponse = function() { + $scope.response = null; + }; + +}; diff --git a/public/fusio/app/controller/schema/update.js b/public/fusio/app/controller/schema/update.js new file mode 100644 index 00000000..484dcde5 --- /dev/null +++ b/public/fusio/app/controller/schema/update.js @@ -0,0 +1,79 @@ +'use strict'; + +module.exports = function($scope, $http, $uibModalInstance, $uibModal, fusio, schema) { + + $scope.schema = schema; + + $scope.update = function(schema) { + var data = angular.copy(schema); + + // convert string to json + if (angular.isString(data.source)) { + data.source = JSON.parse(data.source); + } + + $http.put(fusio.baseUrl + 'backend/schema/' + schema.id, data) + .then(function(response) { + var data = response.data; + $scope.response = data; + if (data.success === true) { + $uibModalInstance.close(data); + } + }) + .catch(function(response) { + $scope.response = response.data; + }); + }; + + $scope.close = function() { + $uibModalInstance.dismiss('cancel'); + }; + + $scope.closeResponse = function() { + $scope.response = null; + }; + + $scope.preview = function(schema) { + var data = angular.copy(schema); + if (typeof data.source == 'string') { + data.source = JSON.parse(data.source); + } + + $http.put(fusio.baseUrl + 'backend/schema/' + data.id, data) + .then(function(response) { + var data = response.data; + $scope.response = data; + if (data.success === true) { + var modalInstance = $uibModal.open({ + size: 'lg', + backdrop: 'static', + templateUrl: 'app/controller/schema/preview.html', + controller: 'SchemaPreviewCtrl', + resolve: { + schema: function() { + return schema; + } + } + }); + + modalInstance.result.then(function(response) { + }, function() { + }); + } + }) + .catch(function(response) { + $scope.response = response.data; + }); + }; + + $http.get(fusio.baseUrl + 'backend/schema/' + schema.id) + .then(function(response) { + var data = response.data; + if (!angular.isString(data.source)) { + data.source = JSON.stringify(data.source, null, 4); + } + + $scope.schema = data; + }); + +}; diff --git a/public/fusio/app/controller/scope/create.js b/public/fusio/app/controller/scope/create.js new file mode 100644 index 00000000..ba0ac51b --- /dev/null +++ b/public/fusio/app/controller/scope/create.js @@ -0,0 +1,62 @@ +'use strict'; + +module.exports = function($scope, $http, $uibModalInstance, fusio) { + + $scope.scope = { + name: '' + }; + + $scope.routes = []; + + $http.get(fusio.baseUrl + 'backend/routes?count=1024') + .then(function(response) { + $scope.routes = response.data.entry; + }); + + $scope.create = function(scope) { + var data = angular.copy(scope); + + var routes = []; + for (var i = 0; i < $scope.routes.length; i++) { + var methods = []; + if ($scope.routes[i].allowedMethods) { + for (var key in $scope.routes[i].allowedMethods) { + if ($scope.routes[i].allowedMethods[key] === true) { + methods.push(key.toUpperCase()); + } + } + } + + if (methods.length > 0) { + routes.push({ + routeId: $scope.routes[i].id, + allow: true, + methods: methods.join('|') + }); + } + } + + data.routes = routes; + + $http.post(fusio.baseUrl + 'backend/scope', data) + .then(function(response) { + var data = response.data; + $scope.response = data; + if (data.success === true) { + $uibModalInstance.close(data); + } + }) + .catch(function(response) { + $scope.response = response.data; + }); + }; + + $scope.close = function() { + $uibModalInstance.dismiss('cancel'); + }; + + $scope.closeResponse = function() { + $scope.response = null; + }; + +}; diff --git a/public/fusio/app/controller/scope/delete.js b/public/fusio/app/controller/scope/delete.js new file mode 100644 index 00000000..5679503a --- /dev/null +++ b/public/fusio/app/controller/scope/delete.js @@ -0,0 +1,29 @@ +'use strict'; + +module.exports = function($scope, $http, $uibModalInstance, fusio, scope) { + + $scope.scope = scope; + + $scope.delete = function(scope) { + $http.delete(fusio.baseUrl + 'backend/scope/' + scope.id) + .then(function(response) { + var data = response.data; + $scope.response = data; + if (data.success === true) { + $uibModalInstance.close(data); + } + }) + .catch(function(response) { + $scope.response = response.data; + }); + }; + + $scope.close = function() { + $uibModalInstance.dismiss('cancel'); + }; + + $scope.closeResponse = function() { + $scope.response = null; + }; + +}; diff --git a/public/fusio/app/controller/scope/update.js b/public/fusio/app/controller/scope/update.js new file mode 100644 index 00000000..94f4f599 --- /dev/null +++ b/public/fusio/app/controller/scope/update.js @@ -0,0 +1,94 @@ +'use strict'; + +module.exports = function($scope, $http, $uibModalInstance, fusio, scope) { + + $scope.scope = scope; + + $scope.routes = []; + + $scope.loadRoutes = function() { + $http.get(fusio.baseUrl + 'backend/routes?count=1024') + .then(function(response) { + var data = response.data; + var routes = []; + for (var i = 0; i < data.entry.length; i++) { + var route = data.entry[i]; + if ($scope.scope.routes) { + for (var j = 0; j < $scope.scope.routes.length; j++) { + if ($scope.scope.routes[j].routeId == route.id) { + var methods = []; + if ($scope.scope.routes[j].methods) { + methods = $scope.scope.routes[j].methods.split('|'); + } + var allowedMethods = {}; + for (var k = 0; k < methods.length; k++) { + allowedMethods[methods[k].toLowerCase()] = true; + } + + route.allow = $scope.scope.routes[j].allow ? true : false; + route.allowedMethods = allowedMethods; + } + } + } + routes.push(route); + } + $scope.routes = routes; + }); + }; + + $scope.update = function(scope) { + var data = angular.copy(scope); + + var routes = []; + if ($scope.routes) { + for (var i = 0; i < $scope.routes.length; i++) { + var methods = []; + if ($scope.routes[i].allowedMethods) { + for (var key in $scope.routes[i].allowedMethods) { + if ($scope.routes[i].allowedMethods[key] === true) { + methods.push(key.toUpperCase()); + } + } + } + + if (methods.length > 0) { + routes.push({ + routeId: $scope.routes[i].id, + allow: true, + methods: methods.join('|') + }); + } + } + } + + data.routes = routes; + + $http.put(fusio.baseUrl + 'backend/scope/' + scope.id, data) + .then(function(response) { + var data = response.data; + $scope.response = data; + if (data.success === true) { + $uibModalInstance.close(data); + } + }) + .catch(function(response) { + $scope.response = response.data; + }); + }; + + $scope.close = function() { + $uibModalInstance.dismiss('cancel'); + }; + + $scope.closeResponse = function() { + $scope.response = null; + }; + + $http.get(fusio.baseUrl + 'backend/scope/' + scope.id) + .then(function(response) { + $scope.scope = response.data; + + $scope.loadRoutes(); + }); + +}; diff --git a/public/fusio/app/controller/user/create.js b/public/fusio/app/controller/user/create.js new file mode 100644 index 00000000..d1939ef0 --- /dev/null +++ b/public/fusio/app/controller/user/create.js @@ -0,0 +1,66 @@ +'use strict'; + +module.exports = function($scope, $http, $uibModalInstance, fusio) { + + $scope.user = { + status: 0, + name: '', + email: '', + scopes: [] + }; + + $scope.statuuus = [{ + id: 0, + name: 'Consumer' + }, { + id: 1, + name: 'Administrator' + }, { + id: 2, + name: 'Disabled' + }]; + + $scope.scopes = []; + + $http.get(fusio.baseUrl + 'backend/scope?count=1024') + .then(function(response) { + $scope.scopes = response.data.entry; + }); + + $scope.create = function(user) { + var data = angular.copy(user); + + // remove app data + if (data.apps) { + delete data.apps; + } + + // filter scopes + if (data.scopes && angular.isArray(data.scopes)) { + data.scopes = data.scopes.filter(function(value) { + return value !== null; + }); + } + + $http.post(fusio.baseUrl + 'backend/user', data) + .then(function(response) { + var data = response.data; + $scope.response = data; + if (data.success === true) { + $uibModalInstance.close(data); + } + }) + .catch(function(response) { + $scope.response = response.data; + }); + }; + + $scope.close = function() { + $uibModalInstance.dismiss('cancel'); + }; + + $scope.closeResponse = function() { + $scope.response = null; + }; + +}; diff --git a/public/fusio/app/controller/user/delete.js b/public/fusio/app/controller/user/delete.js new file mode 100644 index 00000000..e992b396 --- /dev/null +++ b/public/fusio/app/controller/user/delete.js @@ -0,0 +1,29 @@ +'use strict'; + +module.exports = function($scope, $http, $uibModalInstance, fusio, user) { + + $scope.user = user; + + $scope.delete = function(user) { + $http.delete(fusio.baseUrl + 'backend/user/' + user.id) + .then(function(response) { + var data = response.data; + $scope.response = data; + if (data.success === true) { + $uibModalInstance.close(data); + } + }) + .catch(function(response) { + $scope.response = response.data; + }); + }; + + $scope.close = function() { + $uibModalInstance.dismiss('cancel'); + }; + + $scope.closeResponse = function() { + $scope.response = null; + }; + +}; diff --git a/public/fusio/app/controller/user/update.js b/public/fusio/app/controller/user/update.js new file mode 100644 index 00000000..8e773292 --- /dev/null +++ b/public/fusio/app/controller/user/update.js @@ -0,0 +1,86 @@ +'use strict'; + +module.exports = function($scope, $http, $uibModalInstance, fusio, user) { + + $scope.user = user; + + $scope.statuuus = [{ + id: 0, + name: 'Consumer' + }, { + id: 1, + name: 'Administrator' + }, { + id: 2, + name: 'Disabled' + }]; + + $scope.scopes = []; + + $http.get(fusio.baseUrl + 'backend/scope?count=1024') + .then(function(response) { + $scope.scopes = response.data.entry; + + $scope.loadUser(); + }); + + $scope.update = function(user) { + var data = angular.copy(user); + + // remove app data + if (data.apps) { + delete data.apps; + } + + // filter scopes + if (data.scopes && angular.isArray(data.scopes)) { + data.scopes = data.scopes.filter(function(value) { + return value !== null; + }); + } + + $http.put(fusio.baseUrl + 'backend/user/' + data.id, data) + .then(function(response) { + var data = response.data; + $scope.response = data; + if (data.success === true) { + $uibModalInstance.close(data); + } + }) + .catch(function(response) { + $scope.response = response.data; + }); + }; + + $scope.close = function() { + $uibModalInstance.dismiss('cancel'); + }; + + $scope.closeResponse = function() { + $scope.response = null; + }; + + $scope.loadUser = function() { + $http.get(fusio.baseUrl + 'backend/user/' + user.id) + .then(function(response) { + var data = response.data; + var scopes = []; + if (angular.isArray(data.scopes)) { + for (var i = 0; i < $scope.scopes.length; i++) { + var found = null; + for (var j = 0; j < data.scopes.length; j++) { + if ($scope.scopes[i].name == data.scopes[j]) { + found = $scope.scopes[i].name; + break; + } + } + scopes.push(found); + } + } + data.scopes = scopes; + + $scope.user = data; + }); + }; + +};