fix links and server form
This commit is contained in:
parent
2afec412bb
commit
453a9137b9
6 changed files with 20 additions and 33 deletions
|
|
@ -10,12 +10,17 @@ class ServersController < ApplicationController
|
|||
end
|
||||
|
||||
def new
|
||||
@server_templates = current_user.server_templates.order(:name)
|
||||
@server = current_user.servers.build
|
||||
|
||||
if params[:server_template_id]
|
||||
@server_template = current_user.server_templates.find(params[:server_template_id])
|
||||
@server = current_user.servers.build(server_template: @server_template)
|
||||
@server.server_template = @server_template
|
||||
end
|
||||
end
|
||||
|
||||
def create
|
||||
@server_template = current_user.server_templates.find(params[:server_template_id])
|
||||
@server_template = current_user.server_templates.find(server_params[:server_template_id])
|
||||
@server = current_user.servers.build(server_params)
|
||||
@server.server_template = @server_template
|
||||
@server.status = :stopped
|
||||
|
|
@ -25,6 +30,7 @@ class ServersController < ApplicationController
|
|||
SpawnServerJob.perform_later(@server.id)
|
||||
redirect_to @server, notice: "Server spawning..."
|
||||
else
|
||||
@server_templates = current_user.server_templates.order(:name)
|
||||
render :new, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
td = template.overlays.count
|
||||
td
|
||||
= link_to "Edit", edit_server_template_path(template), class: "btn btn--small"
|
||||
= link_to "Spawn", new_server_template_server_path(template), class: "btn btn--small btn--success"
|
||||
= link_to "Spawn", new_server_path(server_template_id: template.id), class: "btn btn--small btn--success"
|
||||
= link_to "Delete", server_template_path(template), method: :delete, data: { confirm: "Sure?" }, class: "btn btn--small btn--danger"
|
||||
- else
|
||||
p No templates yet.
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
h2 = @server_template.name
|
||||
= link_to "Edit", edit_server_template_path(@server_template), class: "btn btn--small"
|
||||
= link_to "Delete", server_template_path(@server_template), method: :delete, data: { confirm: "Sure?" }, class: "btn btn--small btn--danger"
|
||||
= link_to "Spawn Server", new_server_template_server_path(@server_template), class: "btn btn--primary"
|
||||
= link_to "Spawn Server", new_server_path(server_template_id: @server_template.id), class: "btn btn--primary"
|
||||
|
||||
section.overlays
|
||||
h3 Overlays
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
.servers
|
||||
h2 Servers
|
||||
p Select a template to spawn a new server: = link_to "View Templates", server_templates_path
|
||||
p
|
||||
= link_to "New Server", new_server_path, class: "btn btn--primary"
|
||||
|
||||
- if @servers.any?
|
||||
table
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
.server_form
|
||||
h2 Spawn New Server for #{@server_template.name}
|
||||
h2 Spawn New Server
|
||||
|
||||
= form_with model: @server, url: server_template_servers_path(@server_template), method: :post, local: true do |f|
|
||||
= form_with model: @server, url: servers_path, method: :post, local: true do |f|
|
||||
- if @server.errors.any?
|
||||
.alert.alert--error
|
||||
h4 = pluralize(@server.errors.count, "error")
|
||||
|
|
@ -9,6 +9,10 @@
|
|||
- @server.errors.full_messages.each do |msg|
|
||||
li = msg
|
||||
|
||||
.form-group
|
||||
= f.label :server_template_id, "Template"
|
||||
= f.select :server_template_id, options_from_collection_for_select(@server_templates, :id, :name, @server.server_template_id), { prompt: "Select a template" }, class: "form-control", required: true
|
||||
|
||||
.form-group
|
||||
= f.label :name
|
||||
= f.text_field :name, placeholder: "e.g., server1"
|
||||
|
|
@ -17,29 +21,6 @@
|
|||
= f.label :port, "Port (optional, auto-assigned if blank)"
|
||||
= f.number_field :port, placeholder: "Auto: 27016-27999", min: 27016, max: 27999
|
||||
|
||||
.template-preview
|
||||
h3 Template Configuration
|
||||
|
||||
h4 Overlays
|
||||
- if @server_template.overlays.any?
|
||||
ol
|
||||
- @server_template.template_overlays.ordered.each do |to|
|
||||
li = to.overlay.name
|
||||
- else
|
||||
p None
|
||||
|
||||
h4 Config Options
|
||||
- if @server_template.config.present?
|
||||
pre = @server_template.config
|
||||
- else
|
||||
p None
|
||||
|
||||
h4 Startup Parameters
|
||||
- if @server_template.startup_params.present?
|
||||
pre = @server_template.startup_params
|
||||
- else
|
||||
p None
|
||||
|
||||
.form-actions
|
||||
= f.submit "Spawn Server", class: "btn btn--primary"
|
||||
= link_to "Back", servers_path, class: "btn"
|
||||
|
|
|
|||
|
|
@ -13,14 +13,13 @@ Rails.application.routes.draw do
|
|||
# Server resources
|
||||
resources :server_templates do
|
||||
resources :overlays, only: [ :create, :destroy ]
|
||||
resources :servers, only: [ :new, :create ]
|
||||
end
|
||||
|
||||
resources :overlays, only: [ :index, :new, :create, :destroy ]
|
||||
|
||||
resources :job_logs, only: [ :index, :show ]
|
||||
|
||||
resources :servers, only: [ :index, :show, :destroy ] do
|
||||
resources :servers, only: [ :index, :show, :new, :destroy ] do
|
||||
resources :job_logs, only: [ :index ]
|
||||
member do
|
||||
post :spawn
|
||||
|
|
|
|||
Loading…
Reference in a new issue