Refactor controller to use one method that shows all modals based on name.

This commit is contained in:
Daniel Meltzer 2020-05-23 12:19:19 -04:00
parent 25d6ceee6e
commit 7ea862787c
No known key found for this signature in database
GPG key ID: 91C5C7B09A5B1CA0
18 changed files with 34 additions and 74 deletions

2
.gitattributes vendored
View file

@ -1 +1,3 @@
* text=auto * text=auto
public/js/** binary
public/css/** binary

View file

@ -6,47 +6,15 @@ use App\Helpers\Helper;
class ModalController extends Controller class ModalController extends Controller
{ {
function location() { function show($type, $itemId = null) {
return view('modals.location'); $view = view("modals.${type}");
}
function model() { if($type == "statuslabel") {
return view('modals.model'); $view->with('statuslabel_types', Helper::statusTypeList());
} }
if(in_array($type, ['kit-model', 'kit-license', 'kit-consumable', 'kit-accessory'])) {
function statuslabel() { $view->with('kitId', $itemId);
return view('modals.statuslabel')->with('statuslabel_types', Helper::statusTypeList());
} }
return $view;
function supplier() {
return view('modals.supplier');
}
function user() {
return view('modals.user');
}
function category() {
return view('modals.category');
}
function manufacturer() {
return view('modals.manufacturer');
}
function kitModel() {
return view('modals.kit-model');
}
function kitLicense() {
return view('modals.kit-license');
}
function kitConsumable() {
return view('modals.kit-consumable');
}
function kitAccessory() {
return view('modals.kit-accessory');
} }
} }

View file

@ -11,7 +11,7 @@
Create a Button looking like this: Create a Button looking like this:
<a href='{{ route('modal.user') }}' data-toggle="modal" data-target="#createModal" data-select='assigned_to' class="btn btn-sm btn-primary">New</a> <a href='{{ route('modal.show', 'user') }}' data-toggle="modal" data-target="#createModal" data-select='assigned_to' class="btn btn-sm btn-primary">New</a>
If you don't have access to Blade commands (like {{ and }}, etc), you can hard-code a URL as the 'href' If you don't have access to Blade commands (like {{ and }}, etc), you can hard-code a URL as the 'href'

View file

@ -39,7 +39,7 @@
"ignoreColumn": ["actions","image","change","checkbox","checkincheckout","icon"] "ignoreColumn": ["actions","image","change","checkbox","checkincheckout","icon"]
}'> }'>
</table> </table>
<a href="{{ route('modal.kit.model', ['kit' => $item->id]) }}" data-refresh="kitModelsTable" data-toggle="modal" data-target="#createModal" class="btn btn-primary pull-right"><i class="fa fa-plus icon-white"></i> Append</a> <a href="{{ route('modal.show', ['type' => 'kit-model', 'itemId' => $item->id]) }}" data-refresh="kitModelsTable" data-toggle="modal" data-target="#createModal" class="btn btn-primary pull-right"><i class="fa fa-plus icon-white"></i> Append</a>
</div> </div>
</div> <!--.box-body--> </div> <!--.box-body-->
</div> <!-- /.box.box-default--> </div> <!-- /.box.box-default-->
@ -73,7 +73,7 @@
"ignoreColumn": ["actions","image","change","checkbox","checkincheckout","icon"] "ignoreColumn": ["actions","image","change","checkbox","checkincheckout","icon"]
}'> }'>
</table> </table>
<a href="{{ route('modal.kit.license', ['kit' => $item->id]) }}" data-refresh="kitLicensesTable" data-toggle="modal" data-target="#createModal" class="btn btn-primary pull-right"><i class="fa fa-plus icon-white"></i> Append{{-- TODO: trans --}}</a> <a href="{{ route('modal.show', [ 'type' => 'kit-license', 'itemId' => $item->id]) }}" data-refresh="kitLicensesTable" data-toggle="modal" data-target="#createModal" class="btn btn-primary pull-right"><i class="fa fa-plus icon-white"></i> Append{{-- TODO: trans --}}</a>
</div> </div>
</div> <!--.box-body--> </div> <!--.box-body-->
</div> <!-- /.box.box-default--> </div> <!-- /.box.box-default-->
@ -107,7 +107,7 @@
"ignoreColumn": ["actions","image","change","checkbox","checkincheckout","icon"] "ignoreColumn": ["actions","image","change","checkbox","checkincheckout","icon"]
}'> }'>
</table> </table>
<a href="{{ route('modal.kit.consumable', ['kit' => $item->id]) }}" data-refresh="kitConsumablesTable" data-toggle="modal" data-target="#createModal" class="btn btn-primary pull-right"><i class="fa fa-plus icon-white"></i> Append{{-- TODO: trans --}}</a> <a href="{{ route('modal.show', ['type' => 'kit-consumable', 'itemId' => $item->id]) }}" data-refresh="kitConsumablesTable" data-toggle="modal" data-target="#createModal" class="btn btn-primary pull-right"><i class="fa fa-plus icon-white"></i> Append{{-- TODO: trans --}}</a>
</div> </div>
</div> <!--.box-body--> </div> <!--.box-body-->
</div> <!-- /.box.box-default--> </div> <!-- /.box.box-default-->
@ -141,7 +141,7 @@
"ignoreColumn": ["actions","image","change","checkbox","checkincheckout","icon"] "ignoreColumn": ["actions","image","change","checkbox","checkincheckout","icon"]
}'> }'>
</table> </table>
<a href="{{ route('modal.kit.accessory', ['kit' => $item->id]) }}" data-refresh="kitAccessoriesTable" data-toggle="modal" data-target="#createModal" class="btn btn-primary pull-right"><i class="fa fa-plus icon-white"></i> Append{{-- TODO: trans --}}</a> <a href="{{ route('modal.show', ['type' => 'kit-accessory', 'itemId' => $item->id]) }}" data-refresh="kitAccessoriesTable" data-toggle="modal" data-target="#createModal" class="btn btn-primary pull-right"><i class="fa fa-plus icon-white"></i> Append{{-- TODO: trans --}}</a>
</div> </div>
</div> <!--.box-body--> </div> <!--.box-body-->
</div> <!-- /.box.box-default--> </div> <!-- /.box.box-default-->

View file

@ -7,7 +7,7 @@
<h4 class="modal-title">Append accessory{{-- TODO: trans --}}</h4> <h4 class="modal-title">Append accessory{{-- TODO: trans --}}</h4>
</div> </div>
<div class="modal-body"> <div class="modal-body">
<form action="{{ route('api.kits.accessories.store', ['kit_id' => request('kit')]) }}" onsubmit="return false"> <form action="{{ route('api.kits.accessories.store', $kitId) }}" onsubmit="return false">
{{ csrf_field() }} {{ csrf_field() }}
<div class="alert alert-danger" id="modal_error_msg" style="display:none"> <div class="alert alert-danger" id="modal_error_msg" style="display:none">
</div> </div>

View file

@ -7,7 +7,7 @@
<h4 class="modal-title">Append consumable{{-- TODO: trans --}}</h4> <h4 class="modal-title">Append consumable{{-- TODO: trans --}}</h4>
</div> </div>
<div class="modal-body"> <div class="modal-body">
<form action="{{ route('api.kits.consumables.store', ['kit_id' => request('kit')]) }}" onsubmit="return false"> <form action="{{ route('api.kits.consumables.store', $kitId) }}" onsubmit="return false">
{{ csrf_field() }} {{ csrf_field() }}
<div class="alert alert-danger" id="modal_error_msg" style="display:none"> <div class="alert alert-danger" id="modal_error_msg" style="display:none">
</div> </div>

View file

@ -7,7 +7,7 @@
<h4 class="modal-title">Append license{{-- TODO: trans --}}</h4> <h4 class="modal-title">Append license{{-- TODO: trans --}}</h4>
</div> </div>
<div class="modal-body"> <div class="modal-body">
<form action="{{ route('api.kits.licenses.store', ['kit_id' => request('kit')]) }}" onsubmit="return false"> <form action="{{ route('api.kits.licenses.store', $kitId) }}" onsubmit="return false">
{{ csrf_field() }} {{ csrf_field() }}
<div class="alert alert-danger" id="modal_error_msg" style="display:none"> <div class="alert alert-danger" id="modal_error_msg" style="display:none">
</div> </div>

View file

@ -7,7 +7,7 @@
<h4 class="modal-title">Append model{{-- TODO: trans --}}</h4> <h4 class="modal-title">Append model{{-- TODO: trans --}}</h4>
</div> </div>
<div class="modal-body"> <div class="modal-body">
<form action="{{ route('api.kits.models.store', ['kit_id' => request('kit')]) }}" onsubmit="return false"> <form action="{{ route('api.kits.models.store', $kitId) }}" onsubmit="return false">
{{ csrf_field() }} {{ csrf_field() }}
<div class="alert alert-danger" id="modal_error_msg" style="display:none"> <div class="alert alert-danger" id="modal_error_msg" style="display:none">
</div> </div>

View file

@ -18,7 +18,7 @@
<div class="col-md-1 col-sm-1 text-left"> <div class="col-md-1 col-sm-1 text-left">
@can('create', \App\Models\Category::class) @can('create', \App\Models\Category::class)
@if ((!isset($hide_new)) || ($hide_new!='true')) @if ((!isset($hide_new)) || ($hide_new!='true'))
<a href='{{ route('modal.category',['category_type' => isset($category_type) ? $category_type : 'assets' ]) }}' data-toggle="modal" data-target="#createModal" data-select='category_select_id' class="btn btn-sm btn-primary">New</a> <a href='{{ route('modal.show',['type' => 'category', 'category_type' => isset($category_type) ? $category_type : 'assets' ]) }}' data-toggle="modal" data-target="#createModal" data-select='category_select_id' class="btn btn-sm btn-primary">New</a>
@endif @endif
@endcan @endcan
</div> </div>

View file

@ -17,7 +17,7 @@
<div class="col-md-1 col-sm-1 text-left"> <div class="col-md-1 col-sm-1 text-left">
@can('create', \App\Models\PredefinedKit::class) @can('create', \App\Models\PredefinedKit::class)
@if ((!isset($hide_new)) || ($hide_new!='true')) @if ((!isset($hide_new)) || ($hide_new!='true'))
{{-- <a href='{{ route('modal.kit') }}' data-toggle="modal" data-target="#createModal" data-select='kit_id_select' class="btn btn-sm btn-default">New</a> --}} {{-- <a href='{{ route('modal.show, 'kit') }}' data-toggle="modal" data-target="#createModal" data-select='kit_id_select' class="btn btn-sm btn-default">New</a> --}}
@endif @endif
@endcan @endcan
</div> </div>

View file

@ -17,7 +17,7 @@
<div class="col-md-1 col-sm-1 text-left"> <div class="col-md-1 col-sm-1 text-left">
@can('create', \App\Models\Location::class) @can('create', \App\Models\Location::class)
@if ((!isset($hide_new)) || ($hide_new!='true')) @if ((!isset($hide_new)) || ($hide_new!='true'))
<a href='{{ route('modal.location') }}' data-toggle="modal" data-target="#createModal" data-select='{{ $fieldname }}_location_select' class="btn btn-sm btn-primary">New</a> <a href='{{ route('modal.show', 'location') }}' data-toggle="modal" data-target="#createModal" data-select='{{ $fieldname }}_location_select' class="btn btn-sm btn-primary">New</a>
@endif @endif
@endcan @endcan
</div> </div>

View file

@ -19,7 +19,7 @@
<div class="col-md-1 col-sm-1 text-left"> <div class="col-md-1 col-sm-1 text-left">
@can('create', \App\Models\Manufacturer::class) @can('create', \App\Models\Manufacturer::class)
@if ((!isset($hide_new)) || ($hide_new!='true')) @if ((!isset($hide_new)) || ($hide_new!='true'))
<a href='{{ route('modal.manufacturer') }}' data-toggle="modal" data-target="#createModal" data-select='manufacturer_select_id' class="btn btn-sm btn-primary">New</a> <a href='{{ route('modal.show', 'manufacturer') }}' data-toggle="modal" data-target="#createModal" data-select='manufacturer_select_id' class="btn btn-sm btn-primary">New</a>
@endif @endif
@endcan @endcan
</div> </div>

View file

@ -18,7 +18,7 @@
<div class="col-md-1 col-sm-1 text-left"> <div class="col-md-1 col-sm-1 text-left">
@can('create', \App\Models\AssetModel::class) @can('create', \App\Models\AssetModel::class)
@if ((!isset($hide_new)) || ($hide_new!='true')) @if ((!isset($hide_new)) || ($hide_new!='true'))
<a href='{{ route('modal.model') }}' data-toggle="modal" data-target="#createModal" data-select='model_select_id' class="btn btn-sm btn-primary">New</a> <a href='{{ route('modal.show', 'model') }}' data-toggle="modal" data-target="#createModal" data-select='model_select_id' class="btn btn-sm btn-primary">New</a>
<span class="mac_spinner" style="padding-left: 10px; color: green; display:none; width: 30px;"> <span class="mac_spinner" style="padding-left: 10px; color: green; display:none; width: 30px;">
<i class="fa fa-spinner fa-spin" aria-hidden="true"></i> <i class="fa fa-spinner fa-spin" aria-hidden="true"></i>
</span> </span>

View file

@ -8,7 +8,7 @@
<div class="col-md-2 col-sm-2 text-left"> <div class="col-md-2 col-sm-2 text-left">
@can('create', \App\Models\Statuslabel::class) @can('create', \App\Models\Statuslabel::class)
<a href='{{ route('modal.statuslabel') }}' data-toggle="modal" data-target="#createModal" data-select='status_select_id' class="btn btn-sm btn-primary">New</a> <a href='{{ route('modal.show', 'statuslabel') }}' data-toggle="modal" data-target="#createModal" data-select='status_select_id' class="btn btn-sm btn-primary">New</a>
@endcan @endcan
<span class="status_spinner" style="padding-left: 10px; color: green; display:none; width: 30px;"><i class="fa fa-spinner fa-spin" aria-hidden="true"></i> </span> <span class="status_spinner" style="padding-left: 10px; color: green; display:none; width: 30px;"><i class="fa fa-spinner fa-spin" aria-hidden="true"></i> </span>

View file

@ -17,7 +17,7 @@
<div class="col-md-1 col-sm-1 text-left"> <div class="col-md-1 col-sm-1 text-left">
@can('create', \App\Models\Supplier::class) @can('create', \App\Models\Supplier::class)
@if ((!isset($hide_new)) || ($hide_new!='true')) @if ((!isset($hide_new)) || ($hide_new!='true'))
<a href='{{ route('modal.supplier') }}' data-toggle="modal" data-target="#createModal" data-select='supplier_select' class="btn btn-sm btn-primary">New</a> <a href='{{ route('modal.show', 'supplier') }}' data-toggle="modal" data-target="#createModal" data-select='supplier_select' class="btn btn-sm btn-primary">New</a>
@endif @endif
@endcan @endcan
</div> </div>

View file

@ -6,6 +6,6 @@
{!! $errors->first('supplier_id', '<span class="alert-msg" aria-hidden="true"><i class="fa fa-times" aria-hidden="true"></i> :message</span>') !!} {!! $errors->first('supplier_id', '<span class="alert-msg" aria-hidden="true"><i class="fa fa-times" aria-hidden="true"></i> :message</span>') !!}
</div> </div>
<div class="col-md-1 col-sm-1 text-left"> <div class="col-md-1 col-sm-1 text-left">
<a href='{{ route('modal.supplier') }}' data-toggle="modal" data-target="#createModal" data-dependency="supplier" data-select='supplier_select_id' class="btn btn-sm btn-primary">New</a> <a href='{{ route('modal.show', 'supplier') }}' data-toggle="modal" data-target="#createModal" data-dependency="supplier" data-select='supplier_select_id' class="btn btn-sm btn-primary">New</a>
</div> </div>
</div> </div>

View file

@ -17,7 +17,7 @@
<div class="col-md-1 col-sm-1 text-left"> <div class="col-md-1 col-sm-1 text-left">
@can('create', \App\Models\User::class) @can('create', \App\Models\User::class)
@if ((!isset($hide_new)) || ($hide_new!='true')) @if ((!isset($hide_new)) || ($hide_new!='true'))
<a href='{{ route('modal.user') }}' data-toggle="modal" data-target="#createModal" data-select='assigned_user_select' class="btn btn-sm btn-primary">New</a> <a href='{{ route('modal.show', 'user') }}' data-toggle="modal" data-target="#createModal" data-select='assigned_user_select' class="btn btn-sm btn-primary">New</a>
@endif @endif
@endcan @endcan
</div> </div>

View file

@ -80,17 +80,7 @@ Route::group(['middleware' => 'auth'], function () {
*/ */
Route::group(['middleware' => 'auth','prefix' => 'modals'], function () { Route::group(['middleware' => 'auth','prefix' => 'modals'], function () {
Route::get('location',['as' => 'modal.location','uses' => 'ModalController@location']); Route::get('{type}/{itemId?}',['as' => 'modal.show', 'uses' => 'ModalController@show']);
Route::get('category',['as' => 'modal.category','uses' => 'ModalController@category']);
Route::get('manufacturer',['as' => 'modal.manufacturer','uses' => 'ModalController@manufacturer']);
Route::get('model',['as' => 'modal.model','uses' => 'ModalController@model']);
Route::get('statuslabel',['as' => 'modal.statuslabel','uses' => 'ModalController@statuslabel']);
Route::get('supplier',['as' => 'modal.supplier','uses' => 'ModalController@supplier']);
Route::get('user',['as' => 'modal.user','uses' => 'ModalController@user']);
Route::get('kit-model',['as' => 'modal.kit.model','uses' => 'ModalController@kitModel']);
Route::get('kit-license',['as' => 'modal.kit.license','uses' => 'ModalController@kitLicense']);
Route::get('kit-consumable',['as' => 'modal.kit.consumable','uses' => 'ModalController@kitConsumable']);
Route::get('kit-accessory',['as' => 'modal.kit.accessory','uses' => 'ModalController@kitAccessory']);
}); });
/* /*