From 11b7be5c41edda171a05e92295c51320cb315c68 Mon Sep 17 00:00:00 2001 From: David Gay Date: Thu, 2 Nov 2023 18:43:53 -0400 Subject: Update checkpoints to have comment instead of title+desc, and display them --- app/controllers/checkpoints_controller.rb | 2 +- app/views/checkpoints/new.html.erb | 11 +++-------- app/views/runs/show.html.erb | 11 +++++++---- db/migrate/20231102223203_remove_title_from_checkpoints.rb | 11 +++++++++++ db/schema.rb | 5 ++--- test/fixtures/checkpoints.yml | 6 ++---- 6 files changed, 26 insertions(+), 20 deletions(-) create mode 100644 db/migrate/20231102223203_remove_title_from_checkpoints.rb diff --git a/app/controllers/checkpoints_controller.rb b/app/controllers/checkpoints_controller.rb index ef53a6b..07c1a5a 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, :kind) + params.require(:checkpoint).permit(:comment, :save_file, :kind) end def set_run diff --git a/app/views/checkpoints/new.html.erb b/app/views/checkpoints/new.html.erb index 712eae1..b11a9bc 100644 --- a/app/views/checkpoints/new.html.erb +++ b/app/views/checkpoints/new.html.erb @@ -5,17 +5,12 @@ <%= form_with model: [@run, @checkpoint], class: "space-y-4" do |f| %>
- <%= f.label :title %> - <%= f.text_field :title %> +
<%= f.label :comment %>
+ <%= f.text_area :comment %>
- <%= f.label :description %> - <%= f.text_area :description %> -
- -
- <%= f.label :save_file %> +
<%= f.label :save_file %>
<%= f.file_field :save_file %>
diff --git a/app/views/runs/show.html.erb b/app/views/runs/show.html.erb index d7d65b6..55bef02 100644 --- a/app/views/runs/show.html.erb +++ b/app/views/runs/show.html.erb @@ -23,8 +23,8 @@

Checkpoints

<%= link_to "New checkpoint", new_run_checkpoint_path(@run) %> -
- <% @run.checkpoints.each do |checkpoint| %> + <% @run.checkpoints.order(:created_at).reverse.each do |checkpoint| %> +
<%= time_ago_in_words(checkpoint.created_at) %> ago by @@ -38,7 +38,10 @@ (No save file attached.) <% end %>
+ <% if checkpoint.comment %> +
<%= checkpoint.comment %>
+ <% end %>
- <% end %> -
+
+ <% end %> diff --git a/db/migrate/20231102223203_remove_title_from_checkpoints.rb b/db/migrate/20231102223203_remove_title_from_checkpoints.rb new file mode 100644 index 0000000..92e54a0 --- /dev/null +++ b/db/migrate/20231102223203_remove_title_from_checkpoints.rb @@ -0,0 +1,11 @@ +class RemoveTitleFromCheckpoints < ActiveRecord::Migration[7.1] + def up + remove_column :checkpoints, :title + rename_column :checkpoints, :description, :comment + end + + def down + rename_column :checkpoints, :comment, :description + add_column :checkpoints, :title, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index b48737d..0982ec0 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_053134) do +ActiveRecord::Schema[7.1].define(version: 2023_11_02_223203) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -43,8 +43,7 @@ ActiveRecord::Schema[7.1].define(version: 2023_10_31_053134) do end create_table "checkpoints", force: :cascade do |t| - t.string "title" - t.text "description" + t.text "comment" t.bigint "run_id", null: false t.bigint "user_id", null: false t.datetime "created_at", null: false diff --git a/test/fixtures/checkpoints.yml b/test/fixtures/checkpoints.yml index bb83377..02bb57e 100644 --- a/test/fixtures/checkpoints.yml +++ b/test/fixtures/checkpoints.yml @@ -1,13 +1,11 @@ # Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html one: - title: MyString - description: MyText + comment: MyText run: one user: one two: - title: MyString - description: MyText + comment: MyText run: two user: two -- cgit v1.2.3