Starting off

Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
snipe 2024-02-16 18:57:50 +00:00
parent aef45a90b2
commit db73f80058
8 changed files with 35 additions and 5 deletions

View file

@ -148,6 +148,7 @@ class AssetsTransformer
'restore' => ($asset->deleted_at!='' && Gate::allows('create', Asset::class)) ? true : false,
'update' => ($asset->deleted_at=='' && Gate::allows('update', Asset::class)) ? true : false,
'delete' => ($asset->deleted_at=='' && $asset->assigned_to =='' && Gate::allows('delete', Asset::class) && ($asset->deleted_at == '')) ? true : false,
'selectable' => ($asset->deleted_at=='' && $asset->assigned_to =='' && Gate::allows('delete', Asset::class) && ($asset->deleted_at == '')) ? true : false,
];

View file

@ -65,6 +65,9 @@ class LocationsTransformer
$permissions_array['available_actions'] = [
'update' => Gate::allows('update', Location::class) ? true : false,
'delete' => $location->isDeletable(),
'bulk_selectable' => [
'delete' => $location->isDeletable()]
,
'clone' => (Gate::allows('create', Location::class) && ($location->deleted_at == '')),
];

View file

@ -82,6 +82,7 @@ class UsersTransformer
'delete' => $user->isDeletable(),
'clone' => (Gate::allows('create', User::class) && ($user->deleted_at == '')),
'restore' => (Gate::allows('create', User::class) && ($user->deleted_at != '')),
'selectable' => $user->isDeletable(),
];
$array += $permissions_array;

View file

@ -19,8 +19,9 @@ class AssetPresenter extends Presenter
{
$layout = [
[
'field' => 'checkbox',
'field' => 'bulk_selectable',
'checkbox' => true,
'formatter' => 'checkboxEnabledFormatter',
], [
'field' => 'id',
'searchable' => false,

View file

@ -14,7 +14,11 @@ class LocationPresenter extends Presenter
public static function dataTableLayout()
{
$layout = [
[
'field' => 'bulk_selectable',
'checkbox' => true,
'formatter' => 'checkboxEnabledFormatter',
],
[
'field' => 'id',
'searchable' => false,

View file

@ -22,8 +22,9 @@ class UserPresenter extends Presenter
{
$layout = [
[
'field' => 'checkbox',
'field' => 'bulk_selectable',
'checkbox' => true,
'formatter' => 'checkboxEnabledFormatter',
],
[
'field' => 'id',

View file

@ -23,6 +23,7 @@
<table
data-columns="{{ \App\Presenters\LocationPresenter::dataTableLayout() }}"
data-cookie-id-table="locationTable"
data-click-to-select="true"
data-pagination="true"
data-id-table="locationTable"
data-search="true"

View file

@ -398,17 +398,35 @@
// Convert line breaks to <br>
function notesFormatter(value) {
if (value) {
return value.replace(/(?:\r\n|\r|\n)/g, '<br />');;
return value.replace(/(?:\r\n|\r|\n)/g, '<br />');
}
}
// Check if checkbox should be selectable
// Selectability is determined by the API field "selectable" which is set at the Presenter/API Transformer
// However since different bulk actions have different requirements, we have to walk through the available_actions object
// to determine whether to disable it
function checkboxEnabledFormatter (value, row) {
// add some stuff to get the value of the select2 option here?
if ((row.available_actions) && (row.available_actions.bulk_selectable) && (row.available_actions.bulk_selectable.delete !== true)) {
console.log('value for ID ' + row.id + ' is NOT true:' + row.available_actions.bulk_selectable.delete);
return {
disabled:true,
//checked: false, <-- not sure this will work the way we want?
}
}
console.log('value for ID ' + row.id + ' IS true:' + row.available_actions.bulk_selectable.delete);
}
// We need a special formatter for license seats, since they don't work exactly the same
// Checkouts need the license ID, checkins need the specific seat ID
function licenseSeatInOutFormatter(value, row) {
// The user is allowed to check the license seat out and it's available
if ((row.available_actions.checkout == true) && (row.user_can_checkout == true) && ((!row.asset_id) && (!row.assigned_to))) {
if ((row.available_actions.checkout === true) && (row.user_can_checkout === true) && ((!row.asset_id) && (!row.assigned_to))) {
return '<a href="{{ config('app.url') }}/licenses/' + row.license_id + '/checkout/'+row.id+'" class="btn btn-sm bg-maroon" data-tooltip="true" title="{{ trans('general.checkout_tooltip') }}">{{ trans('general.checkout') }}</a>';
} else {
return '<a href="{{ config('app.url') }}/licenses/' + row.id + '/checkin" class="btn btn-sm bg-purple" data-tooltip="true" title="Check in this license seat.">{{ trans('general.checkin') }}</a>';