Skip to content

Commit

Permalink
Merge pull request #269 from simphony/258-new-tab
Browse files Browse the repository at this point in the history
Open new window when starting or viewing application
  • Loading branch information
stefanoborini authored Sep 28, 2016
2 parents 393efc0 + b12a2ee commit 907f35c
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 66 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ jstest:
jshint --config .jshintrc remoteappmanager/static/js/
node-qunit-phantomjs jstests/tests.html

.PHONY: seleniumtest
seleniumtest:
python -m unittest discover -s selenium_tests -t . -v

.PHONY: docs
docs:
sphinx-build -W doc/source doc/build/sphinx
9 changes: 4 additions & 5 deletions jstests/tests/test_remoteappapi.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
define(function (require) {
var RemoteAppAPI = require("remoteappapi");

QUnit.module("Remote App API");
QUnit.test("test", function (assert) {
var RemoteAppAPI = require("remoteappapi");
QUnit.module("Remote App API");
QUnit.test("test", function (assert) {
var api = new RemoteAppAPI();
assert.ok(api !== null);
});
});
});
47 changes: 32 additions & 15 deletions remoteappmanager/static/js/home/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,43 @@ require(
$(".spawn-error-msg").text(msg).show();
};

var new_container_window = function (url_id) {
// Opens a new window for the container at url_id
var w = window.open(undefined);
if (w !== undefined) {
w.location = utils.url_path_join(
base_url,
"containers",
url_id
);
}
};

view.view_button_clicked = function (index) {
var promise = $.Deferred();
var app_info = model.app_data[index];

window.location = utils.url_path_join(
base_url,
"containers",
app_info.container.url_id);
new_container_window(app_info.container.url_id);
promise.resolve();
return promise;
};

