This is an automated email from the ASF dual-hosted git repository.
sebb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/whimsy.git
The following commit(s) were added to refs/heads/master by this push:
new f0b015c Add option to revert to the original mail
f0b015c is described below
commit f0b015cea0108fd9d176e0659158b47cf662a778
Author: Sebb <[email protected]>
AuthorDate: Tue Sep 29 11:08:40 2020 +0100
Add option to revert to the original mail
---
www/secretary/workbench/models/mailbox.rb | 13 +++++++++++
.../workbench/views/actions/revert.json.rb | 8 +++++++
www/secretary/workbench/views/parts.js.rb | 25 ++++++++++++++++++++++
3 files changed, 46 insertions(+)
diff --git a/www/secretary/workbench/models/mailbox.rb
b/www/secretary/workbench/models/mailbox.rb
index 8d3fc6b..07412fe 100644
--- a/www/secretary/workbench/models/mailbox.rb
+++ b/www/secretary/workbench/models/mailbox.rb
@@ -104,6 +104,19 @@ class Mailbox
end
#
+ # Revert a message
+ #
+ def self.revert(message)
+ month, hash = message.match(%r{/(\d+)/(\w+)}).captures
+ mailbox = Mailbox.new(month)
+ email = File.read(File.join(mailbox.dir, hash), encoding: Encoding::BINARY)
+ headers = Message.parse(email)
+ message = Message.new(mailbox, hash, headers, email)
+ message.write_headers
+ message
+ end
+
+ #
# Find a message
#
def find(hash)
diff --git a/www/secretary/workbench/views/actions/revert.json.rb
b/www/secretary/workbench/views/actions/revert.json.rb
new file mode 100644
index 0000000..d9977ab
--- /dev/null
+++ b/www/secretary/workbench/views/actions/revert.json.rb
@@ -0,0 +1,8 @@
+#
+# revert to the original document
+#
+
+message = Mailbox.revert(@message)
+
+# TODO: ensure correct attachment is selected
+{attachments: message.attachments, selected: message.attachments.first}
diff --git a/www/secretary/workbench/views/parts.js.rb
b/www/secretary/workbench/views/parts.js.rb
index c60be0a..056df1e 100644
--- a/www/secretary/workbench/views/parts.js.rb
+++ b/www/secretary/workbench/views/parts.js.rb
@@ -80,6 +80,8 @@ class Parts < Vue
_li "\u21c5 flip", onMousedown: self.rotate_attachment
_li "\u21B6 left", onMousedown: self.rotate_attachment
_li.divider
+ _li "\u2704 revert", onMousedown: self.revert
+ _li.divider
_li "\u2716 delete", onMousedown: self.delete_attachment
_li "\u2709 pdf-ize", onMousedown: self.pdfize
_li.divider
@@ -219,6 +221,8 @@ class Parts < Vue
_li "\u21c5 flip", onMousedown: self.rotate_attachment
_li "\u21B6 left", onMousedown: self.rotate_attachment
_li.divider
+ _li "\u2704 revert", onMousedown: self.revert
+ _li.divider
_li "\u2716 delete", onMousedown: self.delete_attachment
_li "\u2709 pdf-ize", onMousedown: self.pdfize
_li.divider
@@ -409,6 +413,27 @@ class Parts < Vue
}
end
+ # revert to the original
+ def revert(_event)
+ data = {
+ selected: @menu || decodeURI(@selected),
+ message: window.parent.location.pathname
+ }
+
+ @busy = true
+ HTTP.post('../../actions/revert', data).then {|response|
+ @attachments = response.attachments
+ self.selectPart response.selected
+ self.hideMenu()
+
+ # reload attachment in content pane
+ window.parent.frames.content.location.href = response.selected
+ }.catch {|error|
+ alert error
+ self.hideMenu()
+ }
+ end
+
# rotate an attachment
def rotate_attachment(event)
message = window.parent.location.pathname