bord 0.5.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 +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +193 -0
- data/Rakefile +9 -0
- data/app/assets/javascripts/bord/application.js +2361 -0
- data/app/assets/javascripts/bord/attract.js +319 -0
- data/app/assets/javascripts/bord/attractive.js +1642 -0
- data/app/assets/javascripts/bord/entry.js +67 -0
- data/app/assets/javascripts/bord/request.js +314 -0
- data/app/assets/javascripts/bord/runtime/addons/response.js +51 -0
- data/app/assets/javascripts/bord/runtime/addons/template.js +120 -0
- data/app/assets/javascripts/bord/runtime/debug.js +18 -0
- data/app/assets/stylesheets/bord/application.css +736 -0
- data/app/controllers/bord/actions_controller.rb +29 -0
- data/app/controllers/bord/application_controller.rb +23 -0
- data/app/controllers/bord/pages_controller.rb +13 -0
- data/app/controllers/bord/records_controller.rb +14 -0
- data/app/controllers/bord/widgets_controller.rb +18 -0
- data/app/helpers/bord/application_helper.rb +4 -0
- data/app/jobs/bord/application_job.rb +4 -0
- data/app/models/bord/action.rb +8 -0
- data/app/models/bord/action_parameters.rb +19 -0
- data/app/models/bord/allowed_actions.rb +65 -0
- data/app/models/bord/application_record.rb +5 -0
- data/app/models/bord/attract_actions.rb +101 -0
- data/app/models/bord/category.rb +18 -0
- data/app/models/bord/dashboard.rb +25 -0
- data/app/models/bord/entry.rb +98 -0
- data/app/models/bord/page/decorator.rb +33 -0
- data/app/models/bord/page/record_decorator.rb +44 -0
- data/app/models/bord/page.rb +82 -0
- data/app/models/bord/widget/decorator.rb +69 -0
- data/app/models/bord/widget.rb +40 -0
- data/app/models/concerns/bord/conditionable.rb +8 -0
- data/app/views/bord/pages/show.html.erb +9 -0
- data/app/views/bord/records/show.html.erb +13 -0
- data/app/views/bord/shared/_templates.html.erb +75 -0
- data/app/views/bord/widgets/_action.html.erb +7 -0
- data/app/views/bord/widgets/_widget.html.erb +25 -0
- data/app/views/bord/widgets/index.html.erb +17 -0
- data/app/views/layouts/bord/application.html.erb +38 -0
- data/config/routes.rb +11 -0
- data/lib/bord/configuration.rb +60 -0
- data/lib/bord/engine.rb +11 -0
- data/lib/bord/loader.rb +8 -0
- data/lib/bord/options.rb +17 -0
- data/lib/bord/presets/action_mailbox.json +20 -0
- data/lib/bord/presets/active_storage.json +20 -0
- data/lib/bord/presets/devise.json +1 -0
- data/lib/bord/presets/good_job.json +25 -0
- data/lib/bord/presets/sidekiq.json +28 -0
- data/lib/bord/presets/solid_queue.json +12 -0
- data/lib/bord/presets/stripe.json +30 -0
- data/lib/bord/presets/user.json +22 -0
- data/lib/bord/version.rb +3 -0
- data/lib/bord.rb +71 -0
- data/lib/generators/bord/install_generator.rb +16 -0
- data/lib/generators/bord/presets_generator.rb +62 -0
- metadata +116 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: ebb3862bc9aaaa79d7b895cac56f9f4832ec5b7fc164cbe2ec5a7ddfca32aa76
|
|
4
|
+
data.tar.gz: bcd7e3b5f918cabb3d28e21c1a72e65cd35643e1a1cc6a72884dd95302c6bd1a
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 4e9a7cd4e4914a644408e3884bab8cb96066aada77c87c857edc3a4046c8761dc134d7bf124198864bf8f5e6d8c74251cb5b57723841dd77de86c0bda1309f62
|
|
7
|
+
data.tar.gz: fcec7b789bc8b288c33622518e51843b3d072eb3299eb7d1b6a2c4cc7be512138c312fa30eed201a785deb731e278e2c9e1bcf061e2a201f7116329f5bf8dd6a
|
data/MIT-LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright Rails Designer
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
+
a copy of this software and associated documentation files (the
|
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
+
the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be
|
|
12
|
+
included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
# Bord
|
|
2
|
+
|
|
3
|
+
A Rails engine that puts a dashboard at `/bord`. Define metrics, lists, categories and pages in `config/bord/`. Every widget runs your own code: ActiveRecord queries, Stripe calls, Good Job stats, Action Mailbox records.
|
|
4
|
+
|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
**Sponsored By [Rails Designer](https://railsdesigner.com/)**
|
|
8
|
+
|
|
9
|
+
<a href="https://railsdesigner.com/" target="_blank">
|
|
10
|
+
<picture>
|
|
11
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/Rails-Designer/bord/HEAD/.github/logo-dark.svg">
|
|
12
|
+
<source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/Rails-Designer/board/HEAD/.github/logo-light.svg">
|
|
13
|
+
<img alt="Rails Designer" src="https://raw.githubusercontent.com/Rails-Designer/bord/HEAD/.github/logo-light.svg" width="240" style="max-width: 100%;">
|
|
14
|
+
</picture>
|
|
15
|
+
</a>
|
|
16
|
+
|
|
17
|
+
## Getting started
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
bundle add bord
|
|
21
|
+
bin/rails generate bord:install
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
The installer creates `config/bord/dashboard.rb` and mounts the engine at `/bord`. Bord loads every file under `config/bord/**/*.rb` automatically.
|
|
25
|
+
|
|
26
|
+
```ruby
|
|
27
|
+
# config/bord/dashboard.rb
|
|
28
|
+
Bord.draw do
|
|
29
|
+
title "Spinal Labs"
|
|
30
|
+
|
|
31
|
+
category :financials, label: "Financials", position: 1 do
|
|
32
|
+
metric :mrr, label: "MRR", icon: :"dollar-sign", value: -> { Current.account.mrr.format }
|
|
33
|
+
list :recent_users, label: "Recent users", items: -> { User.order(created_at: :desc).limit(5) }
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Values and items are lambdas, evaluated per request. List items are model instances, so Bord renders each entry with `to_bord` (see Lists). Add more categories and widgets the same way.
|
|
39
|
+
|
|
40
|
+
## Metrics
|
|
41
|
+
|
|
42
|
+
```ruby
|
|
43
|
+
metric :users, label: "Users", value: -> { User.count }
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
| Option | Description |
|
|
47
|
+
|--------|-------------|
|
|
48
|
+
| `label` | Card title, defaults to the humanized id |
|
|
49
|
+
| `value` | Scalar or lambda evaluated per request |
|
|
50
|
+
| `href` | Makes the value a link |
|
|
51
|
+
| `position` | Ordering within the category |
|
|
52
|
+
| `actions` | Widget-level actions |
|
|
53
|
+
| `if` / `unless` | Conditional visibility |
|
|
54
|
+
|
|
55
|
+
## Lists
|
|
56
|
+
|
|
57
|
+
```ruby
|
|
58
|
+
list :recent_users,
|
|
59
|
+
label: "Recent users",
|
|
60
|
+
items: -> { User.order(created_at: :desc).limit(5).map { |user| {label: user.email, href: "/admin/users/#{user.id}"} } }
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Each item is a hash with `label`, optional `href` and `actions`. You can also pass model instances and map them with `to_bord`:
|
|
64
|
+
|
|
65
|
+
```ruby
|
|
66
|
+
class User < ApplicationRecord
|
|
67
|
+
def to_bord
|
|
68
|
+
{title: full_name, description: email, href: admin_user_path(self)}
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
list :recent_users,
|
|
73
|
+
label: "Recent users",
|
|
74
|
+
items: -> { User.order(created_at: :desc).limit(5) }
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Without `to_bord`, the title falls back to `ModelName #id`. The id comes from `to_gid` or `to_param`. The link comes from the host polymorphic route.
|
|
78
|
+
|
|
79
|
+
## Categories
|
|
80
|
+
|
|
81
|
+
```ruby
|
|
82
|
+
category :operations, label: "Operations", position: 2 do
|
|
83
|
+
metric :failed_jobs, label: "Failed jobs", value: -> { FailedJob.count }
|
|
84
|
+
end
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Categories group widgets and accept `position` and `if`/`unless`. Widgets outside any category appear below the categories.
|
|
88
|
+
|
|
89
|
+
## Actions
|
|
90
|
+
|
|
91
|
+
Two kinds:
|
|
92
|
+
|
|
93
|
+
```ruby
|
|
94
|
+
# Navigation
|
|
95
|
+
{label: "View", href: "/admin/users"}
|
|
96
|
+
|
|
97
|
+
# Server-side action
|
|
98
|
+
{label: "Refund", action: {record: charge.to_gid.to_s, method: :refund, customer_id: charge.id}}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Bord locates the record by GlobalID, calls `method` with the remaining parameters and refreshes the widget. Add `confirm:` to ask before submitting. Submitted actions must match the actions you declared. Anything else returns 404.
|
|
102
|
+
|
|
103
|
+
A list with per-item actions and a widget-level action:
|
|
104
|
+
|
|
105
|
+
```ruby
|
|
106
|
+
list :recent_charges,
|
|
107
|
+
label: "Recent charges",
|
|
108
|
+
items: -> {
|
|
109
|
+
Current.account.charges.recent.limit(3).map do |charge|
|
|
110
|
+
{
|
|
111
|
+
label: charge.label,
|
|
112
|
+
href: "/charges/#{charge.id}",
|
|
113
|
+
actions: [
|
|
114
|
+
{
|
|
115
|
+
label: "Refund",
|
|
116
|
+
confirm: "Refund this charge?",
|
|
117
|
+
action: {record: charge.to_gid.to_s, method: :refund, customer_id: charge.id}
|
|
118
|
+
}
|
|
119
|
+
]
|
|
120
|
+
}
|
|
121
|
+
end
|
|
122
|
+
},
|
|
123
|
+
actions: [{label: "View all", href: "/admin/charges"}]
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
Use `variant:` to style actions: `:primary`, `:danger` or `:text`.
|
|
127
|
+
|
|
128
|
+
## Pages
|
|
129
|
+
|
|
130
|
+
```ruby
|
|
131
|
+
# config/bord/users.rb
|
|
132
|
+
Bord.page :users,
|
|
133
|
+
label: "Users",
|
|
134
|
+
description: "All users",
|
|
135
|
+
records: -> {
|
|
136
|
+
User.order(created_at: :desc).map do |user|
|
|
137
|
+
{
|
|
138
|
+
title: user.email,
|
|
139
|
+
description: "Joined #{user.created_at.to_date}",
|
|
140
|
+
actions: [{label: "View", href: "/admin/users/#{user.id}"}]
|
|
141
|
+
}
|
|
142
|
+
end
|
|
143
|
+
},
|
|
144
|
+
record: ->(id) {
|
|
145
|
+
user = User.find(id)
|
|
146
|
+
|
|
147
|
+
{
|
|
148
|
+
title: user.email,
|
|
149
|
+
description: "Customer since #{user.created_at.to_date}",
|
|
150
|
+
fields: [{label: "Email", value: user.email}, {label: "Plan", value: user.plan}],
|
|
151
|
+
actions: [{label: "Edit", href: "/admin/users/#{user.id}/edit"}]
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
Routes:
|
|
157
|
+
|
|
158
|
+
- `/bord/pages/:page_id`: record list
|
|
159
|
+
- `/bord/pages/:page_id/records/:record_id`: record detail
|
|
160
|
+
|
|
161
|
+
`record` is optional. Without it, the detail route returns 404.
|
|
162
|
+
|
|
163
|
+
Link to a page from a widget with `bord.page_path(:users)` inside a lambda or a string path.
|
|
164
|
+
|
|
165
|
+
## Presets
|
|
166
|
+
|
|
167
|
+
```bash
|
|
168
|
+
bin/rails generate bord:presets
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
The generator lists the bundled presets: Solid Queue, GoodJob, Stripe, Devise, Sidekiq, Active Storage, Action Mailbox and User. Pick the ones you want and the generator appends their code to `config/bord/presets.rb`.
|
|
172
|
+
|
|
173
|
+
Other gems can ship presets too. A preset is a JSON file at `bord/presets/<name>.json` with `name`, `description`, an optional `note` and `code` lines. Presets from gems show up in the same selection list.
|
|
174
|
+
|
|
175
|
+
## Access
|
|
176
|
+
|
|
177
|
+
In production, `/bord` returns 404 until you set an authenticated `parent_controller`. Development and test work out of the box. Bord has one authorization gate: the host's `parent_controller`. Anyone with dashboard access can run every declared action. Submitted actions must match the actions you declared. Anything else returns 404.
|
|
178
|
+
|
|
179
|
+
## Customization
|
|
180
|
+
|
|
181
|
+
```ruby
|
|
182
|
+
# config/initializers/bord.rb
|
|
183
|
+
Bord.configure do |configuration|
|
|
184
|
+
configuration.parent_controller = "Admin::BaseController"
|
|
185
|
+
configuration.brand_hue = 250
|
|
186
|
+
end
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
`title` is set inside `Bord.draw`.
|
|
190
|
+
|
|
191
|
+
## License
|
|
192
|
+
|
|
193
|
+
MIT
|