detail pages
This commit is contained in:
parent
70af98a989
commit
edc4fe9b75
9 changed files with 125 additions and 6 deletions
|
@ -13,6 +13,17 @@ type Context struct {
|
|||
Story bool
|
||||
}
|
||||
|
||||
func NewContext(w *DfWorld, ref any) *Context {
|
||||
c := &Context{World: w}
|
||||
switch r := ref.(type) {
|
||||
case *WrittenContent:
|
||||
c.HfId = r.AuthorHfid
|
||||
default:
|
||||
fmt.Printf("unknown type for context %T\n", ref)
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
||||
func (c *Context) hf(id int) string {
|
||||
if c.HfId != -1 {
|
||||
if c.HfId == id {
|
||||
|
@ -208,7 +219,7 @@ func (c *Context) worldConstruction(id int) string {
|
|||
|
||||
func (c *Context) writtenContent(id int) string {
|
||||
if x, ok := c.World.WrittenContents[id]; ok {
|
||||
return fmt.Sprintf(`<a class="artform" href="/writtenContent/%d">%s</a>`, id, util.Title(x.Name()))
|
||||
return fmt.Sprintf(`<a class="writtencontent" href="/writtencontent/%d">%s</a>`, id, util.Title(x.Name()))
|
||||
}
|
||||
return "UNKNOWN WORLD CONSTRUCTION"
|
||||
}
|
||||
|
|
|
@ -38,6 +38,7 @@ func NewEventList(world *DfWorld, obj any) *EventList {
|
|||
el.Context.HfId = x.Id()
|
||||
el.Events = world.EventsMatching(func(d HistoricalEventDetails) bool { return d.RelatedToHf(x.Id()) })
|
||||
case *Artifact:
|
||||
el.Context.HfId = x.HolderHfid
|
||||
el.Events = world.EventsMatching(func(d HistoricalEventDetails) bool { return d.RelatedToArtifact(x.Id()) })
|
||||
case *Site:
|
||||
el.Events = world.EventsMatching(func(d HistoricalEventDetails) bool { return d.RelatedToSite(x.Id()) })
|
||||
|
|
|
@ -2,6 +2,7 @@ package model
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"html/template"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
|
@ -185,3 +186,41 @@ func (w *MusicalForm) Type() string {
|
|||
func (w *PoeticForm) Type() string {
|
||||
return "poetic form"
|
||||
}
|
||||
|
||||
func (r *Reference) Html(c *Context) template.HTML {
|
||||
switch r.Type_ {
|
||||
case ReferenceType_ABSTRACTBUILDING:
|
||||
return template.HTML("a building")
|
||||
case ReferenceType_ARTIFACT:
|
||||
return template.HTML(c.artifact(r.Id_))
|
||||
case ReferenceType_DANCEFORM:
|
||||
return template.HTML(c.danceForm(r.Id_))
|
||||
case ReferenceType_ENTITY:
|
||||
return template.HTML(c.entity(r.Id_))
|
||||
case ReferenceType_HISTORICALEVENT:
|
||||
if e, ok := c.World.HistoricalEvents[r.Id_]; ok {
|
||||
return template.HTML("how in " + Time(e.Year, e.Seconds72) + " " + e.Details.Html(c))
|
||||
}
|
||||
case ReferenceType_HISTORICALFIGURE:
|
||||
return template.HTML(c.hf(r.Id_))
|
||||
case ReferenceType_INTERACTION:
|
||||
return template.HTML("an interaction")
|
||||
case ReferenceType_KNOWLEDGESCHOLARFLAG:
|
||||
return template.HTML("specific knowledge")
|
||||
case ReferenceType_LANGUAGE:
|
||||
return template.HTML("a language")
|
||||
case ReferenceType_MUSICALFORM:
|
||||
return template.HTML(c.musicalForm(r.Id_))
|
||||
case ReferenceType_POETICFORM:
|
||||
return template.HTML(c.poeticForm(r.Id_))
|
||||
case ReferenceType_SITE:
|
||||
return template.HTML(c.site(r.Id_, ""))
|
||||
case ReferenceType_SUBREGION:
|
||||
return template.HTML(c.region(r.Id_))
|
||||
case ReferenceType_VALUELEVEL:
|
||||
return template.HTML("a value")
|
||||
case ReferenceType_WRITTENCONTENT:
|
||||
return template.HTML(c.writtenContent(r.Id_))
|
||||
}
|
||||
return template.HTML(r.Type_.String())
|
||||
}
|
||||
|
|
|
@ -21,9 +21,10 @@ func (srv *DfServer) LoadTemplates() {
|
|||
}
|
||||
return nil
|
||||
},
|
||||
"title": util.Title,
|
||||
"kebab": func(s string) string { return strcase.ToKebab(s) },
|
||||
"world": func() *model.DfWorld { return srv.context.world },
|
||||
"title": util.Title,
|
||||
"kebab": func(s string) string { return strcase.ToKebab(s) },
|
||||
"world": func() *model.DfWorld { return srv.context.world },
|
||||
"context": func(r any) *model.Context { return model.NewContext(srv.context.world, r) },
|
||||
"initMap": func() template.HTML {
|
||||
return template.HTML(fmt.Sprintf(`<script>var worldWidth = %d, worldHeight = %d;</script><script src="/js/map.js"></script>`,
|
||||
srv.context.world.Width, srv.context.world.Height))
|
||||
|
|
|
@ -4,7 +4,24 @@
|
|||
|
||||
{{define "content"}}
|
||||
<h1>{{ title .Name }}</h1>
|
||||
|
||||
{{if ne .ItemDescription ""}}<p><i>{{ .ItemDescription }}</i></p>{{end}}
|
||||
<p>
|
||||
{{- if or (ne .ItemType "") (ne .ItemSubtype "")}}
|
||||
{{.Mat}} {{if ne .ItemSubtype ""}}{{.ItemSubtype}}{{else}}{{.ItemType}}{{end}}
|
||||
{{- end}}
|
||||
{{- if gt .PageCount 0 }}
|
||||
with {{ .PageCount }} pages
|
||||
{{- end}}
|
||||
{{- if ne .Writing -1 }}
|
||||
containing {{ writtenContent .Writing}}
|
||||
{{- end}}
|
||||
{{- if ne .SiteId -1 }}
|
||||
stored in {{ site .SiteId}}
|
||||
{{- end}}
|
||||
{{- if ne .HolderHfid -1 }}
|
||||
owned by {{ hf .HolderHfid}}
|
||||
{{- end}}
|
||||
</p>
|
||||
<h3>Events</h3>
|
||||
|
||||
{{ template "events.html" events . }}
|
||||
|
|
|
@ -107,7 +107,7 @@
|
|||
}).responseText;
|
||||
}
|
||||
|
||||
$('a.entity,a.hf,a.region,a.site,a.structure,a.worldconstruction').each(function () {
|
||||
$('a.entity,a.hf,a.region,a.site,a.structure,a.worldconstruction,a.artifact,a.writtencontent').each(function () {
|
||||
var popover = new bootstrap.Popover($(this), { content: loadLinkPopoverData, trigger: "hover", placement: "top", html: true })
|
||||
})
|
||||
</script>
|
||||
|
|
12
backend/templates/popoverArtifact.html
Normal file
12
backend/templates/popoverArtifact.html
Normal file
|
@ -0,0 +1,12 @@
|
|||
{{- if or (ne .ItemType "") (ne .ItemSubtype "")}}
|
||||
{{.Mat}} {{if ne .ItemSubtype ""}}{{.ItemSubtype}}{{else}}{{.ItemType}}{{end}}
|
||||
{{- end}}
|
||||
{{- if ne .Writing -1 }}
|
||||
containing {{ writtenContent .Writing}}
|
||||
{{- end}}
|
||||
{{- if ne .SiteId -1 }}
|
||||
stored in {{ site .SiteId}}
|
||||
{{- end}}
|
||||
{{- if ne .HolderHfid -1 }}
|
||||
owned by {{ hf .HolderHfid}}
|
||||
{{- end}}
|
1
backend/templates/popoverWrittenContent.html
Normal file
1
backend/templates/popoverWrittenContent.html
Normal file
|
@ -0,0 +1 @@
|
|||
{{ .Type_ }} by {{ hf .AuthorHfid }}
|
37
backend/templates/writtencontent.html
Normal file
37
backend/templates/writtencontent.html
Normal file
|
@ -0,0 +1,37 @@
|
|||
{{template "layout.html" .}}
|
||||
|
||||
{{define "title"}}{{ title .Name }}{{end}}
|
||||
|
||||
{{define "content"}}
|
||||
<h3>{{ title .Name }}</h3>
|
||||
<p>{{ .Type_ }} by {{ hf .AuthorHfid }}</p>
|
||||
|
||||
<div class="row">
|
||||
{{- if ne 0 (len .Reference) }}
|
||||
<div class="col-md-9">
|
||||
<h5>References</h5>
|
||||
<ul>
|
||||
{{- range .Reference }}
|
||||
<li> {{ .Html (context $) }}</li>
|
||||
{{- end }}
|
||||
</ul>
|
||||
</div>
|
||||
{{- end }}
|
||||
|
||||
{{- if ne 0 (len .Style) }}
|
||||
<div class="col-3">
|
||||
<h5>Style</h5>
|
||||
<ul>
|
||||
{{- range .Style }}
|
||||
<li> {{ . }}</li>
|
||||
{{- end }}
|
||||
</ul>
|
||||
</div>
|
||||
{{- end }}
|
||||
</div>
|
||||
|
||||
<h5 class="mt-3">Events</h5>
|
||||
{{ template "events.html" events . }}
|
||||
|
||||
<p>{{ json . }}</p>
|
||||
{{- end }}
|
Loading…
Reference in a new issue