Merge pull request #2653 from aignatov-bio/ai-sci-4692-add-archiving-columns-to-datable-helper

Add archiving column to datatable helper [SCI-4692]
This commit is contained in:
aignatov-bio 2020-06-15 15:35:19 +02:00 committed by GitHub
commit a6ff5b1ed8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 73 additions and 59 deletions

View file

@ -200,6 +200,8 @@ var MyModuleRepositories = (function() {
if (!options.assign_mode) {
json.state.columns[0].visible = false;
}
json.state.columns[6].visible = false;
json.state.columns[7].visible = false;
json.state.search.search = null;
callback(json.state);
});

View file

@ -551,6 +551,8 @@ var RepositoryDatatable = (function(global) {
dataType: 'json',
type: 'POST',
success: function(json) {
json.state.columns[6].visible = false; // Here must be switcher depend on active/archive view
json.state.columns[7].visible = false;
callback(json.state);
}
});

View file

@ -279,7 +279,7 @@ var RepositoryColumns = (function() {
// Clear the list
$columnsList.find('li[data-position]').remove();
_.each(TABLE.columns().header(), function(el, index) {
if (index > 1) {
if (!el.dataset.unmanageable) {
let colId = $(el).attr('id');
let colIndex = $(el).attr('data-column-index');
let visible = TABLE.column(colIndex).visible();

View file

@ -12,6 +12,8 @@ module RepositoryDatatableHelper
'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),
'recordInfoUrl': Rails.application.routes.url_helpers.repository_repository_row_path(repository, record)
}

View file

@ -85,7 +85,7 @@ class RepositoryDatatableService
repository_rows = results
end
repository_rows.left_outer_joins(:created_by)
repository_rows.left_outer_joins(:created_by, :archived_by)
.select('repository_rows.*')
.select('COUNT("repository_rows"."id") OVER() AS filtered_count')
.group('repository_rows.id')
@ -105,7 +105,9 @@ class RepositoryDatatableService
'repository_rows.id',
'repository_rows.name',
'repository_rows.created_at',
'users.full_name'
'users.full_name',
'repository_rows.archived_on',
'archived_bies_repository_rows.full_name',
]
@repository.repository_columns.count.times do
array << 'repository_cell.value'

View file

@ -22,6 +22,8 @@
<th id="row-name"><%= t("repositories.table.row_name") %></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>
<th id="archived-by"><%= t("repositories.table.archived_by") %></th>
<% @repository.repository_columns.order(:id).each do |column| %>
<th
class="repository-column"

View file

@ -4,7 +4,7 @@
data-repository-id="<%= repository.id %>"
data-source="<%= repository_index_link %>"
data-toolbar-url="<%= repository_table_toolbar_path(@repository) %>"
data-num-columns="<%= 6 + repository.repository_columns.count %>"
data-num-columns="<%= repository.default_columns_count + repository.repository_columns.count %>"
data-create-record="<%= repository_repository_rows_path(repository) %>"
data-delete-record="<%= repository_delete_records_path(repository) %>"
data-copy-records="<%= repository_copy_records_path(repository) %>"
@ -27,15 +27,17 @@
data-status-url="<%= repository_status_path(@repository) %>">
<thead>
<tr>
<th id="checkbox">
<th id="checkbox" data-unmanageable="true">
<input name="select_all" value="1" type="checkbox" class="sci-checkbox">
<span class="sci-checkbox-label"></span>
</th>
<th id="assigned"><%= t("repositories.table.assigned") %></th>
<th id="assigned" data-unmanageable="true"><%= t("repositories.table.assigned") %></th>
<th id="row-id"><%= t("repositories.table.id") %></th>
<th id="row-name"><%= t("repositories.table.row_name") %></th>
<th id="added-on"><%= t("repositories.table.added_on") %></th>
<th id="added-by"><%= t("repositories.table.added_by") %></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" data-unmanageable="true"><%= t("repositories.table.archived_on") %></th>
<th id="archived-by" data-unmanageable="true"><%= t("repositories.table.archived_by") %></th>
<% repository.repository_columns.order(:id).each do |column| %>
<th
class="repository-column"

View file

@ -940,7 +940,7 @@ class Constants
REPOSITORY_TABLE_DEFAULT_STATE = {
'time' => 0,
'start' => 0,
'length' => 6,
'length' => 8,
'order' => [[2, 'asc']], # Default sorting by 'ID' column
'search' => { 'search' => '',
'smart' => true,
@ -948,11 +948,11 @@ class Constants
'caseInsensitive' => true },
'columns' => [],
'assigned' => 'assigned',
'ColReorder' => [*0..5]
'ColReorder' => [*0..7]
}
6.times do |i|
8.times do |i|
REPOSITORY_TABLE_DEFAULT_STATE['columns'] << {
'visible' => true,
'visible' => (i < 6),
'searchable' => (i >= 1), # Checkboxes column is not searchable
'search' => { 'search' => '',
'smart' => true,

View file

@ -1127,6 +1127,8 @@ en:
row_name: "Name"
added_on: "Added on"
added_by: "Added by"
archived_on: "Archived on"
archived_by: "Archived by"
enter_row_name: "Enter name"
locked_item: "This is read-only item."
assets:

View file

@ -70,15 +70,15 @@ describe RepositoryTableStateColumnUpdateService do
end
it 'should calculate correct length' do
expect(initial_state_1.state['length']).to eq 8
expect(initial_state_2.state['length']).to eq 8
expect(initial_state_1.state['length']).to eq 10
expect(initial_state_2.state['length']).to eq 10
service.update_states_with_new_column(repository)
service.update_states_with_new_column(repository)
[user_1, user_2].each do |user|
state = RepositoryTableStateService.new(user, repository).load_state
expect(state.state['length']).to eq 10
expect(state.state['length']).to eq 12
end
end
@ -142,11 +142,11 @@ describe RepositoryTableStateColumnUpdateService do
end
it 'should keep column order as it was' do
initial_state_1.state['ColReorder'] = [5, 3, 2, 0, 1, 4, 6, 7]
initial_state_1.state['ColReorder'] = [5, 3, 2, 0, 1, 4, 6, 7, 8, 9]
RepositoryTableStateService.new(user_1, repository).update_state(
initial_state_1.state
)
initial_state_2.state['ColReorder'] = [0, 6, 1, 4, 5, 7, 2, 3]
initial_state_2.state['ColReorder'] = [0, 6, 1, 4, 5, 7, 2, 3, 8, 9]
RepositoryTableStateService.new(user_2, repository).update_state(
initial_state_2.state
)
@ -155,9 +155,9 @@ describe RepositoryTableStateColumnUpdateService do
service.update_states_with_new_column(repository)
state_1 = RepositoryTableStateService.new(user_1, repository).load_state
expect(state_1.state['ColReorder']).to eq([5, 3, 2, 0, 1, 4, 6, 7, 8, 9])
expect(state_1.state['ColReorder']).to eq([5, 3, 2, 0, 1, 4, 6, 7, 8, 9, 10, 11])
state_2 = RepositoryTableStateService.new(user_2, repository).load_state
expect(state_2.state['ColReorder']).to eq([0, 6, 1, 4, 5, 7, 2, 3, 8, 9])
expect(state_2.state['ColReorder']).to eq([0, 6, 1, 4, 5, 7, 2, 3, 8, 9, 10, 11])
end
end
@ -177,8 +177,8 @@ describe RepositoryTableStateColumnUpdateService do
expect(initial_state_1).to be_valid_default_repository_table_state(2)
expect(initial_state_2).to be_valid_default_repository_table_state(2)
service.update_states_with_removed_column(repository, 6)
service.update_states_with_removed_column(repository, 6)
service.update_states_with_removed_column(repository, 8)
service.update_states_with_removed_column(repository, 8)
[user_1, user_2].each do |user|
state = RepositoryTableStateService.new(user, repository).load_state
@ -187,15 +187,15 @@ describe RepositoryTableStateColumnUpdateService do
end
it 'should calculate correct length' do
expect(initial_state_1.state['length']).to eq 8
expect(initial_state_2.state['length']).to eq 8
expect(initial_state_1.state['length']).to eq 10
expect(initial_state_2.state['length']).to eq 10
service.update_states_with_removed_column(repository, 6)
service.update_states_with_removed_column(repository, 6)
service.update_states_with_removed_column(repository, 8)
service.update_states_with_removed_column(repository, 8)
[user_1, user_2].each do |user|
state = RepositoryTableStateService.new(user, repository).load_state
expect(state.state['length']).to eq 6
expect(state.state['length']).to eq 8
end
end
@ -204,13 +204,13 @@ describe RepositoryTableStateColumnUpdateService do
RepositoryTableStateService.new(user_1, repository).update_state(
initial_state_1.state
)
initial_state_2.state['order'] = [[7, 'asc']]
initial_state_2.state['order'] = [[9, 'asc']]
RepositoryTableStateService.new(user_2, repository).update_state(
initial_state_2.state
)
service.update_states_with_removed_column(repository, 6)
service.update_states_with_removed_column(repository, 6)
service.update_states_with_removed_column(repository, 8)
service.update_states_with_removed_column(repository, 8)
state_1 = RepositoryTableStateService.new(user_1, repository).load_state
expect(state_1.state['order']).to eq([[3, 'desc']])
@ -232,8 +232,8 @@ describe RepositoryTableStateColumnUpdateService do
initial_state_2.state
)
service.update_states_with_removed_column(repository, 6)
service.update_states_with_removed_column(repository, 6)
service.update_states_with_removed_column(repository, 8)
service.update_states_with_removed_column(repository, 8)
state_1 = RepositoryTableStateService.new(user_1, repository).load_state
expect(state_1.state['search']).to eq search_1
@ -247,19 +247,19 @@ describe RepositoryTableStateColumnUpdateService do
RepositoryTableStateService.new(user_1, repository).update_state(
initial_state_1.state.merge('columns' => cols_1)
)
cols_1.delete_at(6)
cols_1.delete_at(6)
cols_1.delete_at(8)
cols_1.delete_at(8)
cols_2 = initial_state_2.state['columns'].deep_dup
cols_2[4]['searchable'] = false
RepositoryTableStateService.new(user_2, repository).update_state(
initial_state_2.state.merge('columns' => cols_2)
)
cols_2.delete_at(6)
cols_2.delete_at(6)
cols_2.delete_at(8)
cols_2.delete_at(8)
service.update_states_with_removed_column(repository, 6)
service.update_states_with_removed_column(repository, 6)
service.update_states_with_removed_column(repository, 8)
service.update_states_with_removed_column(repository, 8)
state_1 = RepositoryTableStateService.new(user_1, repository).load_state
expect(state_1.state['columns']).to eq cols_1
@ -269,26 +269,26 @@ describe RepositoryTableStateColumnUpdateService do
it 'should keep column order as it was' do
initial_state_1.state['ColReorder'] =
[5, 3, 2, 0, 1, 4, 6, 7]
[5, 3, 2, 0, 1, 4, 6, 7, 8, 9]
RepositoryTableStateService.new(user_1, repository).update_state(
initial_state_1.state
)
initial_state_2.state['ColReorder'] =
[0, 6, 1, 4, 5, 7, 2, 3]
[0, 6, 1, 4, 5, 7, 2, 3, 8, 9]
RepositoryTableStateService.new(user_2, repository).update_state(
initial_state_2.state
)
service.update_states_with_removed_column(repository, 6)
service.update_states_with_removed_column(repository, 6)
service.update_states_with_removed_column(repository, 8)
service.update_states_with_removed_column(repository, 8)
state_1 = RepositoryTableStateService.new(user_1, repository).load_state
expect(state_1.state['ColReorder']).to eq(
[5, 3, 2, 0, 1, 4]
[5, 3, 2, 0, 1, 4, 6, 7]
)
state_2 = RepositoryTableStateService.new(user_2, repository).load_state
expect(state_2.state['ColReorder']).to eq(
[0, 1, 4, 5, 2, 3]
[0, 6, 1, 4, 5, 7, 2, 3]
)
end
end
@ -307,12 +307,12 @@ describe RepositoryTableStateColumnUpdateService do
let!(:initial_state) do
state = RepositoryTableStateService.new(user_1, repository)
.create_default_state
state.state['order'] = [[8, 'desc']]
state.state['order'] = [[10, 'desc']]
(0..9).each do |idx|
state.state['columns'][idx]['search']['search'] = "search_#{idx}"
end
state.state['ColReorder'] =
[0, 1, 2, 9, 8, 4, 7, 3, 5, 6]
[0, 1, 2, 9, 8, 4, 7, 3, 5, 6, 10, 11]
RepositoryTableStateService.new(user_1, repository).update_state(
state.state
)
@ -327,33 +327,33 @@ describe RepositoryTableStateColumnUpdateService do
state = RepositoryTableStateService.new(user_1, repository).load_state
expect(state).to be_valid_repository_table_state(5)
expect(state.state['ColReorder']).to eq(
[0, 1, 2, 9, 8, 4, 7, 3, 5, 6, 10]
[0, 1, 2, 9, 8, 4, 7, 3, 5, 6, 10, 11, 12]
)
service.update_states_with_removed_column(repository, 7)
service.update_states_with_removed_column(repository, 9)
state = RepositoryTableStateService.new(user_1, repository).load_state
expect(state).to be_valid_repository_table_state(4)
expect(state.state['ColReorder']).to eq(
[0, 1, 2, 8, 7, 4, 3, 5, 6, 9]
[0, 1, 2, 8, 4, 7, 3, 5, 6, 9, 10, 11]
)
expect(state.state['order']).to eq([[7, 'desc']])
expect(state.state['order']).to eq([[9, 'desc']])
service.update_states_with_removed_column(repository, 7)
service.update_states_with_removed_column(repository, 9)
state = RepositoryTableStateService.new(user_1, repository).load_state
expect(state).to be_valid_repository_table_state(3)
expect(state.state['ColReorder']).to eq(
[0, 1, 2, 7, 4, 3, 5, 6, 8]
[0, 1, 2, 8, 4, 7, 3, 5, 6, 9, 10]
)
expect(state.state['order']).to eq([[2, 'asc']])
service.update_states_with_removed_column(repository, 7)
service.update_states_with_removed_column(repository, 9)
state = RepositoryTableStateService.new(user_1, repository).load_state
expect(state).to be_valid_repository_table_state(2)
expect(state.state['ColReorder']).to eq(
[0, 1, 2, 4, 3, 5, 6, 7]
[0, 1, 2, 8, 4, 7, 3, 5, 6, 9]
)
service.update_states_with_new_column(repository)
@ -362,7 +362,7 @@ describe RepositoryTableStateColumnUpdateService do
state = RepositoryTableStateService.new(user_1, repository).load_state
expect(state).to be_valid_repository_table_state(4)
expect(state.state['ColReorder']).to eq(
[0, 1, 2, 4, 3, 5, 6, 7, 8, 9]
[0, 1, 2, 8, 4, 7, 3, 5, 6, 9, 10, 11]
)
end
end

View file

@ -7,15 +7,15 @@ RSpec::Matchers.define :be_valid_default_repository_table_state do |nr_of_cols|
state = subject.state
cols_length = 6 + nr_of_cols
cols_array = [*0..(5 + nr_of_cols)]
cols_length = 8 + nr_of_cols
cols_array = [*0..(7 + nr_of_cols)]
expect(state).to be_an_instance_of Hash
expect(state).to include(
'time',
'columns',
'start' => 0,
'length' => cols_length, # 6 default columns + parameter
'length' => cols_length, # 8 default columns + parameter
'order' => [[2, 'asc']],
'search' => {
'search' => '',
@ -28,10 +28,10 @@ RSpec::Matchers.define :be_valid_default_repository_table_state do |nr_of_cols|
)
expect(state['columns']).to be_an_instance_of Array
expect(state['columns'].length).to eq(6 + nr_of_cols)
expect(state['columns'].length).to eq(cols_length)
state['columns'].each_with_index do |val, i|
expect(val).to include(
'visible' => true,
'visible' => !([6, 7].include? i),
'searchable' => (i != 0),
'search' => {
'search' => '', 'smart' => true, 'regex' => false, 'caseInsensitive' => true