Przeglądaj źródła

Use context-appropriate title for mbox/msg view

master
Drew DeVault 4 lat temu
committed by Simon Ser
rodzic
commit
3d1f278fae
Nie znaleziono w bazie danych klucza dla tego podpisu ID klucza GPG: FDE7BE0E88F5E48
3 zmienionych plików z 25 dodań i 15 usunięć
  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 Wyświetl plik

@@ -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),
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 Wyświetl plik

@@ -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


+ 1
- 1
themes/alps/head.html Wyświetl plik

@@ -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>

Ładowanie…
Anuluj
Zapisz