From 266f17c23dd4b9a866bc104d780df3d4fd38265f Mon Sep 17 00:00:00 2001 From: Azareal Date: Thu, 29 Nov 2018 07:46:53 +1000 Subject: [PATCH] Revamped the Nox Account Manager and Control Panel Menus. The topics list template is now generated by loggedin. Replaced some uses of {{if ne .CurrentUser.ID 0}} with {{if .CurrentUser.Loggedin}} Fixed a bug in the profiles where the comment creation form was shown to guests. Added the profile_comments_form_guest phrase. --- common/template_init.go | 8 ++++- common/templates/context.go | 4 +-- common/templates/templates.go | 22 +++++++------- common/topic.go | 4 +-- langs/english.json | 1 + templates/account_own_edit.html | 52 ++++++++++++++++----------------- templates/forum.html | 6 ++-- templates/forums.html | 6 ++-- templates/header.html | 4 +-- templates/profile.html | 10 ++++++- templates/topics.html | 6 ++-- themes/nox/public/account.css | 30 +------------------ themes/nox/public/panel.css | 28 ++---------------- themes/nox/theme.json | 2 +- 14 files changed, 75 insertions(+), 108 deletions(-) diff --git a/common/template_init.go b/common/template_init.go index 88630195..a2952ee3 100644 --- a/common/template_init.go +++ b/common/template_init.go @@ -54,6 +54,8 @@ var Template_topics_handle = func(pi TopicListPage, w io.Writer) error { } return Templates.ExecuteTemplate(w, mapping+".html", pi) } +var Template_topics_guest_handle = Template_topics_handle +var Template_topics_member_handle = Template_topics_handle // nolint var Template_forum_handle = func(pi ForumPage, w io.Writer) error { @@ -270,7 +272,11 @@ func CompileTemplates() error { topicsList = append(topicsList, &TopicsRow{1, "topic-title", "Topic Title", "The topic content.", 1, false, false, now, now, "Date", user3.ID, 1, "", "127.0.0.1", 1, 0, 1, "classname", "", &user2, "", 0, &user3, "General", "/forum/general.2"}) header2.Title = "Topic List" topicListPage := TopicListPage{header, topicsList, forumList, Config.DefaultForum, TopicListSort{"lastupdated", false}, Paginator{[]int{1}, 1, 1}} - topicListTmpl, err := compile("topics", "common.TopicListPage", topicListPage) + /*topicListTmpl, err := compile("topics", "common.TopicListPage", topicListPage) + if err != nil { + return err + }*/ + topicListTmpl, err := compileByLoggedin("topics", "common.TopicListPage", topicListPage) if err != nil { return err } diff --git a/common/templates/context.go b/common/templates/context.go index 7ac03819..2e9e66a7 100644 --- a/common/templates/context.go +++ b/common/templates/context.go @@ -43,8 +43,8 @@ func (con *CContext) PushText(body string, fragIndex int, fragOutIndex int) (ind return con.LastBufIndex() } -func (con *CContext) PushPhrase(body string, langIndex int) (index int) { - *con.OutBuf = append(*con.OutBuf, OutBufferFrame{body, "lang", con.TemplateName, langIndex, nil}) +func (con *CContext) PushPhrase(langIndex int) (index int) { + *con.OutBuf = append(*con.OutBuf, OutBufferFrame{"", "lang", con.TemplateName, langIndex, nil}) return con.LastBufIndex() } diff --git a/common/templates/templates.go b/common/templates/templates.go index 50b0e8e4..232cb165 100644 --- a/common/templates/templates.go +++ b/common/templates/templates.go @@ -325,8 +325,8 @@ func (c *CTemplateSet) compile(name string, content, expects string, expectsInt for fid := 0; len(outBuf) > fid; fid++ { frame := outBuf[fid] + c.detail(frame.Type + " frame") if frame.Type == "text" { - c.detail("text frame:") c.detail(frame) oid := fid c.detail("oid:", oid) @@ -354,13 +354,12 @@ func (c *CTemplateSet) compile(name string, content, expects string, expectsInt } writeTextFrame(frame.TemplateName, frame.Extra.(int)-skip) } else if frame.Type == "varsub" || frame.Type == "cvarsub" { - c.detail(frame.Type + " frame") fout += "w.Write(" + frame.Body + ")\n" } else if frame.Type == "identifier" { - c.detailf(frame.Type+" frame:%+v\n", frame) fout += frame.Body + } else if frame.Type == "lang" { + fout += "w.Write(plist[" + strconv.Itoa(frame.Extra.(int)) + "])\n" } else { - c.detail(frame.Type + " frame") fout += frame.Body } } @@ -721,8 +720,10 @@ func (c *CTemplateSet) compileSubSwitch(con CContext, node *parse.CommandNode) { case *parse.IdentifierNode: c.detail("Identifier Node:", node) c.detail("Identifier Node Args:", node.Args) - out, outval, lit := c.compileIdentSwitch(con, node) - if lit { + out, outval, lit, noident := c.compileIdentSwitch(con, node) + if noident { + return + } else if lit { con.Push("identifier", out) return } @@ -780,7 +781,7 @@ func (c *CTemplateSet) unknownNode(node parse.Node) { func (c *CTemplateSet) compileIdentSwitchN(con CContext, node *parse.CommandNode) (out string) { c.detail("in compileIdentSwitchN") - out, _, _ = c.compileIdentSwitch(con, node) + out, _, _, _ = c.compileIdentSwitch(con, node) return out } @@ -844,7 +845,7 @@ func (c *CTemplateSet) compareJoin(con CContext, pos int, node *parse.CommandNod return pos, out } -func (c *CTemplateSet) compileIdentSwitch(con CContext, node *parse.CommandNode) (out string, val reflect.Value, literal bool) { +func (c *CTemplateSet) compileIdentSwitch(con CContext, node *parse.CommandNode) (out string, val reflect.Value, literal bool, notident bool) { c.dumpCall("compileIdentSwitch", con, node) var litString = func(inner string, bytes bool) { if !bytes { @@ -916,7 +917,8 @@ ArgLoop: // ! Slightly crude but it does the job leftParam := strings.Replace(leftOperand, "\"", "", -1) c.langIndexToName = append(c.langIndexToName, leftParam) - litString("plist["+strconv.Itoa(len(c.langIndexToName)-1)+"]", true) + notident = true + con.PushPhrase(len(c.langIndexToName) - 1) break ArgLoop case "level": // TODO: Implement level literals @@ -981,7 +983,7 @@ ArgLoop: } } c.retCall("compileIdentSwitch", out, val, literal) - return out, val, literal + return out, val, literal, notident } func (c *CTemplateSet) compileReflectSwitch(con CContext, node *parse.CommandNode) (out string, outVal reflect.Value) { diff --git a/common/topic.go b/common/topic.go index 6275c5e2..1bebc2f0 100644 --- a/common/topic.go +++ b/common/topic.go @@ -49,7 +49,7 @@ type TopicUser struct { ID int Link string Title string - Content string + Content string // TODO: Avoid converting this to bytes in templates, particularly if it's long CreatedBy int IsClosed bool Sticky bool @@ -74,7 +74,7 @@ type TopicUser struct { Avatar string MicroAvatar string ContentLines int - ContentHTML string + ContentHTML string // TODO: Avoid converting this to bytes in templates, particularly if it's long Tag string URL string URLPrefix string diff --git a/langs/english.json b/langs/english.json index 886ebf2e..48f7ba0b 100644 --- a/langs/english.json +++ b/langs/english.json @@ -637,6 +637,7 @@ "profile_comments_report_aria":"Report Item", "profile_comments_form_content":"Insert comment here", "profile_comments_form_button":"Create Reply", + "profile_comments_form_guest":"You need to login to comment on this profile.", "profile_owner_tag":"Profile Owner", "ip_search_head":"IP Search", diff --git a/templates/account_own_edit.html b/templates/account_own_edit.html index 4c7b3074..4fcc663e 100644 --- a/templates/account_own_edit.html +++ b/templates/account_own_edit.html @@ -1,29 +1,29 @@
-
-
-
- -
- - -
- - - - - - +
+
+
+ +
+ + +
+ + + + + + +
+
+
+
{{if not .MFASetup}}{{lang "account_dash_2fa_setup"}}{{else}}{{lang "account_dash_2fa_manage"}}{{end}} {{lang "account_dash_security_notice"}}
+
+ +
+
{{.CurrentScore}} / {{.NextScore}}
-
-
{{if not .MFASetup}}{{lang "account_dash_2fa_setup"}}{{else}}{{lang "account_dash_2fa_manage"}}{{end}} {{lang "account_dash_security_notice"}}
-
- -
-
{{.CurrentScore}} / {{.NextScore}}
-
-
-
-
\ No newline at end of file +
+
\ No newline at end of file diff --git a/templates/forum.html b/templates/forum.html index 995c9a76..db148a3b 100644 --- a/templates/forum.html +++ b/templates/forum.html @@ -8,7 +8,7 @@

