Documents' preview

This commit is contained in:
Karel Pičman 2023-06-05 14:18:18 +02:00
parent 9ce4fc481c
commit 2a2ef8ba60
6 changed files with 15 additions and 6 deletions

View File

@ -1,19 +1,21 @@
Changelog for Redmine DMSF Changelog for Redmine DMSF
========================== ==========================
3.0.13 ????-??-?? 3.0.13 *????-??-??*
------------------ ------------------
An option to disable the original module Documents in the plugin's settings An option to disable the original module Documents in the plugin's settings
Documents preview available if the binary is available but not explicitly defined in the plugin's settings
Rubocop tests of the plugin's source codes
3.0.12 2023-03-15 3.0.12 *2023-03-15*
------------------ ------------------
Bug fixing Bug fixing
* Bug: #1436 - Cannot upload new content * Bug: #1436 - Cannot upload new content
3.0.11 2023-03-14 3.0.11 *2023-03-14*
------------------ ------------------
Bug fixing Bug fixing

View File

@ -37,6 +37,7 @@ class DmsfContextMenusController < ApplicationController
@unlockable = @allowed && @dmsf_file.unlockable? && (!@dmsf_file.locked_for_user? || @unlockable = @allowed && @dmsf_file.unlockable? && (!@dmsf_file.locked_for_user? ||
User.current.allowed_to?(:force_file_unlock, @project)) User.current.allowed_to?(:force_file_unlock, @project))
@email_allowed = User.current.allowed_to?(:email_documents, @project) @email_allowed = User.current.allowed_to?(:email_documents, @project)
@preview = RedmineDmsf::Preview.office_available? && Setting.plugin_redmine_dmsf['office_bin'].blank?
elsif @dmsf_folder elsif @dmsf_folder
@locked = @dmsf_folder.locked? @locked = @dmsf_folder.locked?
@project = @dmsf_folder.project @project = @dmsf_folder.project

View File

@ -77,7 +77,7 @@ class DmsfFilesController < ApplicationController
expires_in 0.years, 'must-revalidate' => true expires_in 0.years, 'must-revalidate' => true
pdf_preview = (params[:disposition] != 'attachment') && params[:filename].blank? && @file.pdf_preview pdf_preview = (params[:disposition] != 'attachment') && params[:filename].blank? && @file.pdf_preview
filename = filename_for_content_disposition(@revision.formatted_name(member)) filename = filename_for_content_disposition(@revision.formatted_name(member))
if pdf_preview.present? if pdf_preview.present? && (Setting.plugin_redmine_dmsf['office_bin'].present? || params[:preview].present?)
basename = File.basename(filename, '.*') basename = File.basename(filename, '.*')
send_file pdf_preview, filename: "#{basename}.pdf", type: 'application/pdf', disposition: 'inline' send_file pdf_preview, filename: "#{basename}.pdf", type: 'application/pdf', disposition: 'inline'
else else

View File

@ -87,6 +87,12 @@
<li> <li>
<%= render partial: 'dmsf_context_menus/watch', locals: { object: dmsf_file } %> <%= render partial: 'dmsf_context_menus/watch', locals: { object: dmsf_file } %>
</li> </li>
<% if @preview %>
<li>
<%= context_menu_link l(:label_preview), view_dmsf_file_path(dmsf_file, preview: true),
class: 'icon icon-magnifier', disabled: false %>
</li>
<% end %>
<li> <li>
<%= context_menu_link l(:button_delete), <%= context_menu_link l(:button_delete),
dmsf_link ? dmsf_link_path(id: dmsf_link, folder_id: folder, back_url: back_url) : dmsf_file_path(id: dmsf_file, dmsf_link ? dmsf_link_path(id: dmsf_link, folder_id: folder, back_url: back_url) : dmsf_file_path(id: dmsf_file,

View File

@ -23,7 +23,7 @@
<%= render partial: 'file', locals: { project: @project, folder: @folder, dmsf_file: @dmsf_file, <%= render partial: 'file', locals: { project: @project, folder: @folder, dmsf_file: @dmsf_file,
dmsf_link: @dmsf_link, locked: @locked, unlockable: @unlockable, dmsf_link: @dmsf_link, locked: @locked, unlockable: @unlockable,
allowed: @allowed, email_allowed: @email_allowed, allowed: @allowed, email_allowed: @email_allowed,
notifications: @notifications, back_url: @back_url } %> notifications: @notifications, preview: @preview, back_url: @back_url } %>
<% elsif @dmsf_folder %> <% elsif @dmsf_folder %>
<%= render partial: 'folder', locals: { project: @project, folder: @folder, dmsf_folder: @dmsf_folder, <%= render partial: 'folder', locals: { project: @project, folder: @folder, dmsf_folder: @dmsf_folder,
dmsf_link: @dmsf_link, locked: @locked, unlockable: @unlockable, dmsf_link: @dmsf_link, locked: @locked, unlockable: @unlockable,

View File

@ -27,7 +27,7 @@ module RedmineDmsf
extend Redmine::Utils::Shell extend Redmine::Utils::Shell
include Redmine::I18n include Redmine::I18n
OFFICE_BIN = (Setting.plugin_redmine_dmsf['office_bin'] || 'libreoffice').freeze OFFICE_BIN = (Setting.plugin_redmine_dmsf['office_bin'].presence || 'libreoffice').freeze
def self.office_available? def self.office_available?
return @office_available if defined?(@office_available) return @office_available if defined?(@office_available)