From 37de665053dfcea4d16b1e79b13475af00d26c49 Mon Sep 17 00:00:00 2001 From: "karel.picman@lbcfree.net" Date: Thu, 18 Feb 2021 17:19:37 +0100 Subject: [PATCH] #1207 drag & drop, on/off --- app/controllers/dmsf_controller.rb | 29 ++++++++++++++------- app/models/dmsf_folder.rb | 2 +- app/models/dmsf_query.rb | 3 ++- app/views/dmsf/_query_rows.erb | 10 +++---- app/views/settings/_dmsf_settings.html.erb | 9 +++++++ config/locales/cs.yml | 2 ++ config/locales/de.yml | 2 ++ config/locales/en.yml | 2 ++ config/locales/es.yml | 2 ++ config/locales/fr.yml | 2 ++ config/locales/hu.yml | 2 ++ config/locales/it.yml | 2 ++ config/locales/ja.yml | 2 ++ config/locales/ko.yml | 2 ++ config/locales/nl.yml | 2 ++ config/locales/pl.yml | 2 ++ config/locales/pt-BR.yml | 2 ++ config/locales/ru.yml | 2 ++ config/locales/sl.yml | 2 ++ config/locales/zh-TW.yml | 2 ++ config/locales/zh.yml | 2 ++ init.rb | 3 ++- lib/redmine_dmsf/webdav/project_resource.rb | 2 +- 23 files changed, 72 insertions(+), 18 deletions(-) diff --git a/app/controllers/dmsf_controller.rb b/app/controllers/dmsf_controller.rb index 575de19e..9e3ca016 100644 --- a/app/controllers/dmsf_controller.rb +++ b/app/controllers/dmsf_controller.rb @@ -402,7 +402,7 @@ class DmsfController < ApplicationController if params[:dmsf_folder][:drag_id] =~ /(.+)-(\d+)/ type = $1 id = $2 - if params[:dmsf_folder][:drop_id] =~ /^folder.*-(\d+)/ + if params[:dmsf_folder][:drop_id] =~ /^(\d+)(p|f)span$/ case type when 'file' object = DmsfFile.find_by(id: id) @@ -411,14 +411,25 @@ class DmsfController < ApplicationController when 'file-link', 'folder-link', 'url-link' object = DmsfLink.find_by(id: id) end - dmsf_folder = DmsfFolder.find_by(id: $1) - if object && dmsf_folder - if dmsf_folder == object.dmsf_folder - object.errors[:base] << l(:error_target_folder_same) - elsif object.dmsf_folder&.locked_for_user? - object.errors[:base] << l(:error_folder_is_locked) - else - result = object.move_to(dmsf_folder.project, dmsf_folder) + if object + case $2 + when 'p' + project = Project.find_by(id: $1) + if project && User.current.allowed_to?(:file_manipulation, project) && + User.current.allowed_to?(:folder_manipulation, project) + result = object.move_to(project, nil) + end + when 'f' + dmsf_folder = DmsfFolder.find_by(id: $1) + if dmsf_folder + if dmsf_folder == object.dmsf_folder + object.errors[:base] << l(:error_target_folder_same) + elsif object.dmsf_folder&.locked_for_user? + object.errors[:base] << l(:error_folder_is_locked) + else + result = object.move_to(dmsf_folder.project, dmsf_folder) + end + end end end end diff --git a/app/models/dmsf_folder.rb b/app/models/dmsf_folder.rb index 6d691ab8..6e835eb5 100644 --- a/app/models/dmsf_folder.rb +++ b/app/models/dmsf_folder.rb @@ -578,7 +578,7 @@ class DmsfFolder < ActiveRecord::Base classes << 'hascontextmenu' classes << 'dmsf-draggable' end - if type =~ /^folder/ + if %(project folder).include?(type) classes << 'dmsf-droppable' end if type =~ /link$/ diff --git a/app/models/dmsf_query.rb b/app/models/dmsf_query.rb index dc55e722..309d5482 100644 --- a/app/models/dmsf_query.rb +++ b/app/models/dmsf_query.rb @@ -83,7 +83,7 @@ class DmsfQuery < Query def base_scope unless @scope @scope = [dmsf_folders_scope, dmsf_folder_links_scope, dmsf_projects_scope, dmsf_files_scope, dmsf_file_links_scope, dmsf_url_links_scope]. - inject(:union_all) + compact.inject(:union_all) end @scope end @@ -192,6 +192,7 @@ class DmsfQuery < Query private def dmsf_projects_scope + return nil unless Setting.plugin_redmine_dmsf['dmsf_projects_as_subfolders'] cf_columns = +'' if statement.present? DmsfFileRevisionCustomField.visible.order(:position).pluck(:id).each do |id| diff --git a/app/views/dmsf/_query_rows.erb b/app/views/dmsf/_query_rows.erb index 8622df65..4a384fb2 100644 --- a/app/views/dmsf/_query_rows.erb +++ b/app/views/dmsf/_query_rows.erb @@ -44,7 +44,7 @@ <%= content_tag 'td', column_content(column, node), class: column.css_classes %> <% end %> - <% unless system %> + <% unless (system || (node.type == 'project')) %> <% if defined?(EasyExtensions) %> <%= link_to '', '#', title: l(:button_actions), class: 'icon-only icon-actions js-contextmenu icon-more-horiz' %> <% else %> @@ -75,10 +75,10 @@ }); $(".dmsf-droppable" ).droppable({ drop: function(event, ui) { - var handle = $(this); - var dragObjectId = ui.draggable.find("td").find("input").val() - var dropObjectId = handle.find("td").find("input").val(); - var data = {}; + let handle = $(this); + let dragObjectId = ui.draggable.find("td").find("input").val() + let dropObjectId = handle.attr('id'); + let data = {}; handle.addClass("ui-state-highlight ajax-loading") data['dmsf_folder'] = { drag_id: dragObjectId, drop_id: dropObjectId}; $.ajax({ diff --git a/app/views/settings/_dmsf_settings.html.erb b/app/views/settings/_dmsf_settings.html.erb index 34822371..5f12c4db 100644 --- a/app/views/settings/_dmsf_settings.html.erb +++ b/app/views/settings/_dmsf_settings.html.erb @@ -150,6 +150,15 @@

