Use context-appropriate title for mbox/msg view
This commit is contained in:
parent
1cf95af41e
commit
3d1f278fae
3 changed files with 25 additions and 15 deletions
|
@ -136,7 +136,7 @@ func handleGetMailbox(ctx *alps.Context) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
return ctx.Render(http.StatusOK, "mailbox.html", &MailboxRenderData{
|
return ctx.Render(http.StatusOK, "mailbox.html", &MailboxRenderData{
|
||||||
BaseRenderData: *alps.NewBaseRenderData(ctx),
|
BaseRenderData: *alps.NewBaseRenderData(ctx).WithTitle(mbox.Name),
|
||||||
Mailbox: mbox,
|
Mailbox: mbox,
|
||||||
Mailboxes: mailboxes,
|
Mailboxes: mailboxes,
|
||||||
Messages: msgs,
|
Messages: msgs,
|
||||||
|
@ -271,14 +271,15 @@ func handleGetPart(ctx *alps.Context, raw bool) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
return ctx.Render(http.StatusOK, "message.html", &MessageRenderData{
|
return ctx.Render(http.StatusOK, "message.html", &MessageRenderData{
|
||||||
BaseRenderData: *alps.NewBaseRenderData(ctx),
|
BaseRenderData: *alps.NewBaseRenderData(ctx).
|
||||||
Mailboxes: mailboxes,
|
WithTitle(msg.Envelope.Subject),
|
||||||
Mailbox: mbox,
|
Mailboxes: mailboxes,
|
||||||
Message: msg,
|
Mailbox: mbox,
|
||||||
Part: msg.PartByPath(partPath),
|
Message: msg,
|
||||||
View: view,
|
Part: msg.PartByPath(partPath),
|
||||||
MailboxPage: int(mbox.Messages-msg.SeqNum) / messagesPerPage,
|
View: view,
|
||||||
Flags: flags,
|
MailboxPage: int(mbox.Messages-msg.SeqNum) / messagesPerPage,
|
||||||
|
Flags: flags,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
19
renderer.go
19
renderer.go
|
@ -17,13 +17,15 @@ const themesDir = "themes"
|
||||||
// GlobalRenderData contains data available in all templates.
|
// GlobalRenderData contains data available in all templates.
|
||||||
type GlobalRenderData struct {
|
type GlobalRenderData struct {
|
||||||
Path []string
|
Path []string
|
||||||
URL *url.URL
|
URL *url.URL
|
||||||
|
|
||||||
LoggedIn bool
|
LoggedIn bool
|
||||||
|
|
||||||
// if logged in
|
// if logged in
|
||||||
Username string
|
Username string
|
||||||
|
|
||||||
|
Title string
|
||||||
|
|
||||||
// additional plugin-specific data
|
// additional plugin-specific data
|
||||||
Extra map[string]interface{}
|
Extra map[string]interface{}
|
||||||
}
|
}
|
||||||
|
@ -67,22 +69,29 @@ type RenderData interface {
|
||||||
// // other fields...
|
// // other fields...
|
||||||
// }
|
// }
|
||||||
func NewBaseRenderData(ctx *Context) *BaseRenderData {
|
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 {
|
if ctx.Session != nil {
|
||||||
global.LoggedIn = true
|
global.LoggedIn = true
|
||||||
global.Username = ctx.Session.username
|
global.Username = ctx.Session.username
|
||||||
}
|
}
|
||||||
|
|
||||||
global.URL = ctx.Request().URL
|
|
||||||
global.Path = strings.Split(global.URL.Path, "/")[1:]
|
|
||||||
|
|
||||||
return &BaseRenderData{
|
return &BaseRenderData{
|
||||||
GlobalData: global,
|
GlobalData: global,
|
||||||
Extra: make(map[string]interface{}),
|
Extra: make(map[string]interface{}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (brd *BaseRenderData) WithTitle(title string) *BaseRenderData {
|
||||||
|
brd.GlobalData.Title = title
|
||||||
|
return brd
|
||||||
|
}
|
||||||
|
|
||||||
type renderer struct {
|
type renderer struct {
|
||||||
logger echo.Logger
|
logger echo.Logger
|
||||||
defaultTheme string
|
defaultTheme string
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
{{- if eq (index .GlobalData.Path 0) "mailbox"}}
|
{{- if eq (index .GlobalData.Path 0) "mailbox"}}
|
||||||
<meta id="refresh" http-equiv="refresh" content="60">
|
<meta id="refresh" http-equiv="refresh" content="60">
|
||||||
{{end -}}
|
{{end -}}
|
||||||
<title>Webmail</title>
|
<title>{{.GlobalData.Title}}</title>
|
||||||
<link rel="stylesheet" href="/themes/alps/assets/style.css">
|
<link rel="stylesheet" href="/themes/alps/assets/style.css">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
Loading…
Reference in a new issue