Unit: limit symbol length, change name:string -> description:text

Closes #11
Closes #12
This commit is contained in:
cryptogopher 2024-11-24 15:13:59 +01:00
parent d6fdff252a
commit 3711251656
6 changed files with 28 additions and 16 deletions

View File

@ -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),

View File

@ -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

View File

@ -7,8 +7,8 @@
maxlength: @unit.class.columns_hash['symbol'].limit, autocomplete: "off" %>
</td>
<td>
<%= 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" %>
</td>
<td>
<% unless @unit.base.nil? %>

View File

@ -8,7 +8,7 @@
<%= link_to unit, edit_unit_path(unit), id: dom_id(unit, :edit),
onclick: 'this.blur();', data: {turbo_stream: true} %>
</td>
<td><%= unit.name %></td>
<td><%= unit.description %></td>
<td class="number"><%= scientifize(unit.multiplier) %></td>
<% if current_user.at_least(:active) %>

View File

@ -12,7 +12,7 @@
<thead>
<tr>
<th><%= User.human_attribute_name(:symbol).capitalize %></th>
<th><%= User.human_attribute_name(:name).capitalize %></th>
<th><%= User.human_attribute_name(:description).capitalize %></th>
<th><%= User.human_attribute_name(:multiplier).capitalize %></th>
<% if current_user.at_least(:active) %>
<th><%= t :actions %></th>

View File

@ -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