aboutsummaryrefslogtreecommitdiffstats
path: root/fg21sim/webui
diff options
context:
space:
mode:
authorAaron LI <aaronly.me@outlook.com>2016-11-23 19:36:04 +0800
committerAaron LI <aaronly.me@outlook.com>2016-11-23 19:36:04 +0800
commitd6c0c5e4d102365f64373dd0c5df305424484bc1 (patch)
tree0684b9524785a8efa7e2b02ac26a37ab7df500db /fg21sim/webui
parent64da94ad6393c1361e9e065f6c5708a6551b050c (diff)
downloadfg21sim-d6c0c5e4d102365f64373dd0c5df305424484bc1.tar.bz2
webui: products: Add the client-side support for opening HPX images
Diffstat (limited to 'fg21sim/webui')
-rw-r--r--fg21sim/webui/static/js/products.js79
-rw-r--r--fg21sim/webui/templates/products.html4
2 files changed, 70 insertions, 13 deletions
diff --git a/fg21sim/webui/static/js/products.js b/fg21sim/webui/static/js/products.js
index 72a7028..452d05e 100644
--- a/fg21sim/webui/static/js/products.js
+++ b/fg21sim/webui/static/js/products.js
@@ -198,15 +198,7 @@ var getServerManifest = function (url) {
* @param {String} cmd - The command name or path.
*/
var whichExecutable = function (url, cmd) {
- return $.getJSON(url, {action: "which", cmd: JSON.stringify(cmd)})
- .fail(function (jqxhr) {
- var modalData = {};
- modalData.icon = "times-circle";
- modalData.contents = "Cannot locate the command in PATH!";
- modalData.code = jqxhr.status;
- modalData.reason = jqxhr.statusText;
- showModalProducts(modalData);
- });
+ return $.getJSON(url, {action: "which", cmd: JSON.stringify(cmd)});
};
@@ -253,6 +245,32 @@ var convertProductHPX = function (url, compID, freqID) {
};
+/**
+ * Open the HPX FITS image of the specified product
+ *
+ * NOTE: This request is only allowed when using the Web UI on the localhost
+ *
+ * @param {String} viewer - The command name or path for the FITS viewer.
+ */
+var openProductHPX = function (url, compID, freqID, viewer) {
+ var data = {
+ action: "open",
+ compID: JSON.stringify(compID),
+ freqID: JSON.stringify(freqID),
+ viewer: JSON.stringify(viewer)
+ };
+ return $.getJSON(url, data)
+ .fail(function (jqxhr) {
+ showModalProducts({
+ icon: "times-circle",
+ contents: "Failed to open the HPX image!",
+ code: jqxhr.status,
+ reason: jqxhr.statusText
+ });
+ });
+};
+
+
$(document).ready(function () {
// URL to handle the "products" AJAX requests
var ajax_url = "/ajax/products";
@@ -265,6 +283,21 @@ $(document).ready(function () {
$("input#products-manifest").val(joinPath(workdir, manifest));
});
+ // Validate the FITS viewer executable on change
+ $("input#products-fitsviewer").on("change", function () {
+ var target = $(this);
+ var cmd = target.val();
+ whichExecutable(ajax_url, cmd)
+ .done(function (response) {
+ target[0].setCustomValidity("");
+ target.removeClass("error").data("validity", true);
+ })
+ .fail(function (jqxhr) {
+ target[0].setCustomValidity(jqxhr.statusText);
+ target.addClass("error").data("validity", false);
+ });
+ }).trigger("change"); // Manually trigger the "change" after loading
+
// Get and load products manifest into table
$("#load-products").on("click", function () {
loadServerManifest(ajax_url)
@@ -309,8 +342,8 @@ $(document).ready(function () {
]
};
if (product.data("hpx-image")) {
- var p = ("HPX image: " + product.data("hpx-path") + ", size: " +
- (product.data("hpx-size")/1024/1024).toFixed(1) +
+ var p = ("<strong>HPX image:</strong> " + product.data("hpx-path") +
+ ", size: " + (product.data("hpx-size")/1024/1024).toFixed(1) +
" MB, MD5: " + product.data("hpx-md5"));
modalData.contents.push(p);
}
@@ -335,4 +368,28 @@ $(document).ready(function () {
});
});
});
+
+ // Open the HPX FITS image
+ // NOTE: Only allowed when accessing the Web UI from localhost
+ $(document).on("click", "td.product > .hpx.hpx-open", function () {
+ var input_viewer = $("input#products-fitsviewer");
+ if (input_viewer.data("validity")) {
+ var cell = $(this).closest("td");
+ var compID = cell.data("compID");
+ var freqID = cell.data("freqID");
+ var viewer = input_viewer.val();
+ openProductHPX(ajax_url, compID, freqID, viewer)
+ .done(function (response) {
+ showModalProducts({
+ icon: "check-circle",
+ contents: "Opened HPX FITS image. (PID: " + response.pid + ")"
+ });
+ });
+ } else {
+ showModalProducts({
+ icon: "times-circle",
+ contents: "Invalid name/path for the FITS viewer executable!"
+ });
+ }
+ });
});
diff --git a/fg21sim/webui/templates/products.html b/fg21sim/webui/templates/products.html
index a883565..6ef7e1f 100644
--- a/fg21sim/webui/templates/products.html
+++ b/fg21sim/webui/templates/products.html
@@ -28,8 +28,8 @@
{% if from_localhost %}
<div class="row">
<div class="column form-group">
- <label for="products-ds9">DS9 Executable Path:</label>
- <input class="form-control code" type="text" id="products-ds9" value="ds9" />
+ <label for="products-fitsviewer">FITS Viewer Path:</label>
+ <input class="form-control code" type="text" id="products-fitsviewer" value="ds9" />
</div>
</div>
{% end %}