home: allow disableing list
This commit is contained in:
parent
35544bd64c
commit
5e9795ad0c
9 changed files with 127 additions and 32 deletions
|
|
@ -6,6 +6,7 @@ import (
|
|||
"net/http"
|
||||
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/auth"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/instances"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/server/templating"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/status"
|
||||
|
|
@ -17,6 +18,7 @@ type Home struct {
|
|||
Dependencies struct {
|
||||
Templating *templating.Templating
|
||||
Instances *instances.Instances
|
||||
Auth *auth.Auth
|
||||
}
|
||||
|
||||
instanceNames lazy.Lazy[map[string]struct{}] // instance names
|
||||
|
|
|
|||
|
|
@ -28,7 +28,8 @@ var aboutTemplate = template.Must(template.New("about.html").Parse(aboutHTML))
|
|||
|
||||
// aboutContext is passed to about.html
|
||||
type aboutContext struct {
|
||||
Instances []status.WissKI
|
||||
Instances []status.WissKI // list of WissKI Instancaes
|
||||
SignedIn bool // is there a signed in user?
|
||||
Logo template.HTML
|
||||
SelfRedirect string
|
||||
}
|
||||
|
|
@ -38,6 +39,10 @@ type publicContext struct {
|
|||
templating.RuntimeFlags
|
||||
|
||||
aboutContext
|
||||
|
||||
ListEnabled bool // is the list of instances enabled?
|
||||
ListTitle string // what is the title of the list of instances?
|
||||
|
||||
About template.HTML
|
||||
}
|
||||
|
||||
|
|
@ -66,7 +71,11 @@ func (home *Home) publicHandler(ctx context.Context) http.Handler {
|
|||
// prepare about
|
||||
pc.aboutContext.Logo = logoHTML
|
||||
pc.aboutContext.Instances = home.homeInstances.Get(nil)
|
||||
pc.aboutContext.SelfRedirect = home.Config.Theme.SelfRedirect.String()
|
||||
pc.aboutContext.SelfRedirect = home.Config.Home.SelfRedirect.String()
|
||||
{
|
||||
user, _ := home.Dependencies.Auth.UserOf(r)
|
||||
pc.aboutContext.SignedIn = user != nil
|
||||
}
|
||||
|
||||
// render the about template
|
||||
|
||||
|
|
@ -77,6 +86,17 @@ func (home *Home) publicHandler(ctx context.Context) http.Handler {
|
|||
// and return about!
|
||||
pc.About = template.HTML(builder.String())
|
||||
|
||||
// user is not signed in!
|
||||
|
||||
if pc.aboutContext.SignedIn {
|
||||
pc.ListEnabled = home.Config.Home.List.Private.Value
|
||||
} else {
|
||||
pc.ListEnabled = home.Config.Home.List.Public.Value
|
||||
}
|
||||
|
||||
// title of the list
|
||||
pc.ListTitle = home.Config.Home.List.Title
|
||||
|
||||
return
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,25 +1,27 @@
|
|||
{{ .About }}
|
||||
|
||||
<div class="pure-u-1">
|
||||
<h2>WissKIs on this Distillery</h2>
|
||||
</div>
|
||||
{{ if .ListEnabled }}
|
||||
<div class="pure-u-1">
|
||||
<h2>{{ .ListTitle }}</h2>
|
||||
</div>
|
||||
|
||||
{{range .Instances}}
|
||||
{{ if and .Running (not .NoPrefixes) }}
|
||||
<div class="pure-u-1 pure-u-md-1-3">
|
||||
<h3>{{.Slug}}</h3>
|
||||
<p>
|
||||
<a href="{{.URL}}" target="_blank" rel="noopener noreferrer" class="wisskilink">{{.URL}}</a><br>
|
||||
<small>
|
||||
{{ .Statistics.Bundles.Summary }}
|
||||
{{range .Instances}}
|
||||
{{ if and .Running (not .NoPrefixes) }}
|
||||
<div class="pure-u-1 pure-u-md-1-3">
|
||||
<h3>{{.Slug}}</h3>
|
||||
<p>
|
||||
<a href="{{.URL}}" target="_blank" rel="noopener noreferrer" class="wisskilink">{{.URL}}</a><br>
|
||||
<small>
|
||||
{{ .Statistics.Bundles.Summary }}
|
||||
|
||||
{{ $edit := .Statistics.Bundles.LastEdit }}
|
||||
{{ if $edit.Valid }}
|
||||
<br />
|
||||
last edited {{ $edit.Time.Format "2006-01-02T15:04:05Z07:00" }}
|
||||
{{ end }}
|
||||
</small>
|
||||
</p>
|
||||
</div>
|
||||
{{ $edit := .Statistics.Bundles.LastEdit }}
|
||||
{{ if $edit.Valid }}
|
||||
<br />
|
||||
last edited {{ $edit.Time.Format "2006-01-02T15:04:05Z07:00" }}
|
||||
{{ end }}
|
||||
</small>
|
||||
</p>
|
||||
</div>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
Loading…
Add table
Add a link
Reference in a new issue