Skip to content

Commit

Permalink
Merge pull request #33 from hananils/master
Browse files Browse the repository at this point in the history
Enable inline previews + Kirby 3.7 compatibility
  • Loading branch information
medienbaecker authored Jun 27, 2022
2 parents 3efd5d9 + 095a878 commit 8f75b50
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 70 deletions.
73 changes: 43 additions & 30 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,44 @@
panel.plugin('medienbaecker/modules', {
components: {
'k-modules-section': {
extends: 'k-pages-section',
created: function () {
if (this.parent == 'site') return;
this.$api.post(this.parent + '/modules')
.then((data) => {
if (data.created) {
this.reload();
}
});
},
updated: function () {
this.$nextTick(function () {
this.$el.classList.add('k-modules-section');
})
}
},
},
fields: {
modules_redirect: {
props: {
redirect: String
},
render: function() {
window.location.href = this.redirect;
}
}
}
});
components: {
'k-modules-section': {
extends: 'k-pages-section',
created: function () {
if (this.parent == 'site') return;
this.$api.post(this.parent + '/modules').then((data) => {
if (data.created) {
this.reload();
}
});
},
computed: {
type() {
return 'modules';
}
},
methods: {
onAdd() {
if (this.canAdd) {
this.$dialog('pages/create', {
query: {
parent: this.options.link || this.parent,
view: this.parent,
section: this.name,
modules: this.options.layout
}
});
}
}
}
}
},
fields: {
modules_redirect: {
props: {
redirect: String
},
render: function () {
window.location.href = this.redirect;
}
}
}
});
27 changes: 16 additions & 11 deletions lib/fields/redirect.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
<?php

return [
'computed' => [
'redirect' => function () {
if($this->model()->isHomePage()) {
return $this->model()->site()->panelUrl();
}
else {
return $this->model()->parent()->panelUrl();
}
}
]
];
'computed' => [
'redirect' => function () {
if ($this->model()->isHomePage()) {
return $this->model()
->site()
->panel()
->url();
} else {
return $this->model()
->parent()
->panel()
->url();
}
}
]
];
10 changes: 9 additions & 1 deletion lib/models.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ public function moduleName() {
public function moduleId() {
return str_replace('.', '__', $this->intendedTemplate());
}
public function parents(){
$parents = parent::parents();
return $parents->filter('slug', '!=', 'modules');
}
}

class ModulesPage extends Page {
Expand All @@ -38,4 +42,8 @@ public function url($options = null): string {
public function render(array $data = [], $contentType = 'html'): string {
go($this->parent()->url());
}
}
public function parents(){
$parents = parent::parents();
return $parents->filter('slug', '!=', 'modules');
}
}
60 changes: 32 additions & 28 deletions lib/sections/modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,46 @@

$blueprints = [];
foreach ($moduleRegistry['blueprints'] as $blueprint => $file) {
if(Str::startsWith($blueprint, 'pages/module.')) {
if (Str::startsWith($blueprint, 'pages/module.')) {
$blueprints[] = str_replace('pages/', '', $blueprint);
}
}
}
$default = array_search('module.' . option('medienbaecker.modules.default', 'text'), $blueprints);
if($default !== false) {
$module_text = $blueprints[$default];
unset($blueprints[$default]);
array_unshift($blueprints, $module_text);
if ($default !== false) {
$module_text = $blueprints[$default];
unset($blueprints[$default]);
array_unshift($blueprints, $module_text);
}

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

if (is_string($base)) {
$base = include $base;
$base = include $base;
}

return array_replace_recursive($base, [
'props' => [
'create' => function ($create = null) use ($blueprints) {
return $create ?? $blueprints;
},
'empty' => function ($empty = null) {
return $empty ?? I18n::translate('modules.empty');
},
'headline' => function ($headline = null) {
return $headline ?? I18n::translate('modules');
},
'info' => function(string $info = '{{ page.moduleName }}') {
return $info;
},
'image' => false,
'parent' => function($parent = null) {
return $this->model()->find('modules')
? 'page.find("modules")'
: $parent;
}
]
]);
'props' => [
'create' => function ($create = null) use ($blueprints) {
return $create ?? $blueprints;
},
'empty' => function ($empty = null) {
return $empty ?? I18n::translate('modules.empty');
},
'headline' => function ($headline = null) {
return $headline ?? I18n::translate('modules');
},
'info' => function (string $info = '{{ page.moduleName }}') {
return $info;
},
'image' => false,
'parent' => function ($parent = null) {
return $this->model()->find('modules')
? 'page.find("modules")'
: $parent;
},
'layout' => function (string $layout = 'list') {
$layouts = ['list', 'cardlets', 'cards', 'table', 'module'];
return in_array($layout, $layouts) ? $layout : 'list';
}
]
]);

0 comments on commit 8f75b50

Please sign in to comment.