Skip to content

Commit

Permalink
Refactor controller to use one method that shows all modals based on …
Browse files Browse the repository at this point in the history
…name.
  • Loading branch information
dmeltzer committed May 23, 2020
1 parent 25d6cee commit 7ea8627
Show file tree
Hide file tree
Showing 18 changed files with 35 additions and 75 deletions.
4 changes: 3 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
* text=auto
* text=auto
public/js/** binary
public/css/** binary
52 changes: 10 additions & 42 deletions app/Http/Controllers/ModalController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,47 +6,15 @@

class ModalController extends Controller
{
function location() {
return view('modals.location');
}

function model() {
return view('modals.model');
}

function statuslabel() {
return view('modals.statuslabel')->with('statuslabel_types', Helper::statusTypeList());
}

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');
function show($type, $itemId = null) {
$view = view("modals.${type}");

if($type == "statuslabel") {
$view->with('statuslabel_types', Helper::statusTypeList());
}
if(in_array($type, ['kit-model', 'kit-license', 'kit-consumable', 'kit-accessory'])) {
$view->with('kitId', $itemId);
}
return $view;
}
}
2 changes: 1 addition & 1 deletion resources/assets/js/snipeit_modals.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
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'
Expand Down
8 changes: 4 additions & 4 deletions resources/views/kits/edit.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class="table table-striped snipe-table"
"ignoreColumn": ["actions","image","change","checkbox","checkincheckout","icon"]
}'>
</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> <!--.box-body-->
</div> <!-- /.box.box-default-->
Expand Down Expand Up @@ -73,7 +73,7 @@ class="table table-striped snipe-table"
"ignoreColumn": ["actions","image","change","checkbox","checkincheckout","icon"]
}'>
</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> <!--.box-body-->
</div> <!-- /.box.box-default-->
Expand Down Expand Up @@ -107,7 +107,7 @@ class="table table-striped snipe-table"
"ignoreColumn": ["actions","image","change","checkbox","checkincheckout","icon"]
}'>
</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> <!--.box-body-->
</div> <!-- /.box.box-default-->
Expand Down Expand Up @@ -141,7 +141,7 @@ class="table table-striped snipe-table"
"ignoreColumn": ["actions","image","change","checkbox","checkincheckout","icon"]
}'>
</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> <!--.box-body-->
</div> <!-- /.box.box-default-->
Expand Down
4 changes: 2 additions & 2 deletions resources/views/modals/kit-accessory.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
<h4 class="modal-title">Append accessory{{-- TODO: trans --}}</h4>
</div>
<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() }}
<div class="alert alert-danger" id="modal_error_msg" style="display:none">
</div>

<div class="dynamic-form-row">
<div class="col-md-4 col-xs-12"><label for="modal-accessory_id">{{ trans('general.accessory') }}:
</label></div>
Expand Down
4 changes: 2 additions & 2 deletions resources/views/modals/kit-consumable.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
<h4 class="modal-title">Append consumable{{-- TODO: trans --}}</h4>
</div>
<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() }}
<div class="alert alert-danger" id="modal_error_msg" style="display:none">
</div>

<div class="dynamic-form-row">
<div class="col-md-4 col-xs-12"><label for="modal-consumable_id">{{ trans('general.consumable') }}:
</label></div>
Expand Down
4 changes: 2 additions & 2 deletions resources/views/modals/kit-license.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
<h4 class="modal-title">Append license{{-- TODO: trans --}}</h4>
</div>
<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() }}
<div class="alert alert-danger" id="modal_error_msg" style="display:none">
</div>

<div class="dynamic-form-row">
<div class="col-md-4 col-xs-12"><label for="modal-license_id">{{ trans('general.license') }}:
</label></div>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/modals/kit-model.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<h4 class="modal-title">Append model{{-- TODO: trans --}}</h4>
</div>
<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() }}
<div class="alert alert-danger" id="modal_error_msg" style="display:none">
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<div class="col-md-1 col-sm-1 text-left">
@can('create', \App\Models\Category::class)
@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
@endcan
</div>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/partials/forms/edit/kit-select.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<div class="col-md-1 col-sm-1 text-left">
@can('create', \App\Models\PredefinedKit::class)
@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
@endcan
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<div class="col-md-1 col-sm-1 text-left">
@can('create', \App\Models\Location::class)
@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
@endcan
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<div class="col-md-1 col-sm-1 text-left">
@can('create', \App\Models\Manufacturer::class)
@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
@endcan
</div>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/partials/forms/edit/model-select.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<div class="col-md-1 col-sm-1 text-left">
@can('create', \App\Models\AssetModel::class)
@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;">
<i class="fa fa-spinner fa-spin" aria-hidden="true"></i>
</span>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/partials/forms/edit/status.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<div class="col-md-2 col-sm-2 text-left">

@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

<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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<div class="col-md-1 col-sm-1 text-left">
@can('create', \App\Models\Supplier::class)
@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
@endcan
</div>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/partials/forms/edit/supplier.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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>') !!}
</div>
<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>
2 changes: 1 addition & 1 deletion resources/views/partials/forms/edit/user-select.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<div class="col-md-1 col-sm-1 text-left">
@can('create', \App\Models\User::class)
@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
@endcan
</div>
Expand Down
12 changes: 1 addition & 11 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,7 @@
*/

Route::group(['middleware' => 'auth','prefix' => 'modals'], function () {
Route::get('location',['as' => 'modal.location','uses' => 'ModalController@location']);
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']);
Route::get('{type}/{itemId?}',['as' => 'modal.show', 'uses' => 'ModalController@show']);
});

/*
Expand Down

0 comments on commit 7ea8627

Please sign in to comment.