From 73193baa685102d2c61edab90de1a1ec1418a2b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Pi=C4=8Dman?= Date: Mon, 4 Sep 2023 14:48:07 +0200 Subject: [PATCH] Make DMS document available as Type of a custom field #1248 --- config/locales/cs.yml | 1 + config/locales/de.yml | 1 + config/locales/en.yml | 1 + config/locales/es.yml | 1 + config/locales/fa.yml | 1 + config/locales/fr.yml | 1 + config/locales/hu.yml | 1 + config/locales/it.yml | 1 + config/locales/ja.yml | 1 + config/locales/ko.yml | 1 + config/locales/nl.yml | 3 +- config/locales/pt-BR.yml | 1 + config/locales/sl.yml | 1 + config/locales/ua.yml | 1 + config/locales/zh-TW.yml | 1 + config/locales/zh.yml | 1 + lib/redmine_dmsf.rb | 3 + .../field_formats/dmsf_file_format.rb | 64 +++++++++++++++++++ .../custom_field_dmsf_file_format_test.rb | 40 ++++++++++++ 19 files changed, 124 insertions(+), 1 deletion(-) create mode 100644 lib/redmine_dmsf/field_formats/dmsf_file_format.rb create mode 100644 test/unit/custom_field_dmsf_file_format_test.rb diff --git a/config/locales/cs.yml b/config/locales/cs.yml index c7a2f8a6..62d9a856 100644 --- a/config/locales/cs.yml +++ b/config/locales/cs.yml @@ -21,6 +21,7 @@ cs: dmsf: DMS # Custom fields tab title + label_dmsf_file: DMS Dokument label_dmsf_file_plural: DMS Dokumenty # Email subject & Search options label_dmsf_file_revision_plural: Revize dokumentů label_dmsf_file_revision_access_plural: Přístupy k dokumentům diff --git a/config/locales/de.yml b/config/locales/de.yml index 4609a30e..800eb7a6 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -21,6 +21,7 @@ de: dmsf: DMS # Custom fields tab title + label_dmsf_file: DMS Dokument label_dmsf_file_plural: DMS Dokumente # E-Mail subject & Search options label_dmsf_file_revision_plural: Dokumentenversion label_dmsf_file_revision_access_plural: Dokumentenzugriffe diff --git a/config/locales/en.yml b/config/locales/en.yml index 64b9e419..76e1c78c 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -21,6 +21,7 @@ en: dmsf: DMS # Custom fields tab title + label_dmsf_file: DMS Document label_dmsf_file_plural: DMS Documents # Email subject & Search options label_dmsf_file_revision_plural: Document revisions label_dmsf_file_revision_access_plural: Document accesses diff --git a/config/locales/es.yml b/config/locales/es.yml index f2e47bcc..b43723d7 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -21,6 +21,7 @@ es: dmsf: DMS # Custom fields tab title + label_dmsf_file: DMS Archivo label_dmsf_file_plural: DMS Archivos # Email subject & Search options label_dmsf_file_revision_plural: Document revisions label_dmsf_file_revision_access_plural: Document accesses diff --git a/config/locales/fa.yml b/config/locales/fa.yml index 7e50f0d4..12a79fe4 100644 --- a/config/locales/fa.yml +++ b/config/locales/fa.yml @@ -21,6 +21,7 @@ fa: dmsf: اسناد پیش‌رفته # Custom fields tab title + label_dmsf_file: DMS Document label_dmsf_file_plural: اسناد پیش‌رفته # Email subject & Search options label_dmsf_file_revision_plural: بازبینی‌های اسناد label_dmsf_file_revision_access_plural: دسترسی‌های اسناد پیش‌رفته diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 87b0d177..1f1ef030 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -21,6 +21,7 @@ fr: dmsf: DMS # Custom fields tab title + label_dmsf_file: DMS Fichier label_dmsf_file_plural: DMS Fichiers # Email subject & Search options label_dmsf_file_revision_plural: Révisions du document label_dmsf_file_revision_access_plural: Accès au document diff --git a/config/locales/hu.yml b/config/locales/hu.yml index e3885a20..5f0c1052 100644 --- a/config/locales/hu.yml +++ b/config/locales/hu.yml @@ -21,6 +21,7 @@ hu: dmsf: DMS # Custom fields tab title + label_dmsf_file: DMS Dokumtum label_dmsf_file_plural: DMS Dokumentumok # Email subject & Search options label_dmsf_file_revision_plural: Dokumtum felülvizsgálata label_dmsf_file_revision_access_plural: Dokumentum hozzáférései diff --git a/config/locales/it.yml b/config/locales/it.yml index 116fcd07..49a054da 100644 --- a/config/locales/it.yml +++ b/config/locales/it.yml @@ -21,6 +21,7 @@ it: # Italian strings thx 2 Matteo Arceci! dmsf: DMS # Custom fields tab title + label_dmsf_file: DMS Documento label_dmsf_file_plural: DMS Documenti # Email subject & Search options label_dmsf_file_revision_plural: Revisioni al documento label_dmsf_file_revision_access_plural: Accessi al documento diff --git a/config/locales/ja.yml b/config/locales/ja.yml index fcd4eeac..334f3a93 100644 --- a/config/locales/ja.yml +++ b/config/locales/ja.yml @@ -21,6 +21,7 @@ ja: dmsf: DMS # Custom fields tab title + label_dmsf_file: DMS Document label_dmsf_file_plural: DMS 文書管理ファイル # Email subject & Search options label_dmsf_file_revision_plural: 文書管理ファイルリビジョン label_dmsf_file_revision_access_plural: 文書管理ファイルアクセス diff --git a/config/locales/ko.yml b/config/locales/ko.yml index c5bce6eb..2e6b95f5 100644 --- a/config/locales/ko.yml +++ b/config/locales/ko.yml @@ -21,6 +21,7 @@ ko: dmsf: DMS + label_dmsf_file: DMS Document label_dmsf_file_plural: DMS 문서 label_dmsf_file_revision_plural: 문서 리비전 label_dmsf_file_revision_access_plural: 문서 접근 diff --git a/config/locales/nl.yml b/config/locales/nl.yml index 4ea563ad..79bdb7dc 100644 --- a/config/locales/nl.yml +++ b/config/locales/nl.yml @@ -20,7 +20,8 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. nl: - dmsf: Easy DMS + dmsf: DMS + label_dmsf_file: DMS Document label_dmsf_file_plural: Documenten label_dmsf_file_revision_plural: Document revisies label_dmsf_file_revision_access_plural: Document toegang diff --git a/config/locales/pt-BR.yml b/config/locales/pt-BR.yml index 0447a798..8cc922f1 100644 --- a/config/locales/pt-BR.yml +++ b/config/locales/pt-BR.yml @@ -21,6 +21,7 @@ pt-BR: dmsf: DMS # Custom fields tab title + label_dmsf_file: DMS Arquivo label_dmsf_file_plural: DMS Arquivos # Email subject & Search options label_dmsf_file_revision_plural: Revisões dos Arquivos label_dmsf_file_revision_access_plural: Acessos aos Arquivos diff --git a/config/locales/sl.yml b/config/locales/sl.yml index de4e4b24..9f7baf7e 100644 --- a/config/locales/sl.yml +++ b/config/locales/sl.yml @@ -21,6 +21,7 @@ sl: dmsf: Arhiv # Custom fields tab title + label_dmsf_file: DMS Datoteka label_dmsf_file_plural: DMS Arhivske datoteke # Email subject & Search options label_dmsf_file_revision_plural: Document revisions label_dmsf_file_revision_access_plural: Document accesses diff --git a/config/locales/ua.yml b/config/locales/ua.yml index 63329bb3..cfad3284 100644 --- a/config/locales/ua.yml +++ b/config/locales/ua.yml @@ -21,6 +21,7 @@ uk: dmsf: ЕДО # Custom fields tab title - Заголовок таблиці спеціальних полів + label_dmsf_file: ЕДО Документ label_dmsf_file_plural: ЕДО Документи # Email subject & Search options - Документи DMS # Тема електронного листа і опції пошуку label_dmsf_file_revision_plural: Перегляд / Редакція документа label_dmsf_file_revision_access_plural: Доступ до документів diff --git a/config/locales/zh-TW.yml b/config/locales/zh-TW.yml index 52a0edc9..d7b67cfd 100644 --- a/config/locales/zh-TW.yml +++ b/config/locales/zh-TW.yml @@ -21,6 +21,7 @@ zh-TW: dmsf: 文件總管 # Custom fields tab title + label_dmsf_file: DMS Document label_dmsf_file_plural: DMS 文件檔案 # Email subject & Search options label_dmsf_file_revision_plural: Document revisions label_dmsf_file_revision_access_plural: Document accesses diff --git a/config/locales/zh.yml b/config/locales/zh.yml index 93cfff52..aad5a3a5 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -21,6 +21,7 @@ zh: dmsf: 文档管家 # Custom fields tab title + label_dmsf_file: DMS Document label_dmsf_file_plural: DMS 文件檔案 # Email subject & Search options label_dmsf_file_revision_plural: Document revisions label_dmsf_file_revision_access_plural: Document accesses diff --git a/lib/redmine_dmsf.rb b/lib/redmine_dmsf.rb index 975cbfc7..6ab277a3 100644 --- a/lib/redmine_dmsf.rb +++ b/lib/redmine_dmsf.rb @@ -93,3 +93,6 @@ require "#{File.dirname(__FILE__)}/redmine_dmsf/hooks/helpers/project_helper_hoo # Macros require "#{File.dirname(__FILE__)}/redmine_dmsf/macros" + +# Field formats +require "#{File.dirname(__FILE__)}/redmine_dmsf/field_formats/dmsf_file_format" diff --git a/lib/redmine_dmsf/field_formats/dmsf_file_format.rb b/lib/redmine_dmsf/field_formats/dmsf_file_format.rb new file mode 100644 index 00000000..97db4854 --- /dev/null +++ b/lib/redmine_dmsf/field_formats/dmsf_file_format.rb @@ -0,0 +1,64 @@ +# frozen_string_literal: true + +# Redmine plugin for Document Management System "Features" +# +# Copyright © 2011 Vít Jonáš +# Copyright © 2011-23 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 FieldFormats + # Custom field type DmsfFile + class DmsfFileFormat < Redmine::FieldFormat::RecordList + add 'dmsf_file' + + self.customized_class_names = nil + self.multiple_supported = false + self.bulk_edit_supported = false + + def possible_values_options(_custom_field, object = nil) + options = [] + if object&.project + files = object.project.dmsf_files.visible.to_a + object.project.dmsf_folders.visible.each do |f| + files += f.dmsf_files.visible.to_a + end + files.sort! { |a, b| a.title.casecmp(b.title) } + options = files.map { |f| [f.name, f.id.to_s] } + end + options + end + + def formatted_value(view, _custom_field, value, _customized: nil, _html: false) + return '' if value.blank? + + dmsf_file = DmsfFile.find_by(id: value) + return '' unless dmsf_file + + file_view_url = view.url_for({ controller: :dmsf_files, action: 'view', id: dmsf_file }) + view.link_to( + h(dmsf_file.title), + file_view_url, + target: '_blank', + rel: 'noopener', + class: "icon icon-file #{DmsfHelper.filetype_css(dmsf_file.name)}", + title: h(dmsf_file.last_revision.try(:tooltip)), + 'data-downloadurl' => "#{dmsf_file.last_revision.detect_content_type}:#{h(dmsf_file.name)}:#{file_view_url}" + ) + end + end + end +end diff --git a/test/unit/custom_field_dmsf_file_format_test.rb b/test/unit/custom_field_dmsf_file_format_test.rb new file mode 100644 index 00000000..8b5e9616 --- /dev/null +++ b/test/unit/custom_field_dmsf_file_format_test.rb @@ -0,0 +1,40 @@ +# frozen_string_literal: true + +# Redmine plugin for Document Management System "Features" +# +# Copyright © 2011-23 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. + +require File.expand_path('../../test_helper', __FILE__) + +# File revision tests +class CustomFieldDmsfFileFormatTest < RedmineDmsf::Test::UnitTest + fixtures :custom_fields, :projects, :issues, :trackers + def setup + super + User.current = nil + @issue = Issue.find 1 + @field = IssueCustomField.create!(name: 'DMS Document', field_format: 'dmsf_file') + end + + def test_possible_values_options + n = @issue.project.dmsf_files.visible.all.size + @issue.project.dmsf_folders.visible.each do |f| + n += f.dmsf_files.visible.all.size + end + assert_equal n, @field.possible_values_options(@issue).size + end +end