Skip to content

Commit

Permalink
Added redmine 2.1 and redmine 2.2 compatibility (removed redmine-1.4 …
Browse files Browse the repository at this point in the history
…related code)
  • Loading branch information
nettsundere committed Dec 29, 2012
1 parent 7929a2b commit 1692bd4
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 85 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
coverage
3 changes: 3 additions & 0 deletions Gemfile
@@ -0,0 +1,3 @@
group :test do
gem 'simplecov', '~> 0.6'
end
12 changes: 0 additions & 12 deletions Rakefile

This file was deleted.

26 changes: 11 additions & 15 deletions app/views/attachments/_links.html.erb
@@ -1,12 +1,11 @@
<div class="attachments can_preview"> <div class="attachments">
<% for attachment in attachments %> <% for attachment in attachments %>
<p> <p><%= link_to_attachment_with_preview attachment, :class => 'icon icon-attachment', :download => true -%>
<%= h(" - #{attachment.description}") unless attachment.description.blank? %> <%= h(" - #{attachment.description}") unless attachment.description.blank? %>
<span class="size">(<%= number_to_human_size attachment.filesize %>)</span> <span class="size">(<%= number_to_human_size attachment.filesize %>)</span>
<%= link_to_attachment_with_preview(attachment, :class => 'icon icon-attachment') %>
<% if options[:deletable] %> <% if options[:deletable] %>
<%= link_to image_tag('delete.png'), attachment_path(attachment), <%= link_to image_tag('delete.png'), attachment_path(attachment),
:confirm => l(:text_are_you_sure), :data => {:confirm => l(:text_are_you_sure)},
:method => :delete, :method => :delete,
:class => 'delete', :class => 'delete',
:title => l(:button_delete) %> :title => l(:button_delete) %>
Expand All @@ -16,18 +15,15 @@
<% end %> <% end %>
</p> </p>
<% end %> <% end %>
<% if defined?(thumbnails) && thumbnails %>
<% if Setting.plugin_redmine_lightbox['preview_image_attachments'] %> <% images = attachments.select(&:thumbnailable?) %>
<% images = attachments.select { |a| a.image? } %> <% if images.any? %>
<% unless images.empty? %> <div class="thumbnails">
<div class='images'> <% images.each do |attachment| %>
<% images.each do |attachment| %> <div><%= thumbnail_tag(attachment) %></div>
<%= link_to image_tag(url_for({:controller => 'attachments', :action => 'show', :id => attachment, :filename => attachment.filename }), :class => 'image_attachment_preview'), <% end %>
{:controller => 'attachments', :action => 'show', :id => attachment, :filename => attachment.filename }, :class => 'lightbox', :rel => 'attachments', :title => "#{attachment.filename}#{ ('-' + attachment.description) unless attachment.description.blank? }" %> </div>
<% end -%>
</div>
<% end %> <% end %>
<% end %> <% end %>

</div> </div>


10 changes: 0 additions & 10 deletions app/views/settings/_lightbox_settings.html.erb

This file was deleted.

3 changes: 0 additions & 3 deletions assets/javascripts/jquery_loader.js

This file was deleted.

14 changes: 0 additions & 14 deletions assets/stylesheets/lightbox.css
@@ -1,11 +1,3 @@
div.attachments div.images
{
border: 1px solid #CCCCCC;
padding: 10px;
margin: 10px;
display: inline-block;
}

div.attachments .image_attachment_preview { div.attachments .image_attachment_preview {
width: auto !important; width: auto !important;
width: 180px; width: 180px;
Expand All @@ -18,12 +10,6 @@ div.attachments div.images a.lightbox
margin: 0px 5px; margin: 0px 5px;
} }


div.attachments img.preview_button, .journal img.preview_button
{
margin: 0 4px;
width: 18px;
}

embed.chrome { embed.chrome {
box-sizing: border-box; box-sizing: border-box;
width: 100%; width: 100%;
Expand Down
6 changes: 0 additions & 6 deletions init.rb
Expand Up @@ -13,10 +13,4 @@
version '0.0.1' version '0.0.1'
url 'https://github.com/zipme/redmine_lightbox' url 'https://github.com/zipme/redmine_lightbox'
author_url 'https://github.com/zipme/redmine_lightbox' author_url 'https://github.com/zipme/redmine_lightbox'

default_settings = {
'preview_image_attachments' => true
}

settings(:default => default_settings, :partial => 'settings/lightbox_settings')
end end
Expand Up @@ -8,16 +8,8 @@ def view_layouts_base_html_head(context={})
context[:controller].is_a?(FilesController) || context[:controller].is_a?(FilesController) ||
context[:controller].is_a?(BoardsController)) context[:controller].is_a?(BoardsController))


if Redmine::VERSION.to_s.slice(0, 3) < "2.1"
jquery_include = javascript_include_tag('jquery_loader.js', :plugin => 'redmine_lightbox') \
+ javascript_tag("jQuery.noConflict()")
else
jquery_include = ""
end

