From e20a8876b610fac1696fb56bf293233d69d52edf Mon Sep 17 00:00:00 2001 From: "karel.picman@lbcfree.net" Date: Tue, 16 Jun 2020 10:19:25 +0200 Subject: [PATCH] CSV export fix --- app/controllers/dmsf_controller.rb | 7 +- app/helpers/dmsf_queries_helper.rb | 155 ++++++++++++++++ app/views/dmsf/show.html.erb | 4 +- lib/redmine_dmsf.rb | 1 - .../patches/queries_helper_patch.rb | 168 ------------------ 5 files changed, 161 insertions(+), 174 deletions(-) create mode 100644 app/helpers/dmsf_queries_helper.rb delete mode 100644 lib/redmine_dmsf/patches/queries_helper_patch.rb diff --git a/app/controllers/dmsf_controller.rb b/app/controllers/dmsf_controller.rb index b34c18b2..5347b144 100644 --- a/app/controllers/dmsf_controller.rb +++ b/app/controllers/dmsf_controller.rb @@ -40,6 +40,8 @@ class DmsfController < ApplicationController helper :dmsf_folder_permissions helper :queries include QueriesHelper + helper :dmsf_queries + include DmsfQueriesHelper def permissions render_403 unless DmsfFolder.permissions?(@folder, false) @@ -626,11 +628,10 @@ class DmsfController < ApplicationController end def get_query - use_session = !request.format.csv? if Redmine::Plugin.installed?(:easy_extensions) - @query = retrieve_query_without_easy_extensions(DmsfQuery, use_session) + @query = retrieve_query_without_easy_extensions(DmsfQuery, true) else - @query = retrieve_query(DmsfQuery, use_session) + @query = retrieve_query(DmsfQuery, true) end end diff --git a/app/helpers/dmsf_queries_helper.rb b/app/helpers/dmsf_queries_helper.rb new file mode 100644 index 00000000..46f2c869 --- /dev/null +++ b/app/helpers/dmsf_queries_helper.rb @@ -0,0 +1,155 @@ +# encoding: utf-8 +# frozen_string_literal: true +# +# Redmine plugin for Document Management System "Features" +# +# Copyright © 2011 Vít Jonáš +# Copyright © 2012 Daniel Munn +# Copyright © 2011-20 Karel Pičman +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +module DmsfQueriesHelper + include ApplicationHelper + + def column_value(column, item, value) + unless item.is_a? DmsfFolder + return super column, item, value + end + case column.name + when :id + case item.type + when 'file', 'file-link' + if item.deleted && (item.deleted > 0) + super column, item, value + else + link_to h(value), dmsf_file_path(id: item.id) + end + when 'folder', 'folder-link' + if item.id + if item.deleted && (item.deleted > 0) + super column, item, value + else + link_to h(value), edit_dmsf_path(id: item.project_id, folder_id: item.id) + end + else + if item.deleted && (item.deleted > 0) + super column, item, item.project_id + else + link_to h(item.project_id), edit_root_dmsf_path(id: item.project_id) + end + end + else + h(value) + end + when :author + if value + link_to "#{item.firstname} #{item.lastname}", user_path(id: value) + else + return super column, item, value + end + when :title + if defined?(EasyExtensions) + # In case of font icons there is no space + value = ' '.html_safe + value + end + case item.type + when 'folder' + if item.deleted && (item.deleted > 0) + tag = content_tag('span', value, class: 'icon icon-folder') + else + tag = "".html_safe + + link_to(h(value), + dmsf_folder_path(id: item.project, folder_id: item.id), + class: 'icon icon-folder', + title: h(value)) + end + tag + content_tag('div', item.filename, class: 'dmsf-filename', title: l(:title_filename_for_download)) + when 'folder-link' + if item.deleted && (item.deleted > 0) + tag = content_tag('span', value, class: 'icon icon-folder') + else + tag = "".html_safe + + # For links we use revision_id containing dmsf_folder.id in fact + link_to(h(value), + dmsf_folder_path(id: item.project, folder_id: item.revision_id), + class: 'icon icon-folder', + title: h(value)) + end + tag + content_tag('div', item.filename, class: 'dmsf-filename', title: l(:label_target_folder)) + when 'file', 'file-link' + if item.deleted && (item.deleted > 0) + tag = content_tag('span', value, class: "icon icon-file #{DmsfHelper.filetype_css(item.filename)}") + else + # For links we use revision_id containing dmsf_file.id in fact + file_view_url = url_for({ controller: :dmsf_files, action: 'view', id: (item.type == 'file') ? item.id : item.revision_id }) + content_type = Redmine::MimeType.of(value) + content_type = 'application/octet-stream' if content_type.blank? + tag = "".html_safe + + link_to(h(value), + file_view_url, + target: '_blank', + class: "icon icon-file #{DmsfHelper.filetype_css(item.filename)}", + title: h(value), + 'data-downloadurl': "#{content_type}:#{h(value)}:#{file_view_url}") + end + tag + content_tag('div', item.filename, class: 'dmsf-filename', title: l(:title_filename_for_download)) + when 'url-link' + if item.deleted && (item.deleted > 0) + tag = content_tag('span', value, class: 'icon icon-link') + else + tag = "".html_safe + + link_to(h(value), item.filename, target: '_blank', class: 'icon icon-link') + end + tag + content_tag('div', item.filename, class: 'dmsf-filename', title: l(:field_url)) + else + h(value) + end + when :size + number_to_human_size value + when :workflow + if value + if item.workflow_id && (!(item.deleted && (item.deleted > 0))) + if item.type == 'file' + url = log_dmsf_workflow_path(project_id: item.project_id, id: item.workflow_id, dmsf_file_id: item.id) + else + url = log_dmsf_workflow_path(project_id: item.project_id, id: item.workflow_id, dmsf_link_id: item.id) + end + link_to h(DmsfWorkflow.workflow_str(value.to_i)), url, remote: true + else + h(DmsfWorkflow.workflow_str(value.to_i)) + end + else + super column, item, value + end + else + super column, item, value + end + end + + def csv_value(column, object, value) + case column.name + when :size + ActiveSupport::NumberHelper.number_to_human_size value + when :workflow + DmsfWorkflow.workflow_str value.to_i + when :author + "#{object.firstname} #{object.lastname}" + else + super column, object, value + end + end + +end diff --git a/app/views/dmsf/show.html.erb b/app/views/dmsf/show.html.erb index 38bbef29..bf6ec323 100644 --- a/app/views/dmsf/show.html.erb +++ b/app/views/dmsf/show.html.erb @@ -71,7 +71,7 @@ -<%= form_tag(dmsf_folder_path(d: @project, folder_id: @folder), method: :get, id: 'query_form', class: 'dmsf-query-form') do %> +<%= form_tag(dmsf_folder_path(id: @project, folder_id: @folder), method: :get, id: 'query_form', class: 'dmsf-query-form') do %> <%= render partial: 'queries/query_form' %> <% end %> <%= render partial: 'query_list', locals: { query: @query, dmsf_pages: @dmsf_pages } %> @@ -81,7 +81,7 @@ <% unless @folder && @folder.system %> <% other_formats_links do |f| %> - <%= f.link_to 'CSV', url: { action: :show, id: @project, dmsf_folder_id: @folder } %> + <%= f.link_to 'CSV', url: { action: :show, id: @project, folder_id: @folder } %> <% end %> <% end %> diff --git a/lib/redmine_dmsf.rb b/lib/redmine_dmsf.rb index 9f2010b4..d0fac574 100644 --- a/lib/redmine_dmsf.rb +++ b/lib/redmine_dmsf.rb @@ -32,7 +32,6 @@ require_dependency File.dirname(__FILE__) + '/../app/validators/dmsf_url_validat # Plugin's patches require 'redmine_dmsf/patches/projects_helper_patch' -require 'redmine_dmsf/patches/queries_helper_patch' require 'redmine_dmsf/patches/project_patch' require 'redmine_dmsf/patches/user_preference_patch' require 'redmine_dmsf/patches/user_patch' diff --git a/lib/redmine_dmsf/patches/queries_helper_patch.rb b/lib/redmine_dmsf/patches/queries_helper_patch.rb deleted file mode 100644 index 2027e31b..00000000 --- a/lib/redmine_dmsf/patches/queries_helper_patch.rb +++ /dev/null @@ -1,168 +0,0 @@ -# encoding: utf-8 -# frozen_string_literal: true -# -# Redmine plugin for Document Management System "Features" -# -# Copyright © 2011 Vít Jonáš -# Copyright © 2012 Daniel Munn -# Copyright © 2011-20 Karel Pičman -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - -module RedmineDmsf - module Patches - module QueriesHelperPatch - - ################################################################################################################## - # Overridden methods - - def column_value(column, item, value) - unless item.is_a? DmsfFolder - return super column, item, value - end - case column.name - when :id - case item.type - when 'file', 'file-link' - if item.deleted && (item.deleted > 0) - super column, item, value - else - link_to h(value), dmsf_file_path(id: item.id) - end - when 'folder', 'folder-link' - if item.id - if item.deleted && (item.deleted > 0) - super column, item, value - else - link_to h(value), edit_dmsf_path(id: item.project_id, folder_id: item.id) - end - else - if item.deleted && (item.deleted > 0) - super column, item, item.project_id - else - link_to h(item.project_id), edit_root_dmsf_path(id: item.project_id) - end - end - else - h(value) - end - when :author - if value - link_to "#{item.firstname} #{item.lastname}", user_path(id: value) - else - return super column, item, value - end - when :title - if defined?(EasyExtensions) - # In case of font icons there is no space - value = ' '.html_safe + value - end - case item.type - when 'folder' - if item.deleted && (item.deleted > 0) - tag = content_tag('span', value, class: 'icon icon-folder') - else - tag = "".html_safe + - link_to(h(value), - dmsf_folder_path(id: item.project, folder_id: item.id), - class: 'icon icon-folder', - title: h(value)) - end - tag + content_tag('div', item.filename, class: 'dmsf-filename', title: l(:title_filename_for_download)) - when 'folder-link' - if item.deleted && (item.deleted > 0) - tag = content_tag('span', value, class: 'icon icon-folder') - else - tag = "".html_safe + - # For links we use revision_id containing dmsf_folder.id in fact - link_to(h(value), - dmsf_folder_path(id: item.project, folder_id: item.revision_id), - class: 'icon icon-folder', - title: h(value)) - end - tag + content_tag('div', item.filename, class: 'dmsf-filename', title: l(:label_target_folder)) - when 'file', 'file-link' - if item.deleted && (item.deleted > 0) - tag = content_tag('span', value, class: "icon icon-file #{DmsfHelper.filetype_css(item.filename)}") - else - # For links we use revision_id containing dmsf_file.id in fact - file_view_url = url_for({ controller: :dmsf_files, action: 'view', id: (item.type == 'file') ? item.id : item.revision_id }) - content_type = Redmine::MimeType.of(value) - content_type = 'application/octet-stream' if content_type.blank? - tag = "".html_safe + - link_to(h(value), - file_view_url, - target: '_blank', - class: "icon icon-file #{DmsfHelper.filetype_css(item.filename)}", - title: h(value), - 'data-downloadurl': "#{content_type}:#{h(value)}:#{file_view_url}") - end - tag + content_tag('div', item.filename, class: 'dmsf-filename', title: l(:title_filename_for_download)) - when 'url-link' - if item.deleted && (item.deleted > 0) - tag = content_tag('span', value, class: 'icon icon-link') - else - tag = "".html_safe + - link_to(h(value), item.filename, target: '_blank', class: 'icon icon-link') - end - tag + content_tag('div', item.filename, class: 'dmsf-filename', title: l(:field_url)) - else - h(value) - end - when :size - number_to_human_size value - when :workflow - if value - if item.workflow_id && (!(item.deleted && (item.deleted > 0))) - if item.type == 'file' - url = log_dmsf_workflow_path(project_id: item.project_id, id: item.workflow_id, dmsf_file_id: item.id) - else - url = log_dmsf_workflow_path(project_id: item.project_id, id: item.workflow_id, dmsf_link_id: item.id) - end - link_to(h(DmsfWorkflow.workflow_str(value.to_i)), url, remote: true) - else - h(DmsfWorkflow.workflow_str(value.to_i)) - end - else - super column, item, value - end - else - super column, item, value - end - end - - def csv_value(column, object, value) - case column.name - when :size - ActiveSupport::NumberHelper.number_to_human_size value - when :workflow - DmsfWorkflow.workflow_str(value.to_i) - when :author - "#{object.firstname} #{object.lastname}" - else - super column, object, value - end - end - - end - end -end - -if Redmine::Plugin.installed?(:easy_extensions) - RedmineExtensions::PatchManager.register_helper_patch 'QueriesHelper', - 'RedmineDmsf::Patches::QueriesHelperPatch', prepend: true -else - DmsfController.send :helper, RedmineDmsf::Patches::QueriesHelperPatch -end \ No newline at end of file