Getting rid off all @@ variables
This commit is contained in:
parent
9f6a4d8eec
commit
f7f78e9fec
@ -97,10 +97,7 @@ class DmsfFile < ActiveRecord::Base
|
||||
super
|
||||
end
|
||||
|
||||
@@storage_path = nil
|
||||
|
||||
def self.storage_path
|
||||
return @@storage_path if @@storage_path.present?
|
||||
path = Setting.plugin_redmine_dmsf['dmsf_storage_directory']
|
||||
if path.blank?
|
||||
path = Pathname.new('files').join('dmsf').to_s
|
||||
@ -111,17 +108,6 @@ class DmsfFile < ActiveRecord::Base
|
||||
Rails.root.join(path)
|
||||
end
|
||||
|
||||
# Lets introduce a write for storage path, that way we can also
|
||||
# better interact from test-cases etc
|
||||
def self.storage_path=(path)
|
||||
begin
|
||||
FileUtils.mkdir_p(path) unless File.exist?(path)
|
||||
rescue Exception => e
|
||||
Rails.logger.error e.message
|
||||
end
|
||||
@@storage_path = Pathname.new(path)
|
||||
end
|
||||
|
||||
def self.find_file_by_name(project, folder, name)
|
||||
self.findn_file_by_name(project.id, folder, name)
|
||||
end
|
||||
|
||||
@ -352,15 +352,11 @@ class DmsfFolder < ActiveRecord::Base
|
||||
dmsf_files.visible.where(:project_id => self.project_id).count +
|
||||
dmsf_links.visible.where(:project_id => self.project_id).count
|
||||
end
|
||||
|
||||
@@dmsf_columns = nil
|
||||
|
||||
def self.is_column_on?(column)
|
||||
unless @@dmsf_columns
|
||||
@@dmsf_columns = Setting.plugin_redmine_dmsf['dmsf_columns']
|
||||
@@dmsf_columns = DmsfFolder::DEFAULT_COLUMNS unless @@dmsf_columns
|
||||
end
|
||||
@@dmsf_columns.include? column
|
||||
dmsf_columns = Setting.plugin_redmine_dmsf['dmsf_columns']
|
||||
dmsf_columns = DmsfFolder::DEFAULT_COLUMNS unless dmsf_columns
|
||||
dmsf_columns.include? column
|
||||
end
|
||||
|
||||
def custom_value(custom_field)
|
||||
@ -371,63 +367,61 @@ class DmsfFolder < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def self.get_column_position(column)
|
||||
unless @@dmsf_columns
|
||||
@@dmsf_columns = Setting.plugin_redmine_dmsf['dmsf_columns']
|
||||
@@dmsf_columns = DmsfFolder::DEFAULT_COLUMNS unless @@dmsf_columns
|
||||
end
|
||||
dmsf_columns = Setting.plugin_redmine_dmsf['dmsf_columns']
|
||||
dmsf_columns = DmsfFolder::DEFAULT_COLUMNS unless dmsf_columns
|
||||
pos = 0
|
||||
# 0 - checkbox
|
||||
# 1 - id
|
||||
if @@dmsf_columns.include?('id')
|
||||
if dmsf_columns.include?('id')
|
||||
pos += 1
|
||||
return pos if column == 'id'
|
||||
else
|
||||
return nil if column == 'id'
|
||||
end
|
||||
# 2 - title
|
||||
if @@dmsf_columns.include?('title')
|
||||
if dmsf_columns.include?('title')
|
||||
pos += 1
|
||||
return pos if column == 'title'
|
||||
else
|
||||
return nil if column == 'title'
|
||||
end
|
||||
# 3 - extension
|
||||
if @@dmsf_columns.include?('extension')
|
||||
if dmsf_columns.include?('extension')
|
||||
pos += 1
|
||||
return pos if column == 'extension'
|
||||
else
|
||||
return nil if column == 'extension'
|
||||
end
|
||||
# 4 - size
|
||||
if @@dmsf_columns.include?('size')
|
||||
if dmsf_columns.include?('size')
|
||||
pos += 1
|
||||
return pos if column == 'size'
|
||||
else
|
||||
return nil if column == 'size'
|
||||
end
|
||||
# 5 - modified
|
||||
if @@dmsf_columns.include?('modified')
|
||||
if dmsf_columns.include?('modified')
|
||||
pos += 1
|
||||
return pos if column == 'modified'
|
||||
else
|
||||
return nil if column == 'modified'
|
||||
end
|
||||
# 6 - version
|
||||
if @@dmsf_columns.include?('version')
|
||||
if dmsf_columns.include?('version')
|
||||
pos += 1
|
||||
return pos if column == 'version'
|
||||
else
|
||||
return nil if column == 'version'
|
||||
end
|
||||
# 7 - workflow
|
||||
if @@dmsf_columns.include?('workflow')
|
||||
if dmsf_columns.include?('workflow')
|
||||
pos += 1
|
||||
return pos if column == 'workflow'
|
||||
else
|
||||
return nil if column == 'workflow'
|
||||
end
|
||||
# 8 - author
|
||||
if @@dmsf_columns.include?('author')
|
||||
if dmsf_columns.include?('author')
|
||||
pos += 1
|
||||
return pos if column == 'author'
|
||||
else
|
||||
|
||||
@ -26,7 +26,17 @@
|
||||
<% end %>
|
||||
</td>
|
||||
<% if DmsfFolder.is_column_on?('id') %>
|
||||
<td class="id"><%= link_to(subfolder.id, edit_dmsf_path(:id => project, :folder_id => subfolder)) %></td>
|
||||
<td class="id">
|
||||
<% if subfolder %>
|
||||
<% if subfolder.system %>
|
||||
<%= subfolder.id %>
|
||||
<% else %>
|
||||
<%= link_to(subfolder.id, edit_dmsf_path(:id => project, :folder_id => subfolder)) %>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<%= link_to(link.target_project_id, project_path(link.target_project)) %>
|
||||
<% end %>
|
||||
</td>
|
||||
<% end %>
|
||||
<% if DmsfFolder.is_column_on?('title') %>
|
||||
<td class="dmsf_title">
|
||||
|
||||
@ -230,7 +230,7 @@
|
||||
<%= 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 }) %>
|
||||
:locals => { :selected_columns => Setting.plugin_redmine_dmsf['dmsf_columns'], :extra_columns => @extra_columns }) %>
|
||||
</div>
|
||||
<p class="buttons">
|
||||
<%= submit_tag l(:button_export), :name => nil, :onclick => "hideModal(this);" %>
|
||||
|
||||
@ -31,8 +31,7 @@
|
||||
<% end %>
|
||||
<% 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 %>
|
||||
<% selected_columns = DmsfFolder::DEFAULT_COLUMNS if selected_columns.blank? %>
|
||||
<% columns.each_with_index do |column, i| %>
|
||||
<%= check_box_tag('settings[dmsf_columns][]', column, selected_columns.include?(column)) %>
|
||||
<%= h column.capitalize %>
|
||||
|
||||
@ -142,7 +142,7 @@
|
||||
<%= l(:menu_dmsf) %> <%= l(:field_column_names) %>
|
||||
</em>
|
||||
|
||||
<%= render(:partial => 'settings/dmsf_columns', :locals => { :settings => @settings }) %>
|
||||
<%= render(:partial => 'settings/dmsf_columns', :locals => { :selected_columns => @settings['dmsf_columns'] }) %>
|
||||
|
||||
<hr/>
|
||||
<em class="info">
|
||||
|
||||
@ -34,7 +34,7 @@ class DmsfFilesControllerTest < RedmineDmsf::Test::TestCase
|
||||
@role = Role.find_by_id 1
|
||||
User.current = nil
|
||||
@request.session[:user_id] = 2
|
||||
DmsfFile.storage_path = File.expand_path '../../fixtures/files', __FILE__
|
||||
Setting.plugin_redmine_dmsf['dmsf_storage_directory'] = File.expand_path '../../fixtures/files', __FILE__
|
||||
end
|
||||
|
||||
def test_truth
|
||||
|
||||
@ -25,7 +25,7 @@ class DmsfPublicUrlsControllerTest < RedmineDmsf::Test::TestCase
|
||||
fixtures :dmsf_files, :dmsf_file_revisions, :dmsf_public_urls
|
||||
|
||||
def setup
|
||||
DmsfFile.storage_path = File.expand_path '../../fixtures/files', __FILE__
|
||||
Setting.plugin_redmine_dmsf['dmsf_storage_directory'] = File.expand_path '../../fixtures/files', __FILE__
|
||||
end
|
||||
|
||||
def test_show_valid_url
|
||||
|
||||
@ -25,7 +25,7 @@ class DmsfFileApiTest < RedmineDmsf::Test::IntegrationTest
|
||||
fixtures :projects, :users, :dmsf_files, :dmsf_file_revisions, :members, :roles
|
||||
|
||||
def setup
|
||||
DmsfFile.storage_path = File.expand_path '../../../fixtures/files', __FILE__
|
||||
Setting.plugin_redmine_dmsf['dmsf_storage_directory'] = File.expand_path '../../../fixtures/files', __FILE__
|
||||
timestamp = DateTime.now.strftime("%y%m%d%H%M")
|
||||
@tmp_storage_path = File.expand_path("./dmsf_test-#{timestamp}", DmsfHelper.temp_dir)
|
||||
Dir.mkdir(@tmp_storage_path) unless File.directory?(@tmp_storage_path)
|
||||
@ -78,7 +78,7 @@ class DmsfFileApiTest < RedmineDmsf::Test::IntegrationTest
|
||||
end
|
||||
|
||||
def test_upload_document
|
||||
DmsfFile.storage_path = @tmp_storage_path
|
||||
Setting.plugin_redmine_dmsf['dmsf_storage_directory'] = @tmp_storage_path
|
||||
@role.add_permission! :file_manipulation
|
||||
token = Token.create!(:user => @jsmith, :action => 'api')
|
||||
#curl --data-binary "@cat.gif" -H "Content-Type: application/octet-stream" -X POST -u ${1}:${2} http://localhost:3000/projects/12/dmsf/upload.xml?filename=cat.gif
|
||||
|
||||
@ -25,7 +25,7 @@ class DmsfFolderApiTest < RedmineDmsf::Test::IntegrationTest
|
||||
fixtures :dmsf_folders, :dmsf_files, :dmsf_file_revisions, :projects, :users, :members, :roles
|
||||
|
||||
def setup
|
||||
DmsfFile.storage_path = File.expand_path '../../../fixtures/files', __FILE__
|
||||
Setting.plugin_redmine_dmsf['dmsf_storage_directory'] = File.expand_path '../../../fixtures/files', __FILE__
|
||||
@jsmith = User.find_by_id 2
|
||||
@file1 = DmsfFile.find_by_id 1
|
||||
@folder1 = DmsfFolder.find_by_id 1
|
||||
|
||||
@ -41,7 +41,7 @@ class DmsfWebdavDeleteTest < RedmineDmsf::Test::IntegrationTest
|
||||
Setting.plugin_redmine_dmsf['dmsf_webdav'] = '1'
|
||||
Setting.plugin_redmine_dmsf['dmsf_webdav_strategy'] = 'WEBDAV_READ_WRITE'
|
||||
Setting.plugin_redmine_dmsf['dmsf_webdav_use_project_names'] = false
|
||||
DmsfFile.storage_path = File.expand_path '../../../fixtures/files', __FILE__
|
||||
Setting.plugin_redmine_dmsf['dmsf_storage_directory'] = File.expand_path '../../../fixtures/files', __FILE__
|
||||
User.current = nil
|
||||
end
|
||||
|
||||
|
||||
@ -35,7 +35,7 @@ class DmsfWebdavGetTest < RedmineDmsf::Test::IntegrationTest
|
||||
Setting.plugin_redmine_dmsf['dmsf_webdav'] = '1'
|
||||
Setting.plugin_redmine_dmsf['dmsf_webdav_strategy'] = 'WEBDAV_READ_WRITE'
|
||||
Setting.plugin_redmine_dmsf['dmsf_webdav_use_project_names'] = false
|
||||
DmsfFile.storage_path = File.expand_path '../../../fixtures/files', __FILE__
|
||||
Setting.plugin_redmine_dmsf['dmsf_storage_directory'] = File.expand_path '../../../fixtures/files', __FILE__
|
||||
User.current = nil
|
||||
end
|
||||
|
||||
|
||||
@ -36,8 +36,8 @@ class DmsfWebdavHeadTest < RedmineDmsf::Test::IntegrationTest
|
||||
# Temporarily enable project names
|
||||
Setting.plugin_redmine_dmsf['dmsf_webdav_use_project_names'] = true
|
||||
@project1_uri = Addressable::URI.escape(RedmineDmsf::Webdav::ProjectResource.create_project_name(@project1))
|
||||
Setting.plugin_redmine_dmsf['dmsf_webdav_use_project_names'] = false
|
||||
DmsfFile.storage_path = File.expand_path '../../../fixtures/files', __FILE__
|
||||
Setting.plugin_redmine_dmsf['dmsf_webdav_use_project_names'] = false
|
||||
Setting.plugin_redmine_dmsf['dmsf_storage_directory'] = File.expand_path '../../../fixtures/files', __FILE__
|
||||
User.current = nil
|
||||
end
|
||||
|
||||
|
||||
@ -36,7 +36,7 @@ class DmsfWebdavMkcolTest < RedmineDmsf::Test::IntegrationTest
|
||||
Setting.plugin_redmine_dmsf['dmsf_webdav'] = '1'
|
||||
Setting.plugin_redmine_dmsf['dmsf_webdav_strategy'] = 'WEBDAV_READ_WRITE'
|
||||
Setting.plugin_redmine_dmsf['dmsf_webdav_use_project_names'] = false
|
||||
DmsfFile.storage_path = File.expand_path '../../../fixtures/files', __FILE__
|
||||
Setting.plugin_redmine_dmsf['dmsf_storage_directory'] = File.expand_path '../../../fixtures/files', __FILE__
|
||||
User.current = nil
|
||||
end
|
||||
|
||||
|
||||
@ -30,7 +30,7 @@ class DmsfWebdavMoveTest < RedmineDmsf::Test::IntegrationTest
|
||||
def setup
|
||||
DmsfLock.delete_all # Delete all locks that are in our test DB - probably not safe but ho hum
|
||||
timestamp = DateTime.now.strftime('%y%m%d%H%M')
|
||||
DmsfFile.storage_path = File.expand_path("./dmsf_test-#{timestamp}", DmsfHelper.temp_dir)
|
||||
Setting.plugin_redmine_dmsf['dmsf_storage_directory'] = File.expand_path("./dmsf_test-#{timestamp}", DmsfHelper.temp_dir)
|
||||
Dir.mkdir(DmsfFile.storage_path) unless File.directory?(DmsfFile.storage_path)
|
||||
# Copy the physical files to the temporary storage
|
||||
files = File.expand_path('../../../fixtures/files', __FILE__) + '/.'
|
||||
|
||||
@ -30,7 +30,7 @@ class DmsfWebdavPutTest < RedmineDmsf::Test::IntegrationTest
|
||||
def setup
|
||||
DmsfLock.delete_all # Delete all locks that are in our test DB - probably not safe but ho hum
|
||||
timestamp = DateTime.now.strftime("%y%m%d%H%M")
|
||||
DmsfFile.storage_path = File.expand_path("./dmsf_test-#{timestamp}", DmsfHelper.temp_dir)
|
||||
Setting.plugin_redmine_dmsf['dmsf_storage_directory'] = File.expand_path("./dmsf_test-#{timestamp}", DmsfHelper.temp_dir)
|
||||
Dir.mkdir(DmsfFile.storage_path) unless File.directory?(DmsfFile.storage_path)
|
||||
@admin = credentials 'admin'
|
||||
@jsmith = credentials 'jsmith'
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user