mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-10 23:25:31 +08:00
Add explicit ordering to samples_tables [SCI-2148][SCI-2149]
This commit is contained in:
parent
e0834a57cf
commit
269f7d74fa
3 changed files with 12 additions and 10 deletions
|
@ -1,7 +1,9 @@
|
||||||
class UserSamplesController < ApplicationController
|
class UserSamplesController < ApplicationController
|
||||||
def save_samples_table_status
|
def save_samples_table_status
|
||||||
samples_table = SamplesTable.where(user: @current_user,
|
samples_table = SamplesTable.where(user: @current_user,
|
||||||
team: params[:team]).first
|
team: params[:team])
|
||||||
|
.order(:id)
|
||||||
|
.first
|
||||||
if samples_table
|
if samples_table
|
||||||
samples_table.update(status: params[:state])
|
samples_table.update(status: params[:state])
|
||||||
else
|
else
|
||||||
|
@ -20,7 +22,7 @@ class UserSamplesController < ApplicationController
|
||||||
|
|
||||||
def load_samples_table_status
|
def load_samples_table_status
|
||||||
samples_table_state = SamplesTable.find_status(current_user,
|
samples_table_state = SamplesTable.find_status(current_user,
|
||||||
current_team).first
|
current_team)
|
||||||
if samples_table_state.blank?
|
if samples_table_state.blank?
|
||||||
st = SamplesTable.new(user: current_user, team: current_team)
|
st = SamplesTable.new(user: current_user, team: current_team)
|
||||||
st.save
|
st.save
|
||||||
|
|
|
@ -489,10 +489,7 @@ class SampleDatatable < CustomDatatable
|
||||||
end
|
end
|
||||||
|
|
||||||
def generate_sortable_displayed_columns
|
def generate_sortable_displayed_columns
|
||||||
sort_order = SamplesTable.where(user: @user,
|
sort_order = SamplesTable.find_status(@user, @team)['ColReorder']
|
||||||
team: @team)
|
|
||||||
.pluck(:status)
|
|
||||||
.first['ColReorder']
|
|
||||||
|
|
||||||
sort_order.shift
|
sort_order.shift
|
||||||
sort_order.map! { |i| (i.to_i - 1).to_s }
|
sort_order.map! { |i| (i.to_i - 1).to_s }
|
||||||
|
|
|
@ -3,15 +3,18 @@ class SamplesTable < ApplicationRecord
|
||||||
belongs_to :team, inverse_of: :samples_tables, optional: true
|
belongs_to :team, inverse_of: :samples_tables, optional: true
|
||||||
|
|
||||||
validates :user, :team, presence: true
|
validates :user, :team, presence: true
|
||||||
validates :user, uniqueness: { scope: :team }
|
|
||||||
|
|
||||||
scope :find_status,
|
scope :find_status, (lambda do |user, team|
|
||||||
->(user, team) { where(user: user, team: team).pluck(:status) }
|
where(user: user, team: team)
|
||||||
|
.order(:id).pluck(:status).first
|
||||||
|
end)
|
||||||
|
|
||||||
def self.update_samples_table_state(custom_field, column_index)
|
def self.update_samples_table_state(custom_field, column_index)
|
||||||
samples_table = SamplesTable.where(user: custom_field.user,
|
samples_table = SamplesTable.where(user: custom_field.user,
|
||||||
team: custom_field.team)
|
team: custom_field.team)
|
||||||
team_status = samples_table.first['status']
|
.order(:id)
|
||||||
|
.first
|
||||||
|
team_status = samples_table['status']
|
||||||
if column_index
|
if column_index
|
||||||
# delete column
|
# delete column
|
||||||
team_status['columns'].delete(column_index)
|
team_status['columns'].delete(column_index)
|
||||||
|
|
Loading…
Add table
Reference in a new issue