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{
|
||||
BaseRenderData: *alps.NewBaseRenderData(ctx),
|
||||
BaseRenderData: *alps.NewBaseRenderData(ctx).WithTitle(mbox.Name),
|
||||
Mailbox: mbox,
|
||||
Mailboxes: mailboxes,
|
||||
Messages: msgs,
|
||||
|
@ -271,7 +271,8 @@ func handleGetPart(ctx *alps.Context, raw bool) error {
|
|||
}
|
||||
|
||||
return ctx.Render(http.StatusOK, "message.html", &MessageRenderData{
|
||||
BaseRenderData: *alps.NewBaseRenderData(ctx),
|
||||
BaseRenderData: *alps.NewBaseRenderData(ctx).
|
||||
WithTitle(msg.Envelope.Subject),
|
||||
Mailboxes: mailboxes,
|
||||
Mailbox: mbox,
|
||||
Message: msg,
|
||||
|
|
17
renderer.go
17
renderer.go
|
@ -24,6 +24,8 @@ type GlobalRenderData struct {
|
|||
// 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
|
||||
|
|
|
@ -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…
Reference in a new issue