diff --git a/.jshintrc b/.jshintrc index cc77b267f..95ed49ba6 100644 --- a/.jshintrc +++ b/.jshintrc @@ -1,4 +1,5 @@ { + "esversion": 6, "passfail" : false, "maxerr" : 100, "browser" : true, @@ -8,7 +9,6 @@ ], "debug" : false, "devel" : true, - "es5" : true, "strict" : false, "globalstrict" : false, "asi" : false, @@ -41,7 +41,7 @@ "sub" : false, "trailing" : true, "white" : false, - "indent" : 4, + "indent" : 2, "globals": { "module": true } diff --git a/remoteappmanager/static/js/admin/admin-resources.js b/remoteappmanager/static/js/admin/admin-resources.js index bc51a6cd0..8b9b86774 100644 --- a/remoteappmanager/static/js/admin/admin-resources.js +++ b/remoteappmanager/static/js/admin/admin-resources.js @@ -3,412 +3,412 @@ var urlUtils = require("urlutils"); var utils = require("utils"); var object_to_query_args = function (obj) { - var keys = Object.keys(obj); - if (keys.length === 0) { - return ""; + var keys = Object.keys(obj); + if (keys.length === 0) { + return ""; + } + + var result = []; + for (var idx in keys) { + var key = keys[idx]; + var value = obj[key]; + var key_enc = encodeURIComponent(key); + if ($.isArray(value)) { + for (var v in value) { + result.push(key_enc+"="+encodeURIComponent(v)); + } + } else { + result.push(key_enc+"="+encodeURIComponent(value)); } + } - var result = []; - for (var idx in keys) { - var key = keys[idx]; - var value = obj[key]; - var key_enc = encodeURIComponent(key); - if ($.isArray(value)) { - for (var v in value) { - result.push(key_enc+"="+encodeURIComponent(v)); - } - } else { - result.push(key_enc+"="+encodeURIComponent(value)); - } - } - - return result.join("&"); + return result.join("&"); }; var API = (function () { - // Object representing the interface to the Web API. - // @param base_url : the url at which to find the web API endpoint. - var self = {}; - self.base_urlpath = "/user/admin/"; - self.default_options = { - contentType: "application/json", - cache: false, - dataType : null, - processData: false, - success: null, - error: null - }; - - self.request = function (req_type, endpoint, body, query_args) { - // Performs a request to the final endpoint - var options = {}; - utils.update(options, self.default_options); - utils.update(options, { - type: req_type, - data: body - }); - - var url = urlUtils.pathJoin( - self.base_urlpath, - "api", "v1", - urlUtils.encodeUriComponents(endpoint) - )+'/'; - - if (query_args) { - url = url + "?" + object_to_query_args(query_args); - } - return $.ajax(url, options); - }; - return self; + // Object representing the interface to the Web API. + // @param base_url : the url at which to find the web API endpoint. + var self = {}; + self.base_urlpath = "/user/admin/"; + self.default_options = { + contentType: "application/json", + cache: false, + dataType : null, + processData: false, + success: null, + error: null + }; + + self.request = function (req_type, endpoint, body, query_args) { + // Performs a request to the final endpoint + var options = {}; + utils.update(options, self.default_options); + utils.update(options, { + type: req_type, + data: body + }); + + var url = urlUtils.pathJoin( + self.base_urlpath, + "api", "v1", + urlUtils.encodeUriComponents(endpoint) + )+'/'; + + if (query_args) { + url = url + "?" + object_to_query_args(query_args); + } + return $.ajax(url, options); + }; + return self; })(); var RestError = function(code, message) { - console.log("Creating error "+code+" message: "+message); - this.code = code; - this.message = message; + console.log("Creating error "+code+" message: "+message); + this.code = code; + this.message = message; }; var fail_handler = function(promise, jqXHR) { - var status = jqXHR.status; - var payload = null; - try { - payload = JSON.parse(jqXHR.responseText); - } catch (e) { - // Suppress any syntax error and discard the payload - } - - var err = new RestError(status, ""); - if (payload !== null) { - utils.update(err, payload); - } - promise.reject(err); + var status = jqXHR.status; + var payload = null; + try { + payload = JSON.parse(jqXHR.responseText); + } catch (e) { + // Suppress any syntax error and discard the payload + } + + var err = new RestError(status, ""); + if (payload !== null) { + utils.update(err, payload); + } + promise.reject(err); }; var create_handler = function(promise, data, textStatus, jqXHR) { - var status = jqXHR.status; - - var payload = null; - try { - payload = JSON.parse(data); - } catch (e) { - // Suppress any syntax error and discard the payload - } - - if (status !== 201) { - // Strange situation in which the call succeeded, but - // not with a 201. Just do our best. - console.log( - "Create succeded but response with status " + - status + - " instead of 201." - ); - promise.reject(status, payload); - return; - } - - var id, location; - try { - location = jqXHR.getResponseHeader('Location'); - var url = urlUtils.parse(location); - var arr = url.pathname.replace(/\/$/, "").split('/'); - id = arr[arr.length - 1]; - } catch (e) { - console.log("Response had invalid or absent Location header"); - promise.reject(status, payload); - return; - } - promise.resolve(id, location); + var status = jqXHR.status; + + var payload = null; + try { + payload = JSON.parse(data); + } catch (e) { + // Suppress any syntax error and discard the payload + } + + if (status !== 201) { + // Strange situation in which the call succeeded, but + // not with a 201. Just do our best. + console.log( + "Create succeded but response with status " + + status + + " instead of 201." + ); + promise.reject(status, payload); + return; + } + + var id, location; + try { + location = jqXHR.getResponseHeader('Location'); + var url = urlUtils.parse(location); + var arr = url.pathname.replace(/\/$/, "").split('/'); + id = arr[arr.length - 1]; + } catch (e) { + console.log("Response had invalid or absent Location header"); + promise.reject(status, payload); + return; + } + promise.resolve(id, location); }; var create_singleton_handler = function(promise, data, textStatus, jqXHR) { - var status = jqXHR.status; - - var payload = null; - try { - payload = JSON.parse(data); - } catch (e) { - // Suppress any syntax error and discard the payload - } - - if (status !== 201) { - // Strange situation in which the call succeeded, but - // not with a 201. Just do our best. - console.log( - "Create succeded but response with status " + - status + - " instead of 201." - ); - promise.reject(status, payload); - return; - } - - var location; - try { - location = jqXHR.getResponseHeader('Location'); - } catch (e) { - console.log("Response had invalid or absent Location header"); - promise.reject(status, payload); - return; - } - promise.resolve(location); + var status = jqXHR.status; + + var payload = null; + try { + payload = JSON.parse(data); + } catch (e) { + // Suppress any syntax error and discard the payload + } + + if (status !== 201) { + // Strange situation in which the call succeeded, but + // not with a 201. Just do our best. + console.log( + "Create succeded but response with status " + + status + + " instead of 201." + ); + promise.reject(status, payload); + return; + } + + var location; + try { + location = jqXHR.getResponseHeader('Location'); + } catch (e) { + console.log("Response had invalid or absent Location header"); + promise.reject(status, payload); + return; + } + promise.resolve(location); }; var update_handler = function(promise, data, textStatus, jqXHR) { - var status = jqXHR.status; - - var payload = null; - try { - payload = JSON.parse(data); - } catch (e) { - // Suppress any syntax error and discard the payload - } - - if (status !== 204) { - // Strange situation in which the call succeeded, but - // not with a 201. Just do our best. - console.log( - "Update succeded but response with status " + - status + - " instead of 204." - ); - promise.reject(status, payload); - return; - } - - promise.resolve(); + var status = jqXHR.status; + + var payload = null; + try { + payload = JSON.parse(data); + } catch (e) { + // Suppress any syntax error and discard the payload + } + + if (status !== 204) { + // Strange situation in which the call succeeded, but + // not with a 201. Just do our best. + console.log( + "Update succeded but response with status " + + status + + " instead of 204." + ); + promise.reject(status, payload); + return; + } + + promise.resolve(); }; var delete_handler = function(promise, data, textStatus, jqXHR) { - var status = jqXHR.status; - var payload = null; - try { - payload = JSON.parse(data); - } catch (e) { - // Suppress any syntax error and discard the payload - } - - if (status !== 204) { - console.log( - "Delete succeded but response with status " + - status + - " instead of 204." - ); - promise.reject(status, payload); - return; - } - promise.resolve(); + var status = jqXHR.status; + var payload = null; + try { + payload = JSON.parse(data); + } catch (e) { + // Suppress any syntax error and discard the payload + } + + if (status !== 204) { + console.log( + "Delete succeded but response with status " + + status + + " instead of 204." + ); + promise.reject(status, payload); + return; + } + promise.resolve(); }; var retrieve_handler = function(promise, data, textStatus, jqXHR) { - var status = jqXHR.status; - - var payload = null; - try { - payload = JSON.parse(jqXHR.responseText); - } catch (e) { - // Suppress any syntax error and discard the payload - } + var status = jqXHR.status; + + var payload = null; + try { + payload = JSON.parse(jqXHR.responseText); + } catch (e) { + // Suppress any syntax error and discard the payload + } + + if (status !== 200) { + console.log( + "Retrieve succeded but response with status " + + status + + " instead of 200." + ); + promise.reject(status, payload); + return; + } + + if (payload === null) { + console.log( + "Retrieve succeded but empty or invalid payload" + ); + promise.reject(status, payload); + return; + } + + promise.resolve(payload); +}; - if (status !== 200) { - console.log( - "Retrieve succeded but response with status " + - status + - " instead of 200." - ); - promise.reject(status, payload); - return; - } +var Resource = function(type) { + this.type = type; + + this.create = function(representation, query_args) { + var body = JSON.stringify(representation); + var promise = $.Deferred(); + + API.request("POST", type, body, query_args) + .done(function(data, textStatus, jqXHR) { + create_handler(promise, data, textStatus, jqXHR); + }) + .fail(function(jqXHR) { + fail_handler(promise, jqXHR); + }); + + return promise; + }; + + this.update = function(id, representation, query_args) { + var body = JSON.stringify(representation); + var promise = $.Deferred(); + + API.request("PUT", urlUtils.pathJoin(type, id), body, query_args) + .done(function(data, textStatus, jqXHR) { + update_handler(promise, data, textStatus, jqXHR); + } + ) + .fail(function(jqXHR) { + fail_handler(promise, jqXHR); + }); + + return promise; + }; + + this.delete = function(id, query_args) { + var promise = $.Deferred(); + + API.request("DELETE", urlUtils.pathJoin(type, id), null, query_args) + .done(function(data, textStatus, jqXHR) { + delete_handler(promise, data, textStatus, jqXHR); + } + ) + .fail(function(jqXHR) { + fail_handler(promise, jqXHR); + }); + + return promise; + }; + + this.retrieve = function(id, query_args) { + var promise = $.Deferred(); + + API.request("GET", urlUtils.pathJoin(type, id), null, query_args) + .done(function(data, textStatus, jqXHR) { + retrieve_handler(promise, data, textStatus, jqXHR); + } + ) + .fail(function(jqXHR) { + fail_handler(promise, jqXHR); + }); + + return promise; + }; + + this.items = function(query_args) { + var promise = $.Deferred(); + + API.request("GET", type, null, query_args) + .done(function(data, textStatus, jqXHR) { + var status = jqXHR.status; + + var payload = null; + try { + payload = JSON.parse(jqXHR.responseText); + } catch (e) { + // Suppress any syntax error and discard the payload + } - if (payload === null) { - console.log( - "Retrieve succeded but empty or invalid payload" - ); - promise.reject(status, payload); - return; - } + if (status !== 200) { + console.log( + "Items retrieve succeded but response with status " + + status + + " instead of 200." + ); + promise.reject(status, payload); + return; + } - promise.resolve(payload); -}; + if (payload === null) { + console.log( + "Items Retrieve succeded but empty or invalid payload" + ); + promise.reject(status, payload); + return; + } -var Resource = function(type) { - this.type = type; - - this.create = function(representation, query_args) { - var body = JSON.stringify(representation); - var promise = $.Deferred(); - - API.request("POST", type, body, query_args) - .done(function(data, textStatus, jqXHR) { - create_handler(promise, data, textStatus, jqXHR); - }) - .fail(function(jqXHR) { - fail_handler(promise, jqXHR); - }); - - return promise; - }; - - this.update = function(id, representation, query_args) { - var body = JSON.stringify(representation); - var promise = $.Deferred(); - - API.request("PUT", urlUtils.pathJoin(type, id), body, query_args) - .done(function(data, textStatus, jqXHR) { - update_handler(promise, data, textStatus, jqXHR); - } - ) - .fail(function(jqXHR) { - fail_handler(promise, jqXHR); - }); - - return promise; - }; - - this.delete = function(id, query_args) { - var promise = $.Deferred(); - - API.request("DELETE", urlUtils.pathJoin(type, id), null, query_args) - .done(function(data, textStatus, jqXHR) { - delete_handler(promise, data, textStatus, jqXHR); - } - ) - .fail(function(jqXHR) { - fail_handler(promise, jqXHR); - }); - - return promise; - }; - - this.retrieve = function(id, query_args) { - var promise = $.Deferred(); - - API.request("GET", urlUtils.pathJoin(type, id), null, query_args) - .done(function(data, textStatus, jqXHR) { - retrieve_handler(promise, data, textStatus, jqXHR); - } - ) - .fail(function(jqXHR) { - fail_handler(promise, jqXHR); - }); - - return promise; - }; - - this.items = function(query_args) { - var promise = $.Deferred(); - - API.request("GET", type, null, query_args) - .done(function(data, textStatus, jqXHR) { - var status = jqXHR.status; - - var payload = null; - try { - payload = JSON.parse(jqXHR.responseText); - } catch (e) { - // Suppress any syntax error and discard the payload - } - - if (status !== 200) { - console.log( - "Items retrieve succeded but response with status " + - status + - " instead of 200." - ); - promise.reject(status, payload); - return; - } - - if (payload === null) { - console.log( - "Items Retrieve succeded but empty or invalid payload" - ); - promise.reject(status, payload); - return; - } - - promise.resolve( - payload.identifiers, - payload.items, - payload.offset, - payload.total); - }) - .fail(function(jqXHR) { - fail_handler(promise, jqXHR); - }); - - return promise; - }; + promise.resolve( + payload.identifiers, + payload.items, + payload.offset, + payload.total); + }) + .fail(function(jqXHR) { + fail_handler(promise, jqXHR); + }); + + return promise; + }; }; var SingletonResource = function(type) { - this.type = type; - this.create = function(representation, query_args) { - var body = JSON.stringify(representation); - var promise = $.Deferred(); - - API.request("POST", type, body, query_args) - .done(function(data, textStatus, jqXHR) { - create_singleton_handler(promise, data, textStatus, jqXHR); - }) - .fail(function(jqXHR) { - fail_handler(promise, jqXHR); - }); - - return promise; - }; - this.update = function(representation, query_args) { - var body = JSON.stringify(representation); - var promise = $.Deferred(); - - API.request("PUT", type, body, query_args) - .done(function(data, textStatus, jqXHR) { - update_handler(promise, data, textStatus, jqXHR); - } - ) - .fail(function(jqXHR) { - fail_handler(promise, jqXHR); - }); - - return promise; - - - }; - - this.delete = function(query_args) { - var promise = $.Deferred(); - - API.request("DELETE", type, null, query_args) - .done(function(data, textStatus, jqXHR) { - delete_handler(promise, data, textStatus, jqXHR); - } - ) - .fail(function(jqXHR) { - fail_handler(promise, jqXHR); - }); - - return promise; - }; - - this.retrieve = function(query_args) { - var promise = $.Deferred(); - - API.request("GET", type, null, query_args) - .done(function(data, textStatus, jqXHR) { - retrieve_handler(promise, data, textStatus, jqXHR); - } - ) - .fail(function(jqXHR) { - fail_handler(promise, jqXHR); - }); - - return promise; - }; + this.type = type; + this.create = function(representation, query_args) { + var body = JSON.stringify(representation); + var promise = $.Deferred(); + + API.request("POST", type, body, query_args) + .done(function(data, textStatus, jqXHR) { + create_singleton_handler(promise, data, textStatus, jqXHR); + }) + .fail(function(jqXHR) { + fail_handler(promise, jqXHR); + }); + + return promise; + }; + this.update = function(representation, query_args) { + var body = JSON.stringify(representation); + var promise = $.Deferred(); + + API.request("PUT", type, body, query_args) + .done(function(data, textStatus, jqXHR) { + update_handler(promise, data, textStatus, jqXHR); + } + ) + .fail(function(jqXHR) { + fail_handler(promise, jqXHR); + }); + + return promise; + + + }; + + this.delete = function(query_args) { + var promise = $.Deferred(); + + API.request("DELETE", type, null, query_args) + .done(function(data, textStatus, jqXHR) { + delete_handler(promise, data, textStatus, jqXHR); + } + ) + .fail(function(jqXHR) { + fail_handler(promise, jqXHR); + }); + + return promise; + }; + + this.retrieve = function(query_args) { + var promise = $.Deferred(); + + API.request("GET", type, null, query_args) + .done(function(data, textStatus, jqXHR) { + retrieve_handler(promise, data, textStatus, jqXHR); + } + ) + .fail(function(jqXHR) { + fail_handler(promise, jqXHR); + }); + + return promise; + }; }; module.exports = { - "Application" : new Resource("applications"), - "Accounting" : new Resource("accounting"), - "User" : new Resource("users"), - "Container" : new Resource("containers"), - "Stats" : new SingletonResource("stats"), + "Application" : new Resource("applications"), + "Accounting" : new Resource("accounting"), + "User" : new Resource("users"), + "Container" : new Resource("containers"), + "Stats" : new SingletonResource("stats"), }; \ No newline at end of file diff --git a/remoteappmanager/static/js/admin/main.js b/remoteappmanager/static/js/admin/main.js index 7d680f022..f76bb889a 100644 --- a/remoteappmanager/static/js/admin/main.js +++ b/remoteappmanager/static/js/admin/main.js @@ -1,39 +1,39 @@ -var _ = require("lodash"); -var Vue = require("vuejs"); -var VueRouter = require("vue-router"); -var VueForm = require("vue-form"); +let _ = require("lodash"); +let Vue = require("vuejs"); +let VueRouter = require("vue-router"); +let VueForm = require("vue-form"); require("toolkit"); -var MainView = require("./vue-components/MainView"); -var ContainersView = require("./vue-components/ContainersView"); -var UsersView = require("./vue-components/UsersView"); -var ApplicationsView = require("./vue-components/ApplicationsView"); -var AccountingView = require("./vue-components/AccountingView"); +let MainView = require("./vue-components/MainView"); +let ContainersView = require("./vue-components/ContainersView"); +let UsersView = require("./vue-components/UsersView"); +let ApplicationsView = require("./vue-components/ApplicationsView"); +let AccountingView = require("./vue-components/AccountingView"); // install router Vue.use(VueRouter); Vue.use(VueForm, { - inputClasses: { - valid: 'form-control-success', - invalid: 'form-control-danger' - } + inputClasses: { + valid: 'form-control-success', + invalid: 'form-control-danger' + } }); Vue.filter("truncate", function(value) { - return _.truncate(value, {'length': 12 }); + return _.truncate(value, {'length': 12 }); }); -var router = new VueRouter({ - routes: [ - { path: '/', component: MainView }, - { path: '/containers', component: ContainersView }, - { path: '/users', component: UsersView }, - { path: '/users/:id/accounting', component: AccountingView, name: "user_accounting" }, - { path: '/applications', component: ApplicationsView } - ] +let router = new VueRouter({ + routes: [ + { path: '/', component: MainView }, + { path: '/containers', component: ContainersView }, + { path: '/users', component: UsersView }, + { path: '/users/:id/accounting', component: AccountingView, name: "user_accounting" }, + { path: '/applications', component: ApplicationsView } + ] }); -var vm; +let vm; vm = new Vue({ - el: "#app", - router: router + el: "#app", + router: router }); diff --git a/remoteappmanager/static/js/admin/vue-components/AccountingView.js b/remoteappmanager/static/js/admin/vue-components/AccountingView.js index 8dd2fb25a..de35a1916 100644 --- a/remoteappmanager/static/js/admin/vue-components/AccountingView.js +++ b/remoteappmanager/static/js/admin/vue-components/AccountingView.js @@ -1,130 +1,127 @@ -var resources = require("admin-resources"); -var NewAccountingDialog = require("./accounting/NewAccountingDialog"); +let resources = require("admin-resources"); +let NewAccountingDialog = require("./accounting/NewAccountingDialog"); module.exports = { - components: { - 'new-accounting-dialog': NewAccountingDialog - }, + components: { + 'new-accounting-dialog': NewAccountingDialog + }, - template: - '' + - '
Accounting for user {{ $route.params.id }}
' + - '
' + - '
' + - ' Error: {{communicationError}}' + - '
' + - ' ' + - ' ' + - ' ' + - ' ' + - ' ' + - '
Do you want to remove accounting ' + - ' {{ removeAccountingDialog.accountingToRemove }}?' + - '
' + - '
' + - '
' + - '
', + template: + ` +
Accounting for user {{ $route.params.id }}
+
+
+ Error: {{communicationError}} +
+ + + + + +
Do you want to remove accounting + {{ removeAccountingDialog.accountingToRemove }}? +
+
+
+
`, - data: function () { - var self = this; - return { - table: { - headers: [ - "ID", "Image", "Workspace", "Vol. source", "Vol. target", "Readonly" - ], - rows: [], - globalActions: [{ - label: "Create New Entry", - callback: function() { self.newAccountingDialog.show = true; } - }], - rowActions: [{ - label: "Remove", - callback: this.removeAction - }] - }, + data: function () { + return { + table: { + headers: [ + "ID", "Image", "Workspace", "Vol. source", "Vol. target", "Readonly" + ], + rows: [], + globalActions: [{ + label: "Create New Entry", + callback: () => { this.newAccountingDialog.show = true; } + }], + rowActions: [{ + label: "Remove", + callback: this.removeAction + }] + }, - newAccountingDialog: { - show: false, - userId: this.$route.params.id - }, + newAccountingDialog: { + show: false, + userId: this.$route.params.id + }, - removeAccountingDialog: { - show: false, - accountingToRemove: null - }, + removeAccountingDialog: { + show: false, + accountingToRemove: null + }, - communicationError: null - }; - }, + communicationError: null + }; + }, - mounted: function () { - this.updateTable(); - }, + mounted: function () { + this.updateTable(); + }, - methods: { - updateTable: function() { - var self = this; - this.communicationError = null; - resources.Accounting.items({filter: JSON.stringify({user_id: this.$route.params.id })}) - .done(function (identifiers, items) { - self.table.rows = []; - identifiers.forEach(function(id) { - var item = items[id]; - self.table.rows.push([ - id, - item.image_name, - item.allow_home, - item.volume_source, - item.volume_target, - item.volume_mode === "ro" - ]); - }); - }) - .fail(function () { - self.communicationError = "The request could not be executed successfully"; - }); - }, + methods: { + updateTable: function() { + this.communicationError = null; + resources.Accounting.items({filter: JSON.stringify({user_id: this.$route.params.id })}) + .done((identifiers, items) => { + this.table.rows = []; + identifiers.forEach((id) => { + let item = items[id]; + this.table.rows.push([ + id, + item.image_name, + item.allow_home, + item.volume_source, + item.volume_target, + item.volume_mode === "ro" + ]); + }); + }) + .fail(() => { + this.communicationError = "The request could not be executed successfully"; + }); + }, - newAccountingCreated: function() { - this.newAccountingDialog.show = false; - this.updateTable(); - }, + newAccountingCreated: function() { + this.newAccountingDialog.show = false; + this.updateTable(); + }, - removeAction: function(row) { - this.removeAccountingDialog.accountingToRemove = row[0]; - this.removeAccountingDialog.show = true; - }, + removeAction: function(row) { + this.removeAccountingDialog.accountingToRemove = row[0]; + this.removeAccountingDialog.show = true; + }, - closeRemoveAccountingDialog: function() { - this.removeAccountingDialog.show = false; - this.removeAccountingDialog.accountingToRemove = null; - }, + closeRemoveAccountingDialog: function() { + this.removeAccountingDialog.show = false; + this.removeAccountingDialog.accountingToRemove = null; + }, - removeAccounting: function () { - var self = this; - resources.Accounting.delete(this.removeAccountingDialog.accountingToRemove) - .done(function () { - self.closeRemoveAccountingDialog(); - self.updateTable(); - }) - .fail(function () { - self.closeRemoveAccountingDialog(); - self.communicationError = "The request could not be executed successfully"; - }); - } + removeAccounting: function () { + resources.Accounting.delete(this.removeAccountingDialog.accountingToRemove) + .done(() => { + this.closeRemoveAccountingDialog(); + this.updateTable(); + }) + .fail(() => { + this.closeRemoveAccountingDialog(); + this.communicationError = "The request could not be executed successfully"; + }); } + } }; diff --git a/remoteappmanager/static/js/admin/vue-components/ApplicationsView.js b/remoteappmanager/static/js/admin/vue-components/ApplicationsView.js index 82b85d25d..c0d6cc2ed 100644 --- a/remoteappmanager/static/js/admin/vue-components/ApplicationsView.js +++ b/remoteappmanager/static/js/admin/vue-components/ApplicationsView.js @@ -1,133 +1,130 @@ -var resources = require("admin-resources"); -var NewApplicationDialog = require("./applications/NewApplicationDialog"); +let resources = require("admin-resources"); +let NewApplicationDialog = require("./applications/NewApplicationDialog"); module.exports = { - components: { - 'new-application-dialog': NewApplicationDialog - }, + components: { + 'new-application-dialog': NewApplicationDialog + }, - template: - '' + - '
' + - '
' + - ' Error: {{communicationError}}' + - '
' + - ' ' + - ' ' + - ' ' + - ' ' + - ' ' + - '
Do you want to remove Application ' + - ' {{removeApplicationDialog.applicationToRemove.name}} ' + - ' ({{removeApplicationDialog.applicationToRemove.id}})
' + - '
' + - '
' + - '
', + template: + ` +
+
+ Error: {{communicationError}} +
+ + + - data: function () { - var self=this; - return { - table: { - headers: ["ID", "Image"], - rows: [], - globalActions: [{ - label: "Create New Entry", - callback: function() { self.newApplicationDialog.show = true; } - }], - rowActions: [{ - label: "Remove", - callback: this.removeAction - }] - }, + +
Do you want to remove Application + {{removeApplicationDialog.applicationToRemove.name}} + ({{removeApplicationDialog.applicationToRemove.id}})
+
+
+
`, - newApplicationDialog: { - show: false - }, + data: function () { + return { + table: { + headers: ["ID", "Image"], + rows: [], + globalActions: [{ + label: "Create New Entry", + callback: () => { this.newApplicationDialog.show = true; } + }], + rowActions: [{ + label: "Remove", + callback: this.removeAction + }] + }, - removeApplicationDialog: { - show: false, - applicationToRemove: { - id: null, - name: "" - } - }, + newApplicationDialog: { + show: false + }, - communicationError: null - }; - }, + removeApplicationDialog: { + show: false, + applicationToRemove: { + id: null, + name: "" + } + }, - mounted: function () { - this.updateTable(); - }, + communicationError: null + }; + }, - methods: { - updateTable: function() { - var self = this; - this.communicationError = null; - resources.Application.items() - .done(function (identifiers, items) { - self.table.rows = []; - identifiers.forEach(function(id) { - var item = items[id]; - self.table.rows.push([ - id, - item.image_name - ]); - }); - }) - .fail(function () { - self.communicationError = "The request could not be executed successfully"; - }); - }, + mounted: function () { + this.updateTable(); + }, - newApplicationCreated: function() { - this.newApplicationDialog.show = false; - this.updateTable(); - }, + methods: { + updateTable: function() { + this.communicationError = null; + resources.Application.items() + .done((identifiers, items) => { + this.table.rows = []; + identifiers.forEach((id) => { + let item = items[id]; + this.table.rows.push([ + id, + item.image_name + ]); + }); + }) + .fail(() => { + this.communicationError = "The request could not be executed successfully"; + }); + }, - newApplicationDialogClosed: function() { - this.newApplicationDialog.show = false; - }, + newApplicationCreated: function() { + this.newApplicationDialog.show = false; + this.updateTable(); + }, - removeAction: function(row) { - this.removeApplicationDialog.applicationToRemove = { - id: row[0], - name: row[1] - }; - this.removeApplicationDialog.show = true; - }, + newApplicationDialogClosed: function() { + this.newApplicationDialog.show = false; + }, - removeApplication: function () { - var self = this; - resources.Application.delete(this.removeApplicationDialog.applicationToRemove.id) - .done(function () { - self.closeRemoveApplicationDialog(); - self.updateTable(); - }) - .fail(function () { - self.closeRemoveApplicationDialog(); - this.communicationError = "The request could not be executed successfully"; - }); - }, - closeRemoveApplicationDialog: function() { - this.removeApplicationDialog.show = false; - this.removeApplicationDialog.applicationToRemove = { - name: "", - id: null - }; - } + removeAction: function(row) { + this.removeApplicationDialog.applicationToRemove = { + id: row[0], + name: row[1] + }; + this.removeApplicationDialog.show = true; + }, + + removeApplication: function () { + resources.Application.delete(this.removeApplicationDialog.applicationToRemove.id) + .done(() => { + this.closeRemoveApplicationDialog(); + this.updateTable(); + }) + .fail(() => { + this.closeRemoveApplicationDialog(); + this.communicationError = "The request could not be executed successfully"; + }); + }, + closeRemoveApplicationDialog: function() { + this.removeApplicationDialog.show = false; + this.removeApplicationDialog.applicationToRemove = { + name: "", + id: null + }; } + } }; diff --git a/remoteappmanager/static/js/admin/vue-components/ContainersView.js b/remoteappmanager/static/js/admin/vue-components/ContainersView.js index 7a2c067ea..6869d1e78 100644 --- a/remoteappmanager/static/js/admin/vue-components/ContainersView.js +++ b/remoteappmanager/static/js/admin/vue-components/ContainersView.js @@ -1,92 +1,90 @@ -var resources = require("admin-resources"); +let resources = require("admin-resources"); module.exports = { - template: - '' + - '
' + - ' Error: {{communicationError}}' + - '
' + - ' ' + - ' ' + - ' ' + - '
Do you want to stop container {{ stopContainerDialog.containerToStop }}?
' + - '
' + - '
', + template: + ` +
+ Error: {{communicationError}} +
+ + + +
Do you want to stop container {{ stopContainerDialog.containerToStop }}?
+
+
`, - data: function () { - return { - table: { - headers: ["URL ID", "User", "Image", "Docker ID", "Mapping ID"], - rows: [], - rowActions: [{ - label: "Stop", - callback: this.stopAction - }] - }, - stopContainerDialog: { - show: false, - containerToStop: null - }, - communicationError: null - }; - }, + data: function () { + return { + table: { + headers: ["URL ID", "User", "Image", "Docker ID", "Mapping ID"], + rows: [], + rowActions: [{ + label: "Stop", + callback: this.stopAction + }] + }, + stopContainerDialog: { + show: false, + containerToStop: null + }, + communicationError: null + }; + }, - mounted: function () { - this.updateTable(); - }, + mounted: function () { + this.updateTable(); + }, - methods: { - updateTable: function() { - var self = this; - this.communicationError = null; - resources.Container.items() - .done(function (identifiers, items) { - self.table.rows = []; - identifiers.forEach(function(id) { - var item = items[id]; - self.table.rows.push([ - id, - item.user, - item.image_name, - item.docker_id, - item.mapping_id - ]); - }); - }) - .fail(function () { - self.communicationError = "The request could not be executed successfully"; - }); - }, + methods: { + updateTable: function() { + this.communicationError = null; + resources.Container.items() + .done((identifiers, items) => { + this.table.rows = []; + identifiers.forEach((id) => { + let item = items[id]; + this.table.rows.push([ + id, + item.user, + item.image_name, + item.docker_id, + item.mapping_id + ]); + }); + }) + .fail(() => { + this.communicationError = "The request could not be executed successfully"; + }); + }, - stopAction: function(row) { - this.stopContainerDialog.containerToStop = row[0]; - this.stopContainerDialog.show = true; - }, + stopAction: function(row) { + this.stopContainerDialog.containerToStop = row[0]; + this.stopContainerDialog.show = true; + }, - stopContainer: function () { - var self = this; - resources.Container.delete(this.stopContainerDialog.containerToStop) - .done(function () { - self.updateTable(); - self.closeStopContainerDialog(); - }) - .fail(function () { - self.closeStopContainerDialog(); - self.communicationError = "The request could not be executed successfully"; - }); - }, + stopContainer: function () { + resources.Container.delete(this.stopContainerDialog.containerToStop) + .done(() => { + this.updateTable(); + this.closeStopContainerDialog(); + }) + .fail(() => { + this.closeStopContainerDialog(); + this.communicationError = "The request could not be executed successfully"; + }); + }, - closeStopContainerDialog: function() { - this.stopContainerDialog.show = false; - this.stopContainerDialog.containerToStop = null; - } + closeStopContainerDialog: function() { + this.stopContainerDialog.show = false; + this.stopContainerDialog.containerToStop = null; } + } }; diff --git a/remoteappmanager/static/js/admin/vue-components/MainView.js b/remoteappmanager/static/js/admin/vue-components/MainView.js index b82cba9e4..daf4eba75 100644 --- a/remoteappmanager/static/js/admin/vue-components/MainView.js +++ b/remoteappmanager/static/js/admin/vue-components/MainView.js @@ -1,65 +1,65 @@ -var resources = require("admin-resources"); +let resources = require("admin-resources"); module.exports = { - template: - '
' + - '
' + - '
' + - '
Statistics
' + - '
' + - '
' + - ' Error: {{communicationError}}' + - '
' + - '
' + - '
' + - '
Realm
' + - '
{{ realm }}
' + - '
' + - '
' + - '
Total users
' + - '
{{ num_total_users }}
' + - '
' + - '
' + - '
Number of applications
' + - '
{{ num_applications }}
' + - '
' + - '
' + - '
' + - '
Active users
' + - '
{{ num_active_users }}
' + - '
' + - '
' + - '
Running containers
' + - '
{{ num_running_containers }}
' + - '
' + - '
' + - '
' + - '
' + - '
' + - '
', + template: + `
+
+
+
Statistics
+
+
+ Error: {{communicationError}} +
+
+
+
Realm
+
{{ realm }}
+
+
+
Total users
+
{{ num_total_users }}
+
+
+
Number of applications
+
{{ num_applications }}
+
+
+
+
Active users
+
{{ num_active_users }}
+
+
+
Running containers
+
{{ num_running_containers }}
+
+
+
+
+
+
`, - data: function() { - return { - communicationError: null, - realm: "", - num_total_users: "", - num_applications: "", - num_active_users: "", - num_running_containers: "" - }; - }, + data: function() { + return { + communicationError: null, + realm: "", + num_total_users: "", + num_applications: "", + num_active_users: "", + num_running_containers: "" + }; + }, - mounted: function() { - resources.Stats.retrieve() - .done(function(rep) { - this.realm = rep.realm; - this.num_total_users = rep.num_total_users; - this.num_applications = rep.num_applications; - this.num_active_users = rep.num_active_users; - this.num_running_containers = rep.num_running_containers; - }.bind(this)) - .fail(function() { - this.communicationError = "The request could not be executed successfully"; - }.bind(this)); - } + mounted: function() { + resources.Stats.retrieve() + .done((rep) => { + this.realm = rep.realm; + this.num_total_users = rep.num_total_users; + this.num_applications = rep.num_applications; + this.num_active_users = rep.num_active_users; + this.num_running_containers = rep.num_running_containers; + }) + .fail(() => { + this.communicationError = "The request could not be executed successfully"; + }); + } }; diff --git a/remoteappmanager/static/js/admin/vue-components/UsersView.js b/remoteappmanager/static/js/admin/vue-components/UsersView.js index b915f1d89..1b3403b83 100644 --- a/remoteappmanager/static/js/admin/vue-components/UsersView.js +++ b/remoteappmanager/static/js/admin/vue-components/UsersView.js @@ -1,130 +1,127 @@ -var resources = require("admin-resources"); -var NewUserDialog = require("./users/NewUserDialog"); +let resources = require("admin-resources"); +let NewUserDialog = require("./users/NewUserDialog"); module.exports = { - components: { - 'new-user-dialog': NewUserDialog, - }, + components: { + 'new-user-dialog': NewUserDialog, + }, - template: - '' + - '
' + - ' Error: {{communicationError}}' + - '
' + - ' ' + - ' ' + - ' ' + - ' ' + - '
Do you want to remove User {{removeUserDialog.userToRemove.name}} ' + - ' ({{removeUserDialog.userToRemove.id}})
' + - '
' + - '
', + template: + ` +
+ Error: {{communicationError}} +
+ + + + +
Do you want to remove User {{removeUserDialog.userToRemove.name}} + ({{removeUserDialog.userToRemove.id}})
+
+
`, - data: function () { - var self = this; - return { - table: { - headers: ["ID", "Username"], - rows: [], - globalActions: [{ - label: "Create New Entry", - callback: function() { self.newUserDialog.show = true; } - }], - rowActions: [{ - label: "Policies", - callback: this.showPolicyAction, - type: "info" - }, { - label: "Remove", - callback: this.removeAction - }] - }, - users: [], - newUserDialog: { - show: false - }, - removeUserDialog: { - show: false, - userToRemove: { - id: null, - name: "" - } - }, - communicationError: null - }; - }, + data: function () { + return { + table: { + headers: ["ID", "Username"], + rows: [], + globalActions: [{ + label: "Create New Entry", + callback: () => { this.newUserDialog.show = true; } + }], + rowActions: [{ + label: "Policies", + callback: this.showPolicyAction, + type: "info" + }, { + label: "Remove", + callback: this.removeAction + }] + }, + users: [], + newUserDialog: { + show: false + }, + removeUserDialog: { + show: false, + userToRemove: { + id: null, + name: "" + } + }, + communicationError: null + }; + }, - mounted: function () { - this.updateTable(); - }, + mounted: function () { + this.updateTable(); + }, - methods: { - updateTable: function() { - var self = this; - this.communicationError = null; - resources.User.items() - .done(function (identifiers, items){ - self.table.rows = []; - identifiers.forEach(function(id) { - var item = items[id]; - self.table.rows.push([ - id, - item.name - ]); - }); - }) - .fail(function () { - self.communicationError = "The request could not be executed successfully"; - }); - }, + methods: { + updateTable: function() { + this.communicationError = null; + resources.User.items() + .done((identifiers, items) => { + this.table.rows = []; + identifiers.forEach((id) => { + let item = items[id]; + this.table.rows.push([ + id, + item.name + ]); + }); + }) + .fail(() => { + this.communicationError = "The request could not be executed successfully"; + }); + }, - newUserCreated: function() { - this.newUserDialog.show = false; - this.updateTable(); - }, + newUserCreated: function() { + this.newUserDialog.show = false; + this.updateTable(); + }, - showPolicyAction: function(row) { - this.$router.push({ - name: 'user_accounting', - params: { id: row[0] } - }); - }, + showPolicyAction: function(row) { + this.$router.push({ + name: 'user_accounting', + params: { id: row[0] } + }); + }, - removeAction: function(row) { - this.removeUserDialog.userToRemove.id = row[0]; - this.removeUserDialog.userToRemove.name = row[1]; - this.removeUserDialog.show = true; - }, + removeAction: function(row) { + this.removeUserDialog.userToRemove.id = row[0]; + this.removeUserDialog.userToRemove.name = row[1]; + this.removeUserDialog.show = true; + }, - closeRemoveUserDialog: function() { - this.removeUserDialog.show = false; - this.removeUserDialog.userToRemove = { - id: null, - name: "" - }; - }, + closeRemoveUserDialog: function() { + this.removeUserDialog.show = false; + this.removeUserDialog.userToRemove = { + id: null, + name: "" + }; + }, - removeUser: function () { - var self = this; - resources.User.delete(this.removeUserDialog.userToRemove.id) - .done(function() { - self.closeRemoveUserDialog(); - self.updateTable(); - }) - .fail(function() { - self.closeRemoveUserDialog(); - }); - } + removeUser: function () { + resources.User.delete(this.removeUserDialog.userToRemove.id) + .done(() => { + this.closeRemoveUserDialog(); + this.updateTable(); + }) + .fail(() => { + this.closeRemoveUserDialog(); + }); } + } }; diff --git a/remoteappmanager/static/js/admin/vue-components/accounting/NewAccountingDialog.js b/remoteappmanager/static/js/admin/vue-components/accounting/NewAccountingDialog.js index 2da67a9df..87374dd34 100644 --- a/remoteappmanager/static/js/admin/vue-components/accounting/NewAccountingDialog.js +++ b/remoteappmanager/static/js/admin/vue-components/accounting/NewAccountingDialog.js @@ -1,150 +1,150 @@ -var resources = require("admin-resources"); +let resources = require("admin-resources"); module.exports = { - template: - ' ' + - ' ' + - ' ' + - '', - - props: ['show', "userId"], - - data: function () { - return { - formstate: {}, - crossValidationError: false, - communicationError: null, - model: { - image_name: '', - allow_home: false, - volume_source: '', - volume_target: '', - volume_readonly: false, - volume_source_target: [] - } - }; + template: + ` + + + `, + + props: ['show', "userId"], + + data: function () { + return { + formstate: {}, + crossValidationError: false, + communicationError: null, + model: { + image_name: '', + allow_home: false, + volume_source: '', + volume_target: '', + volume_readonly: false, + volume_source_target: [] + } + }; + }, + + methods: { + close: function () { + this.$emit('closed'); }, - methods: { - close: function () { - this.$emit('closed'); - }, - - fieldClassName: function (field) { - if (!field) { - return ''; - } - if ((field.$dirty || field.$submitted) && field.$invalid) { - return 'has-error'; - } else { - return ''; - } - }, - - createNewAccounting: function () { - var model = this.model; - var formstate = this.formstate; - - if (formstate.$invalid) { - return; - } - if ((model.volume_source.length === 0 && model.volume_target.length !== 0) || - (model.volume_source.length !== 0 && model.volume_target.length === 0)) { - this.crossValidationError = true; - return; - } - - var rep = { - user_id: this.userId, - image_name: this.model.image_name, - allow_home: this.model.allow_home, - volume_source: this.model.volume_source, - volume_target: this.model.volume_target, - volume_mode: (model.volume_readonly ? "ro" : "rw") - }; - - resources.Accounting.create(rep) - .done(function () { - this.$emit('created'); - }.bind(this)) - .fail(function () { - this.communicationError = "The request could not be executed successfully"; - }.bind(this)); - }, - - reset: function () { - Object.assign(this.$data, this.$options.data()); - }, - - validatePath: function(value) { - return (value.length === 0 || value[0] === '/'); - } + fieldClassName: function (field) { + if (!field) { + return ''; + } + if ((field.$dirty || field.$submitted) && field.$invalid) { + return 'has-error'; + } else { + return ''; + } }, - watch: { - "show": function (value) { - if (value) { - this.reset(); - } - }, - "model.volume_source": function() { - delete this.formstate.volume_source.$error.volumesInconsistent; - delete this.formstate.volume_target.$error.volumesInconsistent; - }, - "model.volume_target": function() { - delete this.formstate.volume_source.$error.volumesInconsistent; - delete this.formstate.volume_target.$error.volumesInconsistent; - } + createNewAccounting: function () { + let model = this.model; + let formstate = this.formstate; + + if (formstate.$invalid) { + return; + } + if ((model.volume_source.length === 0 && model.volume_target.length !== 0) || + (model.volume_source.length !== 0 && model.volume_target.length === 0)) { + this.crossValidationError = true; + return; + } + + let rep = { + user_id: this.userId, + image_name: this.model.image_name, + allow_home: this.model.allow_home, + volume_source: this.model.volume_source, + volume_target: this.model.volume_target, + volume_mode: (model.volume_readonly ? "ro" : "rw") + }; + + resources.Accounting.create(rep) + .done(() => { + this.$emit('created'); + }) + .fail(() => { + this.communicationError = "The request could not be executed successfully"; + }); + }, + + reset: function () { + Object.assign(this.$data, this.$options.data()); + }, + + validatePath: function(value) { + return (value.length === 0 || value[0] === '/'); + } + }, + + watch: { + "show": function (value) { + if (value) { + this.reset(); + } + }, + "model.volume_source": function() { + delete this.formstate.volume_source.$error.volumesInconsistent; + delete this.formstate.volume_target.$error.volumesInconsistent; + }, + "model.volume_target": function() { + delete this.formstate.volume_source.$error.volumesInconsistent; + delete this.formstate.volume_target.$error.volumesInconsistent; } + } }; diff --git a/remoteappmanager/static/js/admin/vue-components/applications/NewApplicationDialog.js b/remoteappmanager/static/js/admin/vue-components/applications/NewApplicationDialog.js index 85f45aa72..2c8e2ed2f 100644 --- a/remoteappmanager/static/js/admin/vue-components/applications/NewApplicationDialog.js +++ b/remoteappmanager/static/js/admin/vue-components/applications/NewApplicationDialog.js @@ -1,80 +1,80 @@ -var resources = require("admin-resources"); +let resources = require("admin-resources"); module.exports = { - template: - ' ' + - ' ' + - ' ' + - ' ', + template: + ` + + + `, - props: ['show'], + props: ['show'], - data: function () { - return { - formstate: {}, - communicationError: null, - model: { - name: '' - } - }; - }, - - methods: { - close: function () { - this.$emit('closed'); - }, + data: function () { + return { + formstate: {}, + communicationError: null, + model: { + name: '' + } + }; + }, - fieldClassName: function (field) { - if (!field) { - return ''; - } - if ((field.$touched || field.$submitted) && field.$invalid) { - return 'has-error'; - } else { - return ''; - } - }, + methods: { + close: function () { + this.$emit('closed'); + }, - createNewApplication: function () { - if (!this.formstate.$valid) { - return; - } - resources.Application.create({image_name: this.model.name}) - .done(function () { - this.$emit('created'); - }.bind(this)) - .fail(function () { - this.communicationError = "The request could not be executed successfully"; - }.bind(this)); - }, + fieldClassName: function (field) { + if (!field) { + return ''; + } + if ((field.$touched || field.$submitted) && field.$invalid) { + return 'has-error'; + } else { + return ''; + } + }, - reset: function () { - Object.assign(this.$data, this.$options.data()); - } + createNewApplication: function () { + if (!this.formstate.$valid) { + return; + } + resources.Application.create({image_name: this.model.name}) + .done(() => { + this.$emit('created'); + }) + .fail(() => { + this.communicationError = "The request could not be executed successfully"; + }); }, - watch: { - "show": function (value) { - if (value) { - this.reset(); - } - } + reset: function () { + Object.assign(this.$data, this.$options.data()); + } + }, + + watch: { + "show": function (value) { + if (value) { + this.reset(); + } } + } }; diff --git a/remoteappmanager/static/js/admin/vue-components/users/NewUserDialog.js b/remoteappmanager/static/js/admin/vue-components/users/NewUserDialog.js index 46d481d36..832a24265 100644 --- a/remoteappmanager/static/js/admin/vue-components/users/NewUserDialog.js +++ b/remoteappmanager/static/js/admin/vue-components/users/NewUserDialog.js @@ -1,76 +1,76 @@ -var resources = require("admin-resources"); +let resources = require("admin-resources"); module.exports = { - template: - '' + - ' ' + - ' ' + - '', + template: + ` + + + `, - props: ['show'], + props: ['show'], - data: function () { - return { - formstate: {}, - model: { - name: '' - } - }; - }, - - methods: { - close: function () { - this.$emit('closed'); - }, + data: function () { + return { + formstate: {}, + model: { + name: '' + } + }; + }, - fieldClassName: function (field) { - if (!field) { - return ''; - } - if ((field.$touched || field.$submitted) && field.$invalid) { - return 'has-error'; - } else { - return ''; - } - }, + methods: { + close: function () { + this.$emit('closed'); + }, - createNewUser: function () { - if (!this.formstate.$valid) { - return; - } - resources.User.create({name: this.model.name}) - .done((function () { - this.$emit('created'); - }).bind(this)) - .fail(function () { - this.$emit("closed"); - }.bind(this)); - }, + fieldClassName: function (field) { + if (!field) { + return ''; + } + if ((field.$touched || field.$submitted) && field.$invalid) { + return 'has-error'; + } else { + return ''; + } + }, - reset: function () { - Object.assign(this.$data, this.$options.data()); - } + createNewUser: function () { + if (!this.formstate.$valid) { + return; + } + resources.User.create({name: this.model.name}) + .done(() => { + this.$emit('created'); + }) + .fail(() => { + this.$emit("closed"); + }); }, - watch: { - "show": function (value) { - if (value) { - this.reset(); - } - } + reset: function () { + Object.assign(this.$data, this.$options.data()); + } + }, + + watch: { + "show": function (value) { + if (value) { + this.reset(); + } } + } }; diff --git a/remoteappmanager/static/js/gamodule.js b/remoteappmanager/static/js/gamodule.js index cd71bd96e..c74361bd7 100644 --- a/remoteappmanager/static/js/gamodule.js +++ b/remoteappmanager/static/js/gamodule.js @@ -3,30 +3,32 @@ // matching to prevent loading. function init() { - if (window.apidata.analytics !== undefined) { - window.ga('create', window.apidata.analytics.tracking_id, 'auto'); - } else { - window.ga = function() {}; - } + if (window.apidata.analytics !== undefined) { + window.ga('create', window.apidata.analytics.tracking_id, 'auto'); + } else { + window.ga = function() {}; + } - return function() { - window.ga.apply(this, arguments); - }; + return function() { + window.ga.apply(this, arguments); + }; } -var GaObserver = function() { +class GaObserver { + constructor() { this.ga = init(); -}; + } -GaObserver.prototype.triggerApplicationStarting = function(name) { + triggerApplicationStarting(name) { this.ga("send", "event", { - eventCategory: "Application", - eventAction: "start", - eventLabel: name + eventCategory: "Application", + eventAction: "start", + eventLabel: name }); -}; + } +} module.exports = { - init: init, // For testing purpose - GaObserver: GaObserver + init, // For testing purpose + GaObserver }; diff --git a/remoteappmanager/static/js/urlutils.js b/remoteappmanager/static/js/urlutils.js index 700c7400b..3fac1dd81 100644 --- a/remoteappmanager/static/js/urlutils.js +++ b/remoteappmanager/static/js/urlutils.js @@ -5,46 +5,46 @@ // Modifications Copyright (c) Juptyer Development Team. // Distributed under the terms of the Modified BSD License. -var pathJoin = function () { - // join a sequence of url components with '/' - var url = '', i = 0; +let pathJoin = function () { + // join a sequence of url components with '/' + let url = '', i = 0; - for (i = 0; i < arguments.length; i += 1) { - if (arguments[i] === '') { - continue; - } - if (url.length > 0 && url[url.length-1] !== '/') { - url = url + '/' + arguments[i]; - } else { - url = url + arguments[i]; - } + for (i = 0; i < arguments.length; i += 1) { + if (arguments[i] === '') { + continue; } - url = url.replace(/\/\/+/, '/'); - return url; + if (url.length > 0 && url[url.length-1] !== '/') { + url = url + '/' + arguments[i]; + } else { + url = url + arguments[i]; + } + } + url = url.replace(/\/\/+/, '/'); + return url; }; -var parse = function (url) { - // an `a` element with an href allows attr-access to the parsed segments of a URL - // a = parse_url("http://localhost:8888/path/name#hash") - // a.protocol = "http:" - // a.host = "localhost:8888" - // a.hostname = "localhost" - // a.port = 8888 - // a.pathname = "/path/name" - // a.hash = "#hash" - var a = document.createElement("a"); - a.href = url; - return a; +let parse = function (url) { + // an `a` element with an href allows attr-access to the parsed segments of a URL + // a = parse_url("http://localhost:8888/path/name#hash") + // a.protocol = "http:" + // a.host = "localhost:8888" + // a.hostname = "localhost" + // a.port = 8888 + // a.pathname = "/path/name" + // a.hash = "#hash" + let a = document.createElement("a"); + a.href = url; + return a; }; -var encodeUriComponents = function (uri) { - // encode just the components of a multi-segment uri, - // leaving '/' separators - return uri.split('/').map(encodeURIComponent).join('/'); +let encodeUriComponents = function (uri) { + // encode just the components of a multi-segment uri, + // leaving '/' separators + return uri.split('/').map(encodeURIComponent).join('/'); }; module.exports = { - pathJoin: pathJoin, - encodeUriComponents: encodeUriComponents, - parse: parse + pathJoin, + encodeUriComponents, + parse }; diff --git a/remoteappmanager/static/js/user/configurables.js b/remoteappmanager/static/js/user/configurables.js index 1a1f20e83..f248fe2d6 100644 --- a/remoteappmanager/static/js/user/configurables.js +++ b/remoteappmanager/static/js/user/configurables.js @@ -1,57 +1,59 @@ -var Vue = require("vuejs"); -var utils = require("utils"); - -var resolutionTag = 'resolution'; -var resolutionComponent = Vue.component(resolutionTag + '-component', { - // Your configurable must have a "configDict" property from the model - props: ['configDict'], - - template: - '
' + - ' ' + - ' ' + - '
', - - data: function() { - return { - resolution: this.configDict.resolution, - resolutionOptions: ['Window', '1920x1080', '1280x1024', '1280x800', '1024x768'] - }; - }, - - watch: { - configDict: function() { this.resolution = this.configDict.resolution; }, // model -> view update - resolution: function() { this.$emit('update:configDict', { resolution: this.resolution }); } // view -> model update - } +let Vue = require("vuejs"); +let utils = require("utils"); + +let resolutionTag = 'resolution'; +const resolutionComponent = Vue.component(resolutionTag + '-component', { + // Your configurable must have a "configDict" property from the model + props: ['configDict'], + + template: + `
+ + +
`, + + data: function() { + return { + resolution: this.configDict.resolution, + resolutionOptions: ['Window', '1920x1080', '1280x1024', '1280x800', '1024x768'] + }; + }, + + watch: { + configDict: function() { this.resolution = this.configDict.resolution; }, // model -> view update + resolution: function() { this.$emit('update:configDict', { resolution: this.resolution }); } // view -> model update + } }); // Your configurable class must implement a tag and default configDict -var ResolutionModel = function() { +class ResolutionModel { + constructor() { this.tag = resolutionTag; this.configDict = { resolution: 'Window' }; -}; + } -ResolutionModel.prototype.asConfigDict = function() { - var resolution = this.configDict.resolution; + asConfigDict() { + let resolution = this.configDict.resolution; if (resolution === 'Window') { - var maxSize = utils.maxIframeSize(); - resolution = maxSize[0] + 'x' + maxSize[1]; + let maxSize = utils.maxIframeSize(); + resolution = maxSize[0] + 'x' + maxSize[1]; } return { resolution: resolution }; -}; + } +} -var outputConfigurables = {}; +let outputConfigurables = {}; // Export all your configurable models here outputConfigurables[resolutionTag] = { - model: ResolutionModel, - component: resolutionComponent + model: ResolutionModel, + component: resolutionComponent }; module.exports = outputConfigurables; \ No newline at end of file diff --git a/remoteappmanager/static/js/user/main.js b/remoteappmanager/static/js/user/main.js index 2e06abbae..4f752b0db 100644 --- a/remoteappmanager/static/js/user/main.js +++ b/remoteappmanager/static/js/user/main.js @@ -1,29 +1,29 @@ -var gamodule = require("gamodule"); -var models = require("./models"); -var applicationListView = require("./views/application_list_view"); -var applicationView = require("./views/application_view"); +let gamodule = require("gamodule"); +let models = require("./models"); +let applicationListView = require("./views/application_list_view"); +let applicationView = require("./views/application_view"); require("filters"); // This model keeps the retrieved content from the REST query locally. // It is only synchronized at initial load. -var model = new models.ApplicationListModel(); +let model = new models.ApplicationListModel(); // Initialize views -var appListView = new applicationListView.ApplicationListView({ - el: '#applist', - data: function() { return { model: model }; } +let appListView = new applicationListView.ApplicationListView({ + el: '#applist', + data: function() { return { model: model }; } }); -var appView = new applicationView.ApplicationView({ - el: '#appview', - data: function() { return { model: model }; } +let appView = new applicationView.ApplicationView({ + el: '#appview', + data: function() { return { model: model }; } }); // Create GA observer -var gaObserver = new gamodule.GaObserver(); +let gaObserver = new gamodule.GaObserver(); appView.$on('startApplication', function(application) { - gaObserver.triggerApplicationStarting(application.appData.image.name); + gaObserver.triggerApplicationStarting(application.appData.image.name); }); appListView.$on('entryClicked', function() { appView.focusIframe(); }); diff --git a/remoteappmanager/static/js/user/models.js b/remoteappmanager/static/js/user/models.js index 5e8516106..b5a279afa 100644 --- a/remoteappmanager/static/js/user/models.js +++ b/remoteappmanager/static/js/user/models.js @@ -1,43 +1,44 @@ -var $ = require("jquery"); -var resources = require("user-resources"); -var configurables = require("./configurables"); - -var Status = { - RUNNING: "RUNNING", - STARTING: "STARTING", - STOPPING: "STOPPING", - STOPPED: "STOPPED" +let $ = require("jquery"); +let resources = require("user-resources"); +let configurables = require("./configurables"); + +let Status = { + RUNNING: "RUNNING", + STARTING: "STARTING", + STOPPING: "STOPPING", + STOPPED: "STOPPED" }; -var availableApplicationsInfo = function () { - // Retrieve information from the various applications and - // connect the cascading callbacks. - // Returns a single promise. When resolved, the attached - // callbacks will be passed an array of the promises for the various - // retrieve operations, successful or not. - // This routine will go away when we provide the representation data - // inline with the items at tornado-webapi level. - - var promise = $.Deferred(); - - resources.Application.items() - .done(function (identifiers, items) { - var result = []; - Object.keys(items).forEach(function(key) { - result.push(items[key]); - }); - promise.resolve(result); - - }) - .fail(function() { - promise.resolve([]); - }); - - return promise; +let availableApplicationsInfo = function () { + // Retrieve information from the various applications and + // connect the cascading callbacks. + // Returns a single promise. When resolved, the attached + // callbacks will be passed an array of the promises for the various + // retrieve operations, successful or not. + // This routine will go away when we provide the representation data + // inline with the items at tornado-webapi level. + + let promise = $.Deferred(); + + resources.Application.items() + .done((identifiers, items) => { + let result = []; + Object.keys(items).forEach((key) => { + result.push(items[key]); + }); + promise.resolve(result); + + }) + .fail(() => { + promise.resolve([]); + }); + + return promise; }; -var ApplicationListModel = function() { - // (constructor) Model for the application list. + +class ApplicationListModel { + constructor() { this.appList = []; // Selection index for when we click on one entry. @@ -46,158 +47,159 @@ var ApplicationListModel = function() { this.selectedIndex = null; this.loading = true; -}; + } -ApplicationListModel.prototype.update = function() { + update() { // Requests an update of the object internal data. // This method returns a jQuery Promise object. // When resolved, this.data will contain a list of the retrieved // data. Note that, in error conditions, this routine resolves // successfully in any case, and the data is set to empty list return $.when( - availableApplicationsInfo() - ).done(function (appData) { - // appData contains the data retrieved from the remote API - - var appList = []; - - // Sort application list by names - appData.sort(function(app1, app2) { - var app1Name = app1.image.ui_name? app1.image.ui_name: app1.image.name; - var app2Name = app2.image.ui_name? app2.image.ui_name: app2.image.name; - return app1Name < app2Name? -1: 1; - }); - - // Add the options for some image types - appData.forEach(function(applicationData) { - var app = { - appData: applicationData, - // Default values, will be overwritten - status: Status.STOPPED, - // If true the user will see the loading spinner (when starting the application) - delayed: true, - configurables: [], - isRunning: function() {return this.status === Status.RUNNING;}, - isStopped: function() {return this.status === Status.STOPPED;}, - isStarting: function() {return this.status === Status.STARTING;}, - isStopping: function() {return this.status === Status.STOPPING;} - }; - - this._updateConfigurables(app); - this._updateStatus(app); - - app.delayed = !app.isRunning(); - appList.push(app); - }.bind(this)); - - this.appList = appList; - - if(appList.length) {this.selectedIndex = 0;} - - this.loading = false; - }.bind(this)); -}; + availableApplicationsInfo() + ).done((appData) => { + // appData contains the data retrieved from the remote API + + let appList = []; + + // Sort application list by names + appData.sort((app1, app2) => { + let app1Name = app1.image.ui_name? app1.image.ui_name: app1.image.name; + let app2Name = app2.image.ui_name? app2.image.ui_name: app2.image.name; + return app1Name < app2Name? -1: 1; + }); + + // Add the options for some image types + appData.forEach((applicationData) => { + let app = { + appData: applicationData, + // Default values, will be overwritten + status: Status.STOPPED, + // If true the user will see the loading spinner (when starting the application) + delayed: true, + configurables: [], + isRunning: function() {return this.status === Status.RUNNING;}, + isStopped: function() {return this.status === Status.STOPPED;}, + isStarting: function() {return this.status === Status.STARTING;}, + isStopping: function() {return this.status === Status.STOPPING;} + }; + + this._updateConfigurables(app); + this._updateStatus(app); + + app.delayed = !app.isRunning(); + appList.push(app); + }); + + this.appList = appList; + + if(appList.length) {this.selectedIndex = 0;} -ApplicationListModel.prototype.updateIdx = function(index) { + this.loading = false; + }); + } + + updateIdx(index) { // Refetches and updates the entry at the given index. - var app = this.appList[index]; - var mapping_id = app.appData.mapping_id; + let app = this.appList[index]; + let mapping_id = app.appData.mapping_id; return resources.Application.retrieve(mapping_id) - .done(function(newData) { - app.appData = newData; + .done((newData) => { + app.appData = newData; - this._updateStatus(app); - }.bind(this)); -}; + this._updateStatus(app); + }); + } -ApplicationListModel.prototype._updateConfigurables = function(app) { + _updateConfigurables(app) { // Contains the submodels for the configurables. // It is a dictionary that maps a supported (by the image) configurable tag // to its client-side model. app.configurables = []; app.appData.image.configurables.forEach(function(tag) { - // If this returns null, the tag has not been recognized - // by the client. skip it and let the server deal with the - // missing data, either by using a default or throwing - // an error. - var ConfigurableCls = configurables[tag].model; - - if (ConfigurableCls !== undefined) { - app.configurables.push(new ConfigurableCls()); - } + // If this returns null, the tag has not been recognized + // by the client. skip it and let the server deal with the + // missing data, either by using a default or throwing + // an error. + let ConfigurableCls = configurables[tag].model; + + if (ConfigurableCls !== undefined) { + app.configurables.push(new ConfigurableCls()); + } }); -}; + } -ApplicationListModel.prototype._updateStatus = function(app) { + _updateStatus(app) { if (app.appData.container === undefined) { - app.status = Status.STOPPED; + app.status = Status.STOPPED; } else { - app.status = Status.RUNNING; + app.status = Status.RUNNING; } -}; + } -ApplicationListModel.prototype.startApplication = function() { - var selectedIndex = this.selectedIndex; - var currentApp = this.appList[selectedIndex]; + startApplication() { + let selectedIndex = this.selectedIndex; + let currentApp = this.appList[selectedIndex]; currentApp.status = Status.STARTING; currentApp.delayed = true; - var configurablesData = {}; + let configurablesData = {}; currentApp.configurables.forEach(function(configurable) { - var tag = configurable.tag; - configurablesData[tag] = configurable.asConfigDict(); + let tag = configurable.tag; + configurablesData[tag] = configurable.asConfigDict(); }); - var startPromise = $.Deferred(); + let startPromise = $.Deferred(); resources.Container.create({ - mapping_id: currentApp.appData.mapping_id, - configurables: configurablesData + mapping_id: currentApp.appData.mapping_id, + configurables: configurablesData }) - .done(function() { - this.updateIdx(selectedIndex) - .done(startPromise.resolve) - .fail(function(error) { - currentApp.status = Status.STOPPED; - startPromise.reject(error); - }); - }.bind(this)) - .fail(function(error) { + .done(() => { + this.updateIdx(selectedIndex) + .done(startPromise.resolve) + .fail((error) => { currentApp.status = Status.STOPPED; startPromise.reject(error); + }); + }) + .fail((error) => { + currentApp.status = Status.STOPPED; + startPromise.reject(error); }); return startPromise; -}; + } -ApplicationListModel.prototype.stopApplication = function(index) { - var appStopping = this.appList[index]; + stopApplication(index) { + let appStopping = this.appList[index]; appStopping.status = Status.STOPPING; - var url_id = appStopping.appData.container.url_id; + let url_id = appStopping.appData.container.url_id; - var stopPromise = $.Deferred(); + let stopPromise = $.Deferred(); resources.Container.delete(url_id) - .done(function() { - this.updateIdx(index) - .done(stopPromise.resolve) - .fail(function(error) { - appStopping.status = Status.STOPPED; - stopPromise.reject(error); - }); - }.bind(this)) - .fail(function(error) { + .done(() => { + this.updateIdx(index) + .done(stopPromise.resolve) + .fail(function(error) { appStopping.status = Status.STOPPED; stopPromise.reject(error); + }); + }) + .fail((error) => { + appStopping.status = Status.STOPPED; + stopPromise.reject(error); }); return stopPromise; -}; + } +} module.exports = { - ApplicationListModel: ApplicationListModel + ApplicationListModel }; diff --git a/remoteappmanager/static/js/user/user-resources.js b/remoteappmanager/static/js/user/user-resources.js index c5060fefd..f8d425134 100644 --- a/remoteappmanager/static/js/user/user-resources.js +++ b/remoteappmanager/static/js/user/user-resources.js @@ -3,311 +3,311 @@ var urlUtils = require("urlutils"); var utils = require("utils"); var object_to_query_args = function (obj) { - var keys = Object.keys(obj); - if (keys.length === 0) { - return ""; + var keys = Object.keys(obj); + if (keys.length === 0) { + return ""; + } + + var result = []; + for (var idx in keys) { + var key = keys[idx]; + var value = obj[key]; + var key_enc = encodeURIComponent(key); + if ($.isArray(value)) { + for (var v in value) { + result.push(key_enc+"="+encodeURIComponent(v)); + } + } else { + result.push(key_enc+"="+encodeURIComponent(value)); } + } - var result = []; - for (var idx in keys) { - var key = keys[idx]; - var value = obj[key]; - var key_enc = encodeURIComponent(key); - if ($.isArray(value)) { - for (var v in value) { - result.push(key_enc+"="+encodeURIComponent(v)); - } - } else { - result.push(key_enc+"="+encodeURIComponent(value)); - } - } - - return result.join("&"); + return result.join("&"); }; var API = (function () { - // Object representing the interface to the Web API. - // @param base_url : the url at which to find the web API endpoint. - var self = {}; - self.base_urlpath = "/user/test/"; - self.default_options = { - contentType: "application/json", - cache: false, - dataType : null, - processData: false, - success: null, - error: null - }; - - self.request = function (req_type, endpoint, body, query_args) { - // Performs a request to the final endpoint - var options = {}; - utils.update(options, self.default_options); - utils.update(options, { - type: req_type, - data: body - }); - - var url = urlUtils.pathJoin( - self.base_urlpath, - "api", "v1", - urlUtils.encodeUriComponents(endpoint) - )+'/'; - - if (query_args) { - url = url + "?" + object_to_query_args(query_args); - } - return $.ajax(url, options); - }; - return self; + // Object representing the interface to the Web API. + // @param base_url : the url at which to find the web API endpoint. + var self = {}; + self.base_urlpath = "/user/test/"; + self.default_options = { + contentType: "application/json", + cache: false, + dataType : null, + processData: false, + success: null, + error: null + }; + + self.request = function (req_type, endpoint, body, query_args) { + // Performs a request to the final endpoint + var options = {}; + utils.update(options, self.default_options); + utils.update(options, { + type: req_type, + data: body + }); + + var url = urlUtils.pathJoin( + self.base_urlpath, + "api", "v1", + urlUtils.encodeUriComponents(endpoint) + )+'/'; + + if (query_args) { + url = url + "?" + object_to_query_args(query_args); + } + return $.ajax(url, options); + }; + return self; })(); var RestError = function(code, message) { - console.log("Creating error "+code+" message: "+message); - this.code = code; - this.message = message; + console.log("Creating error "+code+" message: "+message); + this.code = code; + this.message = message; }; var fail_handler = function(promise, jqXHR) { - var status = jqXHR.status; - var payload = null; - try { - payload = JSON.parse(jqXHR.responseText); - } catch (e) { - // Suppress any syntax error and discard the payload - } - - var err = new RestError(status, ""); - if (payload !== null) { - utils.update(err, payload); - } - promise.reject(err); + var status = jqXHR.status; + var payload = null; + try { + payload = JSON.parse(jqXHR.responseText); + } catch (e) { + // Suppress any syntax error and discard the payload + } + + var err = new RestError(status, ""); + if (payload !== null) { + utils.update(err, payload); + } + promise.reject(err); }; var create_handler = function(promise, data, textStatus, jqXHR) { - var status = jqXHR.status; - - var payload = null; - try { - payload = JSON.parse(data); - } catch (e) { - // Suppress any syntax error and discard the payload - } - - if (status !== 201) { - // Strange situation in which the call succeeded, but - // not with a 201. Just do our best. - console.log( - "Create succeded but response with status " + - status + - " instead of 201." - ); - promise.reject(status, payload); - return; - } - - var id, location; - try { - location = jqXHR.getResponseHeader('Location'); - var url = urlUtils.parse(location); - var arr = url.pathname.replace(/\/$/, "").split('/'); - id = arr[arr.length - 1]; - } catch (e) { - console.log("Response had invalid or absent Location header"); - promise.reject(status, payload); - return; - } - promise.resolve(id, location); + var status = jqXHR.status; + + var payload = null; + try { + payload = JSON.parse(data); + } catch (e) { + // Suppress any syntax error and discard the payload + } + + if (status !== 201) { + // Strange situation in which the call succeeded, but + // not with a 201. Just do our best. + console.log( + "Create succeded but response with status " + + status + + " instead of 201." + ); + promise.reject(status, payload); + return; + } + + var id, location; + try { + location = jqXHR.getResponseHeader('Location'); + var url = urlUtils.parse(location); + var arr = url.pathname.replace(/\/$/, "").split('/'); + id = arr[arr.length - 1]; + } catch (e) { + console.log("Response had invalid or absent Location header"); + promise.reject(status, payload); + return; + } + promise.resolve(id, location); }; var update_handler = function(promise, data, textStatus, jqXHR) { - var status = jqXHR.status; - - var payload = null; - try { - payload = JSON.parse(data); - } catch (e) { - // Suppress any syntax error and discard the payload - } - - if (status !== 204) { - // Strange situation in which the call succeeded, but - // not with a 201. Just do our best. - console.log( - "Update succeded but response with status " + - status + - " instead of 204." - ); - promise.reject(status, payload); - return; - } - - promise.resolve(); + var status = jqXHR.status; + + var payload = null; + try { + payload = JSON.parse(data); + } catch (e) { + // Suppress any syntax error and discard the payload + } + + if (status !== 204) { + // Strange situation in which the call succeeded, but + // not with a 201. Just do our best. + console.log( + "Update succeded but response with status " + + status + + " instead of 204." + ); + promise.reject(status, payload); + return; + } + + promise.resolve(); }; var delete_handler = function(promise, data, textStatus, jqXHR) { - var status = jqXHR.status; - var payload = null; - try { - payload = JSON.parse(data); - } catch (e) { - // Suppress any syntax error and discard the payload - } - - if (status !== 204) { - console.log( - "Delete succeded but response with status " + - status + - " instead of 204." - ); - promise.reject(status, payload); - return; - } - promise.resolve(); + var status = jqXHR.status; + var payload = null; + try { + payload = JSON.parse(data); + } catch (e) { + // Suppress any syntax error and discard the payload + } + + if (status !== 204) { + console.log( + "Delete succeded but response with status " + + status + + " instead of 204." + ); + promise.reject(status, payload); + return; + } + promise.resolve(); }; var retrieve_handler = function(promise, data, textStatus, jqXHR) { - var status = jqXHR.status; - - var payload = null; - try { - payload = JSON.parse(jqXHR.responseText); - } catch (e) { - // Suppress any syntax error and discard the payload - } + var status = jqXHR.status; + + var payload = null; + try { + payload = JSON.parse(jqXHR.responseText); + } catch (e) { + // Suppress any syntax error and discard the payload + } + + if (status !== 200) { + console.log( + "Retrieve succeded but response with status " + + status + + " instead of 200." + ); + promise.reject(status, payload); + return; + } + + if (payload === null) { + console.log( + "Retrieve succeded but empty or invalid payload" + ); + promise.reject(status, payload); + return; + } + + promise.resolve(payload); +}; - if (status !== 200) { - console.log( - "Retrieve succeded but response with status " + - status + - " instead of 200." - ); - promise.reject(status, payload); - return; - } +var Resource = function(type) { + this.type = type; + + this.create = function(representation, query_args) { + var body = JSON.stringify(representation); + var promise = $.Deferred(); + + API.request("POST", type, body, query_args) + .done(function(data, textStatus, jqXHR) { + create_handler(promise, data, textStatus, jqXHR); + }) + .fail(function(jqXHR) { + fail_handler(promise, jqXHR); + }); + + return promise; + }; + + this.update = function(id, representation, query_args) { + var body = JSON.stringify(representation); + var promise = $.Deferred(); + + API.request("PUT", urlUtils.pathJoin(type, id), body, query_args) + .done(function(data, textStatus, jqXHR) { + update_handler(promise, data, textStatus, jqXHR); + } + ) + .fail(function(jqXHR) { + fail_handler(promise, jqXHR); + }); + + return promise; + }; + + this.delete = function(id, query_args) { + var promise = $.Deferred(); + + API.request("DELETE", urlUtils.pathJoin(type, id), null, query_args) + .done(function(data, textStatus, jqXHR) { + delete_handler(promise, data, textStatus, jqXHR); + } + ) + .fail(function(jqXHR) { + fail_handler(promise, jqXHR); + }); + + return promise; + }; + + this.retrieve = function(id, query_args) { + var promise = $.Deferred(); + + API.request("GET", urlUtils.pathJoin(type, id), null, query_args) + .done(function(data, textStatus, jqXHR) { + retrieve_handler(promise, data, textStatus, jqXHR); + } + ) + .fail(function(jqXHR) { + fail_handler(promise, jqXHR); + }); + + return promise; + }; + + this.items = function(query_args) { + var promise = $.Deferred(); + + API.request("GET", type, null, query_args) + .done(function(data, textStatus, jqXHR) { + var status = jqXHR.status; + + var payload = null; + try { + payload = JSON.parse(jqXHR.responseText); + } catch (e) { + // Suppress any syntax error and discard the payload + } - if (payload === null) { - console.log( - "Retrieve succeded but empty or invalid payload" - ); - promise.reject(status, payload); - return; - } + if (status !== 200) { + console.log( + "Items retrieve succeded but response with status " + + status + + " instead of 200." + ); + promise.reject(status, payload); + return; + } - promise.resolve(payload); -}; + if (payload === null) { + console.log( + "Items Retrieve succeded but empty or invalid payload" + ); + promise.reject(status, payload); + return; + } -var Resource = function(type) { - this.type = type; - - this.create = function(representation, query_args) { - var body = JSON.stringify(representation); - var promise = $.Deferred(); - - API.request("POST", type, body, query_args) - .done(function(data, textStatus, jqXHR) { - create_handler(promise, data, textStatus, jqXHR); - }) - .fail(function(jqXHR) { - fail_handler(promise, jqXHR); - }); - - return promise; - }; - - this.update = function(id, representation, query_args) { - var body = JSON.stringify(representation); - var promise = $.Deferred(); - - API.request("PUT", urlUtils.pathJoin(type, id), body, query_args) - .done(function(data, textStatus, jqXHR) { - update_handler(promise, data, textStatus, jqXHR); - } - ) - .fail(function(jqXHR) { - fail_handler(promise, jqXHR); - }); - - return promise; - }; - - this.delete = function(id, query_args) { - var promise = $.Deferred(); - - API.request("DELETE", urlUtils.pathJoin(type, id), null, query_args) - .done(function(data, textStatus, jqXHR) { - delete_handler(promise, data, textStatus, jqXHR); - } - ) - .fail(function(jqXHR) { - fail_handler(promise, jqXHR); - }); - - return promise; - }; - - this.retrieve = function(id, query_args) { - var promise = $.Deferred(); - - API.request("GET", urlUtils.pathJoin(type, id), null, query_args) - .done(function(data, textStatus, jqXHR) { - retrieve_handler(promise, data, textStatus, jqXHR); - } - ) - .fail(function(jqXHR) { - fail_handler(promise, jqXHR); - }); - - return promise; - }; - - this.items = function(query_args) { - var promise = $.Deferred(); - - API.request("GET", type, null, query_args) - .done(function(data, textStatus, jqXHR) { - var status = jqXHR.status; - - var payload = null; - try { - payload = JSON.parse(jqXHR.responseText); - } catch (e) { - // Suppress any syntax error and discard the payload - } - - if (status !== 200) { - console.log( - "Items retrieve succeded but response with status " + - status + - " instead of 200." - ); - promise.reject(status, payload); - return; - } - - if (payload === null) { - console.log( - "Items Retrieve succeded but empty or invalid payload" - ); - promise.reject(status, payload); - return; - } - - promise.resolve( - payload.identifiers, - payload.items, - payload.offset, - payload.total); - }) - .fail(function(jqXHR) { - fail_handler(promise, jqXHR); - }); - - return promise; - }; + promise.resolve( + payload.identifiers, + payload.items, + payload.offset, + payload.total); + }) + .fail(function(jqXHR) { + fail_handler(promise, jqXHR); + }); + + return promise; + }; }; module.exports = { - "Container" : new Resource("containers"), - "Application" : new Resource("applications"), + "Container" : new Resource("containers"), + "Application" : new Resource("applications"), }; diff --git a/remoteappmanager/static/js/user/views/application_list_view.js b/remoteappmanager/static/js/user/views/application_list_view.js index 4a0ee8a46..0b2973d3f 100644 --- a/remoteappmanager/static/js/user/views/application_list_view.js +++ b/remoteappmanager/static/js/user/views/application_list_view.js @@ -1,105 +1,105 @@ -var Vue = require("vuejs"); +let Vue = require("vuejs"); require("toolkit"); -var ApplicationListView = Vue.extend({ - template: - ' + `, - data: function() { - return { - 'searchInput': '', - stoppingError: { show: false, appName: '', code: '', message: '' } - }; - }, + data: function() { + return { + 'searchInput': '', + stoppingError: { show: false, appName: '', code: '', message: '' } + }; + }, - computed: { - visibleList: function() { - return this.model.appList.filter(function(app) { - var appName = this.$options.filters.appName(app.appData.image).toLowerCase(); - return appName.indexOf(this.searchInput.toLowerCase()) !== -1; - }.bind(this)); - } - }, + computed: { + visibleList: function() { + return this.model.appList.filter((app) => { + let appName = this.$options.filters.appName(app.appData.image).toLowerCase(); + return appName.indexOf(this.searchInput.toLowerCase()) !== -1; + }); + } + }, - methods: { - stopApplication: function(index) { - var stoppingAppName = this.$options.filters.appName( - this.model.appList[index].appData.image); - this.model.stopApplication(index).fail(function(error) { - this.stoppingError.code = error.code; - this.stoppingError.message = error.message; - this.stoppingError.appName = stoppingAppName; - this.stoppingError.show = true; - }.bind(this)); - }, - closeDialog: function() { - this.stoppingError.show = false; - }, - indexOf: function(app) { - return this.model.appList.indexOf(app); - } + methods: { + stopApplication: function(index) { + let stoppingAppName = this.$options.filters.appName( + this.model.appList[index].appData.image); + this.model.stopApplication(index).fail((error) => { + this.stoppingError.code = error.code; + this.stoppingError.message = error.message; + this.stoppingError.appName = stoppingAppName; + this.stoppingError.show = true; + }); + }, + closeDialog: function() { + this.stoppingError.show = false; + }, + indexOf: function(app) { + return this.model.appList.indexOf(app); } + } }); module.exports = { - ApplicationListView : ApplicationListView + ApplicationListView }; diff --git a/remoteappmanager/static/js/user/views/application_view.js b/remoteappmanager/static/js/user/views/application_view.js index 5b3ce899c..416fbd959 100644 --- a/remoteappmanager/static/js/user/views/application_view.js +++ b/remoteappmanager/static/js/user/views/application_view.js @@ -1,149 +1,148 @@ -var Vue = require("vuejs"); -var urlUtils = require("urlutils"); -var utils = require("utils"); +let Vue = require("vuejs"); +let urlUtils = require("urlutils"); +let utils = require("utils"); require("toolkit"); -var ApplicationView = Vue.extend({ - template: - '' + - '
' + - ' ' + - ' ' + - '
' + - ' Code: {{startingError.code}}' + - ' {{startingError.message}}' + - '
' + - '
' + - - ' ' + - '
' + - '
' + - '
' + - '
' + - '

{{ currentApp.appData.image | appName }}

' + - '
' + - '
' + - '
' + - '

Description

' + - ' {{ currentApp.appData.image.description }}' + - - '

Policy

' + - - '
    ' + - ' ' + - '
  • ' + - ' Workspace accessible' + - '
  • ' + - '
  • ' + - ' Workspace not accessible' + - '
  • ' + - - ' ' + - '
  • ' + - ' Volume mounted: {{ appPolicy.volume_source }} → {{ appPolicy.volume_target }} ({{ appPolicy.volume_mode }})' + - '
  • ' + - '
  • ' + - ' No volumes mounted' + - '
  • ' + - '
' + - - '

Configuration

' + - '
' + - '
No configurable options for this image
' + - '
' + - ' ' + - '
' + - '
' + - '
' + - - ' ' + - ' ' + - '
' + - '
' + - '
' + - - - ' ' + - ' ' + - '
', - - data: function() { - return { - startingError: { show: false, appName: '', code: '', message: '' } - }; +const ApplicationView = Vue.extend({ + template: + ` +
+ + +
+ Code: {{startingError.code}} + {{startingError.message}} +
+
+ + +
+
+
+
+

{{ currentApp.appData.image | appName }}

+
+
+
+

Description

+ {{ currentApp.appData.image.description }} + +

Policy

+ +
    + +
  • + Workspace accessible +
  • +
  • + Workspace not accessible +
  • + + +
  • + Volume mounted: {{ appPolicy.volume_source }} → {{ appPolicy.volume_target }} ({{ appPolicy.volume_mode }}) +
  • +
  • + No volumes mounted +
  • +
+ +

Configuration

+
+
No configurable options for this image
+
+ +
+
+
+ + + +
+
+
+ + + +
`, + + data: function() { + return { + startingError: { show: false, appName: '', code: '', message: '' } + }; + }, + + computed: { + currentApp: function() { + return this.model.appList[this.model.selectedIndex] || null; }, - - computed: { - currentApp: function() { - return this.model.appList[this.model.selectedIndex] || null; - }, - appPolicy: function() { - return this.currentApp.appData.image.policy; - }, - appSource: function() { - var url = urlUtils.pathJoin( - window.apidata.base_url, - 'containers', - this.currentApp.appData.container.url_id - ); - var output = this.currentApp.delayed ? url : url + '/'; - - this.currentApp.delayed = false; - - return output; - } + appPolicy: function() { + return this.currentApp.appData.image.policy; }, - - methods: { - startApplication: function() { - var startingApp = this.currentApp; - var startingAppName = this.$options.filters.appName(startingApp.appData.image); - this.model.startApplication() - .done(function() { - this.$emit('startApplication', startingApp); - }.bind(this)) - .fail(function(error) { - this.startingError.code = error.code; - this.startingError.message = error.message; - this.startingError.appName = startingAppName; - this.startingError.show = true; - }.bind(this)); - }, - closeDialog: function() { - this.startingError.show = false; - }, - getIframeSize: function() { - return utils.maxIframeSize(); - }, - focusIframe: function() { - var iframe = this.$el.querySelector('iframe'); - if(iframe !== null) { - iframe.focus(); - } - } + appSource: function() { + let url = urlUtils.pathJoin( + window.apidata.base_url, + 'containers', + this.currentApp.appData.container.url_id + ); + let output = this.currentApp.delayed ? url : url + '/'; + + this.currentApp.delayed = false; + + return output; + } + }, + + methods: { + startApplication: function() { + let startingApp = this.currentApp; + let startingAppName = this.$options.filters.appName(startingApp.appData.image); + this.model.startApplication() + .done(() => { + this.$emit('startApplication', startingApp); + }) + .fail((error) => { + this.startingError.code = error.code; + this.startingError.message = error.message; + this.startingError.appName = startingAppName; + this.startingError.show = true; + }); }, - - updated: function() { this.focusIframe(); } + closeDialog: function() { + this.startingError.show = false; + }, + getIframeSize: function() { + return utils.maxIframeSize(); + }, + focusIframe: function() { + let iframe = this.$el.querySelector('iframe'); + if(iframe !== null) { + iframe.focus(); + } + } + }, + + updated: function() { this.focusIframe(); } }); module.exports = { - ApplicationView : ApplicationView + ApplicationView }; diff --git a/remoteappmanager/static/js/utils.js b/remoteappmanager/static/js/utils.js index ebdb3077b..cc9f071cd 100644 --- a/remoteappmanager/static/js/utils.js +++ b/remoteappmanager/static/js/utils.js @@ -5,43 +5,43 @@ // Modifications Copyright (c) Juptyer Development Team. // Distributed under the terms of the Modified BSD License. -var $ = require("jquery"); +let $ = require("jquery"); -var all = function (promises) { - // A form of jQuery.when that handles an array of promises - // and equalises the behavior regardless if there's one or more than - // one elements. - if (!Array.isArray(promises)) { - throw new Error("$.all() must be passed an array of promises"); +let all = function (promises) { + // A form of jQuery.when that handles an array of promises + // and equalises the behavior regardless if there's one or more than + // one elements. + if (!Array.isArray(promises)) { + throw new Error("$.all() must be passed an array of promises"); + } + return $.when.apply($, promises).then(function () { + // if single argument was expanded into multiple arguments, + // then put it back into an array for consistency + if (promises.length === 1 && arguments.length > 1) { + // put arguments into an array + return [Array.prototype.slice.call(arguments, 0)]; + } else { + return Array.prototype.slice.call(arguments, 0); } - return $.when.apply($, promises).then(function () { - // if single argument was expanded into multiple arguments, - // then put it back into an array for consistency - if (promises.length === 1 && arguments.length > 1) { - // put arguments into an array - return [Array.prototype.slice.call(arguments, 0)]; - } else { - return Array.prototype.slice.call(arguments, 0); - } - }); + }); }; -var update = function (d1, d2) { - // Transfers the keys from d2 to d1. Returns d1 - $.map(d2, function (i, key) { - d1[key] = d2[key]; - }); - return d1; +let update = function (d1, d2) { + // Transfers the keys from d2 to d1. Returns d1 + $.map(d2, function (i, key) { + d1[key] = d2[key]; + }); + return d1; }; -var maxIframeSize = function () { - // Returns the current iframe viewport size - var box = document.querySelector(".content-wrapper").getBoundingClientRect(); - return [box.width, box.height]; +let maxIframeSize = function () { + // Returns the current iframe viewport size + let box = document.querySelector(".content-wrapper").getBoundingClientRect(); + return [box.width, box.height]; }; module.exports = { - all : all, - update : update, - maxIframeSize: maxIframeSize + all, + update, + maxIframeSize }; diff --git a/remoteappmanager/static/js/vue/filters.js b/remoteappmanager/static/js/vue/filters.js index 0f9acc584..aa0677879 100644 --- a/remoteappmanager/static/js/vue/filters.js +++ b/remoteappmanager/static/js/vue/filters.js @@ -1,16 +1,16 @@ -var Vue = require("vuejs"); -var urlUtils = require("urlutils"); +let Vue = require("vuejs"); +let urlUtils = require("urlutils"); Vue.filter('iconSrc', function(icon_data) { - return ( - icon_data ? - 'data:image/png;base64,' + icon_data : - urlUtils.pathJoin( - window.apidata.base_url, 'static', 'images', 'generic_appicon_128.png' - ) - ); + return ( + icon_data ? + 'data:image/png;base64,' + icon_data : + urlUtils.pathJoin( + window.apidata.base_url, 'static', 'images', 'generic_appicon_128.png' + ) + ); }); Vue.filter('appName', function(image) { - return image.ui_name? image.ui_name: image.name; + return image.ui_name? image.ui_name: image.name; }); diff --git a/remoteappmanager/static/js/vue/toolkit/AdminLTEBox.js b/remoteappmanager/static/js/vue/toolkit/AdminLTEBox.js index 83aa72b84..32791c257 100644 --- a/remoteappmanager/static/js/vue/toolkit/AdminLTEBox.js +++ b/remoteappmanager/static/js/vue/toolkit/AdminLTEBox.js @@ -1,17 +1,17 @@ module.exports = { - props: { - title: { - type: String, - default: "Box" - } - }, - template: - '
' + - '
' + - '
' + - '
{{title}}
' + - '
' + - '
' + - '
' + - '
' + props: { + title: { + type: String, + default: "Box" + } + }, + template: + `
+
+
+
{{title}}
+
+
+
+
` }; diff --git a/remoteappmanager/static/js/vue/toolkit/ConfirmDialog.js b/remoteappmanager/static/js/vue/toolkit/ConfirmDialog.js index c82188cf3..d5e32fdff 100644 --- a/remoteappmanager/static/js/vue/toolkit/ConfirmDialog.js +++ b/remoteappmanager/static/js/vue/toolkit/ConfirmDialog.js @@ -1,30 +1,30 @@ module.exports = { - props: { - title: { - type: String, - default: "Confirm" - }, - closeCallback: { - type: Function, - default: undefined - }, - okCallback: { - type: Function, - default: function() {} - } + props: { + title: { + type: String, + default: "Confirm" }, - template: '' + - ' ' + - '' + closeCallback: { + type: Function, + default: undefined + }, + okCallback: { + type: Function, + default: function() {} + } + }, + template: ` + + ` }; diff --git a/remoteappmanager/static/js/vue/toolkit/DataTable.js b/remoteappmanager/static/js/vue/toolkit/DataTable.js index 3845ddac9..a676cbbf6 100644 --- a/remoteappmanager/static/js/vue/toolkit/DataTable.js +++ b/remoteappmanager/static/js/vue/toolkit/DataTable.js @@ -1,46 +1,43 @@ module.exports = { - props: [ - "headers", "rows", "globalActions", "rowActions" - ], - methods: { - isBoolean: function(value) { - return typeof(value) === "boolean"; - }, - buttonClassFromType: function(value) { - var cls = {"btn": true}; - if (value === undefined) { - value = "danger"; - } - cls["btn-" + value] = true; - return cls; - } + props: [ + "headers", "rows", "globalActions", "rowActions" + ], + methods: { + isBoolean: function(value) { + return typeof(value) === "boolean"; }, - template: - '
' + - '
' + - ' ' + - '
' + - ' ' + - ' ' + - ' ' + - ' ' + - ' ' + - ' ' + - ' ' + - ' ' + - ' ' + - ' ' + - ' ' + - ' ' + - ' ' + - '
{{header}}Actions
' + - ' ' + - '
' + - '
' + buttonClassFromType: function(value = "danger") { + let cls = {"btn": true}; + cls["btn-" + value] = true; + return cls; + } + }, + template: + `
+
+ +
+ + + + + + + + + + + + + +
{{header}}Actions
+ +
+
` }; diff --git a/remoteappmanager/static/js/vue/toolkit/ModalDialog.js b/remoteappmanager/static/js/vue/toolkit/ModalDialog.js index 61a7059a6..6da7b4a59 100644 --- a/remoteappmanager/static/js/vue/toolkit/ModalDialog.js +++ b/remoteappmanager/static/js/vue/toolkit/ModalDialog.js @@ -1,12 +1,12 @@ module.exports = { - template: '' + - ' ' + - '' + template: ` + + ` }; \ No newline at end of file diff --git a/remoteappmanager/static/js/vue/toolkit/toolkit.js b/remoteappmanager/static/js/vue/toolkit/toolkit.js index b1018e319..4155036e0 100644 --- a/remoteappmanager/static/js/vue/toolkit/toolkit.js +++ b/remoteappmanager/static/js/vue/toolkit/toolkit.js @@ -1,8 +1,8 @@ -var Vue = require("vuejs"); -var ConfirmDialog = require("./ConfirmDialog"); -var ModalDialog = require("./ModalDialog"); -var AdminLTEBox = require("./AdminLTEBox"); -var DataTable = require("./DataTable"); +let Vue = require("vuejs"); +let ConfirmDialog = require("./ConfirmDialog"); +let ModalDialog = require("./ModalDialog"); +let AdminLTEBox = require("./AdminLTEBox"); +let DataTable = require("./DataTable"); Vue.component("confirm-dialog", ConfirmDialog); Vue.component("modal-dialog", ModalDialog); @@ -10,8 +10,8 @@ Vue.component("adminlte-box", AdminLTEBox); Vue.component("data-table", DataTable); module.exports = { - ConfirmDialog: ConfirmDialog, - AdminLTEBox: AdminLTEBox, - ModalDialog: ModalDialog, - DataTable: DataTable + ConfirmDialog, + AdminLTEBox, + ModalDialog, + DataTable };