From a0ab84abb52a2f3c4b61e9357e54a79cca1b5805 Mon Sep 17 00:00:00 2001 From: James Hillyerd Date: Sat, 13 Oct 2012 14:11:12 -0700 Subject: [PATCH] Message list is now loaded by AJAX and can be refreshed. Added a message delete button. --- app/controllers/mailbox.go | 30 ++++++++++++--- app/inbucket/datastore.go | 9 +++++ app/views/Mailbox/Index.html | 72 ++++++++++++++++++++++++++++++++++++ app/views/Mailbox/List.html | 54 +++++---------------------- app/views/Mailbox/Show.html | 4 ++ conf/routes | 1 + public/stylesheets/main.css | 17 +++++++++ 7 files changed, 137 insertions(+), 50 deletions(-) create mode 100644 app/views/Mailbox/Index.html diff --git a/app/controllers/mailbox.go b/app/controllers/mailbox.go index 15a5ff1..44265e9 100644 --- a/app/controllers/mailbox.go +++ b/app/controllers/mailbox.go @@ -1,7 +1,6 @@ package controllers import ( - "fmt" "github.com/jhillyerd/inbucket/app/inbucket" "github.com/robfig/revel" ) @@ -11,12 +10,10 @@ type Mailbox struct { } func (c Mailbox) Index(name string) rev.Result { - return c.Redirect("/mailbox/list/%v", name) + return c.Render(name) } func (c Mailbox) List(name string) rev.Result { - title := fmt.Sprintf("Mailbox for %v", name) - ds := inbucket.NewDataStore() mb, err := ds.MailboxFor(name) if err != nil { @@ -32,7 +29,7 @@ func (c Mailbox) List(name string) rev.Result { } rev.INFO.Printf("Got %v messsages", len(messages)) - return c.Render(title, name, messages) + return c.Render(name, messages) } func (c Mailbox) Show(name string, id string) rev.Result { @@ -58,3 +55,26 @@ func (c Mailbox) Show(name string, id string) rev.Result { return c.Render(name, message, body) } + +func (c Mailbox) Delete(name string, id string) rev.Result { + ds := inbucket.NewDataStore() + mb, err := ds.MailboxFor(name) + if err != nil { + rev.ERROR.Printf(err.Error()) + c.Flash.Error(err.Error()) + return c.Redirect(Application.Index) + } + message, err := mb.GetMessage(id) + if err != nil { + rev.ERROR.Printf(err.Error()) + c.Flash.Error(err.Error()) + return c.Redirect(Application.Index) + } + err = message.Delete() + if err != nil { + rev.ERROR.Printf(err.Error()) + c.Flash.Error(err.Error()) + return c.Redirect(Application.Index) + } + return c.RenderText("OK") +} diff --git a/app/inbucket/datastore.go b/app/inbucket/datastore.go index b8d24d8..7b19d55 100644 --- a/app/inbucket/datastore.go +++ b/app/inbucket/datastore.go @@ -239,6 +239,15 @@ func (m *Message) Close() error { return m.createGob() } +// Delete this Message from disk by removing both the gob and raw files +func (m *Message) Delete() error { + err := os.Remove(m.gobPath()) + if err != nil { + return err + } + return os.Remove(m.rawPath()) +} + // createGob reads the .raw file to grab the From and Subject header entries, // then creates the .gob file. func (m *Message) createGob() error { diff --git a/app/views/Mailbox/Index.html b/app/views/Mailbox/Index.html new file mode 100644 index 0000000..e1aae1f --- /dev/null +++ b/app/views/Mailbox/Index.html @@ -0,0 +1,72 @@ +{{$title := printf "Inbucket for %v" .name}} +{{set "title" $title .}} +{{template "header.html" .}} +{{$name := .name}} + + +
+ + +
+
+ +
+
+

Select a message at left, or enter a different username into the box on upper right.

+
+
+ +{{template "footer.html" .}} + diff --git a/app/views/Mailbox/List.html b/app/views/Mailbox/List.html index 16cf461..f991cec 100644 --- a/app/views/Mailbox/List.html +++ b/app/views/Mailbox/List.html @@ -1,48 +1,12 @@ -{{template "header.html" .}} {{$name := .name}} - - -
- - - {{range .messages}} - - {{else}} -
-

No messages!

-
- {{end}} +{{range .messages}} +
- -
-
-

Select a message at left, or enter a different username into the box on upper right.

-
+{{else}} +
+

No messages!

- -{{template "footer.html" .}} - +{{end}} diff --git a/app/views/Mailbox/Show.html b/app/views/Mailbox/Show.html index a0fd0ea..b8ec0ae 100644 --- a/app/views/Mailbox/Show.html +++ b/app/views/Mailbox/Show.html @@ -1,3 +1,7 @@ +
diff --git a/conf/routes b/conf/routes index 2e8db28..e6154b9 100644 --- a/conf/routes +++ b/conf/routes @@ -7,6 +7,7 @@ GET /mailbox/{name} Mailbox.Index GET /mailbox Mailbox.Index GET /mailbox/list/{name} Mailbox.List GET /mailbox/show/{name}/{id} Mailbox.Show +POST /mailbox/delete/{name}/{id} Mailbox.Delete # Ignore favicon requests GET /favicon.ico 404 diff --git a/public/stylesheets/main.css b/public/stylesheets/main.css index 5d83cd8..33e5990 100644 --- a/public/stylesheets/main.css +++ b/public/stylesheets/main.css @@ -266,6 +266,7 @@ a:hover { #emailContent { padding-bottom: 20px; + min-height: 300px; } #emailHeader { @@ -285,3 +286,19 @@ a:hover { color: #000000; } +#emailActions { + padding: 5px 0; + margin: 0 0 10px 0; +} + +#emailActions a { + background: #8ac6dc; + color: #fff; + text-decoration: none; + font-weight: bold; + padding: 5px; +} + +#emailActions a:hover { + background: #becf74; +}
From: