diff --git a/kanga.world/site/plugins/kangaworld-integration/areas.php b/kanga.world/site/plugins/kangaworld-integration/areas.php index 7d08651..d474bf3 100644 --- a/kanga.world/site/plugins/kangaworld-integration/areas.php +++ b/kanga.world/site/plugins/kangaworld-integration/areas.php @@ -1,8 +1,6 @@ __DIR__ . '/classes/KwConfig.php']); return [ @@ -13,20 +11,22 @@ return [ 'menu' => true, // update and delete dialogs 'dialogs' => [ - //require __DIR__ . '/dialogs/update.php', - //require __DIR__ . '/dialogs/delete.php' + require __DIR__ . '/dialogs/create.php', + require __DIR__ . '/dialogs/update.php', + require __DIR__ . '/dialogs/delete.php' ], // dropdown with edit and delete buttons 'dropdowns' => [ - //require __DIR__ . '/dropdowns/kwconfig.php' + require __DIR__ . '/dropdowns/kwconfig.php' ], // search for settings 'searches' => [ - //'products' => require __DIR__ . '/searches/kwconfig.php' + 'kwconfig' => require __DIR__ . '/searches/kwconfig.php' ], // view route 'views' => [ - require __DIR__ . '/views/kwconfig.php' + require __DIR__ . '/views/kwconfig.php', + require __DIR__ . '/views/kwentry.php' ] ] diff --git a/kanga.world/site/plugins/kangaworld-integration/classes/KwConfig.php b/kanga.world/site/plugins/kangaworld-integration/classes/KwConfig.php new file mode 100644 index 0000000..fc3885d --- /dev/null +++ b/kanga.world/site/plugins/kangaworld-integration/classes/KwConfig.php @@ -0,0 +1,142 @@ + $input['title'] ?? null, + 'type' => $input['type'] ?? null, + 'description' => $input['description'] ?? null, + 'data' => $input['data'] ?? null + ]; + + // require a title + if (V::minlength($kwconfig['title'], 1) === false) { + throw new InvalidArgumentException('The title must not be empty'); + } + + // make sure the title is not longer than expected + if (V::maxlength($kwconfig['title'], 255) === false) { + throw new InvalidArgumentException('The title must not be longer than 255 characters'); + } + + // validate the category + if (V::in($kwconfig['type'], static::types()) === false) { + throw new InvalidArgumentException('Please select a valid category'); + } + + // load all products + $kwconfig = static::list(); + + // set/overwrite the data + $kwconfig[$id] = $kwconfig; + + return Data::write(static::file(), $kwconfig); + } + +} + +?> diff --git a/kanga.world/site/plugins/kangaworld-integration/dialogs/create.php b/kanga.world/site/plugins/kangaworld-integration/dialogs/create.php new file mode 100644 index 0000000..b7fbac7 --- /dev/null +++ b/kanga.world/site/plugins/kangaworld-integration/dialogs/create.php @@ -0,0 +1,22 @@ + 'kwconfig/create', + 'load' => function () { + + return [ + 'component' => 'k-form-dialog', + 'props' => [ + 'fields' => require __DIR__ . '/fields.php', + 'submitButton' => t('create'), + ] + ]; + }, + 'submit' => function () { + return KwConfig::create(get()); + } +]; + +?> diff --git a/kanga.world/site/plugins/kangaworld-integration/dialogs/delete.php b/kanga.world/site/plugins/kangaworld-integration/dialogs/delete.php new file mode 100644 index 0000000..c35e9a8 --- /dev/null +++ b/kanga.world/site/plugins/kangaworld-integration/dialogs/delete.php @@ -0,0 +1,20 @@ + 'kwconfig/(:any)/delete', + 'load' => function (string $id) { + return [ + 'component' => 'k-remove-dialog', + 'props' => [ + 'text' => 'Do you really want to delete this entry?' + ] + ]; + }, + 'submit' => function (string $id) { + return KwConfig::delete($id); + } +]; + +?> diff --git a/kanga.world/site/plugins/kangaworld-integration/dialogs/fields.php b/kanga.world/site/plugins/kangaworld-integration/dialogs/fields.php new file mode 100644 index 0000000..502a881 --- /dev/null +++ b/kanga.world/site/plugins/kangaworld-integration/dialogs/fields.php @@ -0,0 +1,31 @@ + [ + 'label' => 'Title', + 'type' => 'text' + ], + 'type' => [ + 'label' => 'Type', + 'type' => 'select', + 'empty' => false, + 'width' => '1/2', + 'options' => A::map(KwConfig::types(), function ($type) { + return ['value' => $type, 'text' => $type]; + }) + ], + 'description' => [ + 'label' => 'Description', + 'type' => 'textarea', + 'buttons' => false + ], + 'price' => [ + 'label' => 'Value', + 'type' => 'text' + ] +]; + +?> diff --git a/kanga.world/site/plugins/kangaworld-integration/dialogs/update.php b/kanga.world/site/plugins/kangaworld-integration/dialogs/update.php new file mode 100644 index 0000000..40bcff7 --- /dev/null +++ b/kanga.world/site/plugins/kangaworld-integration/dialogs/update.php @@ -0,0 +1,23 @@ + 'kwconfig/(:any)/update', + 'load' => function (string $id) { + $kwconfig = KwConfig::find($id); + + return [ + 'component' => 'k-form-dialog', + 'props' => [ + 'fields' => require __DIR__ . '/fields.php', + 'value' => $kwconfig + ] + ]; + }, + 'submit' => function (string $id) { + return KwConfig::update(get()); + } +]; + +?> diff --git a/kanga.world/site/plugins/kangaworld-integration/dropdowns/kwconfig.php b/kanga.world/site/plugins/kangaworld-integration/dropdowns/kwconfig.php new file mode 100644 index 0000000..3c62053 --- /dev/null +++ b/kanga.world/site/plugins/kangaworld-integration/dropdowns/kwconfig.php @@ -0,0 +1,21 @@ + 'kwconfig/(:any)', + 'action' => function (string $id) { + return [ + [ + 'text' => 'Edit', + 'icon' => 'edit', + 'dialog' => 'kwconfig/' . $id . '/update' + ], + [ + 'text' => 'Delete', + 'icon' => 'trash', + 'dialog' => 'kwconfig/' . $id . '/delete' + ] + ]; + } +]; + +?> diff --git a/kanga.world/site/plugins/kangaworld-integration/index.css b/kanga.world/site/plugins/kangaworld-integration/index.css index 3bd54eb..c8af1c3 100644 --- a/kanga.world/site/plugins/kangaworld-integration/index.css +++ b/kanga.world/site/plugins/kangaworld-integration/index.css @@ -14,11 +14,22 @@ overflow: hidden; background: var(--color-white); } +.k-kwconfig-name { + /* width: 8rem; */ +} .k-kwconfig-type { - width: 8rem; + /* width: 8rem; */ +} +.k-kwconfig-description { + width: 50%; } .k-kwconfig-data { - width: 5rem; + /* width: 10rem; */ font-variant-numeric: tabular-nums; text-align: right !important; } +.k-kwconfig th button { + font: inherit; + text-align: left; + width: 100%; +} diff --git a/kanga.world/site/plugins/kangaworld-integration/index.js b/kanga.world/site/plugins/kangaworld-integration/index.js index ee67e73..206d6c7 100644 --- a/kanga.world/site/plugins/kangaworld-integration/index.js +++ b/kanga.world/site/plugins/kangaworld-integration/index.js @@ -1,15 +1,25 @@ (function() { "use strict"; - var render = function() { + var render$1 = function() { var _vm = this; var _h = _vm.$createElement; var _c = _vm._self._c || _h; - return _c("k-inside", [_c("k-view", [_c("k-header", [_vm._v("Kanga World Configuration")]), _c("table", { staticClass: "k-kwconfig" }, [_c("tr", [_c("th", [_vm._v("Title")]), _c("th", { staticClass: "k-kwconfig-type" }, [_vm._v("Type")]), _c("th", [_vm._v("Description")]), _c("th", { staticClass: "k-kwconfig-data" }, [_vm._v("Value")])]), _vm._l(_vm.kwconfig, function(kwconfig, name) { - return _c("tr", { key: name }, [_c("td", [_vm._v(_vm._s(kwconfig.name))]), _c("td", { staticClass: "k-kwconfig-type" }, [_vm._v(_vm._s(kwconfig.type))]), _c("td", [_vm._v(_vm._s(kwconfig.description))]), _c("td", { staticClass: "k-kwconfig-data" }, [_vm._v(_vm._s(kwconfig.data) + " "), _c("k-options-dropdown", { attrs: { "options": "kwconfig/" + name } })], 1)]); + return _c("k-inside", [_c("k-view", [_c("k-header", [_vm._v(" Kanga World Configuration "), _c("k-button-group", { attrs: { "slot": "right" }, slot: "right" }, [_c("k-button", { attrs: { "text": "New Entry", "icon": "add" }, on: { "click": function($event) { + return _vm.$dialog("kwconfig/create"); + } } })], 1)], 1), _c("table", { staticClass: "k-kwconfig" }, [_c("tr", [_c("th", { staticClass: "k-kwconfig-name" }, [_c("button", { on: { "click": function($event) { + return _vm.sortBy("name"); + } } }, [_vm._v(" Name "), _vm.sort === "name" ? _c("span", { domProps: { "innerHTML": _vm._s(_vm.sortArrow) } }) : _vm._e()])]), _c("th", { staticClass: "k-kwconfig-type" }, [_c("button", { on: { "click": function($event) { + return _vm.sortBy("type"); + } } }, [_vm._v(" Type "), _vm.sort === "type" ? _c("span", { domProps: { "innerHTML": _vm._s(_vm.sortArrow) } }) : _vm._e()])]), _c("th", { staticClass: "k-kwconfig-description" }, [_c("button", { on: { "click": function($event) { + return _vm.sortBy("description"); + } } }, [_vm._v(" Description "), _vm.sort === "description" ? _c("span", { domProps: { "innerHTML": _vm._s(_vm.sortArrow) } }) : _vm._e()])]), _c("th", { staticClass: "k-kwconfig-data" }, [_c("button", { on: { "click": function($event) { + return _vm.sortBy("data"); + } } }, [_vm._v(" Value "), _vm.sort === "data" ? _c("span", { domProps: { "innerHTML": _vm._s(_vm.sortArrow) } }) : _vm._e()])])]), _vm._l(_vm.kwconfig, function(kwconfig, name) { + return _c("tr", { key: name }, [_c("td", { staticClass: "k-kwconfig-name" }, [_vm._v(_vm._s(kwconfig.name))]), _c("td", { staticClass: "k-kwconfig-type" }, [_vm._v(_vm._s(kwconfig.type))]), _c("td", { staticClass: "k-kwconfig-description" }, [_vm._v(_vm._s(kwconfig.description))]), _c("td", { staticClass: "k-kwconfig-data" }, [_vm._v(_vm._s(kwconfig.data)), _c("k-options-dropdown", { attrs: { "options": "kwconfig/" + name } })], 1)]); })], 2)], 1)], 1); }; - var staticRenderFns = []; - render._withStripped = true; + var staticRenderFns$1 = []; + render$1._withStripped = true; var KwConfig_vue_vue_type_style_index_0_lang = ""; function normalizeComponent(scriptExports, render2, staticRenderFns2, functionalTemplate, injectStyles, scopeId, moduleIdentifier, shadowMode) { var options = typeof scriptExports === "function" ? scriptExports.options : scriptExports; @@ -62,9 +72,57 @@ options }; } + const __vue2_script$1 = { + props: { + dir: String, + sort: String, + kwconfig: Object + }, + computed: { + sortArrow() { + return this.dir === "asc" ? "↓" : "↑"; + } + }, + methods: { + sortBy(sort) { + let dir = "asc"; + if (sort === this.sort) + dir = this.dir === "asc" ? "desc" : "asc"; + this.$reload({ + query: { + dir, + sort + } + }); + } + } + }; + const __cssModules$1 = {}; + var __component__$1 = /* @__PURE__ */ normalizeComponent(__vue2_script$1, render$1, staticRenderFns$1, false, __vue2_injectStyles$1, null, null, null); + function __vue2_injectStyles$1(context) { + for (let o in __cssModules$1) { + this[o] = __cssModules$1[o]; + } + } + __component__$1.options.__file = "src/components/KwConfig.vue"; + var KwConfig = /* @__PURE__ */ function() { + return __component__$1.exports; + }(); + var render = function() { + var _vm = this; + var _h = _vm.$createElement; + var _c = _vm._self._c || _h; + return _c("k-inside", [_c("k-view", [_c("k-header", [_vm._v(" " + _vm._s(_vm.kwentry.name) + " "), _c("k-button-group", { attrs: { "slot": "left" }, slot: "left" }, [_c("k-button", { attrs: { "text": "Edit", "icon": "edit" }, on: { "click": function($event) { + return _vm.$dialog("kwconfig/" + _vm.kwentry.name + "/update"); + } } }), _c("k-button", { attrs: { "text": "Delete", "icon": "trash" }, on: { "click": function($event) { + return _vm.$dialog("kwconfig/" + _vm.kwentry.name + "/delete"); + } } })], 1)], 1), _c("table", { staticClass: "k-kwconfig" }, [_c("tr", [_c("th", { staticClass: "k-kwconfig-type" }, [_vm._v("Type")]), _c("th", { staticClass: "k-kwconfig-description" }, [_vm._v("Description")]), _c("th", { staticClass: "k-kwconfig-data" }, [_vm._v("Value")])]), _c("tr", [_c("td", { staticClass: "k-kwconfig-type" }, [_vm._v(_vm._s(_vm.kwentry.type))]), _c("td", { staticClass: "k-kwconfig-description" }, [_vm._v(_vm._s(_vm.kwentry.description))]), _c("td", { staticClass: "k-kwconfig-data" }, [_vm._v(_vm._s(_vm.kwentry.data))])])])], 1)], 1); + }; + var staticRenderFns = []; + render._withStripped = true; const __vue2_script = { props: { - kwconfig: Object + kwentry: Object } }; const __cssModules = {}; @@ -74,13 +132,14 @@ this[o] = __cssModules[o]; } } - __component__.options.__file = "src/components/KwConfig.vue"; - var KwConfig = /* @__PURE__ */ function() { + __component__.options.__file = "src/components/KwEntry.vue"; + var KwEntry = /* @__PURE__ */ function() { return __component__.exports; }(); panel.plugin("kangaroopunch/kangaworld-integration", { components: { - "k-kwconfig-view": KwConfig + "k-kwconfig-view": KwConfig, + "k-kwentry-view": KwEntry } }); })(); diff --git a/kanga.world/site/plugins/kangaworld-integration/searches/kwconfig.php b/kanga.world/site/plugins/kangaworld-integration/searches/kwconfig.php new file mode 100644 index 0000000..2c979f2 --- /dev/null +++ b/kanga.world/site/plugins/kangaworld-integration/searches/kwconfig.php @@ -0,0 +1,32 @@ + 'Configuration', + 'icon' => 'globe', + 'query' => function(string $query) { + + $kwconfig = KwConfig::list(); + $results = []; + + foreach ($kwconfig as $kwentry) { + if ((Str::contains($kwentry['name'], $query, true) === true) || + (Str::contains($kwentry['description'], $query, true) === true) || + (Str::contains($kwentry['data'], $query, true) === true)) { + $results[] = [ + 'text' => $kwentry['name'], + 'link' => '/kwconfig/' . esc($kwentry['name'], 'url'), + 'image' => [ + 'icon' => 'globe', + 'back' => 'purple-400' + ] + ]; + } + } + + return $results; + } +]; + +?> diff --git a/kanga.world/site/plugins/kangaworld-integration/src/components/KwConfig.vue b/kanga.world/site/plugins/kangaworld-integration/src/components/KwConfig.vue index 5d72260..7258316 100644 --- a/kanga.world/site/plugins/kangaworld-integration/src/components/KwConfig.vue +++ b/kanga.world/site/plugins/kangaworld-integration/src/components/KwConfig.vue @@ -1,21 +1,48 @@