From 29bd8a74f4c98b0a02fdc786c48a6759e4b69aa6 Mon Sep 17 00:00:00 2001 From: taoyu65 Date: Thu, 10 Aug 2017 14:46:32 -0700 Subject: [PATCH] complete function: distribution of user menus 1. fix selector return value contain space 2. fix loading user menu problem, it will create new user-menu when it does not esist instead of showing wrong message --- src/Models/UserMenu.php | 24 +++++++++++++------ src/resources/lang/en/menu.php | 2 ++ src/resources/lang/zh_cn/menu.php | 2 ++ src/resources/views/common/selector.blade.php | 2 +- .../views/menu/distribution.blade.php | 5 ++-- 5 files changed, 25 insertions(+), 10 deletions(-) diff --git a/src/Models/UserMenu.php b/src/Models/UserMenu.php index 8e0bd80..906a40d 100644 --- a/src/Models/UserMenu.php +++ b/src/Models/UserMenu.php @@ -2,6 +2,9 @@ namespace YM\Models; +use Illuminate\Support\Facades\Cache; +use Illuminate\Support\Facades\DB; + class UserMenu extends UmiBase { use BreadOperation; @@ -21,15 +24,22 @@ public function __construct(array $attributes = [], $openCache = true, $orderBy public function userJsonMenu($userId) { if ($this->openCache) { - return $this->cachedTable - ->where('user_id', $userId) - ->first() - ->json; + $userMenu = $this->cachedTable->where('user_id', $userId)->first(); + } else { + $userMenu = self::where('user_id', $userId)->first(); } - return self::where('user_id', $userId) - ->first() - ->json; + if ($userMenu) { + return $userMenu->json; + } else { + DB::table($this->table) + ->insert([ + 'user_id' => $userId, + 'json' => '[]' + ]); + Cache::pull($this->table); + return '[]'; + } } public function updateUserMenu($userId, $json) diff --git a/src/resources/lang/en/menu.php b/src/resources/lang/en/menu.php index dd9fc2e..3463d70 100644 --- a/src/resources/lang/en/menu.php +++ b/src/resources/lang/en/menu.php @@ -16,4 +16,6 @@ 'tip2' => 'This list is the entire menus, If you want manage different user\'s menu, you can use another function called Distribution', 'reload' => 'Reload', 'save' => 'Save', + 'warning' => 'Warning:', + 'superAdminWarning' => 'is Super Admin which will load all menus regardless this setting, but still can set user menus and it will work when remove that super admin identity.' ]; \ No newline at end of file diff --git a/src/resources/lang/zh_cn/menu.php b/src/resources/lang/zh_cn/menu.php index 0cb51f2..028cb79 100644 --- a/src/resources/lang/zh_cn/menu.php +++ b/src/resources/lang/zh_cn/menu.php @@ -16,4 +16,6 @@ 'tip2' => '这是 系统菜单, 如果你想管理用户菜单, 请进入 菜单设置中的 分配菜单 中设置', 'reload' => '重新加载', 'save' => '保存', + 'warning' => '警告:', + 'superAdminWarning' => '是超级管理员, 超级管理员默认加载所有菜单, 但是依然可以对其进行菜单设置, 只有在取消它的超级管理员身份时才起作用' ]; \ No newline at end of file diff --git a/src/resources/views/common/selector.blade.php b/src/resources/views/common/selector.blade.php index 72421d2..04e4155 100644 --- a/src/resources/views/common/selector.blade.php +++ b/src/resources/views/common/selector.blade.php @@ -57,7 +57,7 @@ @foreach($records as $record) - + @foreach($selector->fields as $item) diff --git a/src/resources/views/menu/distribution.blade.php b/src/resources/views/menu/distribution.blade.php index d467e65..57a2403 100644 --- a/src/resources/views/menu/distribution.blade.php +++ b/src/resources/views/menu/distribution.blade.php @@ -23,8 +23,9 @@ {{trans('umiTrans::menu.userFirst')}}. - {{trans('umiTrans::menu.tip1')}} -

+ {{trans('umiTrans::menu.tip1')}}
+ {{trans('umiTrans::menu.warning')}} "{{config('umi.system_role.super_admin')}}" + {{trans('umiTrans::menu.superAdminWarning')}}