Merge pull request #2136 from biosistemika/SCI-3975-team-export

Sci 3975 team export
This commit is contained in:
Miha Mencin 2019-10-08 21:47:08 +02:00 committed by GitHub
commit 37e6604f8b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 15 deletions

View file

@ -8,6 +8,11 @@ class Asset < ApplicationRecord
include ActiveStorageFileUtil
include ActiveStorageConcerns
attr_accessor :file_file_name
attr_accessor :file_file_size
attr_accessor :file_content_type
attr_accessor :file_updated_at
require 'tempfile'
# Lock duration set to 30 minutes
LOCK_DURATION = 60 * 30

View file

@ -2,6 +2,11 @@ class Experiment < ApplicationRecord
include ArchivableModel
include SearchableModel
include SearchableByNameModel
attr_accessor :workflowimg_file_name
attr_accessor :workflowimg_file_size
attr_accessor :workflowimg_content_type
attr_accessor :workflowimg_updated_at
belongs_to :project, inverse_of: :experiments, touch: true
belongs_to :created_by,

View file

@ -127,7 +127,7 @@ class Step < ApplicationRecord
end
def asset_position(asset)
assets.order(:file_updated_at).each_with_index do |step_asset, i|
assets.order(:updated_at).each_with_index do |step_asset, i|
return { count: assets.count, pos: i } if asset.id == step_asset.id
end
end

View file

@ -15,22 +15,15 @@ module ModelExporters
def copy_files(assets, attachment_name, dir_name)
assets.flatten.each do |a|
next unless a.public_send(attachment_name).attached?
blob = a.public_send(attachment_name).blob
dir = FileUtils.mkdir_p(File.join(dir_name, a.id.to_s)).first
destination_path = File.join(dir, a.file_name)
blob.open do |file|
FileUtils.cp(file.path, destination_path)
end
yield if block_given?
dir = FileUtils.mkdir_p(File.join(dir_name, a.id.to_s)).first
tempfile = Tempfile.new
tempfile.binmode
a.public_send(attachment_name).blob.download { |chunk| tempfile.write(chunk) }
tempfile.flush
tempfile.rewind
FileUtils.cp(
tempfile.path,
File.join(dir, a.file_name)
)
ensure
tempfile.close
tempfile.unlink
end
end