From 2a2ef8ba60765986cb0d186891e71eee9a49c214 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Pi=C4=8Dman?= Date: Mon, 5 Jun 2023 14:18:18 +0200 Subject: [PATCH] Documents' preview --- CHANGELOG.md | 8 +++++--- app/controllers/dmsf_context_menus_controller.rb | 1 + app/controllers/dmsf_files_controller.rb | 2 +- app/views/dmsf_context_menus/_file.html.erb | 6 ++++++ app/views/dmsf_context_menus/dmsf.html.erb | 2 +- lib/redmine_dmsf/preview.rb | 2 +- 6 files changed, 15 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 601dab51..b59a1118 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,19 +1,21 @@ Changelog for Redmine DMSF ========================== -3.0.13 ????-??-?? +3.0.13 *????-??-??* ------------------ 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: #1436 - Cannot upload new content -3.0.11 2023-03-14 +3.0.11 *2023-03-14* ------------------ Bug fixing diff --git a/app/controllers/dmsf_context_menus_controller.rb b/app/controllers/dmsf_context_menus_controller.rb index 00f93122..8e4489ab 100644 --- a/app/controllers/dmsf_context_menus_controller.rb +++ b/app/controllers/dmsf_context_menus_controller.rb @@ -37,6 +37,7 @@ class DmsfContextMenusController < ApplicationController @unlockable = @allowed && @dmsf_file.unlockable? && (!@dmsf_file.locked_for_user? || User.current.allowed_to?(:force_file_unlock, @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 @locked = @dmsf_folder.locked? @project = @dmsf_folder.project diff --git a/app/controllers/dmsf_files_controller.rb b/app/controllers/dmsf_files_controller.rb index 30235d3a..057c264b 100644 --- a/app/controllers/dmsf_files_controller.rb +++ b/app/controllers/dmsf_files_controller.rb @@ -77,7 +77,7 @@ class DmsfFilesController < ApplicationController expires_in 0.years, 'must-revalidate' => true pdf_preview = (params[:disposition] != 'attachment') && params[:filename].blank? && @file.pdf_preview 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, '.*') send_file pdf_preview, filename: "#{basename}.pdf", type: 'application/pdf', disposition: 'inline' else diff --git a/app/views/dmsf_context_menus/_file.html.erb b/app/views/dmsf_context_menus/_file.html.erb index dc853294..3f995ead 100644 --- a/app/views/dmsf_context_menus/_file.html.erb +++ b/app/views/dmsf_context_menus/_file.html.erb @@ -87,6 +87,12 @@
  • <%= render partial: 'dmsf_context_menus/watch', locals: { object: dmsf_file } %>
  • +<% if @preview %> +
  • + <%= context_menu_link l(:label_preview), view_dmsf_file_path(dmsf_file, preview: true), + class: 'icon icon-magnifier', disabled: false %> +
  • +<% end %>
  • <%= 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, diff --git a/app/views/dmsf_context_menus/dmsf.html.erb b/app/views/dmsf_context_menus/dmsf.html.erb index 118c5abc..6d640082 100644 --- a/app/views/dmsf_context_menus/dmsf.html.erb +++ b/app/views/dmsf_context_menus/dmsf.html.erb @@ -23,7 +23,7 @@ <%= render partial: 'file', locals: { project: @project, folder: @folder, dmsf_file: @dmsf_file, dmsf_link: @dmsf_link, locked: @locked, unlockable: @unlockable, allowed: @allowed, email_allowed: @email_allowed, - notifications: @notifications, back_url: @back_url } %> + notifications: @notifications, preview: @preview, back_url: @back_url } %> <% elsif @dmsf_folder %> <%= render partial: 'folder', locals: { project: @project, folder: @folder, dmsf_folder: @dmsf_folder, dmsf_link: @dmsf_link, locked: @locked, unlockable: @unlockable, diff --git a/lib/redmine_dmsf/preview.rb b/lib/redmine_dmsf/preview.rb index eea6438e..6bb8c6f5 100644 --- a/lib/redmine_dmsf/preview.rb +++ b/lib/redmine_dmsf/preview.rb @@ -27,7 +27,7 @@ module RedmineDmsf extend Redmine::Utils::Shell 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? return @office_available if defined?(@office_available)