mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-12-26 09:42:46 +08:00
Add support for inventory columns selection for docx report [SCI-11095]
This commit is contained in:
parent
e53ea89f14
commit
1a04e249ba
8 changed files with 127 additions and 35 deletions
|
@ -968,6 +968,16 @@ function reportHandsonTableConverter() {
|
|||
}
|
||||
|
||||
(function() {
|
||||
function getSelectedRepositoryColumnValues(element, selectedAll = false) {
|
||||
const values = [];
|
||||
$(element).find('option').each((_, option) => {
|
||||
if ($(option).attr('selected-value') || selectedAll) {
|
||||
values.push(option.value);
|
||||
}
|
||||
});
|
||||
return values;
|
||||
}
|
||||
|
||||
function getReportData() {
|
||||
var reportData = {};
|
||||
|
||||
|
@ -1046,8 +1056,17 @@ function reportHandsonTableConverter() {
|
|||
reportData.report.settings.task[e.value] = e.checked;
|
||||
});
|
||||
reportData.report.settings.task.repositories = [];
|
||||
$.each($('.task-contents-container .repositories-contents .repositories-setting:checked'), function(i, e) {
|
||||
reportData.report.settings.task.repositories.push(parseInt(e.value, 10));
|
||||
reportData.report.settings.task.excluded_repository_columns = {};
|
||||
|
||||
$.each($('.task-contents-container .repositories-contents .repositories-setting:checked'), (_, e) => {
|
||||
const value = parseInt(e.value, 10);
|
||||
const $repositoryColumn = $(e).parent().siblings('.repository-columns')[0];
|
||||
const selectedValues = dropdownSelector.getValues($repositoryColumn);
|
||||
const excludedValues = getSelectedRepositoryColumnValues($repositoryColumn, true)
|
||||
.filter((item) => !selectedValues.includes(item))
|
||||
.map((el) => parseInt(el, 10));
|
||||
reportData.report.settings.task.repositories.push(value);
|
||||
reportData.report.settings.task.excluded_repository_columns[value] = excludedValues;
|
||||
});
|
||||
|
||||
reportData.report.settings.task.result_order = dropdownSelector.getValues('#taskResultsOrder');
|
||||
|
@ -1359,6 +1378,20 @@ function reportHandsonTableConverter() {
|
|||
if (dropdownSelector.getValues('#docxTemplateSelector').length > 0) {
|
||||
loadDocxTemplate();
|
||||
}
|
||||
|
||||
$('.repository-columns').each((_, element) => {
|
||||
const elementId = `#${$(element).attr('id')}`;
|
||||
const elements = getSelectedRepositoryColumnValues(elementId);
|
||||
|
||||
dropdownSelector.init(elementId, {
|
||||
selectAppearance: 'simple',
|
||||
optionClass: 'checkbox-icon'
|
||||
});
|
||||
|
||||
if (elements.length) {
|
||||
dropdownSelector.selectValues(elementId, elements);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function loadTemplate() {
|
||||
|
|
|
@ -260,6 +260,15 @@
|
|||
}
|
||||
// scss-lint:enable ImportantRule
|
||||
|
||||
.repositories-contents {
|
||||
.dropdown-selector-container {
|
||||
display: inline-flex;
|
||||
flex-shrink: 0;
|
||||
margin-left: auto;
|
||||
width: 200px;
|
||||
}
|
||||
}
|
||||
|
||||
.project-selector-container {
|
||||
background: $color-white;
|
||||
box-shadow: $modal-shadow;
|
||||
|
|
|
@ -391,17 +391,17 @@ class MyModule < ApplicationRecord
|
|||
{ data: data, headers: headers }
|
||||
end
|
||||
|
||||
def repository_docx_json(repository)
|
||||
headers = [
|
||||
I18n.t('repositories.table.id'),
|
||||
I18n.t('repositories.table.row_name'),
|
||||
I18n.t('repositories.table.added_on'),
|
||||
I18n.t('repositories.table.added_by')
|
||||
]
|
||||
def repository_docx_json(repository, excluded_columns)
|
||||
headers = Report.default_repository_columns.filter_map do |key, value|
|
||||
value unless excluded_columns.include?(key.to_s.to_i)
|
||||
end
|
||||
|
||||
custom_columns = []
|
||||
return false unless repository
|
||||
|
||||
repository.repository_columns.order(:id).each do |column|
|
||||
next if excluded_columns.include?(column.id)
|
||||
|
||||
if column.data_type == 'RepositoryStockValue'
|
||||
if repository.has_stock_consumption?
|
||||
headers.push(I18n.t('repositories.table.row_consumption'))
|
||||
|
@ -416,7 +416,7 @@ class MyModule < ApplicationRecord
|
|||
|
||||
records = repository.assigned_rows(self)
|
||||
.select(:id, :name, :created_at, :created_by_id, :repository_id, :parent_id, :archived)
|
||||
{ headers: headers, rows: records, custom_columns: custom_columns }
|
||||
{ headers: headers, rows: records, custom_columns: custom_columns, excluded_columns: excluded_columns }
|
||||
end
|
||||
|
||||
def deep_clone(current_user)
|
||||
|
|
|
@ -64,7 +64,8 @@ class Report < ApplicationRecord
|
|||
result_comments: true,
|
||||
result_order: 'new',
|
||||
activities: true,
|
||||
repositories: []
|
||||
repositories: [],
|
||||
excluded_repository_columns: {}
|
||||
}
|
||||
}.freeze
|
||||
|
||||
|
@ -126,4 +127,13 @@ class Report < ApplicationRecord
|
|||
ReportActions::ReportContent.new(report, content, {}, current_user).save_with_content
|
||||
report
|
||||
end
|
||||
|
||||
def self.default_repository_columns
|
||||
{
|
||||
'-1': I18n.t('repositories.table.id'),
|
||||
'-2': I18n.t('repositories.table.row_name'),
|
||||
'-3': I18n.t('repositories.table.added_on'),
|
||||
'-4': I18n.t('repositories.table.added_by')
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -5,11 +5,12 @@ module Reports::Docx::DrawMyModuleRepository
|
|||
my_module = subject.my_module
|
||||
repository = subject.repository
|
||||
repository = assigned_repository_or_snapshot(my_module, repository)
|
||||
excluded_repository_columns = @settings.dig(:task, :excluded_repository_columns, repository.id.to_s) || {}
|
||||
|
||||
return unless repository && can_read_experiment?(@user, my_module.experiment) &&
|
||||
(repository.is_a?(RepositorySnapshot) || can_read_repository?(@user, repository))
|
||||
|
||||
repository_data = my_module.repository_docx_json(repository)
|
||||
repository_data = my_module.repository_docx_json(repository, excluded_repository_columns)
|
||||
|
||||
return false unless repository_data[:rows].any? && can_read_repository?(@user, repository)
|
||||
|
||||
|
|
|
@ -6,12 +6,16 @@ module Reports::Docx::RepositoryHelper
|
|||
|
||||
def prepare_row_columns(repository_data, my_module = nil, repository = nil)
|
||||
result = [repository_data[:headers]]
|
||||
excluded_columns = repository_data[:excluded_columns]
|
||||
|
||||
repository_data[:rows].each do |record|
|
||||
row = []
|
||||
row.push(record.code)
|
||||
row.push(escape_input(record.archived ? "#{record.name} [#{I18n.t('general.archived')}]" : record.name))
|
||||
row.push(I18n.l(record.created_at, format: :full))
|
||||
row.push(escape_input(record.created_by.full_name))
|
||||
row.push(record.code) unless excluded_columns.include?(-1)
|
||||
unless excluded_columns.include?(-2)
|
||||
row.push(escape_input(record.archived ? "#{record.name} [#{I18n.t('general.archived')}]" : record.name))
|
||||
end
|
||||
row.push(I18n.l(record.created_at, format: :full)) unless excluded_columns.include?(-3)
|
||||
row.push(escape_input(record.created_by.full_name)) unless excluded_columns.include?(-4)
|
||||
|
||||
cell_values = {}
|
||||
custom_cells = record.repository_cells
|
||||
|
@ -38,6 +42,8 @@ module Reports::Docx::RepositoryHelper
|
|||
end
|
||||
|
||||
repository_data[:custom_columns].each do |column_id|
|
||||
next if excluded_columns.include?(column_id)
|
||||
|
||||
value = cell_values[column_id]
|
||||
row.push(value)
|
||||
end
|
||||
|
|
|
@ -55,7 +55,10 @@
|
|||
</span><br>
|
||||
<span class="repositories-items-description">
|
||||
<i class="sn-icon sn-icon-info"></i>
|
||||
<span><%= t("projects.reports.wizard.third_step.assigned_items_description") %></span>
|
||||
<div class="flex-col font-normal">
|
||||
<p><%= t("projects.reports.wizard.third_step.assigned_items_description") %></p>
|
||||
<p><%= t("projects.reports.wizard.third_step.assigned_items_repository_items_description_html") %></p>
|
||||
</div>
|
||||
</span>
|
||||
<ul class="collapse in" id="repositoriesContents">
|
||||
<li>
|
||||
|
@ -68,25 +71,50 @@
|
|||
<ul class="repositories-contents">
|
||||
<% @repositories.each do |repository| %>
|
||||
<li>
|
||||
<span class="sci-checkbox-container">
|
||||
<input type="checkbox"
|
||||
class="sci-checkbox repositories-setting"
|
||||
value="<%= repository.is_a?(RepositorySnapshot) ? repository.parent_id : repository.id %>"
|
||||
<%= 'checked' if report.new_record? ||
|
||||
@project_contents[:repositories].include?(repository.id) ||
|
||||
(repository.is_a?(Repository) && repository.repository_snapshots.exists?(id: @project_contents[:repositories])) %> />
|
||||
<span class="sci-checkbox-label"></span>
|
||||
</span>
|
||||
<%= repository.name %>
|
||||
<% if repository.archived? %>
|
||||
<span class="archived">
|
||||
<%= t("projects.reports.wizard.third_step.archived") %>
|
||||
<div class="flex items-center">
|
||||
<span class="sci-checkbox-container">
|
||||
<input type="checkbox"
|
||||
class="sci-checkbox repositories-setting"
|
||||
value="<%= repository.is_a?(RepositorySnapshot) ? repository.parent_id : repository.id %>"
|
||||
<%= 'checked' if report.new_record? ||
|
||||
@project_contents[:repositories].include?(repository.id) ||
|
||||
(repository.is_a?(Repository) && repository.repository_snapshots.exists?(id: @project_contents[:repositories])) %> />
|
||||
<span class="sci-checkbox-label"></span>
|
||||
</span>
|
||||
<% elsif repository.is_a?(RepositorySnapshot) %>
|
||||
<span class="deleted">
|
||||
<%= t("projects.reports.wizard.third_step.deleted") %>
|
||||
</span>
|
||||
<% end %>
|
||||
<%= repository.name %>
|
||||
<% if repository.archived? %>
|
||||
<span class="archived">
|
||||
<%= t("projects.reports.wizard.third_step.archived") %>
|
||||
</span>
|
||||
<% elsif repository.is_a?(RepositorySnapshot) %>
|
||||
<span class="deleted">
|
||||
<%= t("projects.reports.wizard.third_step.deleted") %>
|
||||
</span>
|
||||
<% end %>
|
||||
<select class="repository-columns"
|
||||
id=<%= "repository-#{repository.id}" %>
|
||||
data-combine-tags="true"
|
||||
data-placeholder="<%= t("projects.reports.wizard.third_step.repository_column.placeholder") %>"
|
||||
data-select-multiple-all-selected="<%= t("projects.reports.wizard.third_step.repository_column.all_selected") %>"
|
||||
data-select-multiple-name="<%= t("projects.reports.wizard.third_step.repository_column.selected") %>"
|
||||
multiple
|
||||
>
|
||||
<% Report.default_repository_columns.each do |key, value| %>
|
||||
<option value="<%= key %>"
|
||||
selected-value="<%= report.settings.dig(:task, :excluded_repository_columns, repository.id.to_s)&.include?(key.to_s.to_i) ? '' : 'selected' %>"
|
||||
>
|
||||
<%= value %>
|
||||
</option>
|
||||
<% end %>
|
||||
<% repository.repository_columns.find_each do |repository_column| %>
|
||||
<option value="<%= repository_column.id %>"
|
||||
selected-value="<%= report.settings.dig(:task, :excluded_repository_columns, repository.id.to_s)&.include?(repository_column.id.to_i) ? '' : 'selected' %>"
|
||||
>
|
||||
<%= repository_column.name %>
|
||||
</option>
|
||||
<% end %>
|
||||
</select>
|
||||
</div>
|
||||
<div class="divider"></div>
|
||||
</li>
|
||||
<% end %>
|
||||
|
|
|
@ -844,6 +844,7 @@ en:
|
|||
step_comments: "Step comments"
|
||||
assigned_items: "Assigned items"
|
||||
assigned_items_description: "Inventories selected below will only contain the items that you assigned to the tasks directly."
|
||||
assigned_items_repository_items_description_html: "You can customize inventory columns <strong>only for the docx report.</strong> The stock management column by default reflects item consumption."
|
||||
include_all_assigned_iitems: "Include all assigned items from the following inventories"
|
||||
results: "Results"
|
||||
all_results: "Include all results elements"
|
||||
|
@ -866,6 +867,10 @@ en:
|
|||
exclude_timestamps: "Exclude timestamps"
|
||||
archived: "[archived]"
|
||||
deleted: "[deleted]"
|
||||
repository_column:
|
||||
placeholder: 'Select columns'
|
||||
all_selected: 'All columns selected'
|
||||
selected: 'columns selected'
|
||||
|
||||
new:
|
||||
report_name_placeholder: "Name your report"
|
||||
|
|
Loading…
Reference in a new issue