Skip to content

Commit

Permalink
feat: add link as absolute URL without protocol and domain
Browse files Browse the repository at this point in the history
Closes #2
  • Loading branch information
Steffen Giers committed Jan 24, 2020
1 parent 59125f1 commit 4728e95
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 12 deletions.
2 changes: 1 addition & 1 deletion index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 33 additions & 5 deletions index.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,50 @@
<?php

use Kirby\Http\Url;

Kirby::plugin('gearsdigital/enhanced-toolbar-link-dialog', [
'api' => [
'routes' => [
'models' => [
// a camelCased model name results in Kirby\Exception\NotFoundException
'simplepagemodel' => [
'type' => 'Kirby\Cms\Page',
'fields' => [
'id' => function ($page) {
return $page->id();
},
'title' => function ($page) {
return $page->title()->value();
},
'slug' => function ($page) {
return URL::makeAbsolute($page->slug());
},
],
],
],
'collections' => [
'simplepagecollection' => [
'model' => 'simplepagemodel',
'type' => 'Kirby\Toolkit\Collection',
],
],
'routes' => [
[
'pattern' => 'enhanced-toolbar-link-dialog/pages',
'method' => 'get',
'action' => function () {
$page = get('page');
$query = get('search', '*');
$query = get('search');

if (empty($query)) {
$query = '*';
}

return site()->search($query, 'title')->paginate([
$pagedCollection = site()->search($query, 'title')->paginate([
'page' => $page,
'limit' => 10,
]);

return $this->collection('simplepagecollection', $pagedCollection);
},
],
],
Expand All @@ -25,12 +53,12 @@
'en' => [
'gearsdigital.enhanced-toolbar-link-dialog.internal' => 'Internal Link',
'gearsdigital.enhanced-toolbar-link-dialog.external' => 'External Link',
'gearsdigital.enhanced-toolbar-link-dialog.empty' => 'No pages found',
'gearsdigital.enhanced-toolbar-link-dialog.empty' => 'No pages found',
],
'de' => [
'gearsdigital.enhanced-toolbar-link-dialog.internal' => 'Interner Link',
'gearsdigital.enhanced-toolbar-link-dialog.external' => 'Externer Link',
'gearsdigital.enhanced-toolbar-link-dialog.empty' => 'Keine Seiten gefunden.',
'gearsdigital.enhanced-toolbar-link-dialog.empty' => 'Keine Seiten gefunden.',
],
],
]);
12 changes: 6 additions & 6 deletions src/components/EnhancedToolbarLinkDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
search: null,
currentPage: {},
currentTab: {},
pages:[],
pages: [],
value: {
url: null,
text: null
Expand Down Expand Up @@ -130,7 +130,7 @@
}, 200)
},
computed: {
hasPages(){
hasPages() {
return this.pages.length
},
kirbytext() {
Expand All @@ -157,7 +157,7 @@
},
selectPage(model) {
this.value = {
url: model.url,
url: model.slug,
text: this.value.text || model.title
};
if (this.isCurrentPage(model)) {
Expand Down Expand Up @@ -197,9 +197,9 @@
search: this.search
};
this.$api.get('enhanced-toolbar-link-dialog/pages', params).then(response => {
this.pages = response.data;
this.pagination = response.pagination;
});
this.pages = response.data;
this.pagination = response.pagination;
});
},
submit() {
this.$emit("submit", this.kirbytext ? this.createKirbytext() : this.createMarkdown());
Expand Down

0 comments on commit 4728e95

Please sign in to comment.