Show config apply result summary

This commit is contained in:
tian 2026-04-19 13:42:01 +08:00
parent 8806985c8b
commit 1cb3077b80
2 changed files with 89 additions and 0 deletions

View File

@ -102,6 +102,30 @@
</div>
{{end}}
{{if and (eq .ResultTitle "应用候选配置结果") .ConfigStatus}}
<div class="card">
<h2>应用结果摘要</h2>
<div class="row" style="margin-top:10px">
<div>
<div class="muted small">当前运行</div>
<div class="mono">{{if .ConfigStatus.Metadata.ConfigID}}{{.ConfigStatus.Metadata.ConfigID}} / {{if .ConfigStatus.Metadata.ConfigVersion}}{{.ConfigStatus.Metadata.ConfigVersion}}{{else}}未标记{{end}}{{else}}未标记{{end}}</div>
</div>
<div>
<div class="muted small">last_good</div>
<div class="mono">{{if and .ConfigStatus.LastGood .ConfigStatus.LastGood.Exists .ConfigStatus.LastGood.Metadata.ConfigID}}{{.ConfigStatus.LastGood.Metadata.ConfigID}} / {{if .ConfigStatus.LastGood.Metadata.ConfigVersion}}{{.ConfigStatus.LastGood.Metadata.ConfigVersion}}{{else}}未标记{{end}}{{else}}-{{end}}</div>
</div>
<div>
<div class="muted small">candidate</div>
<div>{{if and .ConfigStatus.Candidate .ConfigStatus.Candidate.Exists}}<span class="pill">仍存在</span>{{else}}<span class="pill ok">已清空</span>{{end}}</div>
</div>
<div>
<div class="muted small">media-server</div>
<div>{{if .ConfigStatus.MediaServer.Running}}<span class="pill ok">运行中</span>{{else}}<span class="pill bad">未运行</span>{{end}}</div>
</div>
</div>
</div>
{{end}}
{{if .RawText}}
<div class="card">
<h2>{{if .ResultTitle}}{{.ResultTitle}}{{else}}执行结果{{end}}</h2>

View File

@ -505,6 +505,71 @@ func TestUI_ConfigPreviewCollapsesJSONAfterActionResult(t *testing.T) {
}
}
func TestUI_ConfigPreviewShowsApplySummaryAfterApplyResult(t *testing.T) {
ui := newTestUI(t)
req := httptest.NewRequest(http.MethodGet, "/ui/devices/edge-01/config-preview", nil)
rr := httptest.NewRecorder()
ui.render(rr, req, "config_preview", PageData{
Title: "配置预览",
Device: &models.Device{DeviceID: "edge-01", DeviceName: "入口识别节点", IP: "127.0.0.1", AgentPort: 9100},
SelectedTemplate: "workshop_face_shoe_alarm",
SelectedProfile: "local_3588_test",
SelectedOverlays: []string{"face_debug"},
SelectedConfigID: "preview_edge-01",
ConfigPreview: &service.ConfigPreviewResult{
JSON: `{"templates":{"tpl":{"nodes":[],"edges":[]}},"instances":[],"metadata":{"config_id":"preview_edge-01","config_version":"v2"}}`,
Metadata: map[string]any{
"config_id": "preview_edge-01",
"config_version": "v2",
},
Size: 64,
},
ConfigStatus: &ConfigStatusView{
OK: true,
Metadata: ConfigStatusMetadata{
ConfigID: "preview_edge-01",
ConfigVersion: "v2",
},
Candidate: &ConfigStatusLastGoodFile{
Exists: false,
Path: "/opt/rk3588-media-server/etc/media-server.json.candidate.json",
},
LastGood: &ConfigStatusLastGoodFile{
Exists: true,
Path: "/opt/rk3588-media-server/etc/media-server.json.last_good.json",
Metadata: ConfigStatusMetadata{
ConfigID: "local_3588_face_debug",
ConfigVersion: "20260419.120246",
},
},
MediaServer: ConfigStatusMediaServer{
Running: true,
PID: 1810489,
},
},
ResultTitle: "应用候选配置结果",
RawText: `{"ok":true}`,
})
body := rr.Body.String()
for _, want := range []string{
"应用结果摘要",
"当前运行",
"preview_edge-01 / v2",
"last_good",
"local_3588_face_debug / 20260419.120246",
"candidate",
"已清空",
"media-server",
"运行中",
} {
if !strings.Contains(body, want) {
t.Fatalf("expected apply summary HTML to contain %q, got:\n%s", want, body)
}
}
}
func TestUI_ModelDeploymentPageRendersDeviceActions(t *testing.T) {
ui := newTestUI(t)
req := httptest.NewRequest(http.MethodGet, "/ui/models", nil)