feat: support cloning instances
This commit is contained in:
parent
5914b85fc6
commit
5aa5fe0f5a
5 changed files with 27 additions and 1 deletions
3
Gemfile
3
Gemfile
|
@ -11,6 +11,7 @@ gem "jbuilder"
|
|||
gem "tomlrb"
|
||||
gem "nanoid"
|
||||
gem "spicy-proton"
|
||||
gem "deep_cloneable"
|
||||
|
||||
gem "tzinfo-data", platforms: %i[ windows jruby ]
|
||||
|
||||
|
@ -26,6 +27,7 @@ group :development, :test do
|
|||
gem "debug", platforms: %i[ mri windows ], require: "debug/prelude"
|
||||
gem "brakeman", require: false
|
||||
gem "rubocop-rails-omakase", require: false
|
||||
gem "dockerfile-rails", ">= 1.7"
|
||||
end
|
||||
|
||||
group :development do
|
||||
|
@ -37,4 +39,3 @@ group :test do
|
|||
gem "selenium-webdriver"
|
||||
end
|
||||
|
||||
gem "dockerfile-rails", ">= 1.7", :group => :development
|
||||
|
|
|
@ -101,6 +101,8 @@ GEM
|
|||
debug (1.10.0)
|
||||
irb (~> 1.10)
|
||||
reline (>= 0.3.8)
|
||||
deep_cloneable (3.2.1)
|
||||
activerecord (>= 3.1.0, < 9)
|
||||
dockerfile-rails (1.7.9)
|
||||
rails (>= 3.0.0)
|
||||
drb (2.2.1)
|
||||
|
@ -342,6 +344,7 @@ DEPENDENCIES
|
|||
brakeman
|
||||
capybara
|
||||
debug
|
||||
deep_cloneable
|
||||
dockerfile-rails (>= 1.7)
|
||||
importmap-rails
|
||||
jbuilder
|
||||
|
|
|
@ -58,6 +58,20 @@ class InstanceController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def clone
|
||||
instance = clone_instance_params
|
||||
i = Instance.find_by(public_id: instance)
|
||||
new_inst = i.deep_clone(include: [ :fairies, :pops ])
|
||||
new_inst.public_id = Nanoid.generate(size: 6)
|
||||
new_inst.password = Nanoid.generate(size: 4, alphabet: "0123456789")
|
||||
new_inst.name = Spicy::Proton.pair(" ")
|
||||
if new_inst.save
|
||||
@id = new_inst.public_id
|
||||
@password = new_inst.password
|
||||
render "set_password"
|
||||
end
|
||||
end
|
||||
|
||||
def show
|
||||
@instance = Instance.includes(:pops, :fairies).find_by(public_id: show_instance_params)
|
||||
if @instance
|
||||
|
@ -125,6 +139,10 @@ class InstanceController < ApplicationController
|
|||
params.expect(:info)
|
||||
end
|
||||
|
||||
def clone_instance_params
|
||||
params.expect(:instance)
|
||||
end
|
||||
|
||||
def show_instance_params
|
||||
params.expect(:public_id)
|
||||
end
|
||||
|
|
|
@ -50,3 +50,6 @@
|
|||
<%= javascript_include_tag "list" %>
|
||||
</div>
|
||||
|
||||
<%= form_with url: clone_instance_path(instance: @instance.public_id) do |f| %>
|
||||
<%= f.submit "clone instance" %>
|
||||
<% end %>
|
||||
|
|
|
@ -4,6 +4,7 @@ Rails.application.routes.draw do
|
|||
|
||||
post "/new", to: "instance#create", as: :new_instance
|
||||
post "/new_from_fe", to: "instance#create_from_fe", as: :new_from_fe
|
||||
post "/clone", to: "instance#clone", as: :clone_instance
|
||||
post "/pop", to: "instance#pop", as: :pop_in_instance
|
||||
post "/pop/adjust", to: "instance#adjust_pop", as: :adjust_pop
|
||||
post "/reset", to: "instance#reset", as: :reset_in_instance
|
||||
|
|
Loading…
Add table
Reference in a new issue