diff --git a/app/Http/Controllers/PluginController.php b/app/Http/Controllers/PluginController.php
index 3603b0cf..7961220f 100644
--- a/app/Http/Controllers/PluginController.php
+++ b/app/Http/Controllers/PluginController.php
@@ -48,22 +48,23 @@ class PluginController extends Controller
switch ($request->get('action')) {
case 'enable':
if (! $plugins->isRequirementsSatisfied($plugin)) {
- $msg = '';
+ $reason = [];
foreach ($plugins->getUnsatisfiedRequirements($plugin) as $name => $detail) {
+ $constraint = $detail['constraint'];
+
if (! $detail['version']) {
- $msg .= '
'.trans('admin.plugins.operations.unsatisfied.disabled', [
- 'name' => "$name
"
- ]).'';
+ $reason[] = trans('admin.plugins.operations.unsatisfied.disabled', compact('name'));
} else {
- $msg .= ''.trans('admin.plugins.operations.unsatisfied.version', [
- 'name' => "$name
",
- 'constraint' => "{$detail['constraint']}
"
- ]).'';
+ $reason[] = trans('admin.plugins.operations.unsatisfied.version', compact('name', 'constraint'));
}
}
- return json(''.trans('admin.plugins.operations.unsatisfied.notice')."
", 1);
+ return json([
+ 'errno' => 1,
+ 'msg' => trans('admin.plugins.operations.unsatisfied.notice'),
+ 'reason' => $reason
+ ]);
}
$plugins->enable($name);
diff --git a/resources/assets/src/js/__tests__/admin.test.js b/resources/assets/src/js/__tests__/admin.test.js
index 16bb68a9..7b567805 100644
--- a/resources/assets/src/js/__tests__/admin.test.js
+++ b/resources/assets/src/js/__tests__/admin.test.js
@@ -415,7 +415,7 @@ describe('tests for "plugins" module', () => {
requirements: { 'a': '^1.1.0', 'b': '^2.1.0', 'c': '^3.3.0' },
unsatisfiedRequirements: { 'c': '^3.3.0' }
}))
- .mockReturnValueOnce(Promise.resolve({ errno: 1, msg: 'warning' }))
+ .mockReturnValueOnce(Promise.resolve({ errno: 1, msg: 'notice', reason: ['reason1', 'reason2'] }))
.mockReturnValueOnce(Promise.reject());
const url = jest.fn(path => path);
const swal = jest.fn()
@@ -464,7 +464,7 @@ describe('tests for "plugins" module', () => {
expect(reloadTable).toBeCalledWith(null, false);
await enablePlugin('plugin');
- expect(swal).toBeCalledWith({ type: 'warning', html: 'warning' });
+ expect(swal).toBeCalledWith({ type: 'warning', html: 'notice
' });
await enablePlugin('plugin');
expect(showAjaxError).toBeCalled();
diff --git a/resources/assets/src/js/admin/plugins.js b/resources/assets/src/js/admin/plugins.js
index 361b65c3..ed0a6136 100644
--- a/resources/assets/src/js/admin/plugins.js
+++ b/resources/assets/src/js/admin/plugins.js
@@ -102,17 +102,18 @@ async function enablePlugin(name) {
});
}
- const { errno, msg } = await fetch({
+ const { errno, msg, reason } = await fetch({
type: 'POST',
url: url(`admin/plugins/manage?action=enable&name=${name}`),
dataType: 'json'
});
+
if (errno === 0) {
toastr.success(msg);
$.pluginsTable.ajax.reload(null, false);
} else {
- swal({ type: 'warning', html: msg });
+ swal({ type: 'warning', html: `${msg}
` });
}
} catch (error) {
showAjaxError(error);
diff --git a/resources/lang/en/admin.yml b/resources/lang/en/admin.yml
index ae555b39..a5a07b73 100644
--- a/resources/lang/en/admin.yml
+++ b/resources/lang/en/admin.yml
@@ -110,8 +110,8 @@ plugins:
enabled: :plugin has been enabled.
unsatisfied:
notice: There are unsatisfied dependencies in the plugin, therefore we can't enable it. Please install or update the plugins listed below.
- disabled: The :name plugin is not enabled.
- version: The version of :name does not satisfies the constraint :constraint
+ disabled: The :name
plugin is not enabled
+ version: The version of :name
does not satisfies the constraint :constraint
disabled: :plugin has been disabled.
deleted: The plugin was deleted successfully.
no-config-notice: The plugin is not installed or doesn't provide configuration page.
diff --git a/resources/lang/zh_CN/admin.yml b/resources/lang/zh_CN/admin.yml
index 2c7e0836..911e9a36 100644
--- a/resources/lang/zh_CN/admin.yml
+++ b/resources/lang/zh_CN/admin.yml
@@ -110,8 +110,8 @@ plugins:
enabled: :plugin 已启用
unsatisfied:
notice: 无法启用此插件,因为其仍有未满足的依赖关系。请检查以下插件的版本,更新或安装它们:
- disabled: :name 插件未启用
- version: :name 的版本不符合要求 :constraint
+ disabled: :name
插件未启用
+ version: :name
的版本不符合要求 :constraint
disabled: :plugin 已禁用
deleted: 插件已被成功删除
no-config-notice: 插件未安装或未提供配置页面
diff --git a/tests/PluginControllerTest.php b/tests/PluginControllerTest.php
index bca09319..ba1d7374 100644
--- a/tests/PluginControllerTest.php
+++ b/tests/PluginControllerTest.php
@@ -95,17 +95,16 @@ class PluginControllerTest extends TestCase
'action' => 'enable'
])->seeJson([
'errno' => 1,
- 'msg' => sprintf(
- '%s
',
- trans('admin.plugins.operations.unsatisfied.notice'),
+ 'msg' => trans('admin.plugins.operations.unsatisfied.notice'),
+ 'reason' => [
trans('admin.plugins.operations.unsatisfied.version', [
- 'name' => "example-plugin
",
- 'constraint' => "^6.6.6
"
+ 'name' => 'example-plugin',
+ 'constraint' => '^6.6.6'
]),
trans('admin.plugins.operations.unsatisfied.disabled', [
- 'name' => "whatever
"
+ 'name' => 'whatever'
])
- )
+ ]
]);
// Enable a plugin