You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@whimsical.apache.org by Sam Ruby <ru...@apache.org> on 2015/12/24 11:55:13 UTC

[whimsy.git] [1/1] Commit 9b2e2ab: rotate actions

Commit 9b2e2aba921516f3cf3a05d45365977f51ce4fbf:
    rotate actions


Branch: refs/heads/secmail
Author: Sam Ruby <ru...@intertwingly.net>
Committer: Sam Ruby <ru...@intertwingly.net>
Pusher: rubys <ru...@apache.org>

------------------------------------------------------------
www/secmail/public/secmail.css                               | ++++++++ 
www/secmail/views/actions/rotate-attachment.json.rb          | ++++++++ 
www/secmail/views/index.js.rb                                | + -
www/secmail/views/parts.js.rb                                | +++++++++++ -
------------------------------------------------------------
89 changes: 84 additions, 5 deletions.
------------------------------------------------------------


diff --git a/www/secmail/public/secmail.css b/www/secmail/public/secmail.css
index 2102965..01d302e 100644
--- a/www/secmail/public/secmail.css
+++ b/www/secmail/public/secmail.css
@@ -69,6 +69,14 @@ ul.contextMenu {
   padding-left: 28px;
 }
 
+.divider {
+  height: 2px;
+  width:100%;
+  margin: 9px 0;
+  padding: 0 4px;
+  background-color: #ccc;
+  }
+
 .spinner {
   position: absolute;
   z-index: -1;
diff --git a/www/secmail/views/actions/rotate-attachment.json.rb b/www/secmail/views/actions/rotate-attachment.json.rb
new file mode 100644
index 0000000..3e0244e
--- /dev/null
+++ b/www/secmail/views/actions/rotate-attachment.json.rb
@@ -0,0 +1,32 @@
+#
+# drop part of drag and drop
+#
+
+month, hash = @message.match(%r{/(\d+)/(\w+)}).captures
+
+mbox = Mailbox.new(month)
+message = mbox.find(hash)
+
+begin
+  selected = message.find(@selected).as_pdf
+
+  direction = 'Right' if @direction.include? 'right'
+  direction = 'Left' if @direction.include? 'left'
+  direction = 'Down' if @direction.include? 'flip'
+
+  output = Tempfile.new('output')
+
+  Kernel.system 'pdftk', selected.path, 'cat', "1-end#{direction}", 'output',
+    output.path
+
+  name = @selected.sub(/\.\w+$/, '') + '.pdf'
+
+  message.update_attachment @selected, content: output.read, name: name,
+    mime: 'application/pdf'
+
+ensure
+  selected.unlink if selected
+  output.unlink if output
+end
+
+{attachments: message.attachments, selected: name}
diff --git a/www/secmail/views/index.js.rb b/www/secmail/views/index.js.rb
index ae469a4..3756e5d 100644
--- a/www/secmail/views/index.js.rb
+++ b/www/secmail/views/index.js.rb
@@ -168,7 +168,7 @@ def keydown(event)
       window.location.href = selected.href if selected
 
     elsif event.keyCode == 8 or event.keyCode == 46 # backspace or delete
-      if event.metaKey
+      if event.metaKey or event.ctrlKey
         event.preventDefault()
 
         # mark item as delete pending
diff --git a/www/secmail/views/parts.js.rb b/www/secmail/views/parts.js.rb
index 110c2b8..51438c9 100644
--- a/www/secmail/views/parts.js.rb
+++ b/www/secmail/views/parts.js.rb
@@ -35,8 +35,13 @@ def render
     end
 
     _ul.contextMenu do
-      _li 'burst', onMouseDown: self.burst
-      _li 'delete', onMouseDown: self.delete_attachment
+      _li "\u2704 burst", onMouseDown: self.burst
+      _li.divider
+      _li "\u21B7 right", onMouseDown: self.rotate_attachment
+      _li "\u21c5 flip", onMouseDown: self.rotate_attachment
+      _li "\u21B6 left", onMouseDown: self.rotate_attachment
+      _li.divider
+      _li "\u2716 delete", onMouseDown: self.delete_attachment
     end
 
     _img.spinner src: '../../rotatingclock-slow2.gif' if @busy
@@ -64,10 +69,23 @@ def componentDidMount()
   def menu(event)
     @selected = event.currentTarget.textContent
     menu = document.querySelector('.contextMenu')
-    menu.style.left = event.clientX + 'px'
-    menu.style.top = event.clientY + 'px'
     menu.style.position = :absolute
     menu.style.display = :block
+
+    bodyRect = document.body.getBoundingClientRect()
+    menuRect = menu.getBoundingClientRect()
+    position = {x: event.clientX, y: event.clientY}
+
+    if position.x + menuRect.width > bodyRect.width
+      position.x -= menuRect.width if position.x >= menuRect.width
+    end
+
+    if position.y + menuRect.height > bodyRect.height
+      position.y -= menuRect.height if position.y >= menuRect.height
+    end
+
+    menu.style.left = position.x + 'px'
+    menu.style.top = position.y + 'px'
     event.preventDefault()
   end
 
@@ -135,6 +153,27 @@ def delete_attachment(event)
     end
   end
 
+  # rotate an attachment
+  def rotate_attachment(event)
+    message = window.parent.location.pathname
+
+    data = {
+      selected: @selected,
+      message: message,
+      direction: event.currentTarget.textContent
+    }
+
+    @busy = true
+    HTTP.post '../../actions/rotate-attachment', data do |response|
+      @attachments = response.attachments
+      @selected = response.selected
+      @busy = false
+
+      # reload attachment in content pane
+      window.parent.frames.content.location.href = response.selected
+    end
+  end
+
   #
   # drag/drop support.  Note: support varies by browser (in particular,
   # when events are called and whether or not a particular event has