Tentative Web UI for the Printer device. (#676)

* Tentative Web UI for the Printer device.

* timeout must be a positive value

* Change the attach device class method to accept a dict with arbitrary key value pairs of parameters to be passed to the protobuf interface, rather than hard coded ones. Also renames the RaCtlCmds.attach_image() class method to attach_device().

* Make download_to_iso() use the new attach interface.

* Dynamically get the form items for support devices.

* Change the data structure returned by RaCtlCmds.get_device_types() to a dict, which contains the supported parameters and their default values. Leverage this data in the web ui to derive the form fields from the capabilities of rascsi.

* Tweak UI labels.

* Update FileCmds.read_config() to work with the new RaCtlCmds.attach_device() method.

* Check for numeric value.

* Streamline the UI for support devices.

* Handle support devices better by the oled screen.

* Clean up html.

* Dynamically adjust form field size based on data length.
This commit is contained in:
Daniel Markstedt
2022-02-19 00:04:14 -08:00
committed by GitHub
parent 81ca3c0ce8
commit 2184992ce7
7 changed files with 97 additions and 72 deletions
+4 -2
View File
@@ -68,13 +68,15 @@ def extend_device_names(device_types):
elif device_type == "SCMO":
device_name = _("Magneto-Optical")
elif device_type == "SCCD":
device_name = _("CD-ROM / DVD")
device_name = _("CD / DVD")
elif device_type == "SCBR":
device_name = _("X68000 Host Bridge")
elif device_type == "SCDP":
device_name = _("DaynaPORT SCSI/Link")
elif device_type == "SCLP":
device_name = _("Printer")
elif device_type == "SCHS":
device_name = _("Host Service")
device_name = _("Host Services")
else:
device_name = _("Unknown Device")
mapped_device_types[device_type] = device_name
+28 -26
View File
@@ -316,17 +316,6 @@
<tr style="border: none">
<td style="border: none; vertical-align:top;">
<form action="/scsi/attach_network" method="post">
<label for="if">{{ _("Interface:") }}</label>
<select name="if">
{% for if in netinfo["ifs"] %}
<option value="{{ if }}">
{{ if }}
</option>
{% endfor %}
</select>
<label for="ip">{{ _("Static IP (optional):") }}</label>
<input name="ip" type="text" size="15" placeholder="10.10.20.1" minlength="7" maxlength="15" pattern="^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$">
<input name="mask" type="number" size="2" placeholder="24" min="16" max="30">
<label for="type">{{ _("Type:") }}</label>
<select name="type">
{% for type in NETWORK_DEVICE_TYPES %}
@@ -339,6 +328,17 @@
</option>
{% endfor %}
</select>
<label for="if">{{ _("Interface:") }}</label>
<select name="if">
{% for if in netinfo["ifs"] %}
<option value="{{ if }}">
{{ if }}
</option>
{% endfor %}
</select>
<label for="ip">{{ _("Static IP (optional):") }}</label>
<input name="ip" type="text" size="15" placeholder="10.10.20.1" minlength="7" maxlength="15" pattern="^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$">
<input name="mask" type="number" size="2" placeholder="24" min="16" max="30">
<label for="scsi_id">{{ _("SCSI ID:") }}</label>
<select name="scsi_id">
{% for id in scsi_ids %}
@@ -372,22 +372,23 @@
</li>
</ul>
</details>
<table style="border: none">
<tr style="border: none">
<td style="border: none; vertical-align:top;">
<table border="black" cellpadding="3">
{% for type in SUPPORT_DEVICE_TYPES %}
<tr>
<td>
<div>{{ _("Type:") }} <strong>{{ device_types[type] }}</strong></div>
</td>
<td>
<form action="/scsi/attach_support" method="post">
<label for="type">{{ _("Type:") }}</label>
<select name="type">
{% for type in SUPPORT_DEVICE_TYPES %}
<option value="{{ type }}">
{% for key, value in device_types.items() %}
{% if key == type %}
{{ value }}
{% endif %}
{% endfor %}
</option>
{% endfor %}
</select>
<input name="type" type="hidden" value="{{ type }}">
{% for key, value in device_params[type].items() %}
<label for="{{ key }}">{{ key }}:</label>
{% if value.isnumeric() %}
<input name="{{ key }}" type="number" size="{{ value|length }}" value="{{ value }}">
{% else %}
<input name="{{ key }}" type="text" size="{{ value|length }}" value="{{ value }}">
{% endif %}
{% endfor %}
<label for="scsi_id">{{ _("SCSI ID:") }}</label>
<select name="scsi_id">
{% for id in scsi_ids %}
@@ -402,6 +403,7 @@
</form>
</td>
</tr>
{% endfor %}
</table>
<hr/>
+31 -15
View File
@@ -117,7 +117,7 @@ def index():
image_files = file_cmds.list_images()
config_files = file_cmds.list_config_files()
mapped_device_types = extend_device_names(device_types["device_types"])
mapped_device_types = extend_device_names(device_types["device_types"].keys())
extended_image_files = []
for image in image_files["files"]:
@@ -180,6 +180,7 @@ def index():
current_log_level=server_info["current_log_level"],
netinfo=ractl.get_network_info(),
device_types=mapped_device_types,
device_params=device_types["device_types"],
free_disk=int(disk["free"] / 1024 / 1024),
valid_file_suffix=valid_file_suffix,
cdrom_file_suffix=tuple(server_info["sccd"]),
@@ -501,11 +502,23 @@ def attach_support_device():
"""
Attaches a support device
"""
scsi_id = request.form.get("scsi_id")
unit = request.form.get("unit")
device_type = request.form.get("type")
kwargs = {"unit": int(unit), "device_type": device_type}
process = ractl.attach_image(scsi_id, **kwargs)
params = {}
for item in request.form:
if item == "scsi_id":
scsi_id = request.form.get(item)
elif item == "unit":
unit = request.form.get(item)
elif item == "type":
device_type = request.form.get(item)
else:
params.update({item: request.form.get(item)})
kwargs = {
"unit": int(unit),
"device_type": device_type,
"params": params,
}
process = ractl.attach_device(scsi_id, **kwargs)
process = ReturnCodeMapper.add_msg(process)
if process["status"]:
flash(_(
@@ -525,7 +538,7 @@ def attach_support_device():
@APP.route("/scsi/attach_network", methods=["POST"])
@login_required
def attach_network_adapter():
def attach_network_device():
"""
Attaches a network adapter device
"""
@@ -560,12 +573,11 @@ def attach_network_adapter():
kwargs = {"unit": int(unit), "device_type": device_type}
if interface != "":
arg = interface
if "" not in (ip_addr, mask):
arg += (":" + ip_addr + "/" + mask)
kwargs["interfaces"] = arg
interface += (":" + ip_addr + "/" + mask)
kwargs["params"] = {"interfaces": interface}
process = ractl.attach_image(scsi_id, **kwargs)
process = ractl.attach_device(scsi_id, **kwargs)
process = ReturnCodeMapper.add_msg(process)
if process["status"]:
flash(_(
@@ -585,7 +597,7 @@ def attach_network_adapter():
@APP.route("/scsi/attach", methods=["POST"])
@login_required
def attach():
def attach_image():
"""
Attaches a file image as a device
"""
@@ -595,7 +607,7 @@ def attach():
unit = request.form.get("unit")
device_type = request.form.get("type")
kwargs = {"unit": int(unit), "image": file_name}
kwargs = {"unit": int(unit), "params": {"file": file_name}}
# The most common block size is 512 bytes
expected_block_size = 512
@@ -623,7 +635,7 @@ def attach():
kwargs["block_size"] = conf["block_size"]
expected_block_size = conf["block_size"]
process = ractl.attach_image(scsi_id, **kwargs)
process = ractl.attach_device(scsi_id, **kwargs)
process = ReturnCodeMapper.add_msg(process)
if process["status"]:
flash(_("Attached %(file_name)s to SCSI ID %(id_number)s LUN %(unit_number)s",
@@ -812,7 +824,11 @@ def download_to_iso():
flash(process["msg"], "error")
return redirect(url_for("index"))
process_attach = ractl.attach_image(scsi_id, device_type="SCCD", image=process["file_name"])
process_attach = ractl.attach_device(
scsi_id,
device_type="SCCD",
params={"file": process["file_name"]},
)
process_attach = ReturnCodeMapper.add_msg(process_attach)
if process_attach["status"]:
flash(_("Attached to SCSI ID %(id_number)s", id_number=scsi_id))