fix(panel): space out group switcher spec labels
- render each switcher option as "<label> - <cpu>c <mem>g <disk>g" (e.g. "A - 2c 8g 60g") instead of the cramped "A-2c8g60g" - update MachineSpecs and the pinned tests Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
This commit is contained in:
1 parent
44c3727ad3
commit
2e2022fd1f
5 files changed
+9
-9
No files matched your search
@@ -21,12 +21,12 @@ func UserGroupLabel(name string) string {
|
||||
}
|
||||
|
||||
// MachineSpecs renders a compact quota tag for the container switcher:
|
||||
// "<cpu>c<mem>g<disk>g", e.g. "4c8g40g". CPU reuses FormatCPU (tenths of a
|
||||
// "<cpu>c <mem>g <disk>g", e.g. "4c 8g 40g". CPU reuses FormatCPU (tenths of a
|
||||
// core, so 0.5 stays fractional); memory is MiB rendered as GiB with a trimmed
|
||||
// decimal (1024 -> "1", 512 -> "0.5"); disk is already GiB.
|
||||
func MachineSpecs(cpuTenths, memMB, diskGB int) string {
|
||||
mem := strconv.FormatFloat(float64(memMB)/1024, 'f', -1, 64)
|
||||
return FormatCPU(cpuTenths) + "c" + mem + "g" + strconv.Itoa(diskGB) + "g"
|
||||
return FormatCPU(cpuTenths) + "c " + mem + "g " + strconv.Itoa(diskGB) + "g"
|
||||
}
|
||||
|
||||
type UserGroup struct {
|
||||
|
||||
@@ -47,10 +47,10 @@ func TestMachineSpecs(t *testing.T) {
|
||||
cpu, mem, disk int
|
||||
want string
|
||||
}{
|
||||
{10, 1024, 10, "1c1g10g"},
|
||||
{40, 8192, 40, "4c8g40g"},
|
||||
{5, 512, 10, "0.5c0.5g10g"},
|
||||
{20, 1536, 20, "2c1.5g20g"},
|
||||
{10, 1024, 10, "1c 1g 10g"},
|
||||
{40, 8192, 40, "4c 8g 40g"},
|
||||
{5, 512, 10, "0.5c 0.5g 10g"},
|
||||
{20, 1536, 20, "2c 1.5g 20g"},
|
||||
} {
|
||||
if got := MachineSpecs(test.cpu, test.mem, test.disk); got != test.want {
|
||||
t.Errorf("MachineSpecs(%d, %d, %d) = %q, want %q", test.cpu, test.mem, test.disk, got, test.want)
|
||||
|
||||
@@ -133,7 +133,7 @@ type sshKeyRow struct {
|
||||
type groupMemberRow struct {
|
||||
Name string // account name, used as the <option> value
|
||||
Label string // "A" for the base account, else the numeric suffix
|
||||
Specs string // compact quota tag, e.g. "4c8g40g"
|
||||
Specs string // compact quota tag, e.g. "4c 8g 40g"
|
||||
}
|
||||
|
||||
type pageData struct {
|
||||
|
||||
@@ -1210,7 +1210,7 @@ func TestOverviewGroupSwitcherLabels(t *testing.T) {
|
||||
}
|
||||
cookie := loginAndCookie(t, h, prefix, "alice", "pw")
|
||||
body := doReq(t, h, http.MethodGet, prefix, nil, cookie).Body.String()
|
||||
base, child := "A-1c1g10g", "1-4c8g40g"
|
||||
base, child := "A - 1c 1g 10g", "1 - 4c 8g 40g"
|
||||
for _, want := range []string{">" + base + "</option>", ">" + child + "</option>"} {
|
||||
if !strings.Contains(body, want) {
|
||||
t.Errorf("overview switcher missing %q", want)
|
||||
|
||||
@@ -234,7 +234,7 @@ footer a{color:var(--muted);text-decoration:underline}
|
||||
</div>
|
||||
{{if .Err}}<div class="err">{{.Err}}</div>{{end}}
|
||||
{{if gt .GroupCount 1}}
|
||||
<div class="groupbanner"><span>⚠ {{if eq .Lang "zh"}}您的用户组内有多台机器,当前机器序号为{{else}}Your user group has multiple containers. Current container number:{{end}} <strong class="container-index">{{.GroupIndex}}</strong>。{{if eq .Lang "zh"}}请确认您操作的机器无误。{{else}}Confirm this is the intended container before operating.{{end}}{{if gt (len .GroupUsers) 1}}<form action="{{.Prefix}}/switch-user" method="post" class="inline group-switch"><select name="name" onchange="this.form.submit()" aria-label="{{if eq .Lang "zh"}}切换机器{{else}}Switch container{{end}}">{{range .GroupUsers}}<option value="{{.Name}}"{{if eq .Name $.User.Name}} selected{{end}}>{{.Label}}-{{.Specs}}</option>{{end}}</select></form>{{end}}</div>
|
||||
<div class="groupbanner"><span>⚠ {{if eq .Lang "zh"}}您的用户组内有多台机器,当前机器序号为{{else}}Your user group has multiple containers. Current container number:{{end}} <strong class="container-index">{{.GroupIndex}}</strong>。{{if eq .Lang "zh"}}请确认您操作的机器无误。{{else}}Confirm this is the intended container before operating.{{end}}{{if gt (len .GroupUsers) 1}}<form action="{{.Prefix}}/switch-user" method="post" class="inline group-switch"><select name="name" onchange="this.form.submit()" aria-label="{{if eq .Lang "zh"}}切换机器{{else}}Switch container{{end}}">{{range .GroupUsers}}<option value="{{.Name}}"{{if eq .Name $.User.Name}} selected{{end}}>{{.Label}} - {{.Specs}}</option>{{end}}</select></form>{{end}}</div>
|
||||
{{end}}
|
||||
{{if .Impersonated}}
|
||||
<div class="impbanner">
|
||||
|
||||
Reference in new issue
Block a user