whimsical-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ru...@apache.org
Subject [whimsy] branch master updated: add an action to convert to PDF
Date Sat, 08 Oct 2016 13:17:00 GMT
This is an automated email from the ASF dual-hosted git repository.

rubys pushed a commit to branch master
in repository https://git-dual.apache.org/repos/asf/whimsy.git

The following commit(s) were added to refs/heads/master by this push:
       new  e6c60d3   add an action to convert to PDF
e6c60d3 is described below

commit e6c60d35a6d412010df07b8024606b9fbbe48e60
Author: Sam Ruby <rubys@intertwingly.net>
AuthorDate: Sat Oct 8 09:16:35 2016 -0400

    add an action to convert to PDF
---
 www/secmail/views/actions/pdfize.json.rb | 22 ++++++++++++++++++++++
 www/secmail/views/parts.js.rb            | 25 +++++++++++++++++++++++++
 2 files changed, 47 insertions(+)

diff --git a/www/secmail/views/actions/pdfize.json.rb b/www/secmail/views/actions/pdfize.json.rb
new file mode 100644
index 0000000..0d9077c
--- /dev/null
+++ b/www/secmail/views/actions/pdfize.json.rb
@@ -0,0 +1,22 @@
+#
+# convert attachment to pdf
+#
+
+message = Mailbox.find(@message)
+
+begin
+  source = message.find(@selected).as_pdf
+  source.rewind
+
+  output = SafeTempFile.new('output')
+
+  name = @selected.sub(/\.\w+$/, '') + '.pdf'
+
+  message.update_attachment @selected, content: source.read, name: name,
+    mime: 'application/pdf'
+
+ensure
+  source.unlink if source
+end
+
+{attachments: message.attachments, selected: name}
diff --git a/www/secmail/views/parts.js.rb b/www/secmail/views/parts.js.rb
index 0ea3835..a23378f 100644
--- a/www/secmail/views/parts.js.rb
+++ b/www/secmail/views/parts.js.rb
@@ -70,6 +70,7 @@ class Parts < React
       _li "\u21B6 left", onMouseDown: self.rotate_attachment
       _li.divider
       _li "\u2716 delete", onMouseDown: self.delete_attachment
+      _li "\u2709 pdf-ize", onMouseDown: self.pdfize
     end
 
     if @selected and not @menu and @selected !~ /\.(asc|sig)$/
@@ -164,6 +165,7 @@ class Parts < React
               _li "\u21B6 left", onMouseDown: self.rotate_attachment
           _li.divider
           _li "\u2716 delete", onMouseDown: self.delete_attachment
+          _li "\u2709 pdf-ize", onMouseDown: self.pdfize
         end
 
       elsif @form == :mail
@@ -354,6 +356,29 @@ class Parts < React
     }
   end
 
+  # convert an attachment to pdf
+  def pdfize(event)
+    message = window.parent.location.pathname
+
+    data = {
+      selected: @menu || @selected,
+      message: message
+    }
+
+    @busy = true
+    HTTP.post('../../actions/pdfize', 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
+
   ########################################################################
   #                             Update email                             #
   ########################################################################

-- 
To stop receiving notification emails like this one, please contact
['"commits@whimsical.apache.org" <commits@whimsical.apache.org>'].

Mime
View raw message