webui: render NTP empty state gracefully when not configured

The NTP page showed a red "Failed to fetch NTP data" banner whenever
/data/ietf-ntp:ntp returned 404 — which is the normal RESTCONF response
when NTP isn't configured at all. Treat 404 as the not-configured case
and render the empty-state card with a Configure → link, mirroring the
DHCP status page.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg
2026-06-15 19:45:17 +02:00
parent f00511d235
commit bfb5b14ea0
2 changed files with 16 additions and 5 deletions
+6 -2
View File
@@ -86,8 +86,12 @@ func (h *NTPHandler) Overview(w http.ResponseWriter, r *http.Request) {
} `json:"ietf-ntp:ntp"`
}
if err := h.RC.Get(ctx, "/data/ietf-ntp:ntp", &raw); err != nil {
log.Printf("restconf ntp: %v", err)
data.Error = "Failed to fetch NTP data"
// 404 = NTP container absent (not configured). Render the empty-state
// section instead of a red error banner.
if !restconf.IsNotFound(err) {
log.Printf("restconf ntp: %v", err)
data.Error = "Failed to fetch NTP data"
}
} else {
ss := raw.NTP.ClockState.SystemStatus
synced := strings.Contains(ss.ClockState, "synchronized") &&
+10 -3
View File
@@ -32,8 +32,8 @@
{{end}}
</table>
{{if .NTP.Associations}}
<h3 class="section-subtitle">Associations</h3>
{{if .NTP.Associations}}
<div class="data-table-wrap">
<table class="data-table">
<thead>
@@ -63,12 +63,19 @@
</table>
</div>
{{else}}
<p class="text-muted">No associations.</p>
<p class="empty-message">No upstream associations to display.</p>
{{end}}
</section>
{{else if not .Error}}
<section class="info-card">
<p class="text-muted">NTP data not available.</p>
<div class="card-header">NTP
<a href="/configure/tree?path=/ietf-system:system/ntp"
hx-get="/configure/tree?path=/ietf-system:system/ntp"
hx-target="#content"
hx-push-url="true"
class="btn btn-sm btn-outline card-header-action">Configure &rarr;</a>
</div>
<p class="empty-message">NTP is not configured.</p>
</section>
{{end}}
{{end}}