74 lines
2.7 KiB
PHP
74 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace App\Admin\Controllers;
|
|
|
|
use Dcat\Admin\Admin;
|
|
use Dcat\Admin\Http\Controllers\PermissionController as BaseController;
|
|
use Dcat\Admin\Tree;
|
|
use Illuminate\Support\Str;
|
|
|
|
class PermissionController extends BaseController
|
|
{
|
|
protected function treeView()
|
|
{
|
|
$model = config('admin.database.permissions_model');
|
|
|
|
return new Tree(new $model(), function (Tree $tree) {
|
|
$tree->disableCreateButton();
|
|
$tree->disableEditButton();
|
|
|
|
if (Admin::user()->cannot('dcat.admin.permissions.create')) {
|
|
$tree->disableQuickCreateButton();
|
|
}
|
|
$tree->actions(function (Tree\Actions $actions) {
|
|
$actions->disableEdit(Admin::user()->cannot('dcat.admin.permissions.edit'));
|
|
$actions->disableDelete(Admin::user()->cannot('dcat.admin.permissions.destroy'));
|
|
});
|
|
$tree->branch(function ($branch) {
|
|
$branchName = htmlspecialchars($branch['name']);
|
|
$branchSlug = htmlspecialchars($branch['slug']);
|
|
$payload = "<div class='pull-left' style='min-width:310px'><b>{$branchName}</b> [<span class='text-primary'>{$branchSlug}</span>]";
|
|
|
|
$path = array_filter($branch['http_path']);
|
|
|
|
if (! $path) {
|
|
return $payload.'</div> ';
|
|
}
|
|
|
|
$max = 3;
|
|
if (count($path) > $max) {
|
|
$path = array_slice($path, 0, $max);
|
|
array_push($path, '...');
|
|
}
|
|
|
|
$method = $branch['http_method'] ?: [];
|
|
|
|
$path = collect($path)->map(function ($path) use (&$method) {
|
|
if (Str::contains($path, ':')) {
|
|
[$me, $path] = explode(':', $path);
|
|
|
|
$method = array_merge($method, explode(',', $me));
|
|
}
|
|
if ($path !== '...' && ! empty(config('admin.route.prefix')) && ! Str::contains($path, '.')) {
|
|
$path = trim(admin_base_path($path), '/');
|
|
}
|
|
|
|
$color = Admin::color()->primaryDarker();
|
|
|
|
return "<code style='color:{$color}'>$path</code>";
|
|
})->implode(' ');
|
|
|
|
$method = collect($method ?: ['ANY'])->unique()->map(function ($name) {
|
|
return strtoupper($name);
|
|
})->map(function ($name) {
|
|
return "<span class='label bg-primary'>{$name}</span>";
|
|
})->implode(' ').' ';
|
|
|
|
$payload .= "</div> $method<a class=\"dd-nodrag\">$path</a>";
|
|
|
|
return $payload;
|
|
});
|
|
});
|
|
}
|
|
}
|