solid_web_ui 0.1.0 → 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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 733e4f6cdd63c6b22b5e3ca4166576ebfe2db2a482d6b2fa7e25035e0a12c7a9
4
- data.tar.gz: e1b1e0755169b3ba6f74d576f155bcce21bf029f5d1a2de3e833be7713d806e5
3
+ metadata.gz: c473be31f5f3992b41cfca6aaf1855045104194afa6507947110feb311d374ee
4
+ data.tar.gz: '059154707b3a45e39a94904824c7dca137170549f0f7a8bf52432c51aa11a898'
5
5
  SHA512:
6
- metadata.gz: 66d72bca337446f1df7ae48b7faebe2c760c56e1079eba0a280deb1047bd6ef0a0719bcd64137609a0df7207bc7632239eff6920aa30f16fb28775f7d4b97fa9
7
- data.tar.gz: ae241b3d25a1108b038b88a92e81e36da9137c5c3af126a1abd4c6767ca135e46b9f3200641239cc162a74c690bb73eaa3ad6145450a6b61231e60717afb5348
6
+ metadata.gz: a1a32a7e4292847fb8fa0ecd9df72d8e5c1b8211ac91eed54043373956015e7435a46720e4857d274fa8ba8ca6adeb5e5d1af576b95e3950cb037d20083c099d
7
+ data.tar.gz: d0b391dde5552ab3152edb019427c6caf0fbb77e545fc013580fe0f3491dd9f24ec71dd5399a26140c34dc9029663b25e86248a316a6be211dac63acada112a8
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Anton Radushev
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # solid_web_ui
2
2
 
