mbeditor 0.12.1 → 0.12.2
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 +4 -4
- data/CHANGELOG.md +50 -0
- data/app/assets/javascripts/mbeditor/components/EditorPanel.js +78 -0
- data/app/assets/javascripts/mbeditor/components/ModelGraph.js +233 -59
- data/app/assets/javascripts/mbeditor/file_service.js +9 -0
- data/app/assets/stylesheets/mbeditor/editor.css +60 -0
- data/app/controllers/mbeditor/editors_controller.rb +13 -0
- data/app/services/mbeditor/model_graph_service.rb +13 -3
- data/app/services/mbeditor/route_service.rb +79 -0
- data/lib/mbeditor/configuration.rb +4 -1
- data/lib/mbeditor/engine.rb +17 -3
- data/lib/mbeditor/route_map.rb +1 -0
- data/lib/mbeditor/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a2d9c1ba81f945f5ce0772455f51e66a110fa43a1e24f62c96e6859312c4a968
|
|
4
|
+
data.tar.gz: d01eb3a6edd6e221e92c25e093c7c5944b32c50dafad6a4cacfa953e5c0b1925
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f8c189fa9f7215d5a376ab321a10186645c6671a2c1de874c3f3b254e3ebebb20a2c102e0c5357fb0ee0183eb0c634d2f26c7f7860901cec8e941f56ca26bd75
|
|
7
|
+
data.tar.gz: d0f8bdb6abe76b88e8438c0f31e78055d49fe09dfb3c88df1031312c33985b8ad2906f72482cc32a7c986a4019dee19226e42c96fa6d99b52f1da1cdb4faa790
|
data/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,56 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.12.2] - 2026-08-03
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- **Inline route hints in controllers.** Every action in a controller file is
|
|
14
|
+
annotated with the verb and path that reach it — `GET /orders/:id` beside
|
|
15
|
+
`def show` — and a public action nothing routes to is flagged `no route`.
|
|
16
|
+
Hovering adds the named-route helper. Answering "is this actually reachable?"
|
|
17
|
+
previously meant reading `config/routes.rb` and expanding `resources` in your
|
|
18
|
+
head.
|
|
19
|
+
|
|
20
|
+
Routes come from the host app's own route set rather than by parsing
|
|
21
|
+
`config/routes.rb`. mbeditor runs inside the app, so the routes are already
|
|
22
|
+
built — and they are the only source that accounts for `resources` expansion,
|
|
23
|
+
`member`/`collection` blocks, scopes, constraints and mounted engines.
|
|
24
|
+
|
|
25
|
+
- **`config.model_graph_max_models`** (default 1000, was a hard-coded 300).
|
|
26
|
+
A schema over the cap silently lost models and only said "(truncated)".
|
|
27
|
+
|
|
28
|
+
### Changed
|
|
29
|
+
- **Model boxes are sized to their contents** rather than all being one width,
|
|
30
|
+
so a long model or column name is no longer truncated while a model called
|
|
31
|
+
`Tag` wastes most of its box. Layer positions accumulate per layer, since a
|
|
32
|
+
fixed stride would let a wide box overlap the next layer.
|
|
33
|
+
- **Cluster blocks are packed in two dimensions** instead of stacked in a single
|
|
34
|
+
column, which left a schema with one big core and several small islands
|
|
35
|
+
running off the bottom with the right-hand side empty.
|
|
36
|
+
- **The dummy app now carries a real ActiveRecord schema** — 20 models and 44
|
|
37
|
+
associations covering a hub, a chain, a self-reference, a join table, a
|
|
38
|
+
polymorphic association and unconnected islands — so the model graph can be
|
|
39
|
+
demonstrated and tested against something representative.
|
|
40
|
+
|
|
41
|
+
### Fixed
|
|
42
|
+
- **mbeditor could stop a host app from booting.** The pending-migrations
|
|
43
|
+
middleware was installed whenever `ActiveRecord::Migration::CheckPending` was
|
|
44
|
+
defined, but Rails only puts that middleware in the stack when
|
|
45
|
+
`config.active_record.migration_error` is `:page_load`. Any app loading
|
|
46
|
+
ActiveRecord with a different setting raised "No such middleware to insert
|
|
47
|
+
before" during boot. It now tests the same condition Rails does.
|
|
48
|
+
- **Long labels drew straight out past the edge of their model box.** SVG text
|
|
49
|
+
neither wraps nor ellipsises; labels are now measured against the font the
|
|
50
|
+
theme actually resolves and cut to fit.
|
|
51
|
+
- **"no database connection" hung below the box it belonged to** — the box
|
|
52
|
+
height did not count that placeholder line.
|
|
53
|
+
- **The model search is a real dropdown.** The native `<datalist>` rendered in
|
|
54
|
+
the browser's own chrome: unstyleable, and unable to show the table name and
|
|
55
|
+
column count beside each model. Arrow keys and Enter work as before.
|
|
56
|
+
- **The titlebar wrapped to two lines in a narrow window**, pushing the toolbar
|
|
57
|
+
out of its 32px row. It no longer wraps, and below the width where the toolbar
|
|
58
|
+
drops its button labels the title gives way to the icon alone.
|
|
59
|
+
|
|
10
60
|
## [0.12.1] - 2026-08-03
|
|
11
61
|
|
|
12
62
|
### Added
|
|
@@ -90,6 +90,7 @@ var EditorPanel = function EditorPanel(_ref) {
|
|
|
90
90
|
|
|
91
91
|
var blameDecorationsRef = useRef([]);
|
|
92
92
|
var gitLineDecorationsRef = useRef([]);
|
|
93
|
+
var routeDecorationsRef = useRef([]);
|
|
93
94
|
// Latest git line-diff refresh, read by the poll effect so its interval does
|
|
94
95
|
// not have to be torn down whenever the active tab changes.
|
|
95
96
|
var gitLineRefreshRef = useRef(null);
|
|
@@ -1530,6 +1531,83 @@ var EditorPanel = function EditorPanel(_ref) {
|
|
|
1530
1531
|
}
|
|
1531
1532
|
}, [isBlameVisible, tab.path, blameData, isBlameLoading]);
|
|
1532
1533
|
|
|
1534
|
+
// Inline route hints for controllers.
|
|
1535
|
+
//
|
|
1536
|
+
// Every `def` in a controller gets the verb and path that reach it drawn after
|
|
1537
|
+
// the line, and a public action nothing routes to is called out — the question
|
|
1538
|
+
// "is this actually reachable?" otherwise means reading config/routes.rb and
|
|
1539
|
+
// mentally expanding `resources`. Routes come from the host app's own route
|
|
1540
|
+
// set, which is the only thing that knows how those expand.
|
|
1541
|
+
//
|
|
1542
|
+
// Decorations, not view zones: a hint belongs on the line, and a zone would
|
|
1543
|
+
// push the code around every time a file was opened.
|
|
1544
|
+
useEffect(function () {
|
|
1545
|
+
var editor = monacoRef.current;
|
|
1546
|
+
if (!editor || !window.monaco) return;
|
|
1547
|
+
|
|
1548
|
+
var clear = function () {
|
|
1549
|
+
if (!routeDecorationsRef.current.length) return;
|
|
1550
|
+
routeDecorationsRef.current = editor.deltaDecorations(routeDecorationsRef.current, []);
|
|
1551
|
+
};
|
|
1552
|
+
|
|
1553
|
+
if (!tab.path || !/^app\/controllers\/.+_controller\.rb$/.test(tab.path)) {
|
|
1554
|
+
clear();
|
|
1555
|
+
return;
|
|
1556
|
+
}
|
|
1557
|
+
|
|
1558
|
+
var cancelled = false;
|
|
1559
|
+
FileService.getRoutes(tab.path).then(function (data) {
|
|
1560
|
+
if (cancelled) return;
|
|
1561
|
+
var actions = (data && data.actions) || {};
|
|
1562
|
+
var model = editor.getModel();
|
|
1563
|
+
if (!model) return;
|
|
1564
|
+
|
|
1565
|
+
var decorations = [];
|
|
1566
|
+
var text = model.getValue().split('\n');
|
|
1567
|
+
// Only methods above the first `private`/`protected` are candidates for a
|
|
1568
|
+
// route; flagging a helper below it as unrouted would be noise.
|
|
1569
|
+
var visibilityEnded = false;
|
|
1570
|
+
|
|
1571
|
+
text.forEach(function (line, i) {
|
|
1572
|
+
if (/^\s*(private|protected)\s*$/.test(line)) { visibilityEnded = true; return; }
|
|
1573
|
+
var m = line.match(/^\s*def\s+(?:self\.)?([a-zA-Z_][a-zA-Z0-9_]*[?!=]?)/);
|
|
1574
|
+
if (!m) return;
|
|
1575
|
+
|
|
1576
|
+
var name = m[1];
|
|
1577
|
+
var routes = actions[name];
|
|
1578
|
+
var lineNo = i + 1;
|
|
1579
|
+
var col = line.length + 1;
|
|
1580
|
+
|
|
1581
|
+
if (routes && routes.length) {
|
|
1582
|
+
var label = routes.map(function (r) { return r.verb + ' ' + r.path; }).join(' · ');
|
|
1583
|
+
decorations.push({
|
|
1584
|
+
range: new window.monaco.Range(lineNo, col, lineNo, col),
|
|
1585
|
+
options: {
|
|
1586
|
+
after: { content: ' ' + label, inlineClassName: 'mbeditor-route-hint' },
|
|
1587
|
+
hoverMessage: routes.map(function (r) {
|
|
1588
|
+
return { value: '`' + r.verb + ' ' + r.path + '`' + (r.name ? ' — `' + r.name + '_path`' : '') };
|
|
1589
|
+
}),
|
|
1590
|
+
showIfCollapsed: true
|
|
1591
|
+
}
|
|
1592
|
+
});
|
|
1593
|
+
} else if (!visibilityEnded && !/[?!=]$/.test(name) && name !== 'initialize') {
|
|
1594
|
+
decorations.push({
|
|
1595
|
+
range: new window.monaco.Range(lineNo, col, lineNo, col),
|
|
1596
|
+
options: {
|
|
1597
|
+
after: { content: ' no route', inlineClassName: 'mbeditor-route-hint-none' },
|
|
1598
|
+
hoverMessage: [{ value: 'No route in this application dispatches to this action.' }],
|
|
1599
|
+
showIfCollapsed: true
|
|
1600
|
+
}
|
|
1601
|
+
});
|
|
1602
|
+
}
|
|
1603
|
+
});
|
|
1604
|
+
|
|
1605
|
+
routeDecorationsRef.current = editor.deltaDecorations(routeDecorationsRef.current, decorations);
|
|
1606
|
+
}).catch(function () { /* hints are additive; a failure just means none */ });
|
|
1607
|
+
|
|
1608
|
+
return function () { cancelled = true; clear(); };
|
|
1609
|
+
}, [tab.path, tab.externalContentVersion, monacoReady]);
|
|
1610
|
+
|
|
1533
1611
|
// Render Blame block headers (author + summary) above contiguous commit regions.
|
|
1534
1612
|
useEffect(function () {
|
|
1535
1613
|
if (!monacoRef.current || !window.monaco || !isBlameVisible || !blameData) return;
|
|
@@ -14,7 +14,13 @@
|
|
|
14
14
|
// carried no information at all. Only a layered layout derives position from
|
|
15
15
|
// the associations themselves.
|
|
16
16
|
var ModelGraph = (function () {
|
|
17
|
-
|
|
17
|
+
// Boxes are sized to their contents rather than all being one width. A fixed
|
|
18
|
+
// 188px meant a model with a long name or long column names had its labels
|
|
19
|
+
// truncated while a model called Tag wasted most of its box. Clamped at both
|
|
20
|
+
// ends so one pathological name cannot stretch a whole layer.
|
|
21
|
+
var NODE_W_MIN = 168;
|
|
22
|
+
var NODE_W_MAX = 320;
|
|
23
|
+
var NODE_W = NODE_W_MIN; // fallback for anything without a measured model
|
|
18
24
|
var HEADER_H = 34; // model name + table name
|
|
19
25
|
var FIELD_H = 15;
|
|
20
26
|
var MAX_FIELDS = 8; // the rest are one click away in the schema modal
|
|
@@ -22,14 +28,79 @@ var ModelGraph = (function () {
|
|
|
22
28
|
var LAYER_GAP = 110; // horizontal space between layers
|
|
23
29
|
var ORDER_PASSES = 4; // median sweeps for crossing reduction
|
|
24
30
|
var STRAIGHTEN_PASSES = 3;
|
|
25
|
-
var MAX_ASSOC_LISTED = 12;
|
|
31
|
+
var MAX_ASSOC_LISTED = 12;
|
|
32
|
+
var MAX_SEARCH_RESULTS = 50; // the card stays readable; the rest are counted
|
|
26
33
|
var BLOCK_PAD = 26; // breathing room inside a cluster's boundary
|
|
27
34
|
var BLOCK_GAP = 56; // space between neighbouring clusters
|
|
28
35
|
|
|
36
|
+
// SVG text neither wraps nor ellipsises: a long model or column name simply
|
|
37
|
+
// draws straight out past the edge of its box and over whatever is beside it.
|
|
38
|
+
// Measure with a cached canvas context and cut to fit — accurate for whatever
|
|
39
|
+
// font the theme actually resolves, unlike a characters-per-pixel guess.
|
|
40
|
+
var _measureCtx = null;
|
|
41
|
+
var _measureCache = {};
|
|
42
|
+
|
|
43
|
+
function textWidth(text, font) {
|
|
44
|
+
var key = font + '\u0000' + text;
|
|
45
|
+
if (_measureCache[key] !== undefined) return _measureCache[key];
|
|
46
|
+
if (!_measureCtx) {
|
|
47
|
+
if (typeof document === 'undefined') return text.length * 6;
|
|
48
|
+
_measureCtx = document.createElement('canvas').getContext('2d');
|
|
49
|
+
}
|
|
50
|
+
_measureCtx.font = font;
|
|
51
|
+
var w = _measureCtx.measureText(text).width;
|
|
52
|
+
// Unbounded growth would be a leak on a large schema; the cache only needs
|
|
53
|
+
// to cover one render's worth of labels.
|
|
54
|
+
if (Object.keys(_measureCache).length > 4000) _measureCache = {};
|
|
55
|
+
_measureCache[key] = w;
|
|
56
|
+
return w;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function fitText(text, maxWidth, font) {
|
|
60
|
+
text = String(text == null ? '' : text);
|
|
61
|
+
if (!text || textWidth(text, font) <= maxWidth) return text;
|
|
62
|
+
var lo = 0, hi = text.length;
|
|
63
|
+
while (lo < hi) {
|
|
64
|
+
var mid = Math.ceil((lo + hi) / 2);
|
|
65
|
+
if (textWidth(text.slice(0, mid) + '…', font) <= maxWidth) lo = mid; else hi = mid - 1;
|
|
66
|
+
}
|
|
67
|
+
return lo > 0 ? text.slice(0, lo) + '…' : '…';
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Must match the .mg-name / .mg-table / .mg-field rules in editor.css.
|
|
71
|
+
var FONT_NAME = '600 12px ui-monospace, SFMono-Regular, Menlo, monospace';
|
|
72
|
+
var FONT_SMALL = '9px ui-monospace, SFMono-Regular, Menlo, monospace';
|
|
73
|
+
var FONT_FIELD = '10px ui-monospace, SFMono-Regular, Menlo, monospace';
|
|
74
|
+
|
|
75
|
+
function nodeWidth(model) {
|
|
76
|
+
if (model && model.__mgWidth) return model.__mgWidth;
|
|
77
|
+
if (!model) return NODE_W;
|
|
78
|
+
|
|
79
|
+
// Header: name plus the open-schema button, and the table/count line.
|
|
80
|
+
var need = textWidth(String(model.name || ''), FONT_NAME) + 20 + 26;
|
|
81
|
+
need = Math.max(need, textWidth(
|
|
82
|
+
(model.table || '—') + (model.columnCount ? ' · ' + model.columnCount + ' cols' : ''),
|
|
83
|
+
FONT_SMALL) + 20 + 26);
|
|
84
|
+
|
|
85
|
+
(model.columns || []).slice(0, MAX_FIELDS).forEach(function (c) {
|
|
86
|
+
// name on the left, type right-aligned, with a gap between them
|
|
87
|
+
need = Math.max(need,
|
|
88
|
+
textWidth(String(c.name || ''), FONT_FIELD) +
|
|
89
|
+
textWidth(String(c.type || ''), FONT_SMALL) + 32);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
var w = Math.round(Math.min(NODE_W_MAX, Math.max(NODE_W_MIN, need)));
|
|
93
|
+
try { model.__mgWidth = w; } catch (e) { /* frozen payload — recompute */ }
|
|
94
|
+
return w;
|
|
95
|
+
}
|
|
96
|
+
|
|
29
97
|
function nodeHeight(model) {
|
|
30
98
|
var shown = Math.min((model.columns || []).length, MAX_FIELDS);
|
|
31
99
|
var more = (model.columnCount || 0) > shown ? FIELD_H : 0;
|
|
32
|
-
|
|
100
|
+
// With no columns the box still draws one line — "no database connection" —
|
|
101
|
+
// and not counting it left that text hanging below the box it belongs to.
|
|
102
|
+
var placeholder = shown === 0 ? FIELD_H : 0;
|
|
103
|
+
return HEADER_H + shown * FIELD_H + more + placeholder + 8;
|
|
33
104
|
}
|
|
34
105
|
|
|
35
106
|
// Undirected adjacency: for placement, "A belongs_to B" and "B has_many A"
|
|
@@ -224,15 +295,27 @@ var ModelGraph = (function () {
|
|
|
224
295
|
Object.keys(y).forEach(function (n) { minY = Math.min(minY, y[n]); });
|
|
225
296
|
if (!isFinite(minY)) minY = 0;
|
|
226
297
|
|
|
298
|
+
// Layers are as wide as their widest box, and each starts where the previous
|
|
299
|
+
// one ended. A fixed stride assumed every box was NODE_W and would overlap
|
|
300
|
+
// the next layer as soon as one of them grew.
|
|
301
|
+
var layerX = [];
|
|
302
|
+
var cursorX = 0;
|
|
303
|
+
layers.forEach(function (names, li) {
|
|
304
|
+
layerX[li] = cursorX;
|
|
305
|
+
var widest = 0;
|
|
306
|
+
(names || []).forEach(function (n) { widest = Math.max(widest, nodeWidth(byName[n])); });
|
|
307
|
+
cursorX += (widest || NODE_W_MIN) + LAYER_GAP;
|
|
308
|
+
});
|
|
309
|
+
|
|
227
310
|
var positions = {};
|
|
228
311
|
var maxX = 0, maxY = 0;
|
|
229
312
|
layers.forEach(function (names, li) {
|
|
230
313
|
if (!names) return;
|
|
231
314
|
names.forEach(function (n) {
|
|
232
|
-
var x = li
|
|
315
|
+
var x = layerX[li];
|
|
233
316
|
var yy = y[n] - minY;
|
|
234
317
|
positions[n] = { x: x, y: yy, model: byName[n] };
|
|
235
|
-
maxX = Math.max(maxX, x +
|
|
318
|
+
maxX = Math.max(maxX, x + nodeWidth(byName[n]));
|
|
236
319
|
maxY = Math.max(maxY, yy + nodeHeight(byName[n]));
|
|
237
320
|
});
|
|
238
321
|
});
|
|
@@ -273,10 +356,13 @@ var ModelGraph = (function () {
|
|
|
273
356
|
var positions = {};
|
|
274
357
|
var regions = [];
|
|
275
358
|
var pad = 60;
|
|
276
|
-
var cursorY = pad;
|
|
277
|
-
var maxRight = pad;
|
|
278
359
|
|
|
279
|
-
|
|
360
|
+
// Lay each component out first, then pack the finished blocks. Blocks used
|
|
361
|
+
// to be stacked in a single column, so a schema with a big connected core
|
|
362
|
+
// and a handful of one-model islands ran off the bottom of the canvas with
|
|
363
|
+
// the whole right-hand side empty. Shelf packing wraps them instead, which
|
|
364
|
+
// is both more compact and closer to how the eye scans a page.
|
|
365
|
+
var blocks = components(allNames, adj).map(function (group) {
|
|
280
366
|
var inGroup = {};
|
|
281
367
|
group.forEach(function (n) { inGroup[n] = true; });
|
|
282
368
|
var groupEdges = dir.filter(function (e) { return inGroup[e.from] && inGroup[e.to]; });
|
|
@@ -299,39 +385,67 @@ var ModelGraph = (function () {
|
|
|
299
385
|
orderLayers(layers, adjIn, adjOut);
|
|
300
386
|
var laid = assignCoords(layers, byName, adjIn, adjOut);
|
|
301
387
|
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
388
|
+
return {
|
|
389
|
+
laid: laid,
|
|
390
|
+
group: group,
|
|
391
|
+
w: laid.width + BLOCK_PAD * 2,
|
|
392
|
+
h: laid.height + BLOCK_PAD * 2
|
|
393
|
+
};
|
|
394
|
+
});
|
|
395
|
+
|
|
396
|
+
// Wrap at whichever is wider: a roughly square canvas, or the widest single
|
|
397
|
+
// block (which can never be split).
|
|
398
|
+
var totalArea = blocks.reduce(function (a, b) { return a + b.w * b.h; }, 0);
|
|
399
|
+
var widest = blocks.reduce(function (a, b) { return Math.max(a, b.w); }, 0);
|
|
400
|
+
var targetW = Math.max(widest, Math.sqrt(totalArea * 1.6));
|
|
401
|
+
|
|
402
|
+
var shelfX = pad, shelfY = pad, shelfH = 0, maxRight = pad;
|
|
403
|
+
|
|
404
|
+
blocks.forEach(function (b) {
|
|
405
|
+
if (shelfX > pad && shelfX + b.w > pad + targetW) {
|
|
406
|
+
shelfX = pad;
|
|
407
|
+
shelfY += shelfH + BLOCK_GAP;
|
|
408
|
+
shelfH = 0;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
Object.keys(b.laid.positions).forEach(function (n) {
|
|
412
|
+
var q = b.laid.positions[n];
|
|
413
|
+
positions[n] = {
|
|
414
|
+
x: shelfX + BLOCK_PAD + q.x,
|
|
415
|
+
y: shelfY + BLOCK_PAD + q.y,
|
|
416
|
+
model: q.model
|
|
417
|
+
};
|
|
305
418
|
});
|
|
306
419
|
|
|
307
420
|
regions.push({
|
|
308
|
-
x:
|
|
309
|
-
|
|
310
|
-
label: group.length > 1 ? group.length + ' related models' : group[0]
|
|
421
|
+
x: shelfX, y: shelfY, w: b.w, h: b.h,
|
|
422
|
+
label: b.group.length > 1 ? b.group.length + ' related models' : b.group[0]
|
|
311
423
|
});
|
|
312
424
|
|
|
313
|
-
maxRight = Math.max(maxRight,
|
|
314
|
-
|
|
425
|
+
maxRight = Math.max(maxRight, shelfX + b.w);
|
|
426
|
+
shelfH = Math.max(shelfH, b.h);
|
|
427
|
+
shelfX += b.w + BLOCK_GAP;
|
|
315
428
|
});
|
|
316
429
|
|
|
317
430
|
return {
|
|
318
431
|
positions: positions,
|
|
319
432
|
regions: regions,
|
|
320
433
|
width: maxRight + pad,
|
|
321
|
-
height:
|
|
434
|
+
height: shelfY + shelfH + pad
|
|
322
435
|
};
|
|
323
436
|
}
|
|
324
437
|
|
|
325
438
|
function anchors(a, b) {
|
|
326
439
|
var ah = nodeHeight(a.model), bh = nodeHeight(b.model);
|
|
327
|
-
var
|
|
328
|
-
var
|
|
440
|
+
var aw = nodeWidth(a.model), bw = nodeWidth(b.model);
|
|
441
|
+
var acx = a.x + aw / 2, acy = a.y + ah / 2;
|
|
442
|
+
var bcx = b.x + bw / 2, bcy = b.y + bh / 2;
|
|
329
443
|
var horizontal = Math.abs(bcx - acx) > Math.abs(bcy - acy);
|
|
330
444
|
|
|
331
445
|
if (horizontal) {
|
|
332
446
|
return bcx > acx
|
|
333
|
-
? { x1: a.x +
|
|
334
|
-
: { x1: a.x, y1: acy, x2: b.x +
|
|
447
|
+
? { x1: a.x + aw, y1: acy, x2: b.x, y2: bcy, h: true }
|
|
448
|
+
: { x1: a.x, y1: acy, x2: b.x + bw, y2: bcy, h: true };
|
|
335
449
|
}
|
|
336
450
|
return bcy > acy
|
|
337
451
|
? { x1: acx, y1: a.y + ah, x2: bcx, y2: b.y, h: false }
|
|
@@ -409,6 +523,10 @@ var ModelGraph = (function () {
|
|
|
409
523
|
|
|
410
524
|
var _search = React.useState('');
|
|
411
525
|
var search = _search[0], setSearch = _search[1];
|
|
526
|
+
var _searchOpen = React.useState(false);
|
|
527
|
+
var searchOpen = _searchOpen[0], setSearchOpen = _searchOpen[1];
|
|
528
|
+
var _highlight = React.useState(0);
|
|
529
|
+
var highlight = _highlight[0], setHighlight = _highlight[1];
|
|
412
530
|
var _focused = React.useState(null);
|
|
413
531
|
var focused = _focused[0], setFocused = _focused[1];
|
|
414
532
|
var _hovered = React.useState(null);
|
|
@@ -439,6 +557,21 @@ var ModelGraph = (function () {
|
|
|
439
557
|
return byModel;
|
|
440
558
|
}, [graph]);
|
|
441
559
|
|
|
560
|
+
// Prefix matches first, then anything containing the term — the ordering a
|
|
561
|
+
// name-completion list is expected to have. Capped so a large schema cannot
|
|
562
|
+
// render a list taller than the window.
|
|
563
|
+
var searchMatches = React.useMemo(function () {
|
|
564
|
+
var all = (graph && graph.models) || [];
|
|
565
|
+
var q = search.trim().toLowerCase();
|
|
566
|
+
if (!q) return all.slice(0, MAX_SEARCH_RESULTS);
|
|
567
|
+
var starts = [], contains = [];
|
|
568
|
+
all.forEach(function (m) {
|
|
569
|
+
var i = m.name.toLowerCase().indexOf(q);
|
|
570
|
+
if (i === 0) starts.push(m); else if (i > 0) contains.push(m);
|
|
571
|
+
});
|
|
572
|
+
return starts.concat(contains).slice(0, MAX_SEARCH_RESULTS);
|
|
573
|
+
}, [graph, search]);
|
|
574
|
+
|
|
442
575
|
var hoverCardRef = React.useRef(null);
|
|
443
576
|
var _modelHover = React.useState(null);
|
|
444
577
|
var modelHover = _modelHover[0], setModelHover = _modelHover[1];
|
|
@@ -535,7 +668,7 @@ var ModelGraph = (function () {
|
|
|
535
668
|
var k = v.k >= 1 ? v.k : Math.min(MAX_ZOOM, v.k + (1 - v.k) / 2);
|
|
536
669
|
return {
|
|
537
670
|
k: k,
|
|
538
|
-
x: rect.width / 2 - (pos.x +
|
|
671
|
+
x: rect.width / 2 - (pos.x + nodeWidth(pos.model) / 2) * k,
|
|
539
672
|
y: rect.height / 2 - (pos.y + h / 2) * k
|
|
540
673
|
};
|
|
541
674
|
});
|
|
@@ -661,6 +794,7 @@ var ModelGraph = (function () {
|
|
|
661
794
|
var fields = (m.columns || []).slice(0, MAX_FIELDS);
|
|
662
795
|
var hidden = (m.columnCount || 0) - fields.length;
|
|
663
796
|
var h = nodeHeight(m);
|
|
797
|
+
var w = nodeWidth(m);
|
|
664
798
|
return React.createElement(
|
|
665
799
|
'g',
|
|
666
800
|
{
|
|
@@ -679,11 +813,14 @@ var ModelGraph = (function () {
|
|
|
679
813
|
centreRef.current(m.name);
|
|
680
814
|
}
|
|
681
815
|
},
|
|
682
|
-
React.createElement('rect', { className: 'mg-box', width:
|
|
683
|
-
React.createElement('rect', { className: 'mg-box-header', width:
|
|
684
|
-
|
|
816
|
+
React.createElement('rect', { className: 'mg-box', width: w, height: h, rx: 4 }),
|
|
817
|
+
React.createElement('rect', { className: 'mg-box-header', width: w, height: HEADER_H, rx: 4 }),
|
|
818
|
+
// Budget stops short of the header button, which sits at w - 26.
|
|
819
|
+
React.createElement('text', { className: 'mg-name', x: 10, y: 15 },
|
|
820
|
+
fitText(m.name, w - 44, FONT_NAME)),
|
|
685
821
|
React.createElement('text', { className: 'mg-table', x: 10, y: 27 },
|
|
686
|
-
(m.table || '—') + (m.columnCount ? ' · ' + m.columnCount + ' cols' : '')
|
|
822
|
+
fitText((m.table || '—') + (m.columnCount ? ' · ' + m.columnCount + ' cols' : ''),
|
|
823
|
+
w - 44, FONT_SMALL)),
|
|
687
824
|
// Opening the full schema is now an explicit target rather than
|
|
688
825
|
// anything-anywhere on the box, so clicking around to navigate
|
|
689
826
|
// cannot keep throwing a modal at you.
|
|
@@ -699,20 +836,25 @@ var ModelGraph = (function () {
|
|
|
699
836
|
},
|
|
700
837
|
React.createElement('title', null, 'Open the full schema for ' + m.name),
|
|
701
838
|
React.createElement('rect', {
|
|
702
|
-
className: 'mg-open-btn-bg', x:
|
|
839
|
+
className: 'mg-open-btn-bg', x: w - 26, y: 7, width: 19, height: 19, rx: 3
|
|
703
840
|
}),
|
|
704
841
|
// Three stacked bars — a table, matching what the button opens.
|
|
705
|
-
React.createElement('rect', { className: 'mg-open-btn-bar', x:
|
|
706
|
-
React.createElement('rect', { className: 'mg-open-btn-bar', x:
|
|
707
|
-
React.createElement('rect', { className: 'mg-open-btn-bar', x:
|
|
842
|
+
React.createElement('rect', { className: 'mg-open-btn-bar', x: w - 22, y: 11, width: 11, height: 2 }),
|
|
843
|
+
React.createElement('rect', { className: 'mg-open-btn-bar', x: w - 22, y: 15.5, width: 11, height: 2 }),
|
|
844
|
+
React.createElement('rect', { className: 'mg-open-btn-bar', x: w - 22, y: 20, width: 11, height: 2 })
|
|
708
845
|
),
|
|
709
846
|
fields.map(function (c, i) {
|
|
710
847
|
var y = HEADER_H + 11 + i * FIELD_H;
|
|
848
|
+
var typeW = Math.min(64, textWidth(String(c.type == null ? '' : c.type), FONT_SMALL));
|
|
711
849
|
return React.createElement(
|
|
712
850
|
React.Fragment,
|
|
713
851
|
{ key: c.name },
|
|
714
|
-
|
|
715
|
-
|
|
852
|
+
// The type is right-aligned, so the name's budget is whatever
|
|
853
|
+
// the type does not claim — otherwise the two met in the middle.
|
|
854
|
+
React.createElement('text', { className: 'mg-field', x: 10, y: y },
|
|
855
|
+
fitText(c.name, w - 28 - typeW, FONT_FIELD)),
|
|
856
|
+
React.createElement('text', { className: 'mg-field-type', x: w - 10, y: y, textAnchor: 'end' },
|
|
857
|
+
fitText(c.type, 64, FONT_SMALL))
|
|
716
858
|
);
|
|
717
859
|
}),
|
|
718
860
|
hidden > 0 && React.createElement('text', {
|
|
@@ -781,34 +923,66 @@ var ModelGraph = (function () {
|
|
|
781
923
|
React.createElement(
|
|
782
924
|
'div',
|
|
783
925
|
{ className: 'ide-model-graph-actions' },
|
|
784
|
-
// A
|
|
785
|
-
//
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
placeholder: 'Centre on a model…',
|
|
791
|
-
value: search,
|
|
792
|
-
onChange: function (e) {
|
|
793
|
-
setSearch(e.target.value);
|
|
794
|
-
// Picking from the datalist fires change with the full name, so
|
|
795
|
-
// an exact hit centres immediately rather than needing Enter.
|
|
796
|
-
if (placed.positions[e.target.value]) centreOn(e.target.value);
|
|
797
|
-
},
|
|
798
|
-
onKeyDown: function (e) {
|
|
799
|
-
if (e.key !== 'Enter') return;
|
|
800
|
-
var match = models.filter(function (m) {
|
|
801
|
-
return m.name.toLowerCase().indexOf(e.target.value.trim().toLowerCase()) === 0;
|
|
802
|
-
})[0];
|
|
803
|
-
if (match) { setSearch(match.name); centreOn(match.name); }
|
|
804
|
-
}
|
|
805
|
-
}),
|
|
926
|
+
// A real dropdown rather than a native <datalist>. The datalist was
|
|
927
|
+
// chosen to get filtering and keyboard handling for free, but the
|
|
928
|
+
// browser renders it as an unstyleable list in the platform's own
|
|
929
|
+
// chrome — wrong font, wrong colours, and no way to show which model
|
|
930
|
+
// is in which cluster. This is a few more lines and looks like the
|
|
931
|
+
// rest of the editor.
|
|
806
932
|
React.createElement(
|
|
807
|
-
'
|
|
808
|
-
{
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
933
|
+
'div',
|
|
934
|
+
{ className: 'mg-search-wrap' },
|
|
935
|
+
React.createElement('input', {
|
|
936
|
+
className: 'ide-model-graph-search',
|
|
937
|
+
type: 'text',
|
|
938
|
+
placeholder: 'Centre on a model…',
|
|
939
|
+
value: search,
|
|
940
|
+
onChange: function (e) { setSearch(e.target.value); setSearchOpen(true); setHighlight(0); },
|
|
941
|
+
onFocus: function () { setSearchOpen(true); },
|
|
942
|
+
// A click on an option would otherwise be lost: blur fires first
|
|
943
|
+
// and unmounts the list before mousedown lands.
|
|
944
|
+
onBlur: function () { window.setTimeout(function () { setSearchOpen(false); }, 120); },
|
|
945
|
+
onKeyDown: function (e) {
|
|
946
|
+
if (e.key === 'ArrowDown' || e.key === 'ArrowUp') {
|
|
947
|
+
e.preventDefault();
|
|
948
|
+
setSearchOpen(true);
|
|
949
|
+
setHighlight(function (h) {
|
|
950
|
+
var next = h + (e.key === 'ArrowDown' ? 1 : -1);
|
|
951
|
+
if (next < 0) return searchMatches.length - 1;
|
|
952
|
+
if (next >= searchMatches.length) return 0;
|
|
953
|
+
return next;
|
|
954
|
+
});
|
|
955
|
+
return;
|
|
956
|
+
}
|
|
957
|
+
if (e.key === 'Escape') { setSearchOpen(false); return; }
|
|
958
|
+
if (e.key !== 'Enter') return;
|
|
959
|
+
var pick = searchMatches[highlight] || searchMatches[0];
|
|
960
|
+
if (pick) { setSearch(pick.name); setSearchOpen(false); centreOn(pick.name); }
|
|
961
|
+
}
|
|
962
|
+
}),
|
|
963
|
+
searchOpen && searchMatches.length > 0 && React.createElement(
|
|
964
|
+
'ul',
|
|
965
|
+
{ className: 'mg-search-list' },
|
|
966
|
+
searchMatches.map(function (m, i) {
|
|
967
|
+
return React.createElement(
|
|
968
|
+
'li',
|
|
969
|
+
{
|
|
970
|
+
key: m.name,
|
|
971
|
+
className: 'mg-search-option' + (i === highlight ? ' mg-search-option-active' : ''),
|
|
972
|
+
onMouseEnter: function () { setHighlight(i); },
|
|
973
|
+
onMouseDown: function (ev) {
|
|
974
|
+
ev.preventDefault(); // keep focus so blur cannot beat us
|
|
975
|
+
setSearch(m.name);
|
|
976
|
+
setSearchOpen(false);
|
|
977
|
+
centreOn(m.name);
|
|
978
|
+
}
|
|
979
|
+
},
|
|
980
|
+
React.createElement('span', { className: 'mg-search-option-name' }, m.name),
|
|
981
|
+
React.createElement('span', { className: 'mg-search-option-meta' },
|
|
982
|
+
(m.table || '') + (m.columnCount ? ' · ' + m.columnCount + ' cols' : ''))
|
|
983
|
+
);
|
|
984
|
+
})
|
|
985
|
+
)
|
|
812
986
|
),
|
|
813
987
|
React.createElement('button', {
|
|
814
988
|
type: 'button', className: 'ide-model-graph-btn', title: 'Fit the whole graph',
|
|
@@ -117,6 +117,14 @@ var FileService = (function () {
|
|
|
117
117
|
return axios.get(window.mbeditorBasePath() + '/ping', { timeout: 4000 }).then(function(res) { return res.data; });
|
|
118
118
|
}
|
|
119
119
|
|
|
120
|
+
// Which routes reach each action in a controller. Returns { controller, actions }
|
|
121
|
+
// with an empty actions map for anything that is not a controller, so the
|
|
122
|
+
// caller does not have to know the naming convention.
|
|
123
|
+
function getRoutes(path) {
|
|
124
|
+
return axios.get(window.mbeditorBasePath() + '/routes?path=' + encodeURIComponent(path))
|
|
125
|
+
.then(function (res) { return res.data; });
|
|
126
|
+
}
|
|
127
|
+
|
|
120
128
|
function getState() {
|
|
121
129
|
return axios.get(window.mbeditorBasePath() + '/state').then(function(res) { return res.data; });
|
|
122
130
|
}
|
|
@@ -336,6 +344,7 @@ var FileService = (function () {
|
|
|
336
344
|
formatFile: formatFile,
|
|
337
345
|
runTests: runTests,
|
|
338
346
|
ping: ping,
|
|
347
|
+
getRoutes: getRoutes,
|
|
339
348
|
getState: getState,
|
|
340
349
|
saveState: saveState,
|
|
341
350
|
getBranchState: getBranchState,
|
|
@@ -61,6 +61,17 @@ html, body, #mbeditor-root {
|
|
|
61
61
|
font-size: 13px;
|
|
62
62
|
color: var(--ide-text);
|
|
63
63
|
font-weight: 500;
|
|
64
|
+
/* Never wrap: the titlebar is a fixed 32px row, so a second line pushed the
|
|
65
|
+
toolbar buttons out of it. */
|
|
66
|
+
white-space: nowrap;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/* Below the width where the toolbar drops its button labels, drop the title
|
|
70
|
+
too. The layers icon beside it already identifies the editor, and the host
|
|
71
|
+
and port are in the browser's own address bar. */
|
|
72
|
+
@media (max-width: 1180px) {
|
|
73
|
+
.ide-titlebar-title { display: none; }
|
|
74
|
+
.ide-titlebar-icon { margin-right: 0; }
|
|
64
75
|
}
|
|
65
76
|
|
|
66
77
|
/* Fills the gap between the title and the button cluster. min-width: 0 lets it
|
|
@@ -3335,3 +3346,52 @@ input.ide-model-graph-search[type="search"] {
|
|
|
3335
3346
|
background-image: none;
|
|
3336
3347
|
padding-inline-start: 8px;
|
|
3337
3348
|
}
|
|
3349
|
+
|
|
3350
|
+
/* Model-graph search dropdown. Replaces a native <datalist>, which the browser
|
|
3351
|
+
renders in its own chrome — unstyleable, and unable to show the table name
|
|
3352
|
+
beside each model. */
|
|
3353
|
+
.mg-search-wrap { position: relative; display: inline-block; }
|
|
3354
|
+
.mg-search-list {
|
|
3355
|
+
position: absolute;
|
|
3356
|
+
top: calc(100% + 4px);
|
|
3357
|
+
right: 0;
|
|
3358
|
+
z-index: 40;
|
|
3359
|
+
min-width: 220px;
|
|
3360
|
+
max-height: 280px;
|
|
3361
|
+
overflow-y: auto;
|
|
3362
|
+
margin: 0;
|
|
3363
|
+
padding: 4px 0;
|
|
3364
|
+
list-style: none;
|
|
3365
|
+
background: var(--ide-panel-bg, #252526);
|
|
3366
|
+
border: 1px solid var(--ide-border, #3c3c3c);
|
|
3367
|
+
border-radius: 6px;
|
|
3368
|
+
box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
|
|
3369
|
+
}
|
|
3370
|
+
.mg-search-option {
|
|
3371
|
+
display: flex;
|
|
3372
|
+
align-items: baseline;
|
|
3373
|
+
justify-content: space-between;
|
|
3374
|
+
gap: 10px;
|
|
3375
|
+
padding: 4px 10px;
|
|
3376
|
+
font-size: 11px;
|
|
3377
|
+
color: var(--ide-text, #d4d4d4);
|
|
3378
|
+
cursor: pointer;
|
|
3379
|
+
white-space: nowrap;
|
|
3380
|
+
}
|
|
3381
|
+
.mg-search-option-active { background: var(--ide-accent, #3794ff); color: #fff; }
|
|
3382
|
+
.mg-search-option-name { font-family: var(--ide-mono, monospace); }
|
|
3383
|
+
.mg-search-option-meta { color: var(--ide-text-muted, #858585); font-size: 10px; }
|
|
3384
|
+
.mg-search-option-active .mg-search-option-meta { color: rgba(255, 255, 255, 0.75); }
|
|
3385
|
+
|
|
3386
|
+
/* Inline route hints beside controller actions. Muted and italic so they read
|
|
3387
|
+
as annotation rather than code — they sit on the same line as the `def`. */
|
|
3388
|
+
.mbeditor-route-hint {
|
|
3389
|
+
color: var(--ide-text-muted, #858585) !important;
|
|
3390
|
+
font-style: italic;
|
|
3391
|
+
opacity: 0.85;
|
|
3392
|
+
}
|
|
3393
|
+
.mbeditor-route-hint-none {
|
|
3394
|
+
color: var(--ide-warning, #cca700) !important;
|
|
3395
|
+
font-style: italic;
|
|
3396
|
+
opacity: 0.8;
|
|
3397
|
+
}
|
|
@@ -1072,6 +1072,19 @@ module Mbeditor
|
|
|
1072
1072
|
}
|
|
1073
1073
|
end
|
|
1074
1074
|
|
|
1075
|
+
# GET /mbeditor/routes?path=app/controllers/users_controller.rb
|
|
1076
|
+
#
|
|
1077
|
+
# Which routes reach each action in a controller, for the inline hints the
|
|
1078
|
+
# editor draws beside every `def`. Returns {} for anything that is not a
|
|
1079
|
+
# controller rather than erroring — the client asks for every Ruby file it
|
|
1080
|
+
# opens and should not have to know the convention.
|
|
1081
|
+
def routes
|
|
1082
|
+
key = RouteService.controller_key(params[:path].to_s)
|
|
1083
|
+
return render json: { controller: nil, actions: {} } unless key
|
|
1084
|
+
|
|
1085
|
+
render json: { controller: key, actions: RouteService.for_controller(key) }
|
|
1086
|
+
end
|
|
1087
|
+
|
|
1075
1088
|
# GET /mbeditor/related_files?path=...
|
|
1076
1089
|
def related_files
|
|
1077
1090
|
path = resolve_path(params[:path])
|
|
@@ -22,7 +22,16 @@ module Mbeditor
|
|
|
22
22
|
SolidQueue SolidCache SolidCable
|
|
23
23
|
].freeze
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
# Cap on models drawn. 300 was chosen before the layout could handle that
|
|
26
|
+
# many; a schema slightly over it silently lost models and only said
|
|
27
|
+
# "(truncated)". Raised, and configurable for anything larger — the cost of
|
|
28
|
+
# a bigger graph is now the browser's rendering, not the layout.
|
|
29
|
+
DEFAULT_MAX_MODELS = 1000
|
|
30
|
+
|
|
31
|
+
def self.max_models
|
|
32
|
+
value = Mbeditor.configuration.model_graph_max_models.to_i
|
|
33
|
+
value.positive? ? value : DEFAULT_MAX_MODELS
|
|
34
|
+
end
|
|
26
35
|
|
|
27
36
|
# Only the first few columns travel: the diagram box shows that many and the
|
|
28
37
|
# full list is a click away in the schema modal, which fetches its own data
|
|
@@ -86,7 +95,8 @@ module Mbeditor
|
|
|
86
95
|
classes = model_classes
|
|
87
96
|
return unavailable("No ActiveRecord models found in this application.") if classes.empty?
|
|
88
97
|
|
|
89
|
-
|
|
98
|
+
limit = max_models
|
|
99
|
+
models = classes.first(limit).map { |klass| describe_model(klass, root) }
|
|
90
100
|
known = models.map { |m| m[:name] }.to_set
|
|
91
101
|
|
|
92
102
|
{
|
|
@@ -95,7 +105,7 @@ module Mbeditor
|
|
|
95
105
|
# Edges to classes outside the graph (a gem's model, or a typo in
|
|
96
106
|
# class_name:) would render as arrows into nowhere.
|
|
97
107
|
edges: models.flat_map { |m| m.delete(:edges) }.select { |e| known.include?(e[:to]) }.uniq,
|
|
98
|
-
truncated: classes.length >
|
|
108
|
+
truncated: classes.length > limit,
|
|
99
109
|
generatedAt: Time.now.utc.iso8601
|
|
100
110
|
}
|
|
101
111
|
rescue StandardError => e
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Mbeditor
|
|
4
|
+
# Which routes reach a controller's actions, for the inline hints shown beside
|
|
5
|
+
# each `def` in a controller file.
|
|
6
|
+
#
|
|
7
|
+
# Read from the host app's own route set rather than by parsing config/routes.rb.
|
|
8
|
+
# mbeditor runs inside the host app, so the routes are already built — and they
|
|
9
|
+
# are the only source that accounts for `resources` expansion, `member`/
|
|
10
|
+
# `collection` blocks, scopes, constraints, mounted engines and anything a
|
|
11
|
+
# routes file does in plain Ruby. Parsing the file would get all of that wrong.
|
|
12
|
+
module RouteService
|
|
13
|
+
module_function
|
|
14
|
+
|
|
15
|
+
# Actions with no route are worth calling out, but only for controllers Rails
|
|
16
|
+
# would actually dispatch to. These are the inherited ones every controller
|
|
17
|
+
# has and nobody routes.
|
|
18
|
+
NON_ACTION_METHODS = %w[
|
|
19
|
+
new inspect method_of to_s hash class dup freeze
|
|
20
|
+
].freeze
|
|
21
|
+
|
|
22
|
+
# "app/controllers/admin/users_controller.rb" -> "admin/users", which is the
|
|
23
|
+
# key Rails stores in a route's defaults.
|
|
24
|
+
def controller_key(relative_path)
|
|
25
|
+
path = relative_path.to_s.sub(%r{\A/+}, "")
|
|
26
|
+
match = path.match(%r{\Aapp/controllers/(.+)_controller\.rb\z})
|
|
27
|
+
return nil unless match
|
|
28
|
+
|
|
29
|
+
match[1]
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# => { "show" => [{ verb:, path:, name: }], ... }
|
|
33
|
+
def for_controller(key)
|
|
34
|
+
return {} if key.nil? || key.empty?
|
|
35
|
+
return {} unless defined?(Rails) && Rails.respond_to?(:application) && Rails.application
|
|
36
|
+
|
|
37
|
+
routes_for(key)
|
|
38
|
+
rescue StandardError
|
|
39
|
+
# A broken route set must not take the editor down with it — the file still
|
|
40
|
+
# opens, just without hints.
|
|
41
|
+
{}
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def routes_for(key)
|
|
45
|
+
out = {}
|
|
46
|
+
Rails.application.routes.routes.each do |route|
|
|
47
|
+
defaults = route.defaults
|
|
48
|
+
next unless defaults[:controller] == key
|
|
49
|
+
|
|
50
|
+
action = defaults[:action].to_s
|
|
51
|
+
next if action.empty?
|
|
52
|
+
|
|
53
|
+
(out[action] ||= []) << {
|
|
54
|
+
verb: verb_for(route),
|
|
55
|
+
path: path_for(route),
|
|
56
|
+
name: route.name
|
|
57
|
+
}
|
|
58
|
+
end
|
|
59
|
+
out
|
|
60
|
+
end
|
|
61
|
+
private_class_method :routes_for
|
|
62
|
+
|
|
63
|
+
# Rails has moved this between a String and a Regexp across versions; both
|
|
64
|
+
# stringify usefully, but a Regexp needs its slashes stripped.
|
|
65
|
+
def verb_for(route)
|
|
66
|
+
verb = route.verb
|
|
67
|
+
verb = verb.source.gsub(%r{[$^]}, "") if verb.is_a?(Regexp)
|
|
68
|
+
verb = verb.to_s
|
|
69
|
+
verb.empty? ? "ANY" : verb
|
|
70
|
+
end
|
|
71
|
+
private_class_method :verb_for
|
|
72
|
+
|
|
73
|
+
# "(.:format)" is noise in a hint that has to fit on one line.
|
|
74
|
+
def path_for(route)
|
|
75
|
+
route.path.spec.to_s.sub(/\(\.:format\)\z/, "")
|
|
76
|
+
end
|
|
77
|
+
private_class_method :path_for
|
|
78
|
+
end
|
|
79
|
+
end
|
|
@@ -12,7 +12,7 @@ module Mbeditor
|
|
|
12
12
|
:js_program, :js_program_exclude,
|
|
13
13
|
:js_syntax_check, :babel_standalone_path,
|
|
14
14
|
:ruby_lsp, :ruby_lsp_command, :ruby_lsp_timeout,
|
|
15
|
-
:exception_capture,
|
|
15
|
+
:exception_capture, :model_graph_max_models,
|
|
16
16
|
:search_respect_gitignore, :ripgrep_command
|
|
17
17
|
|
|
18
18
|
def initialize
|
|
@@ -84,6 +84,9 @@ module Mbeditor
|
|
|
84
84
|
# same exposure the log panel already has, since it tails the dev log.
|
|
85
85
|
# Set to false to record nothing.
|
|
86
86
|
@exception_capture = :auto
|
|
87
|
+
# Models drawn in the model graph before it reports itself truncated.
|
|
88
|
+
# nil uses ModelGraphService::DEFAULT_MAX_MODELS.
|
|
89
|
+
@model_graph_max_models = nil
|
|
87
90
|
@mount_path = nil # explicit URL prefix override; nil falls through to detection/"/mbeditor"
|
|
88
91
|
@resilient_routing = true # serve /mbeditor from middleware so the editor survives a broken host routes.rb; false is the escape hatch
|
|
89
92
|
end
|
data/lib/mbeditor/engine.rb
CHANGED
|
@@ -54,9 +54,23 @@ module Mbeditor
|
|
|
54
54
|
# Insert before CheckPending so our middleware wraps it and can rescue
|
|
55
55
|
# the error it raises. Falls back silently if CheckPending is absent
|
|
56
56
|
# (e.g. host app does not use ActiveRecord).
|
|
57
|
-
#
|
|
58
|
-
#
|
|
59
|
-
|
|
57
|
+
#
|
|
58
|
+
# The constant being defined is not enough: Rails only puts CheckPending
|
|
59
|
+
# in the stack when config.active_record.migration_error is :page_load, so
|
|
60
|
+
# an app that loads ActiveRecord with any other setting has the constant
|
|
61
|
+
# but no middleware — and insert_before then raises "No such middleware",
|
|
62
|
+
# taking the host app's boot down with it. app.middleware is a
|
|
63
|
+
# MiddlewareStackProxy here and cannot be inspected, so the only way to
|
|
64
|
+
# know is to try it. Losing this middleware costs a friendlier pending-
|
|
65
|
+
# migration page, which is never worth failing to boot over.
|
|
66
|
+
# Rescuing the call is not an option: app.middleware is a
|
|
67
|
+
# MiddlewareStackProxy, so insert_before only records the operation and the
|
|
68
|
+
# "No such middleware" error surfaces later, during merge_into. Test the
|
|
69
|
+
# same condition Rails uses to add CheckPending in the first place.
|
|
70
|
+
migration_error = app.config.respond_to?(:active_record) &&
|
|
71
|
+
app.config.active_record[:migration_error]
|
|
72
|
+
|
|
73
|
+
if defined?(ActiveRecord::Migration::CheckPending) && migration_error == :page_load
|
|
60
74
|
app.middleware.insert_before ActiveRecord::Migration::CheckPending,
|
|
61
75
|
Mbeditor::Rack::HandlePendingMigrations
|
|
62
76
|
end
|
data/lib/mbeditor/route_map.rb
CHANGED
|
@@ -44,6 +44,7 @@ module Mbeditor
|
|
|
44
44
|
get 'client_config', to: 'editors#client_config'
|
|
45
45
|
get 'related_files', to: 'editors#related_files'
|
|
46
46
|
get 'model_schema', to: 'editors#model_schema'
|
|
47
|
+
get 'routes', to: 'editors#routes'
|
|
47
48
|
get 'changelog', to: 'editors#changelog'
|
|
48
49
|
get 'git_info', to: 'editors#git_info'
|
|
49
50
|
get 'git_status', to: 'editors#git_status'
|
data/lib/mbeditor/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: mbeditor
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.12.
|
|
4
|
+
version: 0.12.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Oliver Noonan
|
|
@@ -133,6 +133,7 @@ files:
|
|
|
133
133
|
- app/services/mbeditor/rails_related_files_service.rb
|
|
134
134
|
- app/services/mbeditor/redmine_service.rb
|
|
135
135
|
- app/services/mbeditor/ri_definition_service.rb
|
|
136
|
+
- app/services/mbeditor/route_service.rb
|
|
136
137
|
- app/services/mbeditor/ruby_definition_service.rb
|
|
137
138
|
- app/services/mbeditor/safe_path.rb
|
|
138
139
|
- app/services/mbeditor/schema_service.rb
|