mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-12-25 17:24:51 +08:00
Add custom method for repository report JSON data
This commit is contained in:
parent
17c643fb21
commit
507443ba38
3 changed files with 24 additions and 4 deletions
|
@ -413,6 +413,26 @@ class MyModule < ApplicationRecord
|
|||
{ headers: headers, data: records }
|
||||
end
|
||||
|
||||
def repository_docx_json(repository_id)
|
||||
headers = [
|
||||
I18n.t('repositories.table.id'),
|
||||
I18n.t('repositories.table.row_name'),
|
||||
I18n.t('repositories.table.added_on'),
|
||||
I18n.t('repositories.table.added_by')
|
||||
]
|
||||
custom_columns = []
|
||||
repository = Repository.find_by(id: repository_id)
|
||||
return false unless repository
|
||||
|
||||
repository.repository_columns.order(:id).each do |column|
|
||||
headers.push(column.name)
|
||||
custom_columns.push(column.id)
|
||||
end
|
||||
|
||||
records = repository_rows.where(repository_id: repository_id).select(:id, :name, :created_at, :created_by_id)
|
||||
{ headers: headers, rows: records, custom_columns: custom_columns }
|
||||
end
|
||||
|
||||
def deep_clone(current_user)
|
||||
deep_clone_to_experiment(current_user, experiment)
|
||||
end
|
||||
|
|
|
@ -6,8 +6,8 @@ module Reports::Docx::DrawMyModuleRepository
|
|||
return unless my_module
|
||||
|
||||
repository_id = subject['id']['repository_id']
|
||||
repository_data = my_module.repository_json(repository_id, subject['sort_order'], @user)
|
||||
return false unless repository_data[:data].any?
|
||||
repository_data = my_module.repository_docx_json(repository_id)
|
||||
return false unless repository_data[:rows].any?
|
||||
|
||||
repository = ::Repository.find(repository_id)
|
||||
table = prepare_row_columns(repository_data)
|
||||
|
|
|
@ -5,7 +5,7 @@ module Reports::Docx::RepositoryHelper
|
|||
|
||||
def prepare_row_columns(repository_data)
|
||||
result = [repository_data[:headers]]
|
||||
repository_data[:data].repository_rows.each do |record|
|
||||
repository_data[:rows].each do |record|
|
||||
row = []
|
||||
row.push(record.id)
|
||||
row.push(escape_input(record.name))
|
||||
|
@ -18,7 +18,7 @@ module Reports::Docx::RepositoryHelper
|
|||
cell_values[cell.repository_column_id] = cell.value.formatted
|
||||
end
|
||||
|
||||
repository_data[:data].mappings.each do |column_id, _position|
|
||||
repository_data[:custom_columns].each do |column_id|
|
||||
value = cell_values[column_id]
|
||||
row.push(value)
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue