I can display the posts in a topic, albeit imperfectly
This commit is contained in:
+3
-3
@@ -25,7 +25,7 @@ import (
|
|||||||
"git.erbosoft.com/amy/amsterdam/htmlcheck"
|
"git.erbosoft.com/amy/amsterdam/htmlcheck"
|
||||||
"git.erbosoft.com/amy/amsterdam/ui"
|
"git.erbosoft.com/amy/amsterdam/ui"
|
||||||
"github.com/CloudyKit/jet/v6"
|
"github.com/CloudyKit/jet/v6"
|
||||||
"github.com/labstack/gommon/log"
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
/* Conferences displayes the list of conferences in a community.
|
/* Conferences displayes the list of conferences in a community.
|
||||||
@@ -513,13 +513,14 @@ func ReadPosts(ctxt ui.AmContext) (string, any, error) {
|
|||||||
postsPostRef := plc.AsString()
|
postsPostRef := plc.AsString()
|
||||||
|
|
||||||
// Render the output.
|
// Render the output.
|
||||||
|
ctxt.VarMap().Set("amsterdam_pageTitle", fmt.Sprintf("%s: %s", topic.Name, summaryLine))
|
||||||
ctxt.VarMap().Set("topicName", topic.Name)
|
ctxt.VarMap().Set("topicName", topic.Name)
|
||||||
ctxt.VarMap().Set("summaryLine", summaryLine)
|
ctxt.VarMap().Set("summaryLine", summaryLine)
|
||||||
ctxt.VarMap().Set("lastRead", lastRead)
|
ctxt.VarMap().Set("lastRead", lastRead)
|
||||||
ctxt.VarMap().Set("pageSize", ctxt.Globals().PostsPerPage)
|
ctxt.VarMap().Set("pageSize", ctxt.Globals().PostsPerPage)
|
||||||
ctxt.VarMap().Set("post_confRef", topicConferenceRef)
|
ctxt.VarMap().Set("post_confRef", topicConferenceRef)
|
||||||
ctxt.VarMap().SetFunc("post_getOverrideLine", templateOverrideLine)
|
ctxt.VarMap().SetFunc("post_getOverrideLine", templateOverrideLine)
|
||||||
ctxt.VarMap().SetFunc("post.getOverrideLink", templateOverrideLink)
|
ctxt.VarMap().SetFunc("post_getOverrideLink", templateOverrideLink)
|
||||||
ctxt.VarMap().SetFunc("post_getText", templatePostText)
|
ctxt.VarMap().SetFunc("post_getText", templatePostText)
|
||||||
ctxt.VarMap().SetFunc("post_getUserName", templateExtractUserName)
|
ctxt.VarMap().SetFunc("post_getUserName", templateExtractUserName)
|
||||||
ctxt.VarMap().Set("post_stem", fmt.Sprintf("/comm/%s/conf/%s/r/%d", comm.Alias, ctxt.GetScratch("currentAlias").(string), topic.Number))
|
ctxt.VarMap().Set("post_stem", fmt.Sprintf("/comm/%s/conf/%s/r/%d", comm.Alias, ctxt.GetScratch("currentAlias").(string), topic.Number))
|
||||||
@@ -532,7 +533,6 @@ func ReadPosts(ctxt ui.AmContext) (string, any, error) {
|
|||||||
ctxt.VarMap().Set("rangeStart", postRange[0])
|
ctxt.VarMap().Set("rangeStart", postRange[0])
|
||||||
ctxt.VarMap().Set("topicListLink", fmt.Sprintf("/comm/%s/conf/%s", comm.Alias, ctxt.GetScratch("currentAlias").(string)))
|
ctxt.VarMap().Set("topicListLink", fmt.Sprintf("/comm/%s/conf/%s", comm.Alias, ctxt.GetScratch("currentAlias").(string)))
|
||||||
ctxt.VarMap().Set("topicNum", topic.Number)
|
ctxt.VarMap().Set("topicNum", topic.Number)
|
||||||
ctxt.VarMap().Set("amsterdam_pageTitle", fmt.Sprintf("%s: %s", topic.Name, summaryLine))
|
|
||||||
if resetLastRead {
|
if resetLastRead {
|
||||||
user := ctxt.CurrentUser()
|
user := ctxt.CurrentUser()
|
||||||
ampool.Submit(func(ctx context.Context) {
|
ampool.Submit(func(ctx context.Context) {
|
||||||
|
|||||||
+7
-3
@@ -89,11 +89,15 @@ func AmGetPost(ctx context.Context, postId int64) (*PostHeader, error) {
|
|||||||
return &(dbdata[0]), nil
|
return &(dbdata[0]), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func AmGetPostRange(ctx context.Context, topic *Topic, first, last int32) ([]PostHeader, error) {
|
func AmGetPostRange(ctx context.Context, topic *Topic, first, last int32) ([]*PostHeader, error) {
|
||||||
var rc []PostHeader
|
var posts []PostHeader
|
||||||
err := amdb.SelectContext(ctx, &rc, "SELECT * FROM posts WHERE topicid = ? AND num >= ? AND num <= ? ORDER BY num", topic.TopicId, first, last)
|
err := amdb.SelectContext(ctx, &posts, "SELECT * FROM posts WHERE topicid = ? AND num >= ? AND num <= ? ORDER BY num", topic.TopicId, first, last)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
rc := make([]*PostHeader, len(posts))
|
||||||
|
for i := range posts {
|
||||||
|
rc[i] = &(posts[i])
|
||||||
|
}
|
||||||
return rc, nil
|
return rc, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,6 +62,7 @@ type AmContext interface {
|
|||||||
ReplaceUser(*database.User)
|
ReplaceUser(*database.User)
|
||||||
SaveSession() error
|
SaveSession() error
|
||||||
SubRender(string) ([]byte, error)
|
SubRender(string) ([]byte, error)
|
||||||
|
SubRender2(string, map[string]any) ([]byte, error)
|
||||||
SetCommunityContext(string) error
|
SetCommunityContext(string) error
|
||||||
SetLeftMenu(string)
|
SetLeftMenu(string)
|
||||||
SetLoginCookie(string)
|
SetLoginCookie(string)
|
||||||
@@ -320,6 +321,27 @@ func (c *amContext) SubRender(name string) ([]byte, error) {
|
|||||||
return buf.Bytes(), err
|
return buf.Bytes(), err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *amContext) SubRender2(name string, vals map[string]any) ([]byte, error) {
|
||||||
|
view, err := views.GetTemplate(name)
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("unable to load template \"%s\": %v", name, err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
newmap := make(jet.VarMap)
|
||||||
|
for k, v := range c.VarMap() {
|
||||||
|
newmap.Set(k, v)
|
||||||
|
}
|
||||||
|
for k, v := range vals {
|
||||||
|
newmap.Set(k, v)
|
||||||
|
}
|
||||||
|
buf := new(bytes.Buffer)
|
||||||
|
err = view.Execute(buf, newmap, c)
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("template \"%s\" failed subrender exec: %v", name, err)
|
||||||
|
}
|
||||||
|
return buf.Bytes(), err
|
||||||
|
}
|
||||||
|
|
||||||
/* SetCommunityContext establishes the community context from a (ID or alias) parameter.
|
/* SetCommunityContext establishes the community context from a (ID or alias) parameter.
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* param - String parameter selecting the community.
|
* param - String parameter selecting the community.
|
||||||
|
|||||||
+6
-11
@@ -74,17 +74,12 @@
|
|||||||
|
|
||||||
<!-- Messages -->
|
<!-- Messages -->
|
||||||
<div class="space-y-6 mb-8">
|
<div class="space-y-6 mb-8">
|
||||||
{{ post_userName := "" }}
|
{{ m := map("foo", "bar") }}
|
||||||
{{ post_text := "" }}
|
{{ range i, p := posts }}
|
||||||
{{ post_overrideLine := "" }}
|
{{ m = map("post_cur", p, "post_userName", post_getUserName(p, .), "post_text", post_getText(p, .),
|
||||||
{{ post_overrideLink := "" }}
|
"post_overrideLine", post_getOverrideLine(p, .), "post_overrideLink", post_getOverrideLink(p, post_topicPermalink)) }}
|
||||||
{{ range i, post_cur := posts }}
|
{{ .SubRender2("singlepost.jet", m) | raw }}
|
||||||
{{ post_userName = post_getUserName(post_cur, .) }}
|
{{ if pin == p.Num }}<hr/>{{ end }}
|
||||||
{{ post_text = post_getText(post_cur, .) }}
|
|
||||||
{{ post_overrideLine = post_getOverrideLine(post_cur, .) }}
|
|
||||||
{{ post_overrideLink = post_getOverrideLink(post_cur, post_topicPermalink) }}
|
|
||||||
{{ .SubRender("singlepost.jet") | raw }}
|
|
||||||
{{ if pin == post_cur.Num }}<hr/>{{ end }}
|
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user