From fdb5b3baf19ed2fdc864226b9680469d66fc13c2 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 27 Jan 2021 17:44:05 -0800 Subject: [PATCH] Depreciation detail view fixes [ch15776] (#9059) * Allow sorting by months for depreciation list view * Added dataTableLayout to standardize the list display table * Implement the dataTableLayout() on the list view blade * Split the view into tabs so we can combine asset depreciations and license depreciations * Updated depreciation view to use tabbed interface for assets and licenses * Added asset models to depreciation details page * Make asset model category sortable * Added cateory as allowed to be sorted on * Added category sort scope * Removed offset variable * Small fixes to asset modes display in depreciation to bulk edit models --- .../Controllers/Api/AssetModelsController.php | 23 ++- app/Http/Controllers/Api/AssetsController.php | 2 - .../Api/DepreciationsController.php | 2 +- .../Controllers/Api/LicensesController.php | 1 + app/Presenters/AssetModelPresenter.php | 124 +++++++++++++- app/Presenters/DepreciationPresenter.php | 44 +++++ resources/views/depreciations/index.blade.php | 11 +- resources/views/depreciations/view.blade.php | 161 +++++++++++++++--- resources/views/models/bulk-edit.blade.php | 81 +++++---- resources/views/models/index.blade.php | 2 +- 10 files changed, 374 insertions(+), 77 deletions(-) diff --git a/app/Http/Controllers/Api/AssetModelsController.php b/app/Http/Controllers/Api/AssetModelsController.php index 408a119882..80409824c5 100644 --- a/app/Http/Controllers/Api/AssetModelsController.php +++ b/app/Http/Controllers/Api/AssetModelsController.php @@ -30,7 +30,20 @@ class AssetModelsController extends Controller public function index(Request $request) { $this->authorize('view', AssetModel::class); - $allowed_columns = ['id','image','name','model_number','eol','notes','created_at','manufacturer','requestable', 'assets_count']; + $allowed_columns = + [ + 'id', + 'image', + 'name', + 'model_number', + 'eol', + 'notes', + 'created_at', + 'manufacturer', + 'requestable', + 'assets_count', + 'category' + ]; $assetmodels = AssetModel::select([ 'models.id', @@ -75,16 +88,16 @@ class AssetModelsController extends Controller case 'manufacturer': $assetmodels->OrderManufacturer($order); break; + case 'category': + $assetmodels->OrderCategory($order); + break; default: $assetmodels->orderBy($sort, $order); break; } - - - $total = $assetmodels->count(); $assetmodels = $assetmodels->skip($offset)->take($limit)->get(); - return (new AssetModelsTransformer)->transformAssetModels($assetmodels, $total); + return (new AssetModelsTransformer)->transformAssetModels($assetmodels, $assetmodels->count()); } diff --git a/app/Http/Controllers/Api/AssetsController.php b/app/Http/Controllers/Api/AssetsController.php index e9aeaed97a..ef9a681ef7 100644 --- a/app/Http/Controllers/Api/AssetsController.php +++ b/app/Http/Controllers/Api/AssetsController.php @@ -141,8 +141,6 @@ class AssetsController extends Controller } $request->filled('order_number') ? $assets = $assets->where('assets.order_number', '=', e($request->get('order_number'))) : ''; - $offset = (($assets) && (request('offset') > $assets->count())) ? 0 : request('offset', 0); - // Set the offset to the API call's offset, unless the offset is higher than the actual count of items in which // case we override with the actual count, so we should return 0 items. diff --git a/app/Http/Controllers/Api/DepreciationsController.php b/app/Http/Controllers/Api/DepreciationsController.php index 95fcd5c94c..931d751d22 100644 --- a/app/Http/Controllers/Api/DepreciationsController.php +++ b/app/Http/Controllers/Api/DepreciationsController.php @@ -20,7 +20,7 @@ class DepreciationsController extends Controller public function index(Request $request) { $this->authorize('view', Depreciation::class); - $allowed_columns = ['id','name','created_at']; + $allowed_columns = ['id','name','months','created_at']; $depreciations = Depreciation::select('id','name','months','user_id','created_at','updated_at'); diff --git a/app/Http/Controllers/Api/LicensesController.php b/app/Http/Controllers/Api/LicensesController.php index bb6d9165a6..07bacdc4de 100644 --- a/app/Http/Controllers/Api/LicensesController.php +++ b/app/Http/Controllers/Api/LicensesController.php @@ -128,6 +128,7 @@ class LicensesController extends Controller 'free_seats_count', 'seats', 'termination_date', + 'depreciation_id' ]; $sort = in_array($request->input('sort'), $allowed_columns) ? e($request->input('sort')) : 'created_at'; $licenses = $licenses->orderBy($sort, $order); diff --git a/app/Presenters/AssetModelPresenter.php b/app/Presenters/AssetModelPresenter.php index 5b9e66bc5c..fc7858f30e 100644 --- a/app/Presenters/AssetModelPresenter.php +++ b/app/Presenters/AssetModelPresenter.php @@ -8,7 +8,129 @@ namespace App\Presenters; */ class AssetModelPresenter extends Presenter { - + public static function dataTableLayout() { + + $layout = [ + [ + "field" => "checkbox", + "checkbox" => true + ], + [ + "field" => "id", + "searchable" => false, + "sortable" => true, + "switchable" => true, + "title" => trans('general.id'), + "visible" => false + ], [ + "field" => "company", + "searchable" => true, + "sortable" => true, + "switchable" => true, + "title" => trans('admin/companies/table.title'), + "visible" => false, + "formatter" => "companiesLinkObjFormatter" + ], [ + "field" => "name", + "searchable" => true, + "sortable" => true, + "visible" => true, + "title" => trans('general.name'), + "formatter" => "modelsLinkFormatter" + ], + [ + "field" => "image", + "searchable" => false, + "sortable" => true, + "switchable" => true, + "title" => trans('general.image'), + "visible" => true, + "formatter" => 'imageFormatter', + ], + [ + "field" => "manufacturer", + "searchable" => false, + "sortable" => true, + "switchable" => true, + "title" => trans('general.manufacturer'), + "visible" => false, + "formatter" => 'manufacturersLinkObjFormatter', + ], + [ + "field" => "model_number", + "searchable" => false, + "sortable" => true, + "switchable" => true, + "title" => trans('admin/models/table.modelnumber'), + "visible" => true, + ], + [ + "field" => "assets_count", + "searchable" => false, + "sortable" => true, + "switchable" => true, + "title" => trans('admin/models/table.numassets'), + "visible" => true, + ], + [ + "field" => "depreciation", + "searchable" => false, + "sortable" => true, + "switchable" => true, + "title" => trans('general.depreciation'), + "visible" => false, + "formatter" => "depreciationsLinkObjFormatter", + ], + [ + "field" => "category", + "searchable" => false, + "sortable" => true, + "switchable" => true, + "title" => trans('general.category'), + "visible" => false, + "formatter" => "categoriesLinkObjFormatter", + ], + [ + "field" => "eol", + "searchable" => false, + "sortable" => true, + "switchable" => true, + "title" => trans('general.eol'), + "visible" => true, + ], + [ + "field" => "fieldset", + "searchable" => false, + "sortable" => true, + "switchable" => true, + "title" => trans('admin/models/general.fieldset'), + "visible" => true, + "formatter" => "fieldsetsLinkObjFormatter", + ], + [ + "field" => "notes", + "searchable" => true, + "sortable" => true, + "switchable" => true, + "title" => trans('general.notes'), + "visible" => false, + ], + ]; + + + $layout[] = [ + "field" => "actions", + "searchable" => false, + "sortable" => false, + "switchable" => false, + "title" => trans('table.actions'), + "formatter" => "licensesActionsFormatter", + ]; + + + return json_encode($layout); + + } /** * Formatted note for this model * @return string diff --git a/app/Presenters/DepreciationPresenter.php b/app/Presenters/DepreciationPresenter.php index 6bbb538842..d6e51ec81c 100644 --- a/app/Presenters/DepreciationPresenter.php +++ b/app/Presenters/DepreciationPresenter.php @@ -8,5 +8,49 @@ namespace App\Presenters; */ class DepreciationPresenter extends Presenter { + /** + * Json Column Layout for bootstrap table + * @return string + */ + public static function dataTableLayout() + { + $layout = [ + [ + "field" => "id", + "searchable" => false, + "sortable" => true, + "switchable" => true, + "title" => trans('general.id'), + "visible" => false + ], [ + "field" => "name", + "searchable" => true, + "sortable" => true, + "title" => trans('general.name'), + "visible" => true, + "formatter" => 'depreciationsLinkFormatter', + ], + + [ + "field" => "months", + "searchable" => true, + "sortable" => true, + "title" => trans('admin/depreciations/table.term'), + "visible" => true, + ], + + [ + "field" => "actions", + "searchable" => false, + "sortable" => false, + "switchable" => false, + "title" => trans('table.actions'), + "visible" => true, + "formatter" => "depreciationsActionsFormatter", + ] + ]; + + return json_encode($layout); + } } diff --git a/resources/views/depreciations/index.blade.php b/resources/views/depreciations/index.blade.php index ecb3d5123e..bfbed2ca6b 100755 --- a/resources/views/depreciations/index.blade.php +++ b/resources/views/depreciations/index.blade.php @@ -2,7 +2,7 @@ {{-- Page title --}} @section('title') -Asset Depreciations + Depreciations @parent @stop @@ -22,6 +22,7 @@ Asset Depreciations
- - - - - - - -
{{ trans('general.id') }}{{ trans('admin/depreciations/table.title') }}{{ trans('admin/depreciations/table.term') }}{{ trans('table.actions') }}
diff --git a/resources/views/depreciations/view.blade.php b/resources/views/depreciations/view.blade.php index 89b465ce20..c0263fda93 100644 --- a/resources/views/depreciations/view.blade.php +++ b/resources/views/depreciations/view.blade.php @@ -3,8 +3,7 @@ {{-- Page title --}} @section('title') - {{ trans('general.depreciation') }} - : {{ $depreciation->name }} + {{ trans('general.depreciation') }}: {{ $depreciation->name }} ({{ $depreciation->months }} {{ trans('general.months') }}) @parent @stop @@ -26,37 +25,147 @@
-
-
-
-
-
- - -
+ + + + +
+
+ + +
+ +
+ {{ Form::open( + [ + 'method' => 'POST', + 'route' => ['models.bulkedit.index'], + 'class' => 'form-inline', + 'id' => 'bulkForm'] + ) }} +
+
+ + + +
+ +
+ +
+ + +
+ +
+ {{ Form::close() }} + +
+
+ +
+ + + +
+
+ +
+
@stop @section('moar_scripts') - @include ('partials.bootstrap-table', [ - 'exportFile' => 'assets-export', - 'search' => true, - 'columns' => \App\Presenters\AssetPresenter::dataTableLayout() - ]) + @include ('partials.bootstrap-table') @stop diff --git a/resources/views/models/bulk-edit.blade.php b/resources/views/models/bulk-edit.blade.php index c4cfb800e1..9680db3a03 100644 --- a/resources/views/models/bulk-edit.blade.php +++ b/resources/views/models/bulk-edit.blade.php @@ -22,43 +22,60 @@
- @foreach ($models as $model) - {{ $model->display_name }} ({{ $model->model_number }})
- @endforeach +
You are about to edit the following:
- - @include ('partials.forms.edit.manufacturer-select', ['translated_name' => trans('general.manufacturer'), 'fieldname' => 'manufacturer_id']) - - - @include ('partials.forms.edit.category-select', ['translated_name' => trans('admin/categories/general.category_name'), 'fieldname' => 'category_id', 'required' => 'true', 'category_type' => 'asset']) - - -
- -
- {{ Form::select('fieldset_id', $fieldset_list , old('fieldset_id', 'NC'), array('class'=>'select2 js-fieldset-field', 'style'=>'width:350px')) }} - {!! $errors->first('fieldset_id', '') !!} -
-
- - - -
- -
- {{ Form::select('depreciation_id', $depreciation_list , old('depreciation_id', 'NC'), array('class'=>'select2', 'style'=>'width:350px')) }} - {!! $errors->first('depreciation_id', '') !!} -
-
+ + @foreach ($models as $model) - + + assets_count > 0 ) ? ' class="warning"' : ' class="success"') !!}> + + + + @endforeach +
+ + {{ $model->display_name }} ({{ $model->model_number }}) + {{ $model->assets_count }} assets +
+ +
+ + @include ('partials.forms.edit.manufacturer-select', ['translated_name' => trans('general.manufacturer'), 'fieldname' => 'manufacturer_id']) + + + @include ('partials.forms.edit.category-select', ['translated_name' => trans('admin/categories/general.category_name'), 'fieldname' => 'category_id', 'required' => 'true', 'category_type' => 'asset']) + + +
+ +
+ {{ Form::select('fieldset_id', $fieldset_list , old('fieldset_id', 'NC'), array('class'=>'select2 js-fieldset-field', 'style'=>'width:350px')) }} + {!! $errors->first('fieldset_id', '') !!} +
+
+ + + +
+ +
+ {{ Form::select('depreciation_id', $depreciation_list , old('depreciation_id', 'NC'), array('class'=>'select2', 'style'=>'width:350px')) }} + {!! $errors->first('depreciation_id', '') !!} +
+
+ + @foreach ($models as $model) + + @endforeach +