mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-03-04 19:53:19 +08:00
change to update samples table state after initialize
This commit is contained in:
parent
114a17ff0f
commit
87dc76f4e3
2 changed files with 10 additions and 11 deletions
|
@ -15,11 +15,11 @@ class CustomField < ActiveRecord::Base
|
|||
class_name: 'User'
|
||||
has_many :sample_custom_fields, inverse_of: :custom_field
|
||||
|
||||
def self.create(opt)
|
||||
user = opt[:user]
|
||||
org = opt[:organization]
|
||||
after_initialize :update_samples_table_state, if: :new_record?
|
||||
|
||||
def update_samples_table_state
|
||||
samples_table = SamplesTable.where(user: user,
|
||||
organization: org)
|
||||
organization: organization)
|
||||
org_status = samples_table.first['status']
|
||||
index = org_status['columns'].count
|
||||
org_status['columns'][index] = { 'visible' => true,
|
||||
|
@ -29,6 +29,5 @@ class CustomField < ActiveRecord::Base
|
|||
'caseInsensitive' => true } }
|
||||
org_status['ColReorder'] << index
|
||||
samples_table.first.update(status: org_status)
|
||||
super(opt)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -10,16 +10,15 @@ class UserOrganization < ActiveRecord::Base
|
|||
belongs_to :organization, inverse_of: :user_organizations
|
||||
|
||||
before_destroy :destroy_associations
|
||||
after_initialize :create_samples_table_state, if: :new_record?
|
||||
|
||||
def role_str
|
||||
I18n.t("user_organizations.enums.role.#{role.to_s}")
|
||||
end
|
||||
|
||||
def self.create(opt)
|
||||
user = opt[:user]
|
||||
org = opt[:organization]
|
||||
def create_samples_table_state
|
||||
org_status = SampleDatatable::SAMPLES_TABLE_DEFAULT_STATE.deep_dup
|
||||
org.custom_fields.each_with_index do |_, index|
|
||||
organization.custom_fields.each_with_index do |_, index|
|
||||
org_status['columns'] << { 'visible' => true,
|
||||
'search' => { 'search' => '',
|
||||
'smart' => true,
|
||||
|
@ -28,8 +27,9 @@ class UserOrganization < ActiveRecord::Base
|
|||
org_status['ColReorder'] << (7 + index)
|
||||
end
|
||||
|
||||
SamplesTable.create(user: user, organization: org, status: org_status)
|
||||
super(opt)
|
||||
SamplesTable.create(user: user,
|
||||
organization: organization,
|
||||
status: org_status)
|
||||
end
|
||||
|
||||
def destroy_associations
|
||||
|
|
Loading…
Reference in a new issue