Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added redmine 2.1 and redmine 2.2 compatibility (removed redmine-1.4 …

…related code)
  • Loading branch information...
commit 1692bd443d410796b0f4ebeb7a001201492c965e 1 parent 7929a2b
@nettsundere nettsundere authored
View
1  .gitignore
@@ -0,0 +1 @@
+coverage
View
3  Gemfile
@@ -0,0 +1,3 @@
+group :test do
+ gem 'simplecov', '~> 0.6'
+end
View
12 Rakefile
@@ -1,12 +0,0 @@
-require 'rake'
-require 'rake/testtask'
-
-desc "Default: run unit tests."
-task :default => :test
-
-desc "Test the redmine_tagging plugin."
-Rake::TestTask.new(:test) do |t|
- t.libs << 'lib'
- t.pattern = 'test/**/*_test.rb'
- t.verbose = true
-end
View
26 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) %>
@@ -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>
View
10 app/views/settings/_lightbox_settings.html.erb
@@ -1,10 +0,0 @@
-<fieldset>
- <p><%= l(:redmine_lightbox_settings) %></p>
- <p>
- <label><%= l(:preview_image_attachments)%></label>
- <%= check_box_tag('settings[preview_image_attachments]',
- '1',
- @settings['preview_image_attachments'])
- %>
- </p>
-</fieldset>
View
3  assets/javascripts/jquery_loader.js
@@ -1,3 +0,0 @@
-if(typeof jQuery == 'undefined') {
- document.write('<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>')
-}
View
14 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;
@@ -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%;
View
6 init.rb
@@ -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
View
8 lib/redmine_lightbox/hooks/view_layouts_base_html_head_hook.rb
@@ -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') \
View
42 lib/redmine_lightbox/patches/issues_helper_patch.rb
@@ -3,18 +3,17 @@
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={})
@@ -22,9 +21,28 @@ def show_detail_with_only_path_disabled(detail, no_html = false, options={})
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)
@@ -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,
View
10 test/functional/issues_controller_test.rb
@@ -1,7 +1,8 @@
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
@@ -9,12 +10,15 @@ def setup
@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
View
16 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
Please sign in to comment.
Something went wrong with that request. Please try again.