Add licenses, accessories and consumables table presenters app\Presenters\PredefinedKitPresenter.php resources\views\partials\bootstrap-table.blade.php

Add refresh licenses, accessories and consumables tables refresh when add a new element resources\assets\js\snipeit_modals.js
Some design fixes resources\views\kits\edit.blade.php
Add default value to form (template) resources\views\modals\kit-model.blade.php
New routes for kit accessories and kit consumables routes\api.php
New routes for kit models, kit accessories and kit consumables routes\web\kits.php
New templates
This commit is contained in:
Dmitrii Minaev 2019-01-27 23:19:24 +03:00
parent 0bbe499414
commit e01e0c5596
12 changed files with 380 additions and 21 deletions

View file

@ -120,10 +120,6 @@ class PredefinedKit extends SnipeModel
}
public function applyToUser(User $user) {
$models = $this->models();
}
/**
* -----------------------------------------------
* BEGIN QUERY SCOPES

View file

@ -144,6 +144,11 @@ class PredefinedKitPresenter extends Presenter
"sortable" => true,
"title" => 'Name', // TODO: trans
"formatter" => "licensesLinkFormatter"
], [
"field" => "quantity",
"searchable" => false,
"sortable" => false,
"title" => 'Quantity', // TODO: trans
], [
"field" => "actions",
"searchable" => false,
@ -157,6 +162,110 @@ class PredefinedKitPresenter extends Presenter
return json_encode($layout);
}
/**
* Json Column Layout for bootstrap table
* @return string
*/
public static function dataTableAccessories()
{
$layout = [
[
"field" => "id",
"searchable" => false,
"sortable" => true,
"switchable" => true,
"title" => trans('general.id'),
"visible" => false
], [
"field" => "pivot_id",
"searchable" => false,
"sortable" => true,
"switchable" => true,
"title" => trans('general.id'),
"visible" => false
], [
"field" => "owner_id",
"searchable" => false,
"sortable" => true,
"switchable" => true,
"title" => trans('general.id'),
"visible" => false
], [
"field" => "name",
"searchable" => true,
"sortable" => true,
"title" => 'Name', // TODO: trans
"formatter" => "accessoriesLinkFormatter" // MYTODO: check
], [
"field" => "quantity",
"searchable" => false,
"sortable" => false,
"title" => 'Quantity', // TODO: trans
], [
"field" => "actions",
"searchable" => false,
"sortable" => false,
"switchable" => false,
"title" => trans('table.actions'),
"formatter" => "kits_accessoriesActionsFormatter", // MYTODO: check
]
];
return json_encode($layout);
}
/**
* Json Column Layout for bootstrap table
* @return string
*/
public static function dataTableConsumables()
{
$layout = [
[
"field" => "id",
"searchable" => false,
"sortable" => true,
"switchable" => true,
"title" => trans('general.id'),
"visible" => false
], [
"field" => "pivot_id",
"searchable" => false,
"sortable" => true,
"switchable" => true,
"title" => trans('general.id'),
"visible" => false
], [
"field" => "owner_id",
"searchable" => false,
"sortable" => true,
"switchable" => true,
"title" => trans('general.id'),
"visible" => false
], [
"field" => "name",
"searchable" => true,
"sortable" => true,
"title" => 'Name', // TODO: trans
"formatter" => "consumablesLinkFormatter" // MYTODO: check
], [
"field" => "quantity",
"searchable" => false,
"sortable" => false,
"title" => 'Quantity', // TODO: trans
], [
"field" => "actions",
"searchable" => false,
"sortable" => false,
"switchable" => false,
"title" => trans('table.actions'),
"formatter" => "kits_consumablesActionsFormatter", // MYTODO: check
]
];
return json_encode($layout);
}
/**

View file

@ -64,7 +64,7 @@ class RouteServiceProvider extends ServiceProvider
require base_path('routes/web/components.php');
require base_path('routes/web/users.php');
require base_path('routes/web/kits.php');
require base_path('routes/web/dbtest.php');
//require base_path('routes/web/dbtest.php');
require base_path('routes/web.php');
});
}

View file

@ -28,7 +28,7 @@ $(function () {
//handle modal-add-interstitial calls
var model, select;
var model, select, refreshSelector;
if($('#createModal').length == 0) {
$('body').append('<div class="modal fade" id="createModal"></div><!-- /.modal -->');
@ -38,6 +38,8 @@ $(function () {
var link = $(event.relatedTarget);
model = link.data("dependency");
select = link.data("select");
refreshSelector = link.data("refresh");
$('#createModal').load(link.attr('href'),function () {
//do we need to re-select2 this, after load? Probably.
$('#createModal').find('select.select2').select2();
@ -123,6 +125,12 @@ $(function () {
$('#createModal').modal('hide');
$('#createModal').html("");
var refreshTable = $('#' + refreshSelector);
if(refreshTable.length > 0) {
refreshTable.bootstrapTable('refresh');
}
// "select" is the original drop-down menu that someone
// clicked 'add' on to add a new 'thing'
// this code adds the newly created object to that select

View file

@ -11,12 +11,13 @@
@section('content')
@parent
{{-- Assets by model --}}
<div class="row">
<div class="col-md-12">
<div class="box box-default">
<div class="box-header with-border">
{{-- <h3 class="box-title"><span>Models </span><a href="{{ route('modal.kit.model', ['kit' => $item->id]) }}" data-toggle="modal" data-target="#createModal" class="btn btn-sm btn-primary"><i class="fa fa-plus icon-white"></i> Append</a></h3> --}}
<h3 class="box-title"><span>Models </span></h3>
<h3 class="box-title"><span>Assets (by models){{-- TODO: trans --}}</span></h3>
</div>
<div class="box-body">
<div class="table-responsive">
@ -39,21 +40,21 @@
"ignoreColumn": ["actions","image","change","checkbox","checkincheckout","icon"]
}'>
</table>
<a href="{{ route('modal.kit.model', ['kit' => $item->id]) }}" 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.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>
</div>
</div> <!--.box-body-->
</div> <!-- /.box.box-default-->
</div> <!-- .col-md-12-->
</div>
{{-- Licenses --}}
<div class="row">
<div class="col-md-12">
<div class="box box-default">
<div class="box-header with-border">
<h3 class="box-title">Licenses</h3>
<h3 class="box-title">Licenses{{-- TODO: trans --}}</h3>
</div>
<div class="box-body">
<div class="table-responsive">
<table
data-cookie-id-table="kitLicensesTable"
data-columns="{{ \App\Presenters\PredefinedKitPresenter::dataTableLicenses() }}"
@ -73,6 +74,7 @@
"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>
</div>
</div> <!--.box-body-->
</div> <!-- /.box.box-default-->

View file

@ -0,0 +1,38 @@
{{-- See snipeit_modals.js for what powers this --}}
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span></button>
<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">
{{ 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>
<div class="col-md-8 col-xs-12 required">
<select class="js-data-ajax" data-endpoint="accessories" name="accessory" style="width: 100%" id="modal-accessory_id" />
</div>
</div>
<div class="dynamic-form-row">
<div class="col-md-4 col-xs-12"><label for="modal-quantity_id">Quantity{{-- TODO: trans --}}:
</label></div>
<div class="col-md-8 col-xs-12 required">
<input type='text' name='quantity' id='modal-quantity_id' class="form-control" value="1">
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">{{ trans('button.cancel') }}</button>
<button type="button" class="btn btn-primary" id="modal-save">{{ trans('general.save') }}</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->

View file

@ -0,0 +1,38 @@
{{-- See snipeit_modals.js for what powers this --}}
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span></button>
<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">
{{ 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>
<div class="col-md-8 col-xs-12 required">
<select class="js-data-ajax" data-endpoint="consumables" name="consumable" style="width: 100%" id="modal-consumable_id" />
</div>
</div>
<div class="dynamic-form-row">
<div class="col-md-4 col-xs-12"><label for="modal-quantity_id">Quantity{{-- TODO: trans --}}:
</label></div>
<div class="col-md-8 col-xs-12 required">
<input type='text' name='quantity' id='modal-quantity_id' class="form-control" value="1">
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">{{ trans('button.cancel') }}</button>
<button type="button" class="btn btn-primary" id="modal-save">{{ trans('general.save') }}</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->

View file

@ -0,0 +1,38 @@
{{-- See snipeit_modals.js for what powers this --}}
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span></button>
<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">
{{ 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>
<div class="col-md-8 col-xs-12 required">
<select class="js-data-ajax" data-endpoint="licenses" name="license" style="width: 100%" id="modal-license_id" />
</div>
</div>
<div class="dynamic-form-row">
<div class="col-md-4 col-xs-12"><label for="modal-quantity_id">Quantity{{-- TODO: trans --}}:
</label></div>
<div class="col-md-8 col-xs-12 required">
<input type='text' name='quantity' id='modal-quantity_id' class="form-control" value="1">
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">{{ trans('button.cancel') }}</button>
<button type="button" class="btn btn-primary" id="modal-save">{{ trans('general.save') }}</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->

View file

@ -24,7 +24,7 @@
<div class="col-md-4 col-xs-12"><label for="modal-quantity_id">Quantity{{-- TODO: trans --}}:
</label></div>
<div class="col-md-8 col-xs-12 required">
<input type='text' name='quantity' id='modal-quantity_id' class="form-control">
<input type='text' name='quantity' id='modal-quantity_id' class="form-control" value="1">
</div>
</div>

View file

@ -341,6 +341,8 @@
var child_formatters = [
['kits', 'models'],
['kits', 'licenses'],
['kits', 'consumables'],
['kits', 'accessories'],
];
for (var i in child_formatters) {

View file

@ -751,7 +751,8 @@ Route::group(['prefix' => 'v1','namespace' => 'Api'], function () {
[ 'as' => 'api.activity.index', 'uses' => 'ReportsController@index' ]
);
// kits
/*--- Kits API ---*/
Route::resource('kits', 'PredefinedKitsController',
[
'names' =>
@ -770,6 +771,7 @@ Route::group(['prefix' => 'v1','namespace' => 'Api'], function () {
Route::group([ 'prefix' => 'kits/{kit_id}' ], function () {
// kit licenses
Route::get('licenses',
[
'as' => 'api.kits.licenses.index',
@ -798,7 +800,7 @@ Route::group(['prefix' => 'v1','namespace' => 'Api'], function () {
]
);
// kit models
Route::get('models',
[
'as' => 'api.kits.models.index',
@ -827,6 +829,64 @@ Route::group(['prefix' => 'v1','namespace' => 'Api'], function () {
]
);
// kit accessories
Route::get('accessories',
[
'as' => 'api.kits.accessories.index',
'uses' => 'PredefinedKitsController@indexAccessories',
]
);
Route::post('accessories',
[
'as' => 'api.kits.accessories.store',
'uses' => 'PredefinedKitsController@storeAccessory',
]
);
Route::put('accessories/{accessory_id}',
[
'as' => 'api.kits.accessories.update',
'uses' => 'PredefinedKitsController@updateAccessory',
]
);
Route::delete('accessories/{accessory_id}',
[
'as' => 'api.kits.accessories.destroy',
'uses' => 'PredefinedKitsController@detachAccessory',
]
);
// kit consumables
Route::get('consumables',
[
'as' => 'api.kits.consumables.index',
'uses' => 'PredefinedKitsController@indexConsumables',
]
);
Route::post('consumables',
[
'as' => 'api.kits.consumables.store',
'uses' => 'PredefinedKitsController@storeConsumable',
]
);
Route::put('consumables/{consumable_id}',
[
'as' => 'api.kits.consumables.update',
'uses' => 'PredefinedKitsController@updateConsumable',
]
);
Route::delete('consumables/{consumable_id}',
[
'as' => 'api.kits.consumables.destroy',
'uses' => 'PredefinedKitsController@detachConsumable',
]
);
}); // kits
});

View file

@ -30,6 +30,14 @@ Route::group([ 'prefix' => 'kits/{kit_id}', 'middleware' => ['auth'] ], function
'uses' => 'Kits\PredefinedKitsController@updateLicense',
]
);
Route::get('licenses/{license_id}/edit',
[
'as' => 'kits.licenses.edit',
'uses' => 'Kits\PredefinedKitsController@editLicense',
]
);
Route::delete('licenses/{license_id}',
[
@ -37,15 +45,10 @@ Route::group([ 'prefix' => 'kits/{kit_id}', 'middleware' => ['auth'] ], function
'uses' => 'Kits\PredefinedKitsController@detachLicense',
]
);
// Route::get('models',
// [
// 'as' => 'kits.models.index',
// 'uses' => 'Kits\PredefinedKitsController@indexModels',
// ]
// );
// Models
Route::post('models',
[
'as' => 'kits.models.store',
@ -76,6 +79,71 @@ Route::group([ 'prefix' => 'kits/{kit_id}', 'middleware' => ['auth'] ], function
]
);
// Consumables
Route::post('consumables',
[
'as' => 'kits.consumables.store',
'uses' => 'Kits\PredefinedKitsController@storeConsumable',
]
);
Route::put('consumables/{consumable_id}',
[
'as' => 'kits.consumables.update',
'uses' => 'Kits\PredefinedKitsController@updateConsumable',
'parameters' => [2 => 'kit_id', 1 => 'consumable_id']
]
);
Route::get('consumables/{consumable_id}/edit',
[
'as' => 'kits.consumables.edit',
'uses' => 'Kits\PredefinedKitsController@editConsumable',
]
);
Route::delete('consumables/{consumable_id}',
[
'as' => 'kits.consumables.detach',
'uses' => 'Kits\PredefinedKitsController@detachConsumable',
]
);
// Accessories
Route::post('accessories',
[
'as' => 'kits.accessories.store',
'uses' => 'Kits\PredefinedKitsController@storeAccessory',
]
);
Route::put('accessories/{accessory_id}',
[
'as' => 'kits.accessories.update',
'uses' => 'Kits\PredefinedKitsController@updateAccessory',
'parameters' => [2 => 'kit_id', 1 => 'accessory_id']
]
);
Route::get('accessories/{accessory_id}/edit',
[
'as' => 'kits.accessories.edit',
'uses' => 'Kits\PredefinedKitsController@editAccessory',
]
);
Route::delete('accessories/{accessory_id}',
[
'as' => 'kits.accessories.detach',
'uses' => 'Kits\PredefinedKitsController@detachAccessory',
]
);
Route::get('checkout',
[
'as' => 'kits.checkout.show',