#1207 basic functionality
This commit is contained in:
parent
33860cea4d
commit
6065f9baad
@ -51,7 +51,10 @@ class DmsfController < ApplicationController
|
||||
|
||||
def expand_folder
|
||||
@idnt = params[:idnt].present? ? params[:idnt].to_i + 1 : 0
|
||||
@query.dmsf_folder_id = @folder.id
|
||||
if params[:project_id].present?
|
||||
@query.project = Project.find_by(id: params[:project_id])
|
||||
end
|
||||
@query.dmsf_folder_id = @folder&.id
|
||||
@query.deleted = false
|
||||
respond_to do |format|
|
||||
format.js { render action: 'query_rows' }
|
||||
|
||||
@ -85,13 +85,19 @@ module DmsfQueriesHelper
|
||||
end
|
||||
when :title
|
||||
case item.type
|
||||
when 'project'
|
||||
tag = link_to(h("[#{value}]"), dmsf_folder_path(id: item.project), class: 'icon icon-folder')
|
||||
unless filter_any?
|
||||
tag = "<span class=\"dmsf_expander\" onclick=\"dmsfToggle(this, '#{item.id}', null,'#{escape_javascript(expand_folder_dmsf_path)}')\"></span>".html_safe + tag
|
||||
end
|
||||
tag + content_tag('div', item.filename, class: 'dmsf-filename', title: l(:title_filename_for_download))
|
||||
when 'folder'
|
||||
if item&.deleted > 0
|
||||
tag = content_tag('span', value, class: 'icon icon-folder')
|
||||
else
|
||||
tag = link_to(h(value), dmsf_folder_path(id: item.project, folder_id: item.id), class: 'icon icon-folder')
|
||||
unless filter_any?
|
||||
tag = "<span class=\"dmsf_expander\" onclick=\"dmsfToggle(this, '#{item.id}','#{escape_javascript(expand_folder_dmsf_path)}')\"></span>".html_safe + tag
|
||||
tag = "<span class=\"dmsf_expander\" onclick=\"dmsfToggle(this, null, '#{item.id}','#{escape_javascript(expand_folder_dmsf_path)}')\"></span>".html_safe + tag
|
||||
end
|
||||
end
|
||||
tag + content_tag('div', item.filename, class: 'dmsf-filename', title: l(:title_filename_for_download))
|
||||
|
||||
@ -565,7 +565,7 @@ class DmsfFolder < ActiveRecord::Base
|
||||
end
|
||||
else
|
||||
classes << 'dmsf-tree'
|
||||
if type == 'folder'
|
||||
if %(folder project).include?(type)
|
||||
classes << 'dmsf-collapsed'
|
||||
classes << 'dmsf-not-loaded'
|
||||
else
|
||||
@ -574,8 +574,10 @@ class DmsfFolder < ActiveRecord::Base
|
||||
if title =~ /^\./
|
||||
classes << 'dmsf-system'
|
||||
else
|
||||
classes << 'hascontextmenu'
|
||||
classes << 'dmsf-draggable'
|
||||
if (type != 'project')
|
||||
classes << 'hascontextmenu'
|
||||
classes << 'dmsf-draggable'
|
||||
end
|
||||
if type =~ /^folder/
|
||||
classes << 'dmsf-droppable'
|
||||
end
|
||||
|
||||
@ -82,7 +82,7 @@ class DmsfQuery < Query
|
||||
|
||||
def base_scope
|
||||
unless @scope
|
||||
@scope = [dmsf_folders_scope, dmsf_folder_links_scope, dmsf_files_scope, dmsf_file_links_scope, dmsf_url_links_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)
|
||||
end
|
||||
@scope
|
||||
@ -171,11 +171,15 @@ class DmsfQuery < Query
|
||||
limit(options[:limit]).
|
||||
offset(options[:offset]).to_a
|
||||
items.each do |item|
|
||||
if item.type == 'folder'
|
||||
case item.type
|
||||
when 'folder'
|
||||
dmsf_folder = DmsfFolder.find_by(id: item.id)
|
||||
if dmsf_folder && (!DmsfFolder.permissions?(dmsf_folder, false))
|
||||
items.delete item
|
||||
end
|
||||
when 'project'
|
||||
p = Project.find_by(id: item.id)
|
||||
items.delete(item) unless p&.dmsf_available?
|
||||
end
|
||||
end
|
||||
items
|
||||
@ -187,6 +191,40 @@ class DmsfQuery < Query
|
||||
|
||||
private
|
||||
|
||||
def dmsf_projects_scope
|
||||
cf_columns = +''
|
||||
if statement.present?
|
||||
DmsfFileRevisionCustomField.visible.order(:position).pluck(:id).each do |id|
|
||||
cf_columns << ",NULL AS cf_#{id}"
|
||||
end
|
||||
end
|
||||
scope = Project.
|
||||
select(%{
|
||||
projects.id AS id,
|
||||
projects.id AS project_id,
|
||||
CAST(NULL AS #{ActiveRecord::Base.connection.type_to_sql(:decimal)}) AS revision_id,
|
||||
projects.name AS title,
|
||||
projects.identifier AS filename,
|
||||
CAST(NULL AS #{ActiveRecord::Base.connection.type_to_sql(:decimal)}) AS size,
|
||||
projects.updated_on AS updated,
|
||||
CAST(NULL AS #{ActiveRecord::Base.connection.type_to_sql(:decimal)}) AS major_version,
|
||||
CAST(NULL AS #{ActiveRecord::Base.connection.type_to_sql(:decimal)}) AS minor_version,
|
||||
CAST(NULL AS #{ActiveRecord::Base.connection.type_to_sql(:decimal)}) AS workflow,
|
||||
CAST(NULL AS #{ActiveRecord::Base.connection.type_to_sql(:decimal)}) AS workflow_id,
|
||||
'' AS firstname,
|
||||
'' AS lastname,
|
||||
CAST(NULL AS #{ActiveRecord::Base.connection.type_to_sql(:decimal)}) AS author,
|
||||
'project' AS type,
|
||||
CAST(0 AS #{ActiveRecord::Base.connection.type_to_sql(:decimal)}) AS deleted,
|
||||
0 AS sort #{cf_columns}}).visible
|
||||
if dmsf_folder_id || deleted
|
||||
scope.where '1=0'
|
||||
else
|
||||
scope = scope.non_templates if scope.respond_to?(:non_templates)
|
||||
scope.where projects: { parent_id: project.id }
|
||||
end
|
||||
end
|
||||
|
||||
def dmsf_folders_scope
|
||||
cf_columns = +''
|
||||
if statement.present?
|
||||
@ -212,7 +250,7 @@ class DmsfQuery < Query
|
||||
users.id AS author,
|
||||
'folder' AS type,
|
||||
dmsf_folders.deleted AS deleted,
|
||||
0 AS sort #{cf_columns}}).
|
||||
1 AS sort #{cf_columns}}).
|
||||
joins('LEFT JOIN users ON dmsf_folders.user_id = users.id')
|
||||
if deleted
|
||||
scope = scope.deleted
|
||||
@ -255,7 +293,7 @@ class DmsfQuery < Query
|
||||
users.id AS author,
|
||||
'folder-link' AS type,
|
||||
dmsf_links.deleted AS deleted,
|
||||
0 AS sort #{cf_columns}}).
|
||||
1 AS sort #{cf_columns}}).
|
||||
joins('LEFT JOIN dmsf_folders ON dmsf_links.target_id = dmsf_folders.id').
|
||||
joins('LEFT JOIN users ON users.id = COALESCE(dmsf_folders.user_id, dmsf_links.user_id)')
|
||||
if dmsf_folder_id
|
||||
@ -294,7 +332,7 @@ class DmsfQuery < Query
|
||||
users.id AS author,
|
||||
'file' AS type,
|
||||
dmsf_files.deleted AS deleted,
|
||||
1 AS sort #{cf_columns}}).
|
||||
2 AS sort #{cf_columns}}).
|
||||
joins(:dmsf_file_revisions).
|
||||
joins('LEFT JOIN users ON dmsf_file_revisions.user_id = users.id ').
|
||||
where(sub_query)
|
||||
@ -334,7 +372,7 @@ class DmsfQuery < Query
|
||||
users.id AS author,
|
||||
'file-link' AS type,
|
||||
dmsf_links.deleted AS deleted,
|
||||
1 AS sort #{cf_columns}}).
|
||||
2 AS sort #{cf_columns}}).
|
||||
joins('JOIN dmsf_files ON dmsf_files.id = dmsf_links.target_id').
|
||||
joins('JOIN dmsf_file_revisions ON dmsf_file_revisions.dmsf_file_id = dmsf_files.id').
|
||||
joins('LEFT JOIN users ON dmsf_file_revisions.user_id = users.id ').
|
||||
@ -376,7 +414,7 @@ class DmsfQuery < Query
|
||||
users.id AS author,
|
||||
'url-link' AS type,
|
||||
dmsf_links.deleted AS deleted,
|
||||
1 AS sort #{cf_columns}}).
|
||||
2 AS sort #{cf_columns}}).
|
||||
joins('LEFT JOIN users ON dmsf_links.user_id = users.id ')
|
||||
if dmsf_folder_id
|
||||
scope.where dmsf_links: { target_type: 'DmsfUrl', dmsf_folder_id: dmsf_folder_id, deleted: deleted }
|
||||
|
||||
@ -27,11 +27,18 @@
|
||||
<% end %>
|
||||
<% query.dmsf_nodes(options).each do |node| %>
|
||||
<% system = node.title =~ /^\./ %>
|
||||
<% id = (node.type == 'folder') ? "#{node.id}span" : "#{node.id}item" %>
|
||||
<% case node.type %>
|
||||
<% when 'project'%>
|
||||
<% id = "#{node.id}pspan" %>
|
||||
<% when 'folder' %>
|
||||
<% id = "#{node.id}fspan" %>
|
||||
<% else %>
|
||||
<% id = "#{node.id}item" %>
|
||||
<% end %>
|
||||
<% @idnt ||= 0 %>
|
||||
<tr id="<%= id %>" class="<%= cycle('odd', 'even') %> <%= node.css_classes(query.deleted) %> <%= 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 %>
|
||||
<%= check_box_tag('ids[]', "#{node.type}-#{node.id}", false, id: nil) unless (system || (node.type == 'project')) %>
|
||||
</td>
|
||||
<% query.inline_columns.each do |column| %>
|
||||
<%= content_tag 'td', column_content(column, node), class: column.css_classes %>
|
||||
|
||||
@ -269,7 +269,12 @@ function dmsfSetupFileDrop() {
|
||||
|
||||
if (window.File && window.FileList && window.ProgressEvent && window.FormData) {
|
||||
|
||||
$.event.addProp('dataTransfer');
|
||||
if($().jquery < '3.0.0') {
|
||||
$.event.fixHooks.drop = {props: ['dataTransfer']};
|
||||
}
|
||||
else{
|
||||
$.event.addProp('dataTransfer');
|
||||
}
|
||||
|
||||
$('form span.dmsf-uploader:not(.dmsffiledroplistner)').has('input:file').each(function () {
|
||||
|
||||
|
||||
@ -20,7 +20,7 @@
|
||||
*/
|
||||
|
||||
/* Function to allow the projects to show up as a tree */
|
||||
function dmsfToggle(el, id, url)
|
||||
function dmsfToggle(el, project_id, folder_id, url)
|
||||
{
|
||||
// Expand not yet loaded selected row
|
||||
let selectedRow = $(el).parents('tr').first();
|
||||
@ -33,15 +33,13 @@ function dmsfToggle(el, id, url)
|
||||
|
||||
if(selectedRow.hasClass('dmsf-not-loaded')){
|
||||
|
||||
dmsfExpandRows(id, selectedRow, url);
|
||||
dmsfExpandRows(project_id, folder_id, selectedRow, url);
|
||||
}
|
||||
|
||||
if(expand) {
|
||||
|
||||
$(selectedRow).switchClass('dmsf-collapsed', 'dmsf-expanded');
|
||||
}
|
||||
else {
|
||||
|
||||
$(selectedRow).switchClass('dmsf-expanded', 'dmsf-collapsed');
|
||||
}
|
||||
|
||||
@ -51,12 +49,11 @@ function dmsfToggle(el, id, url)
|
||||
$("tr.dmsf-tree").each(function(i, tr){
|
||||
|
||||
// Visiblity
|
||||
if($(tr).hasClass(id)) {
|
||||
|
||||
if($(tr).hasClass(folder_id ? (folder_id + 'f') : (project_id + 'p'))) {
|
||||
if (expand) {
|
||||
|
||||
// Display only children with expanded parent
|
||||
m = $(tr).attr('class').match(/(\d+) idnt/);
|
||||
m = $(tr).attr('class').match(/(\d+(p|f)) idnt/);
|
||||
|
||||
if(m){
|
||||
|
||||
@ -69,7 +66,6 @@ function dmsfToggle(el, id, url)
|
||||
} else {
|
||||
|
||||
if(!$(tr).hasClass('dmsf-hidden')) {
|
||||
|
||||
$(tr).addClass('dmsf-hidden');
|
||||
}
|
||||
}
|
||||
@ -93,7 +89,7 @@ function dmsfToggle(el, id, url)
|
||||
}
|
||||
|
||||
/* Add child rows */
|
||||
function dmsfExpandRows(id, parentRow, url) {
|
||||
function dmsfExpandRows(project_id, folder_id, parentRow, url) {
|
||||
|
||||
$(parentRow).removeClass('dmsf-not-loaded');
|
||||
|
||||
@ -105,13 +101,13 @@ function dmsfExpandRows(id, parentRow, url) {
|
||||
idnt = m[1];
|
||||
}
|
||||
|
||||
m = $(parentRow).attr('class').match(/((\d|\s)+) idnt/);
|
||||
m = $(parentRow).attr('class').match(/((\d|p|f|\s)+) idnt/);
|
||||
|
||||
if(m){
|
||||
classes = m[1]
|
||||
}
|
||||
|
||||
m = $(parentRow).attr('id').match(/^(\d+)/);
|
||||
m = $(parentRow).attr('id').match(/^(\d+(p|f))/);
|
||||
|
||||
if(m){
|
||||
classes = classes + ' ' + m[1]
|
||||
@ -122,7 +118,8 @@ function dmsfExpandRows(id, parentRow, url) {
|
||||
type: 'post',
|
||||
dataType: 'html',
|
||||
data: {
|
||||
folder_id: id,
|
||||
project_id: project_id,
|
||||
folder_id: folder_id,
|
||||
row_id: $(parentRow).attr('id'),
|
||||
idnt: idnt,
|
||||
classes: classes
|
||||
@ -144,7 +141,7 @@ function dmsfExpandRows(id, parentRow, url) {
|
||||
}
|
||||
})
|
||||
.fail(function() {
|
||||
alert('An error in rows expanding');
|
||||
console.log('An error in rows expanding');
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -115,6 +115,19 @@ module RedmineDmsf
|
||||
end
|
||||
end
|
||||
|
||||
# Go recursively through the project tree until a dmsf enabled project is found
|
||||
def dmsf_available?
|
||||
return true if(visible? && module_enabled?(:dmsf))
|
||||
children.each do |child|
|
||||
return true if child.dmsf_available?
|
||||
end
|
||||
false
|
||||
end
|
||||
|
||||
# def deleted
|
||||
# 0
|
||||
# end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@ -181,7 +181,7 @@ module RedmineDmsf
|
||||
scope = project_scope.visible
|
||||
scope = scope.non_templates if scope.respond_to?(:non_templates)
|
||||
scope.find_each do |p|
|
||||
if dmsf_available?(p)
|
||||
if p.dmsf_available?
|
||||
@children << child_project(p)
|
||||
end
|
||||
end
|
||||
@ -271,15 +271,6 @@ module RedmineDmsf
|
||||
end
|
||||
end
|
||||
|
||||
# Go recursively through the project tree until a dmsf enabled project is found
|
||||
def dmsf_available?(p)
|
||||
return true if(p.visible? && p.module_enabled?(:dmsf))
|
||||
p.children.each do |child|
|
||||
return true if dmsf_available?(child)
|
||||
end
|
||||
false
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user