Skip to content

Commit

Permalink
template and menu fixes for offline uploader.
Browse files Browse the repository at this point in the history
  • Loading branch information
bengarrett committed May 18, 2024
1 parent d91b582 commit f5a122b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
29 changes: 21 additions & 8 deletions handler/app/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
}
Expand Down Expand Up @@ -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":
Expand Down Expand Up @@ -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"))
)
}
1 change: 1 addition & 0 deletions handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
10 changes: 9 additions & 1 deletion view/app/layoutup_null.tmpl
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
{{- /* layoutup_null.tmpl */}}
{{- define "layoutup" -}}{{end}}
{{- define "layoutup" -}}
<div class="btn-group dropstart">
<button class="btn btn-secondary btn-sm dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">
Uploader
</button>
<ul class="dropdown-menu">
<li><h6 class="dropdown-header">Sorry, the database is offline</h6></li>
</ul>
</div>{{end}}

0 comments on commit f5a122b

Please sign in to comment.