{{.Title}}

- {{if ne .CurrentUser.ID 0}} + {{if .CurrentUser.Loggedin}}
{{if .CurrentUser.Perms.CreateTopic}}
@@ -22,7 +22,7 @@
{{end}}
- {{if ne .CurrentUser.ID 0}} + {{if .CurrentUser.Loggedin}}
@@ -110,7 +110,7 @@
-
{{else}}
{{lang "forum_no_topics"}}{{if .CurrentUser.Perms.CreateTopic}} {{lang "forum_start_one"}}{{end}}
{{end}} +
{{else}}
{{lang "forum_no_topics"}}{{if .CurrentUser.Loggedin}}{{if .CurrentUser.Perms.CreateTopic}} {{lang "forum_start_one"}}{{end}}{{end}}
{{end}} {{if gt .LastPage 1}} diff --git a/templates/forums.html b/templates/forums.html index 54eb4503..570afc3e 100644 --- a/templates/forums.html +++ b/templates/forums.html @@ -8,11 +8,11 @@ {{range .ItemList}}
- {{.Name}} + {{.Name}}
{{if .Desc}} -
{{.Desc}} + {{.Desc}} {{else}} -
{{lang "forums_no_description"}} + {{lang "forums_no_description"}} {{end}}
diff --git a/templates/header.html b/templates/header.html index 301ee8ce..f1e87260 100644 --- a/templates/header.html +++ b/templates/header.html @@ -24,7 +24,7 @@ {{if not .CurrentUser.IsSuperMod}}{{end}}
- + {{/****/}}
{{dock "leftOfNav" .Header }}
- + {{/****/}}
diff --git a/templates/profile.html b/templates/profile.html index 8fef0dc3..8dc22a4d 100644 --- a/templates/profile.html +++ b/templates/profile.html @@ -18,7 +18,7 @@ -
+
{{.CurrentScore}} / {{.NextScore}}
@@ -87,6 +87,7 @@
{{template "profile_comments_row.html" . }}
+{{if .CurrentUser.Loggedin}} {{if not .CurrentUser.IsBanned}} @@ -100,10 +101,16 @@
{{end}} +{{else}} +
+
{{lang "profile_comments_form_guest"}}
+
+{{end}}
+{{if .CurrentUser.Loggedin}} {{/** Quick subpage switcher **/}} {{/** TODO: Stop inlining this **/}} +{{end}} {{template "footer.html" . }} diff --git a/templates/topics.html b/templates/topics.html index 0be169d6..15304696 100644 --- a/templates/topics.html +++ b/templates/topics.html @@ -3,7 +3,7 @@

