diff options
author | David Gay <eapoems@riseup.net> | 2023-10-31 02:04:58 -0400 |
---|---|---|
committer | David Gay <eapoems@riseup.net> | 2023-10-31 02:04:58 -0400 |
commit | 47be31b415f33efbe73055fd0bb297e88f758731 (patch) | |
tree | d73604168c4b493b6f1ce4332bd3fab05d33ce5d /app | |
parent | 52d46329e525133077b4f116c9e608128d8ba982 (diff) |
Checkpoint kinds: comment, checkin, checkout
Diffstat (limited to 'app')
-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 |
6 files changed, 66 insertions, 28 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> |