mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-09-20 14:45:56 +08:00
scheduling creation of demo project at the sign in time
remove wrong schema, fix comment, add migration
This commit is contained in:
parent
2ba040980f
commit
fa7bba9de7
|
@ -47,7 +47,17 @@ class Users::SessionsController < Devise::SessionsController
|
|||
|
||||
def after_sign_in
|
||||
flash[:system_notification_modal] = true
|
||||
|
||||
# Schedule templates creation for user
|
||||
TemplatesService.new.schedule_creation_for_user(current_user)
|
||||
|
||||
# Schedule demo project creation for user
|
||||
current_user.created_teams.each do |team|
|
||||
FirstTimeDataGenerator.delay(
|
||||
queue: :new_demo_project,
|
||||
priority: 10
|
||||
).seed_demo_data_with_id(current_user.id, team.id)
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
|
|
|
@ -11,6 +11,38 @@ module FirstTimeDataGenerator
|
|||
# Do nothing
|
||||
return unless team
|
||||
|
||||
# Skip this team if user already has a demo project
|
||||
return if team.projects.where(demo: true).any?
|
||||
|
||||
name = '[NEW] Demo project by SciNote'
|
||||
exp_name = 'Polymerase chain reaction'
|
||||
# If there is an existing demo project, archive and rename it
|
||||
if team.projects.where(name: name).present?
|
||||
# TODO: check if we still need this code
|
||||
# old = team.projects.where(name: 'Demo project - qPCR')[0]
|
||||
# old.archive! user
|
||||
i = 1
|
||||
while team.projects.where(
|
||||
name: name = "#{name} (#{i})"
|
||||
).present?
|
||||
i += 1
|
||||
end
|
||||
end
|
||||
|
||||
project = Project.create(
|
||||
visibility: 0,
|
||||
name: name,
|
||||
due_date: nil,
|
||||
team: team,
|
||||
created_by: user,
|
||||
created_at: generate_random_time(1.week.ago),
|
||||
last_modified_by: user,
|
||||
archived: false,
|
||||
template: false,
|
||||
demo: true
|
||||
)
|
||||
|
||||
|
||||
# check if samples repo already exist, then create custom repository samples
|
||||
repository = Repository.where(team: team).where(name: REPO_SAMPLES_NAME)
|
||||
repository =
|
||||
|
@ -192,33 +224,6 @@ module FirstTimeDataGenerator
|
|||
)
|
||||
end
|
||||
|
||||
name = 'Demo project'
|
||||
name = '[NEW] Demo project by SciNote'
|
||||
exp_name = 'Polymerase chain reaction'
|
||||
# If there is an existing demo project, archive and rename it
|
||||
if team.projects.where(name: name).present?
|
||||
# TODO: check if we still need this code
|
||||
# old = team.projects.where(name: 'Demo project - qPCR')[0]
|
||||
# old.archive! user
|
||||
i = 1
|
||||
while team.projects.where(
|
||||
name: name = "#{name} (#{i})"
|
||||
).present?
|
||||
i += 1
|
||||
end
|
||||
end
|
||||
|
||||
project = Project.create(
|
||||
visibility: 0,
|
||||
name: name,
|
||||
due_date: nil,
|
||||
team: team,
|
||||
created_by: user,
|
||||
created_at: generate_random_time(1.week.ago),
|
||||
last_modified_by: user,
|
||||
archived: false
|
||||
)
|
||||
|
||||
experiment_description =
|
||||
'Polymerase chain reaction (PCR) monitors the amplification of DNA ' \
|
||||
'in real time (qPCR cyclers constantly scan qPCR plates). It is, in ' \
|
||||
|
|
5
db/migrate/20190304153544_add_demo_flag_to_project.rb
Normal file
5
db/migrate/20190304153544_add_demo_flag_to_project.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
class AddDemoFlagToProject < ActiveRecord::Migration[5.1]
|
||||
def change
|
||||
add_column :projects, :demo, :boolean, null: false, default: false
|
||||
end
|
||||
end
|
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20190227125352) do
|
||||
ActiveRecord::Schema.define(version: 20190304153544) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
|
@ -298,6 +298,7 @@ ActiveRecord::Schema.define(version: 20190227125352) do
|
|||
t.datetime "restored_on"
|
||||
t.string "experiments_order"
|
||||
t.boolean "template"
|
||||
t.boolean "demo", default: false, null: false
|
||||
t.index "trim_html_tags((name)::text) gin_trgm_ops", name: "index_projects_on_name", using: :gin
|
||||
t.index ["archived_by_id"], name: "index_projects_on_archived_by_id"
|
||||
t.index ["created_by_id"], name: "index_projects_on_created_by_id"
|
||||
|
|
Loading…
Reference in a new issue