#699 Columns visiblity check optimization
This commit is contained in:
parent
06415b17e0
commit
5263985d2c
@ -50,6 +50,9 @@ class DmsfFolder < ActiveRecord::Base
|
|||||||
AVAILABLE_COLUMNS = %w(id title extension size modified version workflow author).freeze
|
AVAILABLE_COLUMNS = %w(id title extension size modified version workflow author).freeze
|
||||||
DEFAULT_COLUMNS = %w(title size modified version workflow author).freeze
|
DEFAULT_COLUMNS = %w(title size modified version workflow author).freeze
|
||||||
|
|
||||||
|
@@dmsf_columns = Setting.plugin_redmine_dmsf['dmsf_columns']
|
||||||
|
@@dmsf_columns = DmsfFolder::DEFAULT_COLUMNS unless columns
|
||||||
|
|
||||||
scope :visible, -> { joins(:project).joins(
|
scope :visible, -> { joins(:project).joins(
|
||||||
"LEFT JOIN #{DmsfFolderPermission.table_name} ON #{DmsfFolder.table_name}.id = #{DmsfFolderPermission.table_name}.dmsf_folder_id").where(
|
"LEFT JOIN #{DmsfFolderPermission.table_name} ON #{DmsfFolder.table_name}.id = #{DmsfFolderPermission.table_name}.dmsf_folder_id").where(
|
||||||
:deleted => STATUS_ACTIVE).where(DmsfFolder.visible_condition).distinct
|
:deleted => STATUS_ACTIVE).where(DmsfFolder.visible_condition).distinct
|
||||||
@ -328,15 +331,13 @@ class DmsfFolder < ActiveRecord::Base
|
|||||||
|
|
||||||
# Number of items in the folder
|
# Number of items in the folder
|
||||||
def items
|
def items
|
||||||
dmsf_folders.where(:project_id => self.project_id).visible.count +
|
dmsf_folders.visible.where(:project_id => self.project_id).count +
|
||||||
dmsf_files.visible.where(:container_id => self.project_id).count +
|
dmsf_files.visible.where(:container_id => self.project_id).count +
|
||||||
dmsf_links.visible.where(:project_id => self.project_id).count
|
dmsf_links.visible.where(:project_id => self.project_id).count
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.is_column_on?(column)
|
def self.is_column_on?(column)
|
||||||
columns = Setting.plugin_redmine_dmsf['dmsf_columns']
|
@@dmsf_columns.include? column
|
||||||
columns = DmsfFolder::DEFAULT_COLUMNS unless columns
|
|
||||||
columns.include? column
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def custom_value(custom_field)
|
def custom_value(custom_field)
|
||||||
@ -348,60 +349,58 @@ class DmsfFolder < ActiveRecord::Base
|
|||||||
|
|
||||||
def self.get_column_position(column)
|
def self.get_column_position(column)
|
||||||
pos = 0
|
pos = 0
|
||||||
columns = Setting.plugin_redmine_dmsf['dmsf_columns']
|
|
||||||
columns = DmsfFolder::DEFAULT_COLUMNS unless columns
|
|
||||||
# 0 - checkbox
|
# 0 - checkbox
|
||||||
# 1 - id
|
# 1 - id
|
||||||
if columns.include?('id')
|
if @@dmsf_columns.include?('id')
|
||||||
pos += 1
|
pos += 1
|
||||||
return pos if column == 'id'
|
return pos if column == 'id'
|
||||||
else
|
else
|
||||||
return nil if column == 'id'
|
return nil if column == 'id'
|
||||||
end
|
end
|
||||||
# 2 - title
|
# 2 - title
|
||||||
if columns.include?('title')
|
if @@dmsf_columns.include?('title')
|
||||||
pos += 1
|
pos += 1
|
||||||
return pos if column == 'title'
|
return pos if column == 'title'
|
||||||
else
|
else
|
||||||
return nil if column == 'title'
|
return nil if column == 'title'
|
||||||
end
|
end
|
||||||
# 3 - extension
|
# 3 - extension
|
||||||
if columns.include?('extension')
|
if @@dmsf_columns.include?('extension')
|
||||||
pos += 1
|
pos += 1
|
||||||
return pos if column == 'extension'
|
return pos if column == 'extension'
|
||||||
else
|
else
|
||||||
return nil if column == 'extension'
|
return nil if column == 'extension'
|
||||||
end
|
end
|
||||||
# 4 - size
|
# 4 - size
|
||||||
if columns.include?('size')
|
if @@dmsf_columns.include?('size')
|
||||||
pos += 1
|
pos += 1
|
||||||
return pos if column == 'size'
|
return pos if column == 'size'
|
||||||
else
|
else
|
||||||
return nil if column == 'size'
|
return nil if column == 'size'
|
||||||
end
|
end
|
||||||
# 5 - modified
|
# 5 - modified
|
||||||
if columns.include?('modified')
|
if @@dmsf_columns.include?('modified')
|
||||||
pos += 1
|
pos += 1
|
||||||
return pos if column == 'modified'
|
return pos if column == 'modified'
|
||||||
else
|
else
|
||||||
return nil if column == 'modified'
|
return nil if column == 'modified'
|
||||||
end
|
end
|
||||||
# 6 - version
|
# 6 - version
|
||||||
if columns.include?('version')
|
if @@dmsf_columns.include?('version')
|
||||||
pos += 1
|
pos += 1
|
||||||
return pos if column == 'version'
|
return pos if column == 'version'
|
||||||
else
|
else
|
||||||
return nil if column == 'version'
|
return nil if column == 'version'
|
||||||
end
|
end
|
||||||
# 7 - workflow
|
# 7 - workflow
|
||||||
if columns.include?('workflow')
|
if @@dmsf_columns.include?('workflow')
|
||||||
pos += 1
|
pos += 1
|
||||||
return pos if column == 'workflow'
|
return pos if column == 'workflow'
|
||||||
else
|
else
|
||||||
return nil if column == 'workflow'
|
return nil if column == 'workflow'
|
||||||
end
|
end
|
||||||
# 8 - author
|
# 8 - author
|
||||||
if columns.include?('author')
|
if @@dmsf_columns.include?('author')
|
||||||
pos += 1
|
pos += 1
|
||||||
return pos if column == 'author'
|
return pos if column == 'author'
|
||||||
else
|
else
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user