popovers
This commit is contained in:
parent
6f3f13bdb7
commit
87451e7357
10 changed files with 54 additions and 15 deletions
|
@ -201,7 +201,7 @@ func (c *Context) poeticForm(id int) string {
|
|||
|
||||
func (c *Context) worldConstruction(id int) string {
|
||||
if x, ok := c.World.WorldConstructions[id]; ok {
|
||||
return fmt.Sprintf(`<a class="worldconstruction" href="/wc/%d"><i class="%s fa-xs"></i> %s</a>`, id, x.Icon(), util.Title(x.Name()))
|
||||
return fmt.Sprintf(`<a class="worldconstruction" href="/worldconstruction/%d"><i class="%s fa-xs"></i> %s</a>`, id, x.Icon(), util.Title(x.Name()))
|
||||
}
|
||||
return "UNKNOWN WORLD CONSTRUCTION"
|
||||
}
|
||||
|
|
|
@ -42,36 +42,29 @@ func StartServer(world *model.DfWorld, static embed.FS) {
|
|||
|
||||
srv.RegisterWorldPage("/entities", "entities.html", func(p Parms) any { return grouped(srv.context.world.Entities) })
|
||||
srv.RegisterWorldResourcePage("/entity/{id}", "entity.html", func(id int) any { return srv.context.world.Entities[id] })
|
||||
srv.RegisterWorldResourcePage("/popover/entity/{id}", "popoverEntity.html", func(id int) any { return srv.context.world.Entities[id] })
|
||||
|
||||
srv.RegisterWorldPage("/regions", "regions.html", func(p Parms) any { return grouped(srv.context.world.Regions) })
|
||||
srv.RegisterWorldResourcePage("/region/{id}", "region.html", func(id int) any { return srv.context.world.Regions[id] })
|
||||
srv.RegisterWorldResourcePage("/popover/region/{id}", "popoverRegion.html", func(id int) any { return srv.context.world.Regions[id] })
|
||||
|
||||
srv.RegisterWorldPage("/sites", "sites.html", func(p Parms) any { return grouped(srv.context.world.Sites) })
|
||||
srv.RegisterWorldResourcePage("/site/{id}", "site.html", func(id int) any { return srv.context.world.Sites[id] })
|
||||
srv.RegisterWorldResourcePage("/popover/site/{id}", "popoverSite.html", func(id int) any { return srv.context.world.Sites[id] })
|
||||
|
||||
srv.RegisterWorldPage("/structures", "structures.html", func(p Parms) any {
|
||||
return flatGrouped(srv.context.world.Sites, func(s *model.Site) []*model.Structure { return util.Values(s.Structures) })
|
||||
})
|
||||
srv.RegisterWorldPage("/site/{siteId}/structure/{id}", "structure.html", func(p Parms) any {
|
||||
siteId, err := strconv.Atoi(p["siteId"])
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
structureId, err := strconv.Atoi(p["id"])
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
if site, ok := srv.context.world.Sites[siteId]; ok {
|
||||
return site.Structures[structureId]
|
||||
}
|
||||
return nil
|
||||
})
|
||||
srv.RegisterWorldPage("/site/{siteId}/structure/{id}", "structure.html", srv.findStructure)
|
||||
srv.RegisterWorldPage("/popover/site/{siteId}/structure/{id}", "popoverStructure.html", srv.findStructure)
|
||||
|
||||
srv.RegisterWorldPage("/worldconstructions", "worldconstructions.html", func(p Parms) any { return grouped(srv.context.world.WorldConstructions) })
|
||||
srv.RegisterWorldResourcePage("/worldconstruction/{id}", "worldconstruction.html", func(id int) any { return srv.context.world.WorldConstructions[id] })
|
||||
srv.RegisterWorldResourcePage("/popover/worldconstruction/{id}", "popoverWorldconstruction.html", func(id int) any { return srv.context.world.WorldConstructions[id] })
|
||||
|
||||
srv.RegisterWorldPage("/artifacts", "artifacts.html", func(p Parms) any { return grouped(srv.context.world.Artifacts) })
|
||||
srv.RegisterWorldResourcePage("/artifact/{id}", "artifact.html", func(id int) any { return srv.context.world.Artifacts[id] })
|
||||
srv.RegisterWorldResourcePage("/popover/artifact/{id}", "popoverArtifact.html", func(id int) any { return srv.context.world.Artifacts[id] })
|
||||
|
||||
srv.RegisterWorldPage("/artforms", "artforms.html", func(p Parms) any {
|
||||
return &struct {
|
||||
|
@ -87,8 +80,10 @@ func StartServer(world *model.DfWorld, static embed.FS) {
|
|||
|
||||
srv.RegisterWorldPage("/writtencontents", "writtencontents.html", func(p Parms) any { return grouped(srv.context.world.WrittenContents) })
|
||||
srv.RegisterWorldResourcePage("/writtencontent/{id}", "writtencontent.html", func(id int) any { return srv.context.world.WrittenContents[id] })
|
||||
srv.RegisterWorldResourcePage("/popover/writtencontent/{id}", "popoverWrittencontent.html", func(id int) any { return srv.context.world.WrittenContents[id] })
|
||||
|
||||
srv.RegisterWorldResourcePage("/hf/{id}", "hf.html", func(id int) any { return srv.context.world.HistoricalFigures[id] })
|
||||
srv.RegisterWorldResourcePage("/popover/hf/{id}", "popoverHf.html", func(id int) any { return srv.context.world.HistoricalFigures[id] })
|
||||
|
||||
srv.RegisterWorldPage("/", "eventTypes.html", func(p Parms) any { return srv.context.world.AllEventTypes() })
|
||||
srv.RegisterWorldPage("/events", "eventTypes.html", func(p Parms) any { return srv.context.world.AllEventTypes() })
|
||||
|
@ -107,6 +102,21 @@ func StartServer(world *model.DfWorld, static embed.FS) {
|
|||
http.ListenAndServe(":8080", srv.router)
|
||||
}
|
||||
|
||||
func (srv *DfServer) findStructure(p Parms) any {
|
||||
siteId, err := strconv.Atoi(p["siteId"])
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
structureId, err := strconv.Atoi(p["id"])
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
if site, ok := srv.context.world.Sites[siteId]; ok {
|
||||
return site.Structures[structureId]
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type spaHandler struct {
|
||||
server *DfServer
|
||||
staticFS embed.FS
|
||||
|
|
6
backend/static/js/popper.min.js
vendored
Normal file
6
backend/static/js/popper.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
|
@ -11,6 +11,7 @@
|
|||
<link href="/css/all.min.css" rel="stylesheet">
|
||||
<link href="/css/legends.css" rel="stylesheet">
|
||||
<script src="/js/jquery-3.6.0.min.js"></script>
|
||||
<script src="/js/popper.min.js"></script>
|
||||
<script src="/js/bootstrap.min.js"></script>
|
||||
<script src="/js/autocomplete.js"></script>
|
||||
</head>
|
||||
|
@ -96,6 +97,17 @@
|
|||
$('.nav-tabs button').on('click', function (e) {
|
||||
window.location.hash = $(this).data("bs-target")
|
||||
});
|
||||
|
||||
function loadLinkPopoverData() {
|
||||
return $.ajax({
|
||||
url: "/popover" + this.getAttribute("href"),
|
||||
async: false
|
||||
}).responseText;
|
||||
}
|
||||
|
||||
$('a.entity,a.hf,a.region,a.site,a.structure,a.worldconstruction').each(function () {
|
||||
var popover = new bootstrap.Popover($(this), { content: loadLinkPopoverData, trigger: "hover", placement: "top", html: true })
|
||||
})
|
||||
</script>
|
||||
</body>
|
||||
|
||||
|
|
1
backend/templates/popoverEntity.html
Normal file
1
backend/templates/popoverEntity.html
Normal file
|
@ -0,0 +1 @@
|
|||
{{ .Race }} {{ .Type }}
|
6
backend/templates/popoverHf.html
Normal file
6
backend/templates/popoverHf.html
Normal file
|
@ -0,0 +1,6 @@
|
|||
{{if .Female }}
|
||||
<i class="fa-solid fa-venus fa-xs"></i>
|
||||
{{else}}
|
||||
<i class="fa-solid fa-mars fa-xs"></i>
|
||||
{{end}}
|
||||
{{ .Race }} (*{{ .BirthYear }}{{ if ge .DeathYear 0 }} †{{ .DeathYear }}{{ end }})
|
1
backend/templates/popoverRegion.html
Normal file
1
backend/templates/popoverRegion.html
Normal file
|
@ -0,0 +1 @@
|
|||
{{ .Type }}
|
1
backend/templates/popoverSite.html
Normal file
1
backend/templates/popoverSite.html
Normal file
|
@ -0,0 +1 @@
|
|||
{{ .Type }}{{if .Ruin}} (ruin){{end}}
|
1
backend/templates/popoverStructure.html
Normal file
1
backend/templates/popoverStructure.html
Normal file
|
@ -0,0 +1 @@
|
|||
{{ .Type }} in {{ site .SiteId }}
|
1
backend/templates/popoverWorldconstruction.html
Normal file
1
backend/templates/popoverWorldconstruction.html
Normal file
|
@ -0,0 +1 @@
|
|||
{{ .Type }}
|
Loading…
Reference in a new issue