mirror of
https://github.com/snipe/snipe-it.git
synced 2025-02-21 03:15:45 -08:00
Fixed #2402 - add ability to restore manufacturers
This commit is contained in:
parent
fabc9e5d1c
commit
f7784b6543
|
@ -25,14 +25,20 @@ class ManufacturersController extends Controller
|
|||
$allowed_columns = ['id','name','url','support_url','support_email','support_phone','created_at','updated_at','image', 'assets_count', 'consumables_count', 'components_count', 'licenses_count'];
|
||||
|
||||
$manufacturers = Manufacturer::select(
|
||||
array('id','name','url','support_url','support_email','support_phone','created_at','updated_at','image')
|
||||
array('id','name','url','support_url','support_email','support_phone','created_at','updated_at','image', 'deleted_at')
|
||||
)->withCount('assets')->withCount('licenses')->withCount('consumables')->withCount('accessories');
|
||||
|
||||
if ($request->input('deleted')=='true') {
|
||||
$manufacturers->onlyTrashed();
|
||||
}
|
||||
|
||||
if ($request->has('search')) {
|
||||
$manufacturers = $manufacturers->TextSearch($request->input('search'));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
$offset = request('offset', 0);
|
||||
$limit = $request->input('limit', 50);
|
||||
$order = $request->input('order') === 'asc' ? 'asc' : 'desc';
|
||||
|
|
|
@ -242,6 +242,29 @@ class ManufacturersController extends Controller
|
|||
return redirect()->route('manufacturers.index')->with('error', $error);
|
||||
}
|
||||
|
||||
/**
|
||||
* Restore a given Manufacturer (mark as un-deleted)
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v4.1.15]
|
||||
* @param int $id
|
||||
* @return Redirect
|
||||
*/
|
||||
public function restore($manufacturers_id)
|
||||
{
|
||||
$this->authorize('create', Manufacturer::class);
|
||||
$manufacturer = Manufacturer::onlyTrashed()->where('id',$manufacturers_id)->first();
|
||||
|
||||
if ($manufacturer) {
|
||||
// I don't know why $manufacturer->restore(); didn't work here...
|
||||
// $manufacturer->restore();
|
||||
return redirect()->route('manufacturers.index')->with('success', trans('admin/manufacturers/message.restore.success'));
|
||||
}
|
||||
\Log::debug('No joy');
|
||||
return redirect()->back()->with('error', trans('admin/manufacturers/message.does_not_exist'));
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -36,10 +36,12 @@ class ManufacturersTransformer
|
|||
'accessories_count' => (int) $manufacturer->accessories_count,
|
||||
'created_at' => Helper::getFormattedDateObject($manufacturer->created_at, 'datetime'),
|
||||
'updated_at' => Helper::getFormattedDateObject($manufacturer->updated_at, 'datetime'),
|
||||
'deleted_at' => Helper::getFormattedDateObject($manufacturer->deleted_at, 'datetime'),
|
||||
];
|
||||
|
||||
$permissions_array['available_actions'] = [
|
||||
'update' => Gate::allows('update', Manufacturer::class) ? true : false,
|
||||
'update' => (($manufacturer->deleted_at=='') && (Gate::allows('update', Manufacturer::class))) ? true : false,
|
||||
'restore' => (($manufacturer->deleted_at!='') && (Gate::allows('create', Manufacturer::class))) ? true : false,
|
||||
'delete' => (Gate::allows('delete', Manufacturer::class) && ($manufacturer->assets_count == 0) && ($manufacturer->licenses_count==0) && ($manufacturer->consumables_count==0) && ($manufacturer->accessories_count==0) && ($manufacturer->deleted_at=='')) ? true : false,
|
||||
];
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ class Manufacturer extends SnipeModel
|
|||
'support_email' => 'email|nullable'
|
||||
);
|
||||
|
||||
protected $hidden = ['user_id','deleted_at'];
|
||||
protected $hidden = ['user_id'];
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -15,6 +15,11 @@ return array(
|
|||
'success' => 'Manufacturer updated successfully.'
|
||||
),
|
||||
|
||||
'restore' => array(
|
||||
'error' => 'Manufacturer was not restored, please try again',
|
||||
'success' => 'Manufacturer restored successfully.'
|
||||
),
|
||||
|
||||
'delete' => array(
|
||||
'confirm' => 'Are you sure you wish to delete this manufacturer?',
|
||||
'error' => 'There was an issue deleting the manufacturer. Please try again.',
|
||||
|
|
|
@ -175,9 +175,11 @@
|
|||
'select_company' => 'Select Company',
|
||||
'select_asset' => 'Select Asset',
|
||||
'settings' => 'Settings',
|
||||
'show_deleted' => 'Show Deleted',
|
||||
'show_current' => 'Show Current',
|
||||
'sign_in' => 'Sign in',
|
||||
'signature' => 'Signature',
|
||||
'skin' => 'Skin',
|
||||
'skin' => 'Skin',
|
||||
'some_features_disabled' => 'DEMO MODE: Some features are disabled for this installation.',
|
||||
'site_name' => 'Site Name',
|
||||
'state' => 'State',
|
||||
|
|
|
@ -12,6 +12,14 @@
|
|||
<a href="{{ route('manufacturers.create') }}" class="btn btn-primary pull-right">
|
||||
{{ trans('general.create') }}</a>
|
||||
@endcan
|
||||
|
||||
@if (Input::get('deleted')=='true')
|
||||
<a class="btn btn-default pull-right" href="{{ route('manufacturers.index') }}" style="margin-right: 5px;">{{ trans('general.show_current') }}</a>
|
||||
@else
|
||||
<a class="btn btn-default pull-right" href="{{ route('manufacturers.index', ['deleted' => 'true']) }}" style="margin-right: 5px;">
|
||||
{{ trans('general.show_deleted') }}</a>
|
||||
@endif
|
||||
|
||||
@stop
|
||||
|
||||
{{-- Page content --}}
|
||||
|
@ -37,7 +45,7 @@
|
|||
data-sort-order="asc"
|
||||
id="manufacturersTable"
|
||||
class="table table-striped snipe-table"
|
||||
data-url="{{route('api.manufacturers.index') }}"
|
||||
data-url="{{route('api.manufacturers.index', ['deleted' => e(Input::get('deleted')) ]) }}"
|
||||
data-export-options='{
|
||||
"fileName": "export-manufacturers-{{ date('Y-m-d') }}",
|
||||
"ignoreColumn": ["actions","image","change","checkbox","checkincheckout","icon"]
|
||||
|
|
|
@ -26,6 +26,12 @@ Route::group(['middleware' => 'auth'], function () {
|
|||
/*
|
||||
* Manufacturers
|
||||
*/
|
||||
|
||||
Route::group([ 'prefix' => 'manufacturers', 'middleware' => ['auth'] ], function () {
|
||||
|
||||
Route::get('{manufacturers_id}/restore', [ 'as' => 'restore/manufacturer', 'uses' => 'ManufacturersController@restore']);
|
||||
});
|
||||
|
||||
Route::resource('manufacturers', 'ManufacturersController', [
|
||||
'parameters' => ['manufacturer' => 'manufacturers_id']
|
||||
]);
|
||||
|
|
Loading…
Reference in a new issue