janela 0.2.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +38 -1
  3. data/README.md +200 -20
  4. data/UPGRADING.md +136 -0
  5. data/app/assets/javascripts/janela/chart_controller.js +12 -5
  6. data/app/assets/javascripts/janela/{dashboard_controller.js → frame_controller.js} +11 -4
  7. data/app/assets/stylesheets/janela.css +163 -0
  8. data/app/controllers/janela/application_controller.rb +18 -0
  9. data/app/controllers/janela/frames_controller.rb +57 -0
  10. data/app/controllers/janela/panes_controller.rb +66 -13
  11. data/app/controllers/janela/queries_controller.rb +17 -0
  12. data/app/controllers/janela/{snapshot_panes_controller.rb → snapshot_queries_controller.rb} +7 -5
  13. data/app/helpers/janela/{dashboard_helper.rb → frames_helper.rb} +25 -9
  14. data/app/models/janela/frame.rb +28 -0
  15. data/app/models/janela/pane.rb +102 -99
  16. data/app/models/janela/query.rb +149 -0
  17. data/app/models/janela/snapshot.rb +5 -5
  18. data/app/views/janela/frames/_card.html.erb +7 -0
  19. data/app/views/janela/frames/_form.html.erb +23 -0
  20. data/app/views/janela/frames/_frame.html.erb +4 -0
  21. data/app/views/janela/frames/_pane.html.erb +12 -0
  22. data/app/views/janela/frames/edit.html.erb +25 -0
  23. data/app/views/janela/frames/index.html.erb +15 -0
  24. data/app/views/janela/frames/new.html.erb +5 -0
  25. data/app/views/janela/frames/show.html.erb +9 -0
  26. data/app/views/janela/panes/_form.html.erb +58 -0
  27. data/app/views/janela/panes/_row.html.erb +12 -0
  28. data/app/views/janela/panes/edit.html.erb +5 -0
  29. data/app/views/janela/panes/new.html.erb +22 -0
  30. data/app/views/janela/panes/show.html.erb +3 -46
  31. data/app/views/janela/queries/_query.html.erb +47 -0
  32. data/app/views/janela/queries/show.html.erb +4 -0
  33. data/app/views/janela/shared/_errors.html.erb +7 -0
  34. data/app/views/layouts/janela/application.html.erb +13 -5
  35. data/config/importmap.rb +1 -1
  36. data/config/locales/en.yml +64 -0
  37. data/config/routes.rb +15 -2
  38. data/db/migrate/20260916000001_create_janela_frames.rb +13 -0
  39. data/db/migrate/20260916000002_create_janela_panes.rb +22 -0
  40. data/docs/decisions/001-built-to-be-forked.md +4 -0
  41. data/docs/decisions/009-snapshots.md +5 -2
  42. data/docs/decisions/010-agent-guidance-ships-the-agent-waits.md +8 -4
  43. data/docs/decisions/012-frames-and-panes-are-data.md +166 -0
  44. data/docs/decisions/013-naming-and-addressing-frames.md +119 -0
  45. data/docs/decisions/014-corrections-before-frames-are-built.md +222 -0
  46. data/docs/decisions/015-how-breaking-change-is-communicated.md +114 -0
  47. data/docs/decisions/016-the-styling-vocabulary.md +100 -0
  48. data/docs/decisions/017-janela-owns-no-data-store.md +113 -0
  49. data/docs/decisions/018-a-table-is-the-universal-renderer.md +75 -0
  50. data/docs/decisions/019-a-created-frame-asks-the-host-who-owns-it.md +79 -0
  51. data/docs/decisions/020-formatting-belongs-to-the-measure.md +93 -0
  52. data/docs/decisions/021-a-check-has-a-name-a-host-can-silence.md +84 -0
  53. data/docs/decisions/INDEX.md +22 -7
  54. data/docs/multi-tenancy.md +175 -0
  55. data/lib/janela/definition.rb +5 -5
  56. data/lib/janela/doctor.rb +219 -0
  57. data/lib/janela/engine.rb +15 -2
  58. data/lib/janela/measure.rb +65 -4
  59. data/lib/janela/version.rb +1 -1
  60. data/lib/janela.rb +17 -0
  61. data/lib/tasks/janela.rake +6 -0
  62. metadata +54 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 86e2bcbf47fdcf475b8e34b2b1897d308a6c9f478e7b3f0903979cd3fa6bb8e2
4
- data.tar.gz: 9116c50f2f6e92a69489827acf9e9d580954c21bbe068887c3605b96d0531019
3
+ metadata.gz: 507d6baa4984a11605225ee2f97d8795f606e1d1b4739bb7d63567702d6a76c5
4
+ data.tar.gz: b12856e553a97feed8c12c56f78774addd360a603b8fc56cb81b01ee6167fe34
5
5
  SHA512:
