From 522382fb9f15683523101e964ec2046fb57a2c2f Mon Sep 17 00:00:00 2001 From: martinRenou Date: Wed, 26 Apr 2017 16:10:15 +0100 Subject: [PATCH 01/13] Loading is now a property of the model --- remoteappmanager/static/js/home/controller.js | 2 -- remoteappmanager/static/js/home/models.js | 4 ++++ .../static/js/home/views/application_list_view.js | 3 +-- remoteappmanager/static/js/home/views/application_view.js | 2 +- remoteappmanager/templates/home.html | 4 ++-- 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/remoteappmanager/static/js/home/controller.js b/remoteappmanager/static/js/home/controller.js index b553054db..7ebf2f220 100644 --- a/remoteappmanager/static/js/home/controller.js +++ b/remoteappmanager/static/js/home/controller.js @@ -19,8 +19,6 @@ require([ var app_view = new application_view.ApplicationView(); $.when(model.update()).done(function () { - app_list_view.loading = false; - app_list_view.model = model; app_view.model = model; }); diff --git a/remoteappmanager/static/js/home/models.js b/remoteappmanager/static/js/home/models.js index d63e2789f..464d819df 100644 --- a/remoteappmanager/static/js/home/models.js +++ b/remoteappmanager/static/js/home/models.js @@ -43,6 +43,8 @@ define([ // Should be the index of the selected app_data, // or null if no selection. this.selected_index = null; + + this.loading = true; }; ApplicationListModel.prototype.update = function() { @@ -71,6 +73,8 @@ define([ this.app_list[data_idx].delayed = true; } }.bind(this)); + + this.loading = false; }.bind(this)); }; diff --git a/remoteappmanager/static/js/home/views/application_list_view.js b/remoteappmanager/static/js/home/views/application_list_view.js index fd603bcca..c6cdaf481 100644 --- a/remoteappmanager/static/js/home/views/application_list_view.js +++ b/remoteappmanager/static/js/home/views/application_list_view.js @@ -17,8 +17,7 @@ define([ data: function() { return { - loading: true, - model: { app_list: [], selected_index: null } + model: { app_list: [], selected_index: null, loading: true } }; }, diff --git a/remoteappmanager/static/js/home/views/application_view.js b/remoteappmanager/static/js/home/views/application_view.js index 44431ea1f..41be6e43c 100644 --- a/remoteappmanager/static/js/home/views/application_view.js +++ b/remoteappmanager/static/js/home/views/application_view.js @@ -18,7 +18,7 @@ define([ data: function() { return { - model: { app_list: [], selected_index: null } + model: { app_list: [], selected_index: null, loading: true } }; }, diff --git a/remoteappmanager/templates/home.html b/remoteappmanager/templates/home.html index 0d6bf4be0..4a99866e4 100644 --- a/remoteappmanager/templates/home.html +++ b/remoteappmanager/templates/home.html @@ -24,12 +24,12 @@ We initialize this element with "display: none" to prevent displaying "No applications found" and the loading spinner at the same time --> -
  • +
  • No applications found
  • -
  • +
  • Loading From bc71535bd7654b534d4c19fd01b111cdf80e865c Mon Sep 17 00:00:00 2001 From: martinRenou Date: Wed, 26 Apr 2017 17:02:43 +0100 Subject: [PATCH 02/13] Sort application list by names --- remoteappmanager/static/js/home/models.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/remoteappmanager/static/js/home/models.js b/remoteappmanager/static/js/home/models.js index 464d819df..63557850f 100644 --- a/remoteappmanager/static/js/home/models.js +++ b/remoteappmanager/static/js/home/models.js @@ -60,6 +60,13 @@ define([ this.app_list = []; + // Sort application list by names + app_data.sort(function(app1, app2) { + var app1_name = app1.image.ui_name? app1.image.ui_name: app1.image.name; + var app2_name = app2.image.ui_name? app2.image.ui_name: app2.image.name; + return app1_name < app2_name? -1: 1; + }); + // Add the options for some image types app_data.forEach(function(application_data, data_idx) { this.app_list[data_idx] = { app_data: application_data }; From b9cf1dbdd3865c37190eeab824907f02261c467c Mon Sep 17 00:00:00 2001 From: martinRenou Date: Thu, 27 Apr 2017 10:26:30 +0100 Subject: [PATCH 03/13] Fix jstest --- jstests/tests/home/test_views.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/jstests/tests/home/test_views.js b/jstests/tests/home/test_views.js index e55ac06cd..95352149f 100644 --- a/jstests/tests/home/test_views.js +++ b/jstests/tests/home/test_views.js @@ -13,15 +13,15 @@ define([ { model: model } ); - assert.ok(view.loading); + assert.ok(model.loading); model.update() .done(function() { view.model = model; - view.loading = false; + model.loading = false; } ) .done(function() { - assert.notOk(view.loading); + assert.notOk(model.loading); }); }); }); From ac0089fc76d255e20f12cf29261725dbf9d1f257 Mon Sep 17 00:00:00 2001 From: martinRenou Date: Thu, 27 Apr 2017 12:39:38 +0100 Subject: [PATCH 04/13] Correctly instantiate the views with the model And adapt the model so that Vue is aware of the app_list changes. --- remoteappmanager/static/js/home/controller.js | 14 +++++++++----- remoteappmanager/static/js/home/models.js | 13 +++++++------ .../static/js/home/views/application_list_view.js | 8 -------- .../static/js/home/views/application_view.js | 8 -------- 4 files changed, 16 insertions(+), 27 deletions(-) diff --git a/remoteappmanager/static/js/home/controller.js b/remoteappmanager/static/js/home/controller.js index 7ebf2f220..f209d0bc7 100644 --- a/remoteappmanager/static/js/home/controller.js +++ b/remoteappmanager/static/js/home/controller.js @@ -15,11 +15,15 @@ require([ // It is only synchronized at initial load. var model = new models.ApplicationListModel(); - var app_list_view = new application_list_view.ApplicationListView(); - var app_view = new application_view.ApplicationView(); + var app_list_view = new application_list_view.ApplicationListView({ + el: '#applist', + data: function() { return { model: model }; } + }); - $.when(model.update()).done(function () { - app_list_view.model = model; - app_view.model = model; + var app_view = new application_view.ApplicationView({ + el: 'div.content-wrapper', + data: function() { return { model: model }; } }); + + model.update(); }); diff --git a/remoteappmanager/static/js/home/models.js b/remoteappmanager/static/js/home/models.js index 63557850f..5998de286 100644 --- a/remoteappmanager/static/js/home/models.js +++ b/remoteappmanager/static/js/home/models.js @@ -69,7 +69,13 @@ define([ // Add the options for some image types app_data.forEach(function(application_data, data_idx) { - this.app_list[data_idx] = { app_data: application_data }; + this.app_list.push({ + app_data: application_data, + // Default values, will be overwritten + status: Status.STOPPED, + delayed: true, + configurables: [] + }); this._update_configurables(data_idx); this._update_status(data_idx); @@ -103,11 +109,6 @@ define([ // Updates the configurables submodel for a given application index. var image = this.app_list[index].app_data.image; - // Contains the submodels for the configurables. - // It is a dictionary that maps a supported (by the image) configurable tag - // to its client-side model. - this.app_list[index].configurables = []; - 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 diff --git a/remoteappmanager/static/js/home/views/application_list_view.js b/remoteappmanager/static/js/home/views/application_list_view.js index c6cdaf481..6fdf92a46 100644 --- a/remoteappmanager/static/js/home/views/application_list_view.js +++ b/remoteappmanager/static/js/home/views/application_list_view.js @@ -13,14 +13,6 @@ define([ (will next be wrapped in a main ViewModel which will contain the applicationListView and the applicationView) */ var ApplicationListView = Vue.extend({ - el: '#applist', - - data: function() { - return { - model: { app_list: [], selected_index: null, loading: true } - }; - }, - methods: { stop_application: function(index) { var app_stopping = this.model.app_list[index]; diff --git a/remoteappmanager/static/js/home/views/application_view.js b/remoteappmanager/static/js/home/views/application_view.js index 41be6e43c..55592ab95 100644 --- a/remoteappmanager/static/js/home/views/application_view.js +++ b/remoteappmanager/static/js/home/views/application_view.js @@ -14,14 +14,6 @@ define([ var Status = utils.Status; var ApplicationView = Vue.extend({ - el: 'div.content-wrapper', - - data: function() { - return { - model: { app_list: [], selected_index: null, loading: true } - }; - }, - computed: { current_app: function() { return this.model.app_list[this.model.selected_index] || null; From a351e7ac5c982d13c95c437420b524324ce4ef66 Mon Sep 17 00:00:00 2001 From: martinRenou Date: Thu, 27 Apr 2017 12:50:03 +0100 Subject: [PATCH 05/13] Reinitialize configurables at update --- remoteappmanager/static/js/home/models.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/remoteappmanager/static/js/home/models.js b/remoteappmanager/static/js/home/models.js index 5998de286..08581892e 100644 --- a/remoteappmanager/static/js/home/models.js +++ b/remoteappmanager/static/js/home/models.js @@ -109,6 +109,11 @@ define([ // Updates the configurables submodel for a given application index. var image = this.app_list[index].app_data.image; + // Contains the submodels for the configurables. + // It is a dictionary that maps a supported (by the image) configurable tag + // to its client-side model. + this.app_list[index].configurables = []; + 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 From a92cb9a6ceca47ae5927e77dc779dced0665ec96 Mon Sep 17 00:00:00 2001 From: martinRenou Date: Thu, 27 Apr 2017 12:52:51 +0100 Subject: [PATCH 06/13] Fix linter test --- remoteappmanager/static/js/home/controller.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/remoteappmanager/static/js/home/controller.js b/remoteappmanager/static/js/home/controller.js index f209d0bc7..acdd0003f 100644 --- a/remoteappmanager/static/js/home/controller.js +++ b/remoteappmanager/static/js/home/controller.js @@ -15,12 +15,12 @@ require([ // It is only synchronized at initial load. var model = new models.ApplicationListModel(); - var app_list_view = new application_list_view.ApplicationListView({ + new application_list_view.ApplicationListView({ // jshint ignore:line el: '#applist', data: function() { return { model: model }; } }); - var app_view = new application_view.ApplicationView({ + new application_view.ApplicationView({ // jshint ignore:line el: 'div.content-wrapper', data: function() { return { model: model }; } }); From fd26c3e2f6f08838aba74285fe35ce9e15ada00d Mon Sep 17 00:00:00 2001 From: martinRenou Date: Thu, 27 Apr 2017 13:13:36 +0100 Subject: [PATCH 07/13] Start_application and stop_application are now model methods --- remoteappmanager/static/js/home/controller.js | 2 - remoteappmanager/static/js/home/models.js | 61 ++++++++++++++++++- .../js/home/views/application_list_view.js | 29 +-------- .../static/js/home/views/application_view.js | 42 +------------ remoteappmanager/templates/home.html | 4 +- 5 files changed, 64 insertions(+), 74 deletions(-) diff --git a/remoteappmanager/static/js/home/controller.js b/remoteappmanager/static/js/home/controller.js index acdd0003f..5afa87085 100644 --- a/remoteappmanager/static/js/home/controller.js +++ b/remoteappmanager/static/js/home/controller.js @@ -1,11 +1,9 @@ /*globals: require, console*/ require([ - "urlutils", "home/models", "home/views/application_list_view", "home/views/application_view" ], function( - urlutils, models, application_list_view, application_view) { diff --git a/remoteappmanager/static/js/home/models.js b/remoteappmanager/static/js/home/models.js index 08581892e..653ddb5ca 100644 --- a/remoteappmanager/static/js/home/models.js +++ b/remoteappmanager/static/js/home/models.js @@ -2,11 +2,14 @@ define([ 'jquery', 'home/configurables', 'utils', - 'jsapi/v1/resources' -], function ($, configurables, utils, resources) { + 'jsapi/v1/resources', + "gamodule", + "dialogs" +], function ($, configurables, utils, resources, gamodule, dialogs) { "use strict"; var Status = utils.Status; + var ga = gamodule.init(); var available_applications_info = function () { // Retrieve information from the various applications and @@ -137,6 +140,60 @@ define([ } }; + ApplicationListModel.prototype.start_application = function() { + var selected_index = this.selected_index; + var current_app = this.app_list[selected_index]; + + current_app.status = Status.STARTING; + current_app.delayed = true; + + var configurables_data = {}; + current_app.configurables.forEach(function(configurable) { + var tag = configurable.tag; + configurables_data[tag] = configurable.as_config_dict(); + }); + + resources.Container.create({ + mapping_id: current_app.app_data.mapping_id, + configurables: configurables_data + }).done(function() { + ga("send", "event", { + eventCategory: "Application", + eventAction: "start", + eventLabel: current_app.app_data.image.name + }); + + this.update_idx(selected_index) + .fail(function(error) { + current_app.status = Status.STOPPED; + dialogs.webapi_error_dialog(error); + }); + }.bind(this)).fail(function(error) { + current_app.status = Status.STOPPED; + dialogs.webapi_error_dialog(error); + }); + } + + ApplicationListModel.prototype.stop_application = function(index) { + var app_stopping = this.app_list[index]; + app_stopping.status = Status.STOPPING; + + var url_id = app_stopping.app_data.container.url_id; + + resources.Container.delete(url_id) + .done(function() { + this.update_idx(index) + .fail(function(error) { + app_stopping.status = Status.STOPPED; + dialogs.webapi_error_dialog(error); + }); + }.bind(this)) + .fail(function(error) { + app_stopping.status = Status.STOPPED; + dialogs.webapi_error_dialog(error); + }); + } + return { ApplicationListModel: ApplicationListModel }; diff --git a/remoteappmanager/static/js/home/views/application_list_view.js b/remoteappmanager/static/js/home/views/application_list_view.js index 6fdf92a46..d7336bc85 100644 --- a/remoteappmanager/static/js/home/views/application_list_view.js +++ b/remoteappmanager/static/js/home/views/application_list_view.js @@ -1,40 +1,13 @@ define([ - 'urlutils', 'utils', - "dialogs", '../../components/vue/dist/vue.min', - "jsapi/v1/resources" -], function (urlutils, utils, dialogs, Vue, resources) { +], function (utils, Vue) { 'use strict'; - var Status = utils.Status; - /* Create application_list ViewModel (will next be wrapped in a main ViewModel which will contain the applicationListView and the applicationView) */ var ApplicationListView = Vue.extend({ - methods: { - stop_application: function(index) { - var app_stopping = this.model.app_list[index]; - app_stopping.status = Status.STOPPING; - - var url_id = app_stopping.app_data.container.url_id; - - resources.Container.delete(url_id) - .done(function() { - this.model.update_idx(index) - .fail(function(error) { - app_stopping.status = Status.STOPPED; - dialogs.webapi_error_dialog(error); - }); - }.bind(this)) - .fail(function(error) { - app_stopping.status = Status.STOPPED; - dialogs.webapi_error_dialog(error); - }); - } - }, - filters: utils.filters }); diff --git a/remoteappmanager/static/js/home/views/application_view.js b/remoteappmanager/static/js/home/views/application_view.js index 55592ab95..53050fd1e 100644 --- a/remoteappmanager/static/js/home/views/application_view.js +++ b/remoteappmanager/static/js/home/views/application_view.js @@ -2,15 +2,10 @@ define([ 'jquery', "urlutils", "utils", - "gamodule", - "dialogs", - "home/models", - '../../components/vue/dist/vue.min', - "jsapi/v1/resources" -], function ($, urlutils, utils, gamodule, dialogs, models, Vue, resources) { + '../../components/vue/dist/vue.min' +], function ($, urlutils, utils, Vue) { "use strict"; - var ga = gamodule.init(); var Status = utils.Status; var ApplicationView = Vue.extend({ @@ -36,39 +31,6 @@ define([ }, methods: { - start_application: function() { - var selected_index = this.model.selected_index; - var current_app = this.current_app; - - current_app.status = Status.STARTING; - current_app.delayed = true; - - var configurables_data = {}; - current_app.configurables.forEach(function(configurable) { - var tag = configurable.tag; - configurables_data[tag] = configurable.as_config_dict(); - }); - - resources.Container.create({ - mapping_id: current_app.app_data.mapping_id, - configurables: configurables_data - }).done(function() { - ga("send", "event", { - eventCategory: "Application", - eventAction: "start", - eventLabel: current_app.app_data.image.name - }); - - this.model.update_idx(selected_index) - .fail(function(error) { - current_app.status = Status.STOPPED; - dialogs.webapi_error_dialog(error); - }); - }.bind(this)).fail(function(error) { - current_app.status = Status.STOPPED; - dialogs.webapi_error_dialog(error); - }); - }, get_iframe_size: function() { return utils.max_iframe_size(); } diff --git a/remoteappmanager/templates/home.html b/remoteappmanager/templates/home.html index 4a99866e4..f9dab1fb3 100644 --- a/remoteappmanager/templates/home.html +++ b/remoteappmanager/templates/home.html @@ -53,7 +53,7 @@ @@ -111,7 +111,7 @@

    Configuration