From db35da0cee88335acdccf88ce54a1831a5da08e2 Mon Sep 17 00:00:00 2001 From: aignatov-bio Date: Thu, 11 Jun 2020 12:48:31 +0200 Subject: [PATCH 1/2] Add archiving column to datatable helper --- app/assets/javascripts/my_modules/repositories.js | 2 ++ .../javascripts/repositories/repository_datatable.js | 2 ++ app/assets/javascripts/repository_columns/index.js | 2 +- app/helpers/repository_datatable_helper.rb | 2 ++ app/services/repository_datatable_service.rb | 6 ++++-- .../repositories/_full_view_table.html.erb | 2 ++ app/views/repositories/_repository_table.html.erb | 12 +++++++----- config/initializers/constants.rb | 8 ++++---- config/locales/en.yml | 2 ++ 9 files changed, 26 insertions(+), 12 deletions(-) diff --git a/app/assets/javascripts/my_modules/repositories.js b/app/assets/javascripts/my_modules/repositories.js index 65dd815f8..97fa84c8a 100644 --- a/app/assets/javascripts/my_modules/repositories.js +++ b/app/assets/javascripts/my_modules/repositories.js @@ -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); }); diff --git a/app/assets/javascripts/repositories/repository_datatable.js b/app/assets/javascripts/repositories/repository_datatable.js index 4d0a6652a..9a0f31aaa 100644 --- a/app/assets/javascripts/repositories/repository_datatable.js +++ b/app/assets/javascripts/repositories/repository_datatable.js @@ -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); } }); diff --git a/app/assets/javascripts/repository_columns/index.js b/app/assets/javascripts/repository_columns/index.js index e6f270bbc..1b8525a4b 100644 --- a/app/assets/javascripts/repository_columns/index.js +++ b/app/assets/javascripts/repository_columns/index.js @@ -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(); diff --git a/app/helpers/repository_datatable_helper.rb b/app/helpers/repository_datatable_helper.rb index c82815b6a..699ea025f 100644 --- a/app/helpers/repository_datatable_helper.rb +++ b/app/helpers/repository_datatable_helper.rb @@ -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) } diff --git a/app/services/repository_datatable_service.rb b/app/services/repository_datatable_service.rb index e9f7b73c5..66b110245 100644 --- a/app/services/repository_datatable_service.rb +++ b/app/services/repository_datatable_service.rb @@ -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' diff --git a/app/views/my_modules/repositories/_full_view_table.html.erb b/app/views/my_modules/repositories/_full_view_table.html.erb index bc0cc541c..e6fe398fb 100644 --- a/app/views/my_modules/repositories/_full_view_table.html.erb +++ b/app/views/my_modules/repositories/_full_view_table.html.erb @@ -22,6 +22,8 @@ <%= t("repositories.table.row_name") %> <%= t("repositories.table.added_on") %> <%= t("repositories.table.added_by") %> + <%= t("repositories.table.archived_on") %> + <%= t("repositories.table.archived_by") %> <% @repository.repository_columns.order(:id).each do |column| %> - + - <%= t("repositories.table.assigned") %> + <%= t("repositories.table.assigned") %> <%= t("repositories.table.id") %> <%= t("repositories.table.row_name") %> - <%= t("repositories.table.added_on") %> - <%= t("repositories.table.added_by") %> + <%= t("repositories.table.added_on") %> + <%= t("repositories.table.added_by") %> + <%= t("repositories.table.archived_on") %> + <%= t("repositories.table.archived_by") %> <% repository.repository_columns.order(:id).each do |column| %> 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, diff --git a/config/locales/en.yml b/config/locales/en.yml index ad4747a8c..86203b64c 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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: From fe37afcc41ccafc6d9c4b9c57e07f22d924c5e8d Mon Sep 17 00:00:00 2001 From: aignatov-bio Date: Mon, 15 Jun 2020 09:54:01 +0200 Subject: [PATCH 2/2] Update tests --- ..._table_state_column_update_service_spec.rb | 84 +++++++++---------- .../be_valid_default_repository_state.rb | 10 +-- 2 files changed, 47 insertions(+), 47 deletions(-) diff --git a/spec/services/repository_table_state_column_update_service_spec.rb b/spec/services/repository_table_state_column_update_service_spec.rb index d1fa8fb4d..65b681712 100644 --- a/spec/services/repository_table_state_column_update_service_spec.rb +++ b/spec/services/repository_table_state_column_update_service_spec.rb @@ -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 diff --git a/spec/support/matchers/be_valid_default_repository_state.rb b/spec/support/matchers/be_valid_default_repository_state.rb index 29e28b924..7e66f660a 100644 --- a/spec/support/matchers/be_valid_default_repository_state.rb +++ b/spec/support/matchers/be_valid_default_repository_state.rb @@ -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