Merge pull request #1034 from okriuchykhin/ok_SCI_2148

Add explicit ordering to samples_tables [SCI-2148][SCI-2149]
This commit is contained in:
okriuchykhin 2018-03-16 11:15:23 +01:00 committed by GitHub
commit 95425dc64b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 11 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)
@ -38,7 +41,7 @@ class SamplesTable < ApplicationRecord
SAMPLES_TABLE_DEFAULT_STATE['columns'].first
team_status['ColReorder'].insert(2, index)
end
samples_table.first.update(status: team_status)
samples_table.update(status: team_status)
end
def self.create_samples_table_state(user_team)