diff --git a/app/models/user_organization.rb b/app/models/user_organization.rb index e964e6c91..ed4a0353d 100644 --- a/app/models/user_organization.rb +++ b/app/models/user_organization.rb @@ -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| diff --git a/config/initializers/constants.rb b/config/initializers/constants.rb index b6c48d551..2fdc408d7 100644 --- a/config/initializers/constants.rb +++ b/config/initializers/constants.rb @@ -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 diff --git a/db/migrate/20161123161514_create_samples_tables.rb b/db/migrate/20161123161514_create_samples_tables.rb index f643c4235..26cd6a69e 100644 --- a/db/migrate/20161123161514_create_samples_tables.rb +++ b/db/migrate/20161123161514_create_samples_tables.rb @@ -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,