From e18d69916eae55a46764c4c1bdba3706c2f4bf0f Mon Sep 17 00:00:00 2001 From: Roman Steiner Date: Mon, 28 Mar 2022 17:45:49 +0200 Subject: [PATCH 1/2] add "controls" option --- index.js | 33 ++++++++++++++++++++++++++++----- readme.md | 24 ++++++++++++++++++++++++ src/PagesDisplaySection.php | 10 +++++++++- 3 files changed, 61 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 895539a..8f162e3 100644 --- a/index.js +++ b/index.js @@ -1,7 +1,30 @@ panel.plugin("rasteiner/k3-pagesdisplay-section", { - components: { - "k-pagesdisplay-section": { - extends: "k-pages-section", - }, - }, + use: [(Vue) => { + const o = Vue.component("k-pages-section").options; + Vue.component("k-pagesdisplay-section", { + extends: o, + props: { + controls: { + type: [Boolean, String], + default: true, + }, + }, + methods: { + items(data) { + if(this.controls === false) return data; + + data = o.methods.items.call(this, data); + + if(this.controls === "flag") { + for(const item of data) { + delete item.flag.click + delete item.options + } + } + + return data; + }, + }, + }); + }], }); diff --git a/readme.md b/readme.md index cd30cfe..d8a0bf5 100644 --- a/readme.md +++ b/readme.md @@ -54,3 +54,27 @@ sections: type: pagesdisplay query: page.siblings(false) ``` + +### Disable Controls + +In addition to leaving the controls (the status flag and the options dropdown) visible - the default, it's possible to either hide them completely or show only the status flag. + +To completely hide the controls: +```yaml +sections: + mysection: + headline: Siblings + type: pagesdisplay + query: page.siblings(false) + controls: false +``` + +To show only the status flag: +```yaml +sections: + mysection: + headline: Siblings + type: pagesdisplay + query: page.siblings(false) + controls: flag +``` diff --git a/src/PagesDisplaySection.php b/src/PagesDisplaySection.php index 3fb8926..efbd7a3 100755 --- a/src/PagesDisplaySection.php +++ b/src/PagesDisplaySection.php @@ -17,7 +17,15 @@ }, 'query' => function (string $query = 'page.children') { return $query; - } + }, + 'controls' => function ($controls = true) { + if(is_bool($controls)) { + return $controls; + } + if($controls !== 'flag') { + throw new InvalidArgumentException('Invalid value for "controls" option. It must be either true, false or "flag"'); + } + }, ], 'computed' => [ 'pages' => function () { From ce9528cf8d5d5d01a121790e09a9a85e0dba1d33 Mon Sep 17 00:00:00 2001 From: Roman Steiner Date: Mon, 28 Mar 2022 17:54:56 +0200 Subject: [PATCH 2/2] refactor guard statement --- src/PagesDisplaySection.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/PagesDisplaySection.php b/src/PagesDisplaySection.php index efbd7a3..46e765c 100755 --- a/src/PagesDisplaySection.php +++ b/src/PagesDisplaySection.php @@ -19,12 +19,11 @@ return $query; }, 'controls' => function ($controls = true) { - if(is_bool($controls)) { - return $controls; - } - if($controls !== 'flag') { + if(!is_bool($controls) && $controls !== 'flag') { throw new InvalidArgumentException('Invalid value for "controls" option. It must be either true, false or "flag"'); } + + return $controls; }, ], 'computed' => [