Documents export #641

This commit is contained in:
Karel Picman 2017-02-02 14:09:44 +01:00
parent 3cf0f774d5
commit 134076aa05
32 changed files with 379 additions and 69 deletions

View File

@ -31,9 +31,10 @@ class DmsfController < ApplicationController
accept_api_auth :show, :create, :save
skip_before_action :verify_authenticity_token, if: -> { request.headers["HTTP_X_REDMINE_API_KEY"].present? }
skip_before_action :verify_authenticity_token, if: -> { request.headers['HTTP_X_REDMINE_API_KEY'].present? }
helper :all
#helper :dmsf
def expand_folder
@tree_view = true
@ -58,6 +59,10 @@ class DmsfController < ApplicationController
render :layout => !request.xhr?
}
format.api
format.csv {
send_data(DmsfHelper.dmsf_to_csv(@folder ? @folder : @project, params[:settings][:dmsf_columns]),
:type => 'text/csv; header=present', :filename => 'dmsf.csv')
}
end
end
@ -594,6 +599,7 @@ class DmsfController < ApplicationController
@file_approval_allowed = User.current.allowed_to?(:file_approval, @project)
tag = params[:custom_field_id].present? && params[:custom_value].present?
@folder = nil if tag
@extra_columns = [l(:label_document_url), l(:label_last_revision_id)]
if @tree_view
@locked_for_user = false
else
@ -688,7 +694,7 @@ class DmsfController < ApplicationController
@file_delete_allowed && !@locked_for_user && !@folder
@trash_enabled = DmsfFolder.deleted.where(:project_id => @project.id).any? ||
DmsfFile.deleted.where(:container_id => @project.id, :container_type => 'Project').any? ||
DmsfLink.deleted.where(:container_id => @project.id, :container_type => 'Project').any?
DmsfLink.deleted.where(:project_id => @project.id).any?
end
end

View File

@ -109,7 +109,7 @@ class DmsfFilesController < ApplicationController
else
revision.increase_version(version)
end
file_upload = params[:attachments]['1'] if params[:attachments].present?
file_upload = params[:dmsf_attachments]['1'] if params[:dmsf_attachments].present?
unless file_upload
revision.size = last_revision.size
revision.disk_filename = last_revision.disk_filename

View File

@ -3,7 +3,7 @@
# Redmine plugin for Document Management System "Features"
#
# Copyright (C) 2011 Vít Jonáš <vit.jonas@gmail.com>
# Copyright (C) 2011-16 Karel Pičman <karel.picman@kontron.com>
# Copyright (C) 2011-17 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
@ -117,4 +117,37 @@ module DmsfHelper
tree
end
def self.dmsf_to_csv(parent, columns)
Redmine::Export::CSV.generate do |csv|
# Header
csv << columns.map { |c| c.capitalize }
# Lines
DmsfHelper.object_to_csv(csv, parent, columns)
end
end
def self.object_to_csv(csv, parent, columns, level = -1)
# Folder
if level >= 0
csv << parent.to_csv(columns, level + 1)
end
# Sub-folders
folders = parent.dmsf_folders.visible.to_a
folders.concat(parent.folder_links.visible.to_a.map{ |l| l.folder })
folders.compact!
folders.sort!{ |x, y| x.title <=> y.title}
folders.each do |f|
DmsfHelper.object_to_csv(csv, f, columns, level + 1)
end
# Files
files = parent.dmsf_files.visible.to_a
files.concat(parent.file_links.visible.to_a.map{ |l| l.target_file })
files.concat(parent.url_links.visible.to_a)
files.compact!
files.sort!{ |x, y| x.title <=> y.title}
files.each do |file_or_link|
csv << file_or_link.to_csv(columns, level + 1)
end
end
end

View File