return stylesheet_link_tag("jquery.fancybox-1.3.4.css", :plugin => "redmine_lightbox", :media => "screen") \ return stylesheet_link_tag("jquery.fancybox-1.3.4.css", :plugin => "redmine_lightbox", :media => "screen") \
+ stylesheet_link_tag("lightbox.css", :plugin => "redmine_lightbox", :media => "screen") \ + stylesheet_link_tag("lightbox.css", :plugin => "redmine_lightbox", :media => "screen") \
+ jquery_include \
+ javascript_include_tag('jquery.fancybox-1.3.4.pack.js', :plugin => 'redmine_lightbox') \ + javascript_include_tag('jquery.fancybox-1.3.4.pack.js', :plugin => 'redmine_lightbox') \
+ javascript_include_tag('jquery.easing-1.3.pack.js', :plugin => 'redmine_lightbox') \ + javascript_include_tag('jquery.easing-1.3.pack.js', :plugin => 'redmine_lightbox') \
+ javascript_include_tag('lightbox.js', :plugin => 'redmine_lightbox') \ + javascript_include_tag('lightbox.js', :plugin => 'redmine_lightbox') \
Expand Down
42 changes: 30 additions & 12 deletions lib/redmine_lightbox/patches/issues_helper_patch.rb
Expand Up @@ -3,28 +3,46 @@
module RedmineLightbox module RedmineLightbox
module Patches module Patches
module IssuesHelperPatch module IssuesHelperPatch

def link_to_attachment_with_preview(attachment, options = {}) def link_to_attachment_with_preview(attachment, options = {})
preview_icon = absolute_url(image_path('preview.png', :plugin => :redmine_lightbox)) preview_icon = absolute_asset_url('images/preview.png')
preview_button = image_tag(preview_icon, :class => "preview_button") icon_style = "width: 18px; margin: 0px 4px"

preview_button = image_tag(preview_icon, :style => icon_style)
download_link = link_to_attachment_without_preview(attachment, :only_path => false)


if attachment.image? && Setting.plugin_redmine_lightbox['preview_image_attachments'] unless preview_available?(attachment)
download_link return link_to_attachment_without_preview(attachment, options)
else
"#{download_link} #{preview_link_with(attachment, preview_button)}"
end end

download_link = link_to_attachment_without_preview(attachment, :only_path => false)
raw("#{download_link} #{preview_link_with(attachment, preview_button)}")
end end


def show_detail_with_only_path_disabled(detail, no_html = false, options={}) def show_detail_with_only_path_disabled(detail, no_html = false, options={})
show_detail_without_only_path_disabled(detail, no_html, options.merge(:only_path => false)) show_detail_without_only_path_disabled(detail, no_html, options.merge(:only_path => false))
end end


private private
def absolute_asset_url(asset_url, plugin_asset = true)
if plugin_asset
paths = [
'plugin_assets',
'redmine_lightbox',
asset_url
]
relative_url = File.join(*paths)
else
relative_url = asset_url
end

"#{home_url}#{relative_url}"
end

def preview_available?(attachment)
image = attachment.image?
pdf_or_swf = attachment.filename =~ /.(pdf|swf)$/i
attachment_preview = attachment.attachment_preview
text = attachment.is_text?


def absolute_url(relative_url) image || text || pdf_or_swf || attachment_preview
"#{home_url}#{relative_url[1..-1]}"
end end


def preview_link_with(attachment, preview_button) def preview_link_with(attachment, preview_button)
Expand All @@ -47,7 +65,7 @@ def preview_link_with(attachment, preview_button)
end end


if attachment.is_text? if attachment.is_text?
link_to(image_tag(absolute_url(image_path('magnifier.png'))), link_to(image_tag(absolute_asset_url('images/magnifier.png', false)),
:controller => 'attachments', :controller => 'attachments',
:action => 'show', :action => 'show',
:id => attachment, :id => attachment,
Expand Down
10 changes: 7 additions & 3 deletions test/functional/issues_controller_test.rb
@@ -1,20 +1,24 @@
require File.dirname(__FILE__) + '/../test_helper' require File.dirname(__FILE__) + '/../test_helper'


class IssuesControllerTest < ActionController::TestCase class IssuesControllerTest < ActionController::TestCase
fixtures :issues, :attachments, :users fixtures :issues, :projects, :attachments, :users, :issue_statuses,
:enumerations, :trackers


def setup def setup
set_fixtures_attachments_directory set_fixtures_attachments_directory


@some_file = Attachment.find_by_filename("source.rb") @some_file = Attachment.find_by_filename("source.rb")


@some_file.create_attachment_preview(:file_type => "pdf") @some_file.create_attachment_preview(:file_type => "pdf")

@request.session[:user_id] = 2
User.stubs(:current).returns(User.find_by_id(2))
User.any_instance.stubs(:allowed_to?).returns(true)
end end


def test_should_show_issue_with_attachments_and_previews def test_should_show_issue_with_attachments_and_previews

@issue_with_file_id = @some_file.container_id @issue_with_file_id = @some_file.container_id

get :show, :id => @issue_with_file_id get :show, :id => @issue_with_file_id
assert_response :success assert_response :success
end end
Expand Down
16 changes: 14 additions & 2 deletions test/test_helper.rb
@@ -1,7 +1,19 @@
# Load the normal Rails helper # Load the normal Rails helper
helper_path = File.expand_path(File.dirname(__FILE__) + '/../../../test/test_helper') helper_path = File.expand_path(File.dirname(__FILE__) + '/../../../test/test_helper')
if !File.exists?(helper_path)
helper_path = File.expand_path(File.dirname(__FILE__) + '/../../../../test/test_helper') plugin_root = File.expand_path(File.dirname(__FILE__) + '/../')

if RUBY_VERSION >= "1.9"
require 'simplecov'
SimpleCov.start do
base_dir = plugin_root
root base_dir
add_group "Models", "app/models"
add_group "Controllers", "app/controllers"
add_group "Helpers", "app/helpers"
add_group "Views", "app/views"
add_group "Lib", "lib"
end
end end


require helper_path require helper_path

0 comments on commit 1692bd4

Please sign in to comment.