From 37112516563d65c5756580d92079a4a4a97a9020 Mon Sep 17 00:00:00 2001 From: cryptogopher Date: Sun, 24 Nov 2024 15:13:59 +0100 Subject: [PATCH] Unit: limit symbol length, change name:string -> description:text Closes #11 Closes #12 --- app/assets/stylesheets/application.css | 28 ++++++++++++++++------- app/models/unit.rb | 4 ++-- app/views/units/_form.html.erb | 4 ++-- app/views/units/_unit.html.erb | 2 +- app/views/units/index.html.erb | 2 +- db/migrate/20230602185352_create_units.rb | 4 ++-- 6 files changed, 28 insertions(+), 16 deletions(-) diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index 14ec9a7..797249b 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -98,16 +98,21 @@ input[type=submit] { width: fit-content; } input:not([type=submit]):not([type=checkbox]), -select { +select, +textarea { padding: 0.2em 0.4em; } .button, button, input, -select { +select, +textarea { border: solid 1px var(--color-gray); border-radius: 0.25em; } +textarea { + margin: 0 +} .button > svg, .tab > svg, button > svg { @@ -151,7 +156,8 @@ input[type=checkbox]:checked { -webkit-appearance: checkbox; } input:hover, -select:hover { +select:hover, +textarea:hover { border-color: #009ade; outline: solid 1px #009ade; } @@ -160,11 +166,13 @@ select:hover { } input:focus-visible, select:focus-within, -select:focus-visible { +select:focus-visible, +textarea:focus-visible { accent-color: #006c9b; background-color: var(--color-focus-gray); } -input[type=text]:read-only { +input[type=text]:read-only, +textarea:read-only { border: none; padding-left: 0; padding-right: 0; @@ -336,7 +344,7 @@ table.items th, table.items td { padding-inline: 1em 0; } -table.items td:has(input) { +table.items td:has(input, textarea) { padding-inline-start: calc(0.6em - 0.9px); } table.items th:last-child { @@ -367,7 +375,7 @@ table.items td.link a::after { table.items td.subunit { padding-inline-start: 1.8em; } -table.items td.subunit:has(input) { +table.items td.subunit:has(input, textarea) { padding-inline-start: calc(1.4em - 1px); } table.items td.actions { @@ -390,6 +398,9 @@ table.items tr.dropzone::after { table.items td.handle { cursor: move; } +table.items tr.form td { + vertical-align: top; +} /* TODO: replace :hover:focus-visible combos with proper LOVE stye order */ /* TODO: Update styling, including rem removal. */ @@ -440,7 +451,8 @@ table.items input[type=submit] { table.items .button:not(:hover), table.items button:not(:hover), table.items input:not(:hover), -table.items select:not(:hover) { +table.items select:not(:hover), +table.items textarea:not(:hover) { border-color: var(--color-border-gray); } table.items .button:not(:hover), diff --git a/app/models/unit.rb b/app/models/unit.rb index f4131de..de362aa 100644 --- a/app/models/unit.rb +++ b/app/models/unit.rb @@ -1,5 +1,5 @@ class Unit < ApplicationRecord - ATTRIBUTES = [:symbol, :name, :multiplier, :base_id] + ATTRIBUTES = [:symbol, :description, :multiplier, :base_id] belongs_to :user, optional: true belongs_to :base, optional: true, class_name: "Unit" @@ -11,7 +11,7 @@ class Unit < ApplicationRecord end validates :symbol, presence: true, uniqueness: {scope: :user_id}, length: {maximum: columns_hash['symbol'].limit} - validates :name, length: {maximum: columns_hash['name'].limit} + validates :description, length: {maximum: columns_hash['description'].limit} validates :multiplier, numericality: {equal_to: 1}, unless: :base validates :multiplier, numericality: {other_than: 0}, if: :base diff --git a/app/views/units/_form.html.erb b/app/views/units/_form.html.erb index e2dd699..3d4dfc6 100644 --- a/app/views/units/_form.html.erb +++ b/app/views/units/_form.html.erb @@ -7,8 +7,8 @@ maxlength: @unit.class.columns_hash['symbol'].limit, autocomplete: "off" %> - <%= form.text_field :name, form: :unit_form, size: 30, - maxlength: @unit.class.columns_hash['name'].limit, autocomplete: "off" %> + <%= form.text_area :description, form: :unit_form, cols: 30, rows: 1, escape: false, + maxlength: @unit.class.columns_hash['description'].limit, autocomplete: "off" %> <% unless @unit.base.nil? %> diff --git a/app/views/units/_unit.html.erb b/app/views/units/_unit.html.erb index d04c175..d1eec64 100644 --- a/app/views/units/_unit.html.erb +++ b/app/views/units/_unit.html.erb @@ -8,7 +8,7 @@ <%= link_to unit, edit_unit_path(unit), id: dom_id(unit, :edit), onclick: 'this.blur();', data: {turbo_stream: true} %> - <%= unit.name %> + <%= unit.description %> <%= scientifize(unit.multiplier) %> <% if current_user.at_least(:active) %> diff --git a/app/views/units/index.html.erb b/app/views/units/index.html.erb index c6d4aa2..e2b8258 100644 --- a/app/views/units/index.html.erb +++ b/app/views/units/index.html.erb @@ -12,7 +12,7 @@ <%= User.human_attribute_name(:symbol).capitalize %> - <%= User.human_attribute_name(:name).capitalize %> + <%= User.human_attribute_name(:description).capitalize %> <%= User.human_attribute_name(:multiplier).capitalize %> <% if current_user.at_least(:active) %> <%= t :actions %> diff --git a/db/migrate/20230602185352_create_units.rb b/db/migrate/20230602185352_create_units.rb index fb878b6..4b5f64c 100644 --- a/db/migrate/20230602185352_create_units.rb +++ b/db/migrate/20230602185352_create_units.rb @@ -2,8 +2,8 @@ class CreateUnits < ActiveRecord::Migration[7.0] def change create_table :units do |t| t.references :user, foreign_key: true - t.string :symbol, null: false - t.string :name + t.string :symbol, null: false, limit: 15 + t.text :description t.decimal :multiplier, null: false, precision: 30, scale: 15, default: 1.0 t.references :base