This commit is contained in:
Karel Pičman 2020-02-21 14:27:52 +01:00
parent 052b25f99f
commit 82d9d9c5a6
8 changed files with 133 additions and 66 deletions

View File

@ -25,7 +25,7 @@ class DmsfController < ApplicationController
include RedmineDmsf::DmsfZip
before_action :find_project
before_action :authorize, :except => [:expand_folder]
before_action :authorize, :except => [:expand_folder, :exp_folder]
before_action :find_folder, :except => [:new, :create, :edit_root, :save_root, :add_email, :append_email,
:autocomplete_for_user]
before_action :find_parent, :only => [:new, :create]
@ -57,6 +57,16 @@ class DmsfController < ApplicationController
end
end
def exp_folder
@idnt = params[:idnt].present? ? params[:idnt].to_i + 1 : 0
@query = retrieve_query(DmsfQuery, true)
@query.dmsf_folder_id = @folder.id
@query.deleted = false
respond_to do |format|
format.js { render action: 'query_rows' }
end
end
def switch_rlf
rlf = params[:rlf] == 'true'
cookie_options = {

View File

@ -577,16 +577,20 @@ class DmsfFolder < ActiveRecord::Base
end
def css_classes
classes = []
classes = %w(dmsf_tree)
if type == 'folder'
classes << 'dmsf_collapsed'
classes << 'dmsf-not-loaded'
else
classes << 'dmsf_child'
end
if title =~ /^\./
classes << 'dmsf_system'
else
classes << 'hascontextmenu'
classes << 'dmsf-draggable'
if type =~ /^folder/
classes << 'dmsf-droppable'
classes << 'dmsf-draggable'
else
classes << 'dmsf-draggable'
end
if type =~ /link$/
classes << 'dmsf_gray'

View File

@ -41,59 +41,8 @@
</tr>
</thead>
<tbody>
<% level = 0 %>
<% query.dmsf_nodes.each do |node| %>
<% system = node.title =~ /^\./ %>
<tr id="node-<%= node.id %>" class="<%= cycle('odd', 'even') %> <%= node.css_classes %> <%= level > 0 ? "idnt idnt-#{level}" : nil %>">
<td class="checkbox hide-when-print">
<%= check_box_tag('ids[]', "#{node.type}-#{node.id}", false, id: nil) unless system %>
</td>
<% query.inline_columns.each do |column| %>
<%= content_tag 'td', column_content(column, node), class: column.css_classes %>
<% end %>
<td class="buttons">
<%= link_to_context_menu %>
</td>
</tr>
<% end %>
<%= render partial: 'query_rows', locals: { query: query } %>
</tbody>
</table>
</div>
<% end %>
<% unless query.deleted %>
<%= late_javascript_tag do %>
$(function() {
$(".dmsf-draggable").draggable({
axis: "y",
revert: "invalid"
});
$(".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 = {};
handle.addClass("ui-state-highlight ajax-loading")
data['dmsf_folder'] = { drag_id: dragObjectId, drop_id: dropObjectId};
$.ajax({
url: '<%= dmsf_folder_url(query.project) %>',
type: 'put',
dataType: 'script',
data: data,
error: function(jqXHR, textStatus, errorThrown){
alert(textStatus + " " + jqXHR.status);
ui.draggable.animate(ui.draggable.data("ui-draggable").originalPosition, "slow");
},
complete: function(jqXHR, textStatus, errorThrown){
handle.removeClass("ui-state-highlight ajax-loading")
if(textStatus == 'success'){
ui.draggable.remove();
}
}
});
}
});
});
<% end %>
<% end %>

View File

@ -0,0 +1,74 @@
<%
# encoding: utf-8
#
# Redmine plugin for Document Management System "Features"
#
# Copyright © 2011-20 Karel Pičman <karel.picman@kontron.com>
#
# 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.
%>
<% query.dmsf_nodes.each do |node| %>
<% system = node.title =~ /^\./ %>
<% @idnt ||= 0 %>
<tr id="<%= node.id %>span" class="<%= cycle('odd', 'even') %> <%= node.css_classes %> <%= params[:classes] %> <%= @idnt > 0 ? "idnt idnt-#{@idnt}" : nil %>">
<td class="checkbox hide-when-print">
<%= check_box_tag('ids[]', "#{node.type}-#{node.id}", false, id: nil) unless system %>
</td>
<% query.inline_columns.each do |column| %>
<%= content_tag 'td', column_content(column, node), class: column.css_classes %>
<% end %>
<td class="buttons">
<%= link_to_context_menu %>
</td>
</tr>
<% end %>
<% unless query.deleted %>
<%= late_javascript_tag do %>
$(function() {
$(".dmsf-draggable").draggable({
axis: "y",
revert: "invalid"
});
$(".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 = {};
handle.addClass("ui-state-highlight ajax-loading")
data['dmsf_folder'] = { drag_id: dragObjectId, drop_id: dropObjectId};
$.ajax({
url: '<%= dmsf_folder_url(query.project) %>',
type: 'put',
dataType: 'script',
data: data,
error: function(jqXHR, textStatus, errorThrown){
alert(textStatus + " " + jqXHR.status);
ui.draggable.animate(ui.draggable.data("ui-draggable").originalPosition, "slow");
},
complete: function(jqXHR, textStatus, errorThrown){
handle.removeClass("ui-state-highlight ajax-loading")
if(textStatus == 'success'){
ui.draggable.remove( );
}
}
});
}
});
});
<% end %>
<% end %>

