diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4ebc8ae --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +coverage diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..89a0edb --- /dev/null +++ b/Gemfile @@ -0,0 +1,3 @@ +group :test do + gem 'simplecov', '~> 0.6' +end diff --git a/Rakefile b/Rakefile deleted file mode 100644 index ffa56e9..0000000 --- a/Rakefile +++ /dev/null @@ -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 diff --git a/app/views/attachments/_links.html.erb b/app/views/attachments/_links.html.erb index c9b6872..04cdafa 100644 --- a/app/views/attachments/_links.html.erb +++ b/app/views/attachments/_links.html.erb @@ -1,12 +1,11 @@ -
+
<% for attachment in attachments %> -

+

<%= link_to_attachment_with_preview attachment, :class => 'icon icon-attachment', :download => true -%> <%= h(" - #{attachment.description}") unless attachment.description.blank? %> (<%= number_to_human_size attachment.filesize %>) - <%= 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 %>

<% end %> - -<% if Setting.plugin_redmine_lightbox['preview_image_attachments'] %> - <% images = attachments.select { |a| a.image? } %> - <% unless images.empty? %> -
- <% 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 -%> -
+<% if defined?(thumbnails) && thumbnails %> + <% images = attachments.select(&:thumbnailable?) %> + <% if images.any? %> +
+ <% images.each do |attachment| %> +
<%= thumbnail_tag(attachment) %>
+ <% end %> +
<% end %> <% end %> -
diff --git a/app/views/settings/_lightbox_settings.html.erb b/app/views/settings/_lightbox_settings.html.erb deleted file mode 100644 index 20c63d5..0000000 --- a/app/views/settings/_lightbox_settings.html.erb +++ /dev/null @@ -1,10 +0,0 @@ -
-

<%= l(:redmine_lightbox_settings) %>

-

- - <%= check_box_tag('settings[preview_image_attachments]', - '1', - @settings['preview_image_attachments']) - %> -

-
diff --git a/assets/javascripts/jquery_loader.js b/assets/javascripts/jquery_loader.js deleted file mode 100644 index 7ed7c17..0000000 --- a/assets/javascripts/jquery_loader.js +++ /dev/null @@ -1,3 +0,0 @@ -if(typeof jQuery == 'undefined') { - document.write('') -} diff --git a/assets/stylesheets/lightbox.css b/assets/stylesheets/lightbox.css index 20c0aea..6da0bff 100644 --- a/assets/stylesheets/lightbox.css +++ b/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%; diff --git a/init.rb b/init.rb index fa46f40..60a032b 100644 --- a/init.rb +++ b/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 diff --git a/lib/redmine_lightbox/hooks/view_layouts_base_html_head_hook.rb b/lib/redmine_lightbox/hooks/view_layouts_base_html_head_hook.rb index 486ba12..92f2c12 100644 --- a/lib/redmine_lightbox/hooks/view_layouts_base_html_head_hook.rb +++ b/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') \ diff --git a/lib/redmine_lightbox/patches/issues_helper_patch.rb b/lib/redmine_lightbox/patches/issues_helper_patch.rb index 5935a17..7720106 100644 --- a/lib/redmine_lightbox/patches/issues_helper_patch.rb +++ b/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, diff --git a/test/functional/issues_controller_test.rb b/test/functional/issues_controller_test.rb index 43b30f5..4b6f5e2 100644 --- a/test/functional/issues_controller_test.rb +++ b/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 diff --git a/test/test_helper.rb b/test/test_helper.rb index 5dc041d..a2972cc 100644 --- a/test/test_helper.rb +++ b/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