From 7ecea9e7e60d75a94158cd445e432d9c1593f993 Mon Sep 17 00:00:00 2001 From: Pig Fang Date: Thu, 16 Jan 2020 12:33:14 +0800 Subject: [PATCH] new plugins management page --- app/Http/Controllers/MarketController.php | 1 - app/Http/Controllers/PluginController.php | 16 +- app/Services/Plugin.php | 7 +- .../src/components/mixins/enablePlugin.ts | 40 ---- resources/assets/src/views/admin/Market.vue | 9 +- resources/assets/src/views/admin/Plugins.vue | 222 +++++++----------- .../assets/tests/views/admin/Market.test.ts | 15 +- .../assets/tests/views/admin/Plugins.test.ts | 101 ++------ resources/misc/changelogs/en/5.0.0.md | 1 + resources/misc/changelogs/zh_CN/5.0.0.md | 1 + .../ControllersTest/PluginControllerTest.php | 14 +- webpack.config.js | 4 +- 12 files changed, 137 insertions(+), 294 deletions(-) delete mode 100644 resources/assets/src/components/mixins/enablePlugin.ts diff --git a/app/Http/Controllers/MarketController.php b/app/Http/Controllers/MarketController.php index 922b82be..9a4ea329 100644 --- a/app/Http/Controllers/MarketController.php +++ b/app/Http/Controllers/MarketController.php @@ -21,7 +21,6 @@ class MarketController extends Controller $plugin = $manager->get($item['name']); if ($plugin) { - $item['enabled'] = $plugin->isEnabled(); $item['installed'] = $plugin->version; $item['can_update'] = Comparator::greaterThan($item['version'], $item['installed']); } else { diff --git a/app/Http/Controllers/PluginController.php b/app/Http/Controllers/PluginController.php index bfb19540..9c59a36a 100644 --- a/app/Http/Controllers/PluginController.php +++ b/app/Http/Controllers/PluginController.php @@ -88,21 +88,19 @@ class PluginController extends Controller public function getPluginData(PluginManager $plugins) { return $plugins->all() - ->map(function ($plugin) use ($plugins) { + ->map(function (Plugin $plugin) { return [ 'name' => $plugin->name, - 'title' => trans($plugin->title ?: 'EMPTY'), - 'author' => $plugin->author, - 'description' => trans($plugin->description ?: 'EMPTY'), + 'title' => trans($plugin->title), + 'description' => trans($plugin->description ?? ''), 'version' => $plugin->version, - 'url' => $plugin->url, 'enabled' => $plugin->isEnabled(), 'readme' => (bool) $plugin->getReadme(), 'config' => $plugin->hasConfig(), - 'dependencies' => [ - 'all' => $plugin->require, - 'unsatisfied' => $plugins->getUnsatisfied($plugin), - ], + 'icon' => array_merge( + ['fa' => 'plug', 'faType' => 'fas', 'bg' => 'navy'], + $plugin->getManifestAttr('enchants.icon', []) + ), ]; }) ->values(); diff --git a/app/Services/Plugin.php b/app/Services/Plugin.php index 16c01c60..568c6c76 100644 --- a/app/Services/Plugin.php +++ b/app/Services/Plugin.php @@ -16,7 +16,7 @@ class Plugin ]; /** - * The full directory of this plugin. + * The full path of this plugin. * * @var string */ @@ -29,11 +29,6 @@ class Plugin */ protected $manifest; - /** - * Whether the plugin is enabled. - * - * @var bool - */ protected $enabled = false; public function __construct(string $path, array $manifest) diff --git a/resources/assets/src/components/mixins/enablePlugin.ts b/resources/assets/src/components/mixins/enablePlugin.ts deleted file mode 100644 index 7680540e..00000000 --- a/resources/assets/src/components/mixins/enablePlugin.ts +++ /dev/null @@ -1,40 +0,0 @@ -import Vue from 'vue' -import { showModal, toast } from '../../scripts/notify' -import alertUnresolvedPlugins from './alertUnresolvedPlugins' - -export default Vue.extend({ - data: () => ({ plugins: [] }), - methods: { - async enablePlugin({ - name, dependencies: { all }, originalIndex, - }: { - name: string - dependencies: { all: Record } - originalIndex: number - }) { - if (Object.keys(all).length === 0) { - try { - await showModal({ - text: this.$t('admin.noDependenciesNotice'), - okButtonType: 'warning', - }) - } catch { - return - } - } - - const { - code, message, data: { reason } = { reason: [] }, - } = await this.$http.post( - '/admin/plugins/manage', - { action: 'enable', name }, - ) as { code: number, message: string, data: { reason: string[] } } - if (code === 0) { - toast.success(message) - this.$set(this.plugins[originalIndex], 'enabled', true) - } else { - alertUnresolvedPlugins(message, reason) - } - }, - }, -}) diff --git a/resources/assets/src/views/admin/Market.vue b/resources/assets/src/views/admin/Market.vue index ef7427e2..040428ca 100644 --- a/resources/assets/src/views/admin/Market.vue +++ b/resources/assets/src/views/admin/Market.vue @@ -43,11 +43,8 @@ {{ $t('admin.updatePlugin') }} - -