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
def puzzle_params
params.expect(puzzle: [ :brand, :name, :image ])
params.expect(puzzle: [ :brand, :name, :image, :pieces ])
end
end

View File

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

View File

@ -29,16 +29,9 @@ css:
= image_tag(puzzle.image, style: "max-height: 200px; object-fit: contain") if puzzle.image.attached?
.mt-2.fs-6 style="text-align: center"
=> "#{puzzle.name} -"
= puzzle.brand
= "#{puzzle.brand} #{puzzle.pieces}p"
.row
.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"
table.table.table-striped.table-hover
thead
@ -76,7 +69,7 @@ css:
= puzzle.name
.fs-6 style="margin-left: 15px"
b
= puzzle.brand
= "#{puzzle.brand} - #{puzzle.pieces}p"
- else
.d-flex.flex-column style="height: calc(100vh - 180px)"
@ -84,17 +77,6 @@ css:
- @contest.puzzles.each do |puzzle|
= 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"
table.table.table-striped.table-hover
thead

View File

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

View File

@ -15,6 +15,11 @@
.form-floating
= form.text_field :brand, autocomplete: "off", class: "form-control"
= 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
.col
.form-text.mb-1

View File

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

View File

@ -33,14 +33,15 @@ fr:
file: Fichier
separator: Délimiteur
message:
author: "Auteur.ice"
processed: "Traité ?"
text: "Contenu"
time: "Temps"
author: Auteur.ice
processed: Traité ?
text: Contenu
time: Temps
puzzle:
brand: "Marque"
image: "Image"
name: "Nom"
brand: Marque
image: Image
name: Nom
pieces: Nombre de pièces
session:
email_address: Adresse email
password: Mot de passe
@ -78,6 +79,8 @@ fr:
attributes:
name:
blank: Le nom du puzzle est obligatoire
pieces:
blank: Il est obligatoire d'indiquer le nombre de pièces
user:
attributes:
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.
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|
t.string "name", 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.integer "contest_id", null: false
t.string "brand"
t.integer "pieces", null: false
t.index ["contest_id"], name: "index_puzzles_on_contest_id"
end