View File

@ -0,0 +1,2 @@
// Add rows
$('#<%= params[:row_id] %>').after('<%= escape_javascript(render(partial: 'dmsf/query_rows', locals: { query: @query })) %>');

View File

@ -50,7 +50,10 @@ function dmsfToggle(EL, PM, url)
spanid = els[i].id;
classid = spanid;
classid = classid.match(/(\w+)span/)[1];
m = classid.match(/(\w+)span/);
if(m) {
classid = m[1];
}
classid = new RegExp(classid);
if(tmpclassid.test(els[i].className) && (tmpspanid.toString() !== PM.toString()))
@ -130,13 +133,25 @@ function dmsfExpandRows(EL, parentRow, url) {
parentRow.className = parentRow.className.replace(/dmsf-not-loaded/, '');
var idnt = 0;
var result = parentRow.className.match(/idnt-(\d+)/);
var pos = $(parentRow).find('.dmsf_position').text();
var classes = '';
var m = parentRow.className.match(/idnt-(\d+)/);
if(result){
idnt = result[1];
if(m){
idnt = m[1];
}
var pos = $(parentRow).find('.dmsf_position').text();
m = parentRow.className.match(/((\d|\s)+) idnt/);
if(m){
classes = m[1]
}
m = parentRow.id.match(/^(\d+)/);
if(m){
classes = classes + ' ' + m[1]
}
$.ajax({
url: url,
@ -146,7 +161,9 @@ function dmsfExpandRows(EL, parentRow, url) {
folder_id: EL,
row_id: parentRow.id,
idnt: idnt,
pos: pos}
pos: pos,
classes: classes
}
}).done(function(data) {
eval(data);
})

View File

@ -51,6 +51,7 @@ if Redmine::Plugin.installed? :redmine_dmsf
get '/projects/:id/dmsf/trash', :controller => 'dmsf', :action => 'trash', :as => 'trash_dmsf'
get '/projects/:id/dmsf/restore', :controller => 'dmsf', :action => 'restore', :as => 'restore_dmsf'
post '/projects/:id/dmsf/expand_folder', :controller => 'dmsf', :action => 'expand_folder', :as => 'expand_folder_dmsf'
post '/projects/:id/dmsf/exp_folder', controller: 'dmsf', action: 'exp_folder', as: 'exp_folder_dmsf'
get '/projects/:id/dmsf/add_email', :controller => 'dmsf', :action => 'add_email', :as => 'add_email_dmsf'
post '/projects/:id/dmsf/append_email', :controller => 'dmsf', :action => 'append_email', :as => 'append_email_dmsf'
get '/projects/:id/dmsf/autocomplete_for_user', :controller => 'dmsf', :action => 'autocomplete_for_user'

View File

@ -50,24 +50,34 @@ module RedmineDmsf
link_to "#{item.firstname} #{item.lastname}", user_path(id: value)
when :title
case item.type
when 'folder', 'folder-link'
when 'folder'
"<span class=\"dmsf_expander\" onclick=\"dmsfToggle('#{item.id}','#{item.id}span','#{escape_javascript(exp_folder_dmsf_path)}')\"></span>".html_safe +
link_to(h(value),
dmsf_folder_path(id: item.project_id, folder_id: item.id),
class: 'icon icon-folder',
title: h(value)) +
content_tag('div', item.filename, class: 'dmsf_filename', title: l(:title_filename_for_download))
content_tag('div', item.filename, class: 'dmsf_filename', title: l(:title_filename_for_download))
when 'folder-link'
"<span class=\"dmsf_expander\"></span>".html_safe +
link_to(h(value),
dmsf_folder_path(id: item.project_id, folder_id: item.id),
class: 'icon icon-folder',
title: h(value)) +
content_tag('div', item.filename, class: 'dmsf_filename', title: l(:title_filename_for_download))
when 'file', 'file-link'
file_view_url = url_for({ controller: :dmsf_files, action: 'view', id: item.id })
content_type = Redmine::MimeType.of(value)
content_type = 'application/octet-stream' if content_type.blank?
"<span class=\"dmsf_expander\"></span>".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}") +
content_tag('div', item.filename, class: 'dmsf_filename', title: l(:title_filename_for_download))
content_tag('div', item.filename, class: 'dmsf_filename', title: l(:title_filename_for_download))
when 'url-link'
"<span class=\"dmsf_expander\"></span>".html_safe +
link_to(h(value), item.filename, target: '_blank', class: 'icon icon-link') +
content_tag('div', item.filename, class: 'dmsf_filename', title: l(:title_filename_for_download))
else