-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Added ability to bulk delete locations
- Loading branch information
Showing
16 changed files
with
295 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
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 @@ public function print_assigned($id) | |
* @author [A. Gianotto] [<[email protected]>] | ||
* @param int $locationId | ||
* @since [v6.0.14] | ||
* @return View | ||
* @return \Illuminate\Contracts\View\View | ||
*/ | ||
public function getClone($locationId = null) | ||
{ | ||
|
@@ -272,8 +273,92 @@ public function print_all_assigned($id) | |
|
||
} | ||
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] [<[email protected]>] | ||
* @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] [<[email protected]>] | ||
* @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')] | ||
)); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
@extends('layouts/default') | ||
|
||
{{-- Page title --}} | ||
@section('title') | ||
{{ trans('general.bulk.delete.header', ['object_type' => trans_choice('general.location_plural', $valid_count)]) }} | ||
@parent | ||
@stop | ||
|
||
@section('header_right') | ||
<a href="{{ URL::previous() }}" class="btn btn-primary pull-right"> | ||
{{ trans('general.back') }}</a> | ||
@stop | ||
|
||
{{-- Page content --}} | ||
@section('content') | ||
<div class="row"> | ||
<!-- left column --> | ||
<div class="col-md-8 col-md-offset-2"> | ||
<form class="form-horizontal" method="post" action="{{ route('locations.bulkdelete.store') }}" autocomplete="off" role="form"> | ||
{{csrf_field()}} | ||
<div class="box box-default"> | ||
<div class="box-header with-border"> | ||
<h2 class="box-title" style="color: red">{{ trans_choice('general.bulk.delete.warn', $valid_count, ['count' => $valid_count,'object_type' => trans_choice('general.location_plural', $valid_count)]) }}</h2> | ||
</div> | ||
|
||
<div class="box-body"> | ||
<table class="table table-striped table-condensed"> | ||
<thead> | ||
<tr> | ||
<td class="col-md-1"> | ||
<label> | ||
<input type="checkbox" id="checkAll" checked="checked"> | ||
</label> | ||
</td> | ||
<td class="col-md-10">{{ trans('general.name') }}</td> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
@foreach ($locations as $location) | ||
<tr{!! (($location->assets_count > 0 ) ? ' class="danger"' : '') !!}> | ||
<td> | ||
<input type="checkbox" name="ids[]" class="{ ($location->isDeletable() ? '' : ' disabled') }}" value="{{ $location->id }}" {!! (($location->isDeletable()) ? ' checked="checked"' : ' disabled') !!}> | ||
</td> | ||
<td>{{ $location->name }}</td> | ||
|
||
</tr> | ||
@endforeach | ||
</tbody> | ||
</table> | ||
</div><!-- /.box-body --> | ||
|
||
<div class="box-footer text-right"> | ||
<a class="btn btn-link pull-left" href="{{ URL::previous() }}">{{ trans('button.cancel') }}</a> | ||
<button type="submit" class="btn btn-success" id="submit-button"><i class="fas fa-check icon-white" aria-hidden="true"></i> {{ trans('general.delete') }}</button> | ||
</div><!-- /.box-footer --> | ||
</div><!-- /.box --> | ||
</form> | ||
</div> <!-- .col-md-12--> | ||
</div><!--.row--> | ||
@stop | ||
@section('moar_scripts') | ||
<script> | ||
$("#checkAll").change(function () { | ||
$("input:checkbox").prop('checked', $(this).prop("checked")); | ||
}); | ||
</script> | ||
@stop |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.