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

</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 {
width: auto !important;
width: 180px;
Expand All @@ -18,12 +10,6 @@ div.attachments div.images a.lightbox
margin: 0px 5px;
}

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

embed.chrome {
box-sizing: border-box;
width: 100%;
Expand Down
6 changes: 0 additions & 6 deletions init.rb
Expand Up @@ -13,10 +13,4 @@
version '0.0.1'
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
Expand Up @@ -8,16 +8,8 @@ def view_layouts_base_html_head(context={})
context[:controller].is_a?(FilesController) ||
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") \
+ 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.easing-1.3.pack.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 Patches
module IssuesHelperPatch

def link_to_attachment_with_preview(attachment, options = {})
preview_icon = absolute_url(image_path('preview.png', :plugin => :redmine_lightbox))
preview_button = image_tag(preview_icon, :class => "preview_button")

download_link = link_to_attachment_without_preview(attachment, :only_path => false)
preview_icon = absolute_asset_url('images/preview.png')
icon_style = "width: 18px; margin: 0px 4px"
preview_button = image_tag(preview_icon, :style => icon_style)

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

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

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))
end

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)
"#{home_url}#{relative_url[1..-1]}"
image || text || pdf_or_swf || attachment_preview
end

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

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',
:action => 'show',
: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'

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

def setup
set_fixtures_attachments_directory

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

@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

def test_should_show_issue_with_attachments_and_previews

@issue_with_file_id = @some_file.container_id

get :show, :id => @issue_with_file_id
assert_response :success
end
Expand Down
16 changes: 14 additions & 2 deletions test/test_helper.rb
@@ -1,7 +1,19 @@
# Load the normal Rails 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

require helper_path

0 comments on commit 1692bd4

Please sign in to comment.