mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-09-20 23:16:15 +08:00
add SamplesTable for new users
This commit is contained in:
parent
1bc0ca9e75
commit
39b6fa66fe
|
@ -15,6 +15,23 @@ class UserOrganization < ActiveRecord::Base
|
|||
I18n.t("user_organizations.enums.role.#{role.to_s}")
|
||||
end
|
||||
|
||||
def self.create(opt)
|
||||
user = opt[:user]
|
||||
org = opt[:organization]
|
||||
org_status = Constants::SAMPLES_TABLE_DEFAULT_STATE
|
||||
org.custom_fields.each_with_index do |_, index|
|
||||
org_status['columns'] << { 'visible' => true,
|
||||
'search' => { 'search' => '',
|
||||
'smart' => true,
|
||||
'regex' => false,
|
||||
'caseInsensitive' => true } }
|
||||
org_status['ColReorder'] << (7 + index)
|
||||
end
|
||||
|
||||
SamplesTable.create(user: user, organization: org, status: org_status)
|
||||
super(opt)
|
||||
end
|
||||
|
||||
def destroy_associations
|
||||
# Destroy the user from all organization's projects
|
||||
organization.projects.each do |project|
|
||||
|
|
|
@ -239,4 +239,51 @@ class Constants
|
|||
'Isaac Sandaljian',
|
||||
'Markus Rademacher'
|
||||
].freeze
|
||||
|
||||
SAMPLES_TABLE_DEFAULT_STATE = {
|
||||
'time' => 0,
|
||||
'start' => 0,
|
||||
'length' => 10,
|
||||
'order' => [[2, 'desc']],
|
||||
'search' => { 'search' => '',
|
||||
'smart' => true,
|
||||
'regex' => false,
|
||||
'caseInsensitive' => true },
|
||||
'columns' => [{ 'visible' => true,
|
||||
'search' => { 'search' => '',
|
||||
'smart' => true,
|
||||
'regex' => false,
|
||||
'caseInsensitive' => true } },
|
||||
{ 'visible' => true,
|
||||
'search' => { 'search' => '',
|
||||
'smart' => true,
|
||||
'regex' => false,
|
||||
'caseInsensitive' => true } },
|
||||
{ 'visible' => true,
|
||||
'search' => { 'search' => '',
|
||||
'smart' => true,
|
||||
'regex' => false,
|
||||
'caseInsensitive' => true } },
|
||||
{ 'visible' => true,
|
||||
'search' => { 'search' => '',
|
||||
'smart' => true,
|
||||
'regex' => false,
|
||||
'caseInsensitive' => true } },
|
||||
{ 'visible' => true,
|
||||
'search' => { 'search' => '',
|
||||
'smart' => true,
|
||||
'regex' => false,
|
||||
'caseInsensitive' => true } },
|
||||
{ 'visible' => true,
|
||||
'search' => { 'search' => '',
|
||||
'smart' => true,
|
||||
'regex' => false,
|
||||
'caseInsensitive' => true } },
|
||||
{ 'visible' => true,
|
||||
'search' => { 'search' => '',
|
||||
'smart' => true,
|
||||
'regex' => false,
|
||||
'caseInsensitive' => true } }],
|
||||
'ColReorder' => [0, 1, 2, 3, 4, 5, 6]
|
||||
}.freeze
|
||||
end
|
||||
|
|
|
@ -1,52 +1,8 @@
|
|||
class CreateSamplesTables < ActiveRecord::Migration
|
||||
@@def_state = { 'time' => 0,
|
||||
'start' => 0,
|
||||
'length' => 10,
|
||||
'order' => [[2, 'desc']],
|
||||
'search' => { 'search' => '',
|
||||
'smart' => true,
|
||||
'regex' => false,
|
||||
'caseInsensitive' => true },
|
||||
'columns' => [{ 'visible' => true,
|
||||
'search' => { 'search' => '',
|
||||
'smart' => true,
|
||||
'regex' => false,
|
||||
'caseInsensitive' => true } },
|
||||
{ 'visible' => true,
|
||||
'search' => { 'search' => '',
|
||||
'smart' => true,
|
||||
'regex' => false,
|
||||
'caseInsensitive' => true } },
|
||||
{ 'visible' => true,
|
||||
'search' => { 'search' => '',
|
||||
'smart' => true,
|
||||
'regex' => false,
|
||||
'caseInsensitive' => true } },
|
||||
{ 'visible' => true,
|
||||
'search' => { 'search' => '',
|
||||
'smart' => true,
|
||||
'regex' => false,
|
||||
'caseInsensitive' => true } },
|
||||
{ 'visible' => true,
|
||||
'search' => { 'search' => '',
|
||||
'smart' => true,
|
||||
'regex' => false,
|
||||
'caseInsensitive' => true } },
|
||||
{ 'visible' => true,
|
||||
'search' => { 'search' => '',
|
||||
'smart' => true,
|
||||
'regex' => false,
|
||||
'caseInsensitive' => true } },
|
||||
{ 'visible' => true,
|
||||
'search' => { 'search' => '',
|
||||
'smart' => true,
|
||||
'regex' => false,
|
||||
'caseInsensitive' => true } }],
|
||||
'ColReorder' => [0, 1, 2, 3, 4, 5, 6] }
|
||||
|
||||
def change
|
||||
create_table :samples_tables do |t|
|
||||
t.jsonb :status, null: false, default: @@def_state
|
||||
t.jsonb :status, null: false,
|
||||
default: Constants::SAMPLES_TABLE_DEFAULT_STATE
|
||||
# Foreign keys
|
||||
t.references :user, null: false
|
||||
t.references :organization, null: false
|
||||
|
@ -59,7 +15,7 @@ class CreateSamplesTables < ActiveRecord::Migration
|
|||
User.find_each do |user|
|
||||
next unless user.organizations
|
||||
user.organizations.find_each do |org|
|
||||
org_status = @@def_state.deep_dup
|
||||
org_status = Constants::SAMPLES_TABLE_DEFAULT_STATE.deep_dup
|
||||
next unless org.custom_fields
|
||||
org.custom_fields.each_with_index do |_, index|
|
||||
org_status['columns'] << { 'visible' => true,
|
||||
|
|
Loading…
Reference in a new issue