1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-12-03 17:36:05 +00:00

feat(instances): the VM's screen keeps its shape and says what it is

The screen beside the VM summary was a 4:3 black box: wide screens got
bars, nothing said it was live or that a click opens the console, and on
phones it took the card's width. The picture now keeps its own shape on
the theme's background, a caption under it says "Live" (or "Suspended":
the picture of a suspended VM stays) and, when it is a button, "Open
console"; on phones it is a small picture beside its caption.
This commit is contained in:
catborise 2026-11-25 12:12:55 +03:00
parent d5cc696d73
commit 5d0f658075
9 changed files with 62 additions and 16 deletions

View file

@ -92,17 +92,20 @@
</div>
{% if show_screen %}
{# the VM's screen, read by instance_page.js every few seconds and shown once one has come; opens the console where it can #}
{# its caption: whether the picture follows the VM (a suspended one's stays), and that a click opens the console #}
{% if screen_opens_console %}
<button type="button" class="vm-screen" id="vm-screen" hidden data-url="{% url 'console' compute.id instance.uuid %}"
data-window="console-{{ instance.uuid }}" data-screen-url="{% url 'instances:screen' instance.id %}"
title="{% trans "Open console" %}">
<img alt="{% blocktrans with name=instance.name %}Screen of {{ name }}{% endblocktrans %}">
</button>
data-window="console-{{ instance.uuid }}" data-screen-url="{% url 'instances:screen' instance.id %}">
{% else %}
<div class="vm-screen" id="vm-screen" hidden data-screen-url="{% url 'instances:screen' instance.id %}">
<img alt="{% blocktrans with name=instance.name %}Screen of {{ name }}{% endblocktrans %}">
</div>
{% endif %}
<span class="vm-screen-frame"><img alt="{% blocktrans with name=instance.name %}Screen of {{ name }}{% endblocktrans %}"></span>
<span class="vm-screen-caption">
{% if instance.status == 3 %}<span class="vm-screen-state">{% bs_icon 'pause-fill' %} {% trans "Suspended" %}</span>
{% else %}<span class="vm-screen-state"><span class="vm-screen-live" aria-hidden="true"></span> {% trans "Live" context "screen" %}</span>{% endif %}
{% if screen_opens_console %}<span class="vm-screen-open">{% trans "Open console" %}</span>{% endif %}
</span>
{% if screen_opens_console %}</button>{% else %}</div>{% endif %}
{% endif %}
</div>
<div class="card-footer p-1">

View file

@ -197,12 +197,16 @@ class PendingEditsTestCase(TestCase):
(element,) = self.page(status=status, **reachable).xpath(screen)
# shown once its script has read a frame; a button that opens the console
self.assertEqual((element.tag, element.get("hidden"), element.get("data-screen-url")), ("button", "", url))
caption = "normalize-space(//*[@id='vm-screen']/*[@class='vm-screen-caption'])"
self.assertEqual(self.page(status=1, **reachable).xpath(caption), "Live Open console")
self.assertEqual(self.page(status=3, **reachable).xpath(caption), "Suspended Open console") # its last picture
self.assertFalse(self.page(status=5, **reachable).xpath(screen))
# a console the panel cannot open (loopback VNC on a TCP host, SPICE): the screen alone, not a button
for console in ({**reachable, "get_console_listener_addr": ("127.0.0.1", "127.0.0.1")},
{**reachable, "get_console_type": ("spice", "spice")}):
(element,) = self.page(**console).xpath(screen)
self.assertEqual((element.tag, element.get("data-window")), ("div", None))
self.assertNotIn("Open console", element.text_content())
def test_the_clone_form_lists_the_persistent_devices(self):
nic = {"type": "network", "mac": "52:54:10:00:00:01", "nic": "default", "state": "up", "model": "virtio",

Binary file not shown.

View file

@ -13410,3 +13410,8 @@ msgstr "Hiçbir dosya sistemi boşaltılmadı: %(errors)s"
#: instances/templates/instance.html:98
msgid "Screen of %(name)s"
msgstr "%(name)s ekranı"
#: instances/templates/instance.html:105
msgctxt "screen"
msgid "Live"
msgstr "Canlı"

Binary file not shown.

View file

@ -13506,3 +13506,8 @@ msgstr "Жодну файлову систему не звільнено: %(erro
#: instances/templates/instance.html:98
msgid "Screen of %(name)s"
msgstr "Екран ВМ %(name)s"
#: instances/templates/instance.html:105
msgctxt "screen"
msgid "Live"
msgstr "Наживо"

Binary file not shown.

View file

@ -12536,3 +12536,8 @@ msgstr "没有文件系统被修剪:%(errors)s"
#: instances/templates/instance.html:98
msgid "Screen of %(name)s"
msgstr "%(name)s 的屏幕"
#: instances/templates/instance.html:105
msgctxt "screen"
msgid "Live"
msgstr "实时"

View file

@ -383,19 +383,43 @@ td .tag-more {
/* high contrast themes would drop the marks' colours, which carry their meaning */
@media (forced-colors: active) { .run-mark { forced-color-adjust: none; } }
/* the VM page's screen thumbnail (instance.html): the console's picture, a button that opens it */
/* the VM page's screen thumbnail (instance.html): the picture at its own shape, a caption under it
(live or suspended, and "Open console" when it is a button); on phones a small picture beside the caption */
.vm-screen {
display: block;
padding: 0;
display: flex;
align-items: center;
gap: .75rem;
width: 100%;
max-width: 16rem;
aspect-ratio: 4 / 3;
padding: 0;
color: var(--bs-body-color);
text-align: start;
background: none;
border: 0;
}
.vm-screen[hidden] { display: none; }
.vm-screen-frame {
flex: none;
display: flex;
align-items: center;
justify-content: center;
width: 6.5rem;
max-height: 5rem;
overflow: hidden;
background: #000;
background: var(--bs-tertiary-bg);
border: 1px solid var(--bs-border-color);
border-radius: var(--bs-border-radius);
}
.vm-screen[hidden] { display: none; }
.vm-screen img { display: block; width: 100%; height: 100%; object-fit: contain; }
.vm-screen:focus-visible { outline: 0; box-shadow: var(--bs-focus-ring-x, 0) var(--bs-focus-ring-y, 0) 0 var(--bs-focus-ring-width) var(--bs-focus-ring-color); }
@media (min-width: 768px) { .vm-screen { flex: none; width: 13rem; align-self: flex-start; } }
.vm-screen-frame img { display: block; max-width: 100%; max-height: 5rem; height: auto; }
.vm-screen-caption { display: flex; flex-direction: column; gap: .125rem; font-size: .875em; line-height: 1.3; }
.vm-screen-state { color: var(--bs-secondary-color); }
.vm-screen-live { display: inline-block; width: .5rem; height: .5rem; border-radius: 50%; background: var(--bs-success); vertical-align: .05em; }
.vm-screen-open { color: var(--bs-link-color); }
button.vm-screen:hover .vm-screen-open { text-decoration: underline; }
button.vm-screen:hover .vm-screen-frame { border-color: var(--bs-link-color); }
.vm-screen:focus-visible { outline: 0; border-radius: var(--bs-border-radius); box-shadow: 0 0 0 var(--bs-focus-ring-width) var(--bs-focus-ring-color); }
@media (min-width: 768px) {
.vm-screen { flex: none; flex-direction: column; align-items: stretch; gap: .375rem; width: 13rem; align-self: flex-start; }
.vm-screen-frame { width: 100%; max-height: 10rem; }
.vm-screen-frame img { max-height: 10rem; }
.vm-screen-caption { flex-direction: row; justify-content: space-between; gap: .5rem; }
}