Skip to content

Commit

Permalink
Role & Permission Name Pretty Print
Browse files Browse the repository at this point in the history
  • Loading branch information
sudippalash committed Jan 12, 2024
1 parent 69f2ace commit 3e19a00
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 9 deletions.
12 changes: 12 additions & 0 deletions config/role-creator.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@
'route_name' => 'user.roles',
'route_prefix' => 'user/roles',
'middleware' => [],

/*
|--------------------------------------------------------------------------
| Role & Permission Name Pretty Print
|--------------------------------------------------------------------------
|
| You can set the delimiter to separate your role/permission name for pretty preview
| Example: array('-', '_', '=', '|', '/')
|
*/

'role_permission_name_separator' => ['-', '_'],

/*
|--------------------------------------------------------------------------
Expand Down
6 changes: 5 additions & 1 deletion src/Traits/RoleCrud.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ public function create()
$permissionArr[$per->module][] = (object) [
'id' => $per->id,
'name' => $per->name,
'label' => $this->prettyPrint($per->name, $per->module),
'module' => $this->prettyPrint($per->module),
];
}

Expand Down Expand Up @@ -84,7 +86,7 @@ public function show(Request $request, $id)

$permissioDone = [];
foreach ($data->permissions as $per) {
$permissioDone[$per->module][] = $per->name;
$permissioDone[$this->prettyPrint($per->module)][] = $this->prettyPrint($per->name, $per->module);
}

$cssClass = $this->cssGenerate();
Expand All @@ -109,6 +111,8 @@ public function edit(Request $request, $id)
$permissionArr[$per->module][] = (object) [
'id' => $per->id,
'name' => $per->name,
'label' => $this->prettyPrint($per->name, $per->module),
'module' => $this->prettyPrint($per->module),
];
}

Expand Down
15 changes: 15 additions & 0 deletions src/Traits/RoleUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,19 @@ public function cssGenerate()

return $cssClass;
}

private function prettyPrint($string, $module = null)
{
if (! empty($module)) {
$string = str_replace($module, ' ', $string);
}


$separator = config('role-creator.role_permission_name_separator');
if (is_array($separator)) {
$string = trim(str_replace($separator, ' ', $string));
}

return ucwords($string);
}
}
4 changes: 2 additions & 2 deletions src/resources/views/bootstrap/form.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@
<td>
<div class="custom-control custom-switch">
<input type="checkbox" class="custom-control-input" id="module{{ $i }}" onclick="moduleCheck({{ $i }})"{{ (array_key_exists($module, $permissioDone)) ? ' checked' : '' }}>
<label class="custom-control-label" for="module{{ $i }}">{{ ucfirst($module) }}</label>
<label class="custom-control-label" for="module{{ $i }}">{{ $moduleArr[0]->module }}</label>
</div>
</td>
<td>
<div class="row" id="moduleContent{{ $i }}">
@foreach($moduleArr as $md)
<div class="col-sm-2 custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input" id="permission{{ $md->id }}" name="permissions[]" value="{{ $md->name }}"{{ (isset($permissioDone[$module]) && in_array($md->name, $permissioDone[$module])) ? ' checked' : '' }}>
<label class="custom-control-label" for="permission{{ $md->id }}">{{ str_replace($module, '', $md->name) }}</label><br>
<label class="custom-control-label" for="permission{{ $md->id }}">{{ $md->label }}</label><br>
</div>
@endforeach
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/resources/views/bootstrap/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@
<div class="row">
@foreach($moduleArr as $md)
<div class="col-sm-2 custom-control custom-checkbox">
<input class="custom-control-input" type="checkbox" value="{{ $md }}" checked disabled>
<label class="custom-control-label">{{ str_replace($module, '', $md) }}</label><br>
<input class="custom-control-input" type="checkbox" checked disabled>
<label class="custom-control-label">{{ $md }}</label><br>
</div>
@endforeach
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/resources/views/bootstrap3/form.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@
<td>
<div class="custom-control custom-switch">
<input type="checkbox" class="custom-control-input" id="module{{ $i }}" onclick="moduleCheck({{ $i }})"{{ (array_key_exists($module, $permissioDone)) ? ' checked' : '' }}>
<label class="custom-control-label" for="module{{ $i }}">{{ ucfirst($module) }}</label>
<label class="custom-control-label" for="module{{ $i }}">{{ $moduleArr[0]->module }}</label>
</div>
</td>
<td>
<div class="row" id="moduleContent{{ $i }}">
@foreach($moduleArr as $md)
<div class="col-sm-2 custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input" id="permission{{ $md->id }}" name="permissions[]" value="{{ $md->name }}"{{ (isset($permissioDone[$module]) && in_array($md->name, $permissioDone[$module])) ? ' checked' : '' }}>
<label class="custom-control-label" for="permission{{ $md->id }}">{{ str_replace($module, '', $md->name) }}</label><br>
<label class="custom-control-label" for="permission{{ $md->id }}">{{ $md->label }}</label><br>
</div>
@endforeach
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/resources/views/bootstrap3/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@
<div class="row">
@foreach($moduleArr as $md)
<div class="col-sm-2 custom-control custom-checkbox">
<input class="custom-control-input" type="checkbox" value="{{ $md }}" checked disabled>
<label class="custom-control-label">{{ str_replace($module, '', $md) }}</label><br>
<input class="custom-control-input" type="checkbox" checked disabled>
<label class="custom-control-label">{{ $md }}</label><br>
</div>
@endforeach
</div>
Expand Down

0 comments on commit 3e19a00

Please sign in to comment.