Skip to content

Commit 8f75b50

Browse files
Merge pull request #33 from hananils/master
Enable inline previews + Kirby 3.7 compatibility
2 parents 3efd5d9 + 095a878 commit 8f75b50

File tree

4 files changed

+100
-70
lines changed

4 files changed

+100
-70
lines changed

index.js

Lines changed: 43 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,44 @@
11
panel.plugin('medienbaecker/modules', {
2-
components: {
3-
'k-modules-section': {
4-
extends: 'k-pages-section',
5-
created: function () {
6-
if (this.parent == 'site') return;
7-
this.$api.post(this.parent + '/modules')
8-
.then((data) => {
9-
if (data.created) {
10-
this.reload();
11-
}
12-
});
13-
},
14-
updated: function () {
15-
this.$nextTick(function () {
16-
this.$el.classList.add('k-modules-section');
17-
})
18-
}
19-
},
20-
},
21-
fields: {
22-
modules_redirect: {
23-
props: {
24-
redirect: String
25-
},
26-
render: function() {
27-
window.location.href = this.redirect;
28-
}
29-
}
30-
}
31-
});
2+
components: {
3+
'k-modules-section': {
4+
extends: 'k-pages-section',
5+
created: function () {
6+
if (this.parent == 'site') return;
7+
this.$api.post(this.parent + '/modules').then((data) => {
8+
if (data.created) {
9+
this.reload();
10+
}
11+
});
12+
},
13+
computed: {
14+
type() {
15+
return 'modules';
16+
}
17+
},
18+
methods: {
19+
onAdd() {
20+
if (this.canAdd) {
21+
this.$dialog('pages/create', {
22+
query: {
23+
parent: this.options.link || this.parent,
24+
view: this.parent,
25+
section: this.name,
26+
modules: this.options.layout
27+
}
28+
});
29+
}
30+
}
31+
}
32+
}
33+
},
34+
fields: {
35+
modules_redirect: {
36+
props: {
37+
redirect: String
38+
},
39+
render: function () {
40+
window.location.href = this.redirect;
41+
}
42+
}
43+
}
44+
});

lib/fields/redirect.php

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
<?php
22

33
return [
4-
'computed' => [
5-
'redirect' => function () {
6-
if($this->model()->isHomePage()) {
7-
return $this->model()->site()->panelUrl();
8-
}
9-
else {
10-
return $this->model()->parent()->panelUrl();
11-
}
12-
}
13-
]
14-
];
4+
'computed' => [
5+
'redirect' => function () {
6+
if ($this->model()->isHomePage()) {
7+
return $this->model()
8+
->site()
9+
->panel()
10+
->url();
11+
} else {
12+
return $this->model()
13+
->parent()
14+
->panel()
15+
->url();
16+
}
17+
}
18+
]
19+
];

lib/models.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ public function moduleName() {
2929
public function moduleId() {
3030
return str_replace('.', '__', $this->intendedTemplate());
3131
}
32+
public function parents(){
33+
$parents = parent::parents();
34+
return $parents->filter('slug', '!=', 'modules');
35+
}
3236
}
3337

3438
class ModulesPage extends Page {
@@ -38,4 +42,8 @@ public function url($options = null): string {
3842
public function render(array $data = [], $contentType = 'html'): string {
3943
go($this->parent()->url());
4044
}
41-
}
45+
public function parents(){
46+
$parents = parent::parents();
47+
return $parents->filter('slug', '!=', 'modules');
48+
}
49+
}

lib/sections/modules.php

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,42 +4,46 @@
44

55
$blueprints = [];
66
foreach ($moduleRegistry['blueprints'] as $blueprint => $file) {
7-
if(Str::startsWith($blueprint, 'pages/module.')) {
7+
if (Str::startsWith($blueprint, 'pages/module.')) {
88
$blueprints[] = str_replace('pages/', '', $blueprint);
9-
}
9+
}
1010
}
1111
$default = array_search('module.' . option('medienbaecker.modules.default', 'text'), $blueprints);
12-
if($default !== false) {
13-
$module_text = $blueprints[$default];
14-
unset($blueprints[$default]);
15-
array_unshift($blueprints, $module_text);
12+
if ($default !== false) {
13+
$module_text = $blueprints[$default];
14+
unset($blueprints[$default]);
15+
array_unshift($blueprints, $module_text);
1616
}
1717

1818
$base = Section::$types['pages'];
1919

2020
if (is_string($base)) {
21-
$base = include $base;
21+
$base = include $base;
2222
}
2323

2424
return array_replace_recursive($base, [
25-
'props' => [
26-
'create' => function ($create = null) use ($blueprints) {
27-
return $create ?? $blueprints;
28-
},
29-
'empty' => function ($empty = null) {
30-
return $empty ?? I18n::translate('modules.empty');
31-
},
32-
'headline' => function ($headline = null) {
33-
return $headline ?? I18n::translate('modules');
34-
},
35-
'info' => function(string $info = '{{ page.moduleName }}') {
36-
return $info;
37-
},
38-
'image' => false,
39-
'parent' => function($parent = null) {
40-
return $this->model()->find('modules')
41-
? 'page.find("modules")'
42-
: $parent;
43-
}
44-
]
45-
]);
25+
'props' => [
26+
'create' => function ($create = null) use ($blueprints) {
27+
return $create ?? $blueprints;
28+
},
29+
'empty' => function ($empty = null) {
30+
return $empty ?? I18n::translate('modules.empty');
31+
},
32+
'headline' => function ($headline = null) {
33+
return $headline ?? I18n::translate('modules');
34+
},
35+
'info' => function (string $info = '{{ page.moduleName }}') {
36+
return $info;
37+
},
38+
'image' => false,
39+
'parent' => function ($parent = null) {
40+
return $this->model()->find('modules')
41+
? 'page.find("modules")'
42+
: $parent;
43+
},
44+
'layout' => function (string $layout = 'list') {
45+
$layouts = ['list', 'cardlets', 'cards', 'table', 'module'];
46+
return in_array($layout, $layouts) ? $layout : 'list';
47+
}
48+
]
49+
]);

0 commit comments

Comments
 (0)