+

+ <%= content_tag :label, l(:label_dmsf_projects_as_subfolders) %> + <%= check_box_tag 'settings[dmsf_projects_as_subfolders]', true, @settings['dmsf_projects_as_subfolders'] %> + + <%= l(:note_dmsf_projects_as_subfolders) %>
+ <%= l(:label_default) %>: <%= l(:general_text_Yes) %> +
+

+
<%= l(:menu_dmsf) %> <%= l(:field_column_names) %> diff --git a/config/locales/cs.yml b/config/locales/cs.yml index ec8b33dd..a22a503f 100644 --- a/config/locales/cs.yml +++ b/config/locales/cs.yml @@ -418,6 +418,8 @@ cs: dmsf_copy: "Kopie (%{n})" label_empty_trash_bin: Vysypat koš + label_dmsf_projects_as_subfolders: Podprojekty jako podaresáře + note_dmsf_projects_as_subfolders: Přidá podprojekty jako podadresáře do pohledu DMS easy_pages: modules: diff --git a/config/locales/de.yml b/config/locales/de.yml index 6127c166..b00dd375 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -417,6 +417,8 @@ de: dmsf_copy: "Kopie (%{n})" label_empty_trash_bin: Empty Trash + label_dmsf_projects_as_subfolders: Sub-projects as sub-folders + note_dmsf_projects_as_subfolders: Add sub-projects as sub-folders into DMS view easy_pages: modules: diff --git a/config/locales/en.yml b/config/locales/en.yml index bf0218e5..83b167f0 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -418,6 +418,8 @@ en: dmsf_copy: "Copy (%{n})" label_empty_trash_bin: Empty Trash + label_dmsf_projects_as_subfolders: Sub-projects as sub-folders + note_dmsf_projects_as_subfolders: Add sub-projects as sub-folders into DMS view easy_pages: modules: diff --git a/config/locales/es.yml b/config/locales/es.yml index 6e1b5904..802e70cd 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -418,6 +418,8 @@ es: dmsf_copy: "Copy (%{n})" label_empty_trash_bin: Empty Trash + label_dmsf_projects_as_subfolders: Sub-projects as sub-folders + note_dmsf_projects_as_subfolders: Add sub-projects as sub-folders into DMS view easy_pages: modules: diff --git a/config/locales/fr.yml b/config/locales/fr.yml index d270201f..493779d4 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -418,6 +418,8 @@ fr: dmsf_copy: "Copy (%{n})" label_empty_trash_bin: Empty Trash + label_dmsf_projects_as_subfolders: Sub-projects as sub-folders + note_dmsf_projects_as_subfolders: Add sub-projects as sub-folders into DMS view easy_pages: modules: diff --git a/config/locales/hu.yml b/config/locales/hu.yml index 11eedee1..11b7da57 100644 --- a/config/locales/hu.yml +++ b/config/locales/hu.yml @@ -417,6 +417,8 @@ hu: dmsf_copy: "Copy (%{n})" label_empty_trash_bin: Empty Trash + label_dmsf_projects_as_subfolders: Sub-projects as sub-folders + note_dmsf_projects_as_subfolders: Add sub-projects as sub-folders into DMS view easy_pages: modules: diff --git a/config/locales/it.yml b/config/locales/it.yml index 412ecf12..35047aec 100644 --- a/config/locales/it.yml +++ b/config/locales/it.yml @@ -418,6 +418,8 @@ it: # Italian strings thx 2 Matteo Arceci! dmsf_copy: "Copy (%{n})" label_empty_trash_bin: Empty Trash + label_dmsf_projects_as_subfolders: Sub-projects as sub-folders + note_dmsf_projects_as_subfolders: Add sub-projects as sub-folders into DMS view easy_pages: modules: diff --git a/config/locales/ja.yml b/config/locales/ja.yml index a137ceb8..c1e0c787 100644 --- a/config/locales/ja.yml +++ b/config/locales/ja.yml @@ -418,6 +418,8 @@ ja: dmsf_copy: "Copy (%{n})" label_empty_trash_bin: Empty Trash + label_dmsf_projects_as_subfolders: Sub-projects as sub-folders + note_dmsf_projects_as_subfolders: Add sub-projects as sub-folders into DMS view easy_pages: modules: diff --git a/config/locales/ko.yml b/config/locales/ko.yml index ca24790a..a545dfba 100644 --- a/config/locales/ko.yml +++ b/config/locales/ko.yml @@ -417,6 +417,8 @@ ko: dmsf_copy: "Copy (%{n})" label_empty_trash_bin: Empty Trash + label_dmsf_projects_as_subfolders: Sub-projects as sub-folders + note_dmsf_projects_as_subfolders: Add sub-projects as sub-folders into DMS view easy_pages: modules: diff --git a/config/locales/nl.yml b/config/locales/nl.yml index 454237f1..4e629d65 100644 --- a/config/locales/nl.yml +++ b/config/locales/nl.yml @@ -418,6 +418,8 @@ nl: dmsf_copy: "Copy (%{n})" label_empty_trash_bin: Empty Trash + label_dmsf_projects_as_subfolders: Sub-projects as sub-folders + note_dmsf_projects_as_subfolders: Add sub-projects as sub-folders into DMS view easy_pages: modules: diff --git a/config/locales/pl.yml b/config/locales/pl.yml index af6b2702..23860d9d 100644 --- a/config/locales/pl.yml +++ b/config/locales/pl.yml @@ -418,6 +418,8 @@ pl: dmsf_copy: "Copy (%{n})" label_empty_trash_bin: Empty Trash + label_dmsf_projects_as_subfolders: Sub-projects as sub-folders + note_dmsf_projects_as_subfolders: Add sub-projects as sub-folders into DMS view easy_pages: modules: diff --git a/config/locales/pt-BR.yml b/config/locales/pt-BR.yml index 6bce6e3d..b96942d0 100644 --- a/config/locales/pt-BR.yml +++ b/config/locales/pt-BR.yml @@ -418,6 +418,8 @@ pt-BR: dmsf_copy: "Copy (%{n})" label_empty_trash_bin: Empty Trash + label_dmsf_projects_as_subfolders: Sub-projects as sub-folders + note_dmsf_projects_as_subfolders: Add sub-projects as sub-folders into DMS view easy_pages: modules: diff --git a/config/locales/ru.yml b/config/locales/ru.yml index c6f8ddc9..1a363887 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -418,6 +418,8 @@ ru: dmsf_copy: "Copy (%{n})" label_empty_trash_bin: Empty Trash + label_dmsf_projects_as_subfolders: Sub-projects as sub-folders + note_dmsf_projects_as_subfolders: Add sub-projects as sub-folders into DMS view easy_pages: modules: diff --git a/config/locales/sl.yml b/config/locales/sl.yml index 5dfe9340..4fd0b159 100644 --- a/config/locales/sl.yml +++ b/config/locales/sl.yml @@ -418,6 +418,8 @@ sl: dmsf_copy: "Copy (%{n})" label_empty_trash_bin: Empty Trash + label_dmsf_projects_as_subfolders: Sub-projects as sub-folders + note_dmsf_projects_as_subfolders: Add sub-projects as sub-folders into DMS view easy_pages: modules: diff --git a/config/locales/zh-TW.yml b/config/locales/zh-TW.yml index f446897c..a2ca41e1 100644 --- a/config/locales/zh-TW.yml +++ b/config/locales/zh-TW.yml @@ -417,6 +417,8 @@ zh-TW: dmsf_copy: "Copy (%{n})" label_empty_trash_bin: Empty Trash + label_dmsf_projects_as_subfolders: Sub-projects as sub-folders + note_dmsf_projects_as_subfolders: Add sub-projects as sub-folders into DMS view easy_pages: modules: diff --git a/config/locales/zh.yml b/config/locales/zh.yml index 7cff2360..389595a9 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -418,6 +418,8 @@ zh: dmsf_copy: "Copy (%{n})" label_empty_trash_bin: Empty Trash + label_dmsf_projects_as_subfolders: Sub-projects as sub-folders + note_dmsf_projects_as_subfolders: Add sub-projects as sub-folders into DMS view easy_pages: modules: diff --git a/init.rb b/init.rb index 54230017..24af342f 100644 --- a/init.rb +++ b/init.rb @@ -59,7 +59,8 @@ Redmine::Plugin.register :redmine_dmsf do 'dmsf_documents_email_links_only' => nil, 'dmsf_enable_cjk_ngrams' => nil, 'dmsf_webdav_use_project_names' => Redmine::Plugin.installed?(:easy_extensions) ? '1' : nil, - 'dmsf_webdav_ignore_1b_file_for_authentication' => '1' + 'dmsf_webdav_ignore_1b_file_for_authentication' => '1', + 'dmsf_projects_as_subfolders' => Redmine::Plugin.installed?(:easy_extensions) ? '1' : nil, } end diff --git a/lib/redmine_dmsf/webdav/project_resource.rb b/lib/redmine_dmsf/webdav/project_resource.rb index e4cea810..e24da0ef 100644 --- a/lib/redmine_dmsf/webdav/project_resource.rb +++ b/lib/redmine_dmsf/webdav/project_resource.rb @@ -30,7 +30,7 @@ module RedmineDmsf @children = [] if project # Sub-projects - load_projects project.children + load_projects(project.children) if Setting.plugin_redmine_dmsf['dmsf_projects_as_subfolders'] if project.module_enabled?(:dmsf) # Folders if User.current.allowed_to?(:view_dmsf_folders, project)