view.stop_button_clicked = function (index) {
var promise = $.Deferred();
var app_info = model.app_data[index];

var url_id = app_info.container.url_id;
return appapi.stop_application(url_id, {

appapi.stop_application(url_id, {
success: function () {
app_info.container = null;
view.update_entry(index);
model.update_idx(index)
.done(promise.resolve)
.fail(promise.reject);
},
error: function (jqXHR, status, error) {
report_error(jqXHR, status, error);
promise.reject();
}});
return promise;
};

view.start_button_clicked = function (index) {
Expand All @@ -56,10 +72,12 @@ require(
configurables_data[tag] = configurable.as_config_dict();
}
);

return appapi.start_application(mapping_id, configurables_data, {

var promise = $.Deferred();
appapi.start_application(mapping_id, configurables_data, {
error: function(jqXHR, status, error) {
report_error(jqXHR, status, error);
promise.reject();
},
statusCode: {
201: function (data, textStatus, request) {
Expand All @@ -68,14 +86,13 @@ require(
var arr = url.pathname.replace(/\/$/, "").split('/');
var url_id = arr[arr.length-1];

window.location = utils.url_path_join(
base_url,
"containers",
url_id
);
new_container_window(url_id);
model.update_idx(index).done(promise.resolve);
}
}
});

return promise;
};

$.when(model.update()).done(function () { view.render(); });
Expand Down
52 changes: 36 additions & 16 deletions remoteappmanager/static/js/home/models.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,45 @@ define(['jquery', 'home/configurables'], function ($, configurables) {

// Add the options for some image types
for (var data_idx = 0; data_idx < self.app_data.length; ++data_idx) {
var image = self.app_data[data_idx].image;
self.configurables[data_idx] = {};

for (var cfg_idx = 0; cfg_idx < image.configurables.length; ++cfg_idx) {
var tag = image.configurables[cfg_idx];

// 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.from_tag(tag);

if (ConfigurableCls !== null) {
self.configurables[data_idx][tag] = new ConfigurableCls();
}
}
self._update_configurables(data_idx);
}
});
};

ApplicationListModel.prototype.update_idx = function(index) {
// Refetches and updates the entry at the given index.
var self = this;

var entry = this.app_data[index];
var mapping_id = entry.mapping_id;
return $.when(
self._appapi.application_info(mapping_id)
).done(function(new_data) {
self.app_data[index] = new_data;
self._update_configurables(index);
});
};

ApplicationListModel.prototype._update_configurables = function(index) {
// Updates the configurables submodel for a given application index.
var self = this;
var image = self.app_data[index].image;
self.configurables[index] = {};

for (var cfg_idx = 0; cfg_idx < image.configurables.length; ++cfg_idx) {
var tag = image.configurables[cfg_idx];

// 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.from_tag(tag);

if (ConfigurableCls !== null) {
self.configurables[index][tag] = new ConfigurableCls();
}
}
};

return {
ApplicationListModel: ApplicationListModel
Expand Down
35 changes: 17 additions & 18 deletions remoteappmanager/static/js/home/views.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ define(["jquery", "utils"], function ($, utils) {
this.stop_button_clicked = function(index) {};
this.start_button_clicked = function(index) {};
this.view_button_clicked = function(index) {};

this._x_button_clicked = function () {
// Triggered when the button X (left side) is clicked
var button = this;
var index = $(button).data("index");
var button = $(this);
var index = button.data("index");

var icon_elem = $(button).find(".x-icon");
var icon_elem = button.find(".x-icon");
var icons = ['fa-start', 'fa-eye'];
var icon_type;

Expand All @@ -35,29 +35,28 @@ define(["jquery", "utils"], function ($, utils) {
}
}

var update_entry = function () { self.update_entry(index); };
icon_elem.removeClass(icon_type).addClass("fa-spinner fa-spin");

var restore_icon = function () {
icon_elem.removeClass("fa-spinner fa-spin").addClass(icon_type);
};

var app_info = self.model.app_data[index];
button.prop("disabled", true);

var app_info = self.model.app_data[index];
if (app_info.container !== null) {
self.view_button_clicked(index).done(restore_icon);
self.view_button_clicked(index).always(update_entry);
} else {
self.start_button_clicked(index).done(restore_icon);
self.start_button_clicked(index).always(update_entry);
}
};

this._y_button_clicked = function () {
var button = this;
var index = $(button).data("index");
$(button).find(".y-icon").removeClass("fa-stop").addClass("fa-spinner fa-spin");
var button = $(this);
var index = button.data("index");
var icon_elem = button.find(".y-icon");

self.stop_button_clicked(index).done(function () {
$(button).find(".y-icon").removeClass("fa-spinner fa-spin").addClass("fa-stop");
});
icon_elem.removeClass("fa-stop").addClass("fa-spinner fa-spin");
button.prop("disabled", true);

var update_entry = function () { self.update_entry(index); };
self.stop_button_clicked(index).always(update_entry);
};

$("#applist").html(
Expand Down
14 changes: 14 additions & 0 deletions selenium_tests/selenium_test_base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# -*- coding: utf-8 -*-
import time
import os
import contextlib
import sqlite3
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
Expand All @@ -23,6 +26,17 @@ def setUp(self):
self.verificationErrors = []
self.accept_next_alert = True

permissions_db_path = os.path.join(ff_profile.profile_dir,
"permissions.sqlite")

with contextlib.closing(sqlite3.connect(permissions_db_path)) as db:
cur = db.cursor()
cur.execute(
("INSERT INTO moz_perms VALUES (1, '{base_url}', "
"'popup', 1, 0, 0, 1474977124357)").format(
base_url=self.base_url))
db.commit()

def is_element_present(self, how, what):
try:
self.driver.find_element(by=how, value=what)
Expand Down
22 changes: 10 additions & 12 deletions selenium_tests/test_start_stop_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,28 @@ def test_start_stop_container(self):
wait = WebDriverWait(driver, 10)
wait.until(EC.element_to_be_clickable((By.ID, 'bnx_0')))

self.assertEqual(len(driver.window_handles), 1)
main_window = driver.window_handles[0]

driver.execute_script(
"arguments[0].click()",
driver.find_element_by_id("bnx_0")
)
self.wait_for(lambda: "noVNC" == driver.title)
driver.execute_script(
"arguments[0].click()",
driver.find_element_by_link_text("Close")
)
self.wait_for(lambda: "noVNC" != driver.title)

self.wait_for(lambda: len(driver.window_handles) == 2)
driver.switch_to.window(main_window)

driver.find_element_by_css_selector(".view-button")
# Try clicking on View.
driver.execute_script(
"arguments[0].click()",
driver.find_element_by_id("bnx_0")
)
self.wait_for(lambda: "noVNC" == driver.title)
driver.execute_script(
"arguments[0].click()",
driver.find_element_by_link_text("Close")
)

self.wait_for(lambda: len(driver.window_handles) == 3)
driver.switch_to.window(main_window)

# Click on Stop.
self.wait_for(lambda: "noVNC" != driver.title)
driver.execute_script(
"arguments[0].click()",
driver.find_element_by_id("bny_0")
Expand Down

0 comments on commit 907f35c

Please sign in to comment.