mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-26 06:04:08 -08:00
Merge pull request #11027 from snipe/features/add_bulk_edit_to_other_asset_views
Fixed #11026 - add bulk edit to other asset views
This commit is contained in:
commit
e353780b1b
|
@ -11,6 +11,7 @@ use App\Models\Setting;
|
|||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
|
||||
class BulkAssetsController extends Controller
|
||||
{
|
||||
|
@ -30,9 +31,17 @@ class BulkAssetsController extends Controller
|
|||
$this->authorize('update', Asset::class);
|
||||
|
||||
if (! $request->filled('ids')) {
|
||||
return redirect()->back()->with('error', 'No assets selected');
|
||||
return redirect()->back()->with('error', trans('admin/hardware/message.update.no_assets_selected'));
|
||||
|
||||
}
|
||||
|
||||
// Figure out where we need to send the user after the update is complete, and store that in the session
|
||||
$bulk_back_url = request()->headers->get('referer');
|
||||
session(['bulk_back_url' => $bulk_back_url]);
|
||||
|
||||
\Log::debug('Back to url: '.$bulk_back_url);
|
||||
|
||||
|
||||
|
||||
$asset_ids = array_values(array_unique($request->input('ids')));
|
||||
|
||||
|
@ -73,10 +82,15 @@ class BulkAssetsController extends Controller
|
|||
{
|
||||
$this->authorize('update', Asset::class);
|
||||
|
||||
\Log::debug($request->input('ids'));
|
||||
// Get the back url from the session and then destroy the session
|
||||
$bulk_back_url = route('hardware');
|
||||
if ($request->session()->has('bulk_back_url')) {
|
||||
$bulk_back_url = $request->session()->pull('bulk_back_url');
|
||||
}
|
||||
|
||||
|
||||
if (! $request->filled('ids') || count($request->input('ids')) <= 0) {
|
||||
return redirect()->route('hardware.index')->with('warning', trans('No assets selected, so nothing was updated.'));
|
||||
return redirect($bulk_back_url)->with('error', trans('admin/hardware/message.update.no_assets_selected'));
|
||||
}
|
||||
|
||||
$assets = array_keys($request->input('ids'));
|
||||
|
@ -147,11 +161,13 @@ class BulkAssetsController extends Controller
|
|||
->update($this->update_array);
|
||||
} // endforeach
|
||||
|
||||
return redirect()->route('hardware.index')->with('success', trans('admin/hardware/message.update.success'));
|
||||
// no values given, nothing to update
|
||||
return redirect($bulk_back_url)->with('success', trans('admin/hardware/message.update.success'));
|
||||
|
||||
|
||||
}
|
||||
|
||||
return redirect()->route('hardware.index')->with('warning', trans('admin/hardware/message.update.nothing_updated'));
|
||||
// no values given, nothing to update
|
||||
return redirect($bulk_back_url)->with('warning', trans('admin/hardware/message.update.nothing_updated'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -188,6 +204,11 @@ class BulkAssetsController extends Controller
|
|||
{
|
||||
$this->authorize('delete', Asset::class);
|
||||
|
||||
$bulk_back_url = route('hardware');
|
||||
if ($request->session()->has('bulk_back_url')) {
|
||||
$bulk_back_url = $request->session()->pull('bulk_back_url');
|
||||
}
|
||||
|
||||
if ($request->filled('ids')) {
|
||||
$assets = Asset::find($request->get('ids'));
|
||||
foreach ($assets as $asset) {
|
||||
|
@ -199,11 +220,11 @@ class BulkAssetsController extends Controller
|
|||
->update($update_array);
|
||||
} // endforeach
|
||||
|
||||
return redirect()->to('hardware')->with('success', trans('admin/hardware/message.delete.success'));
|
||||
return redirect($bulk_back_url)->with('success', trans('admin/hardware/message.delete.success'));
|
||||
// no values given, nothing to update
|
||||
}
|
||||
|
||||
return redirect()->to('hardware')->with('info', trans('admin/hardware/message.delete.nothing_updated'));
|
||||
return redirect($bulk_back_url)->with('error', trans('admin/hardware/message.delete.nothing_updated'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -224,6 +245,9 @@ class BulkAssetsController extends Controller
|
|||
*/
|
||||
public function storeCheckout(Request $request)
|
||||
{
|
||||
|
||||
$this->authorize('checkout', Asset::class);
|
||||
|
||||
try {
|
||||
$admin = Auth::user();
|
||||
|
||||
|
|
|
@ -17,6 +17,10 @@ class AssetAuditPresenter extends Presenter
|
|||
public static function dataTableLayout()
|
||||
{
|
||||
$layout = [
|
||||
[
|
||||
'field' => 'checkbox',
|
||||
'checkbox' => true,
|
||||
],
|
||||
[
|
||||
'field' => 'id',
|
||||
'searchable' => false,
|
||||
|
|
|
@ -17,6 +17,7 @@ return [
|
|||
'error' => 'Asset was not updated, please try again',
|
||||
'success' => 'Asset updated successfully.',
|
||||
'nothing_updated' => 'No fields were selected, so nothing was updated.',
|
||||
'no_assets_selected' => 'No assets were selected, so nothing was updated.',
|
||||
],
|
||||
|
||||
'restore' => [
|
||||
|
|
|
@ -17,6 +17,7 @@ return [
|
|||
'error' => 'Asset was not updated, please try again',
|
||||
'success' => 'Asset updated successfully.',
|
||||
'nothing_updated' => 'No fields were selected, so nothing was updated.',
|
||||
'no_assets_selected' => 'No assets were selected, so nothing was updated.',
|
||||
],
|
||||
|
||||
'restore' => [
|
||||
|
|
|
@ -28,6 +28,9 @@
|
|||
<div class="col-md-12">
|
||||
<div class="box box-default">
|
||||
<div class="box-body">
|
||||
@if ($category->category_type=='asset')
|
||||
@include('partials.asset-bulk-actions')
|
||||
@endif
|
||||
|
||||
<table
|
||||
|
||||
|
|
|
@ -23,11 +23,9 @@
|
|||
<div class="col-md-12">
|
||||
<div class="box">
|
||||
<div class="box-body">
|
||||
{{ Form::open([
|
||||
'method' => 'POST',
|
||||
'route' => ['hardware/bulkedit'],
|
||||
'class' => 'form-inline',
|
||||
'id' => 'bulkForm']) }}
|
||||
|
||||
@include('partials.asset-bulk-actions')
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
|
||||
|
|
|
@ -143,7 +143,7 @@
|
|||
<input type="radio" class="minimal" name="requestable" value="0"> {{ trans('general.no')}}
|
||||
</label>
|
||||
<label class="radio">
|
||||
<input type="radio" class="minimal" name="requestable" value=""> {{ trans('general.do_not_change')}}
|
||||
<input type="radio" class="minimal" name="requestable" value="" checked> {{ trans('general.do_not_change')}}
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -65,24 +65,7 @@
|
|||
|
||||
|
||||
|
||||
<div id="toolbar">
|
||||
{{ Form::open([
|
||||
'method' => 'POST',
|
||||
'route' => ['hardware/bulkedit'],
|
||||
'class' => 'form-inline',
|
||||
'id' => 'bulkForm']) }}
|
||||
|
||||
|
||||
<label for="bulk_actions"><span class="sr-only">{{ trans('button.bulk_actions') }}</span></label>
|
||||
<select name="bulk_actions" class="form-control select2" aria-label="bulk_actions">
|
||||
<option value="edit">{{ trans('button.edit') }}</option>
|
||||
<option value="delete">{{ trans('button.delete') }}</option>
|
||||
<option value="labels">{{ trans_choice('button.generate_labels', 2) }}</option>
|
||||
</select>
|
||||
|
||||
<button class="btn btn-primary" id="bulkEdit" disabled>{{ trans('button.go') }}</button>
|
||||
{{ Form::close() }}
|
||||
</div>
|
||||
@include('partials.asset-bulk-actions')
|
||||
|
||||
@endif
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
</div>
|
||||
</div>
|
||||
<div class="box-body">
|
||||
|
||||
<div class="table table-responsive">
|
||||
|
||||
<table
|
||||
|
@ -56,6 +57,10 @@
|
|||
</div>
|
||||
</div>
|
||||
<div class="box-body">
|
||||
|
||||
|
||||
@include('partials.asset-bulk-actions')
|
||||
|
||||
<div class="table table-responsive">
|
||||
|
||||
<table
|
||||
|
|
|
@ -45,6 +45,8 @@
|
|||
<div class="tab-content">
|
||||
<div class="tab-pane fade in active" id="assets">
|
||||
|
||||
@include('partials.asset-bulk-actions')
|
||||
<div class="table table-responsive">
|
||||
<table
|
||||
data-columns="{{ \App\Presenters\AssetPresenter::dataTableLayout() }}"
|
||||
data-cookie-id-table="assetsListingTable"
|
||||
|
@ -65,6 +67,7 @@
|
|||
"ignoreColumn": ["actions","image","change","checkbox","checkincheckout","icon"]
|
||||
}'>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
</div> <!-- /.tab-pane assets -->
|
||||
|
||||
|
|
|
@ -42,21 +42,11 @@
|
|||
</div><!-- /.box-header -->
|
||||
@endif
|
||||
<div class="box-body">
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
{{ Form::open([
|
||||
'method' => 'POST',
|
||||
'route' => ['hardware/bulkedit'],
|
||||
'class' => 'form-inline',
|
||||
'id' => 'bulkForm']) }}
|
||||
<div id="toolbar">
|
||||
<select name="bulk_actions" class="form-control select2">
|
||||
<option value="edit">{{ trans('button.edit') }}</option>
|
||||
<option value="delete">{{ trans('button.delete') }}</option>
|
||||
<option value="labels">{{ trans_choice('button.generate_labels', 2) }}</option>
|
||||
</select>
|
||||
<button class="btn btn-primary" id="bulkEdit" disabled>{{ trans('button.go') }}</button>
|
||||
</div>
|
||||
|
||||
@include('partials.asset-bulk-actions')
|
||||
|
||||
|
||||
|
||||
|
||||
<table
|
||||
data-columns="{{ \App\Presenters\AssetPresenter::dataTableLayout() }}"
|
||||
|
@ -79,8 +69,7 @@
|
|||
}'>
|
||||
</table>
|
||||
{{ Form::close() }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div> <!-- /.box-body-->
|
||||
</div> <!-- /.box-default-->
|
||||
</div> <!-- /.col-md-9-->
|
||||
|
|
22
resources/views/partials/asset-bulk-actions.blade.php
Normal file
22
resources/views/partials/asset-bulk-actions.blade.php
Normal file
|
@ -0,0 +1,22 @@
|
|||
<div id="toolbar">
|
||||
{{ Form::open([
|
||||
'method' => 'POST',
|
||||
'route' => ['hardware/bulkedit'],
|
||||
'class' => 'form-inline',
|
||||
'id' => 'bulkForm']) }}
|
||||
|
||||
|
||||
<label for="bulk_actions">
|
||||
<span class="sr-only">
|
||||
{{ trans('button.bulk_actions') }}
|
||||
</span>
|
||||
</label>
|
||||
<select name="bulk_actions" class="form-control select2" aria-label="bulk_actions">
|
||||
<option value="edit">{{ trans('button.edit') }}</option>
|
||||
<option value="delete">{{ trans('button.delete') }}</option>
|
||||
<option value="labels">{{ trans_choice('button.generate_labels', 2) }}</option>
|
||||
</select>
|
||||
|
||||
<button class="btn btn-primary" id="bulkEdit" disabled>{{ trans('button.go') }}</button>
|
||||
{{ Form::close() }}
|
||||
</div>
|
|
@ -61,7 +61,8 @@
|
|||
<li>
|
||||
<a href="#consumables" data-toggle="tab">
|
||||
<span class="hidden-lg hidden-md">
|
||||
<i class="fas fa-tint fa-2x"></i></span>
|
||||
<i class="fas fa-tint fa-2x"></i>
|
||||
</span>
|
||||
<span class="hidden-xs hidden-sm">{{ trans('general.consumables') }}
|
||||
{!! ($user->consumables->count() > 0 ) ? '<badge class="badge badge-secondary">'.$user->consumables->count().'</badge>' : '' !!}
|
||||
</span>
|
||||
|
@ -71,7 +72,8 @@
|
|||
<li>
|
||||
<a href="#files" data-toggle="tab">
|
||||
<span class="hidden-lg hidden-md">
|
||||
<i class="far fa-file fa-2x"></i></span>
|
||||
<i class="far fa-file fa-2x"></i>
|
||||
</span>
|
||||
<span class="hidden-xs hidden-sm">{{ trans('general.file_uploads') }}
|
||||
{!! ($user->uploads->count() > 0 ) ? '<badge class="badge badge-secondary">'.$user->uploads->count().'</badge>' : '' !!}
|
||||
</span>
|
||||
|
@ -81,7 +83,8 @@
|
|||
<li>
|
||||
<a href="#history" data-toggle="tab">
|
||||
<span class="hidden-lg hidden-md">
|
||||
<i class="fas fa-history fa-2x"></i></span>
|
||||
<i class="fas fa-history fa-2x"></i>
|
||||
</span>
|
||||
<span class="hidden-xs hidden-sm">{{ trans('general.history') }}</span>
|
||||
</a>
|
||||
</li>
|
||||
|
@ -345,7 +348,7 @@
|
|||
<div class="row">
|
||||
|
||||
<div class="col-md-3">
|
||||
{{ trans('admin/users/table.employee_num') }}<
|
||||
{{ trans('admin/users/table.employee_num') }}
|
||||
</div>
|
||||
<div class="col-md-9">
|
||||
{{ $user->employee_num }}
|
||||
|
@ -563,10 +566,13 @@
|
|||
</div> <!--/.row-->
|
||||
</div><!-- /.tab-pane -->
|
||||
|
||||
|
||||
<div class="tab-pane" id="asset">
|
||||
<!-- checked out assets table -->
|
||||
<div class="table-responsive table-striped">
|
||||
|
||||
@include('partials.asset-bulk-actions')
|
||||
|
||||
<div class="table table-responsive">
|
||||
|
||||
<table
|
||||
data-click-to-select="true"
|
||||
data-columns="{{ \App\Presenters\AssetPresenter::dataTableLayout() }}"
|
||||
|
@ -793,6 +799,7 @@
|
|||
<div class="tab-pane" id="history">
|
||||
<div class="table-responsive">
|
||||
|
||||
|
||||
<table
|
||||
data-click-to-select="true"
|
||||
data-cookie-id-table="usersHistoryTable"
|
||||
|
@ -804,7 +811,6 @@
|
|||
data-show-export="true"
|
||||
data-show-refresh="true"
|
||||
data-sort-order="desc"
|
||||
data-toolbar="#toolbar"
|
||||
id="usersHistoryTable"
|
||||
class="table table-striped snipe-table"
|
||||
data-url="{{ route('api.activity.index', ['target_id' => $user->id, 'target_type' => 'user']) }}"
|
||||
|
|
Loading…
Reference in a new issue