Add explicit ordering to samples_tables [SCI-2148][SCI-2149]

This commit is contained in:
Oleksii Kriuchykhin 2018-03-12 18:07:35 +01:00
parent e0834a57cf
commit 269f7d74fa
3 changed files with 12 additions and 10 deletions

View file

@ -1,7 +1,9 @@
class UserSamplesController < ApplicationController
def save_samples_table_status
samples_table = SamplesTable.where(user: @current_user,
team: params[:team]).first
team: params[:team])
.order(:id)
.first
if samples_table
samples_table.update(status: params[:state])
else
@ -20,7 +22,7 @@ class UserSamplesController < ApplicationController
def load_samples_table_status
samples_table_state = SamplesTable.find_status(current_user,
current_team).first
current_team)
if samples_table_state.blank?
st = SamplesTable.new(user: current_user, team: current_team)
st.save

View file

@ -489,10 +489,7 @@ class SampleDatatable < CustomDatatable
end
def generate_sortable_displayed_columns
sort_order = SamplesTable.where(user: @user,
team: @team)
.pluck(:status)
.first['ColReorder']
sort_order = SamplesTable.find_status(@user, @team)['ColReorder']
sort_order.shift
sort_order.map! { |i| (i.to_i - 1).to_s }

View file

@ -3,15 +3,18 @@ class SamplesTable < ApplicationRecord
belongs_to :team, inverse_of: :samples_tables, optional: true
validates :user, :team, presence: true
validates :user, uniqueness: { scope: :team }
scope :find_status,
->(user, team) { where(user: user, team: team).pluck(:status) }
scope :find_status, (lambda do |user, team|
where(user: user, team: team)
.order(:id).pluck(:status).first
end)
def self.update_samples_table_state(custom_field, column_index)
samples_table = SamplesTable.where(user: custom_field.user,
team: custom_field.team)
team_status = samples_table.first['status']
.order(:id)
.first
team_status = samples_table['status']
if column_index
# delete column
team_status['columns'].delete(column_index)