From 4df8e1ffe3252dac4db340bd1e17bf8b30fbb67e Mon Sep 17 00:00:00 2001 From: rekonder Date: Thu, 8 Jun 2017 23:31:43 +0200 Subject: [PATCH] Fixed bugs with duplicated generated csv, toggle columns and exportig right columns of selected repository --- .../repositories/repository_datatable.js | 35 +++++++------------ app/controllers/repositories_controller.rb | 6 ++-- app/views/repositories/_repository.html.erb | 1 + 3 files changed, 15 insertions(+), 27 deletions(-) diff --git a/app/assets/javascripts/repositories/repository_datatable.js b/app/assets/javascripts/repositories/repository_datatable.js index e33823dae..e2254c613 100644 --- a/app/assets/javascripts/repositories/repository_datatable.js +++ b/app/assets/javascripts/repositories/repository_datatable.js @@ -226,7 +226,8 @@ $('form#form-export').submit(function(e) { appendSamplesIdToForm(form); // Append visible column information - $('table#repository-table thead tr').children('th').each(function(i) { + $('.active table#repository-table thead tr').children('th') + .each(function(i) { var th = $(this); var val; if ($(th).attr('id') === 'checkbox' || $(th).attr('id') === 'assigned') @@ -685,26 +686,7 @@ function updateButtons() { $('th').removeClass('disable-click'); $('.repository-row-selector').removeClass('disabled'); $('.repository-row-selector').prop('disabled', false); - if (rowsSelected.length === 1) { - $('#editRepositoryRecord').prop('disabled', false); - $('#editRepositoryRecord').removeClass('disabled'); - $('#deleteRepositoryRecordsButton').prop('disabled', false); - $('#deleteRepositoryRecordsButton').removeClass('disabled'); - $('#exportRepositoriesButton').removeClass('disabled'); - $('#exportRepositoriesButton').prop('disabled', false); - $('#exportRepositoriesButton').on('click', function() { - $('#exportRepositoryModal') - .modal('show') - }); - $('#export-repositories').on('click', function() { - animateSpinner(null, true); - $('#form-export').submit(); - }); - $('#assignRepositoryRecords').removeClass('disabled'); - $('#assignRepositoryRecords').prop('disabled', false); - $('#unassignRepositoryRecords').removeClass('disabled'); - $('#unassignRepositoryRecords').prop('disabled', false); - } else if (rowsSelected.length === 0) { + if (rowsSelected.length === 0) { $('#editRepositoryRecord').prop('disabled', true); $('#editRepositoryRecord').addClass('disabled'); $('#deleteRepositoryRecordsButton').prop('disabled', true); @@ -718,8 +700,13 @@ function updateButtons() { $('#unassignRepositoryRecords').addClass('disabled'); $('#unassignRepositoryRecords').prop('disabled', true); } else { - $('#editRepositoryRecord').prop('disabled', true); - $('#editRepositoryRecord').addClass('disabled'); + if (rowsSelected.length === 1) { + $('#editRepositoryRecord').prop('disabled', false); + $('#editRepositoryRecord').removeClass('disabled'); + } else { + $('#editRepositoryRecord').prop('disabled', true); + $('#editRepositoryRecord').addClass('disabled'); + } $('#deleteRepositoryRecordsButton').prop('disabled', false); $('#deleteRepositoryRecordsButton').removeClass('disabled'); $('#exportRepositoriesButton').removeClass('disabled'); @@ -748,6 +735,7 @@ function updateButtons() { $('#deleteRepositoryRecordsButton').prop('disabled', true); $('#exportRepositoriesButton').addClass('disabled'); $('#exportRepositoriesButton').off('click'); + $('#export-repositories').off('click'); $('#assignRepositoryRecords').addClass('disabled'); $('#assignRepositoryRecords').prop('disabled', true); $('#unassignRepositoryRecords').addClass('disabled'); @@ -1045,6 +1033,7 @@ function changeToEditMode() { if (!_.isEmpty(searchText)) { table.search(searchText).draw(); } + initRowSelection(); }); } diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index c8f9b55c0..b55dc397f 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -1,5 +1,5 @@ class RepositoriesController < ApplicationController - before_action :load_vars, except: [:repository_table_index, :export_repository] + before_action :load_vars, except: %i(repository_table_index export_repository) before_action :check_view_all_permissions, only: :index before_action :check_edit_and_destroy_permissions, only: %(destroy destroy_modal rename_modal update) @@ -7,7 +7,6 @@ class RepositoriesController < ApplicationController %(copy_modal copy) before_action :check_create_permissions, only: %(create_new_modal create) - before_action :generate_zip, only: :export_repository def index render('repositories/index') @@ -273,8 +272,7 @@ class RepositoriesController < ApplicationController sample_row << I18n.l(row.created_at, format: :full) else record = row_record.joins(:repository_columns, :repository_cells) - .where(repository_columns: { id: header }) - .take + .where(repository_columns: { id: header }).take if record sample_row << record.repository_cells.take.value.data else diff --git a/app/views/repositories/_repository.html.erb b/app/views/repositories/_repository.html.erb index bf4bd9b81..be704eb98 100644 --- a/app/views/repositories/_repository.html.erb +++ b/app/views/repositories/_repository.html.erb @@ -88,3 +88,4 @@ repository_index_link: repository_table_index_path(repository) } %> +