mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-10-27 14:37:35 +08:00
Merge pull request #2136 from biosistemika/SCI-3975-team-export
Sci 3975 team export
This commit is contained in:
commit
37e6604f8b
4 changed files with 18 additions and 15 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue