diff --git a/app/assets/javascripts/experiments/table.js b/app/assets/javascripts/experiments/table.js index f0f0839d8..5f0f2bea0 100644 --- a/app/assets/javascripts/experiments/table.js +++ b/app/assets/javascripts/experiments/table.js @@ -245,6 +245,7 @@ var ExperimnetTable = { let visibleColumns = $('.table-display-modal .fa-eye').map((_i, col) => col.dataset.column).toArray(); // Update columns on backend - $.post('', { columns: visibleColumns }, () => {}); + $.post($('.table-display-modal').data('column-state-url'), { columns: visibleColumns }, () => {}); $('.experiment-table')[0].style.setProperty('--columns-count', $('.table-display-modal .fa-eye').length + 1); }); diff --git a/app/controllers/experiments_controller.rb b/app/controllers/experiments_controller.rb index bb1b3a682..8dba38dc9 100644 --- a/app/controllers/experiments_controller.rb +++ b/app/controllers/experiments_controller.rb @@ -92,6 +92,7 @@ class ExperimentsController < ApplicationController redirect_to module_archive_experiment_path(@experiment) if @experiment.archived_branch? @project = @experiment.project @active_modules = @experiment.my_modules.active.order(:name) + @my_module_visible_table_columns = current_user.settings["visible_my_module_table_columns"].present? ? current_user.settings["visible_my_module_table_columns"] : [] end def load_table diff --git a/app/controllers/my_modules_controller.rb b/app/controllers/my_modules_controller.rb index b54ee9077..b1bb6f990 100644 --- a/app/controllers/my_modules_controller.rb +++ b/app/controllers/my_modules_controller.rb @@ -6,13 +6,13 @@ class MyModulesController < ApplicationController include ActionView::Helpers::UrlHelper include ApplicationHelper - before_action :load_vars, except: %i(restore_group) + before_action :load_vars, except: %i(restore_group save_table_state) before_action :check_create_permissions, only: %i(new create) before_action :check_archive_permissions, only: %i(update) before_action :check_manage_permissions, only: %i( create description due_date update_description update_protocol_description update_protocol ) - before_action :check_read_permissions, except: %i(update update_description update_protocol_description restore_group) + before_action :check_read_permissions, except: %i(update update_description update_protocol_description restore_group save_table_state) before_action :check_update_state_permissions, only: :update_state before_action :set_inline_name_editing, only: %i(protocols results activities archive) before_action :load_experiment_my_modules, only: %i(protocols results activities archive) @@ -30,8 +30,8 @@ class MyModulesController < ApplicationController def create max_xy = @experiment.my_modules.select('MAX("my_modules"."x") AS x, MAX("my_modules"."y") AS y').take - x = max_xy ? (max_xy.x + 10) : 1 - y = max_xy ? (max_xy.y + 10) : 1 + x = max_xy.x ? (max_xy.x + 10) : 1 + y = max_xy.y ? (max_xy.y + 10) : 1 @my_module = @experiment.my_modules.new(my_module_params) @my_module.assign_attributes(created_by: current_user, last_modified_by: current_user, x: x, y: y) @my_module.transaction do @@ -77,6 +77,11 @@ class MyModulesController < ApplicationController end end + def save_table_state + current_user.settings.update(visible_my_module_table_columns: params[:columns]) + current_user.save! + end + def status_state respond_to do |format| format.json do diff --git a/app/views/experiments/_table_display_modal.html.erb b/app/views/experiments/_table_display_modal.html.erb index c3f382ba1..effb8eed8 100644 --- a/app/views/experiments/_table_display_modal.html.erb +++ b/app/views/experiments/_table_display_modal.html.erb @@ -1,4 +1,4 @@ -