@ -523,29 +523,74 @@ class DmsfFile < ActiveRecord::Base
end
end
def extension
$1 if self.last_revision && self.last_revision.disk_filename =~ /\.(.+)$/
end
include ActionView::Helpers::NumberHelper
include Rails.application.routes.url_helpers
def to_csv
csv = "\"#{self.title}\""
csv << ';'
csv << "\"#{number_to_human_size(self.last_revision.size)}\""
csv << ';'
csv << "\"#{format_time(self.last_revision.updated_at)}\""
csv << ';'
csv << "\"#{self.last_revision.version}\""
csv << ';'
csv << "\"#{self.last_revision.workflow_str(false)}\""
csv << ';'
csv << "\"#{self.last_revision.user}\""
csv << ';'
csv << "\"#{self.id}\""
csv << ';'
csv << "\"r#{self.last_revision.id}\""
csv << ';'
default_url_options[:host] = Setting.host_name
csv << "\"#{url_for(:controller => :dmsf_files, :action => 'view', :id => self)}\""
csv << ';'
def to_csv(columns, level)
csv = []
# Id
csv << self.id if columns.include?('id')
# Title
csv << self.title.insert(0, ' ' * level) if columns.include?('title')
# Extension
csv << self.extension if columns.include?('extension')
# Size
csv << number_to_human_size(self.last_revision.size) if columns.include?('size')
# Modified
if columns.include?('modified')
if self.last_revision
csv << format_time(self.last_revision.updated_at)
else
csv << ''
end
end
# Version
if columns.include?('version')
if self.last_revision
csv << self.last_revision.version
else
csv << ''
end
end
# Workflow
if columns.include?('workflow')
if self.last_revision
csv << self.last_revision.workflow_str(false)
else
csv << ''
end
end
# Author
if columns.include?('author')
if self.last_revision && self.last_revision.user
csv << self.last_revision.user.name
else
csv << ''
end
end
# Url
if columns.include?(l(:label_document_url))
default_url_options[:host] = Setting.host_name
url = url_for(:controller => :dmsf_files, :action => 'view', :id => self.id)
csv << url_for(:controller => :dmsf_files, :action => 'view', :id => self.id)
end
# Revision
if columns.include?(l(:label_last_revision_id))
if self.last_revision
csv << self.last_revision.id
else
csv << ''
end
end
# Custom fields
cfs = CustomField.where(:type => 'DmsfFileRevisionCustomField').order(:position)
cfs.each do |c|
csv << self.custom_value(c) if columns.include?(c.name)
end
csv
end

View File

@ -424,6 +424,42 @@ class DmsfFolder < ActiveRecord::Base
end
end
include ActionView::Helpers::NumberHelper
include Rails.application.routes.url_helpers
def to_csv(columns, level)
csv = []
# Id
csv << self.id if columns.include?('id')
# Title
csv << self.title.insert(0, ' ' * level) if columns.include?('title')
# Extension
csv << '' if columns.include?('extension')
# Size
csv << '' if columns.include?('size')
# Modified
csv << format_time(self.updated_at) if columns.include?('modified')
# Version
csv << '' if columns.include?('version')
# Workflow
csv << '' if columns.include?('workflow')
# Author
csv << self.user.name if columns.include?('author')
# Url
if columns.include?(l(:label_document_url))
default_url_options[:host] = Setting.host_name
csv << url_for(:controller => :dmsf, :action => 'show', :id => self.project_id, :folder_id => self.id)
end
# Revision
csv << '' if columns.include?(l(:label_last_revision_id))
# Custom fields
cfs = CustomField.where(:type => 'DmsfFileRevisionCustomField').order(:position)
cfs.each do |c|
csv << self.custom_value(c) if columns.include?(c.name)
end
csv
end
private
def self.directory_subtree(tree, folder, level, current_folder)

View File

@ -46,8 +46,8 @@ class DmsfLink < ActiveRecord::Base
end
end
STATUS_DELETED = 1
STATUS_ACTIVE = 0
STATUS_DELETED = 1.freeze
STATUS_ACTIVE = 0.freeze
scope :visible, -> { where(:deleted => STATUS_ACTIVE) }
scope :deleted, -> { where(:deleted => STATUS_DELETED) }
@ -150,4 +150,36 @@ class DmsfLink < ActiveRecord::Base
!is_folder?
end
def to_csv(columns, level)
csv = []
if self.target_type == 'DmsfUrl'
# Id
csv << '' if columns.include?('id')
# Title
csv << self.title.insert(0, ' ' * level) if columns.include?('title')
# Extension
csv << '' if columns.include?('extension')
# Size
csv << '' if columns.include?('size')
# Modified
csv << format_time(self.updated_at) if columns.include?('modified')
# Version
csv << '' if columns.include?('version')
# Workflow
csv << '' if columns.include?('workflow')
# Author
csv << self.last_revision.user.name if columns.include?('author')
# Url
csv << self.external_url if columns.include?('url')
# Revision
csv << '' if columns.include?('revision')
# Custom fields
cfs = CustomField.where(:type => 'DmsfFileRevisionCustomField').order(:position)
cfs.each do |c|
csv << '' if columns.include?(c.name)
end
end
csv
end
end

