From e2d67406db463f179d81ff890fb44fd45d71f559 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Pi=C4=8Dman?= Date: Wed, 25 May 2022 16:02:57 +0200 Subject: [PATCH] Filename in the download link --- app/controllers/dmsf_files_controller.rb | 3 ++- app/views/dmsf_context_menus/_file.html.erb | 6 ++++-- app/views/dmsf_context_menus/_revision_actions.html.erb | 8 ++++---- app/views/dmsf_context_menus/_revisions.html.erb | 5 ++++- config/routes.rb | 1 + 5 files changed, 15 insertions(+), 8 deletions(-) diff --git a/app/controllers/dmsf_files_controller.rb b/app/controllers/dmsf_files_controller.rb index b2ea82fd..a5d0bf0e 100644 --- a/app/controllers/dmsf_files_controller.rb +++ b/app/controllers/dmsf_files_controller.rb @@ -69,12 +69,13 @@ class DmsfFilesController < ApplicationController member = Member.find_by(user_id: User.current.id, project_id: @file.project.id) # IE has got a tendency to cache files expires_in 0.year, 'must-revalidate' => true - pdf_preview = @file.pdf_preview + pdf_preview = (params[:disposition] != 'attachment') && params[:filename].blank? && @file.pdf_preview filename = filename_for_content_disposition(@revision.formatted_name(member)) if pdf_preview.present? basename = File.basename(filename, '.*') send_file pdf_preview, filename: "#{basename}.pdf", type: 'application/pdf', disposition: 'inline' else + params[:disposition] = 'attachment' if params[:filename].present? send_file @revision.disk_file, filename: filename, type: @revision.detect_content_type, disposition: params[:disposition].present? ? params[:disposition] : @revision.dmsf_file.disposition end diff --git a/app/views/dmsf_context_menus/_file.html.erb b/app/views/dmsf_context_menus/_file.html.erb index 46e55a86..00f3f3f9 100644 --- a/app/views/dmsf_context_menus/_file.html.erb +++ b/app/views/dmsf_context_menus/_file.html.erb @@ -62,8 +62,10 @@ back_url: back_url } %>
  • -<%= context_menu_link l(:button_download), view_dmsf_file_path(dmsf_file, disposition: 'attachment'), - class: 'icon icon-download', disabled: false %> + <% member = Member.find_by(user_id: User.current.id, project_id: dmsf_file.project.id) %> + <% filename = dmsf_file.last_revision&.formatted_name(member) %> + <%= context_menu_link l(:button_download), static_dmsf_file_path(dmsf_file, filename: filename), + class: 'icon icon-download', disabled: false %>
  • <%= context_menu_link l(:field_mail), entries_operations_dmsf_path(id: project, folder_id: folder, diff --git a/app/views/dmsf_context_menus/_revision_actions.html.erb b/app/views/dmsf_context_menus/_revision_actions.html.erb index 9fdb63b6..8830cd86 100644 --- a/app/views/dmsf_context_menus/_revision_actions.html.erb +++ b/app/views/dmsf_context_menus/_revision_actions.html.erb @@ -23,10 +23,10 @@ <%= link_to_function l(:title_download_entries), "$('#revision_access_#{revision.id}').toggle(); $('.drdn.expanded').removeClass('expanded');", class: 'icon icon-group dmsf-revision-action-button' %> -<%= link_to l(:title_download), - view_dmsf_file_path(file, download: revision, disposition: 'attachment'), - title: l(:title_title_version_version_download, title: h(revision.title), version: revision.version), - class: 'icon icon-download dmsf-revision-action-button' %> +<% member = Member.find_by(user_id: User.current.id, project_id: revision.dmsf_file.project.id) %> +<% filename = revision.formatted_name(member) %> +<%= link_to l(:button_download), static_dmsf_file_path(file, download: revision, filename: filename), + class: 'icon icon-download', disabled: false %> <%= link_to l(:title_obsolete_revision), obsolete_revision_path(revision), data: { confirm: l(:text_are_you_sure) }, diff --git a/app/views/dmsf_context_menus/_revisions.html.erb b/app/views/dmsf_context_menus/_revisions.html.erb index e14043d4..3e1e2299 100644 --- a/app/views/dmsf_context_menus/_revisions.html.erb +++ b/app/views/dmsf_context_menus/_revisions.html.erb @@ -40,7 +40,10 @@ class: 'icon dmsf-icon-link' %> <%= link_to "#{l(:button_copy)}/#{l(:button_move)}", copy_file_path(id: file, back_url: back_url), title: l(:title_copy), class: 'icon icon-copy' %> -<%= link_to l(:button_download), view_dmsf_file_path(file, disposition: 'attachment'), class: 'icon icon-download' %> +<% member = Member.find_by(user_id: User.current.id, project_id: file.project.id) %> +<% filename = file.last_revision&.formatted_name(member) %> +<%= link_to l(:button_download), static_dmsf_file_path(file, filename: filename), class: 'icon icon-download', + disabled: false %> <%= render partial: 'dmsf_context_menus/watch', locals: { object: file } %> <%= delete_link(dmsf_file_path(id: file, details: true), back_url: dmsf_folder_path(id: file.project, folder_id: file.dmsf_folder)) if file_delete_allowed %> diff --git a/config/routes.rb b/config/routes.rb index 27609966..82f11548 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -96,6 +96,7 @@ if Redmine::Plugin.installed? :redmine_dmsf get '/dmsf/files/:id/revision/obsolete', controller: 'dmsf_files', action: 'obsolete_revision', as: 'obsolete_revision' get '/dmsf/files/:id/download', to: 'dmsf_files#view', download: '', as: 'download_dmsf_file' # Otherwise will not route nil into the download param get '/dmsf/files/:id/view', to: 'dmsf_files#view', as: 'view_dmsf_file' + get '/dmsf/files/:id/:filename', to: 'dmsf_files#view', :id => /\d+/, :filename => /.*/, as: 'static_dmsf_file' get '/dmsf/files/:id', controller: 'dmsf_files', action: 'show', as: 'dmsf_file' delete '/dmsf/files/:id', controller: 'dmsf_files', action: 'delete' get '/dmsf/files/:id/restore', controller: 'dmsf_files', action: 'restore', as: 'restore_dmsf_file'