Skip to content

Commit 3f40a8c

Browse files
committed
✨ support for query language in view buttons built with janitor
Signed-off-by: Bruno Meilick <[email protected]>
1 parent 77dc16e commit 3f40a8c

File tree

11 files changed

+107
-19
lines changed

11 files changed

+107
-19
lines changed

classes/Janitor.php

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,10 +240,29 @@ public static function resolveQueriesInCommand(array $args): array
240240
$model = Janitor::resolveModel($model);
241241
}
242242

243-
if (! $model && $path = get('path')) {
243+
if (! $modelKey && ! $model && $path = get('path')) {
244244
// infer model (page or page draft) from current panel path
245-
$id = trim(str_replace(['panel/pages', '+'], ['', '/'], $path), '/');
246-
$model = kirby()->page($id);
245+
if (Str::contains($path, 'panel/site')) {
246+
$model = kirby()->site();
247+
} elseif (Str::contains($path, 'panel/pages')) {
248+
$id = trim(str_replace(['panel/pages', '+'], ['', '/'], $path), '/');
249+
$model = kirby()->page($id);
250+
$args[] = '--page';
251+
$args[] = $model->uuid()?->toString() ?? $model->id();
252+
} elseif (Str::contains($path, 'panel/users')) {
253+
$id = trim(str_replace(['panel/users', '+'], ['', '/'], $path), '/');
254+
$model = kirby()->user($id);
255+
$args[] = '--user';
256+
$args[] = $model->uuid()?->toString() ?? $model->id();
257+
} elseif (Str::contains($path, 'panel/account')) {
258+
// $id = trim(str_replace(['panel/account', '+'], ['', '/'], $path), '/');
259+
$model = kirby()->user();
260+
$args[] = '--user';
261+
$args[] = $model->uuid()?->toString() ?? $model->id();
262+
}
263+
264+
$args[] = '--model';
265+
$args[] = $model->uuid()?->toString() ?? $model->id();
247266
}
248267

249268
$args = array_map(function ($value) use ($model) {

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "bnomei/kirby-janitor",
33
"type": "kirby-plugin",
4-
"version": "5.4.0",
4+
"version": "5.4.1",
55
"license": "MIT",
66
"homepage": "https://github.com/bnomei/kirby-janitor",
77
"description": "Kirby Plugin for running commands like cleaning the cache from within the Panel, PHP code or a cronjob",

composer.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
'janitor:backupzip' => require __DIR__.'/commands/backupzip.php',
3030
'janitor:call' => require __DIR__.'/commands/call.php',
3131
'janitor:cleancontent' => require __DIR__.'/commands/cleancontent.php',
32+
'janitor:clear' => require __DIR__.'/commands/flush.php', // alias for flush
3233
'janitor:clipboard' => require __DIR__.'/commands/clipboard.php',
3334
'janitor:download' => require __DIR__.'/commands/download.php',
3435
'janitor:flush' => require __DIR__.'/commands/flush.php',

tests/content/demo/demo.en.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Title: Demo
2+
3+
----
4+
5+
Uuid: cflemndqqesgfg2z

tests/site/blueprints/pages/default.yml

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,12 @@ preset: page
33

44
buttons:
55
janitor:
6-
command: whistle
7-
label: Whistle
8-
icon: audio
9-
janitor_2:
10-
command: ping
11-
label: Ping
12-
progress: ....
13-
success: Pong
14-
error: BAMM
6+
component: k-janitor-view-button
7+
props:
8+
command: whistle
9+
label: Whistle
10+
icon: audio
11+
open: true
1512
preview: true
1613
settings: true
1714

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
title: Demo
2+
3+
buttons:
4+
janitor:
5+
type: janitor
6+
command: 'notify'
7+
label: Show UUID as notification
8+
icon: bell
9+
open: true
10+
preview: true
11+
settings: true
12+
13+
fields:
14+
15+
info:
16+
type: info
17+
text: "Janitor has many of options and built in commands.<br>It can be used to create **view buttons** and like a **field**."
18+
19+
janitor_color:
20+
label: Define custom initial and status colors
21+
type: janitor
22+
command: 'janitor:job --key random.colors'
23+
icon: wand
24+
color: 'var(--color-purple-800)'
25+
backgroundColor: 'var(--color-purple-400)'
26+
27+
janitor_run:
28+
type: janitor
29+
command: 'janitor:out --msg "Email was sent to <{{ user.name }}>. '
30+
label: 'Run any PHP code, like clearing the "Pages Cache" or "Send email"'
31+
icon: email
32+
33+
janitor_open:
34+
type: janitor
35+
command: 'janitor:open --data {{ user.panel.url }}'
36+
label: Goto current user in Panel
37+
icon: user

tests/site/blueprints/site.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
buttons:
2+
janitor:
3+
type: janitor
4+
command: 'notify'
5+
label: Panel notification (success/error)
6+
icon: bell
7+
open: true
8+
preview: true
9+
languages: true
10+
111
sections:
212
pages:
313
type: pages

tests/site/blueprints/users/admin.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
buttons:
2+
janitor:
3+
component: k-janitor-view-button
4+
props:
5+
type: janitor
6+
command: 'notify'
7+
label: Show UUID as notification
8+
icon: bell
9+
janitor_2:
10+
component: k-janitor-view-button
11+
props:
12+
command: ping
13+
label: Ping
14+
progress: ...
15+
success: Pong
16+
error: BAMM
17+
icon: circle
18+
settings: true
19+
120
fields:
221
test_uuid:
322
type: janitor

tests/site/commands/notify.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
'status' => 200,
1212
'notification' => [
1313
rand(0, 1) ? 'success' : 'error',
14-
page($cli->arg('page'))->uuid()->toString(),
14+
$cli->arg('model'),
1515
],
1616
]);
1717
},

0 commit comments

Comments
 (0)