forked from paginagmbh/redmine_lightbox2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixed preview and preview_online methods in AttachmentsController; so…
…me refactoring (added ActiveSupport::Concern)
- Loading branch information
1 parent
54a4446
commit 2a0394d
Showing
6 changed files
with
180 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,18 @@ | ||
require 'redmine' | ||
|
||
require_dependency 'redmine_lightbox/hooks/view_layouts_base_html_head_hook' | ||
require_dependency 'redmine_lightbox/services/document_converter' | ||
require_dependency 'redmine_lightbox/patches/attachment_patch' | ||
require_dependency 'redmine_lightbox/patches/attachments_controller_patch' | ||
require_dependency 'redmine_lightbox/patches/issues_helper_patch' | ||
require 'redmine_lightbox/hooks/view_layouts_base_html_head_hook' | ||
require 'redmine_lightbox/services/document_converter' | ||
require 'redmine_lightbox/patches/attachment_patch' | ||
require 'redmine_lightbox/patches/attachments_controller_patch' | ||
require 'redmine_lightbox/patches/application_helper_patch' | ||
require 'redmine_lightbox/patches/issues_helper_patch' | ||
require 'redmine_lightbox/patches/wiki_helper_patch' | ||
|
||
Redmine::Plugin.register :redmine_lightbox do | ||
name 'Redmine Light Box plugin' | ||
author 'G.K.' | ||
author 'G.K., Undev.ru' | ||
description 'Lightbox for attachments' | ||
version '0.0.1' | ||
url 'https://github.com/zipme/redmine_lightbox' | ||
author_url 'https://github.com/zipme/redmine_lightbox' | ||
version '0.0.2' | ||
url 'https://github.com/Undev/redmine_lightbox' | ||
author_url 'https://github.com/Undev/redmine_lightbox' | ||
end |
102 changes: 102 additions & 0 deletions
102
lib/redmine_lightbox/patches/application_helper_patch.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
require_dependency 'application_helper' | ||
|
||
module RedmineLightbox | ||
module Patches | ||
module ApplicationHelperPatch | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
alias_method_chain :link_to_attachment, :preview | ||
end | ||
|
||
def link_to_attachment_with_preview(attachment, options = {}) | ||
preview_icon = absolute_asset_url('images/preview.png') | ||
icon_style = "width: 18px; margin: 0px 4px" | ||
preview_button = image_tag(preview_icon, :style => icon_style) | ||
|
||
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 thumbnail_with_preview_tag(attachment) | ||
preview_link_with(attachment, | ||
image_tag(url_for(:controller => 'attachments', :action => 'thumbnail', :id => attachment))) | ||
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? | ||
|
||
image || text || pdf_or_swf || attachment_preview | ||
end | ||
|
||
def preview_link_with(attachment, preview_button) | ||
if attachment.attachment_preview | ||
link_class = "attachment_preview" | ||
attachment_action = "preview" | ||
else | ||
if attachment.filename =~ /.(pdf|swf)$/i | ||
link_class = $1 | ||
else | ||
link_class = "image" | ||
end | ||
attachment_action = ($1 === 'swf' || attachment.image?) ? 'download_inline' : 'show' | ||
end | ||
|
||
if attachment.description.present? | ||
attachment_title = "#{attachment.filename}#{ ('-' + attachment.description)}" | ||
else | ||
attachment_title = attachment.filename | ||
end | ||
|
||
if attachment.is_text? | ||
link_to(image_tag(absolute_asset_url('images/magnifier.png', false)), | ||
:controller => 'attachments', | ||
:action => 'show', | ||
:id => attachment, | ||
:filename => attachment.filename, | ||
:only_path => false) | ||
else | ||
link_to(preview_button, { | ||
:controller => 'attachments', | ||
:action => attachment_action, | ||
:id => attachment, | ||
:filename => attachment.filename, | ||
:only_path => false }, | ||
:class => link_class, | ||
:rel => 'attachments', | ||
:title => attachment_title | ||
) | ||
end | ||
end | ||
|
||
end | ||
end | ||
end | ||
|
||
unless ApplicationHelper.included_modules.include?(RedmineLightbox::Patches::ApplicationHelperPatch) | ||
ApplicationHelper.send(:include, RedmineLightbox::Patches::ApplicationHelperPatch) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
require_dependency 'application_helper' | ||
require_dependency 'wiki_helper' | ||
|
||
unless WikiHelper.included_modules.include?(ApplicationHelper) | ||
WikiHelper.send(:include, ApplicationHelper) | ||
end |