From c9cdc6640cd248d3cf7a3b1a869969e62d3b9afe Mon Sep 17 00:00:00 2001 From: Pig Fang Date: Wed, 28 Aug 2019 16:04:26 +0800 Subject: [PATCH] Add more info at status page --- app/Http/Controllers/AdminController.php | 15 +++++++++++++-- resources/lang/en/admin.yml | 9 +++++++++ resources/lang/en/general.yml | 2 ++ resources/lang/zh_CN/admin.yml | 9 +++++++++ resources/lang/zh_CN/general.yml | 2 ++ resources/views/admin/status.blade.php | 18 ++++++++++++++---- tests/AdminControllerTest.php | 13 ++++++++++++- 7 files changed, 61 insertions(+), 7 deletions(-) diff --git a/app/Http/Controllers/AdminController.php b/app/Http/Controllers/AdminController.php index c5902b35..2e47fd78 100644 --- a/app/Http/Controllers/AdminController.php +++ b/app/Http/Controllers/AdminController.php @@ -14,6 +14,7 @@ use Illuminate\Support\Arr; use Illuminate\Support\Str; use App\Services\OptionForm; use Illuminate\Http\Request; +use App\Services\PluginManager; use Illuminate\Support\Collection; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Redis; @@ -362,12 +363,21 @@ class AdminController extends Controller ->with('forms', compact('resources', 'redis', 'cache')); } - public function status(Request $request) + public function status(Request $request, PluginManager $plugins) { $db = get_db_config(); + $enabledPlugins = $plugins->getEnabledPlugins()->map(function ($plugin) { + return ['title' => trans($plugin->title), 'version' => $plugin->version]; + }); return view('admin.status') ->with('detail', [ + 'bs' => [ + 'version' => config('app.version'), + 'env' => config('app.env'), + 'debug' => config('app.debug') ? trans('general.yes') : trans('general.no'), + 'laravel' => app()->version(), + ], 'server' => [ 'php' => PHP_VERSION, 'web' => $request->server('SERVER_SOFTWARE', trans('general.unknown')), @@ -381,7 +391,8 @@ class AdminController extends Controller 'database' => Arr::get($db, 'database'), 'prefix' => Arr::get($db, 'prefix'), ], - ]); + ]) + ->with('plugins', $enabledPlugins); } public function getUserData(Request $request, User $users) diff --git a/resources/lang/en/admin.yml b/resources/lang/en/admin.yml index 51c99b50..c78d56de 100644 --- a/resources/lang/en/admin.yml +++ b/resources/lang/en/admin.yml @@ -85,6 +85,14 @@ customize: black-light: Black Light status: + info: Information + health: Health + bs: + name: Blessing Skin + version: Version + env: Application Environment + debug: Debugging or Not? + laravel: Laravel Version server: name: Server php: PHP Version @@ -98,6 +106,7 @@ status: username: Username database: Database prefix: Table Prefix + plugins: Enabled Plugins (:amount) plugins: name: Name diff --git a/resources/lang/en/general.yml b/resources/lang/en/general.yml index 699cc632..e54a2c2c 100644 --- a/resources/lang/en/general.yml +++ b/resources/lang/en/general.yml @@ -43,6 +43,8 @@ reset: Reset submit: Submit cancel: Cancel +yes: Yes +no: No op-success: Operated successfully. unknown: Unknown diff --git a/resources/lang/zh_CN/admin.yml b/resources/lang/zh_CN/admin.yml index 748e0d3e..11449887 100644 --- a/resources/lang/zh_CN/admin.yml +++ b/resources/lang/zh_CN/admin.yml @@ -85,6 +85,14 @@ customize: black-light: 黑色主题 - 白色侧边栏 status: + info: 信息 + health: 健康 + bs: + name: Blessing Skin + version: 版本 + env: 应用环境 + debug: 是否处于调试状态 + laravel: Laravel 版本 server: name: 服务器 php: PHP 版本 @@ -98,6 +106,7 @@ status: username: 用户名 database: 数据库 prefix: 数据表前缀 + plugins: 已开启的插件 (:amount) plugins: name: 名称 diff --git a/resources/lang/zh_CN/general.yml b/resources/lang/zh_CN/general.yml index 3470f93c..d6e513a8 100644 --- a/resources/lang/zh_CN/general.yml +++ b/resources/lang/zh_CN/general.yml @@ -43,6 +43,8 @@ reset: 重置 submit: 提交 cancel: 取消 +yes: 是 +no: 否 op-success: 操作成功 unknown: 未知 diff --git a/resources/views/admin/status.blade.php b/resources/views/admin/status.blade.php index d90ea1d2..ac6c613a 100644 --- a/resources/views/admin/status.blade.php +++ b/resources/views/admin/status.blade.php @@ -10,10 +10,11 @@
-
-
+
-
+
+

@lang('admin.status.info')

+
@@ -28,12 +29,21 @@ @endforeach @endforeach + + + + @foreach ($plugins as $plugin) + + + + + @endforeach
@lang('admin.status.plugins', ['amount' => $plugins->count()])
{{ $plugin['title'] }}{{ $plugin['version'] }}
-
+
diff --git a/tests/AdminControllerTest.php b/tests/AdminControllerTest.php index 3695bfb6..c3c74d69 100644 --- a/tests/AdminControllerTest.php +++ b/tests/AdminControllerTest.php @@ -7,6 +7,7 @@ use App\Models\User; use App\Models\Player; use App\Notifications; use App\Models\Texture; +use App\Services\Plugin; use Illuminate\Support\Str; use Illuminate\Foundation\Testing\WithoutMiddleware; use Illuminate\Foundation\Testing\DatabaseTransactions; @@ -118,9 +119,19 @@ class AdminControllerTest extends TestCase public function testStatus() { + $this->mock(\App\Services\PluginManager::class, function ($mock) { + $mock->shouldReceive('getEnabledPlugins') + ->andReturn(collect([ + 'a' => new Plugin('', ['title' => 'MyPlugin', 'version' => '0.0.0']) + ])); + }); + $this->get('/admin/status') ->assertSee(PHP_VERSION) - ->assertSee(humanize_db_type()); + ->assertSee(humanize_db_type()) + ->assertSee('(1)') + ->assertSee('MyPlugin') + ->assertSee('0.0.0'); } public function testUsers()