All new accounts created on Gitlab now require administrator approval. If you invite any collaborators, please let Flux staff know so they can approve the accounts.

Commit 273e5ebb authored by Leigh B Stoller's avatar Leigh B Stoller

Rework imdataset dataset forms to use cascading selection lists, to

avoid total user confusion about what to do.
parent 66f5265f
......@@ -146,6 +146,12 @@ function (_, sup, moment, mainString, helpString)
return;
});
});
// After error, need to rebuild selections lists
if (formfields.dataset_instance) {
HandleInstanceChange(formfields.dataset_instance,
formfields.dataset_node,
formfields.dataset_bsname);
}
}
//
......@@ -270,32 +276,78 @@ function (_, sup, moment, mainString, helpString)
}
/*
* When instance changes, need to get the manifest and find the
* a node with a blockstore to offer the user.
* When instance changes, need to get the manifest and find the a
* node with a blockstore to offer the user. The node and bsname
* args are optional, used for regenerating the form after an
* error.
*/
function HandleInstanceChange(uuid)
function HandleInstanceChange(uuid, selected_node, selected_bsname)
{
var EMULAB_NS = "http://www.protogeni.net/resources/rspec/ext/emulab/1";
var noderefs = {};
// Clear old handler, set again below.
$('#dataset_node').off("change");
var callback = function(json) {
var xmlDoc = $.parseXML(json.value);
var xml = $(xmlDoc);
/*
* Build up selection list of nodes in the instance that
* contain block stores.
*/
var options = "";
$(xml).find("node").each(function() {
var node = $(this).attr("client_id");
var bsref = this.getElementsByTagNameNS(EMULAB_NS,'blockstore');
_.each(json.value, function(manifest, aggregate_urn) {
var xmlDoc = $.parseXML(manifest);
var xml = $(xmlDoc);
if (bsref.length) {
var bsname = $(bsref).attr("name");
var bsclass = $(bsref).attr("class");
$(xml).find("node").each(function() {
var node = $(this).attr("client_id");
var bslist = this.getElementsByTagNameNS(EMULAB_NS,
'blockstore');
var selected = (selected_node == node ? "selected" : "");
if (bsclass == "local") {
$('#dataset_node').val(node);
$('#dataset_bsname').val(bsname);
return;
for (var i = 0; i < bslist.length; ++i) {
var bsname = $(bslist[i]).attr("name");
var bsclass = $(bslist[i]).attr("class");
if (bsclass == "local") {
noderefs[node] = this;
options = options +
"<option value='" + node +
"' " + selected + " >" +
node + "</option>";
return;
}
}
}
});
});
if (options == "") {
$('#dataset_node')
.html("<option value=''>Please Select</option>");
$('#dataset_bsname')
.html("<option value=''>Please Select</option>");
sup.SpitOops("oops",
"The selected instance does not have any nodes " +
"that can be used to create an image backed dataset");
return;
}
$('#dataset_node')
.html("<option value=''>Please Select</option>" + options);
$('#dataset_bsname')
.html("<option value=''>Please Select</option>");
$('#dataset_node').on("change", function (event) {
$("#dataset_node option:selected").each(function() {
HandleInstanceNodeChange(noderefs[$(this).val()]);
return;
});
});
if (selected_node && selected_bsname) {
HandleInstanceNodeChange(noderefs[selected_node],
selected_bsname);
}
};
var xmlthing = sup.CallServerMethod(null, "status",
"GetInstanceManifest",
......@@ -303,6 +355,31 @@ function (_, sup, moment, mainString, helpString)
xmlthing.done(callback);
}
function HandleInstanceNodeChange(noderef, selected_bsname)
{
var EMULAB_NS = "http://www.protogeni.net/resources/rspec/ext/emulab/1";
/*
* Build up selection list of blockstores on the node.
*/
var options = "";
var bslist = noderef.getElementsByTagNameNS(EMULAB_NS, 'blockstore');
for (var i = 0; i < bslist.length; ++i) {
var bsname = $(bslist[i]).attr("name");
var bsclass = $(bslist[i]).attr("class");
var selected = (selected_bsname == bsname ? "selected" : "");
if (bsclass == "local") {
options = options +
"<option value='" + bsname + "' " + selected + " >" +
bsname + "</option>";
}
}
$('#dataset_bsname')
.html("<option value=''>Please Select</option>" + options);
}
$(document).ready(initialize);
});
......
......@@ -341,6 +341,13 @@ function (_, sup, moment, mainString, snapshotString, ShowImagingModal)
return;
});
});
// After error, need to rebuild selections lists
if (formfields.dataset_instance) {
HandleInstanceChange(formfields.dataset_instance,
formfields.dataset_node,
formfields.dataset_bsname);
}
//
// Handle submit button.
//
......@@ -410,32 +417,78 @@ function (_, sup, moment, mainString, snapshotString, ShowImagingModal)
}
/*
* When instance changes, need to get the manifest and find the
* a node with a blockstore to offer the user.
* When instance changes, need to get the manifest and find the a
* node with a blockstore to offer the user. The node and bsname
* args are optional, used for regenerating the form after an
* error.
*/
function HandleInstanceChange(uuid)
function HandleInstanceChange(uuid, selected_node, selected_bsname)
{
var EMULAB_NS = "http://www.protogeni.net/resources/rspec/ext/emulab/1";
var noderefs = {};
// Clear old handler, set again below.
$('#dataset_node').off("change");
var callback = function(json) {
var xmlDoc = $.parseXML(json.value);
var xml = $(xmlDoc);
/*
* Build up selection list of nodes in the instance that
* contain block stores.
*/
var options = "";
$(xml).find("node").each(function() {
var node = $(this).attr("client_id");
var bsref = this.getElementsByTagNameNS(EMULAB_NS,'blockstore');
_.each(json.value, function(manifest, aggregate_urn) {
var xmlDoc = $.parseXML(manifest);
var xml = $(xmlDoc);
if (bsref.length) {
var bsname = $(bsref).attr("name");
var bsclass = $(bsref).attr("class");
$(xml).find("node").each(function() {
var node = $(this).attr("client_id");
var bslist = this.getElementsByTagNameNS(EMULAB_NS,
'blockstore');
var selected = (selected_node == node ? "selected" : "");
if (bsclass == "local") {
$('#dataset_node').val(node);
$('#dataset_bsname').val(bsname);
return;
for (var i = 0; i < bslist.length; ++i) {
var bsname = $(bslist[i]).attr("name");
var bsclass = $(bslist[i]).attr("class");
if (bsclass == "local") {
noderefs[node] = this;
options = options +
"<option value='" + node +
"' " + selected + " >" +
node + "</option>";
return;
}
}
}
});
});
if (options == "") {
$('#dataset_node')
.html("<option value=''>Please Select</option>");
$('#dataset_bsname')
.html("<option value=''>Please Select</option>");
sup.SpitOops("oops",
"The selected instance does not have any nodes " +
"that can be used to create an image backed dataset");
return;
}
$('#dataset_node')
.html("<option value=''>Please Select</option>" + options);
$('#dataset_bsname')
.html("<option value=''>Please Select</option>");
$('#dataset_node').on("change", function (event) {
$("#dataset_node option:selected").each(function() {
HandleInstanceNodeChange(noderefs[$(this).val()]);
return;
});
});
if (selected_node && selected_bsname) {
HandleInstanceNodeChange(noderefs[selected_node],
selected_bsname);
}
};
var xmlthing = sup.CallServerMethod(null, "status",
"GetInstanceManifest",
......@@ -443,6 +496,31 @@ function (_, sup, moment, mainString, snapshotString, ShowImagingModal)
xmlthing.done(callback);
}
function HandleInstanceNodeChange(noderef, selected_bsname)
{
var EMULAB_NS = "http://www.protogeni.net/resources/rspec/ext/emulab/1";
/*
* Build up selection list of blockstores on the node.
*/
var options = "";
var bslist = noderef.getElementsByTagNameNS(EMULAB_NS, 'blockstore');
for (var i = 0; i < bslist.length; ++i) {
var bsname = $(bslist[i]).attr("name");
var bsclass = $(bslist[i]).attr("class");
var selected = (selected_bsname == bsname ? "selected" : "");
if (bsclass == "local") {
options = options +
"<option value='" + bsname + "' " + selected + " >" +
bsname + "</option>";
}
}
$('#dataset_bsname')
.html("<option value=''>Please Select</option>" + options);
}
$(document).ready(initialize);
});
......
......@@ -123,21 +123,36 @@
</option>
<% }); %>
</select>
<select name="dataset_node"
id="dataset_node"
class='form-control format-me'
data-key="dataset_node"
data-label="Node"
placeholder='Please Select'>
</select>
<select name="dataset_bsname"
id="dataset_bsname"
class='form-control format-me'
data-key="dataset_bsname"
data-label="BS Name"
placeholder='Please Select'>
</select>
<% } else if (embedded) { %>
<input name="dataset_node" id='dataset_node'
value="<%- formfields.dataset_node %>"
class="form-control format-me"
data-key="dataset_node"
data-label="Node"
placeholder="Node to snapshot dataset from"
type="text">
<input name="dataset_bsname" id='dataset_bsname'
value="<%- formfields.dataset_bsname %>"
class="form-control format-me"
data-key="dataset_bsname"
data-label="BS Name"
placeholder="Blockstore name on the node"
type="text">
<% } %>
<input name="dataset_node" id='dataset_node'
value="<%- formfields.dataset_node %>"
class="form-control format-me"
data-key="dataset_node"
data-label="Node"
placeholder="Node to snapshot dataset from"
type="text">
<input name="dataset_bsname" id='dataset_bsname'
value="<%- formfields.dataset_bsname %>"
class="form-control format-me"
data-key="dataset_bsname"
data-label="BS Name"
placeholder="Blockstore name on the node"
type="text">
</div>
<% } %>
<div id='dataset_expires_div'
......
......@@ -38,7 +38,21 @@
</option>
<% }); %>
</select>
<% } %>
<select name="dataset_node"
id="dataset_node"
class='form-control format-me'
data-key="dataset_node"
data-label="Node"
placeholder='Please Select'>
</select>
<select name="dataset_bsname"
id="dataset_bsname"
class='form-control format-me'
data-key="dataset_bsname"
data-label="BS Name"
placeholder='Please Select'>
</select>
<% } else if (embedded) { %>
<input name="dataset_node" id='dataset_node'
value="<%- formfields.dataset_node %>"
class="form-control format-me"
......@@ -53,6 +67,7 @@
data-label="BS Name"
placeholder="Blockstore name on the node"
type="text">
<% } %>
</div>
<br><br>
<center>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment