Add number of pieces to puzzles
All checks were successful
CI / scan_ruby (push) Successful in 16s
CI / scan_js (push) Successful in 12s
CI / lint (push) Successful in 12s
CI / test (push) Successful in 34s

This commit is contained in:
sto 2025-06-27 09:23:25 +02:00
parent b6da55723d
commit 0599def237
9 changed files with 51 additions and 39 deletions

View File

@ -61,6 +61,6 @@ class PuzzlesController < ApplicationController
end end
def puzzle_params def puzzle_params
params.expect(puzzle: [ :brand, :name, :image ]) params.expect(puzzle: [ :brand, :name, :image, :pieces ])
end end
end end

View File

@ -5,6 +5,7 @@
# id :integer not null, primary key # id :integer not null, primary key
# brand :string # brand :string
# name :string # name :string
# pieces :integer not null
# created_at :datetime not null # created_at :datetime not null
# updated_at :datetime not null # updated_at :datetime not null
# contest_id :integer not null # contest_id :integer not null
@ -24,4 +25,5 @@ class Puzzle < ApplicationRecord
has_one_attached :image has_one_attached :image
validates :name, presence: true validates :name, presence: true
validates :pieces, presence: true
end end

View File

@ -29,16 +29,9 @@ css:
= image_tag(puzzle.image, style: "max-height: 200px; object-fit: contain") if puzzle.image.attached? = image_tag(puzzle.image, style: "max-height: 200px; object-fit: contain") if puzzle.image.attached?
.mt-2.fs-6 style="text-align: center" .mt-2.fs-6 style="text-align: center"
=> "#{puzzle.name} -" => "#{puzzle.name} -"
= puzzle.brand = "#{puzzle.brand} #{puzzle.pieces}p"
.row .row
.col-6.d-flex.flex-column style="height: calc(100vh - 180px)" .col-6.d-flex.flex-column style="height: calc(100vh - 180px)"
/ = form_with model: Contest do |form|
/ .row.mb-3
/ .col
/ .form-check.form-switch
/ = form.check_box :refresh, class: "form-check-input"
/ = form.label t("contests.scoreboard.refresh")
.d-flex.flex-column style="overflow-y: auto" .d-flex.flex-column style="overflow-y: auto"
table.table.table-striped.table-hover table.table.table-striped.table-hover
thead thead
@ -76,7 +69,7 @@ css:
= puzzle.name = puzzle.name
.fs-6 style="margin-left: 15px" .fs-6 style="margin-left: 15px"
b b
= puzzle.brand = "#{puzzle.brand} - #{puzzle.pieces}p"
- else - else
.d-flex.flex-column style="height: calc(100vh - 180px)" .d-flex.flex-column style="height: calc(100vh - 180px)"
@ -84,17 +77,6 @@ css:
- @contest.puzzles.each do |puzzle| - @contest.puzzles.each do |puzzle|
= image_tag(puzzle.image, class: "img-fluid ms-3 me-3", style: "max-height: 220px") if puzzle.image.attached? = image_tag(puzzle.image, class: "img-fluid ms-3 me-3", style: "max-height: 220px") if puzzle.image.attached?
.mb-3 style="display: inline-flex"
a.btn.btn-primary href="/public/#{@contest.friendly_id}"
= t("helpers.buttons.refresh")
/ = form_with model: Contest do |form|
/ .row.mb-3
/ .col
/ .form-check.form-switch
/ = form.check_box :refresh, class: "form-check-input"
/ = form.label t("contests.scoreboard.refresh")
.d-flex.flex-column style="overflow-y: auto" .d-flex.flex-column style="overflow-y: auto"
table.table.table-striped.table-hover table.table.table-striped.table-hover
thead thead

View File

@ -43,12 +43,14 @@ javascript:
table.table.table-striped.table-hover table.table.table-striped.table-hover
thead thead
tr tr
th scope="col" th
= t("activerecord.attributes.puzzle.image") = t("activerecord.attributes.puzzle.image")
th scope="col" th
= t("activerecord.attributes.puzzle.name") = t("activerecord.attributes.puzzle.name")
th scope="col" th
= t("activerecord.attributes.puzzle.brand") = t("activerecord.attributes.puzzle.brand")
th
= t("activerecord.attributes.puzzle.pieces")
tbody tbody
- @puzzles.each do |puzzle| - @puzzles.each do |puzzle|
tr.align-middle scope="row" tr.align-middle scope="row"
@ -58,6 +60,8 @@ javascript:
= puzzle.name = puzzle.name
td td
= puzzle.brand = puzzle.brand
td
= puzzle.pieces
td td
a.btn.btn-sm.btn-secondary href=edit_contest_puzzle_path(@contest, puzzle) a.btn.btn-sm.btn-secondary href=edit_contest_puzzle_path(@contest, puzzle)
= t("helpers.buttons.edit") = t("helpers.buttons.edit")

View File

@ -15,6 +15,11 @@
.form-floating .form-floating
= form.text_field :brand, autocomplete: "off", class: "form-control" = form.text_field :brand, autocomplete: "off", class: "form-control"
= form.label :brand, class: "required" = form.label :brand, class: "required"
.row.mb-3
.col
.form-floating
= form.number_field :pieces, autocomplete: "off", class: "form-control"
= form.label :pieces, class: "required"
.row.mb-3 .row.mb-3
.col .col
.form-text.mb-1 .form-text.mb-1

View File

@ -62,14 +62,15 @@ en:
file: File file: File
separator: Separator separator: Separator
message: message:
author: "Author" author: Author
processed: "Processed?" processed: Processed?
text: "Content" text: Content
time: "Time" time: Time
puzzle: puzzle:
brand: "Brand" brand: Brand
image: "Image" image: Image
name: "Name" name: Name
pieces: Number of pieces
session: session:
email_address: Email address email_address: Email address
password: Password password: Password
@ -107,6 +108,8 @@ en:
attributes: attributes:
name: name:
blank: The puzzle name cannot be empty blank: The puzzle name cannot be empty
pieces:
blank: It's mandatory to provide the number of pieces
user: user:
attributes: attributes:
email_address: email_address:

View File

@ -33,14 +33,15 @@ fr:
file: Fichier file: Fichier
separator: Délimiteur separator: Délimiteur
message: message:
author: "Auteur.ice" author: Auteur.ice
processed: "Traité ?" processed: Traité ?
text: "Contenu" text: Contenu
time: "Temps" time: Temps
puzzle: puzzle:
brand: "Marque" brand: Marque
image: "Image" image: Image
name: "Nom" name: Nom
pieces: Nombre de pièces
session: session:
email_address: Adresse email email_address: Adresse email
password: Mot de passe password: Mot de passe
@ -78,6 +79,8 @@ fr:
attributes: attributes:
name: name:
blank: Le nom du puzzle est obligatoire blank: Le nom du puzzle est obligatoire
pieces:
blank: Il est obligatoire d'indiquer le nombre de pièces
user: user:
attributes: attributes:
email_address: email_address:

View File

@ -0,0 +1,12 @@
class AddPiecesToPuzzle < ActiveRecord::Migration[8.0]
def change
add_column :puzzles, :pieces, :integer
Puzzle.find_each do |puzzle|
puzzle.pieces = 500
puzzle.save
end
change_column_null :puzzles, :pieces, false
end
end

3
db/schema.rb generated
View File

@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[8.0].define(version: 2025_06_25_075513) do ActiveRecord::Schema[8.0].define(version: 2025_06_27_070407) do
create_table "active_storage_attachments", force: :cascade do |t| create_table "active_storage_attachments", force: :cascade do |t|
t.string "name", null: false t.string "name", null: false
t.string "record_type", null: false t.string "record_type", null: false
@ -115,6 +115,7 @@ ActiveRecord::Schema[8.0].define(version: 2025_06_25_075513) do
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
t.integer "contest_id", null: false t.integer "contest_id", null: false
t.string "brand" t.string "brand"
t.integer "pieces", null: false
t.index ["contest_id"], name: "index_puzzles_on_contest_id" t.index ["contest_id"], name: "index_puzzles_on_contest_id"
end end