3
+ [![Gem Version](https://img.shields.io/gem/v/solid_web_ui)](https://rubygems.org/gems/solid_web_ui)
4
+ [![Downloads](https://img.shields.io/gem/dt/solid_web_ui)](https://rubygems.org/gems/solid_web_ui)
5
+ [![CI](https://github.com/doromones/solid-web/actions/workflows/ci.yml/badge.svg)](https://github.com/doromones/solid-web/actions/workflows/ci.yml)
6
+ [![License: MIT](https://img.shields.io/badge/license-MIT-blue)](LICENSE)
7
+
3
8
  Web dashboards for Rails' **Solid Queue**, **Solid Cache** and **Solid Cable** — one gem
4
9
  (`solid_web_ui`) with three independently mountable Rails engines sharing one design system.
5
10
 
@@ -15,6 +20,12 @@ The shared core (`SolidWebUi`) provides the layout, ViewComponents, design-token
15
20
  dry-configurable base. The engines are plain Rails mountable engines — **no ActiveAdmin required**;
16
21
  host authentication is inherited through a configurable `base_controller_class`.
17
22
 
23
+ Every dashboard **auto-refreshes**: a frequency `<select>`, a countdown and a manual refresh
24
+ button in the header keep the stats and tables live without a full reload (the data region is a
25
+ turbo-frame, morphed in place when Turbo is present, otherwise fetched and swapped). Configure or
26
+ disable it via `SolidWebUi.config.refresh_interval` / `refresh_intervals` / `javascript` — see
27
+ [docs/configuration.md](docs/configuration.md#live-auto-refresh).
28
+
18
29
  ## Install
19
30
 
20
31
  ```ruby
@@ -0,0 +1,125 @@
1
+ // Live auto-refresh for the Solid* dashboards.
2
+ //
3
+ // Self-contained, dependency-free. Drives the controls rendered by
4
+ // SolidWebUi::Ui::RefreshControlsComponent: a frequency <select>, a countdown
5
+ // and a manual "refresh now" button. On each tick it reloads the dashboard's
6
+ // turbo-frame (morph, when Turbo is on the page) or falls back to fetch+replace.
7
+ //
8
+ // Linked via solid_web_ui_head_tags. The IIFE runs once per Turbo session (the
9
+ // asset is data-turbo-track="reload", so Turbo navigations don't re-execute it).
10
+ // A single module-level timer ticks for the whole session, re-reading the DOM
11
+ // each tick — so it never holds references to elements replaced by a navigation
12
+ // and never leaks timers/listeners across pages. Per-panel <select>/button
13
+ // handlers are bound once via a data flag.
14
+ (function () {
15
+ "use strict";
16
+
17
+ var TICK_MS = 250;
18
+ var SELECT = "[data-swui-refresh-select]";
19
+ var STATUS = "[data-swui-refresh-status]";
20
+ var NOW = "[data-swui-refresh-now]";
21
+
22
+ // nextAt timestamp per panel element; a WeakMap so detached panels are GC'd.
23
+ var nextAt = new WeakMap();
24
+
25
+ function intervalOf(panel) {
26
+ var select = panel.querySelector(SELECT);
27
+ return select ? (parseInt(select.value, 10) || 0) : 0;
28
+ }
29
+
30
+ function schedule(panel) {
31
+ var seconds = intervalOf(panel);
32
+ nextAt.set(panel, seconds > 0 ? Date.now() + seconds * 1000 : 0);
33
+ }
34
+
35
+ function reloadFrame(frameId) {
36
+ var frame = document.getElementById(frameId);
37
+ if (!frame) return;
38
+ if (typeof frame.reload === "function") {
39
+ // Real <turbo-frame>: reload its OWN current src, which Turbo keeps in sync
40
+ // as the user navigates within the frame (stat cards, filter tabs, pages) —
41
+ // so a refresh re-fetches the view on screen, never snapping back to the
42
+ // page first loaded. Morphs in place when the frame carries refresh="morph".
43
+ // First refresh on a page with no src yet: seed it from the current URL.
44
+ if (frame.getAttribute("src")) {
45
+ frame.reload();
46
+ } else {
47
+ frame.setAttribute("src", window.location.href);
48
+ }
49
+ return;
50
+ }
51
+ // Fallback (no Turbo): frames are inert, so in-frame links navigate the whole
52
+ // page — the frame's current URL is just the document's. Fetch and swap.
53
+ var url = frame.getAttribute("src") || window.location.href;
54
+ fetch(url, { headers: { "X-Requested-With": "XMLHttpRequest" }, credentials: "same-origin" })
55
+ .then(function (r) {
56
+ if (!r.ok) throw new Error("refresh failed: " + r.status);
57
+ return r.text();
58
+ })
59
+ .then(function (html) {
60
+ var doc = new DOMParser().parseFromString(html, "text/html");
61
+ var incoming = doc.getElementById(frameId);
62
+ if (incoming) frame.innerHTML = incoming.innerHTML;
63
+ })
64
+ .catch(function () { /* transient error — keep the last view, retry next tick */ });
65
+ }
66
+
67
+ function refreshNow(panel) {
68
+ reloadFrame(panel.dataset.frame);
69
+ schedule(panel);
70
+ }
71
+
72
+ function render(panel) {
73
+ var status = panel.querySelector(STATUS);
74
+ if (!status) return;
75
+ if (intervalOf(panel) <= 0) { status.textContent = "Auto-refresh off"; return; }
76
+ if (document.hidden) { status.textContent = "Paused"; return; }
77
+ var remaining = Math.max(0, Math.ceil(((nextAt.get(panel) || 0) - Date.now()) / 1000));
78
+ status.textContent = "Next refresh in " + remaining + "s";
79
+ }
80
+
81
+ // Bind the per-panel handlers exactly once (the flag survives an immediate
82
+ // DOMContentLoaded+turbo:load double-fire on the same element).
83
+ function bind(panel) {
84
+ if (panel.dataset.swuiRefreshReady === "1") return;
85
+ panel.dataset.swuiRefreshReady = "1";
86
+
87
+ var select = panel.querySelector(SELECT);
88
+ var storageKey = panel.dataset.storageKey;
89
+ if (select && storageKey) {
90
+ var stored = null;
91
+ try { stored = window.localStorage.getItem(storageKey); } catch (e) { stored = null; }
92
+ var offered = Array.prototype.some.call(select.options, function (o) { return o.value === stored; });
93
+ if (stored !== null && offered) select.value = stored;
94
+ select.addEventListener("change", function () {
95
+ try { window.localStorage.setItem(storageKey, select.value); } catch (e) { /* ignore */ }
96
+ schedule(panel);
97
+ render(panel);
98
+ });
99
+ }
100
+ var nowBtn = panel.querySelector(NOW);
101
+ if (nowBtn) nowBtn.addEventListener("click", function () { refreshNow(panel); render(panel); });
102
+
103
+ schedule(panel);
104
+ render(panel);
105
+ }
106
+
107
+ function bindAll() {
108
+ Array.prototype.forEach.call(document.querySelectorAll("[data-swui-refresh]"), bind);
109
+ }
110
+
111
+ // One timer for the whole session: re-reads the DOM each tick, so it always
112
+ // operates on the panels currently on the page (and does nothing when there
113
+ // are none) without retaining stale element references.
114
+ function tick() {
115
+ Array.prototype.forEach.call(document.querySelectorAll("[data-swui-refresh]"), function (panel) {
116
+ if (!nextAt.has(panel)) schedule(panel);
117
+ if (intervalOf(panel) > 0 && !document.hidden && Date.now() >= nextAt.get(panel)) refreshNow(panel);
118
+ render(panel);
119
+ });
120
+ }
121
+
122
+ document.addEventListener("DOMContentLoaded", bindAll);
123
+ document.addEventListener("turbo:load", bindAll);
124
+ window.setInterval(tick, TICK_MS);
125
+ })();
@@ -1,4 +1,5 @@
1
1
  /*! tailwindcss v4.3.0 | MIT License | https://tailwindcss.com */
2
+ @layer properties;
2
3
  @layer theme, components, utilities;
3
4
  @layer utilities {
4
5
  .static {
@@ -10,6 +11,12 @@
10
11
  .contents {
11
12
  display: contents;
12
13
  }
14
+ .hidden {
15
+ display: none;
16
+ }
17
+ .filter {
18
+ filter: var(--tw-blur,) var(--tw-brightness,) var(--tw-contrast,) var(--tw-grayscale,) var(--tw-hue-rotate,) var(--tw-invert,) var(--tw-saturate,) var(--tw-sepia,) var(--tw-drop-shadow,);
19
+ }
13
20
  }
14
21
  @layer components {
15
22
  .solid-web-ui {
@@ -47,6 +54,50 @@
47
54
  flex-wrap: wrap;
48
55
  gap: 0.25rem;
49
56
  }
57
+ .solid-web-ui .swui-refresh-bar {
58
+ display: flex;
59
+ justify-content: flex-end;
60
+ margin-bottom: 1rem;
61
+ }
62
+ .solid-web-ui .swui-refresh {
63
+ display: inline-flex;
64
+ align-items: center;
65
+ gap: 0.5rem;
66
+ }
67
+ .solid-web-ui .swui-refresh__field {
68
+ display: inline-flex;
69
+ align-items: center;
70
+ gap: 0.4rem;
71
+ }
72
+ .solid-web-ui .swui-refresh__label {
73
+ font-size: 0.75rem;
74
+ text-transform: uppercase;
75
+ letter-spacing: 0.03em;
76
+ color: var(--swui-color-muted);
77
+ }
78
+ .solid-web-ui .swui-refresh__select {
79
+ padding: 0.3rem 0.5rem;
80
+ border: 1px solid var(--swui-color-border);
81
+ border-radius: var(--swui-radius);
82
+ background: var(--swui-color-surface);
83
+ color: var(--swui-color-text);
84
+ font: inherit;
85
+ font-size: 0.85rem;
86
+ cursor: pointer;
87
+ }
88
+ .solid-web-ui .swui-refresh__select:hover {
89
+ border-color: var(--swui-color-primary);
90
+ }
91
+ .solid-web-ui .swui-refresh__status {
92
+ font-size: 0.8rem;
93
+ color: var(--swui-color-muted);
94
+ font-variant-numeric: tabular-nums;
95
+ min-width: 8.5rem;
96
+ }
97
+ .solid-web-ui .swui-refresh__now {
98
+ line-height: 1;
99
+ padding: 0.35rem 0.55rem;
100
+ }
50
101
  .solid-web-ui .swui-nav__link {
51
102
  display: inline-block;
52
103
  padding: 0.4rem 0.75rem;
@@ -230,3 +281,75 @@
230
281
  margin: 1.5rem 0 0.75rem;
231
282
  }
232
283
  }
284
+ @property --tw-blur {
285
+ syntax: "*";
286
+ inherits: false;
287
+ }
288
+ @property --tw-brightness {
289
+ syntax: "*";
290
+ inherits: false;
291
+ }
292
+ @property --tw-contrast {
293
+ syntax: "*";
294
+ inherits: false;
295
+ }
296
+ @property --tw-grayscale {
297
+ syntax: "*";
298
+ inherits: false;
299
+ }
300
+ @property --tw-hue-rotate {
301
+ syntax: "*";
302
+ inherits: false;
303
+ }
304
+ @property --tw-invert {
305
+ syntax: "*";
306
+ inherits: false;
307
+ }
308
+ @property --tw-opacity {
309
+ syntax: "*";
310
+ inherits: false;
311
+ }
312
+ @property --tw-saturate {
313
+ syntax: "*";
314
+ inherits: false;
315
+ }
316
+ @property --tw-sepia {
317
+ syntax: "*";
318
+ inherits: false;
319
+ }
320
+ @property --tw-drop-shadow {
321
+ syntax: "*";
322
+ inherits: false;
323
+ }
324
+ @property --tw-drop-shadow-color {
325
+ syntax: "*";
326
+ inherits: false;
327
+ }
328
+ @property --tw-drop-shadow-alpha {
329
+ syntax: "<percentage>";
330
+ inherits: false;
331
+ initial-value: 100%;
332
+ }
333
+ @property --tw-drop-shadow-size {
334
+ syntax: "*";
335
+ inherits: false;
336
+ }
337
+ @layer properties {
338
+ @supports ((-webkit-hyphens: none) and (not (margin-trim: inline))) or ((-moz-orient: inline) and (not (color:rgb(from red r g b)))) {
339
+ *, ::before, ::after, ::backdrop {
340
+ --tw-blur: initial;
341
+ --tw-brightness: initial;
342
+ --tw-contrast: initial;
343
+ --tw-grayscale: initial;
344
+ --tw-hue-rotate: initial;
345
+ --tw-invert: initial;
346
+ --tw-opacity: initial;
347
+ --tw-saturate: initial;
348
+ --tw-sepia: initial;
349
+ --tw-drop-shadow: initial;
350
+ --tw-drop-shadow-color: initial;
351
+ --tw-drop-shadow-alpha: 100%;
352
+ --tw-drop-shadow-size: initial;
353
+ }
354
+ }
355
+ }
@@ -0,0 +1 @@
1
+ <%= button_to label, url, method: http_method, class: css_classes, form: form_options %>
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SolidWebUi
4
+ module Ui
5
+ # A button that performs a mutating action through a form (Rails +button_to+):
6
+ # retry/discard a job, pause/resume a queue, clear the cache, trim messages.
7
+ #
8
+ # Always targets the top frame (data-turbo-frame="_top") so the action's
9
+ # redirect/flash escapes the dashboard's refresh turbo-frame. Pass danger: for
10
+ # destructive styling and confirm: for a Turbo confirmation dialog.
11
+ class ActionButtonComponent < ViewComponent::Base
12
+ def initialize(label:, url:, method: :post, danger: false, confirm: nil)
13
+ @label = label
14
+ @url = url
15
+ @method = method
16
+ @danger = danger
17
+ @confirm = confirm
18
+ end
19
+
20
+ private
21
+
22
+ attr_reader :label, :url
23
+
24
+ def http_method = @method
25
+
26
+ def css_classes
27
+ [ "swui-btn", (@danger ? "swui-btn--danger" : nil) ].compact.join(" ")
28
+ end
29
+
30
+ # button_to applies these to the <form>; the class goes on the <button>.
31
+ def form_options
32
+ data = { turbo_frame: "_top" }
33
+ data[:turbo_confirm] = @confirm if @confirm
34
+ { data: data }
35
+ end
36
+ end
37
+ end
38
+ end
@@ -1,15 +1,36 @@
1
- <div class="swui-page">
2
- <header class="swui-page__header">
3
- <h1 class="swui-page__title"><%= title %></h1>
4
- <% if nav.any? %>
5
- <nav class="swui-nav">
6
- <% nav.each do |item| %>
7
- <%= link_to item[:label], item[:href], class: nav_link_class(item) %>
8
- <% end %>
9
- </nav>
10
- <% end %>
11
- </header>
12
- <main class="swui-page__body">
13
- <%= content %>
14
- </main>
1
+ <%# Self-scoping under .solid-web-ui so the dashboard is themed correctly whether %>
2
+ <%# it renders in the gem's standalone layout or inside a host layout. %>
3
+ <div class="solid-web-ui" data-color-scheme="<%= SolidWebUi.config.color_scheme %>">
4
+ <div class="swui-page">
5
+ <header class="swui-page__header">
6
+ <h1 class="swui-page__title"><%= title %></h1>
7
+ <% if nav.any? %>
8
+ <nav class="swui-nav">
9
+ <% nav.each do |item| %>
10
+ <%= link_to item[:label], item[:href], class: nav_link_class(item) %>
11
+ <% end %>
12
+ </nav>
13
+ <% end %>
14
+ </header>
15
+ <main class="swui-page__body">
16
+ <% if refresh? %>
17
+ <%# Controls sit just above the data region, right-aligned, and OUTSIDE the %>
18
+ <%# frame so the <select> value and the countdown survive every reload. %>
19
+ <div class="swui-refresh-bar">
20
+ <%= render(SolidWebUi::Ui::RefreshControlsComponent.new(frame_id: SolidWebUi::Ui::PageComponent::FRAME_ID)) %>
21
+ </div>
22
+ <%# The body is reloaded in place by the bundled JS (morph when Turbo is %>
23
+ <%# present). No src here: JS sets it at refresh time to avoid a redundant %>
24
+ <%# fetch on initial load. data-turbo-action="advance" promotes in-frame %>
25
+ <%# navigations (stat cards, filter tabs, pagination) to update the URL, so %>
26
+ <%# the address bar tracks the current view and auto-refresh/reload target %>
27
+ <%# it instead of snapping back to the dashboard. %>
28
+ <turbo-frame id="<%= SolidWebUi::Ui::PageComponent::FRAME_ID %>" refresh="morph" data-turbo-action="advance">
29
+ <%= content %>
30
+ </turbo-frame>
31
+ <% else %>
32
+ <%= content %>
33
+ <% end %>
34
+ </main>
35
+ </div>
15
36
  </div>
@@ -4,16 +4,25 @@ module SolidWebUi
4
4
  module Ui
5
5
  # Page chrome shared by every dashboard screen: a title, an optional nav bar
6
6
  # (array of { label:, href:, active: }) and the page body as content.
7
+ #
8
+ # When +refresh+ is on (the default), the body is wrapped in a turbo-frame and
9
+ # the header gains the live auto-refresh controls; the bundled JS reloads that
10
+ # frame on the chosen interval. Pass refresh: false for a static page.
7
11
  class PageComponent < ViewComponent::Base
8
- def initialize(title:, nav: [])
12
+ FRAME_ID = "swui-refresh-frame"
13
+
14
+ def initialize(title:, nav: [], refresh: true)
9
15
  @title = title
10
16
  @nav = nav || []
17
+ @refresh = refresh
11
18
  end
12
19
 
13
20
  private
14
21
 
15
22
  attr_reader :title, :nav
16
23
 
24
+ def refresh? = @refresh
25
+
17
26
  def nav_link_class(item)
18
27
  [ "swui-nav__link", item[:active] ? "swui-nav__link--active" : nil ].compact.join(" ")
19
28
  end
@@ -0,0 +1,16 @@
1
+ <div class="swui-refresh"
2
+ data-swui-refresh
3
+ data-frame="<%= frame_id %>"
4
+ data-interval="<%= default_interval %>"
5
+ data-storage-key="<%= SolidWebUi::Ui::RefreshControlsComponent::STORAGE_KEY %>">
6
+ <label class="swui-refresh__field">
7
+ <span class="swui-refresh__label">Auto-refresh</span>
8
+ <select class="swui-refresh__select" data-swui-refresh-select aria-label="Auto-refresh interval">
9
+ <% intervals.each do |seconds| %>
10
+ <option value="<%= seconds %>" <%= "selected" if seconds == default_interval %>><%= option_label(seconds) %></option>
11
+ <% end %>
12
+ </select>
13
+ </label>
14
+ <span class="swui-refresh__status" data-swui-refresh-status aria-live="polite"></span>
15
+ <button type="button" class="swui-btn swui-refresh__now" data-swui-refresh-now aria-label="Refresh now">↻</button>
16
+ </div>
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SolidWebUi
4
+ module Ui
5
+ # Live auto-refresh controls for a dashboard page: a frequency <select>, a
6
+ # countdown to the next refresh and a manual "refresh now" button. The actual
7
+ # polling is driven by the bundled vanilla JS (app/assets/javascripts/
8
+ # solid_web_ui.js), which reads the data-* attributes emitted here and reloads
9
+ # the turbo-frame named by +frame_id+. Rendering is pure markup, so the panel
10
+ # works whether or not Turbo is on the page (JS falls back to fetch+replace).
11
+ class RefreshControlsComponent < ViewComponent::Base
12
+ STORAGE_KEY = "swui:refresh-interval"
13
+
14
+ def initialize(frame_id:, default_interval: nil, intervals: nil)
15
+ @frame_id = frame_id
16
+ @default_interval = (default_interval || SolidWebUi.config.refresh_interval).to_i
17
+ @intervals = Array(intervals || SolidWebUi.config.refresh_intervals).map(&:to_i)
18
+ end
19
+
20
+ private
21
+
22
+ attr_reader :frame_id, :default_interval, :intervals
23
+
24
+ def option_label(seconds)
25
+ seconds.zero? ? "Off" : "#{seconds}s"
26
+ end
27
+ end
28
+ end
29
+ end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module SolidWebUi::Cable
4
4
  class ApplicationController < SolidWebUi.resolve_base_controller(SolidWebUi::Cable.config.base_controller_class)
5
- layout "solid_web_ui"
5
+ layout -> { SolidWebUi::Cable.config.layout }
6
6
  helper SolidWebUi::ComponentHelper
7
7
 
8
8
  private
@@ -2,7 +2,7 @@
2
2
 
3
3
  module SolidWebUi::Cache
4
4
  class ApplicationController < SolidWebUi.resolve_base_controller(SolidWebUi::Cache.config.base_controller_class)
5
- layout "solid_web_ui"
5
+ layout -> { SolidWebUi::Cache.config.layout }
6
6
  helper SolidWebUi::ComponentHelper
7
7
 
8
8
  private
@@ -5,7 +5,7 @@ module SolidWebUi::Queue
5
5
  # so host authentication/authorization applies. Resolved lazily at autoload
6
6
  # time, after host initializers have set `base_controller_class`.
7
7
  class ApplicationController < SolidWebUi.resolve_base_controller(SolidWebUi::Queue.config.base_controller_class)
8
- layout "solid_web_ui"
8
+ layout -> { SolidWebUi::Queue.config.layout }
9
9
  helper SolidWebUi::ComponentHelper
10
10
 
11
11
  private
@@ -5,8 +5,14 @@ module SolidWebUi
5
5
  # read `swui_page(...)` instead of `render SolidWebUi::Ui::PageComponent.new(...)`.
6
6
  # Included into each engine's controller via `helper SolidWebUi::ComponentHelper`.
7
7
  module ComponentHelper
8
- def swui_page(title:, nav: [], &block)
9
- render(Ui::PageComponent.new(title: title, nav: nav), &block)
8
+ def swui_page(title:, nav: [], refresh: true, &block)
9
+ render(Ui::PageComponent.new(title: title, nav: nav, refresh: refresh), &block)
10
+ end
11
+
12
+ def swui_refresh_controls(frame_id:, default_interval: nil, intervals: nil)
13
+ render(Ui::RefreshControlsComponent.new(frame_id: frame_id,
14
+ default_interval: default_interval,
15
+ intervals: intervals))
10
16
  end
11
17
 
12
18
  def swui_stat_card(label:, value:, tone: :neutral, href: nil)
@@ -17,6 +23,11 @@ module SolidWebUi
17
23
  render(Ui::StatusBadgeComponent.new(label: label, status: status))
18
24
  end
19
25
 
26
+ def swui_action_button(label:, url:, method: :post, danger: false, confirm: nil)
27
+ render(Ui::ActionButtonComponent.new(label: label, url: url, method: method,
28
+ danger: danger, confirm: confirm))
29
+ end
30
+
20
31
  def swui_table(headers:, empty_message: "Nothing to show.", &block)
21
32
  render(Ui::TableComponent.new(headers: headers, empty_message: empty_message), &block)
22
33
  end
@@ -5,29 +5,9 @@
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1">
6
6
  <title><%= content_for?(:title) ? yield(:title) : "Solid Web" %></title>
7
7
  <%= csrf_meta_tags %>
8
-
9
- <% if SolidWebUi.config.stylesheet %>
10
- <%= stylesheet_link_tag "solid_web_ui", "data-turbo-track": "reload" %>
11
- <% end %>
12
- <% Array(SolidWebUi.config.extra_stylesheets).each do |sheet| %>
13
- <%= stylesheet_link_tag sheet, "data-turbo-track": "reload" %>
14
- <% end %>
15
-
16
- <%# Theme tokens (host re-themes by overriding these values, never the stylesheet). %>
17
- <style>
18
- .solid-web-ui { <%= SolidWebUi::Theme.css_vars(SolidWebUi.config.theme).html_safe %> }
19
- <% if SolidWebUi.config.color_scheme.to_s == "dark" %>
20
- .solid-web-ui { <%= SolidWebUi::Theme.dark_css_vars(SolidWebUi.config.theme).html_safe %> }
21
- <% elsif SolidWebUi.config.color_scheme.to_s == "auto" %>
22
- @media (prefers-color-scheme: dark) {
23
- .solid-web-ui { <%= SolidWebUi::Theme.dark_css_vars(SolidWebUi.config.theme).html_safe %> }
24
- }
25
- <% end %>
26
- </style>
8
+ <%= solid_web_ui_head_tags %>
27
9
  </head>
28
10
  <body>
29
- <div class="solid-web-ui" data-color-scheme="<%= SolidWebUi.config.color_scheme %>">
30
- <%= yield %>
31
- </div>
11
+ <%= yield %>
32
12
  </body>
33
13
  </html>
@@ -8,8 +8,8 @@
8
8
  </div>
9
9
 
10
10
  <% if SolidWebUi::Cable.config.enable_trim %>
11
- <%= button_to "Trim old messages", trim_messages_path, method: :delete, class: "swui-btn swui-btn--danger",
12
- form: { data: { turbo_confirm: "Delete messages older than the retention window?" } } %>
11
+ <%= swui_action_button(label: "Trim old messages", url: trim_messages_path, method: :delete,
12
+ danger: true, confirm: "Delete messages older than the retention window?") %>
13
13
  <% end %>
14
14
 
15
15
  <h2 class="swui-section-title">Top channels</h2>
@@ -9,7 +9,7 @@
9
9
  </div>
10
10
 
11
11
  <% if SolidWebUi::Cache.config.enable_clear %>
12
- <%= button_to "Clear cache", clear_entries_path, method: :delete, class: "swui-btn swui-btn--danger",
13
- form: { data: { turbo_confirm: "Delete ALL cache entries?" } } %>
12
+ <%= swui_action_button(label: "Clear cache", url: clear_entries_path, method: :delete,
13
+ danger: true, confirm: "Delete ALL cache entries?") %>
14
14
  <% end %>
15
15
  <% end %>
@@ -11,11 +11,11 @@
11
11
  <td><%= short_time(failed.created_at) %></td>
12
12
  <td>
13
13
  <% if SolidWebUi::Queue.config.enable_retry %>
14
- <%= button_to "Retry", retry_failed_execution_path(failed), class: "swui-btn" %>
14
+ <%= swui_action_button(label: "Retry", url: retry_failed_execution_path(failed)) %>
15
15
  <% end %>
16
16
  <% if SolidWebUi::Queue.config.enable_discard %>
17
- <%= button_to "Discard", failed_execution_path(failed), method: :delete, class: "swui-btn swui-btn--danger",
18
- form: { data: { turbo_confirm: "Discard this job permanently?" } } %>
17
+ <%= swui_action_button(label: "Discard", url: failed_execution_path(failed), method: :delete,
18
+ danger: true, confirm: "Discard this job permanently?") %>
19
19
  <% end %>
20
20
  </td>
21
21
  </tr>
@@ -13,9 +13,9 @@
13
13
  <td>
14
14
  <% if SolidWebUi::Queue.config.enable_pause %>
15
15
  <% if queue.paused? %>
16
- <%= button_to "Resume", resume_queue_path(queue.name), class: "swui-btn" %>
16
+ <%= swui_action_button(label: "Resume", url: resume_queue_path(queue.name)) %>
17
17
  <% else %>
18
- <%= button_to "Pause", pause_queue_path(queue.name), class: "swui-btn" %>
18
+ <%= swui_action_button(label: "Pause", url: pause_queue_path(queue.name)) %>
19
19
  <% end %>
20
20
  <% end %>
21
21
  </td>
@@ -15,6 +15,12 @@ module SolidWebUi
15
15
  base.setting :per_page, default: 25
16
16
  base.setting :time_zone, default: "UTC"
17
17
  base.setting :page_title, default: base.respond_to?(:name) ? base.name : "Solid Web"
18
+ # Which layout the dashboards render in. Default is the gem's standalone,
19
+ # full-page layout. Point it at a host layout (e.g. "admin") to render the
20
+ # dashboards inside the host's chrome (sidebar/header). The host layout must
21
+ # then include `<%= solid_web_ui_head_tags %>` and reference its own routes
22
+ # via `main_app.` (so they resolve from the isolated engine's context).
23
+ base.setting :layout, default: "solid_web_ui"
18
24
  end
19
25
  end
20
26
  end
@@ -9,5 +9,12 @@ module SolidWebUi
9
9
  # three web engines (queue/cache/cable) resolve the shared layout, components
10
10
  # and the single precompiled stylesheet without any manual view-path wiring.
11
11
  class Engine < ::Rails::Engine
12
+ # Expose solid_web_ui_head_tags to every host view, so a host layout can pull
13
+ # in the dashboards' stylesheet + theme tokens when embedding them.
14
+ initializer "solid_web_ui.head_helper" do
15
+ ActiveSupport.on_load(:action_view) do
16
+ include SolidWebUi::HeadHelper
17
+ end
18
+ end
12
19
  end
13
20
  end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SolidWebUi
4
+ # Emits the dashboards' stylesheet + theme tokens. Included into ActionView
5
+ # app-wide (see SolidWebUi::Engine) so a host layout can drop
6
+ # `<%= solid_web_ui_head_tags %>` into its <head> when rendering the dashboards
7
+ # inside its own chrome (config.layout = "your_layout").
8
+ #
9
+ # Defined in lib/ (not app/helpers) because it is mixed into ActionView during
10
+ # boot, before the engine's autoload paths are ready.
11
+ module HeadHelper
12
+ def solid_web_ui_head_tags
13
+ tags = []
14
+ if SolidWebUi.config.stylesheet
15
+ tags << stylesheet_link_tag("solid_web_ui", "data-turbo-track": "reload")
16
+ end
17
+ Array(SolidWebUi.config.extra_stylesheets).each do |sheet|
18
+ tags << stylesheet_link_tag(sheet, "data-turbo-track": "reload")
19
+ end
20
+ tags << solid_web_ui_theme_style_tag
21
+ if SolidWebUi.config.javascript
22
+ tags << javascript_include_tag("solid_web_ui", defer: true, "data-turbo-track": "reload")
23
+ end
24
+ safe_join(tags)
25
+ end
26
+
27
+ private
28
+
29
+ def solid_web_ui_theme_style_tag
30
+ theme = SolidWebUi.config.theme
31
+ css = +".solid-web-ui { #{SolidWebUi::Theme.css_vars(theme)} }"
32
+ case SolidWebUi.config.color_scheme.to_s
33
+ when "dark"
34
+ css << " .solid-web-ui { #{SolidWebUi::Theme.dark_css_vars(theme)} }"
35
+ when "auto"
36
+ css << " @media (prefers-color-scheme: dark) { .solid-web-ui { #{SolidWebUi::Theme.dark_css_vars(theme)} } }"
37
+ end
38
+ content_tag(:style, css.html_safe) # rubocop:disable Rails/OutputSafety
39
+ end
40
+ end
41
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SolidWebUi
4
- VERSION = "0.1.0"
4
+ VERSION = "0.3.0"
5
5
  end
data/lib/solid_web_ui.rb CHANGED
@@ -6,6 +6,7 @@ require "solid_web_ui/version"
6
6
  require "solid_web_ui/configurable"
7
7
  require "solid_web_ui/theme"
8
8
  require "solid_web_ui/paginator"
9
+ require "solid_web_ui/head_helper"
9
10
  require "solid_web_ui/engine"
10
11
 
11
12
  module SolidWebUi
@@ -16,6 +17,13 @@ module SolidWebUi
16
17
  setting :color_scheme, default: "auto" # "auto" | "light" | "dark"
17
18
  setting :stylesheet, default: true # false → don't link the bundled CSS (host takes over)
18
19
  setting :extra_stylesheets, default: [] # extra Propshaft stylesheet names to link after ours
20
+ setting :javascript, default: true # false → don't link the bundled live-refresh JS
21
+
22
+ # Live auto-refresh of the dashboards (polling a turbo-frame). The default is
23
+ # the pre-selected interval (seconds; 0 disables); refresh_intervals are the
24
+ # choices offered in the dashboard's frequency <select>.
25
+ setting :refresh_interval, default: 10 # seconds; 0 = off
26
+ setting :refresh_intervals, default: [ 0, 2, 5, 10, 30, 60 ].freeze
19
27
 
20
28
  # Resolve a configured controller class name to a class. Called lazily when a
21
29
  # web engine's ApplicationController is autoloaded, so host initializers have
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solid_web_ui
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anton Radushev
@@ -114,12 +114,18 @@ executables: []
114
114
  extensions: []
115
115
  extra_rdoc_files: []
116
116
  files:
117
+ - LICENSE
117
118
  - README.md
119
+ - app/assets/javascripts/solid_web_ui.js
118
120
  - app/assets/stylesheets/solid_web_ui.css
121
+ - app/components/solid_web_ui/ui/action_button_component.html.erb
122
+ - app/components/solid_web_ui/ui/action_button_component.rb
119
123
  - app/components/solid_web_ui/ui/page_component.html.erb
120
124
  - app/components/solid_web_ui/ui/page_component.rb
121
125
  - app/components/solid_web_ui/ui/paginator_component.html.erb
122
126
  - app/components/solid_web_ui/ui/paginator_component.rb
127
+ - app/components/solid_web_ui/ui/refresh_controls_component.html.erb
128
+ - app/components/solid_web_ui/ui/refresh_controls_component.rb
123
129
  - app/components/solid_web_ui/ui/stat_card_component.html.erb
124
130
  - app/components/solid_web_ui/ui/stat_card_component.rb
125
131
  - app/components/solid_web_ui/ui/status_badge_component.rb
@@ -163,6 +169,7 @@ files:
163
169
  - lib/solid_web_ui/cache/routes.rb
164
170
  - lib/solid_web_ui/configurable.rb
165
171
  - lib/solid_web_ui/engine.rb
172
+ - lib/solid_web_ui/head_helper.rb
166
173
  - lib/solid_web_ui/paginator.rb
167
174
  - lib/solid_web_ui/queue.rb
168
175
  - lib/solid_web_ui/queue/engine.rb