Fixed #2402 - add ability to restore manufacturers

This commit is contained in:
snipe 2018-03-03 18:46:19 -08:00
parent fabc9e5d1c
commit f7784b6543
8 changed files with 57 additions and 5 deletions

View file

@ -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']; $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( $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'); )->withCount('assets')->withCount('licenses')->withCount('consumables')->withCount('accessories');
if ($request->input('deleted')=='true') {
$manufacturers->onlyTrashed();
}
if ($request->has('search')) { if ($request->has('search')) {
$manufacturers = $manufacturers->TextSearch($request->input('search')); $manufacturers = $manufacturers->TextSearch($request->input('search'));
} }
$offset = request('offset', 0); $offset = request('offset', 0);
$limit = $request->input('limit', 50); $limit = $request->input('limit', 50);
$order = $request->input('order') === 'asc' ? 'asc' : 'desc'; $order = $request->input('order') === 'asc' ? 'asc' : 'desc';

View file

@ -242,6 +242,29 @@ class ManufacturersController extends Controller
return redirect()->route('manufacturers.index')->with('error', $error); 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'));
}

View file

@ -36,10 +36,12 @@ class ManufacturersTransformer
'accessories_count' => (int) $manufacturer->accessories_count, 'accessories_count' => (int) $manufacturer->accessories_count,
'created_at' => Helper::getFormattedDateObject($manufacturer->created_at, 'datetime'), 'created_at' => Helper::getFormattedDateObject($manufacturer->created_at, 'datetime'),
'updated_at' => Helper::getFormattedDateObject($manufacturer->updated_at, 'datetime'), 'updated_at' => Helper::getFormattedDateObject($manufacturer->updated_at, 'datetime'),
'deleted_at' => Helper::getFormattedDateObject($manufacturer->deleted_at, 'datetime'),
]; ];
$permissions_array['available_actions'] = [ $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, '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,
]; ];

View file

@ -21,7 +21,7 @@ class Manufacturer extends SnipeModel
'support_email' => 'email|nullable' 'support_email' => 'email|nullable'
); );
protected $hidden = ['user_id','deleted_at']; protected $hidden = ['user_id'];

View file

@ -15,6 +15,11 @@ return array(
'success' => 'Manufacturer updated successfully.' 'success' => 'Manufacturer updated successfully.'
), ),
'restore' => array(
'error' => 'Manufacturer was not restored, please try again',
'success' => 'Manufacturer restored successfully.'
),
'delete' => array( 'delete' => array(
'confirm' => 'Are you sure you wish to delete this manufacturer?', 'confirm' => 'Are you sure you wish to delete this manufacturer?',
'error' => 'There was an issue deleting the manufacturer. Please try again.', 'error' => 'There was an issue deleting the manufacturer. Please try again.',

View file

@ -175,9 +175,11 @@
'select_company' => 'Select Company', 'select_company' => 'Select Company',
'select_asset' => 'Select Asset', 'select_asset' => 'Select Asset',
'settings' => 'Settings', 'settings' => 'Settings',
'show_deleted' => 'Show Deleted',
'show_current' => 'Show Current',
'sign_in' => 'Sign in', 'sign_in' => 'Sign in',
'signature' => 'Signature', 'signature' => 'Signature',
'skin' => 'Skin', 'skin' => 'Skin',
'some_features_disabled' => 'DEMO MODE: Some features are disabled for this installation.', 'some_features_disabled' => 'DEMO MODE: Some features are disabled for this installation.',
'site_name' => 'Site Name', 'site_name' => 'Site Name',
'state' => 'State', 'state' => 'State',

View file

@ -12,6 +12,14 @@
<a href="{{ route('manufacturers.create') }}" class="btn btn-primary pull-right"> <a href="{{ route('manufacturers.create') }}" class="btn btn-primary pull-right">
{{ trans('general.create') }}</a> {{ trans('general.create') }}</a>
@endcan @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 @stop
{{-- Page content --}} {{-- Page content --}}
@ -37,7 +45,7 @@
data-sort-order="asc" data-sort-order="asc"
id="manufacturersTable" id="manufacturersTable"
class="table table-striped snipe-table" 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='{ data-export-options='{
"fileName": "export-manufacturers-{{ date('Y-m-d') }}", "fileName": "export-manufacturers-{{ date('Y-m-d') }}",
"ignoreColumn": ["actions","image","change","checkbox","checkincheckout","icon"] "ignoreColumn": ["actions","image","change","checkbox","checkincheckout","icon"]

View file

@ -26,6 +26,12 @@ Route::group(['middleware' => 'auth'], function () {
/* /*
* Manufacturers * Manufacturers
*/ */
Route::group([ 'prefix' => 'manufacturers', 'middleware' => ['auth'] ], function () {
Route::get('{manufacturers_id}/restore', [ 'as' => 'restore/manufacturer', 'uses' => 'ManufacturersController@restore']);
});
Route::resource('manufacturers', 'ManufacturersController', [ Route::resource('manufacturers', 'ManufacturersController', [
'parameters' => ['manufacturer' => 'manufacturers_id'] 'parameters' => ['manufacturer' => 'manufacturers_id']
]); ]);