6
- metadata.gz: a132498d5553317cd888139ba00559b5c7844c3878bdfe4c0c595783e14e3e4a082ec6fbe0a844d9f07a985a586daf4a4104164ff9dd452ed8ddf4390bdfe630
7
- data.tar.gz: 5f35f6d28fe84c469e3502f97f8c0ec13b7e1c703f04c5aa21360ef7ad6e14b4cc9c8e8d174e5ac1af9207adcc221d3ed430e2851059ef41f08eb5833637712b
6
+ metadata.gz: 65c9dd8f4ea0efc927fe648e52bd519ef7485d9cfda48bc200f4371cc33d8c844d5a496b9de9af7396b256306b5549614fe3235a1742774c118fc26b3b3e6eac
7
+ data.tar.gz: 70cac5044f03d17ebf4bd56f5407005815c5945f0979b869d93116d26b4c97d636dd53b18f973d1917efe54ce040d66014bd6e717d9135d66caea1d0a094389c
data/CHANGELOG.md CHANGED
@@ -5,7 +5,43 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
- ## [Unreleased]
8
+ ## [0.3.0] - 2026-09-16
9
+
10
+ ### Added
11
+
12
+ - `docs/multi-tenancy.md`, shipped in the gem: what goes through the host's scope and what does not, worked wiring for Pundit, acts_as_tenant and CanCanCan, what owns a frame an analyst creates, how to prove it with a test, and the honest note that a snapshot has no owner column yet (#32).
13
+ - A measure declares how its number reads: `precision:`, `prefix:` and `suffix:`, applied the same way to a table cell, a single value and a chart tooltip. Precision defaults to what the schema already says, so counting rows is whole, a `decimal(10, 2)` column reads to the cent and only an average of an integer falls back to two places. Formatting is rendering, never rounding: a snapshot stores the number and reads back under whatever format is declared later (ADR 020, #25).
14
+ - A pane whose row asks for a chart renders as its table where no chart runtime exists, which is the engine's own pages; a host's page still draws the chart. `janela_frame(@frame, charts: false)` asks for it explicitly (ADR 018).
15
+ - The engine's layout loads Janela's own stylesheet, so its pages are styled on install. It still loads none of the host's assets.
16
+ - The analyst's editing surface: conventional Rails CRUD on frames and on panes nested under a frame, on Janela's own pages, working with nothing but HTML. Adding a pane is two steps, the first picking a model and the second offering only the measures and dimensions that model declares, because those pages run no JavaScript to refill one select from another. A pane moves with Up and Down buttons rather than a position field, and positions stay contiguous. Every action reads through the host's scope, so another tenant's frame is a 404 to change as well as to read (ADR 012, ADR 014).
17
+ - `janela_frame_owner`, a hook a host defines on its own `ApplicationController`. Janela assigns its return value as the owner of a frame it creates, so a host whose `policy_scope` filters frames by owner does not have the analyst's new dashboard hidden the instant it is saved. A host with no tenancy defines nothing and gets a nil owner. Duck typed, like `policy_scope` itself.
18
+ - Janela serves its own pages: an index of frames and a page per frame, at the mount root (`/dashboards`, `/dashboards/3`). Both read through the host's `policy_scope`, the noun in every heading comes from `Janela::Frame.model_name.human` so a host renames it in its own locale file, and the gem ships `config/locales/en.yml` with the English defaults. A host that wants a different index writes its own page over `Janela::Frame` and never routes to ours (ADR 013).
19
+ - A dashboard can be data. `Janela::Frame` holds a name and a grid (`columns` 1 to 12, `gap` 0 to 8), `Janela::Pane` holds one visual (`position`, `span` 1 to 12, model, measure, dimension, renderer, granularity, limit and an optional title of its own), and `janela_frame @frame` renders one. The block form is unchanged, so nothing already built has to move (ADR 012, ADR 014). Run `bin/rails janela:install:migrations && bin/rails db:migrate` for the two new tables.
20
+ - A pane row is rendered by its own nested route, `<mount>/:frame_id/panes/:id`, and identified in the DOM as `janela_pane_<id>`, so two rows showing the same measure by the same dimension do not share a turbo frame. The ad hoc pane grammar from ADR 005 is unchanged.
21
+ - A frame renders every pane inline on the first response, so a shared link is a correct dashboard before any JavaScript runs and a page load makes no request per pane. Filters in the page URL apply to every pane either way.
22
+ - A pane row is validated against the registry on save: the model must have a `janela` block, the measure, dimension, renderer and granularity must be declared or supported, a granularity only applies to a time dimension, and a limit is 1 to 1000. A bad row is rejected with a readable message rather than rendering as a missing pane later.
23
+ - `Janela::Frame belongs_to :owner, polymorphic: true, optional: true`. Janela sets nothing there and reads nothing from it; it exists so a multi tenant host's Pundit `Scope` has a column to filter on. Every lookup of a frame or a pane row goes through that scope, so another tenant's frame is a 404 (ADR 014).
24
+ - A stylesheet, `app/assets/stylesheets/janela.css`, which a host includes with `stylesheet_link_tag "janela"`. It defines the grid classes for every value the records allow, styles the existing `janela-pane`, `janela-chart`, `janela-value` and `janela-empty` hooks so a pane is legible on install (#15), and collapses to one column on a narrow screen. Set `--janela-space` to move the whole spacing scale. The engine never injects it into a layout it does not own (ADR 016).
25
+ - `bin/rails janela:doctor` reads a host application and lists what it still needs to do: identifiers from an earlier version, unregistered Stimulus controllers, a `through:` dimension whose associated model has no allowlist, an unmounted engine, a mounted engine whose tables were never migrated, a `policy_scope` that filters frames by owner where the host defines no `janela_frame_owner`, and whether anything authenticates the endpoints. Exits non-zero on an error so it can run in CI (ADR 015). Every finding names the check that produced it, such as `unauthenticated-endpoints`, and a host silences one it has judged a false alarm with `Janela.silenced_checks`. A silenced check is still named in the output every run (ADR 021).
26
+ - `UPGRADING.md`, shipped inside the gem, with the steps for each release that needs a host to act. The changelog says what changed; the upgrade guide says what to do.
27
+
28
+ ### Changed
29
+
30
+ - Numbers render to the precision the measure means rather than to whatever the database returned. A sum of a `decimal(10, 2)` column that read as `375.0` now reads as `375.00`, and an average that read as `928.8767833333333` now reads as `928.88`. Nothing is rounded before it is stored or compared (ADR 020).
31
+ - Janela's own minimal layout now links the gem's own stylesheet, refining ADR 011. It still loads nothing of the host's, and still no JavaScript, because Turbo and Stimulus come from the host's bundler: Janela's own pages are therefore correct, styled, static dashboards. Panes render inline and filters in the URL apply; nothing cross-filters, and a chart pane draws nothing there. The engine also declares `janela.css` for precompilation, so a host on Sprockets serves it in production.
32
+ - A snapshot is read through the host's scope rather than `Snapshot.find`, so a stored pane a host's policy hides is a 404 rather than a result anyone who guesses an id can read (ADR 014).
33
+ - The frame controller no longer rewrites pane `src` attributes when it connects, only when the filters actually change. A pane rendered inline would otherwise be fetched again immediately and its first render thrown away.
34
+ - A frame or a pane a host's scope cannot see now answers with Janela's own sentence inside the requesting turbo frame, rather than the host's error page. Still a 404.
35
+ - Breaking rename, no behaviour change (ADR 014). A host must act on all of these:
36
+ - The Stimulus controller `janela--dashboard` is now `janela--frame`, and its file is `frame_controller.js`. Change `application.register("janela--dashboard", ...)` to `application.register("janela--frame", ...)`, and the import path from `@retail-tasker/janela/dashboard_controller` to `@retail-tasker/janela/frame_controller` on npm, or `janela/dashboard_controller` to `janela/frame_controller` on importmap.
37
+ - Any `data-action="janela--dashboard#clear"` (or `#toggle`), `data-janela--dashboard-*-param` and `data-janela--dashboard-target` in the host's own markup becomes `janela--frame`.
38
+ - The helper `janela_dashboard do ... end` is now `janela_frame do ... end`. `janela_pane` and `janela_snapshot_pane` are unchanged.
39
+ - The helper module `Janela::DashboardHelper` is now `Janela::FramesHelper`, which only matters to a host that includes or overrides it.
40
+ - `Janela::Pane` is now `Janela::Query`, and its `frame_id` is `turbo_frame_id`. `Pane` is reserved for a future record. Frame unqualified now means the dashboard; the DOM element is always spelled turbo frame.
41
+ - `Janela::PanesController` is now `Janela::QueriesController` and `Janela::SnapshotPanesController` is now `Janela::SnapshotQueriesController`, with their views at `app/views/janela/queries/`. A host that overrides the view moves its copy.
42
+ - `test/query_test.rb` is now `definition_query_test.rb`, since `query_test` read as a test of `Janela::Query` rather than of `Definition#query`.
43
+ - Unchanged on purpose: the pane URLs, the route helpers `pane_path` and `snapshot_pane_path`, the turbo frame ids, and the CSS hooks `janela-pane`, `janela-chart`, `janela-value` and `janela-empty`.
44
+ - The README's advice on styling a directly opened pane was wrong: it suggested pointing Janela at the host's application layout, which is the thing that raises `NameError` inside an isolated engine. It now shows a small asset-only layout instead, the pattern a real host arrived at.
9
45
 
10
46
  ## [0.2.1] - 2026-09-15
11
47
 
@@ -62,6 +98,7 @@ First alpha, installed from GitHub for testing in a single host application.
62
98
  - Only models that declare a `janela` block are addressable over HTTP.
63
99
  - ADRs 001 to 004 in `docs/decisions/`, shipped inside the gem.
64
100
 
101
+ [0.3.0]: https://github.com/retail-tasker/janela/releases/tag/v0.3.0
65
102
  [0.2.1]: https://github.com/retail-tasker/janela/releases/tag/v0.2.1
66
103
  [0.2.0]: https://github.com/retail-tasker/janela/releases/tag/v0.2.0
67
104
  [0.1.0]: https://github.com/retail-tasker/janela/releases/tag/v0.1.0
data/README.md CHANGED
@@ -25,7 +25,7 @@ Janela is an alpha on [rubygems.org](https://rubygems.org/gems/janela). It has t
25
25
 
26
26
  ```ruby
27
27
  # Gemfile
28
- gem "janela", "~> 0.2"
28
+ gem "janela", "~> 0.3"
29
29
  ```
30
30
 
31
31
  ```ruby
@@ -43,9 +43,9 @@ yarn add github:retail-tasker/janela # or: npm install github:retail-tasker/ja
43
43
 
44
44
  ```js
45
45
  // app/javascript/controllers/index.js
46
- import JanelaDashboardController from "@retail-tasker/janela/dashboard_controller"
46
+ import JanelaFrameController from "@retail-tasker/janela/frame_controller"
47
47
  import JanelaChartController from "@retail-tasker/janela/chart_controller"
48
- application.register("janela--dashboard", JanelaDashboardController)
48
+ application.register("janela--frame", JanelaFrameController)
49
49
  application.register("janela--chart", JanelaChartController)
50
50
  ```
51
51
 
@@ -53,16 +53,22 @@ The chart controller imports `chart.js`, which is a peer dependency: add `chart.
53
53
 
54
54
  **With importmap-rails:**
55
55
 
56
- Nothing to install. The engine pins `janela/dashboard_controller`, `janela/chart_controller` and a vendored `chart.js` for you (your own `chart.js` pin wins if you have one). Register the controllers:
56
+ Nothing to install. The engine pins `janela/frame_controller`, `janela/chart_controller` and a vendored `chart.js` for you (your own `chart.js` pin wins if you have one). Register the controllers:
57
57
 
58
58
  ```js
59
59
  // app/javascript/application.js
60
- import JanelaDashboardController from "janela/dashboard_controller"
60
+ import JanelaFrameController from "janela/frame_controller"
61
61
  import JanelaChartController from "janela/chart_controller"
62
- application.register("janela--dashboard", JanelaDashboardController)
62
+ application.register("janela--frame", JanelaFrameController)
63
63
  application.register("janela--chart", JanelaChartController)
64
64
  ```
65
65
 
66
+ Include the stylesheet in whichever layout renders dashboards. It is small, it is the grid, and it is meant to be overridden:
67
+
68
+ ```erb
69
+ <%= stylesheet_link_tag "janela" %>
70
+ ```
71
+
66
72
  Requires Rails 8.0+ and Ruby 3.3+. If your app is on Rails 8.1.x with the `json` gem at 3.x, encrypted cookie reads raise inside ActiveSupport and every Turbo Frame request will 500 in the browser; pin `gem "json", "< 3"` until Rails ships the fix.
67
73
 
68
74
  ## Usage
@@ -86,6 +92,20 @@ end
86
92
 
87
93
  A dimension with a `granularity` is a time dimension. Groupdate buckets it (`hour`, `day`, `week`, `month`, `quarter`, `year`), fills empty buckets with zero, and uses your app's `Time.zone` and week start. **On SQLite, buckets are UTC**, because SQLite cannot convert time zones: with a non-UTC `Time.zone` a daily bucket is shifted by your offset, and an early-morning row lands in the previous day. Coarser granularities blunt the shift without removing it. If you need local-day buckets on SQLite, store a local date column and use it as a plain dimension.
88
94
 
95
+ ### How numbers read
96
+
97
+ A measure says what its own number means, and every renderer asks it, so a table cell, a single value and a chart tooltip cannot disagree (ADR 020):
98
+
99
+ ```ruby
100
+ measure :revenue, sum: :amount, prefix: "$" # $1,234.50
101
+ measure :pass_rate, average: :score, precision: 1, suffix: "%" # 66.7%
102
+ measure :orders, count: true # 1,234
103
+ ```
104
+
105
+ Precision defaults to what the schema already says. Counting rows has no decimal places, a `decimal(10, 2)` column reads to the cent, and summing an integer column stays whole. Declare `precision:` where the schema has nothing to say, such as averaging an integer, or where you want something else. Thousands are delimited with your app's locale.
106
+
107
+ Formatting is rendering, never rounding. The number itself reaches a snapshot and an order clause at full precision, so a snapshot taken last month reads back under a format you declare today.
108
+
89
109
  Then query them:
90
110
 
91
111
  ```ruby
@@ -120,11 +140,11 @@ end
120
140
 
121
141
  ### Dashboards
122
142
 
123
- Compose panes on any page. Each pane is a Turbo Frame; clicking a value in one re-scopes the others:
143
+ Compose panes on any page. Each pane is a Turbo Frame; clicking a value in one re-scopes the others. `janela_frame` wraps them: a frame is Janela's own word for the dashboard, so the gem's vocabulary never dictates what you call one (ADR 014).
124
144
 
125
145
  ```erb
126
- <%= janela_dashboard do %>
127
- <button type="button" data-action="janela--dashboard#clear">Clear filters</button>
146
+ <%= janela_frame do %>
147
+ <button type="button" data-action="janela--frame#clear">Clear filters</button>
128
148
 
129
149
  <%= janela_pane Order, :revenue %>
130
150
  <%= janela_pane Order, :revenue, by: :status, as: :bar %>
@@ -135,6 +155,88 @@ Compose panes on any page. Each pane is a Turbo Frame; clicking a value in one r
135
155
 
136
156
  A pane with no `by:` is the measure's single total, the KPI tile. `limit: 10` keeps the top ten rows or bars. `as:` is `:table` by default, `:bar` for a Chart.js bar chart, or `:line`, which suits a time dimension: `janela_pane Order, :revenue, by: :placed_on, as: :line, granularity: :week`. A chart fills its container's width at Chart.js's default aspect ratio, so wrap it in an element with the width you want. Clicking a bar does exactly what clicking a table value does.
137
157
 
158
+ ### Frames
159
+
160
+ A dashboard does not have to be written in ERB. A frame is a record, so the person who decides which panes a dashboard has and how wide each one is does not need a deploy to change it (ADR 012):
161
+
162
+ ```bash
163
+ bin/rails janela:install:migrations && bin/rails db:migrate
164
+ ```
165
+
166
+ ```ruby
167
+ frame = Janela::Frame.create!(name: "Orders", columns: 3, gap: 4)
168
+ frame.panes.create!(model: "orders", measure: "revenue")
169
+ frame.panes.create!(model: "orders", measure: "revenue", dimension: "placed_on",
170
+ renderer: "line", granularity: "month", span: 3)
171
+ frame.panes.create!(model: "orders", measure: "revenue", dimension: "status",
172
+ renderer: "bar", span: 2, title: "Money by status")
173
+ ```
174
+
175
+ ```erb
176
+ <%= janela_frame @frame %>
177
+ ```
178
+
179
+ Same helper, two ways to supply the panes. A row names a model by its route key, and only a measure, dimension, renderer and granularity the model's `janela` block declares: a row that names anything else is rejected on save, so an analyst arranges what is shown and cannot invent a query or reach a model nobody exposed. `position` orders the panes and is set for you when you leave it out. `title` is optional and replaces the title Janela would write itself.
180
+
181
+ The layout is CSS Grid's own vocabulary as small integers: `columns` 1 to 12 and `gap` 0 to 8 on the frame, `span` 1 to 12 on a pane. Each one picks a class the shipped stylesheet already defines, `janela-cols-3`, `janela-gap-4`, `janela-span-2`, so nothing an analyst types reaches CSS. Set `--janela-space` once, anywhere, to move the whole spacing scale; the grid collapses to a single column on a narrow screen. ADR 016 has the reasoning.
182
+
183
+ A frame renders each pane inline on the first response, so the page is a correct dashboard before any JavaScript runs and there is no request per pane on load. Cross-filtering then works exactly as it does for hand written panes. Every pane of a frame goes through your Pundit scope if you have one, the same as every other Janela query.
184
+
185
+ A frame may belong to an owner, `belongs_to :owner, polymorphic: true, optional: true`. Janela sets nothing there and reads nothing from it: it exists so a multi tenant host's Pundit `Scope` has a column to filter on. Set it to whatever your tenant is, and leave it null if you have one tenant.
186
+
187
+ ### Janela's own pages
188
+
189
+ The engine serves an index and a page per frame at the mount root, so you can install the gem and navigate the same day:
190
+
191
+ ```
192
+ /dashboards every frame your scope returns
193
+ /dashboards/3 one frame
194
+ /dashboards/orders/revenue/status an ad hoc pane, grammar unchanged
195
+ ```
196
+
197
+ No model's route key is all digits, so a frame id and a pane URL cannot be confused. Both pages read through `policy_scope(Janela::Frame)`, so a frame your scope does not return is a 404 rather than a page, and so is a pane row under it.
198
+
199
+ These pages render in Janela's own minimal layout, which loads the gem's stylesheet and nothing else. It does not load Turbo or Stimulus, because those come from your bundler and the engine cannot name them. So Janela's own pages are correct, styled, **static** dashboards: every pane is rendered inline and the numbers are right, filters in the URL apply, and nothing cross-filters when you click. A chart pane needs Chart.js, so on these pages it draws nothing; put a frame on your own page, where your JavaScript is, for the interactive version.
200
+
201
+ The noun in the headings is `Janela::Frame.model_name.human`, so rename it in your own locale file rather than in a setting:
202
+
203
+ ```yaml
204
+ en:
205
+ activerecord:
206
+ models:
207
+ janela/frame:
208
+ one: "Dashboard"
209
+ other: "Dashboards"
210
+ ```
211
+
212
+ A host that wants a different index writes its own page over `Janela::Frame` and never routes to ours.
213
+
214
+ ### Editing a dashboard
215
+
216
+ The same pages are the analyst's editing surface, as conventional Rails CRUD:
217
+
218
+ ```
219
+ /dashboards/new name it and choose its grid
220
+ /dashboards/3/edit rename it, rearrange it, add and remove panes
221
+ /dashboards/3/panes/new
222
+ ```
223
+
224
+ Everything there works with nothing but HTML, because those pages load no JavaScript. Adding a pane is therefore two steps: the first picks a model, the second offers exactly the measures and dimensions that model's `janela` block declares, so a choice that would be rejected is never offered. Granularity appears when the dimension can take one. A pane moves with Up and Down buttons rather than a position field, because arranging the window is the point, and positions stay contiguous. There is no drag and drop and no canvas; a visual editor is its own decision, not built.
225
+
226
+ **Tell Janela what a new frame belongs to.** If your `ApplicationController` defines `janela_frame_owner`, the engine assigns its return value as the owner of a frame it creates. Without it, a host whose `policy_scope` filters frames by owner would hide the analyst's new dashboard the instant it was saved:
227
+
228
+ ```ruby
229
+ class ApplicationController < ActionController::Base
230
+ def janela_frame_owner
231
+ Current.account
232
+ end
233
+ end
234
+ ```
235
+
236
+ A host with no tenancy defines nothing, gets a nil owner, and is correct: nothing is filtering on it. Every editing action reads through `policy_scope(Janela::Frame)` as well, so another tenant's frame is a 404 to change as much as to read. The [multi tenancy guide](docs/multi-tenancy.md) has the wiring for each of the common setups.
237
+
238
+ ### Filters and clicks
239
+
138
240
  The dashboard's filters live in the page URL as the same `q[...]` parameters, so a reload keeps them and a filtered dashboard is a link you can send: `/reports/orders?q[status_eq]=paid` renders filtered before any JavaScript runs. A pane ignores filters on its own dimension, so clicking a value re-scopes the rest of the dashboard rather than collapsing the pane you clicked. Time panes re-scope with the others but are not click sources yet; drill-down is the next decision. The selected value is marked `aria-pressed="true"` on tables and drawn solid against faded siblings on charts, so it can be styled and read. A pane with no matching rows renders a `.janela-empty` paragraph. A group whose dimension is null is labelled `(none)` and filters with Ransack's null predicate rather than an empty string. Only models that declare a `janela` block can be requested over HTTP.
139
241
 
140
242
  ### Pane URLs
@@ -151,15 +253,11 @@ Every pane has its own URL under the mount, and a Turbo Frame in a dashboard loa
151
253
  orders revenue by placed_on, per week, as a line
152
254
  ```
153
255
 
154
- The model is its route key (`orders`, `sales_orders`), then the measure, then optionally the dimension. Where an analyst would say *by*, the URL has a `/`; *where* is a `q` filter; *as a bar chart* is `?as=bar`; *top ten* is `?limit=10`; *as of* a snapshot is `/snapshots/:id/` in front. Category panes are always ordered by the measure, largest first; time panes are chronological. A pane opened on its own renders inside your application layout with its filters applied, so a filtered pane is a link you can send someone. ADR 005 has the reasoning.
256
+ The model is its route key (`orders`, `sales_orders`), then the measure, then optionally the dimension. Where an analyst would say *by*, the URL has a `/`; *where* is a `q` filter; *as a bar chart* is `?as=bar`; *top ten* is `?limit=10`; *as of* a snapshot is `/snapshots/:id/` in front. Category panes are always ordered by the measure, largest first; time panes are chronological. A pane opened on its own renders with its filters applied, so a filtered pane is a link you can send someone. ADR 005 has the grammar, ADR 011 the layout it renders in.
155
257
 
156
258
  ### Snapshots
157
259
 
158
- A snapshot freezes the results of several panes at one instant, under one set of filters, so an audience sees exactly what was signed off while the live dashboard stays editable. Results are stored, not HTML; a stored pane can still be drawn as a table or a chart.
159
-
160
- ```bash
161
- bin/rails janela:install:migrations && bin/rails db:migrate
162
- ```
260
+ A snapshot freezes the results of several panes at one instant, under one set of filters, so an audience sees exactly what was signed off while the live dashboard stays editable. Results are stored, not HTML; a stored pane can still be drawn as a table or a chart. It needs the same migrations frames do.
163
261
 
164
262
  ```ruby
165
263
  Janela::Snapshot.take(name: "September 2026", filters: { status_eq: "paid" }) do |take|
@@ -175,7 +273,32 @@ Render a stored pane the same way you render a live one:
175
273
  <%= janela_snapshot_pane @snapshot, Order, :revenue, by: :status, as: :bar %>
176
274
  ```
177
275
 
178
- Panes render in Janela's own minimal layout when opened directly, so a shared pane link shows its numbers but no host styling and no charts; set `Janela::ApplicationController.layout "application"` in an initializer to use your own layout, which must not call a bare host route helper (inside an engine those need a `main_app.` prefix). Inside a dashboard, panes are Turbo Frames and carry no layout at all.
276
+ Inside a dashboard a pane is a Turbo Frame and carries no layout at all. Opened directly it renders in Janela's own minimal layout, which deliberately loads no assets, because the gem cannot know your asset names or whether you bundle. A direct pane link therefore shows its numbers unstyled, and a chart pane shows nothing, since the chart needs Stimulus.
277
+
278
+ To make direct pane links styled and chart-capable, give Janela a small layout of your own that loads your assets and nothing else:
279
+
280
+ ```erb
281
+ <%# app/views/layouts/janela.html.erb %>
282
+ <!DOCTYPE html>
283
+ <html>
284
+ <head>
285
+ <title><%= content_for(:title) || "Insights" %></title>
286
+ <meta name="viewport" content="width=device-width,initial-scale=1">
287
+ <%= csrf_meta_tags %>
288
+ <%= csp_meta_tag %>
289
+ <%= stylesheet_link_tag :app %>
290
+ <%= javascript_importmap_tags %>
291
+ </head>
292
+ <body><%= yield %></body>
293
+ </html>
294
+ ```
295
+
296
+ ```ruby
297
+ # config/initializers/janela.rb
298
+ Rails.application.config.to_prepare { Janela::ApplicationController.layout "janela" }
299
+ ```
300
+
301
+ Do not point Janela at your **application** layout. Janela is an isolated engine, so a bare route helper anywhere in that layout, a nav link for instance, resolves against Janela's routes and raises `NameError`. Keep the layout above small and asset-only.
179
302
 
180
303
  Stored panes are static by nature: no filter buttons, charts ignore clicks, and the URL says *as of*: `/dashboards/snapshots/42/orders/revenue/status`. Request filters are ignored because the snapshot's were fixed when it was taken.
181
304
 
@@ -198,23 +321,80 @@ end
198
321
 
199
322
  Two details matter. It is *prepended* so it runs before any filter on your `ApplicationController` that assumes a signed-in user (tenant lookups, audit logging). It redirects through `main_app` because Janela is an isolated engine, so a bare `new_session_path` inside it resolves against Janela's own routes and fails.
200
323
 
201
- Scoping is automatic when you use Pundit: `Janela::ApplicationController` calls `policy_scope(model)` if your `ApplicationController` defines it, and falls back to `model.all` otherwise. Every model you put on a dashboard needs a policy with a `Scope`.
324
+ Scoping is automatic when you use Pundit: `Janela::ApplicationController` calls `policy_scope(model)` if your `ApplicationController` defines it, and falls back to `model.all` otherwise. Every model you put on a dashboard needs a policy with a `Scope`, and so do `Janela::Frame` and `Janela::Snapshot`: frames, pane rows and stored panes are all read through the scope, never around it. `test/dummy/app/controllers/application_controller.rb` is the smallest honest example of the wiring.
325
+
326
+ **Multi tenancy** has its own guide: [docs/multi-tenancy.md](docs/multi-tenancy.md). It covers what goes through your scope, worked wiring for Pundit, acts_as_tenant and CanCanCan, what owns a frame the analyst creates, and the one rough edge, which is that a snapshot has no owner column yet.
327
+
328
+ ### The pages Janela serves
329
+
330
+ Mounting the engine gives you an index of frames and a page per frame with no
331
+ work at all, which is enough to navigate on the day you install it:
332
+
333
+ ```
334
+ /insights every frame your policy scope returns
335
+ /insights/3 one frame
336
+ ```
337
+
338
+ Both go through your `policy_scope`, so a frame another tenant owns is a 404.
339
+
340
+ These pages load Janela's own stylesheet and nothing of yours, because the gem
341
+ cannot know your asset names or bundler. Two consequences worth knowing. They
342
+ do not cross-filter, since that needs Stimulus. And a pane whose row asks for a
343
+ chart renders as its **table** here, because there is no chart runtime on the
344
+ page and a table needs nothing: the same frame rendered in your own page with
345
+ `janela_frame(@frame)` draws the chart. A renderer is a viewing choice, not part
346
+ of the pane (ADR 018).
347
+
348
+ ### Checking an installation
349
+
350
+ ```bash
351
+ bin/rails janela:doctor
352
+ ```
353
+
354
+ Reads your application and lists what still needs doing: identifiers left over
355
+ from an earlier version, Stimulus controllers you have not registered, tables
356
+ you have not migrated, a `through:` dimension whose associated model does not
357
+ allowlist the attribute, a policy that scopes frames by an owner you never
358
+ supply, and whether the engine is mounted and authenticated. It exits non-zero
359
+ when it finds an error, so it works in CI. It only reads and reports.
360
+
361
+ Every finding names the check that produced it:
362
+
363
+ ```
364
+ WARNING (unauthenticated-endpoints): no authentication filter found on ApplicationController
365
+ ```
366
+
367
+ One check cannot be certain: Janela reads your controller's filters to guess
368
+ whether the endpoints are authenticated, so if you authenticate another way it
369
+ is a false alarm every run. Silence one you have judged, by name:
370
+
371
+ ```ruby
372
+ # config/initializers/janela.rb
373
+ Janela.silenced_checks = %w[unauthenticated-endpoints]
374
+ ```
375
+
376
+ Silenced checks are named in the output every run, because a silence nobody
377
+ remembers is how a real finding goes unread (ADR 021).
378
+
379
+ Run it after installing and after any upgrade. Steps for a specific version
380
+ upgrade are in [UPGRADING.md](UPGRADING.md).
202
381
 
203
382
  ## Design
204
383
 
205
384
  Janela ships the load-bearing core of a BI tool and nothing else. The reasoning is recorded in [`docs/decisions/`](docs/decisions/INDEX.md), starting with ADR 001.
206
385
 
207
- - **Measures and dimensions are a Ruby DSL on the model**, config-as-code like `routes.rb`. No drag-and-drop designer.
386
+ - **Measures and dimensions are a Ruby DSL on the model**, config-as-code like `routes.rb`. Developers define what can be asked.
387
+ - **Composition is data.** A frame and its panes are records, so analysts arrange what is shown without a deploy (ADR 012). A visual, drag-and-drop editor is not built and is a decision of its own.
208
388
  - **Querying rides on [Ransack](https://github.com/activerecord-hackery/ransack)'s association-path traversal.** Janela does not invent a query language.
209
389
  - **Cross-filtering is a Stimulus controller plus Turbo Frames.** Click a value in one pane, shared filter state updates, every other frame on the page re-renders.
210
390
  - **Charts are [Chart.js](https://www.chartjs.org)**, driven by one small Stimulus controller from the same values the tables show. Not a charting engine.
211
391
  - **Publishing creates a Snapshot.** An ActiveJob freezes the result set into a new record; the live dashboard stays editable and the published view is a point-in-time fork, not a toggle on the same record. Not built yet.
212
392
 
213
- Deliberately out of scope: report designer UI, natural-language query, a separate data warehouse, a row-level-security subsystem (use your app's Pundit/CanCanCan), refresh-scheduling UI (schedule the Snapshot job with whatever you already use), embedding SDK, mobile app, print/paginated reports. If you need one of those, the codebase is meant to be small enough to fork and add your own.
393
+ Deliberately out of scope: natural-language query, a separate data warehouse, a row-level-security subsystem (use your app's Pundit/CanCanCan), refresh-scheduling UI (schedule the Snapshot job with whatever you already use), embedding SDK, mobile app, print/paginated reports. If you need one of those, the codebase is meant to be small enough to fork and add your own.
214
394
 
215
395
  ## Status
216
396
 
217
- **v0.2.1 alpha.** The measures/dimensions DSL, time dimensions, cross-filtering, bar and line charts, pane URLs, shareable dashboard URLs and snapshots work and are covered by unit and real-browser tests. Not yet built: drill-down on time panes, other chart types. Open work is in [GitHub Issues](https://github.com/retail-tasker/janela/issues).
397
+ **v0.3.0 alpha.** The measures/dimensions DSL, time dimensions, cross-filtering, bar and line charts, pane URLs, shareable dashboard URLs, snapshots, database-backed frames and the engine's own pages for reading and editing them work and are covered by unit and real-browser tests. Not yet built: a visual editor, drill-down on time panes, other chart types. Open work is in [GitHub Issues](https://github.com/retail-tasker/janela/issues).
218
398
 
219
399
  ## Development
220
400
 
data/UPGRADING.md ADDED
@@ -0,0 +1,136 @@
1
+ # Upgrading Janela
2
+
3
+ What to do, in order, when a release needs you to act. For what
4
+ changed and why, see [CHANGELOG.md](CHANGELOG.md); for why it was
5
+ decided, see [docs/decisions](docs/decisions/INDEX.md).
6
+
7
+ After any upgrade, run:
8
+
9
+ ```bash
10
+ bin/rails janela:doctor
11
+ ```
12
+
13
+ It reads your application and lists what still needs changing.
14
+
15
+ ## 0.2.1 to 0.3.0
16
+
17
+ Two things arrive together. Janela's own words settle on frames and
18
+ panes, which is a rename across your application: a frame is the
19
+ dashboard, a pane is one visual in it. And a dashboard can now be a
20
+ database record rather than only ERB, which is what the new tables and
21
+ the engine's own pages are for.
22
+
23
+ Step 1 is the one that breaks a page if you skip it. The renames after
24
+ it can be done in any order, and `janela:doctor` will tell you what you
25
+ have missed.
26
+
27
+ **1. Run the migrations.**
28
+
29
+ ```bash
30
+ bin/rails janela:install:migrations
31
+ bin/rails db:migrate
32
+ ```
33
+
34
+ Required if you mount the engine, even if you never intend to store a
35
+ dashboard. From this release the mount root serves an index of frames,
36
+ so without the tables `/dashboards` raises where it used to work.
37
+
38
+ **2. Rename the Stimulus controller you register.**
39
+
40
+ ```js
41
+ // app/javascript/controllers/index.js, or wherever you register it
42
+ - import JanelaDashboardController from "@retail-tasker/janela/dashboard_controller"
43
+ - application.register("janela--dashboard", JanelaDashboardController)
44
+ + import JanelaFrameController from "@retail-tasker/janela/frame_controller"
45
+ + application.register("janela--frame", JanelaFrameController)
46
+ ```
47
+
48
+ On importmap the path is `janela/frame_controller` rather than
49
+ `janela/dashboard_controller`. On npm, reinstall so the new export
50
+ path resolves:
51
+
52
+ ```bash
53
+ yarn add github:retail-tasker/janela#v0.3.0 # or bump your version range
54
+ ```
55
+
56
+ **3. Rename the helper that wraps your panes.**
57
+
58
+ ```erb
59
+ - <%= janela_dashboard do %>
60
+ + <%= janela_frame do %>
61
+ <%= janela_pane Order, :revenue %>
62
+ <% end %>
63
+ ```
64
+
65
+ `janela_pane` and `janela_snapshot_pane` are unchanged.
66
+
67
+ **4. Rename any Janela data attributes in your own markup.**
68
+
69
+ Anything you wrote by hand, most likely a clear button:
70
+
71
+ ```erb
72
+ - <button data-action="janela--dashboard#clear">Clear filters</button>
73
+ + <button data-action="janela--frame#clear">Clear filters</button>
74
+ ```
75
+
76
+ The same applies to `data-janela--dashboard-target` and
77
+ `data-janela--dashboard-*-param` if you built your own controls.
78
+
79
+ **5. Rename the constants, if you reference them.**
80
+
81
+ Most applications do not.
82
+
83
+ | Was | Now |
84
+ | --- | --- |
85
+ | `Janela::Pane` | `Janela::Query` |
86
+ | `Janela::Pane#frame_id` | `Janela::Query#turbo_frame_id` |
87
+ | `Janela::DashboardHelper` | `Janela::FramesHelper` |
88
+ | `Janela::PanesController` | `Janela::QueriesController` |
89
+ | `Janela::SnapshotPanesController` | `Janela::SnapshotQueriesController` |
90
+
91
+ `Janela::Pane` is reserved for a database record in a later release,
92
+ which is why the runtime object had to give the name up.
93
+
94
+ If you override Janela's view, move your copy from
95
+ `app/views/janela/panes/` to `app/views/janela/queries/`.
96
+
97
+ **6. Tell Janela what a new frame belongs to, if your policy asks.**
98
+
99
+ Only for a multi tenant host. If your Pundit scope filters
100
+ `Janela::Frame` by an owner, a frame created through Janela's own form
101
+ would be saved with no owner and hidden by that scope the instant it
102
+ was saved. Define the hook on the controller Janela inherits from:
103
+
104
+ ```ruby
105
+ class ApplicationController < ActionController::Base
106
+ def janela_frame_owner
107
+ Current.account # whatever your scope filters frames by
108
+ end
109
+ end
110
+ ```
111
+
112
+ `janela:doctor` reports this one for you: it asks your policy for a
113
+ scope and looks for an owner in it. `docs/multi-tenancy.md`, shipped
114
+ in the gem, has the wiring for Pundit, acts_as_tenant and CanCanCan.
115
+
116
+ **7. Link the stylesheet, if you have not.**
117
+
118
+ ```erb
119
+ <%= stylesheet_link_tag "janela" %>
120
+ ```
121
+
122
+ Optional. It is the grid and enough style to read a pane, and Janela's
123
+ own pages load it themselves either way.
124
+
125
+ **Numbers read differently, and you need do nothing.** A measure now
126
+ renders to the precision it means rather than to whatever the database
127
+ returned, so a sum of a `decimal(10, 2)` column that read as `375.0`
128
+ reads as `375.00`. Declare `precision:`, `prefix:` or `suffix:` on the
129
+ measure to say otherwise. Nothing is rounded before it is stored or
130
+ compared.
131
+
132
+ **Nothing else changed.** Pane URLs, the route helpers `pane_path` and
133
+ `snapshot_pane_path`, turbo frame ids, and the CSS hooks
134
+ `janela-pane`, `janela-chart`, `janela-value` and `janela-empty` are
135
+ all as they were. Your measures, dimensions and snapshots are
136
+ untouched.
@@ -4,11 +4,12 @@ import { Chart, registerables } from "chart.js"
4
4
  Chart.register(...registerables)
5
5
 
6
6
  // Renders one pane as a chart and turns a click on a bar into the same
7
- // toggle event a table button emits, so the dashboard controller cannot tell
8
- // the difference. Turbo replaces the frame on every cross-filter, so the chart
9
- // is destroyed on disconnect and rebuilt on connect.
7
+ // toggle event a table button emits, so the frame controller cannot tell the
8
+ // difference. Turbo replaces the turbo frame on every cross-filter, so the
9
+ // chart is destroyed on disconnect and rebuilt on connect.
10
10
  export default class extends Controller {
11
- static values = { type: String, labels: Array, values: Array, filters: Object, title: String, selected: String }
11
+ static values = { type: String, labels: Array, values: Array, filters: Object, title: String,
12
+ selected: String, formatted: Array }
12
13
 
13
14
  connect() {
14
15
  this.chart = new Chart(this.element, {
@@ -25,7 +26,13 @@ export default class extends Controller {
25
26
  options: {
26
27
  animation: false,
27
28
  scales: { y: { beginAtZero: true } },
28
- plugins: { legend: { display: false } },
29
+ plugins: {
30
+ legend: { display: false },
31
+ // The server formatted every number for the table, so the tooltip
32
+ // reads the same string rather than formatting a second time here
33
+ // and disagreeing with the cell beside it.
34
+ tooltip: { callbacks: { label: (item) => this.formattedValue[item.dataIndex] ?? item.formattedValue } }
35
+ },
29
36
  onClick: (_event, elements) => {
30
37
  if (elements.length === 0) return
31
38
  const label = this.labelsValue[elements[0].index]
@@ -1,7 +1,7 @@
1
1
  import { Controller } from "@hotwired/stimulus"
2
2
 
3
- // Shared filter state for every pane on the page. Clicking a value rewrites
4
- // each frame's src, and Turbo reloads a frame whenever its src changes, so
3
+ // Shared filter state for every pane in the frame. Clicking a value rewrites
4
+ // each turbo frame's src, and Turbo reloads one whenever its src changes, so
5
5
  // cross-filtering needs no streams, no sockets and no state library.
6
6
  export default class extends Controller {
7
7
  static targets = ["pane"]
@@ -26,7 +26,14 @@ export default class extends Controller {
26
26
  this.filtersValue = {}
27
27
  }
28
28
 
29
- filtersValueChanged() {
29
+ // Stimulus calls this as the controller connects, handing back the value it
30
+ // just read from the attribute the server rendered, so nothing has changed
31
+ // yet. A frame rendered from rows is already showing the right numbers
32
+ // inline, and a src assigned here would make Turbo fetch every pane and
33
+ // throw that first render away (ADR 014).
34
+ filtersValueChanged(filters, previous) {
35
+ if (previous === undefined || JSON.stringify(filters) === JSON.stringify(previous)) return
36
+
30
37
  this.paneTargets.forEach((pane) => {
31
38
  const url = new URL(pane.dataset.janelaSrc, window.location.origin)
32
39
  this.writeFilters(url)
@@ -37,7 +44,7 @@ export default class extends Controller {
37
44
  }
38
45
 
39
46
  // The page URL carries the same q[...] the panes do, so a reload or a
40
- // pasted link opens the dashboard filtered (ADR 008). Replaced rather than
47
+ // pasted link opens the frame filtered (ADR 008). Replaced rather than
41
48
  // pushed: a click is not a place the back button should return to.
42
49
  syncPageUrl() {
43
50
  const url = new URL(window.location.href)