diff --git a/handler/app/template.go b/handler/app/template.go index 257b838a..d27c5988 100644 --- a/handler/app/template.go +++ b/handler/app/template.go @@ -32,6 +32,7 @@ type Templ struct { Environment config.Config // Environment configurations from the host system environment. Public embed.FS // Public facing files. View embed.FS // Views are Go templates. + RecordCount int // RecordCount is the total number of records in the database. Subresource SRI // SRI are the Subresource Integrity hashes for the layout. Version string // Version is the current version of the app. } @@ -619,6 +620,8 @@ func (web Templ) tmpl(name filename) *template.Template { } config := web.Environment files = lockTmpls(config.ReadMode, files...) + offline := web.RecordCount < 1 + files = dbTmpls(offline, files...) // append any additional and embedded templates switch name { case "artifact.tmpl": @@ -688,21 +691,31 @@ func templates() map[string]filename { } } +func dbTmpls(offline bool, files ...string) []string { + if offline { + return append(files, + GlobTo("layoutup_null.tmpl"), + GlobTo("layoutjsup_null.tmpl"), + GlobTo("uploader_null.tmpl"), + ) + } + return append(files, + GlobTo("layoutup.tmpl"), + GlobTo("layoutjsup.tmpl"), + GlobTo("uploader.tmpl"), + GlobTo("uploaderhtmx.tmpl"), + ) +} + func lockTmpls(lock bool, files ...string) []string { - files = append(files, GlobTo("layoutup.tmpl")) if lock { return append(files, GlobTo("layoutlock_null.tmpl"), GlobTo("layoutjs_null.tmpl"), - GlobTo("layoutjsup_null.tmpl"), - GlobTo("layoutup_null.tmpl"), - GlobTo("uploader_null.tmpl")) + ) } return append(files, GlobTo("layoutlock.tmpl"), GlobTo("layoutjs.tmpl"), - GlobTo("layoutjsup.tmpl"), - GlobTo("layoutup.tmpl"), - GlobTo("uploader.tmpl"), - GlobTo("uploaderhtmx.tmpl")) + ) } diff --git a/handler/handler.go b/handler/handler.go index 6426b2aa..6bd8eb03 100644 --- a/handler/handler.go +++ b/handler/handler.go @@ -203,6 +203,7 @@ func (c Configuration) Registry(logger *zap.SugaredLogger) (*TemplateRegistry, e Environment: c.Environment, Brand: *c.Brand, Public: c.Public, + RecordCount: c.RecordCount, Version: c.Version, View: c.View, } diff --git a/view/app/layoutup_null.tmpl b/view/app/layoutup_null.tmpl index e3f6d81f..676f41b1 100644 --- a/view/app/layoutup_null.tmpl +++ b/view/app/layoutup_null.tmpl @@ -1,2 +1,10 @@ {{- /* layoutup_null.tmpl */}} -{{- define "layoutup" -}}{{end}} \ No newline at end of file +{{- define "layoutup" -}} +
+ + +
{{end}} \ No newline at end of file