Device table refinement in Web UI (#884)

* Refine the attached device table to optimize information displayed

* Error handling when attempting to insert withough image file

* Format the parameters in the jinja template instead

* Call the DaynaPORT device Ethernet Adapter in the Web UI
This commit is contained in:
Daniel Markstedt 2022-10-03 11:47:08 -07:00 committed by GitHub
parent c80953e0a4
commit fd47411322
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 46 additions and 23 deletions

View File

@ -42,21 +42,19 @@
{% if units %} {% if units %}
<td><b>{{ _("LUN") }}</b></td> <td><b>{{ _("LUN") }}</b></td>
{% endif %} {% endif %}
<td><b>{{ _("Type") }}</b></td> <td><b>{{ _("Device") }}</b></td>
<td><b>{{ _("Status") }}</b></td> <td><b>{{ _("Parameters") }}</b></td>
<td><b>{{ _("File") }}</b></td>
<td><b>{{ _("Product") }}</b></td> <td><b>{{ _("Product") }}</b></td>
<td><b>{{ _("Actions") }}</b></td> <td><b>{{ _("Actions") }}</b></td>
</tr> </tr>
{% for device in devices %} {% for device in devices | sort(attribute='id') %}
<tr> <tr>
{% if device["id"] not in reserved_scsi_ids %} {% if device["id"] not in reserved_scsi_ids %}
<td style="text-align:center">{{ device.id }}</td> <td style="text-align:center">{{ device.id }}</td>
{% if units %} {% if units %}
<td style="text-align:center">{{ device.unit }}</td> <td style="text-align:center">{{ device.unit }}</td>
{% endif %} {% endif %}
<td style="text-align:center">{{ device.device_type }}</td> <td style="text-align:center">{{ device.device_name }}</td>
<td style="text-align:center">{{ device.status }}</td>
<td style="text-align:left"> <td style="text-align:left">
{% if "No Media" in device.status %} {% if "No Media" in device.status %}
<form action="/scsi/attach" method="post"> <form action="/scsi/attach" method="post">
@ -84,14 +82,30 @@
<input type="submit" value="{{ _("Attach") }}"> <input type="submit" value="{{ _("Attach") }}">
</form> </form>
{% else %} {% else %}
{% if device.params %}
{% for key in device.params %}
{% if key == "interface" %}
({{device.params[key]}})
{% elif key == "timeout" %}
({{key}}:{{device.params[key]}})
{% else %}
{{device.params[key]}}
{% endif %}
{% endfor %}
{% elif device.file %}
{{ device.file }} {{ device.file }}
{% endif %} {% endif %}
</td>
{% if device.vendor == "RaSCSI" %}
<td style="text-align:center">{{ device.product }}</td>
{% else %}
<td style="text-align:center">{{ device.vendor }} {{ device.product }}</td>
{% endif %} {% endif %}
</td>
<td style="text-align:center">
{% if device.vendor != "RaSCSI" %}
{{ device.vendor }}
{% endif %}
{{ device.product }}
{% if device.vendor != "RaSCSI" %}
{{ device.revision }}
{% endif %}
</td>
<td style="text-align:center"> <td style="text-align:center">
{% if device.device_type != "-" %} {% if device.device_type != "-" %}
{% if device.device_type in REMOVABLE_DEVICE_TYPES and "No Media" not in device.status %} {% if device.device_type in REMOVABLE_DEVICE_TYPES and "No Media" not in device.status %}
@ -119,7 +133,6 @@
{% if units %} {% if units %}
<td class="inactive"></td> <td class="inactive"></td>
{% endif %} {% endif %}
<td class="inactive"></td>
<td class="inactive">{{ _("Reserved ID") }}</td> <td class="inactive">{{ _("Reserved ID") }}</td>
<td class="inactive">{{ RESERVATIONS[device.id] }}</td> <td class="inactive">{{ RESERVATIONS[device.id] }}</td>
<td class="inactive"></td> <td class="inactive"></td>
@ -179,7 +192,7 @@
<tr style="font-weight: bold;"> <tr style="font-weight: bold;">
<td>{{ _("File") }}</td> <td>{{ _("File") }}</td>
<td>{{ _("Size") }}</td> <td>{{ _("Size") }}</td>
<td>{{ _("Parameters and Actions") }}</td> <td>{{ _("Actions") }}</td>
</tr> </tr>
{% for file in files|sort(attribute='name') %} {% for file in files|sort(attribute='name') %}
<tr> <tr>

View File

@ -601,6 +601,9 @@ def attach_image():
unit = request.form.get("unit") unit = request.form.get("unit")
device_type = request.form.get("type") device_type = request.form.get("type")
if not file_name:
return response(error=True, message=_("No image file to insert"))
kwargs = {"unit": int(unit), "params": {"file": file_name}} kwargs = {"unit": int(unit), "params": {"file": file_name}}
if device_type: if device_type:

View File

@ -47,18 +47,25 @@ def sort_and_format_devices(devices):
For SCSI IDs where no device is attached, inject a (dict) with placeholder text. For SCSI IDs where no device is attached, inject a (dict) with placeholder text.
""" """
occupied_ids = [] occupied_ids = []
formatted_devices = []
for device in devices: for device in devices:
occupied_ids.append(device["id"]) occupied_ids.append(device["id"])
device["device_name"] = get_device_name(device["device_type"])
formatted_devices.append(device)
formatted_devices = devices # Add placeholder data for non-occupied IDs
for scsi_id in range(8):
# Add padding devices and sort the list if scsi_id not in occupied_ids:
for i in range(8): formatted_devices.append(
if i not in occupied_ids: {
formatted_devices.append({"id": i, "device_type": "-", \ "id": scsi_id,
"status": "-", "file": "-", "product": "-"}) "unit": "-",
# Sort list of devices by id "device_name": "-",
formatted_devices.sort(key=lambda dic: str(dic["id"])) "status": "-",
"file": "-",
"product": "-",
}
)
return formatted_devices return formatted_devices
@ -91,7 +98,7 @@ def get_device_name(device_type):
if device_type == "SCBR": if device_type == "SCBR":
return _("Host Bridge") return _("Host Bridge")
if device_type == "SCDP": if device_type == "SCDP":
return _("DaynaPORT SCSI/Link") return _("Ethernet Adapter")
if device_type == "SCLP": if device_type == "SCLP":
return _("Printer") return _("Printer")
if device_type == "SCHS": if device_type == "SCHS":