From deb8c44e451cdae4a74957118f0d83d84b11f876 Mon Sep 17 00:00:00 2001 From: Pig Fang Date: Sun, 25 Aug 2019 15:54:29 +0800 Subject: [PATCH] Improve text of plugins management --- app/Http/Controllers/PluginController.php | 12 +++++++---- .../src/components/mixins/enablePlugin.ts | 21 ++++++------------- .../assets/tests/views/admin/Plugins.test.ts | 13 +++++------- resources/lang/en/admin.yml | 6 +++--- resources/lang/zh_CN/admin.yml | 6 +++--- tests/PluginControllerTest.php | 16 ++++++++++++-- 6 files changed, 39 insertions(+), 35 deletions(-) diff --git a/app/Http/Controllers/PluginController.php b/app/Http/Controllers/PluginController.php index e2bcd9df..ee76662b 100644 --- a/app/Http/Controllers/PluginController.php +++ b/app/Http/Controllers/PluginController.php @@ -34,17 +34,21 @@ class PluginController extends Controller if ($result === true) { return json(trans('admin.plugins.operations.enabled', ['plugin' => $plugin->title]), 0); } else { - $unsatisfied = $result['unsatisfied']->map(function ($detail, $name) { + $unsatisfied = $result['unsatisfied']->map(function ($detail, $name) use ($plugins) { $constraint = $detail['constraint']; if (! $detail['version']) { + $plugin = $plugins->get($name); + $name = $plugin ? trans($plugin->title) : $name; return trans('admin.plugins.operations.unsatisfied.disabled', compact('name')); } else { - return trans('admin.plugins.operations.unsatisfied.version', compact('name', 'constraint')); + $title = trans($plugins->get($name)->title); + return trans('admin.plugins.operations.unsatisfied.version', compact('title', 'constraint')); } })->values()->all(); - $conflicts = $result['conflicts']->map(function ($detail, $name) { - return trans('admin.plugins.operations.unsatisfied.conflict', compact('name')); + $conflicts = $result['conflicts']->map(function ($detail, $name) use ($plugins) { + $title = trans($plugins->get($name)->title); + return trans('admin.plugins.operations.unsatisfied.conflict', compact('title')); })->values()->all(); $reason = array_merge($unsatisfied, $conflicts); diff --git a/resources/assets/src/components/mixins/enablePlugin.ts b/resources/assets/src/components/mixins/enablePlugin.ts index 37f336ad..958861fe 100644 --- a/resources/assets/src/components/mixins/enablePlugin.ts +++ b/resources/assets/src/components/mixins/enablePlugin.ts @@ -31,21 +31,12 @@ export default Vue.extend({ this.$message.success(message) this.$set(this.plugins[originalIndex], 'enabled', true) } else { - const div = document.createElement('div') - const p = document.createElement('p') - p.textContent = message - div.appendChild(p) - const ul = document.createElement('ul') - reason.forEach(item => { - const li = document.createElement('li') - li.textContent = item - ul.appendChild(li) - }) - div.appendChild(ul) - this.$alert(div.innerHTML.replace(/`([\w-_]+)`/g, '$1'), { - dangerouslyUseHTMLString: true, - type: 'warning', - }) + const h = this.$createElement + const vnode = h('div', {}, [ + h('p', message), + h('ul', {}, reason.map(item => h('li', item))) + ]) + this.$alert('', { message: vnode, type: 'warning' }) } }, }, diff --git a/resources/assets/tests/views/admin/Plugins.test.ts b/resources/assets/tests/views/admin/Plugins.test.ts index 2c0ff846..28a83424 100644 --- a/resources/assets/tests/views/admin/Plugins.test.ts +++ b/resources/assets/tests/views/admin/Plugins.test.ts @@ -57,7 +57,7 @@ test('enable plugin', async () => { ]) Vue.prototype.$http.post .mockResolvedValueOnce({ - code: 1, message: '1', data: { reason: ['`a
`b'] }, + code: 1, message: '1', data: { reason: ['abc'] }, }) .mockResolvedValue({ code: 0, message: '0' }) Vue.prototype.$confirm @@ -83,13 +83,10 @@ test('enable plugin', async () => { '/admin/plugins/manage', { action: 'enable', name: 'a' } ) - expect(Vue.prototype.$alert).toBeCalledWith( - '

1

', - { - type: 'warning', - dangerouslyUseHTMLString: true, - } - ) + expect(Vue.prototype.$alert).toBeCalledWith('', ({ + type: 'warning', + message: expect.anything() + })) wrapper.findAll('.actions').at(1) .find('a') diff --git a/resources/lang/en/admin.yml b/resources/lang/en/admin.yml index c22f64b2..94c71642 100644 --- a/resources/lang/en/admin.yml +++ b/resources/lang/en/admin.yml @@ -96,9 +96,9 @@ plugins: enabled: :plugin has been enabled. unsatisfied: notice: There are conflicts or unsatisfied dependencies in the plugin, therefore we can't enable it. Please install or update the plugins listed below, and disable those have conflicts. - disabled: 'The :name plugin is not enabled.' - version: 'The version of :name does not satisfies the constraint `:constraint`.' - conflict: 'The :name plugin cannot run with this plugin at the same time.' + disabled: 'The ":name" plugin is not enabled.' + version: 'The version of ":title" does not satisfies the constraint ":constraint".' + conflict: 'The ":title" plugin cannot run with this plugin at the same time.' disabled: :plugin has been disabled. deleted: The plugin was deleted successfully. no-config-notice: The plugin is not installed or doesn't provide a configuration page. diff --git a/resources/lang/zh_CN/admin.yml b/resources/lang/zh_CN/admin.yml index 70e51446..b6c1f40b 100644 --- a/resources/lang/zh_CN/admin.yml +++ b/resources/lang/zh_CN/admin.yml @@ -101,9 +101,9 @@ plugins: enabled: :plugin 已启用 unsatisfied: notice: 无法启用此插件,因为其仍有冲突或未满足的依赖关系。请检查以下插件的版本,更新或安装它们并禁用存在冲突的插件: - disabled: ':name 插件未启用' - version: ':name 的版本不符合要求 `:constraint`' - conflict: ':name 插件与此插件不能同时运行' + disabled: '「:name」插件未启用' + version: '「:title」的版本不符合要求 ":constraint"' + conflict: '「:title」插件与此插件不能同时运行' disabled: :plugin 已禁用 deleted: 插件已被成功删除 no-config-notice: 插件未安装或未提供配置页面 diff --git a/tests/PluginControllerTest.php b/tests/PluginControllerTest.php index 6e113dcb..3bf84c1b 100644 --- a/tests/PluginControllerTest.php +++ b/tests/PluginControllerTest.php @@ -89,6 +89,18 @@ class PluginControllerTest extends TestCase ->with('fake2') ->once() ->andReturn(new Plugin('', ['name' => 'fake2'])); + $mock->shouldReceive('get') + ->with('dep') + ->once() + ->andReturn(new Plugin('', ['title' => 'dep'])); + $mock->shouldReceive('get') + ->with('whatever') + ->once() + ->andReturn(null); + $mock->shouldReceive('get') + ->with('conf') + ->once() + ->andReturn(new Plugin('', ['title' => 'conf'])); $mock->shouldReceive('enable') ->with('fake2') ->once() @@ -152,11 +164,11 @@ class PluginControllerTest extends TestCase 'data' => [ 'reason' => [ trans('admin.plugins.operations.unsatisfied.version', [ - 'name' => 'dep', + 'title' => 'dep', 'constraint' => '^6.6.6', ]), trans('admin.plugins.operations.unsatisfied.disabled', ['name' => 'whatever']), - trans('admin.plugins.operations.unsatisfied.conflict', ['name' => 'conf']), + trans('admin.plugins.operations.unsatisfied.conflict', ['title' => 'conf']), ], ], ]);