Improve text of plugins management

This commit is contained in:
Pig Fang 2019-08-25 15:54:29 +08:00
parent c976a5c5f8
commit deb8c44e45
6 changed files with 39 additions and 35 deletions

View File

@ -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);

View File

@ -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, '<code>$1</code>'), {
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' })
}
},
},

View File

@ -57,7 +57,7 @@ test('enable plugin', async () => {
])
Vue.prototype.$http.post
.mockResolvedValueOnce({
code: 1, message: '1', data: { reason: ['`a<div></div>`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(
'<p>1</p><ul><li>`a&lt;div&gt;&lt;/div&gt;`b</li></ul>',
{
type: 'warning',
dangerouslyUseHTMLString: true,
}
)
expect(Vue.prototype.$alert).toBeCalledWith('', ({
type: 'warning',
message: expect.anything()
}))
wrapper.findAll('.actions').at(1)
.find('a')

View File

@ -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.

View File

@ -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: 插件未安装或未提供配置页面

View File

@ -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']),
],
],
]);