diff --git a/weed/admin/static/js/theme.js b/weed/admin/static/js/theme.js deleted file mode 100644 index 79b5ce21f7..0000000000 --- a/weed/admin/static/js/theme.js +++ /dev/null @@ -1,43 +0,0 @@ -// Applies the saved color theme (auto, light or dark) before the page paints. -(function () { - var storageKey = 'admin-theme'; - var choices = ['auto', 'light', 'dark']; - var media = window.matchMedia ? window.matchMedia('(prefers-color-scheme: dark)') : null; - var root = document.documentElement; - - function savedChoice() { - try { - var value = localStorage.getItem(storageKey); - return choices.indexOf(value) >= 0 ? value : 'auto'; - } catch (e) { - return 'auto'; - } - } - - function apply(choice) { - var dark = choice === 'dark' || (choice === 'auto' && media && media.matches); - root.setAttribute('data-bs-theme', dark ? 'dark' : 'light'); - root.setAttribute('data-theme-choice', choice); - } - - var current = savedChoice(); - apply(current); - - if (media && media.addEventListener) { - media.addEventListener('change', function () { - apply(current); - }); - } - - document.addEventListener('click', function (event) { - var toggle = event.target.closest && event.target.closest('[data-theme-toggle]'); - if (!toggle) { - return; - } - current = choices[(choices.indexOf(current) + 1) % choices.length]; - try { - localStorage.setItem(storageKey, current); - } catch (e) {} - apply(current); - }); -})(); diff --git a/weed/admin/static_gz/js/theme.js.gz b/weed/admin/static_gz/js/theme.js.gz deleted file mode 100644 index 4b18d0dc25..0000000000 Binary files a/weed/admin/static_gz/js/theme.js.gz and /dev/null differ diff --git a/weed/admin/view/layout/layout.templ b/weed/admin/view/layout/layout.templ index 11c766bd3d..ebf437d3a7 100644 --- a/weed/admin/view/layout/layout.templ +++ b/weed/admin/view/layout/layout.templ @@ -12,6 +12,56 @@ script setBasePath(prefix string) { window.__BASE_PATH__ = prefix; } +// themeScript applies the saved color theme (auto, light or dark) inline, so +// the root is themed before any external script or stylesheet is fetched. +templ themeScript() { + +} + templ Layout(view ViewContext, content templ.Component) { {{ username := view.Username @@ -55,7 +105,7 @@ templ Layout(view ViewContext, content templ.Component) { - + @themeScript() @@ -404,7 +454,7 @@ templ LoginForm(title string, errorMessage string, csrfToken string) { {title} - Login - + @themeScript() diff --git a/weed/admin/view/layout/layout_templ.go b/weed/admin/view/layout/layout_templ.go index 5dd6682a39..0e0600ab40 100644 --- a/weed/admin/view/layout/layout_templ.go +++ b/weed/admin/view/layout/layout_templ.go @@ -27,6 +27,33 @@ func setBasePath(prefix string) templ.ComponentScript { } } +// themeScript applies the saved color theme (auto, light or dark) inline, so +// the root is themed before any external script or stylesheet is fetched. +func themeScript() templ.Component { + return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context + if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { + return templ_7745c5c3_CtxErr + } + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) + if !templ_7745c5c3_IsBuffer { + defer func() { + templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) + if templ_7745c5c3_Err == nil { + templ_7745c5c3_Err = templ_7745c5c3_BufErr + } + }() + } + ctx = templ.InitializeContext(ctx) + ctx = templ.ClearChildren(ctx) + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + return nil + }) +} + func Layout(view ViewContext, content templ.Component) templ.Component { return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context @@ -75,98 +102,93 @@ func Layout(view ViewContext, content templ.Component) templ.Component { isIcebergWorkerPage := currentPath == "/plugin/lanes/iceberg" || strings.HasPrefix(currentPath, "/plugin/lanes/iceberg/") isLifecycleWorkerPage := currentPath == "/plugin/lanes/lifecycle" || strings.HasPrefix(currentPath, "/plugin/lanes/lifecycle/") isLanceWorkerPage := currentPath == "/plugin/lanes/lance" || strings.HasPrefix(currentPath, "/plugin/lanes/lance/") - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "SeaweedFS AdminSeaweedFS Admin") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = themeScript().Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 5, "") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 9, "\">") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -174,59 +196,59 @@ func Layout(view ViewContext, content templ.Component) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 9, "
MAIN
  • Dashboard
  • ") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 14, "\">Dashboard
  • ") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -234,7 +256,7 @@ func Layout(view ViewContext, content templ.Component) templ.Component { templ_7745c5c3_ElementWriter := templ_7745c5c3_Buffer templ_7745c5c3_Buffer := templ.GetBuffer() var templ_7745c5c3_ElementScripts []templ.ComponentScript - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 14, "Cluster ") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 18, ">Cluster ") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -287,7 +309,7 @@ func Layout(view ViewContext, content templ.Component) templ.Component { templ_7745c5c3_ElementWriter := templ_7745c5c3_Buffer templ_7745c5c3_Buffer := templ.GetBuffer() var templ_7745c5c3_ElementScripts []templ.ComponentScript - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 18, "
  • ") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 27, "\">Mount Clients
  • ") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -405,7 +427,7 @@ func Layout(view ViewContext, content templ.Component) templ.Component { templ_7745c5c3_ElementWriter := templ_7745c5c3_Buffer templ_7745c5c3_Buffer := templ.GetBuffer() var templ_7745c5c3_ElementScripts []templ.ComponentScript - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 27, "Storage ") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 31, ">Storage ") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -458,7 +480,7 @@ func Layout(view ViewContext, content templ.Component) templ.Component { templ_7745c5c3_ElementWriter := templ_7745c5c3_Buffer templ_7745c5c3_Buffer := templ.GetBuffer() var templ_7745c5c3_ElementScripts []templ.ComponentScript - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 31, "
  • OBJECT STORE
    OBJECT STORE
    MANAGEMENT
    MANAGEMENT
    ") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 61, "
    WORKERS
    WORKERS
    ") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 82, "
    ") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -939,123 +961,110 @@ func Layout(view ViewContext, content templ.Component) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 82, "
    ") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 95, "\">") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -1098,160 +1120,155 @@ func LoginForm(title string, errorMessage string, csrfToken string) templ.Compon ctx = templ.InitializeContext(ctx) ctx = templ.ClearChildren(ctx) prefix := dash.URLPrefixFromContext(ctx) - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 95, "") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 96, "<!doctype html><html lang=\"en\"><head><meta charset=\"UTF-8\"><title>") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } var templ_7745c5c3_Var64 string templ_7745c5c3_Var64, templ_7745c5c3_Err = templ.JoinStringErrs(title) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/layout/layout.templ`, Line: 404, Col: 17} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/layout/layout.templ`, Line: 454, Col: 17} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var64)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 96, " - Login

    ") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } var templ_7745c5c3_Var69 string - templ_7745c5c3_Var69, templ_7745c5c3_Err = templruntime.NewAttributeExpression(prefix + "/static/css/admin.css").ResolveURL(ctx) + templ_7745c5c3_Var69, templ_7745c5c3_Err = templ.JoinStringErrs(title) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/layout/layout.templ`, Line: 410, Col: 49} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/layout/layout.templ`, Line: 470, Col: 57} } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var69) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var69)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 101, "\" rel=\"stylesheet\">

    ") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - var templ_7745c5c3_Var70 string - templ_7745c5c3_Var70, templ_7745c5c3_Err = templ.JoinStringErrs(title) - if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/layout/layout.templ`, Line: 420, Col: 57} - } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var70)) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 102, "

    Please sign in to continue

    ") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 103, "

    Please sign in to continue

    ") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } if errorMessage != "" { - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 103, "
    ") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 104, "
    ") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var71 string - templ_7745c5c3_Var71, templ_7745c5c3_Err = templ.JoinStringErrs(errorMessage) + var templ_7745c5c3_Var70 string + templ_7745c5c3_Var70, templ_7745c5c3_Err = templ.JoinStringErrs(errorMessage) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/layout/layout.templ`, Line: 427, Col: 45} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/layout/layout.templ`, Line: 477, Col: 45} } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var71)) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var70)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 104, "
    ") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 105, "
    ") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 105, "
    ") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 109, "\">") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err }