View File

@ -44,7 +44,7 @@
<% end %>
<% if DmsfFolder.is_column_on?('extension') %>
<td class="dmsf_extension">
<%= $1 if file.last_revision.disk_filename =~ /\.(.+)$/ %>
<%= file.extension %>
</td>
<% end %>
<% if DmsfFolder.is_column_on?('size') %>

View File

@ -207,3 +207,22 @@
<% if (@file_manipulation_allowed && !@locked_for_user) %>
<%= render(:partial => 'dmsf_upload/multi_upload') %>
<% end %>
<% other_formats_links do |f| %>
<%= f.link_to 'CSV', :url => params, :onclick => "showModal('csv-export-options', '350px'); return false;" %>
<% end %>
<div id="csv-export-options" style="display:none;">
<h3 class="title"><%= l(:label_export_options, :export_format => 'CSV') %></h3>
<%= form_tag(dmsf_folder_path(:id => @project, :format => 'csv'), :method => :get, :id => 'csv-export-form') do %>
<%= hidden_field_tag(:folder_id, @folder.id) if @folder %>
<div class="tabular">
<%= render(:partial => 'settings/dmsf_columns',
:locals => { :settings => Setting.plugin_redmine_dmsf, :extra_columns => @extra_columns }) %>
</div>
<p class="buttons">
<%= submit_tag l(:button_export), :name => nil, :onclick => "hideModal(this);" %>
<%= submit_tag l(:button_cancel), :name => nil, :onclick => "hideModal(this);", :type => 'button' %>
</p>
<% end %>
</div>

View File

@ -128,6 +128,10 @@
</tr>
<% end %>
<% @file_links.each do |link| %>
<% unless link.target_file %>
<% Rails.logger.error "Error: dmsf_link id #{link.id} has no target file!" %>
<% next %>
<% end %>
<% unless link.target_file.last_revision %>
<% Rails.logger.error "Error: dmsf_file id #{link.target_id} has no revision!" %>
<% next %>

View File

@ -77,7 +77,7 @@
<div class="box">
<p>
<%= label_tag('file_upload', l(:label_new_content)) %>
<%= render :partial => 'upload_form' %>
<%= render :partial => 'dmsf_upload/form', :locals => { :multiple => false } %>
</p>
</div>
<p>

View File

