ChiliProject is not maintained anymore. Please be advised that there will be no more updates.

We do not recommend that you setup new ChiliProject instances and we urge all existing users to migrate their data to a maintained system, e.g. Redmine. We will provide a migration script later. In the meantime, you can use the instructions by Christian Daehn.

init.rb

init.rb file fron ScreenshotPaste plugin - Paweł O, 2011-12-11 09:05 pm

Download (1.5 kB)

 
1
require 'redmine'
2
require 'base64'
3
require 'dispatcher'
4
5
Redmine::Plugin.register :redmine_screenshot_paste do
6
  name 'Screenshot Paste'
7
  author 'Jean-Philippe Lang'
8
  description 'Allow pasting a screenshot from the clipboard on the issue form.'
9
  version '1.0.2'
10
end
11
12
class UploadedScreenshot
13
  def initialize(content, name)
14
    @raw = StringIO.new(Base64.decode64(content))
15
    @name = name.to_s.strip
16
    @name = "screenshot" if @name.blank?
17
    @name << ".png"
18
  end
19
  
20
  def size
21
    @raw.size
22
  end
23
  
24
  def original_filename
25
    @name
26
  end
27
  
28
  def content_type
29
    "image/png"
30
  end
31
  
32
  def read(*args)
33
    @raw.read(*args)
34
  end
35
end
36
37
module RedmineScreenshotPaste
38
  def self.included(base)
39
    base.send(:include, InstanceMethods)
40
    base.send(:alias_method_chain, :attach_files, :screenshot)
41
  end
42
43
  module InstanceMethods
44
    def attach_files_with_screenshot(obj, attachments)
45
      if screenshot = params[:uploaded_screenshot]
46
        file = UploadedScreenshot.new(screenshot['content'], screenshot['name'])
47
        attachments[:screenshot] = {:file => file,
48
                                    :description => screenshot['description']}
49
      end
50
      attach_files_without_screenshot(obj, attachments)
51
    end
52
  end
53
end
54
55
56
class RedmineScreenshotPasteHook < Redmine::Hook::ViewListener
57
  render_on :view_issues_form_details_bottom, :partial => 'screenshot'
58
end
59
60
Dispatcher.to_prepare :redmine_screenshot_paste do
61
  ApplicationController.send :include, RedmineScreenshotPaste
62
end