Browse Source

Use context-appropriate title for mbox/msg view

master
Drew DeVault 4 years ago
committed by Simon Ser
parent
commit
3d1f278fae
No known key found for this signature in database GPG Key ID: FDE7BE0E88F5E48
3 changed files with 25 additions and 15 deletions
  1. +10
    -9
      plugins/base/routes.go
  2. +14
    -5
      renderer.go
  3. +1
    -1
      themes/alps/head.html

+ 10
- 9
plugins/base/routes.go View File

@@ -136,7 +136,7 @@ func handleGetMailbox(ctx *alps.Context) error {
}

return ctx.Render(http.StatusOK, "mailbox.html", &MailboxRenderData{
BaseRenderData: *alps.NewBaseRenderData(ctx),
BaseRenderData: *alps.NewBaseRenderData(ctx).WithTitle(mbox.Name),
Mailbox: mbox,
Mailboxes: mailboxes,
Messages: msgs,
@@ -271,14 +271,15 @@ func handleGetPart(ctx *alps.Context, raw bool) error {
}

return ctx.Render(http.StatusOK, "message.html", &MessageRenderData{
BaseRenderData: *alps.NewBaseRenderData(ctx),
Mailboxes: mailboxes,
Mailbox: mbox,
Message: msg,
Part: msg.PartByPath(partPath),
View: view,
MailboxPage: int(mbox.Messages-msg.SeqNum) / messagesPerPage,
Flags: flags,
BaseRenderData: *alps.NewBaseRenderData(ctx).
WithTitle(msg.Envelope.Subject),
Mailboxes: mailboxes,
Mailbox: mbox,
Message: msg,
Part: msg.PartByPath(partPath),
View: view,
MailboxPage: int(mbox.Messages-msg.SeqNum) / messagesPerPage,
Flags: flags,
})
}



+ 14
- 5
renderer.go View File

@@ -17,13 +17,15 @@ const themesDir = "themes"
// GlobalRenderData contains data available in all templates.
type GlobalRenderData struct {
Path []string
URL *url.URL
URL *url.URL

LoggedIn bool

// if logged in
Username string

Title string

// additional plugin-specific data
Extra map[string]interface{}
}
@@ -67,22 +69,29 @@ type RenderData interface {
// // other fields...
// }
func NewBaseRenderData(ctx *Context) *BaseRenderData {
global := GlobalRenderData{Extra: make(map[string]interface{})}
global := GlobalRenderData{
Extra: make(map[string]interface{}),
Path: strings.Split(ctx.Request().URL.Path, "/")[1:],
Title: "Webmail",
URL: ctx.Request().URL,
}

if ctx.Session != nil {
global.LoggedIn = true
global.Username = ctx.Session.username
}

global.URL = ctx.Request().URL
global.Path = strings.Split(global.URL.Path, "/")[1:]

return &BaseRenderData{
GlobalData: global,
Extra: make(map[string]interface{}),
}
}

func (brd *BaseRenderData) WithTitle(title string) *BaseRenderData {
brd.GlobalData.Title = title
return brd
}

type renderer struct {
logger echo.Logger
defaultTheme string


+ 1
- 1
themes/alps/head.html View File

@@ -7,7 +7,7 @@
{{- if eq (index .GlobalData.Path 0) "mailbox"}}
<meta id="refresh" http-equiv="refresh" content="60">
{{end -}}
<title>Webmail</title>
<title>{{.GlobalData.Title}}</title>
<link rel="stylesheet" href="/themes/alps/assets/style.css">
</head>
<body>

Loading…
Cancel
Save