From db73f80058cf97d664d013c979abf9920704cfa3 Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 16 Feb 2024 18:57:50 +0000 Subject: [PATCH 01/19] Starting off Signed-off-by: snipe --- app/Http/Transformers/AssetsTransformer.php | 1 + .../Transformers/LocationsTransformer.php | 3 +++ app/Http/Transformers/UsersTransformer.php | 1 + app/Presenters/AssetPresenter.php | 3 ++- app/Presenters/LocationPresenter.php | 6 ++++- app/Presenters/UserPresenter.php | 3 ++- resources/views/locations/index.blade.php | 1 + .../views/partials/bootstrap-table.blade.php | 22 +++++++++++++++++-- 8 files changed, 35 insertions(+), 5 deletions(-) diff --git a/app/Http/Transformers/AssetsTransformer.php b/app/Http/Transformers/AssetsTransformer.php index f5d5ae12b5..c91bceac20 100644 --- a/app/Http/Transformers/AssetsTransformer.php +++ b/app/Http/Transformers/AssetsTransformer.php @@ -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, ]; diff --git a/app/Http/Transformers/LocationsTransformer.php b/app/Http/Transformers/LocationsTransformer.php index 635a90cbc7..b072f9ed40 100644 --- a/app/Http/Transformers/LocationsTransformer.php +++ b/app/Http/Transformers/LocationsTransformer.php @@ -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 == '')), ]; diff --git a/app/Http/Transformers/UsersTransformer.php b/app/Http/Transformers/UsersTransformer.php index 0ebaca2692..16224bb216 100644 --- a/app/Http/Transformers/UsersTransformer.php +++ b/app/Http/Transformers/UsersTransformer.php @@ -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; diff --git a/app/Presenters/AssetPresenter.php b/app/Presenters/AssetPresenter.php index de7c2c7709..eebf92ac72 100644 --- a/app/Presenters/AssetPresenter.php +++ b/app/Presenters/AssetPresenter.php @@ -19,8 +19,9 @@ class AssetPresenter extends Presenter { $layout = [ [ - 'field' => 'checkbox', + 'field' => 'bulk_selectable', 'checkbox' => true, + 'formatter' => 'checkboxEnabledFormatter', ], [ 'field' => 'id', 'searchable' => false, diff --git a/app/Presenters/LocationPresenter.php b/app/Presenters/LocationPresenter.php index 86e82c1220..6a9bc0b568 100644 --- a/app/Presenters/LocationPresenter.php +++ b/app/Presenters/LocationPresenter.php @@ -14,7 +14,11 @@ class LocationPresenter extends Presenter public static function dataTableLayout() { $layout = [ - + [ + 'field' => 'bulk_selectable', + 'checkbox' => true, + 'formatter' => 'checkboxEnabledFormatter', + ], [ 'field' => 'id', 'searchable' => false, diff --git a/app/Presenters/UserPresenter.php b/app/Presenters/UserPresenter.php index f70ddf8af6..dd7e22656b 100644 --- a/app/Presenters/UserPresenter.php +++ b/app/Presenters/UserPresenter.php @@ -22,8 +22,9 @@ class UserPresenter extends Presenter { $layout = [ [ - 'field' => 'checkbox', + 'field' => 'bulk_selectable', 'checkbox' => true, + 'formatter' => 'checkboxEnabledFormatter', ], [ 'field' => 'id', diff --git a/resources/views/locations/index.blade.php b/resources/views/locations/index.blade.php index 4133f1a2f7..0b368babbb 100755 --- a/resources/views/locations/index.blade.php +++ b/resources/views/locations/index.blade.php @@ -23,6 +23,7 @@ function notesFormatter(value) { if (value) { - return value.replace(/(?:\r\n|\r|\n)/g, '
');; + return value.replace(/(?:\r\n|\r|\n)/g, '
'); } } + // 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 '{{ trans('general.checkout') }}'; } else { return '{{ trans('general.checkin') }}'; From a6a65b75230753a6b5176dd551df7b03c98c8dc9 Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 20 Feb 2024 16:40:09 +0000 Subject: [PATCH 02/19] Fixed locations isDeletable check Signed-off-by: snipe --- app/Models/Location.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Models/Location.php b/app/Models/Location.php index 145d6cef9a..1122b5da15 100755 --- a/app/Models/Location.php +++ b/app/Models/Location.php @@ -106,6 +106,7 @@ class Location extends SnipeModel return Gate::allows('delete', $this) && ($this->assignedAssets()->count() === 0) && ($this->assets()->count() === 0) + && ($this->children()->count() === 0) && ($this->users()->count() === 0); } From 1e602793b2f605334ce5ea2cfce047cab3c7a4fe Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 20 Feb 2024 16:40:23 +0000 Subject: [PATCH 03/19] Added manager ID to filter Signed-off-by: snipe --- .../Controllers/Api/LocationsController.php | 29 +++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/Api/LocationsController.php b/app/Http/Controllers/Api/LocationsController.php index b888493286..e1c79dfbe4 100644 --- a/app/Http/Controllers/Api/LocationsController.php +++ b/app/Http/Controllers/Api/LocationsController.php @@ -25,9 +25,27 @@ class LocationsController extends Controller { $this->authorize('view', Location::class); $allowed_columns = [ - 'id', 'name', 'address', 'address2', 'city', 'state', 'country', 'zip', 'created_at', - 'updated_at', 'manager_id', 'image', - 'assigned_assets_count', 'users_count', 'assets_count','assigned_assets_count', 'assets_count', 'rtd_assets_count', 'currency', 'ldap_ou', ]; + 'id', + 'name', + 'address', + 'address2', + 'city', + 'state', + 'country', + 'zip', + 'created_at', + 'updated_at', + 'manager_id', + 'image', + 'assigned_assets_count', + 'users_count', + 'assets_count', + 'assigned_assets_count', + 'assets_count', + 'rtd_assets_count', + 'currency', + 'ldap_ou', + ]; $locations = Location::with('parent', 'manager', 'children')->select([ 'locations.id', @@ -50,6 +68,7 @@ class LocationsController extends Controller ])->withCount('assignedAssets as assigned_assets_count') ->withCount('assets as assets_count') ->withCount('rtd_assets as rtd_assets_count') + ->withCount('children as children_count') ->withCount('users as users_count'); if ($request->filled('search')) { @@ -80,6 +99,10 @@ class LocationsController extends Controller $locations->where('locations.country', '=', $request->input('country')); } + if ($request->filled('manager_id')) { + $locations->where('locations.manager_id', '=', $request->input('manager_id')); + } + // Make sure the offset and limit are actually integers and do not exceed system limits $offset = ($request->input('offset') > $locations->count()) ? $locations->count() : app('api_offset_value'); $limit = app('api_limit_value'); From a32c679519e3eddf27074b30e5541aa4fd181697 Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 20 Feb 2024 16:40:31 +0000 Subject: [PATCH 04/19] Removed debugging Signed-off-by: snipe --- app/Http/Controllers/Api/UsersController.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/app/Http/Controllers/Api/UsersController.php b/app/Http/Controllers/Api/UsersController.php index 3eb7783e3d..6fbaf281b0 100644 --- a/app/Http/Controllers/Api/UsersController.php +++ b/app/Http/Controllers/Api/UsersController.php @@ -274,11 +274,6 @@ class UsersController extends Controller $offset = ($request->input('offset') > $users->count()) ? $users->count() : app('api_offset_value'); $limit = app('api_limit_value'); - \Log::debug('Requested offset: '. $request->input('offset')); - \Log::debug('App offset: '. app('api_offset_value')); - \Log::debug('Actual offset: '. $offset); - \Log::debug('Limit: '. $limit); - $total = $users->count(); $users = $users->skip($offset)->take($limit)->get(); From 9b146ae1d2fd80cda91ca5f0a87924c5ce78e145 Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 20 Feb 2024 16:40:51 +0000 Subject: [PATCH 05/19] Formatting for API response Signed-off-by: snipe --- app/Http/Transformers/LocationsTransformer.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Http/Transformers/LocationsTransformer.php b/app/Http/Transformers/LocationsTransformer.php index b072f9ed40..513b967f42 100644 --- a/app/Http/Transformers/LocationsTransformer.php +++ b/app/Http/Transformers/LocationsTransformer.php @@ -66,8 +66,8 @@ class LocationsTransformer 'update' => Gate::allows('update', Location::class) ? true : false, 'delete' => $location->isDeletable(), 'bulk_selectable' => [ - 'delete' => $location->isDeletable()] - , + 'delete' => $location->isDeletable() + ], 'clone' => (Gate::allows('create', Location::class) && ($location->deleted_at == '')), ]; From c3f21d92921b5f191ab8186ab7adefa70b5b8c2d Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 20 Feb 2024 16:41:58 +0000 Subject: [PATCH 06/19] Removed new checkbox selectability on users and assets - more complicated work to be done Signed-off-by: snipe --- app/Http/Transformers/AssetsTransformer.php | 1 - app/Http/Transformers/UsersTransformer.php | 1 - app/Presenters/AssetPresenter.php | 3 +-- app/Presenters/UserPresenter.php | 3 +-- 4 files changed, 2 insertions(+), 6 deletions(-) diff --git a/app/Http/Transformers/AssetsTransformer.php b/app/Http/Transformers/AssetsTransformer.php index c91bceac20..f5d5ae12b5 100644 --- a/app/Http/Transformers/AssetsTransformer.php +++ b/app/Http/Transformers/AssetsTransformer.php @@ -148,7 +148,6 @@ 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, ]; diff --git a/app/Http/Transformers/UsersTransformer.php b/app/Http/Transformers/UsersTransformer.php index 16224bb216..0ebaca2692 100644 --- a/app/Http/Transformers/UsersTransformer.php +++ b/app/Http/Transformers/UsersTransformer.php @@ -82,7 +82,6 @@ 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; diff --git a/app/Presenters/AssetPresenter.php b/app/Presenters/AssetPresenter.php index eebf92ac72..de7c2c7709 100644 --- a/app/Presenters/AssetPresenter.php +++ b/app/Presenters/AssetPresenter.php @@ -19,9 +19,8 @@ class AssetPresenter extends Presenter { $layout = [ [ - 'field' => 'bulk_selectable', + 'field' => 'checkbox', 'checkbox' => true, - 'formatter' => 'checkboxEnabledFormatter', ], [ 'field' => 'id', 'searchable' => false, diff --git a/app/Presenters/UserPresenter.php b/app/Presenters/UserPresenter.php index dd7e22656b..f70ddf8af6 100644 --- a/app/Presenters/UserPresenter.php +++ b/app/Presenters/UserPresenter.php @@ -22,9 +22,8 @@ class UserPresenter extends Presenter { $layout = [ [ - 'field' => 'bulk_selectable', + 'field' => 'checkbox', 'checkbox' => true, - 'formatter' => 'checkboxEnabledFormatter', ], [ 'field' => 'id', From b2c8fbf349b2a55fe9e94c99559770b54a5f16e4 Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 20 Feb 2024 16:42:04 +0000 Subject: [PATCH 07/19] Removed debugging Signed-off-by: snipe --- app/Providers/SettingsServiceProvider.php | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/app/Providers/SettingsServiceProvider.php b/app/Providers/SettingsServiceProvider.php index 41dd80b4fc..1c89dc2b8c 100644 --- a/app/Providers/SettingsServiceProvider.php +++ b/app/Providers/SettingsServiceProvider.php @@ -39,24 +39,12 @@ class SettingsServiceProvider extends ServiceProvider $limit = abs($int_limit); } -// \Log::debug('Max in env: '.config('app.max_results')); -// \Log::debug('Original requested limit: '.request('limit')); -// \Log::debug('Int limit: '.$int_limit); -// \Log::debug('Modified limit: '.$limit); -// \Log::debug('------------------------------'); - - return $limit; }); // Make sure the offset is actually set and is an integer \App::singleton('api_offset_value', function () { $offset = intval(request('offset')); -// \Log::debug('Original requested offset: '.request('offset')); -// \Log::debug('Modified offset: '.$offset); -// \Log::debug('------------------------------'); - - return $offset; }); From bc8db3deabddcd8cecf8a47799938790ccefa067 Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 20 Feb 2024 16:42:14 +0000 Subject: [PATCH 08/19] Added bulk delete routes Signed-off-by: snipe --- routes/web.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/routes/web.php b/routes/web.php index 635cdbcb94..88bba08f81 100644 --- a/routes/web.php +++ b/routes/web.php @@ -54,7 +54,18 @@ Route::group(['middleware' => 'auth'], function () { */ Route::group(['prefix' => 'locations', 'middleware' => ['auth']], function () { - + + Route::post( + 'bulkdelete', + [LocationsController::class, 'postBulkDelete'] + )->name('locations.bulkdelete.show'); + + Route::post( + 'bulkedit', + [LocationsController::class, 'postBulkDeleteStore'] + )->name('locations.bulkdelete.store'); + + Route::get('{locationId}/clone', [LocationsController::class, 'getClone'] )->name('clone/location'); @@ -68,6 +79,7 @@ Route::group(['middleware' => 'auth'], function () { '{locationId}/printallassigned', [LocationsController::class, 'print_all_assigned'] )->name('locations.print_all_assigned'); + }); Route::resource('locations', LocationsController::class, [ From 660f3ccba19b1bb3abd06cf4c3ef0382722536c5 Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 20 Feb 2024 16:42:28 +0000 Subject: [PATCH 09/19] Removed duplicate key Signed-off-by: snipe --- resources/lang/en-US/general.php | 1 - 1 file changed, 1 deletion(-) diff --git a/resources/lang/en-US/general.php b/resources/lang/en-US/general.php index 0754d70468..c4f120d5d5 100644 --- a/resources/lang/en-US/general.php +++ b/resources/lang/en-US/general.php @@ -443,7 +443,6 @@ return [ 'sample_value' => 'Sample Value', 'no_headers' => 'No Columns Found', 'error_in_import_file' => 'There was an error reading the CSV file: :error', - 'percent_complete' => ':percent % Complete', 'errors_importing' => 'Some Errors occurred while importing: ', 'warning' => 'WARNING: :warning', 'success_redirecting' => '"Success... Redirecting.', From d5324bce6a9dafcfef72685ab2f4d5dc3e50d35b Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 20 Feb 2024 16:43:07 +0000 Subject: [PATCH 10/19] Added more generic bulk translations for trans_choice Signed-off-by: snipe --- resources/lang/en-US/general.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/resources/lang/en-US/general.php b/resources/lang/en-US/general.php index c4f120d5d5..69627a37aa 100644 --- a/resources/lang/en-US/general.php +++ b/resources/lang/en-US/general.php @@ -182,6 +182,7 @@ return [ 'lock_passwords' => 'This field value will not be saved in a demo installation.', 'feature_disabled' => 'This feature has been disabled for the demo installation.', 'location' => 'Location', + 'location_plural' => 'Location|Locations', 'locations' => 'Locations', 'logo_size' => 'Square logos look best with Logo + Text. Logo maximum display size is 50px high x 500px wide. ', 'logout' => 'Logout', @@ -502,5 +503,15 @@ return [ 'or' => 'or', 'url' => 'URL', 'edit_fieldset' => 'Edit fieldset fields and options', + 'bulk' => [ + 'delete' => + [ + 'header' => 'Bulk Delete :object_type', + 'warn' => 'You are about to delete one :object_type|You are about to delete :count :object_type', + 'success' => ':object_type successfully deleted|Successfully deleted :count :object_type', + 'error' => 'Could not delete :object_type', + ], + + ], ]; From 8f71460fa191cdd6de3e6dd6c6945e73cdd5462a Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 20 Feb 2024 16:43:27 +0000 Subject: [PATCH 11/19] Formatting changes only Signed-off-by: snipe --- resources/views/partials/bootstrap-table.blade.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/resources/views/partials/bootstrap-table.blade.php b/resources/views/partials/bootstrap-table.blade.php index 5e247b7b5b..e26c681008 100644 --- a/resources/views/partials/bootstrap-table.blade.php +++ b/resources/views/partials/bootstrap-table.blade.php @@ -139,12 +139,12 @@ }); - // Handle whether or not the edit button should be disabled + // Handle whether the edit button should be disabled $('.snipe-table').on('uncheck.bs.table', function () { - var buttonName = $(this).data('bulk-button-id'); if ($(this).bootstrapTable('getSelections').length == 0) { + $(buttonName).attr('disabled', 'disabled'); } }); From 50b841d54d5613cdf029f00a9ed9e3c7d2faaef9 Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 20 Feb 2024 16:43:57 +0000 Subject: [PATCH 12/19] Added table data-dash attributes to make the checkbox stuff work Signed-off-by: snipe --- resources/views/locations/index.blade.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/resources/views/locations/index.blade.php b/resources/views/locations/index.blade.php index 0b368babbb..2d020cb026 100755 --- a/resources/views/locations/index.blade.php +++ b/resources/views/locations/index.blade.php @@ -20,12 +20,17 @@
+ @include('partials.locations-bulk-actions') +
Date: Tue, 20 Feb 2024 16:44:20 +0000 Subject: [PATCH 13/19] API-ify the managed locations tab in user view Signed-off-by: snipe --- resources/views/users/view.blade.php | 47 ++++++++++++++++++---------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/resources/views/users/view.blade.php b/resources/views/users/view.blade.php index c28a9079cf..cce0110cef 100755 --- a/resources/views/users/view.blade.php +++ b/resources/views/users/view.blade.php @@ -1015,23 +1015,36 @@
-
-
- - - - - - - - @foreach ($user->managedLocations as $location) - - - - - @endforeach - -
{{ trans('general.name') }}{{ trans('general.date') }}
{!! $location->present()->nameUrl() !!}{{ $location->created_at }}
+ + @include('partials.locations-bulk-actions') + + + +
+ From 1ca9420baa9cefadd7c6d7d26f967964a8128777 Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 20 Feb 2024 16:44:29 +0000 Subject: [PATCH 14/19] Fixed incorrect gate Signed-off-by: snipe --- resources/views/partials/models-bulk-actions.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/partials/models-bulk-actions.blade.php b/resources/views/partials/models-bulk-actions.blade.php index d8a3f202c7..8fca921ae1 100644 --- a/resources/views/partials/models-bulk-actions.blade.php +++ b/resources/views/partials/models-bulk-actions.blade.php @@ -6,7 +6,7 @@ 'id' => 'modelsBulkForm']) }} @if (request('status')!='deleted') - @can('delete', \App\Models\User::class) + @can('delete', \App\Models\AssetModel::class)
+ + + {{ trans('general.name') }} + + + + @foreach ($locations as $location) + assets_count > 0 ) ? ' class="danger"' : '') !!}> + + assets_count == 0) ? ' checked="checked"' : ' disabled') !!}> + + {{ $location->name }} + + + @endforeach + + +
+ + + + + + +@stop +@section('moar_scripts') + +@stop diff --git a/resources/views/partials/locations-bulk-actions.blade.php b/resources/views/partials/locations-bulk-actions.blade.php new file mode 100644 index 0000000000..47e13614b5 --- /dev/null +++ b/resources/views/partials/locations-bulk-actions.blade.php @@ -0,0 +1,20 @@ +@can('delete', \App\Models\User::class) +
+ {{ Form::open([ + 'method' => 'POST', + 'route' => ['locations.bulkdelete.show'], + 'class' => 'form-inline', + 'id' => 'locationsBulkForm']) }} + +
+ + + +
+ + {{ Form::close() }} +
+@endcan + From 9010b7acd0ed69cadaebc2389bf8e79a611ce0b7 Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 20 Feb 2024 17:27:10 +0000 Subject: [PATCH 16/19] Use isDeletable instead of asset count Signed-off-by: snipe --- resources/views/locations/bulk-delete.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/locations/bulk-delete.blade.php b/resources/views/locations/bulk-delete.blade.php index a89dff8bc2..deab1e7fbd 100644 --- a/resources/views/locations/bulk-delete.blade.php +++ b/resources/views/locations/bulk-delete.blade.php @@ -39,7 +39,7 @@ @foreach ($locations as $location) assets_count > 0 ) ? ' class="danger"' : '') !!}> - assets_count == 0) ? ' checked="checked"' : ' disabled') !!}> + isDeletable()) ? ' checked="checked"' : ' disabled') !!}> {{ $location->name }} From 972b198248b37858d62c3d7271716e27fe4df2e8 Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 20 Feb 2024 17:27:16 +0000 Subject: [PATCH 17/19] Removed debugging Signed-off-by: snipe --- app/Http/Controllers/AssetModelsController.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/app/Http/Controllers/AssetModelsController.php b/app/Http/Controllers/AssetModelsController.php index 012f40e399..484a2e2f85 100755 --- a/app/Http/Controllers/AssetModelsController.php +++ b/app/Http/Controllers/AssetModelsController.php @@ -442,7 +442,6 @@ class AssetModelsController extends Controller $del_count = 0; foreach ($models as $model) { - \Log::debug($model->id); if ($model->assets_count > 0) { $del_error_count++; @@ -452,8 +451,6 @@ class AssetModelsController extends Controller } } - \Log::debug($del_count); - \Log::debug($del_error_count); if ($del_error_count == 0) { return redirect()->route('models.index') From 179748012852f2734fa3b82685216ada2c5d1a38 Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 20 Feb 2024 17:27:56 +0000 Subject: [PATCH 18/19] Few more translations Signed-off-by: snipe --- app/Http/Controllers/LocationsController.php | 87 +++++++++++++++++++- resources/lang/en-US/general.php | 3 +- 2 files changed, 88 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/LocationsController.php b/app/Http/Controllers/LocationsController.php index 7a4b47b385..dad1d0b241 100755 --- a/app/Http/Controllers/LocationsController.php +++ b/app/Http/Controllers/LocationsController.php @@ -8,6 +8,7 @@ use App\Models\Location; use App\Models\User; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Storage; +use Illuminate\Http\Request; /** * This controller handles all actions related to Locations for @@ -238,7 +239,7 @@ class LocationsController extends Controller * @author [A. Gianotto] [] * @param int $locationId * @since [v6.0.14] - * @return View + * @return \Illuminate\Contracts\View\View */ public function getClone($locationId = null) { @@ -272,8 +273,92 @@ class LocationsController extends Controller } return redirect()->route('locations.index')->with('error', trans('admin/locations/message.does_not_exist')); + } + /** + * Returns a view that allows the user to bulk delete locations + * + * @author [A. Gianotto] [] + * @since [v6.3.1] + * @return \Illuminate\Contracts\View\View + */ + public function postBulkDelete(Request $request) + { + $locations_raw_array = $request->input('ids'); + + // Make sure some IDs have been selected + if ((is_array($locations_raw_array)) && (count($locations_raw_array) > 0)) { + $locations = Location::whereIn('id', $locations_raw_array)->get(); + + $valid_count = 0; + foreach ($locations as $location) { + if ($location->isDeletable()) { + $valid_count++; + } + } + return view('locations/bulk-delete', compact('locations'))->with('valid_count', $valid_count); + } + + return redirect()->route('models.index') + ->with('error', 'You must select at least one model to edit.'); + } + + /** + * Checks that locations can be deleted and deletes them if they can + * + * @author [A. Gianotto] [] + * @since [v6.3.1] + * @return \Illuminate\Http\RedirectResponse + */ + public function postBulkDeleteStore(Request $request) { + $locations_raw_array = $request->input('ids'); + + if ((is_array($locations_raw_array)) && (count($locations_raw_array) > 0)) { + $locations = Location::whereIn('id', $locations_raw_array)->get(); + + $success_count = 0; + $error_count = 0; + + foreach ($locations as $location) { + + // Can we delete this location? + if ($location->isDeletable()) { + $location->delete(); + $success_count++; + } else { + $error_count++; + } + } + + \Log::debug('Success count: '.$success_count); + \Log::debug('Error count: '.$error_count); + // Complete success + if ($success_count == count($locations_raw_array)) { + return redirect() + ->route('locations.index') + ->with('success', trans_choice('general.bulk.delete.success', $success_count, + ['object_type' => trans_choice('general.location_plural', $success_count), 'count' => $success_count] + )); + } + + // Partial success + if ($error_count > 0) { + return redirect() + ->route('locations.index') + ->with('warning', trans('general.bulk.partial_success', + ['success' => $success_count, 'error' => $error_count, 'object_type' => trans('general.locations')] + )); + } + } + + + // Nothing was selected - return to the index + return redirect() + ->route('locations.index') + ->with('error', trans('general.bulk.nothing_selected', + ['object_type' => trans('general.locations')] + )); } } diff --git a/resources/lang/en-US/general.php b/resources/lang/en-US/general.php index 69627a37aa..6e1663b590 100644 --- a/resources/lang/en-US/general.php +++ b/resources/lang/en-US/general.php @@ -510,8 +510,9 @@ return [ 'warn' => 'You are about to delete one :object_type|You are about to delete :count :object_type', 'success' => ':object_type successfully deleted|Successfully deleted :count :object_type', 'error' => 'Could not delete :object_type', + 'nothing_selected' => 'No :object_type selected - nothing to do', + 'partial' => 'Deleted :success_count :object_type, but :error_count :object_type could not be deleted', ], - ], ]; From cb0f9024b10eb08707bab75b9a6761d935be038a Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 20 Feb 2024 17:56:40 +0000 Subject: [PATCH 19/19] Fixed gate Signed-off-by: snipe --- resources/views/partials/locations-bulk-actions.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/partials/locations-bulk-actions.blade.php b/resources/views/partials/locations-bulk-actions.blade.php index 47e13614b5..228a68dfba 100644 --- a/resources/views/partials/locations-bulk-actions.blade.php +++ b/resources/views/partials/locations-bulk-actions.blade.php @@ -1,4 +1,4 @@ -@can('delete', \App\Models\User::class) +@can('delete', \App\Models\Location::class)
{{ Form::open([ 'method' => 'POST',