From 2d366ce6a04bcf63e5f5ce4e99a6b78a55bb581e Mon Sep 17 00:00:00 2001 From: Azareal Date: Wed, 17 Apr 2019 20:12:35 +1000 Subject: [PATCH] Move action posts now show the forum the topic has been moved to. Move modlog events now show the forum the topic has been moved to. Moved the .action_icon styling from topic.html into the theme stylesheets. Added the topic.action_topic_move_dest phrase. --- langs/english.json | 1 + routes/panel/logs.go | 11 ++++++++++- routes/topic.go | 29 ++++++++++++++++++++-------- templates/topic_posts.html | 2 +- themes/shadow/public/main.css | 5 +++++ themes/tempra_simple/public/main.css | 4 ++++ 6 files changed, 42 insertions(+), 10 deletions(-) diff --git a/langs/english.json b/langs/english.json index 04a870de..572857b9 100644 --- a/langs/english.json +++ b/langs/english.json @@ -656,6 +656,7 @@ "topic.action_topic_stick":"This topic was pinned by %s", "topic.action_topic_unstick":"This topic was unpinned by %s", "topic.action_topic_move":"This topic was moved by %s", + "topic.action_topic_move_dest":"This topic was moved to %s by %s", "topic.action_topic_default":"%s has happened", "topic.your_information":"Your information", diff --git a/routes/panel/logs.go b/routes/panel/logs.go index b89958a6..6e6c6e55 100644 --- a/routes/panel/logs.go +++ b/routes/panel/logs.go @@ -51,11 +51,13 @@ func handleUnknownTopic(topic *common.Topic, err error) *common.Topic { } // TODO: Move the log building logic into /common/ and it's own abstraction +// TODO: Localise this func topicElementTypeAction(action string, elementType string, elementID int, actor *common.User, topic *common.Topic) (out string) { if action == "delete" { return fmt.Sprintf("Topic #%d was deleted by %s", elementID, actor.Link, actor.Name) } - switch action { + aarr := strings.Split(action, "-") + switch aarr[0] { case "lock": out = "%s was locked by %s" case "unlock": @@ -65,6 +67,13 @@ func topicElementTypeAction(action string, elementType string, elementID int, ac case "unstick": out = "%s was unpinned by %s" case "move": + if len(aarr) == 2 { + fid, _ := strconv.Atoi(aarr[1]) + forum, err := common.Forums.Get(fid) + if err == nil { + return fmt.Sprintf("%s was moved to %s by %s", topic.Link, topic.Title, forum.Link, forum.Name, actor.Link, actor.Name) + } + } out = "%s was moved by %s" // TODO: Add where it was moved to, we'll have to change the source data for that, most likely? Investigate that and try to work this in default: return fmt.Sprintf("Unknown action '%s' on elementType '%s' by %s", action, elementType, actor.Link, actor.Name) diff --git a/routes/topic.go b/routes/topic.go index fa44e598..d42dbdba 100644 --- a/routes/topic.go +++ b/routes/topic.go @@ -190,7 +190,8 @@ func ViewTopic(w http.ResponseWriter, r *http.Request, user common.User, header // We really shouldn't have inline HTML, we should do something about this... if replyItem.ActionType != "" { var action string - switch replyItem.ActionType { + aarr := strings.Split(replyItem.ActionType, "-") + switch aarr[0] { case "lock": action = "lock" replyItem.ActionIcon = "🔒︎" @@ -204,15 +205,25 @@ func ViewTopic(w http.ResponseWriter, r *http.Request, user common.User, header action = "unstick" replyItem.ActionIcon = "📌︎" case "move": - action = "move" + if len(aarr) == 2 { + fid, _ := strconv.Atoi(aarr[1]) + forum, err := common.Forums.Get(fid) + if err == nil { + replyItem.ActionType = phrases.GetTmplPhrasef("topic.action_topic_move_dest", forum.Link, forum.Name, replyItem.UserLink, replyItem.CreatedByName) + } else { + action = "move" + } + } else { + action = "move" + } + replyItem.ActionIcon = "" + default: + // TODO: Only fire this off if a corresponding phrase for the ActionType doesn't exist? Or maybe have some sort of action registry? + replyItem.ActionType = phrases.GetTmplPhrasef("topic.action_topic_default", replyItem.ActionType) replyItem.ActionIcon = "" } if action != "" { replyItem.ActionType = phrases.GetTmplPhrasef("topic.action_topic_"+action, replyItem.UserLink, replyItem.CreatedByName) - } else { - // TODO: Only fire this off if a corresponding phrase for the ActionType doesn't exist? Or maybe have some sort of action registry? - replyItem.ActionType = phrases.GetTmplPhrasef("topic.action_topic_default", replyItem.ActionType) - replyItem.ActionIcon = "" } } @@ -228,6 +239,7 @@ func ViewTopic(w http.ResponseWriter, r *http.Request, user common.User, header header.Hooks.VhookNoRet("topic_reply_row_assign", &tpage, &replyItem) // TODO: Use a pointer instead to make it easier to abstract this loop? What impact would this have on escape analysis? tpage.ItemList = append(tpage.ItemList, replyItem) + //log.Printf("r: %d-%d", replyItem.ID, len(tpage.ItemList)-1) } err = rows.Err() if err != nil { @@ -266,6 +278,7 @@ func ViewTopic(w http.ResponseWriter, r *http.Request, user common.User, header //log.Printf("amap: %+v\n", amap) //log.Printf("attachMap: %+v\n", attachMap) for id, attach := range amap { + //log.Print("id:", id) tpage.ItemList[attachMap[id]].Attachments = attach /*for _, a := range attach { log.Printf("a: %+v\n", a) @@ -929,8 +942,8 @@ func MoveTopicSubmit(w http.ResponseWriter, r *http.Request, user common.User, s return common.InternalErrorJS(err, w, r) } - // TODO: Log more data so we can list the destination forum in the action post? - err = addTopicAction("move", topic, user) + // ? - Is there a better way of doing this? + err = addTopicAction("move-"+strconv.Itoa(fid), topic, user) if err != nil { return common.InternalErrorJS(err, w, r) } diff --git a/templates/topic_posts.html b/templates/topic_posts.html index be23e817..54408af5 100644 --- a/templates/topic_posts.html +++ b/templates/topic_posts.html @@ -1,7 +1,7 @@
{{range .ItemList}} {{if .ActionType}}
- {{.ActionIcon}} + {{.ActionIcon}} {{.ActionType}}
{{else}} diff --git a/themes/shadow/public/main.css b/themes/shadow/public/main.css index 1363b409..73e4554e 100644 --- a/themes/shadow/public/main.css +++ b/themes/shadow/public/main.css @@ -253,6 +253,11 @@ h1, h2, h3, h4, h5 { float: right; } +.action_item .action_icon { + font-size: 18px; + padding-right: 5px; +} + /* TODO: Rewrite the closed topic header so that it looks more consistent with the rest of the theme */ .topic_closed_head .topic_status_closed { margin-bottom: -10px; diff --git a/themes/tempra_simple/public/main.css b/themes/tempra_simple/public/main.css index cf3ca513..b6b7984a 100644 --- a/themes/tempra_simple/public/main.css +++ b/themes/tempra_simple/public/main.css @@ -782,6 +782,10 @@ red { text-align: center; background-color: rgb(255,245,245); } +.action_item .action_icon { + font-size: 18px; + padding-right: 5px; +} blockquote { border: 1px solid hsl(0, 0%, 80%);