mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-01-27 10:08:11 +08:00
Merge pull request #2695 from okriuchykhin/ok_SCI_4738
Add repository snapshots to export all [SCI-4738]
This commit is contained in:
commit
6726a19cbe
6 changed files with 33 additions and 36 deletions
|
@ -138,19 +138,8 @@ module ReportsHelper
|
|||
end
|
||||
|
||||
def assigned_repositories_in_project_list(project)
|
||||
live_repositories = Repository.accessible_by_teams(project.team)
|
||||
.joins(repository_rows:
|
||||
{ my_module_repository_rows: { my_module: { experiment: :project } } })
|
||||
.where(repository_rows:
|
||||
{ my_module_repository_rows: { my_module: { experiments: { project: project } } } })
|
||||
.select(:id, :name)
|
||||
|
||||
snapshots = RepositorySnapshot.joins(my_module: { experiment: :project })
|
||||
.where('experiments.project_id = ?', project.id)
|
||||
.left_outer_joins(:original_repository)
|
||||
.where(original_repositories_repositories: { id: nil })
|
||||
.select('DISTINCT ON ("repositories"."parent_id") "repositories".*')
|
||||
.order(:parent_id, updated_at: :desc)
|
||||
live_repositories = Repository.assigned_to_project(project)
|
||||
snapshots = RepositorySnapshot.assigned_to_project(project)
|
||||
|
||||
snapshots.each { |snapshot| snapshot.name = "#{snapshot.name} #{t('projects.reports.index.deleted')}" }
|
||||
(live_repositories + snapshots).sort_by { |r| r.name.downcase }
|
||||
|
|
|
@ -210,6 +210,12 @@ class Project < ApplicationRecord
|
|||
})
|
||||
end
|
||||
|
||||
def assigned_repositories_and_snapshots
|
||||
live_repositories = Repository.assigned_to_project(self)
|
||||
snapshots = RepositorySnapshot.assigned_to_project(self)
|
||||
(live_repositories + snapshots).sort_by { |r| r.name.downcase }
|
||||
end
|
||||
|
||||
def my_modules_ids
|
||||
ids = active_experiments.map do |exp|
|
||||
exp.my_modules.pluck(:id) if exp.my_modules
|
||||
|
|
|
@ -131,17 +131,11 @@ class Report < ApplicationRecord
|
|||
result_children)
|
||||
end
|
||||
|
||||
module_children +=
|
||||
gen_element_content(my_module, nil, 'my_module_activity', true, 'asc')
|
||||
module_children +=
|
||||
gen_element_content(my_module,
|
||||
my_module.repository_rows.select(:repository_id)
|
||||
.distinct.map(&:repository),
|
||||
'my_module_repository', true, 'asc')
|
||||
repositories = project.assigned_repositories_and_snapshots
|
||||
|
||||
modules +=
|
||||
gen_element_content(my_module, nil, 'my_module', true, nil,
|
||||
module_children)
|
||||
module_children += gen_element_content(my_module, nil, 'my_module_activity', true, 'asc')
|
||||
module_children += gen_element_content(my_module, repositories, 'my_module_repository', true, 'asc')
|
||||
modules += gen_element_content(my_module, nil, 'my_module', true, nil, module_children)
|
||||
end
|
||||
|
||||
report_contents +=
|
||||
|
|
|
@ -50,6 +50,12 @@ class Repository < RepositoryBase
|
|||
.distinct
|
||||
}
|
||||
|
||||
scope :assigned_to_project, lambda { |project|
|
||||
accessible_by_teams(project.team)
|
||||
.joins(repository_rows: { my_module_repository_rows: { my_module: { experiment: :project } } })
|
||||
.where(repository_rows: { my_module_repository_rows: { my_module: { experiments: { project: project } } } })
|
||||
}
|
||||
|
||||
def self.within_global_limits?
|
||||
return true unless Rails.configuration.x.global_repositories_limit.positive?
|
||||
|
||||
|
|
|
@ -17,6 +17,15 @@ class RepositorySnapshot < RepositoryBase
|
|||
validates :status, presence: true
|
||||
validate :only_one_selected_for_my_module, if: ->(obj) { obj.changed.include? 'selected' }
|
||||
|
||||
scope :assigned_to_project, lambda { |project|
|
||||
joins(my_module: { experiment: :project })
|
||||
.where('experiments.project_id = ?', project.id)
|
||||
.left_outer_joins(:original_repository)
|
||||
.where(original_repositories_repositories: { id: nil })
|
||||
.select('DISTINCT ON ("repositories"."parent_id") "repositories".*')
|
||||
.order(:parent_id, updated_at: :desc)
|
||||
}
|
||||
|
||||
def default_columns_count
|
||||
Constants::REPOSITORY_SNAPSHOT_TABLE_DEFAULT_STATE['length']
|
||||
end
|
||||
|
|
|
@ -59,17 +59,11 @@ class TeamZipExport < ZipExport
|
|||
inventories = "#{project_path}/Inventories"
|
||||
FileUtils.mkdir_p(inventories)
|
||||
|
||||
# Find all assigned inventories through all tasks in the project
|
||||
task_ids = p.project_my_modules
|
||||
repo_rows = RepositoryRow.joins(:my_modules)
|
||||
.where(my_modules: { id: task_ids })
|
||||
.distinct
|
||||
repositories = p.assigned_repositories_and_snapshots
|
||||
|
||||
# Iterate through every inventory repo and save it to CSV
|
||||
repo_rows.map(&:repository).uniq.each_with_index do |repo, repo_idx|
|
||||
curr_repo_rows = repo_rows.select { |x| x.repository_id == repo.id }
|
||||
obj_filenames[:my_module_repository][repo.id] =
|
||||
save_inventories_to_csv(inventories, repo, curr_repo_rows, repo_idx)
|
||||
repositories.each_with_index do |repo, repo_idx|
|
||||
obj_filenames[:my_module_repository][repo.id] = save_inventories_to_csv(inventories, repo, repo_idx)
|
||||
end
|
||||
|
||||
# Include all experiments
|
||||
|
@ -233,7 +227,7 @@ class TeamZipExport < ZipExport
|
|||
end
|
||||
|
||||
# Helper method for saving inventories to CSV
|
||||
def save_inventories_to_csv(path, repo, repo_rows, idx)
|
||||
def save_inventories_to_csv(path, repo, idx)
|
||||
repo_name = "#{to_filesystem_name(repo.name)} (#{idx})"
|
||||
|
||||
# Attachment folder
|
||||
|
@ -263,14 +257,13 @@ class TeamZipExport < ZipExport
|
|||
end
|
||||
|
||||
# Generate CSV
|
||||
csv_data = RepositoryZipExport.to_csv(repo_rows, col_ids, @user, @team,
|
||||
handle_name_func)
|
||||
csv_data = RepositoryZipExport.to_csv(repo.repository_rows, col_ids, @user, @team, handle_name_func)
|
||||
File.open(csv_file, 'wb') { |f| f.write(csv_data) }
|
||||
|
||||
# Save all attachments (it doesn't work directly in callback function
|
||||
assets.each do |asset, asset_path|
|
||||
asset.file.open do |file|
|
||||
FileUtils.cp(file.path, asset_path)
|
||||
FileUtils.cp(file.path, asset_path)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue