forked from fixin.me/fixin.me
Compare commits
3 Commits
fix/system
...
feature/qu
| Author | SHA1 | Date | |
|---|---|---|---|
| 862430e586 | |||
| 3702e24153 | |||
| d893e59293 |
84
CLAUDE.md
Normal file
84
CLAUDE.md
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
# CLAUDE.md
|
||||||
|
|
||||||
|
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
||||||
|
|
||||||
|
## Project Overview
|
||||||
|
|
||||||
|
Fixin.me is a "quantified self" Rails 7.2.3 application for personal data tracking. Users define hierarchical **quantities** (metrics to track), **units** (with optional conversion hierarchies), and **readouts** (individual measurements). There is also a non-persistent **measurement** model used as a form wrapper.
|
||||||
|
|
||||||
|
## Setup
|
||||||
|
|
||||||
|
Configuration files are distributed as `.dist` templates — copy and customize before use:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cp config/application.rb.dist config/application.rb
|
||||||
|
cp config/database.yml.dist config/database.yml
|
||||||
|
cp config/puma.rb.dist config/puma.rb
|
||||||
|
```
|
||||||
|
|
||||||
|
```bash
|
||||||
|
bundle config --local frozen true
|
||||||
|
bundle config --local path .gem
|
||||||
|
bundle config --local with mysql development test # or: pg, sqlite
|
||||||
|
bundle install
|
||||||
|
RAILS_ENV=development bundle exec rails db:create db:migrate db:seed
|
||||||
|
```
|
||||||
|
|
||||||
|
## Common Commands
|
||||||
|
|
||||||
|
```bash
|
||||||
|
bundle exec rails s # start server
|
||||||
|
bundle exec rails test # all unit/model/controller tests
|
||||||
|
bundle exec rails test:system # all system tests (Capybara + Selenium)
|
||||||
|
bundle exec rails test test/system/units_test.rb # single test file
|
||||||
|
bundle exec rails test --seed 64690 --name test_add_unit # single test by name
|
||||||
|
bundle exec rails db:seed:export # export default settings as seed file
|
||||||
|
```
|
||||||
|
|
||||||
|
## Architecture
|
||||||
|
|
||||||
|
### Data Model
|
||||||
|
|
||||||
|
- **Quantity** — hierarchical tree (self-referential `parent_id`). Cached `depth` and `pathname` fields are recomputed via recursive CTEs on write. Direct assignment to cached fields is blocked.
|
||||||
|
- **Unit** — optional hierarchy via `base_id` and `multiplier` for unit conversion. Multiplier precision/scale is validated by a custom validator.
|
||||||
|
- **Readout** — single measurement: `value` (IEEE 754 float), `quantity`, `unit`, `category`.
|
||||||
|
- **Measurement** — `ActiveModel::Model` form wrapper (not database-backed); bridges the readout creation form.
|
||||||
|
- **User** — Devise-managed with a status enum: `admin`, `active`, `restricted`, `locked`, `disabled`. Admins can disguise as other users.
|
||||||
|
|
||||||
|
### Hierarchical Queries
|
||||||
|
|
||||||
|
Both `Quantity` and `Unit` use recursive CTEs for tree traversal (ordered traversal, ancestors, progenies, common ancestors). `lib/core_ext/arel/` patches Arel to support CTE with `UPDATE`/`DELETE` statements, working around Rails issue #54658.
|
||||||
|
|
||||||
|
### Custom Extensions (`lib/core_ext/`)
|
||||||
|
|
||||||
|
- **arel/** — CTE support for UPDATE/DELETE
|
||||||
|
- **active_model/** — precision/scale validator used by `Unit#multiplier`
|
||||||
|
- **active_record/** — `attr_cached` mechanism (see `ApplicationRecord`)
|
||||||
|
- **action_view/** — record identifier suffixes
|
||||||
|
- Miscellaneous: `Array#delete_bang`, `BigDecimal` scientific notation
|
||||||
|
|
||||||
|
### Response Handling
|
||||||
|
|
||||||
|
Controllers respond to both HTML and Turbo Stream formats. Errors during Turbo Stream requests trigger a redirect with flash rather than rendering inline, handled in `ApplicationController`.
|
||||||
|
|
||||||
|
### Numeric Precision
|
||||||
|
|
||||||
|
Readout values are stored as IEEE 754 double-precision floats (not fixed-point decimals). Rationale in `DESIGN.md`: biological values span many orders of magnitude; 15-digit float precision is sufficient and avoids conversion overhead.
|
||||||
|
|
||||||
|
### Routes
|
||||||
|
|
||||||
|
```
|
||||||
|
measurements GET/POST /measurements
|
||||||
|
readouts GET/POST /readouts, DELETE /readouts/:id/discard
|
||||||
|
quantities CRUD + POST /quantities/:id/reparent
|
||||||
|
units CRUD + POST /units/:id/rebase
|
||||||
|
users CRUD + POST /users/:id/disguise, POST /users/revert
|
||||||
|
default/ namespace for default units import/export and admin panel
|
||||||
|
root → /units (authenticated), /sign_in (unauthenticated)
|
||||||
|
```
|
||||||
|
|
||||||
|
## Database Requirements
|
||||||
|
|
||||||
|
The database must support:
|
||||||
|
- Recursive CTEs with `UPDATE`/`DELETE` (MySQL ≥ 8.0, PostgreSQL, or SQLite3)
|
||||||
|
- Decimal precision of 30+ digits
|
||||||
@@ -18,14 +18,12 @@
|
|||||||
/* Strive for simplicity:
|
/* Strive for simplicity:
|
||||||
* * style elements/tags only - if possible,
|
* * style elements/tags only - if possible,
|
||||||
* * replace element/tag name with class name - if element has to be styled
|
* * replace element/tag name with class name - if element has to be styled
|
||||||
* differently depending on context (e.g. <form>; <a> as link/button),
|
* differently depending on context (e.g. <form>, <table>, <a> as link/button),
|
||||||
* * styles with multiple selectors should have all selectors with same
|
* * styles with multiple selectors should have all selectors with same
|
||||||
* specificity, to allow proper rule specificity vs order management.
|
* specificity, to allow proper rule specificity vs order management.
|
||||||
*
|
*
|
||||||
* NOTE: style in a modular way, similar to how CSS @scope would be used,
|
* NOTE: style in a modular way, similar to how CSS @scope would be used,
|
||||||
* to make transition easier once @scope is widely available. */
|
* to make transition easier once @scope is widely available. */
|
||||||
/* TODO: review styles with multiple selectors and try to convert them to the same
|
|
||||||
* specificity. */
|
|
||||||
:root {
|
:root {
|
||||||
--color-focus-gray: #f3f3f3;
|
--color-focus-gray: #f3f3f3;
|
||||||
--color-border-gray: #dddddd;
|
--color-border-gray: #dddddd;
|
||||||
@@ -57,8 +55,8 @@
|
|||||||
:focus-visible {
|
:focus-visible {
|
||||||
outline: none;
|
outline: none;
|
||||||
}
|
}
|
||||||
/* NOTE: move to higher priority layer instead of using !important? */
|
/* NOTE: move to higher priority layer instead of using !important?; add CSS
|
||||||
/* TODO: add CSS @layer requirements in README */
|
* @layer requirements in README */
|
||||||
[disabled] {
|
[disabled] {
|
||||||
border-color: var(--color-border-gray) !important;
|
border-color: var(--color-border-gray) !important;
|
||||||
color: var(--color-border-gray) !important;
|
color: var(--color-border-gray) !important;
|
||||||
@@ -80,10 +78,13 @@
|
|||||||
* gray - target for interaction with keyboard,
|
* gray - target for interaction with keyboard,
|
||||||
* red - destructive, non-undoable action.
|
* red - destructive, non-undoable action.
|
||||||
*/
|
*/
|
||||||
|
/* TODO: merge selectors using :is() */
|
||||||
|
a,
|
||||||
button,
|
button,
|
||||||
details,
|
details,
|
||||||
input,
|
input,
|
||||||
select,
|
select,
|
||||||
|
summary,
|
||||||
textarea {
|
textarea {
|
||||||
background-color: inherit;
|
background-color: inherit;
|
||||||
font: inherit;
|
font: inherit;
|
||||||
@@ -101,7 +102,14 @@ textarea {
|
|||||||
border-radius: 0.25em;
|
border-radius: 0.25em;
|
||||||
padding: 0.2em 0.4em;
|
padding: 0.2em 0.4em;
|
||||||
}
|
}
|
||||||
svg,
|
svg {
|
||||||
|
height: 1.4em;
|
||||||
|
margin: 0 0.2em 0 0;
|
||||||
|
width: 1.4em;
|
||||||
|
}
|
||||||
|
svg:last-child {
|
||||||
|
margin-right: 0;
|
||||||
|
}
|
||||||
textarea {
|
textarea {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
}
|
}
|
||||||
@@ -153,6 +161,10 @@ table form summary,
|
|||||||
table form textarea {
|
table form textarea {
|
||||||
color: inherit;
|
color: inherit;
|
||||||
}
|
}
|
||||||
|
table svg:not(:only-child) {
|
||||||
|
height: 1.25em;
|
||||||
|
width: 1.25em;
|
||||||
|
}
|
||||||
input:focus-visible,
|
input:focus-visible,
|
||||||
select:focus-visible,
|
select:focus-visible,
|
||||||
select:focus-within,
|
select:focus-within,
|
||||||
@@ -214,21 +226,17 @@ textarea:invalid {
|
|||||||
padding: 0.6em 0.5em;
|
padding: 0.6em 0.5em;
|
||||||
width: fit-content;
|
width: fit-content;
|
||||||
}
|
}
|
||||||
|
.link {
|
||||||
|
color: inherit;
|
||||||
|
text-decoration: underline 1px var(--color-border-gray);
|
||||||
|
text-underline-offset: 0.25em;
|
||||||
|
}
|
||||||
[name=cancel],
|
[name=cancel],
|
||||||
.auxiliary {
|
.auxiliary {
|
||||||
border-color: var(--color-border-gray);
|
border-color: var(--color-border-gray);
|
||||||
color: var(--color-nav-gray);
|
color: var(--color-nav-gray);
|
||||||
fill: var(--color-nav-gray);
|
fill: var(--color-nav-gray);
|
||||||
}
|
}
|
||||||
.button > svg,
|
|
||||||
.tab > svg {
|
|
||||||
height: 1.4em;
|
|
||||||
width: 1.4em;
|
|
||||||
}
|
|
||||||
.button > svg:not(:last-child),
|
|
||||||
.tab > svg:not(:last-child) {
|
|
||||||
margin-right: 0.2em;
|
|
||||||
}
|
|
||||||
.button:focus-visible,
|
.button:focus-visible,
|
||||||
.tab:focus-visible,
|
.tab:focus-visible,
|
||||||
.tab:hover {
|
.tab:hover {
|
||||||
@@ -244,6 +252,13 @@ textarea:invalid {
|
|||||||
background-color: var(--color-red);
|
background-color: var(--color-red);
|
||||||
border-color: var(--color-red);
|
border-color: var(--color-red);
|
||||||
}
|
}
|
||||||
|
.link:focus-visible {
|
||||||
|
text-decoration-color: var(--color-gray);
|
||||||
|
}
|
||||||
|
.link:hover {
|
||||||
|
color: var(--color-blue);
|
||||||
|
text-decoration-color: var(--color-blue);
|
||||||
|
}
|
||||||
table .button {
|
table .button {
|
||||||
border-color: var(--color-border-gray);
|
border-color: var(--color-border-gray);
|
||||||
color: var(--color-table-gray);
|
color: var(--color-table-gray);
|
||||||
@@ -251,15 +266,6 @@ table .button {
|
|||||||
height: 100%;
|
height: 100%;
|
||||||
padding: 0.4em;
|
padding: 0.4em;
|
||||||
}
|
}
|
||||||
/* TODO: move normal, non-button links (<a>:hover/:focus) styling here (i.e.
|
|
||||||
* page-wide, top-level) and remove from `table.items` - as the style should be
|
|
||||||
* same everywhere. */
|
|
||||||
/* TODO: apply link class to non-button/-tab links. Add light underscore for links? */
|
|
||||||
input[type=text]:read-only,
|
|
||||||
textarea:read-only {
|
|
||||||
border: none;
|
|
||||||
padding-inline: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* NOTE: collapse gaps around empty rows (`topside`) once possible with
|
/* NOTE: collapse gaps around empty rows (`topside`) once possible with
|
||||||
@@ -271,16 +277,16 @@ body {
|
|||||||
grid-template-areas:
|
grid-template-areas:
|
||||||
"header header header"
|
"header header header"
|
||||||
"nav nav nav"
|
"nav nav nav"
|
||||||
"leftside topside rightside"
|
|
||||||
"leftside main rightside";
|
"leftside main rightside";
|
||||||
grid-template-columns: 1fr minmax(max-content, 2fr) 1fr;
|
grid-template-columns: 1fr minmax(max-content, 2fr) 1fr;
|
||||||
font-family: system-ui;
|
font-family: system-ui;
|
||||||
margin: 0.4em;
|
margin: 0.4em;
|
||||||
}
|
}
|
||||||
body:not(:has(.topside-area)) {
|
body:has(> .topside-area) {
|
||||||
grid-template-areas:
|
grid-template-areas:
|
||||||
"header header header"
|
"header header header"
|
||||||
"nav nav nav"
|
"nav nav nav"
|
||||||
|
"leftside topside rightside"
|
||||||
"leftside main rightside";
|
"leftside main rightside";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -431,14 +437,18 @@ header {
|
|||||||
|
|
||||||
.tabular-form table {
|
.tabular-form table {
|
||||||
border: none;
|
border: none;
|
||||||
|
border-spacing: 0.4em 0;
|
||||||
|
margin-inline: -0.4em;
|
||||||
}
|
}
|
||||||
.tabular-form table td {
|
.tabular-form table td {
|
||||||
border: none;
|
border: none;
|
||||||
text-align: left;
|
|
||||||
vertical-align: middle;
|
vertical-align: middle;
|
||||||
}
|
}
|
||||||
.tabular-form table td:first-child {
|
.tabular-form table td {
|
||||||
color: inherit;
|
padding-inline: 0;
|
||||||
|
}
|
||||||
|
.tabular-form table :is(form, input, select, textarea):only-child {
|
||||||
|
margin-inline-start: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -457,59 +467,41 @@ header {
|
|||||||
background-color: var(--color-focus-gray);
|
background-color: var(--color-focus-gray);
|
||||||
}
|
}
|
||||||
.items-table th {
|
.items-table th {
|
||||||
padding-block: 0.75em;
|
padding: 0.75em 0 0.75em 1em;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
.items-table th,
|
|
||||||
.items-table td {
|
|
||||||
padding-inline: 1em 0;
|
|
||||||
}
|
|
||||||
/* For <a> to fill <td> completely, we use an `::after` pseudoelement. */
|
|
||||||
.items-table td.link {
|
|
||||||
padding: 0;
|
|
||||||
position: relative;
|
|
||||||
}
|
|
||||||
.items-table td.link a {
|
|
||||||
color: inherit;
|
|
||||||
font: inherit;
|
|
||||||
}
|
|
||||||
.items-table td.link a::after {
|
|
||||||
content: '';
|
|
||||||
inset: 0;
|
|
||||||
position: absolute;
|
|
||||||
}
|
|
||||||
.items-table td:first-child {
|
|
||||||
padding-inline-start: calc(1em + var(--depth) * 0.8em);
|
|
||||||
}
|
|
||||||
.items-table td:has(input, select, textarea) {
|
|
||||||
padding-inline-start: calc(0.6em - 0.9px);
|
|
||||||
}
|
|
||||||
.items-table td:first-child:has(input, select, textarea) {
|
|
||||||
padding-inline-start: calc(0.6em + var(--depth) * 0.8em - 0.9px);
|
|
||||||
}
|
|
||||||
.items-table th:last-child {
|
.items-table th:last-child {
|
||||||
padding-inline-end: 0.4em;
|
padding-inline-end: 0.4em;
|
||||||
}
|
}
|
||||||
.items-table td:last-child {
|
|
||||||
padding-inline-end: 0.1em;
|
|
||||||
}
|
|
||||||
.items-table td {
|
.items-table td {
|
||||||
border-top: 1px solid var(--color-border-gray);
|
border-top: 1px solid var(--color-border-gray);
|
||||||
height: 2.4em;
|
height: 2.4em;
|
||||||
padding-block: 0.1em;
|
padding: 0.1em 0 0.1em calc(1em + var(--depth) * 0.8em);
|
||||||
}
|
}
|
||||||
.items-table .actions {
|
.items-table td:last-child {
|
||||||
display: flex;
|
padding-inline-end: 0.1em;
|
||||||
|
}
|
||||||
|
.items-table :is(form, input, select, textarea):only-child {
|
||||||
|
margin-inline-start: calc(-0.4em - 0.9px);
|
||||||
|
}
|
||||||
|
/* For <a> to fill table cell completely, we use an `::after` pseudoelement. */
|
||||||
|
/* TODO: expand to whole row? will require adjusting z-index on inputs/buttons */
|
||||||
|
.items-table td:has(> .link) {
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
.items-table .link::after {
|
||||||
|
content: '';
|
||||||
|
inset: -1px 0 0 0;
|
||||||
|
position: absolute;
|
||||||
|
}
|
||||||
|
.items-table .flex {
|
||||||
gap: 0.4em;
|
gap: 0.4em;
|
||||||
justify-content: end;
|
justify-content: end;
|
||||||
}
|
}
|
||||||
.items-table .actions.centered {
|
.items-table .dropzone {
|
||||||
justify-content: center;
|
|
||||||
}
|
|
||||||
.items-table tr.dropzone {
|
|
||||||
position: relative;
|
position: relative;
|
||||||
}
|
}
|
||||||
.items-table tr.dropzone::after {
|
.items-table .dropzone::after {
|
||||||
content: '';
|
content: '';
|
||||||
inset: 1px 0 0 0;
|
inset: 1px 0 0 0;
|
||||||
position: absolute;
|
position: absolute;
|
||||||
@@ -517,72 +509,37 @@ header {
|
|||||||
outline-offset: -1px;
|
outline-offset: -1px;
|
||||||
z-index: var(--z-index-table-row-outline);
|
z-index: var(--z-index-table-row-outline);
|
||||||
}
|
}
|
||||||
.items-table td.handle {
|
.items-table .handle {
|
||||||
cursor: move;
|
cursor: grab;
|
||||||
}
|
}
|
||||||
.items-table tr.form td {
|
.items-table .form td {
|
||||||
vertical-align: top;
|
vertical-align: top;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO: replace `:hover:focus-visible` combos with proper LOVE style order. */
|
|
||||||
/* TODO: update table styling: simplify selectors, deduplicate, remove non-font rem. */
|
|
||||||
.items-table td.link a:hover,
|
|
||||||
.items-table td.link a:focus-visible,
|
|
||||||
.items-table td.link a:hover:focus-visible {
|
|
||||||
text-decoration: underline;
|
|
||||||
text-decoration-thickness: 0.05rem;
|
|
||||||
text-underline-offset: 0.2rem;
|
|
||||||
}
|
|
||||||
.items-table td.link a:hover {
|
|
||||||
color: var(--color-blue);
|
|
||||||
}
|
|
||||||
.items-table td.link a:focus-visible {
|
|
||||||
text-decoration-color: var(--color-gray);
|
|
||||||
}
|
|
||||||
.items-table td.link a:hover:focus-visible {
|
|
||||||
color: var(--color-dark-blue);
|
|
||||||
}
|
|
||||||
|
|
||||||
.items-table td:not(:first-child),
|
.items-table td:not(:first-child),
|
||||||
.grayed {
|
.grayed {
|
||||||
color: var(--color-table-gray);
|
color: var(--color-table-gray);
|
||||||
fill: var(--color-table-gray);
|
fill: var(--color-gray);
|
||||||
}
|
}
|
||||||
.items-table svg {
|
.items-table td:has(> svg:only-child) {
|
||||||
height: 1rem;
|
|
||||||
vertical-align: middle;
|
|
||||||
width: 1rem;
|
|
||||||
}
|
|
||||||
.items-table svg:last-child {
|
|
||||||
height: 1.2rem;
|
|
||||||
width: 1.2rem;
|
|
||||||
}
|
|
||||||
.items-table td.svg {
|
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
.items-table td.number {
|
|
||||||
text-align: right;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
.centered {
|
.center {
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
}
|
}
|
||||||
.extendedright {
|
|
||||||
margin-right: auto;
|
|
||||||
}
|
|
||||||
.hexpand {
|
.hexpand {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
.hflex {
|
.flex {
|
||||||
display: flex;
|
display: flex;
|
||||||
gap: 0.8em;
|
gap: 0.8em;
|
||||||
}
|
}
|
||||||
.hflex.reverse {
|
.flex.reverse {
|
||||||
flex-direction: row-reverse;
|
flex-direction: row-reverse;
|
||||||
}
|
}
|
||||||
.hflex.centered {
|
.flex.vertical {
|
||||||
justify-content: center;
|
flex-direction: column;
|
||||||
}
|
}
|
||||||
.hint {
|
.hint {
|
||||||
color: var(--color-table-gray);
|
color: var(--color-table-gray);
|
||||||
@@ -597,10 +554,11 @@ header {
|
|||||||
color: var(--color-gray);
|
color: var(--color-gray);
|
||||||
font-style: italic;
|
font-style: italic;
|
||||||
}
|
}
|
||||||
.vflex {
|
.ralign {
|
||||||
display: flex;
|
text-align: right;
|
||||||
gap: 0.8em;
|
}
|
||||||
flex-direction: column;
|
.rextend {
|
||||||
|
margin-right: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -647,7 +605,7 @@ summary::marker {
|
|||||||
}
|
}
|
||||||
/* NOTE: use `details[open]::details-content` once widely available. */
|
/* NOTE: use `details[open]::details-content` once widely available. */
|
||||||
details[open] ul {
|
details[open] ul {
|
||||||
background: white;
|
background-color: white;
|
||||||
border: 1px solid var(--color-border-gray);
|
border: 1px solid var(--color-border-gray);
|
||||||
border-radius: 0.25em;
|
border-radius: 0.25em;
|
||||||
box-shadow: 1px 1px 3px var(--color-border-gray);
|
box-shadow: 1px 1px 3px var(--color-border-gray);
|
||||||
@@ -670,11 +628,6 @@ li input[type=checkbox] {
|
|||||||
li::marker {
|
li::marker {
|
||||||
content: '';
|
content: '';
|
||||||
}
|
}
|
||||||
|
|
||||||
#measurement_form {
|
|
||||||
min-width: 66%;
|
|
||||||
width: max-content;
|
|
||||||
}
|
|
||||||
/*
|
/*
|
||||||
* TODO:
|
* TODO:
|
||||||
* * disable <label> containing disabled checkbox: `label:has(input[disabled])`,
|
* * disable <label> containing disabled checkbox: `label:has(input[disabled])`,
|
||||||
@@ -682,3 +635,8 @@ li::marker {
|
|||||||
* * focused label styling (currently only checkbox has focus),
|
* * focused label styling (currently only checkbox has focus),
|
||||||
* * disabled checkbox blue square focus removal.
|
* * disabled checkbox blue square focus removal.
|
||||||
* */
|
* */
|
||||||
|
|
||||||
|
#measurement_form {
|
||||||
|
min-width: 66%;
|
||||||
|
width: max-content;
|
||||||
|
}
|
||||||
|
|||||||
@@ -8,6 +8,10 @@ class QuantitiesController < ApplicationController
|
|||||||
raise AccessForbidden unless current_user.at_least(:active)
|
raise AccessForbidden unless current_user.at_least(:active)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
before_action only: [:new, :edit, :create, :update] do
|
||||||
|
@user_units = current_user.units.ordered
|
||||||
|
end
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@quantities = current_user.quantities.ordered.includes(:parent, :subquantities)
|
@quantities = current_user.quantities.ordered.includes(:parent, :subquantities)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -86,6 +86,7 @@ module ApplicationHelper
|
|||||||
def initialize(...)
|
def initialize(...)
|
||||||
super(...)
|
super(...)
|
||||||
@default_options.merge!(@options.slice(:form))
|
@default_options.merge!(@options.slice(:form))
|
||||||
|
@default_html_options.merge!(@options.slice(:form))
|
||||||
end
|
end
|
||||||
|
|
||||||
[:text_field, :password_field, :text_area].each do |selector|
|
[:text_field, :password_field, :text_area].each do |selector|
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
class Quantity < ApplicationRecord
|
class Quantity < ApplicationRecord
|
||||||
ATTRIBUTES = [:name, :description, :parent_id]
|
ATTRIBUTES = [:name, :description, :parent_id, :default_unit_id]
|
||||||
attr_cached :depth, :pathname
|
attr_cached :depth, :pathname
|
||||||
|
|
||||||
belongs_to :user, optional: true
|
belongs_to :user, optional: true
|
||||||
belongs_to :parent, optional: true, class_name: "Quantity"
|
belongs_to :parent, optional: true, class_name: "Quantity"
|
||||||
|
belongs_to :default_unit, optional: true, class_name: "Unit"
|
||||||
has_many :subquantities, ->{ order(:name) }, class_name: "Quantity",
|
has_many :subquantities, ->{ order(:name) }, class_name: "Quantity",
|
||||||
inverse_of: :parent, dependent: :restrict_with_error
|
inverse_of: :parent, dependent: :restrict_with_error
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
class Readout < ApplicationRecord
|
class Readout < ApplicationRecord
|
||||||
ATTRIBUTES = [:quantity_id, :value, :unit_id]
|
ATTRIBUTES = [:quantity_id, :value, :unit_id, :taken_at]
|
||||||
|
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
belongs_to :quantity
|
belongs_to :quantity
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
</td>
|
</td>
|
||||||
|
|
||||||
<% if current_user.at_least(:active) %>
|
<% if current_user.at_least(:active) %>
|
||||||
<td class="actions">
|
<td class="flex">
|
||||||
<% unless unit.portable.nil? %>
|
<% unless unit.portable.nil? %>
|
||||||
<% if unit.default? %>
|
<% if unit.default? %>
|
||||||
<%= image_button_to_if unit.portable?, t('.import'), 'download-outline',
|
<%= image_button_to_if unit.portable?, t('.import'), 'download-outline',
|
||||||
|
|||||||
@@ -23,10 +23,10 @@
|
|||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<header class="hflex">
|
<header class="flex">
|
||||||
<%= image_link_to t(".source_code"), "code-braces", source_code_url %>
|
<%= image_link_to t(".source_code"), "code-braces", source_code_url %>
|
||||||
<%= image_link_to t(".issue_tracker"), "bug-outline", issue_tracker_url,
|
<%= image_link_to t(".issue_tracker"), "bug-outline", issue_tracker_url,
|
||||||
class: "extendedright" %>
|
class: "rextend" %>
|
||||||
<% if user_signed_in? %>
|
<% if user_signed_in? %>
|
||||||
<%= image_link_to_unless_current(current_user, "account-wrench-outline",
|
<%= image_link_to_unless_current(current_user, "account-wrench-outline",
|
||||||
edit_user_registration_path) %>
|
edit_user_registration_path) %>
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
<%= tabular_form_with model: Measurement.new, id: :measurement_form,
|
<%= tabular_form_with model: Measurement.new, id: :measurement_form,
|
||||||
class: 'topside-area vflex centered',
|
class: 'topside-area flex vertical center',
|
||||||
html: {onkeydown: 'formProcessKey(event)'} do |form| %>
|
html: {onkeydown: 'formProcessKey(event)'} do |form| %>
|
||||||
|
|
||||||
<table class="items-table centered">
|
<table class="items-table center">
|
||||||
<tbody id="readouts">
|
<tbody id="readouts">
|
||||||
<%= tabular_fields_for @measurement do |form| %>
|
<%= tabular_fields_for @measurement do |form| %>
|
||||||
<tr class="italic">
|
<tr class="italic">
|
||||||
<td class="hexpand hmin50"><%= t '.taken_at_html' %></td>
|
<td class="hexpand hmin50"><%= t '.taken_at_html' %></td>
|
||||||
<td colspan="3" class="number">
|
<td colspan="3" class="ralign">
|
||||||
<%= form.datetime_field :taken_at, required: true %>
|
<%= form.datetime_field :taken_at, required: true, value: Time.current.strftime('%Y-%m-%dT%H:%M') %>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
@@ -16,7 +16,7 @@
|
|||||||
</table>
|
</table>
|
||||||
|
|
||||||
<%# TODO: right-click selection; unnecessary with hierarchical tags? %>
|
<%# TODO: right-click selection; unnecessary with hierarchical tags? %>
|
||||||
<details id="quantity_select" class="centered hexpand" open
|
<details id="quantity_select" class="center hexpand" open
|
||||||
onkeydown="detailsProcessKey(event)">
|
onkeydown="detailsProcessKey(event)">
|
||||||
<summary autofocus>
|
<summary autofocus>
|
||||||
<!-- TODO: Set content with CSS when span empty to avoid duplication -->
|
<!-- TODO: Set content with CSS when span empty to avoid duplication -->
|
||||||
@@ -30,7 +30,7 @@
|
|||||||
<ul><%= quantities_check_boxes(@quantities) %></ul>
|
<ul><%= quantities_check_boxes(@quantities) %></ul>
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
<div class="hflex reverse">
|
<div class="flex reverse">
|
||||||
<%= form.button id: :create_measurement_button, disabled: true -%>
|
<%= form.button id: :create_measurement_button, disabled: true -%>
|
||||||
<%= image_link_to t(:cancel), "close-outline", measurements_path, name: :cancel,
|
<%= image_link_to t(:cancel), "close-outline", measurements_path, name: :cancel,
|
||||||
class: 'dangerous', onclick: render_turbo_stream('form_close') %>
|
class: 'dangerous', onclick: render_turbo_stream('form_close') %>
|
||||||
|
|||||||
@@ -8,8 +8,13 @@
|
|||||||
<td>
|
<td>
|
||||||
<%= form.text_area :description, cols: 30, rows: 1, escape: false %>
|
<%= form.text_area :description, cols: 30, rows: 1, escape: false %>
|
||||||
</td>
|
</td>
|
||||||
|
<td>
|
||||||
|
<%= form.collection_select :default_unit_id, @user_units, :id,
|
||||||
|
->(u){ sanitize(' ' * (u.base_id? ? 1 : 0) + u.symbol) },
|
||||||
|
{include_blank: true}, onchange: "this.dataset.changed = ''" %>
|
||||||
|
</td>
|
||||||
|
|
||||||
<td class="actions">
|
<td class="flex">
|
||||||
<%= form.button %>
|
<%= form.button %>
|
||||||
<%= image_link_to t(:cancel), "close-outline", quantities_path, class: 'dangerous',
|
<%= image_link_to t(:cancel), "close-outline", quantities_path, class: 'dangerous',
|
||||||
name: :cancel, onclick: render_turbo_stream('form_close', {row: row}) %>
|
name: :cancel, onclick: render_turbo_stream('form_close', {row: row}) %>
|
||||||
|
|||||||
@@ -5,14 +5,15 @@
|
|||||||
data: {drag_path: reparent_quantity_path(quantity), drop_id: dom_id(quantity),
|
data: {drag_path: reparent_quantity_path(quantity), drop_id: dom_id(quantity),
|
||||||
drop_id_param: "quantity[parent_id]"} do %>
|
drop_id_param: "quantity[parent_id]"} do %>
|
||||||
|
|
||||||
<td class="link" style="--depth:<%= quantity.depth %>">
|
<td style="--depth:<%= quantity.depth %>">
|
||||||
<%= link_to quantity, edit_quantity_path(quantity), onclick: 'this.blur();',
|
<%= link_to quantity, edit_quantity_path(quantity), class: 'link',
|
||||||
data: {turbo_stream: true} %>
|
onclick: 'this.blur();', data: {turbo_stream: true} %>
|
||||||
</td>
|
</td>
|
||||||
<td><%= quantity.description %></td>
|
<td><%= quantity.description %></td>
|
||||||
|
<td><%= quantity.default_unit&.symbol %></td>
|
||||||
|
|
||||||
<% if current_user.at_least(:active) %>
|
<% if current_user.at_least(:active) %>
|
||||||
<td class="actions">
|
<td class="flex">
|
||||||
<%= image_link_to t('.new_subquantity'), 'plus-outline', new_quantity_path(quantity),
|
<%= image_link_to t('.new_subquantity'), 'plus-outline', new_quantity_path(quantity),
|
||||||
id: dom_id(quantity, :new, :link), onclick: 'this.blur();', data: {turbo_stream: true} %>
|
id: dom_id(quantity, :new, :link), onclick: 'this.blur();', data: {turbo_stream: true} %>
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,8 @@
|
|||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th><%= Quantity.human_attribute_name(:name) %></th>
|
<th><%= Quantity.human_attribute_name(:name) %></th>
|
||||||
<th><%= Quantity.human_attribute_name(:description) %></th>
|
<th class="hexpand"><%= Quantity.human_attribute_name(:description) %></th>
|
||||||
|
<th><%= Quantity.human_attribute_name(:default_unit) %></th>
|
||||||
<% if current_user.at_least(:active) %>
|
<% if current_user.at_least(:active) %>
|
||||||
<th><%= t :actions %></th>
|
<th><%= t :actions %></th>
|
||||||
<th></th>
|
<th></th>
|
||||||
@@ -25,7 +26,7 @@
|
|||||||
ondragover: "dragOver(event)", ondrop: "drop(event)",
|
ondragover: "dragOver(event)", ondrop: "drop(event)",
|
||||||
ondragenter: "dragEnter(event)", ondragleave: "dragLeave(event)",
|
ondragenter: "dragEnter(event)", ondragleave: "dragLeave(event)",
|
||||||
data: {drop_id: "quantity_", drop_id_param: "quantity[parent_id]"} do %>
|
data: {drop_id: "quantity_", drop_id_param: "quantity[parent_id]"} do %>
|
||||||
<th colspan="4"><%= t '.top_level_drop' %></th>
|
<th colspan="5"><%= t '.top_level_drop' %></th>
|
||||||
<% end %>
|
<% end %>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody id="quantities">
|
<tbody id="quantities">
|
||||||
|
|||||||
@@ -4,18 +4,25 @@
|
|||||||
<td>
|
<td>
|
||||||
<%# TODO: add grayed readout index (in separate column?) %>
|
<%# TODO: add grayed readout index (in separate column?) %>
|
||||||
<%= readout.quantity.relative_pathname(@superquantity) %>
|
<%= readout.quantity.relative_pathname(@superquantity) %>
|
||||||
|
<%= form.hidden_field :quantity_id %>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<%= form.number_field :value, required: true, autofocus: readout_counter == 0 %>
|
<%= form.number_field :value, required: true, autofocus: readout_counter == 0 %>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<%= form.hidden_field :quantity_id %>
|
|
||||||
<%= form.collection_select :unit_id, @user_units, :id,
|
<%= form.collection_select :unit_id, @user_units, :id,
|
||||||
->(u){ sanitize(' ' * (u.base_id ? 1 : 0) + u.symbol) },
|
->(u){ sanitize(' ' * (u.base_id ? 1 : 0) + u.symbol) },
|
||||||
{prompt: '', disabled: '', selected: ''}, required: true %>
|
{prompt: '', disabled: '', selected: readout.quantity.default_unit_id || ''}, required: true,
|
||||||
|
data: {default_unit_id: readout.quantity.default_unit_id || ''},
|
||||||
|
onchange: "readoutUnitChanged(this)" %>
|
||||||
</td>
|
</td>
|
||||||
<td class="actions">
|
<td class="flex">
|
||||||
<%# TODO: change to _link_ after giving up displaying relative paths %>
|
<%# TODO: change to _link_ after giving up displaying relative paths %>
|
||||||
|
<%= image_button_tag '', 'check-circle-outline',
|
||||||
|
class: 'set-default-unit', name: nil, type: 'button', disabled: true,
|
||||||
|
title: t('readouts.form.set_default_unit'),
|
||||||
|
data: {path: quantity_path(readout.quantity)},
|
||||||
|
onclick: 'setDefaultUnit(this)' %>
|
||||||
<%= image_button_tag '', 'delete-outline', class: 'dangerous', name: nil,
|
<%= image_button_tag '', 'delete-outline', class: 'dangerous', name: nil,
|
||||||
formaction: discard_readouts_path(readout.quantity),
|
formaction: discard_readouts_path(readout.quantity),
|
||||||
formmethod: :get, formnovalidate: true, data: {turbo_stream: true} %>
|
formmethod: :get, formnovalidate: true, data: {turbo_stream: true} %>
|
||||||
|
|||||||
@@ -8,11 +8,11 @@
|
|||||||
<td>
|
<td>
|
||||||
<%= form.text_area :description, cols: 30, rows: 1, escape: false %>
|
<%= form.text_area :description, cols: 30, rows: 1, escape: false %>
|
||||||
</td>
|
</td>
|
||||||
<td class="number">
|
<td>
|
||||||
<%= form.number_field :multiplier, required: true, size: 10, min: :step if @unit.base_id? %>
|
<%= form.number_field :multiplier, required: true, size: 10, min: :step if @unit.base_id? %>
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
<td class="actions">
|
<td class="flex">
|
||||||
<%= form.button %>
|
<%= form.button %>
|
||||||
<%= image_link_to t(:cancel), "close-outline", units_path, class: 'dangerous',
|
<%= image_link_to t(:cancel), "close-outline", units_path, class: 'dangerous',
|
||||||
name: :cancel, onclick: render_turbo_stream('form_close', {row: row}) %>
|
name: :cancel, onclick: render_turbo_stream('form_close', {row: row}) %>
|
||||||
|
|||||||
@@ -6,14 +6,15 @@
|
|||||||
drop_id: dom_id(unit.base || unit),
|
drop_id: dom_id(unit.base || unit),
|
||||||
drop_id_param: "unit[base_id]"} do %>
|
drop_id_param: "unit[base_id]"} do %>
|
||||||
|
|
||||||
<td class="link" style="--depth:<%= unit.base_id? ? 1 : 0 %>">
|
<td style="--depth:<%= unit.base_id? ? 1 : 0 %>">
|
||||||
<%= link_to unit, edit_unit_path(unit), onclick: 'this.blur();', data: {turbo_stream: true} %>
|
<%= link_to unit, edit_unit_path(unit), class: 'link', onclick: 'this.blur();',
|
||||||
|
data: {turbo_stream: true} %>
|
||||||
</td>
|
</td>
|
||||||
<td><%= unit.description %></td>
|
<td><%= unit.description %></td>
|
||||||
<td class="number"><%= unit.multiplier.to_html %></td>
|
<td class="ralign"><%= unit.multiplier.to_html %></td>
|
||||||
|
|
||||||
<% if current_user.at_least(:active) %>
|
<% if current_user.at_least(:active) %>
|
||||||
<td class="actions">
|
<td class="flex">
|
||||||
<% unless unit.base_id? %>
|
<% unless unit.base_id? %>
|
||||||
<%= image_link_to t('.new_subunit'), 'plus-outline', new_unit_path(unit),
|
<%= image_link_to t('.new_subunit'), 'plus-outline', new_unit_path(unit),
|
||||||
id: dom_id(unit, :new, :link), onclick: 'this.blur();', data: {turbo_stream: true} %>
|
id: dom_id(unit, :new, :link), onclick: 'this.blur();', data: {turbo_stream: true} %>
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th><%= Unit.human_attribute_name(:symbol) %></th>
|
<th><%= Unit.human_attribute_name(:symbol) %></th>
|
||||||
<th><%= Unit.human_attribute_name(:description) %></th>
|
<th class="hexpand"><%= Unit.human_attribute_name(:description) %></th>
|
||||||
<th><%= Unit.human_attribute_name(:multiplier) %></th>
|
<th><%= Unit.human_attribute_name(:multiplier) %></th>
|
||||||
<% if current_user.at_least(:active) %>
|
<% if current_user.at_least(:active) %>
|
||||||
<th><%= t :actions %></th>
|
<th><%= t :actions %></th>
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
<tbody>
|
<tbody>
|
||||||
<% @users.each do |user| %>
|
<% @users.each do |user| %>
|
||||||
<tr>
|
<tr>
|
||||||
<td class="link"><%= link_to user, user_path(user) %></td>
|
<td><%= link_to user, user_path(user), class: 'link' %></td>
|
||||||
<td>
|
<td>
|
||||||
<% if user == current_user %>
|
<% if user == current_user %>
|
||||||
<%= user.status %>
|
<%= user.status %>
|
||||||
@@ -22,11 +22,11 @@
|
|||||||
<% end %>
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</td>
|
</td>
|
||||||
<td class="svg">
|
<td>
|
||||||
<%= svg_tag 'pictograms/checkbox-marked-outline' if user.confirmed_at.present? %>
|
<%= svg_tag 'pictograms/checkbox-marked-outline' if user.confirmed_at.present? %>
|
||||||
</td>
|
</td>
|
||||||
<td><%= l user.created_at, format: :without_tz %></td>
|
<td><%= l user.created_at, format: :without_tz %></td>
|
||||||
<td class="actions">
|
<td class="flex">
|
||||||
<% if allow_disguise?(user) %>
|
<% if allow_disguise?(user) %>
|
||||||
<%= image_link_to t('.disguise'), 'incognito', disguise_user_path(user) %>
|
<%= image_link_to t('.disguise'), 'incognito', disguise_user_path(user) %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
<%= f.email_field :email, autofocus: true, autocomplete: "email" %>
|
<%= f.email_field :email, autofocus: true, autocomplete: "email" %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="actions">
|
<div class="flex">
|
||||||
<%= f.submit "Resend unlock instructions" %>
|
<%= f.submit "Resend unlock instructions" %>
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -58,4 +58,7 @@ Rails.application.configure do
|
|||||||
# config.action_view.annotate_rendered_view_with_filenames = true
|
# config.action_view.annotate_rendered_view_with_filenames = true
|
||||||
|
|
||||||
config.log_level = :info
|
config.log_level = :info
|
||||||
|
|
||||||
|
# Allow Capybara's dynamic test server host (127.0.0.1:<random_port>)
|
||||||
|
config.hosts << '127.0.0.1'
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -11,8 +11,13 @@ en:
|
|||||||
activerecord:
|
activerecord:
|
||||||
attributes:
|
attributes:
|
||||||
quantity:
|
quantity:
|
||||||
|
default_unit: Default unit
|
||||||
description: Description
|
description: Description
|
||||||
name: Name
|
name: Name
|
||||||
|
readout:
|
||||||
|
created_at: Recorded at
|
||||||
|
taken_at: Taken at
|
||||||
|
value: Value
|
||||||
unit:
|
unit:
|
||||||
base: Base unit
|
base: Base unit
|
||||||
description: Description
|
description: Description
|
||||||
@@ -81,6 +86,9 @@ en:
|
|||||||
revert: Revert
|
revert: Revert
|
||||||
sign_out: Sign out
|
sign_out: Sign out
|
||||||
source_code: Get code
|
source_code: Get code
|
||||||
|
readouts:
|
||||||
|
form:
|
||||||
|
set_default_unit: Set as default unit
|
||||||
measurements:
|
measurements:
|
||||||
navigation: Measurements
|
navigation: Measurements
|
||||||
no_items: There are no measurements taken. You can Add some now.
|
no_items: There are no measurements taken. You can Add some now.
|
||||||
@@ -89,6 +97,15 @@ en:
|
|||||||
taken_at_html: Measurement taken at 
|
taken_at_html: Measurement taken at 
|
||||||
index:
|
index:
|
||||||
new_measurement: Add measurement
|
new_measurement: Add measurement
|
||||||
|
readout:
|
||||||
|
destroy: Delete
|
||||||
|
create:
|
||||||
|
success:
|
||||||
|
one: Recorded 1 measurement.
|
||||||
|
other: Recorded %{count} measurements.
|
||||||
|
no_readouts: No readouts selected.
|
||||||
|
destroy:
|
||||||
|
success: Measurement deleted.
|
||||||
quantities:
|
quantities:
|
||||||
navigation: Quantities
|
navigation: Quantities
|
||||||
no_items: There are no configured quantities. You can Add some or Import from defaults.
|
no_items: There are no configured quantities. You can Add some or Import from defaults.
|
||||||
|
|||||||
6
db/migrate/20260402000000_add_taken_at_to_readouts.rb
Normal file
6
db/migrate/20260402000000_add_taken_at_to_readouts.rb
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
class AddTakenAtToReadouts < ActiveRecord::Migration[7.2]
|
||||||
|
def change
|
||||||
|
add_column :readouts, :taken_at, :datetime
|
||||||
|
add_index :readouts, [:user_id, :taken_at]
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
class AddDefaultUnitToQuantities < ActiveRecord::Migration[7.2]
|
||||||
|
def change
|
||||||
|
add_reference :quantities, :default_unit, foreign_key: {to_table: :units}, null: true
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -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[7.2].define(version: 2025_01_21_230456) do
|
ActiveRecord::Schema[7.2].define(version: 2026_04_03_000000) do
|
||||||
create_table "quantities", charset: "utf8mb4", collation: "utf8mb4_0900_as_ci", force: :cascade do |t|
|
create_table "quantities", charset: "utf8mb4", collation: "utf8mb4_0900_as_ci", force: :cascade do |t|
|
||||||
t.bigint "user_id"
|
t.bigint "user_id"
|
||||||
t.string "name", limit: 31, null: false
|
t.string "name", limit: 31, null: false
|
||||||
@@ -20,6 +20,8 @@ ActiveRecord::Schema[7.2].define(version: 2025_01_21_230456) do
|
|||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at", null: false
|
||||||
t.integer "depth", default: 0, null: false
|
t.integer "depth", default: 0, null: false
|
||||||
t.string "pathname", limit: 511, null: false
|
t.string "pathname", limit: 511, null: false
|
||||||
|
t.bigint "default_unit_id"
|
||||||
|
t.index ["default_unit_id"], name: "index_quantities_on_default_unit_id"
|
||||||
t.index ["parent_id"], name: "index_quantities_on_parent_id"
|
t.index ["parent_id"], name: "index_quantities_on_parent_id"
|
||||||
t.index ["user_id", "parent_id", "name"], name: "index_quantities_on_user_id_and_parent_id_and_name", unique: true
|
t.index ["user_id", "parent_id", "name"], name: "index_quantities_on_user_id_and_parent_id_and_name", unique: true
|
||||||
t.index ["user_id"], name: "index_quantities_on_user_id"
|
t.index ["user_id"], name: "index_quantities_on_user_id"
|
||||||
@@ -32,10 +34,12 @@ ActiveRecord::Schema[7.2].define(version: 2025_01_21_230456) do
|
|||||||
t.decimal "value", precision: 30, scale: 15, null: false
|
t.decimal "value", precision: 30, scale: 15, null: false
|
||||||
t.datetime "created_at", null: false
|
t.datetime "created_at", null: false
|
||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at", null: false
|
||||||
|
t.datetime "taken_at"
|
||||||
t.index ["quantity_id", "created_at"], name: "index_readouts_on_quantity_id_and_created_at", unique: true
|
t.index ["quantity_id", "created_at"], name: "index_readouts_on_quantity_id_and_created_at", unique: true
|
||||||
t.index ["quantity_id"], name: "index_readouts_on_quantity_id"
|
t.index ["quantity_id"], name: "index_readouts_on_quantity_id"
|
||||||
t.index ["unit_id"], name: "index_readouts_on_unit_id"
|
t.index ["unit_id"], name: "index_readouts_on_unit_id"
|
||||||
t.index ["user_id"], name: "index_readouts_on_user_id"
|
t.index ["user_id"], name: "index_readouts_on_user_id"
|
||||||
|
t.index ["user_id", "taken_at"], name: "index_readouts_on_user_id_and_taken_at"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "units", charset: "utf8mb4", collation: "utf8mb4_0900_as_ci", force: :cascade do |t|
|
create_table "units", charset: "utf8mb4", collation: "utf8mb4_0900_as_ci", force: :cascade do |t|
|
||||||
@@ -70,6 +74,7 @@ ActiveRecord::Schema[7.2].define(version: 2025_01_21_230456) do
|
|||||||
end
|
end
|
||||||
|
|
||||||
add_foreign_key "quantities", "quantities", column: "parent_id", on_delete: :cascade
|
add_foreign_key "quantities", "quantities", column: "parent_id", on_delete: :cascade
|
||||||
|
add_foreign_key "quantities", "units", column: "default_unit_id"
|
||||||
add_foreign_key "quantities", "users"
|
add_foreign_key "quantities", "users"
|
||||||
add_foreign_key "readouts", "quantities"
|
add_foreign_key "readouts", "quantities"
|
||||||
add_foreign_key "readouts", "units"
|
add_foreign_key "readouts", "units"
|
||||||
|
|||||||
45
test/system/quantities_test.rb
Normal file
45
test/system/quantities_test.rb
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
require "application_system_test_case"
|
||||||
|
|
||||||
|
class QuantitiesTest < ApplicationSystemTestCase
|
||||||
|
setup do
|
||||||
|
@user = sign_in(user: users(:alice))
|
||||||
|
@unit = @user.units.create!(symbol: 'kg')
|
||||||
|
@quantity = @user.quantities.create!(name: 'Weight')
|
||||||
|
visit quantities_path
|
||||||
|
end
|
||||||
|
|
||||||
|
test "update button turns red when default unit changes" do
|
||||||
|
click_on 'Weight'
|
||||||
|
|
||||||
|
button = find('button[name=button]')
|
||||||
|
initial_color = evaluate_script("getComputedStyle(arguments[0]).backgroundColor", button)
|
||||||
|
|
||||||
|
select 'kg', from: 'quantity[default_unit_id]'
|
||||||
|
|
||||||
|
changed_color = evaluate_script("getComputedStyle(arguments[0]).backgroundColor", button)
|
||||||
|
refute_equal initial_color, changed_color, "Button color should change when default unit is altered"
|
||||||
|
end
|
||||||
|
|
||||||
|
test "saving default unit pre-selects it in measurements form" do
|
||||||
|
click_on 'Weight'
|
||||||
|
select 'kg', from: 'quantity[default_unit_id]'
|
||||||
|
click_on t('helpers.submit.update')
|
||||||
|
assert_selector '.flash.notice'
|
||||||
|
|
||||||
|
@quantity.reload
|
||||||
|
assert_equal @unit.id, @quantity.default_unit_id
|
||||||
|
|
||||||
|
visit measurements_path
|
||||||
|
find(:link_or_button, t('measurements.index.new_measurement')).click
|
||||||
|
assert_selector '#measurement_form'
|
||||||
|
|
||||||
|
within '#quantity_select' do
|
||||||
|
check 'Weight'
|
||||||
|
end
|
||||||
|
find('button[formaction]').click
|
||||||
|
|
||||||
|
within 'tbody#readouts' do
|
||||||
|
assert_selector "option[value='#{@unit.id}'][selected]"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user