{{lang "topics_head"}}

- {{if ne .CurrentUser.ID 0}} + {{if .CurrentUser.Loggedin}}
{{if .ForumList}}
@@ -29,7 +29,7 @@ {{end}}
-{{if ne .CurrentUser.ID 0}} +{{if .CurrentUser.Loggedin}} {{/** TODO: Hide these from unauthorised users? **/}}
@@ -116,7 +116,7 @@
- {{range .TopicList}}{{template "topics_topic.html" . }}{{else}}
{{lang "topics_no_topics"}}{{if .CurrentUser.Perms.CreateTopic}} {{lang "topics_start_one"}}{{end}}
{{end}} + {{range .TopicList}}{{template "topics_topic.html" . }}{{else}}
{{lang "topics_no_topics"}}{{if .CurrentUser.Loggedin}}{{if .CurrentUser.Perms.CreateTopic}} {{lang "topics_start_one"}}{{end}}{{end}}
{{end}}
{{if gt .LastPage 1}} diff --git a/themes/nox/public/account.css b/themes/nox/public/account.css index e37266d0..86f5d154 100644 --- a/themes/nox/public/account.css +++ b/themes/nox/public/account.css @@ -6,35 +6,7 @@ #back { padding: 0px; } - -.rowmenu { - margin-left: 16px; -} -.colstack_left { - width: 200px; - padding-top: 12px; - padding-right: 24px; - padding-bottom: 24px; - padding-left: 24px; - background-color: #3e3e3e; -} -.colstack_left .colstack_head { - font-size: 19px; - margin-bottom: 4px; -} -.colstack_left .colstack_head:not(:first-child) { - margin-top: 8px; -} -.colstack_left .colstack_head a { - color: rgb(210, 210, 210); -} -.rowmenu { - margin-bottom: 2px; - font-size: 17px; -} -.rowmenu a { - color: rgb(180, 180, 180); -} +{{template "acc_panel_common.css" }} .colstack_right { background-color: #333333; diff --git a/themes/nox/public/panel.css b/themes/nox/public/panel.css index b368bccd..3478c0d4 100644 --- a/themes/nox/public/panel.css +++ b/themes/nox/public/panel.css @@ -10,38 +10,16 @@ .footer .widget, #poweredByHolder { background-color: #393939; } -.rowmenu { - margin-left: 16px; -} .submenu a:before { content: "-"; margin-right: 8px; } -.colstack_left { - width: 200px; - padding-top: 12px; - padding-right: 24px; - padding-bottom: 24px; - padding-left: 24px; - background-color: #3e3e3e; -} +{{template "acc_panel_common.css" }} .colstack_left .colstack_head { font-size: 19px; - margin-bottom: 4px; -} -.colstack_left .colstack_head:not(:first-child) { - margin-top: 8px; -} -.colstack_left .colstack_head a { - color: rgb(210, 210, 210); -} -.rowmenu { - margin-bottom: 2px; - font-size: 17px; -} -.rowmenu a { - color: rgb(180, 180, 180); + padding-top: 10px; + padding-bottom: 10px; } .menu_stats { margin-left: 4px; diff --git a/themes/nox/theme.json b/themes/nox/theme.json index 78696545..a76fa507 100644 --- a/themes/nox/theme.json +++ b/themes/nox/theme.json @@ -1,6 +1,6 @@ { "Name": "nox", - "FriendlyName": "Nox (Incomplete)", + "FriendlyName": "Nox (WIP)", "Version": "0.0.1", "Creator": "Azareal", "URL": "github.com/Azareal/Gosora",