From cb37df882edc51ed47f4b353ce42eabd80416b19 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Thu, 19 Nov 2020 11:17:40 -0500 Subject: Add notices on action completion --- plugins/base/routes.go | 5 +++++ renderer.go | 3 +++ session.go | 11 +++++++++++ themes/alps/assets/style.css | 7 +++++++ themes/alps/mailbox.html | 2 +- themes/alps/nav.html | 6 ++++++ 6 files changed, 33 insertions(+), 1 deletion(-) diff --git a/plugins/base/routes.go b/plugins/base/routes.go index 0345189..1562a15 100644 --- a/plugins/base/routes.go +++ b/plugins/base/routes.go @@ -306,6 +306,7 @@ func handleDeleteMailbox(ctx *alps.Context) error { ctx.Session.DoIMAP(func(c *imapclient.Client) error { return c.Delete(mbox.Name) }) + ctx.Session.PutNotice("Mailbox deleted.") return ctx.Redirect(http.StatusFound, "/mailbox/INBOX") } @@ -519,6 +520,7 @@ func submitCompose(ctx *alps.Context, msg *OutgoingMessage, options *composeOpti return fmt.Errorf("failed to save message to Sent mailbox: %v", err) } + ctx.Session.PutNotice("Message sent.") return ctx.Redirect(http.StatusFound, "/mailbox/INBOX") } @@ -651,6 +653,7 @@ func handleCompose(ctx *alps.Context, msg *OutgoingMessage, options *composeOpti if err != nil { return fmt.Errorf("failed to save message to Draft mailbox: %v", err) } + ctx.Session.PutNotice("Message saved as draft.") return ctx.Redirect(http.StatusFound, fmt.Sprintf( "/message/%s/%d/edit?part=1", drafts.Name, uid)) } else { @@ -981,6 +984,7 @@ func handleMove(ctx *alps.Context) error { return err } + ctx.Session.PutNotice("Message(s) moved.") if path := formOrQueryParam(ctx, "next"); path != "" { return ctx.Redirect(http.StatusFound, path) } @@ -1032,6 +1036,7 @@ func handleDelete(ctx *alps.Context) error { return err } + ctx.Session.PutNotice("Message(s) deleted.") if path := formOrQueryParam(ctx, "next"); path != "" { return ctx.Redirect(http.StatusFound, path) } diff --git a/renderer.go b/renderer.go index 1123b0b..d8ea325 100644 --- a/renderer.go +++ b/renderer.go @@ -28,6 +28,8 @@ type GlobalRenderData struct { HavePlugin func(name string) bool + Notice string + // additional plugin-specific data Extra map[string]interface{} } @@ -95,6 +97,7 @@ func NewBaseRenderData(ectx echo.Context) *BaseRenderData { if isactx && ctx.Session != nil { global.LoggedIn = true global.Username = ctx.Session.username + global.Notice = ctx.Session.PopNotice() } return &BaseRenderData{ diff --git a/session.go b/session.go index 950b324..8ea9634 100644 --- a/session.go +++ b/session.go @@ -57,6 +57,7 @@ type Session struct { pings chan struct{} timer *time.Timer store Store + notice string imapLocker sync.Mutex imapConn *imapclient.Client // protected by locker, can be nil @@ -183,6 +184,16 @@ func (s *Session) PopAttachment(uuid string) *Attachment { return a } +func (s *Session) PutNotice(n string) { + s.notice = n +} + +func (s *Session) PopNotice() string { + n := s.notice + s.notice = "" + return n +} + // Store returns a store suitable for storing persistent user data. func (s *Session) Store() Store { return s.store diff --git a/themes/alps/assets/style.css b/themes/alps/assets/style.css index e07f4e2..e4a0d35 100644 --- a/themes/alps/assets/style.css +++ b/themes/alps/assets/style.css @@ -118,6 +118,13 @@ header nav div { float: right; } header nav div > a{ margin-left: 1rem; } header a.active { font-weight: bold; color: black; text-decoration: none; } +header .notice { + color: #0c5460; + background-color: #d1ecf1; + border: 1px solid #bee5eb; + padding: 0.5rem; + text-align: center; +} footer { text-align: right; } diff --git a/themes/alps/mailbox.html b/themes/alps/mailbox.html index 9a4c9ce..a3a2e6a 100644 --- a/themes/alps/mailbox.html +++ b/themes/alps/mailbox.html @@ -21,7 +21,7 @@ {{ $classes = printf "%s %s" $classes "message-list-deleted" }} {{ end }} - {{ if not (.HasFlag "\\Deleted") }} + {{ if and (not (.HasFlag "\\Deleted")) .Envelope }}
diff --git a/themes/alps/nav.html b/themes/alps/nav.html index d7eee9c..8fccea4 100644 --- a/themes/alps/nav.html +++ b/themes/alps/nav.html @@ -30,4 +30,10 @@ {{ end }} + {{ if .GlobalData.Notice }} +
+ {{ .GlobalData.Notice }} + Dismiss +
+ {{ end }} -- cgit v1.2.3