diff options
-rw-r--r-- | app/controllers/checkpoints_controller.rb | 2 | ||||
-rw-r--r-- | app/models/checkpoint.rb | 2 | ||||
-rw-r--r-- | app/models/run.rb | 8 | ||||
-rw-r--r-- | app/views/checkpoints/new.html.erb | 72 | ||||
-rw-r--r-- | app/views/home/index.html.erb | 5 | ||||
-rw-r--r-- | app/views/runs/show.html.erb | 5 | ||||
-rw-r--r-- | db/migrate/20231031053134_add_kind_to_checkpoints.rb | 5 | ||||
-rw-r--r-- | db/schema.rb | 3 |
8 files changed, 73 insertions, 29 deletions
diff --git a/app/controllers/checkpoints_controller.rb b/app/controllers/checkpoints_controller.rb index 94df2c3..ef53a6b 100644 --- a/app/controllers/checkpoints_controller.rb +++ b/app/controllers/checkpoints_controller.rb @@ -18,7 +18,7 @@ class CheckpointsController < ApplicationController protected def checkpoint_params - params.require(:checkpoint).permit(:title, :description, :save_file) + params.require(:checkpoint).permit(:title, :description, :save_file, :kind) end def set_run diff --git a/app/models/checkpoint.rb b/app/models/checkpoint.rb index c014b2e..9cdb774 100644 --- a/app/models/checkpoint.rb +++ b/app/models/checkpoint.rb @@ -1,4 +1,6 @@ class Checkpoint < ApplicationRecord + enum kind: {comment: 0, checkin: 1, checkout: 2} + belongs_to :run belongs_to :user diff --git a/app/models/run.rb b/app/models/run.rb index 7c9209e..023202b 100644 --- a/app/models/run.rb +++ b/app/models/run.rb @@ -3,5 +3,11 @@ class Run < ApplicationRecord belongs_to :user has_many :checkpoints, dependent: :destroy - validates_presence_of :title + validates :title, presence: true + + def checked_in? + last_checkpoint = checkpoints.where.not(kind: :comment).last + # If there are no non-comment checkpoints, then the run was never checked in. + last_checkpoint.nil? ? false : last_checkpoint.checkin? + end end diff --git a/app/views/checkpoints/new.html.erb b/app/views/checkpoints/new.html.erb index d122d91..712eae1 100644 --- a/app/views/checkpoints/new.html.erb +++ b/app/views/checkpoints/new.html.erb @@ -1,31 +1,55 @@ -<%= form_with model: [@run, @checkpoint] do |f| %> - <div> - <%= f.label :title %> - <%= f.text_field :title %> - </div> +<div class="space-y-4"> + <h1 class="text-xl"><%= @run.title %></h1> - <div> - <%= f.label :description %> - <%= f.text_area :description %> - </div> + <p class="subtitle">New checkpoint</p> - <div> - <%= f.label :save_file %> - <%= f.file_field :save_file %> - </div> + <%= form_with model: [@run, @checkpoint], class: "space-y-4" do |f| %> + <div> + <%= f.label :title %> + <%= f.text_field :title %> + </div> - <div> - <%= f.submit "Submit checkpoint", class: "btn-primary" %> - </div> + <div> + <%= f.label :description %> + <%= f.text_area :description %> + </div> - <% if @checkpoint.errors.any? %> <div> - <p><%= pluralize(@checkpoint.errors.count, "error") %> prohibited this checkpoint from being saved:</p> - <ul> - <% @checkpoint.errors.full_messages.each do |message| %> - <li><%= message %></li> - <% end %> - </ul> + <%= f.label :save_file %> + <%= f.file_field :save_file %> </div> + + <div> + <div> + <%= f.radio_button :kind, "comment" %> + <%= f.label :kind_comment, "I'm just leaving a comment" %> + </div> + <% if @run.checked_in? %> + <div> + <%= f.radio_button :kind, "checkout" %> + <%= f.label :kind_checkout, "I'm checking out this save file, lock the run until I check it back in" %> + </div> + <% else %> + <div> + <%= f.radio_button :kind, "checkin" %> + <%= f.label :kind_checkin, "I'm checking in this save file so another trainer can play it" %> + </div> + <% end %> + </div> + + <div> + <%= f.submit "Save checkpoint", class: "btn-primary" %> + </div> + + <% if @checkpoint.errors.any? %> + <div> + <p><%= pluralize(@checkpoint.errors.count, "error") %> prohibited this checkpoint from being saved:</p> + <ul> + <% @checkpoint.errors.full_messages.each do |message| %> + <li><%= message %></li> + <% end %> + </ul> + </div> + <% end %> <% end %> -<% end %> +</div> diff --git a/app/views/home/index.html.erb b/app/views/home/index.html.erb index 457200c..a961565 100644 --- a/app/views/home/index.html.erb +++ b/app/views/home/index.html.erb @@ -9,7 +9,10 @@ <li>At <%= checkpoint.created_at %> <%= checkpoint.user.name %> checked in a save for <%= link_to checkpoint.run.title, run_path(checkpoint.run) %> (<%= checkpoint.run.game.title %>) - <%= link_to "[save file]", rails_blob_path(checkpoint.save_file, disposition: "attachment") %></li> + <% if checkpoint.save_file.attached? %> + <%= link_to "[save file]", rails_blob_path(checkpoint.save_file, disposition: "attachment") %> + <% end %> + </li> <% end %> </ul> </div> diff --git a/app/views/runs/show.html.erb b/app/views/runs/show.html.erb index eb580ad..832889a 100644 --- a/app/views/runs/show.html.erb +++ b/app/views/runs/show.html.erb @@ -10,6 +10,9 @@ <ul class="list-disc"> <% @run.checkpoints.each do |checkpoint| %> <li><%= checkpoint.created_at %> - <%= link_to "[save file]", rails_blob_path(checkpoint.save_file, disposition: "attachment") %></li> + <% if checkpoint.save_file.attached? %> + <%= link_to "[save file]", rails_blob_path(checkpoint.save_file, disposition: "attachment") %> + <% end %> + </li> <% end %> </ul> diff --git a/db/migrate/20231031053134_add_kind_to_checkpoints.rb b/db/migrate/20231031053134_add_kind_to_checkpoints.rb new file mode 100644 index 0000000..2b71498 --- /dev/null +++ b/db/migrate/20231031053134_add_kind_to_checkpoints.rb @@ -0,0 +1,5 @@ +class AddKindToCheckpoints < ActiveRecord::Migration[7.1] + def change + add_column :checkpoints, :kind, :integer, default: 0 + end +end diff --git a/db/schema.rb b/db/schema.rb index bed04ff..b48737d 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 2023_10_31_050050) do +ActiveRecord::Schema[7.1].define(version: 2023_10_31_053134) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -49,6 +49,7 @@ ActiveRecord::Schema[7.1].define(version: 2023_10_31_050050) do t.bigint "user_id", null: false t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.integer "kind", default: 0 t.index ["run_id"], name: "index_checkpoints_on_run_id" t.index ["user_id"], name: "index_checkpoints_on_user_id" end |