Skip to content

Commit

Permalink
complete function: distribution of user menus
Browse files Browse the repository at this point in the history
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
  • Loading branch information
taoyu65 committed Aug 10, 2017
1 parent 016d7cd commit 29bd8a7
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 10 deletions.
24 changes: 17 additions & 7 deletions src/Models/UserMenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace YM\Models;

use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;

class UserMenu extends UmiBase
{
use BreadOperation;
Expand All @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions src/resources/lang/en/menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@
'tip2' => 'This list is the <strong class="red">entire menus</strong>, If you want manage different user\'s menu, you can use another function called <strong>Distribution</strong>',
'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.'
];
2 changes: 2 additions & 0 deletions src/resources/lang/zh_cn/menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@
'tip2' => '这是 <strong class="red">系统菜单</strong>, 如果你想管理用户菜单, 请进入 菜单设置中的 <strong>分配菜单</strong> 中设置',
'reload' => '重新加载',
'save' => '保存',
'warning' => '警告:',
'superAdminWarning' => '是超级管理员, 超级管理员默认加载所有菜单, 但是依然可以对其进行菜单设置, 只有在取消它的超级管理员身份时才起作用'
];
2 changes: 1 addition & 1 deletion src/resources/views/common/selector.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
</thead>
<tbody>
@foreach($records as $record)
<tr class="tr" onclick="parent.{{$selector->functionName}}($(this).find('#{{$selector->returnField}}').html())" >
<tr class="tr" onclick="parent.{{$selector->functionName}}($(this).find('#{{$selector->returnField}}').html().trim())" >
@foreach($selector->fields as $item)
<td>
<span id="{{$item}}">
Expand Down
5 changes: 3 additions & 2 deletions src/resources/views/menu/distribution.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@
<i class="ace-icon fa fa-check"></i>
{{trans('umiTrans::menu.userFirst')}}.
</strong>
{{trans('umiTrans::menu.tip1')}}
</p>
{{trans('umiTrans::menu.tip1')}} <br>
<span class="red"><strong>{{trans('umiTrans::menu.warning')}} </strong>"{{config('umi.system_role.super_admin')}}"
{{trans('umiTrans::menu.superAdminWarning')}}</span>
</div>
</div>

Expand Down

0 comments on commit 29bd8a7

Please sign in to comment.