diff --git a/app/models/dmsf_file.rb b/app/models/dmsf_file.rb index 611d8d9b..cd307094 100644 --- a/app/models/dmsf_file.rb +++ b/app/models/dmsf_file.rb @@ -517,81 +517,6 @@ class DmsfFile < ActiveRecord::Base File.extname(last_revision.disk_filename).strip.downcase[1..-1] if last_revision end - include ActionView::Helpers::NumberHelper - include Rails.application.routes.url_helpers - - def to_csv(columns, level) - csv = [] - # Project - csv << project.name if columns.include?(l(:field_project)) - # Id - csv << id if columns.include?('id') - # Title - csv << title.insert(0, ' ' * level) if columns.include?('title') - # Extension - csv << extension if columns.include?('extension') - # Size - csv << number_to_human_size(last_revision.size) if columns.include?('size') - # Modified - if columns.include?('modified') - if last_revision - csv << format_time(last_revision.updated_at) - else - csv << '' - end - end - # Version - if columns.include?('version') - if last_revision - csv << last_revision.version - else - csv << '' - end - end - # Workflow - if columns.include?('workflow') - if last_revision - csv << last_revision.workflow_str(false) - else - csv << '' - end - end - # Author - if columns.include?('author') - if last_revision && last_revision.user - csv << last_revision.user.name - else - csv << '' - end - end - # Last approver - if columns.include?(l(:label_last_approver)) - if last_revision && last_revision.dmsf_workflow - csv << last_revision.workflow_tooltip - else - csv << '' - end - end - # Url - if columns.include?(l(:label_document_url)) - default_url_options[:host] = Setting.host_name - csv << url_for(controller: :dmsf_files, action: 'view', id: id) - end - # Revision - if columns.include?(l(:label_last_revision_id)) - if last_revision - csv << last_revision.id - else - csv << '' - end - end - # Custom fields - DmsfFileRevisionCustomField.visible.order(:position).each do |c| - csv << custom_value(c).value if columns.include?(c.name) - end - csv - end - def thumbnail(options={}) if image? size = options[:size].to_i diff --git a/app/models/dmsf_folder.rb b/app/models/dmsf_folder.rb index 4ba3c855..5a552f74 100644 --- a/app/models/dmsf_folder.rb +++ b/app/models/dmsf_folder.rb @@ -47,7 +47,7 @@ class DmsfFolder < ActiveRecord::Base INVALID_CHARACTERS = '\[\]\/\\\?":<>#%\*' STATUS_DELETED = 1 STATUS_ACTIVE = 0 - AVAILABLE_COLUMNS = %w(id title extension size modified version workflow author).freeze + AVAILABLE_COLUMNS = %w(id title size modified version workflow author).freeze DEFAULT_COLUMNS = %w(title size modified version workflow author).freeze def self.visible_condition(system=true) @@ -359,42 +359,35 @@ class DmsfFolder < ActiveRecord::Base else return nil if column == 'title' end - # 3 - extension - if dmsf_columns.include?('extension') - pos += 1 - return pos if column == 'extension' - else - return nil if column == 'extension' - end - # 4 - size + # 3 - size if dmsf_columns.include?('size') pos += 1 return pos if column == 'size' else return nil if column == 'size' end - # 5 - modified + # 4 - modified if dmsf_columns.include?('modified') pos += 1 return pos if column == 'modified' else return nil if column == 'modified' end - # 6 - version + # 5 - version if dmsf_columns.include?('version') pos += 1 return pos if column == 'version' else return nil if column == 'version' end - # 7 - workflow + # 6 - workflow if dmsf_columns.include?('workflow') pos += 1 return pos if column == 'workflow' else return nil if column == 'workflow' end - # 8 - author + # 7 - author if dmsf_columns.include?('author') pos += 1 return pos if column == 'author' @@ -407,66 +400,27 @@ class DmsfFolder < ActiveRecord::Base pos += 1 end end - # 10 - commands + # 8 - commands pos += 1 return pos if column == 'commands' - # 11 - (position) + # 9 - (position) pos += 1 return pos if column == 'position' - # 12 - (size calculated) + # 10 - (size calculated) pos += 1 return pos if column == 'size_calculated' - # 13 - (modified calculated) + # 11 - (modified calculated) pos += 1 return pos if column == 'modified_calculated' - # 14 - (version calculated) + # 12 - (version calculated) pos += 1 return pos if column == 'version_calculated' - # 15 - (clear title) + # 13 - (clear title) pos += 1 return pos if column == 'clear_title' nil end - include ActionView::Helpers::NumberHelper - include Rails.application.routes.url_helpers - - def to_csv(columns, level) - csv = [] - # Project - csv << project.name if columns.include?(l(:field_project)) - # Id - csv << id if columns.include?('id') - # Title - csv << title.insert(0, ' ' * level) if columns.include?('title') - # Extension - csv << '' if columns.include?('extension') - # Size - csv << '' if columns.include?('size') - # Modified - csv << format_time(updated_at) if columns.include?('modified') - # Version - csv << '' if columns.include?('version') - # Workflow - csv << '' if columns.include?('workflow') - # Author - csv << user.name if columns.include?('author') - # Last approver - csv << '' if columns.include?(l(:label_last_approver)) - # Url - if columns.include?(l(:label_document_url)) - default_url_options[:host] = Setting.host_name - csv << url_for(controller: :dmsf, action: 'show', id: project_id, folder_id: id) - end - # Revision - csv << '' if columns.include?(l(:label_last_revision_id)) - # Custom fields - DmsfFileRevisionCustomField.visible.order(:position).each do |c| - csv << custom_value(c).value if columns.include?(c.name) - end - csv - end - def get_locked_title if locked_for_user? if lock.reverse[0].user diff --git a/app/models/dmsf_link.rb b/app/models/dmsf_link.rb index 2356b048..bde48b24 100644 --- a/app/models/dmsf_link.rb +++ b/app/models/dmsf_link.rb @@ -164,39 +164,4 @@ class DmsfLink < ActiveRecord::Base !is_folder? end - def to_csv(columns, level) - csv = [] - if target_type == 'DmsfUrl' - # Project - csv << project.name if columns.include?(l(:field_project)) - # Id - csv << id if columns.include?('id') - # Title - csv << title.insert(0, ' ' * level) if columns.include?('title') - # Extension - csv << '' if columns.include?('extension') - # Size - csv << '' if columns.include?('size') - # Modified - csv << format_time(updated_at) if columns.include?('modified') - # Version - csv << '' if columns.include?('version') - # Workflow - csv << '' if columns.include?('workflow') - # Author - csv << user.name if columns.include?('author') - # Last approver - csv << '' if columns.include?(l(:label_last_approver)) - # Url - csv << external_url if columns.include?(l(:label_document_url)) - # Revision - csv << '' if columns.include?(l(:label_last_revision_id)) - # Custom fields - DmsfFileRevisionCustomField.visible.order(:position).each do |c| - csv << '' if columns.include?(c.name) - end - end - csv - end - end diff --git a/app/models/dmsf_query.rb b/app/models/dmsf_query.rb index 21745770..90ca4a65 100644 --- a/app/models/dmsf_query.rb +++ b/app/models/dmsf_query.rb @@ -31,7 +31,6 @@ class DmsfQuery < Query self.available_columns = [ QueryColumn.new(:id, sortable: 'id', caption: '#'), DmsfTitleQueryColumn.new(:title, sortable: 'title', frozen: true), - QueryColumn.new(:extension, sortable: 'extension'), QueryColumn.new(:size, sortable: 'size'), DmsfModifiedQueryColumn.new(:modified, sortable: 'updated'), DmsfVersionQueryColumn.new(:version, sortable: 'major_version, minor_version'), @@ -175,7 +174,6 @@ class DmsfQuery < Query NULL AS revision_id, dmsf_folders.title AS title, NULL AS filename, - NULL AS extension, NULL AS size, dmsf_folders.updated_at AS updated, NULL AS major_version, @@ -209,7 +207,6 @@ class DmsfQuery < Query NULL AS revision_id, dmsf_links.name AS title, dmsf_folders.title AS filename, - NULL AS extension, NULL AS size, COALESCE(dmsf_folders.updated_at, dmsf_links.updated_at) AS updated, NULL AS major_version, @@ -244,7 +241,6 @@ class DmsfQuery < Query dmsf_file_revisions.id AS revision_id, dmsf_file_revisions.title AS title, dmsf_file_revisions.name AS filename, - SUBSTR(dmsf_file_revisions.disk_filename, POSITION('.' IN dmsf_file_revisions.disk_filename) + 1, LENGTH(dmsf_file_revisions.disk_filename) - POSITION('.' IN dmsf_file_revisions.disk_filename)) AS extension, dmsf_file_revisions.size AS size, dmsf_file_revisions.updated_at AS updated, dmsf_file_revisions.major_version AS major_version, @@ -257,7 +253,7 @@ class DmsfQuery < Query 'file' AS type, dmsf_files.deleted AS deleted, 1 AS sort #{cf_columns}}). - joins('JOIN dmsf_file_revisions ON dmsf_file_revisions.dmsf_file_id = dmsf_files.id'). + joins(:dmsf_file_revisions). joins('LEFT JOIN users ON dmsf_file_revisions.user_id = users.id '). where('dmsf_file_revisions.created_at = (SELECT MAX(r.created_at) FROM dmsf_file_revisions r WHERE r.dmsf_file_id = dmsf_file_revisions.dmsf_file_id)') if deleted @@ -279,7 +275,6 @@ class DmsfQuery < Query dmsf_file_revisions.id AS revision_id, dmsf_links.name AS title, dmsf_file_revisions.name AS filename, - SUBSTR(dmsf_file_revisions.disk_filename, POSITION('.' IN dmsf_file_revisions.disk_filename) + 1, LENGTH(dmsf_file_revisions.disk_filename) - POSITION('.' IN dmsf_file_revisions.disk_filename)) AS extension, dmsf_file_revisions.size AS size, dmsf_file_revisions.updated_at AS updated, dmsf_file_revisions.major_version AS major_version, @@ -315,7 +310,6 @@ class DmsfQuery < Query NULL AS revision_id, dmsf_links.name AS title, dmsf_links.external_url AS filename, - NULL AS extension, NULL AS size, dmsf_links.updated_at AS updated, NULL AS major_version, diff --git a/config/locales/en.yml b/config/locales/en.yml index 6011ec80..2dce44de 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -403,7 +403,6 @@ en: button_edit_content: Edit content field_workflow: Workflow field_modified: Updated - field_extension: Ext. field_updated: Updated field_count: Downloads/Email field_first_at: First diff --git a/test/unit/dmsf_file_test.rb b/test/unit/dmsf_file_test.rb index cfccf0c7..caf8afe4 100644 --- a/test/unit/dmsf_file_test.rb +++ b/test/unit/dmsf_file_test.rb @@ -259,12 +259,6 @@ class DmsfFileTest < RedmineDmsf::Test::UnitTest assert_nil DmsfFile.find_file_by_name(@issue1, nil, 'test.odt') end - def test_to_csv - columns = %w(id title) - csv = @file1.to_csv(columns, 0) - assert_equal 2, csv.size - end - def test_storage_path setting = Setting.plugin_redmine_dmsf['dmsf_storage_directory'] Setting.plugin_redmine_dmsf['dmsf_storage_directory'] = 'files/dmsf' diff --git a/test/unit/dmsf_folder_test.rb b/test/unit/dmsf_folder_test.rb index 9a599636..e9684353 100644 --- a/test/unit/dmsf_folder_test.rb +++ b/test/unit/dmsf_folder_test.rb @@ -116,40 +116,32 @@ class DmsfFolderTest < RedmineDmsf::Test::UnitTest # 1 - id assert_nil DmsfFolder.get_column_position('id'), "The column 'id' is on?" # 2 - title - assert_equal DmsfFolder.get_column_position('title'), 1, "The expected position of the 'title' column is 2" - # 3 - extension - assert_nil DmsfFolder.get_column_position('extensions'), "The column 'extensions' is on?" - # 4 - size - assert_equal DmsfFolder.get_column_position('size'), 2, "The expected position of the 'size' column is 4" - # 5 - modified - assert_equal DmsfFolder.get_column_position('modified'), 3, "The expected position of the 'modified' column is 5" - # 6 - version - assert_equal DmsfFolder.get_column_position('version'), 4, "The expected position of the 'version' column is 6" - # 7 - workflow - assert_equal DmsfFolder.get_column_position('workflow'), 5, "The expected position of the 'workflow' column is 7" - # 8 - author - assert_equal DmsfFolder.get_column_position('author'), 6, "The expected position of the 'workflow' column is 8" - # 9 - custom fields + assert_equal DmsfFolder.get_column_position('title'), 1, "The expected position of the 'title' column is 1" + # 3 - size + assert_equal DmsfFolder.get_column_position('size'), 2, "The expected position of the 'size' column is 2" + # 4 - modified + assert_equal DmsfFolder.get_column_position('modified'), 3, "The expected position of the 'modified' column is 3" + # 5 - version + assert_equal DmsfFolder.get_column_position('version'), 4, "The expected position of the 'version' column is 4" + # 6 - workflow + assert_equal DmsfFolder.get_column_position('workflow'), 5, "The expected position of the 'workflow' column is 5" + # 7 - author + assert_equal DmsfFolder.get_column_position('author'), 6, "The expected position of the 'workflow' column is 6" + # 8 - custom fields assert_nil DmsfFolder.get_column_position('Tag'), "The column 'Tag' is on?" - # 10- commands - assert_equal DmsfFolder.get_column_position('commands'), 7, "The expected position of the 'commands' column is 10" - # 11- (position) - assert_equal DmsfFolder.get_column_position('position'), 8, "The expected position of the 'position' column is 11" - # 12- (size) + # 9 - commands + assert_equal DmsfFolder.get_column_position('commands'), 7, "The expected position of the 'commands' column is 7" + # 10 - position + assert_equal DmsfFolder.get_column_position('position'), 8, "The expected position of the 'position' column is 8" + # 11 - size assert_equal DmsfFolder.get_column_position('size_calculated'), 9, - "The expected position of the 'size_calculated' column is 12" - # 13- (modified) + "The expected position of the 'size_calculated' column is 9" + # 12 - modified assert_equal DmsfFolder.get_column_position('modified_calculated'), 10, - "The expected position of the 'modified_calculated' column is 13" - # 14- (version) + "The expected position of the 'modified_calculated' column is 10" + # 13 - version assert_equal DmsfFolder.get_column_position('version_calculated'), 11, - "The expected position of the 'version_calculated' column is 14" - end - - def test_to_csv - columns = %w(id title) - csv = @folder4.to_csv(columns, 0) - assert_equal 2, csv.size + "The expected position of the 'version_calculated' column is 11" end def test_directory_tree diff --git a/test/unit/dmsf_link_test.rb b/test/unit/dmsf_link_test.rb index 386425e5..5e00231d 100644 --- a/test/unit/dmsf_link_test.rb +++ b/test/unit/dmsf_link_test.rb @@ -243,13 +243,4 @@ class DmsfLinksTest < RedmineDmsf::Test::UnitTest assert_nil DmsfLink.find_by(id: @folder_link.id) end - def test_to_csv - columns = %w(id title) - csv = @file_link.to_csv(columns, 0) - assert_equal 0, csv.size - @file_link.target_type = 'DmsfUrl' - csv = @file_link.to_csv(columns, 0) - assert_equal 2, csv.size - end - end \ No newline at end of file