Add relationship column to the inventory [SCI-9356]

This commit is contained in:
Andrej 2023-09-26 08:43:20 +02:00
parent a65101cd61
commit 1aa9b17b1a
10 changed files with 48 additions and 10 deletions

View file

@ -128,6 +128,12 @@ var MyModuleRepositories = (function() {
render: function(data, type, row) {
return "<a href='" + row.recordInfoUrl + "' class='record-info-link'>" + data + '</a>';
}
}, {
targets: 4,
class: 'relationship',
render: function(data) {
return $.fn.dataTable.render.RelationshipValue(data);
}
});
} else {
columnDefs.push({

View file

@ -266,3 +266,17 @@ $.fn.dataTable.render.RepositoryStockConsumptionValue = function(data = {}) {
$.fn.dataTable.render.defaultRepositoryStockConsumptionValue = function() {
return $.fn.dataTable.render.RepositoryStockConsumptionValue();
};
$.fn.dataTable.render.RelationshipValue = function(data) {
if (data > 0) {
return `<div class="flex flex-wrap items-center">
<i class="sn-icon sn-icon-navigator"></i>
<a class="bg-sn-science-blue flex flex-wrap text-white w-4 h-4
ml-2 rounded-lg content-center justify-center text-xs" href='#'>
${data}
</a>
</div>`;
}
return '';
};

View file

@ -675,8 +675,17 @@ var RepositoryDatatable = (function(global) {
+ "class='record-info-link'>" + data + '</a>';
}
}, {
// Added on column
targets: 4,
class: 'relationship',
visible: true,
searchable: false,
orderable: true,
render: function(data) {
return $.fn.dataTable.render.RelationshipValue(data);
}
}, {
// Added on column
targets: 5,
class: 'added-on',
visible: true
}, {

View file

@ -232,10 +232,11 @@ module RepositoryDatatableHelper
'1': assigned_row(record),
'2': record.code,
'3': escape_input(record.name),
'4': I18n.l(record.created_at, format: :full),
'5': escape_input(record.created_by.full_name),
'6': (record.archived_on ? I18n.l(record.archived_on, format: :full) : ''),
'7': escape_input(record.archived_by&.full_name)
'4': record.relationship_count,
'5': I18n.l(record.created_at, format: :full),
'6': escape_input(record.created_by.full_name),
'7': (record.archived_on ? I18n.l(record.archived_on, format: :full) : ''),
'8': escape_input(record.archived_by&.full_name)
}
end

View file

@ -188,4 +188,8 @@ class RepositoryRow < ApplicationRecord
'-'
end
end
def relationship_count
parent_connections.size + child_connections.size
end
end

View file

@ -26,6 +26,7 @@
<% end %>
<th id="row-id"><%= t("repositories.table.id") %></th>
<th id="row-name"><%= t("repositories.table.row_name") %></th>
<th id="relationship"><%= t("repositories.table.relationship") %></th>
<th id="added-on"><%= t("repositories.table.added_on") %></th>
<th id="added-by"><%= t("repositories.table.added_by") %></th>
<th id="archived-on"><%= t("repositories.table.archived_on") %></th>

View file

@ -40,6 +40,7 @@
<% end %>
<th id="row-id"><%= t("repositories.table.id") %></th>
<th id="row-name"><%= t("repositories.table.row_name") %></th>
<th id="relationship"><%= t("repositories.table.relationship") %></th>
<th id="added-on" ><%= t("repositories.table.added_on") %></th>
<th id="added-by" ><%= t("repositories.table.added_by") %></th>
<th id="archived-on"><%= t("repositories.table.archived_on") %></th>

View file

@ -344,12 +344,12 @@ class Constants
'order' => [[3, 'asc']], # Default sorting by 'name' column
'columns' => [],
'assigned' => 'assigned',
'ColReorder' => [*0..7]
'ColReorder' => [*0..8]
}
8.times do |i|
9.times do |i|
REPOSITORY_TABLE_DEFAULT_STATE['columns'] << {
'visible' => (i < 6),
'searchable' => (i >= 1), # Checkboxes column is not searchable
'visible' => (i < 7),
'searchable' => (i >= 1 && i != 4), # Checkboxes and relationship column is not searchable
'search' => { 'search' => '',
'smart' => true,
'regex' => false,

View file

@ -1941,6 +1941,7 @@ en:
added_by: "Added by"
archived_on: "Archived on"
archived_by: "Archived by"
relationship: "Relationship"
row_consumption: "Consumed"
enter_row_name: "Enter name"
locked_item: "This is read-only item."

View file

@ -22,7 +22,8 @@ module.exports = {
current: 'currentColor',
'brand-warning': '#f0ad4e',
'sn-blue': '#104DA9',
'sn-grey': '#98a2b3'
'sn-grey': '#98a2b3',
'sn-science-blue': '#3B99FD'
}
}
},