@ -23,7 +23,7 @@
<span id="dmsf_attachments_fields">
<% if defined?(container) && container && container.saved_attachments %>
<% container.saved_attachments.each_with_index do |attachment, i| %>
<span id="dmsf_attachments_p<%#= i %>">
<span id="dmsf_attachments_p<%= i %>">
<%= text_field_tag("dmsf_attachments[p#{i}][filename]", attachment.filename, :class => 'filename') +
text_field_tag("dmsf_attachments[p#{i}][description]", attachment.description, :maxlength => 255, :placeholder => l(:label_optional_description), :class => 'description') +
link_to('&nbsp;'.html_safe, dmsf_attachment_path(attachment, :attachment_id => "p#{i}", :format => 'js'), :method => 'delete', :remote => true, :class => 'remove-upload') %>
@ -36,8 +36,8 @@
<%= file_field_tag 'dmsf_attachments[dummy][file]',
:id => nil,
:class => 'file_selector',
:multiple => true,
:onchange => 'dmsfAddInputFiles(this);',
:multiple => multiple,
:onchange => "dmsfAddInputFiles(this);",
:data => {
:max_file_size => Setting.attachment_max_size.to_i.kilobytes,
:max_file_size_message => l(:error_attachment_too_big, :max_size => number_to_human_size(Setting.attachment_max_size.to_i.kilobytes)),

View File

@ -40,7 +40,7 @@
<div class="dmsf_uploader">
<p>
<label><%= l(:label_document_plural) %></label>
<%= render :partial => 'dmsf_upload/form' %>
<%= render :partial => 'dmsf_upload/form', :locals => { :multiple => true } %>
</p>
</div>
<%= submit_tag l(:label_upload) %>

View File

@ -0,0 +1,36 @@
<%
# encoding: utf-8
#
# Redmine plugin for Document Management System "Features"
#
# Copyright (C) 2011-17 Karel Picman <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.
%>
<p>
<%= content_tag(:label, l(:field_column_names)) %>
<% columns = DmsfFolder::AVAILABLE_COLUMNS.dup %>
<% columns.concat(extra_columns) if defined?(extra_columns) %>
<% cfs = CustomField.where(:type => 'DmsfFileRevisionCustomField').order(:position) %>
<% columns.concat(cfs.map{ |c| c.name }) %>
<% selected_columns = settings[:dmsf_columns] %>
<% selected_columns = DmsfFolder::DEFAULT_COLUMNS unless selected_columns %>
<% columns.each_with_index do |column, i| %>
<%= check_box_tag('settings[dmsf_columns][]', column, selected_columns.include?(column)) %>
<%= h column.capitalize %>
<br/>
<% end %>
</p>

View File

@ -133,19 +133,7 @@
<%= l(:menu_dmsf) %> <%= l(:field_column_names) %>
</em>
<p>
<%= content_tag(:label, l(:field_column_names)) %>
<% columns = DmsfFolder::AVAILABLE_COLUMNS.dup %>
<% cfs = CustomField.where(:type => 'DmsfFileRevisionCustomField').order(:position) %>
<% columns.concat(cfs.map{ |c| c.name }) %>
<% selected_columns = @settings[:dmsf_columns] %>
<% selected_columns = DmsfFolder::DEFAULT_COLUMNS unless selected_columns %>
<% columns.each_with_index do |column, i| %>
<%= check_box_tag('settings[dmsf_columns][]', column, selected_columns.include?(column)) %>
<%= h column.capitalize %>
<br/>
<% end %>
</p>
<%= render(:partial => 'settings/dmsf_columns', :locals => { :settings => @settings }) %>
<hr/>
<em class="info">

View File

@ -1,5 +1,23 @@
/* Redmine - project management software
Copyright (C) 2006-2016 Jean-Philippe Lang */
/* encoding: utf-8
*
* Redmine plugin for Document Management System "Features"
*
* Copyright (C) 2011-17 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.
*/
function dmsfAddFile(inputEl, file, eagerUpload) {
@ -9,11 +27,35 @@ function dmsfAddFile(inputEl, file, eagerUpload) {
var fileSpan = $('<span>', { id: 'dmsf_attachments_' + attachmentId });
fileSpan.append(
$('<input>', { type: 'text', 'class': 'filename readonly', name: 'dmsf_attachments[' + attachmentId + '][filename]', readonly: 'readonly'} ).val(file.name),
$('<input>', { type: 'text', 'class': 'description', name: 'dmsf_attachments[' + attachmentId + '][description]', maxlength: 255, placeholder: $(inputEl).data('description-placeholder') } ).toggle(!eagerUpload),
$('<a>&nbsp</a>').attr({ href: "#", 'class': 'remove-upload' }).click(dmsfRemoveFile).toggle(!eagerUpload)
).appendTo('#dmsf_attachments_fields');
if($(inputEl).attr('multiple') == 'multiple') {
fileSpan.append(
$('<input>', {
type: 'text',
'class': 'filename readonly',
name: 'dmsf_attachments[' + attachmentId + '][filename]',
readonly: 'readonly'
}).val(file.name),
$('<input>', {
type: 'text',
'class': 'description',
name: 'dmsf_attachments[' + attachmentId + '][description]',
maxlength: 255,
placeholder: $(inputEl).data('description-placeholder')
}).toggle(!eagerUpload),
$('<a>&nbsp</a>').attr({href: "#", 'class': 'remove-upload'}).click(dmsfRemoveFile).toggle(!eagerUpload)
).appendTo('#dmsf_attachments_fields');
}
else{
fileSpan.append(
$('<input>', {
type: 'text',
'class': 'filename readonly',
name: 'dmsf_attachments[' + attachmentId + '][filename]',
readonly: 'readonly'
}).val(file.name)
).appendTo('#dmsf_attachments_fields');
$('#dmsf_file_revision_name').val(file.name);
}
if(eagerUpload) {
dmsfAjaxUpload(file, attachmentId, fileSpan, inputEl);
@ -58,7 +100,7 @@ function dmsfAjaxUpload(file, attachmentId, fileSpan, inputEl) {
dmsfAjaxUpload.uploading--;
fileSpan.removeClass('ajax-loading');
var form = fileSpan.parents('form');
if (form.queue('upload').length == 0 && dmsfAjaxUpload.uploading == 0) {
if ((form.queue('upload').length == 0) && (dmsfAjaxUpload.uploading == 0)) {
$('input:submit', form).removeAttr('disabled');
}
form.dequeue('upload');
@ -134,7 +176,10 @@ function dmsfAddInputFiles(inputEl) {
}
}
clearedFileInput.insertAfter('#dmsf_attachments_fields');
if($(inputEl).attr('multiple') == 'multiple')
clearedFileInput.insertAfter('#dmsf_attachments_fields');
else
$('.dmsf_add_attachment').toggle();
}
function dmsfUploadAndAttachFiles(files, inputEl) {

View File

@ -344,4 +344,7 @@ cs:
text_memcached_servers: Je podporován pouze jeden server. Pokud není vyplněno, kešování je vypnuté. Při změně adresy je potřeba restartovat aplikaci.
label_webdav_ignore: Vzory názvů ignorovaných souborů
note_webdav_ignore: Regulární výraz pro názvy souborů, které budou ignorovány při volání PUT.
note_webdav_ignore: Regulární výraz pro názvy souborů, které budou ignorovány při volání PUT.
label_document_url: Url
label_last_revision_id: Revize

View File

@ -344,4 +344,7 @@ en:
text_memcached_servers: Only a single server is supported, if empty then caching is disabled. After changing this, the application must be restarted!
label_webdav_ignore: Ignored files patterns
note_webdav_ignore: A regular expresion with filenames to ignore by PUT requests.
note_webdav_ignore: A regular expresion with filenames to ignore by PUT requests.
label_document_url: Url
label_last_revision_id: Revision

View File

@ -344,4 +344,7 @@ es:
text_memcached_servers: Only a single server is supported, if empty then caching is disabled. After changing this, the application must be restarted!
label_webdav_ignore: Ignored files patterns
note_webdav_ignore: A regular expresion with filenames to ignore by PUT requests.
note_webdav_ignore: A regular expresion with filenames to ignore by PUT requests.
label_document_url: Url
label_last_revision_id: Revision

View File

@ -344,4 +344,7 @@ fr:
text_memcached_servers: Only a single server is supported, if empty then caching is disabled. After changing this, the application must be restarted!
label_webdav_ignore: Ignored files patterns
note_webdav_ignore: A regular expresion with filenames to ignore by PUT requests.
note_webdav_ignore: A regular expresion with filenames to ignore by PUT requests.
label_document_url: Url
label_last_revision_id: Revision

View File

@ -344,4 +344,7 @@ it: # Italian strings thx 2 Matteo Arceci!
text_memcached_servers: Only a single server is supported, if empty then caching is disabled. After changing this, the application must be restarted!
label_webdav_ignore: Ignored files patterns
note_webdav_ignore: A regular expresion with filenames to ignore by PUT requests.
note_webdav_ignore: A regular expresion with filenames to ignore by PUT requests.
label_document_url: Url
label_last_revision_id: Revision

View File

@ -344,4 +344,7 @@ ja:
text_memcached_servers: Only a single server is supported, if empty then caching is disabled. After changing this, the application must be restarted!
label_webdav_ignore: Ignored files patterns
note_webdav_ignore: A regular expresion with filenames to ignore by PUT requests.
note_webdav_ignore: A regular expresion with filenames to ignore by PUT requests.
label_document_url: Url
label_last_revision_id: Revision

View File

@ -344,4 +344,7 @@ pl:
text_memcached_servers: Only a single server is supported, if empty then caching is disabled. After changing this, the application must be restarted!
label_webdav_ignore: Ignored files patterns
note_webdav_ignore: A regular expresion with filenames to ignore by PUT requests.
note_webdav_ignore: A regular expresion with filenames to ignore by PUT requests.
label_document_url: Url
label_last_revision_id: Revision

View File

@ -344,4 +344,7 @@ pt-BR:
text_memcached_servers: Only a single server is supported, if empty then caching is disabled. After changing this, the application must be restarted!
label_webdav_ignore: Ignored files patterns
note_webdav_ignore: A regular expresion with filenames to ignore by PUT requests.
note_webdav_ignore: A regular expresion with filenames to ignore by PUT requests.
label_document_url: Url
label_last_revision_id: Revision

View File

@ -344,4 +344,7 @@ ru:
text_memcached_servers: Only a single server is supported, if empty then caching is disabled. After changing this, the application must be restarted!
label_webdav_ignore: Ignored files patterns
note_webdav_ignore: A regular expresion with filenames to ignore by PUT requests.
note_webdav_ignore: A regular expresion with filenames to ignore by PUT requests.
label_document_url: Url
label_last_revision_id: Revision

View File

@ -344,4 +344,7 @@ sl:
text_memcached_servers: Only a single server is supported, if empty then caching is disabled. After changing this, the application must be restarted!
label_webdav_ignore: Ignored files patterns
note_webdav_ignore: A regular expresion with filenames to ignore by PUT requests.
note_webdav_ignore: A regular expresion with filenames to ignore by PUT requests.
label_document_url: Url
label_last_revision_id: Revision

View File

@ -344,4 +344,7 @@ zh-TW:
text_memcached_servers: Only a single server is supported, if empty then caching is disabled. After changing this, the application must be restarted!
label_webdav_ignore: Ignored files patterns
note_webdav_ignore: A regular expresion with filenames to ignore by PUT requests.
note_webdav_ignore: A regular expresion with filenames to ignore by PUT requests.
label_document_url: Url
label_last_revision_id: Revision

View File

@ -344,4 +344,7 @@ zh:
text_memcached_servers: Only a single server is supported, if empty then caching is disabled. After changing this, the application must be restarted!
label_webdav_ignore: Ignored files patterns
note_webdav_ignore: A regular expresion with filenames to ignore by PUT requests.
note_webdav_ignore: A regular expresion with filenames to ignore by PUT requests.
label_document_url: Url
label_last_revision_id: Revision

View File

@ -31,7 +31,8 @@ module RedmineDmsf
html = "<div class=\"dmsf_uploader\">"
html << '<p>'
html << "<label>#{l(:label_document_plural)}</label>"
html << context[:controller].send(:render_to_string, {:partial => 'dmsf_upload/form', :locals => context})
html << context[:controller].send(:render_to_string,
{:partial => 'dmsf_upload/form', :locals => { :multiple => true }})
html << '</p>'
html << '</div>'
html.html_safe

View File

@ -2,7 +2,7 @@
#
# Redmine plugin for Document Management System "Features"
#
# Copyright (C) 2011-16 Karel Pičman <karel.picman@kontron.com>
# Copyright (C) 2011-17 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
@ -196,4 +196,12 @@ class DmsfControllerTest < RedmineDmsf::Test::TestCase
assert_select 'tr.dmsf_tree'
end
def test_show_csv
@role.add_permission! :view_dmsf_files
@role.add_permission! :view_dmsf_folders
get :show, :id => @project.id, :format => 'csv', :settings => {:dmsf_columns => ['id', 'title']}
assert_response :success
assert_equal 'text/csv; header=present', @response.content_type
end
end

View File

@ -239,4 +239,10 @@ class DmsfFileTest < RedmineDmsf::Test::UnitTest
assert_nil DmsfFile.find_file_by_name(@issue1, nil, 'test.odt')
end
def test_to_csv
columns = ['id', 'title']
csv = @file1.to_csv(columns, 0)
assert_equal 2, csv.size
end
end

View File

@ -142,5 +142,11 @@ class DmsfFolderTest < RedmineDmsf::Test::UnitTest
assert RedmineDmsf::Webdav::Cache.exist?("#{cache_key}.invalid")
RedmineDmsf::Webdav::Cache.init_nullcache
end
end
def test_to_csv
columns = ['id', 'title']
csv = @folder4.to_csv(columns, 0)
assert_equal 2, csv.size
end
end

View File

@ -236,5 +236,14 @@ class DmsfLinksTest < RedmineDmsf::Test::UnitTest
@folder_link.errors.full_messages.to_sentence
assert_nil DmsfLink.find_by_id @folder_link.id
end
def test_to_csv
columns = ['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