From f5cf0fadab5f71c7264ca0761277c68ce3d78088 Mon Sep 17 00:00:00 2001 From: Nico Hoffmann Date: Sun, 5 May 2024 17:07:34 +0200 Subject: [PATCH] Buttons for all the views --- config/areas/languages/views.php | 11 +++++- config/areas/system/views.php | 1 + config/areas/users/views.php | 5 ++- panel/public/js/plugins.js | 12 +++---- .../src/components/View/Buttons/AddButton.vue | 26 ++++++++++++++ .../View/Buttons/AddLanguagesButton.vue | 9 +++++ .../View/Buttons/AddUsersButton.vue | 16 +++++++++ panel/src/components/View/Buttons/Buttons.vue | 4 ++- .../View/Buttons/LanguagesButton.vue | 2 +- .../components/View/Buttons/PreviewButton.vue | 9 ++--- .../components/View/Buttons/RemoveButton.vue | 26 ++++++++++++++ .../View/Buttons/RemoveLanguageButton.vue | 10 ++++++ .../View/Buttons/SettingsButton.vue | 29 +++++++-------- .../components/View/Buttons/StatusButton.vue | 2 +- .../components/View/Buttons/ThemeButton.vue | 2 +- panel/src/components/View/Buttons/index.js | 10 ++++++ panel/src/components/Views/Files/FileView.vue | 11 +++++- .../Views/Languages/LanguageView.vue | 36 +++++-------------- .../Views/Languages/LanguagesView.vue | 13 +++---- .../components/Views/System/SystemView.vue | 5 +++ .../src/components/Views/Users/UsersView.vue | 10 ++---- panel/src/panel/plugins.js | 4 +-- panel/src/panel/plugins.test.js | 4 +-- src/Cms/Blueprint.php | 2 +- src/Panel/File.php | 2 +- src/Panel/Page.php | 2 +- src/Panel/Site.php | 2 +- src/Panel/User.php | 2 +- 28 files changed, 182 insertions(+), 85 deletions(-) create mode 100644 panel/src/components/View/Buttons/AddButton.vue create mode 100644 panel/src/components/View/Buttons/AddLanguagesButton.vue create mode 100644 panel/src/components/View/Buttons/AddUsersButton.vue create mode 100644 panel/src/components/View/Buttons/RemoveButton.vue create mode 100644 panel/src/components/View/Buttons/RemoveLanguageButton.vue diff --git a/config/areas/languages/views.php b/config/areas/languages/views.php index f37ded0247..f89d9bb80d 100644 --- a/config/areas/languages/views.php +++ b/config/areas/languages/views.php @@ -12,10 +12,11 @@ return App::instance()->option('languages.variables', true) !== false; }, 'action' => function (string $code) { + $kirby = App::instance(); $language = Find::language($code); $link = '/languages/' . $language->code(); $strings = []; - $foundation = App::instance()->defaultLanguage()->translations(); + $foundation = $kirby->defaultLanguage()->translations(); $translations = $language->translations(); ksort($foundation); @@ -67,6 +68,11 @@ ] ], 'props' => [ + 'buttons' => $kirby->option('panel.viewButtons.language', [ + 'preview', + 'settings', + 'remove' + ]), 'deletable' => $language->isDeletable(), 'code' => Escape::html($language->code()), 'default' => $language->isDefault(), @@ -107,6 +113,9 @@ return [ 'component' => 'k-languages-view', 'props' => [ + 'buttons' => $kirby->option('panel.viewButtons.languages', [ + 'add' + ]), 'languages' => $kirby->languages()->values(fn ($language) => [ 'deletable' => $language->isDeletable(), 'default' => $language->isDefault(), diff --git a/config/areas/system/views.php b/config/areas/system/views.php index 01f2eb23c0..49da8bb672 100644 --- a/config/areas/system/views.php +++ b/config/areas/system/views.php @@ -87,6 +87,7 @@ return [ 'component' => 'k-system-view', 'props' => [ + 'buttons' => $kirby->option('panel.viewButtons.system', []), 'environment' => $environment, 'exceptions' => $kirby->option('debug') === true ? $exceptions : [], 'info' => $system->info(), diff --git a/config/areas/users/views.php b/config/areas/users/views.php index 5f0ce9d940..bf75a0d7e7 100644 --- a/config/areas/users/views.php +++ b/config/areas/users/views.php @@ -18,7 +18,10 @@ return [ 'component' => 'k-users-view', 'props' => [ - 'role' => function () use ($kirby, $roles, $role) { + 'buttons' => $kirby->option('panel.viewButtons.users', [ + 'add' + ]), + 'role' => function () use ($roles, $role) { if ($role) { return $roles[$role] ?? null; } diff --git a/panel/public/js/plugins.js b/panel/public/js/plugins.js index 4639d03a33..c7f7780060 100644 --- a/panel/public/js/plugins.js +++ b/panel/public/js/plugins.js @@ -2,12 +2,12 @@ window.panel = window.panel ?? {}; window.panel.plugins = { components: {}, created: [], - headerButtons: {}, icons: {}, routes: [], textareaButtons: {}, thirdParty: {}, use: [], + viewButtons: {}, views: {}, writerMarks: {}, writerNodes: {} @@ -36,11 +36,6 @@ window.panel.plugin = function (plugin, extensions) { window.panel.plugins.components[`k-${name}-field`] = options; }); - // Header Buttons - resolve(extensions, "headerButtons", (name, options) => { - window.panel.plugins.components[`k-view-${name}-button`] = options; - }); - // Icons resolve(extensions, "icons", (name, options) => { window.panel.plugins.icons[name] = options; @@ -54,6 +49,11 @@ window.panel.plugin = function (plugin, extensions) { }; }); + // View Buttons + resolve(extensions, "viewButtons", (name, options) => { + window.panel.plugins.components[`k-view-${name}-button`] = options; + }); + // `Vue.use` resolve(extensions, "use", (name, options) => { window.panel.plugins.use.push(options); diff --git a/panel/src/components/View/Buttons/AddButton.vue b/panel/src/components/View/Buttons/AddButton.vue new file mode 100644 index 0000000000..7bafc627fb --- /dev/null +++ b/panel/src/components/View/Buttons/AddButton.vue @@ -0,0 +1,26 @@ + + + diff --git a/panel/src/components/View/Buttons/AddLanguagesButton.vue b/panel/src/components/View/Buttons/AddLanguagesButton.vue new file mode 100644 index 0000000000..55e21147a6 --- /dev/null +++ b/panel/src/components/View/Buttons/AddLanguagesButton.vue @@ -0,0 +1,9 @@ + diff --git a/panel/src/components/View/Buttons/AddUsersButton.vue b/panel/src/components/View/Buttons/AddUsersButton.vue new file mode 100644 index 0000000000..10540be123 --- /dev/null +++ b/panel/src/components/View/Buttons/AddUsersButton.vue @@ -0,0 +1,16 @@ + diff --git a/panel/src/components/View/Buttons/Buttons.vue b/panel/src/components/View/Buttons/Buttons.vue index 1edc488018..909ba6382b 100644 --- a/panel/src/components/View/Buttons/Buttons.vue +++ b/panel/src/components/View/Buttons/Buttons.vue @@ -4,6 +4,7 @@ :is="`k-view-${button}-button`" v-for="button in buttons" :key="button" + @action="$emit('action', $event)" /> @@ -17,6 +18,7 @@ export default { props: { buttons: Array - } + }, + emits: ["action"] }; diff --git a/panel/src/components/View/Buttons/LanguagesButton.vue b/panel/src/components/View/Buttons/LanguagesButton.vue index 512386dbc3..6650ddb798 100644 --- a/panel/src/components/View/Buttons/LanguagesButton.vue +++ b/panel/src/components/View/Buttons/LanguagesButton.vue @@ -18,7 +18,7 @@ diff --git a/panel/src/components/View/Buttons/RemoveLanguageButton.vue b/panel/src/components/View/Buttons/RemoveLanguageButton.vue new file mode 100644 index 0000000000..de421f59d7 --- /dev/null +++ b/panel/src/components/View/Buttons/RemoveLanguageButton.vue @@ -0,0 +1,10 @@ + diff --git a/panel/src/components/View/Buttons/SettingsButton.vue b/panel/src/components/View/Buttons/SettingsButton.vue index 2edf833de7..24fd8e0720 100644 --- a/panel/src/components/View/Buttons/SettingsButton.vue +++ b/panel/src/components/View/Buttons/SettingsButton.vue @@ -8,40 +8,41 @@ variant="filled" size="sm" class="k-view-settings-button k-view-options" - @click="$refs.settings.toggle()" + @click="onClick" />