Moving license index to new API format

This commit is contained in:
snipe 2017-02-10 18:43:30 -08:00
parent eb3767890e
commit c67b44b3d5
11 changed files with 122 additions and 238 deletions

View file

@ -29,7 +29,7 @@ class LicensesController extends Controller
$offset = request('offset', 0); $offset = request('offset', 0);
$limit = request('limit', 50); $limit = request('limit', 50);
$allowed_columns = ['id','name','purchase_cost','expiration_date','purchase_order','order_number','notes','purchase_date','serial','manufacturer','company']; $allowed_columns = ['id','name','purchase_cost','expiration_date','purchase_order','order_number','notes','purchase_date','serial','manufacturer','company','license_name','license_email'];
$order = $request->input('order') === 'asc' ? 'asc' : 'desc'; $order = $request->input('order') === 'asc' ? 'asc' : 'desc';
$sort = in_array($request->input('sort'), $allowed_columns) ? e($request->input('sort')) : 'created_at'; $sort = in_array($request->input('sort'), $allowed_columns) ? e($request->input('sort')) : 'created_at';
@ -45,7 +45,6 @@ class LicensesController extends Controller
break; break;
} }
$total = $licenses->count(); $total = $licenses->count();
$licenses = $licenses->skip($offset)->take($limit)->get(); $licenses = $licenses->skip($offset)->take($limit)->get();
return (new LicensesTransformer)->transformLicenses($licenses, $total); return (new LicensesTransformer)->transformLicenses($licenses, $total);

View file

@ -4,6 +4,7 @@ namespace App\Http\Transformers;
use App\Models\License; use App\Models\License;
use Gate; use Gate;
use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Eloquent\Collection;
use App\Helpers\Helper;
class LicensesTransformer class LicensesTransformer
{ {
@ -22,21 +23,23 @@ class LicensesTransformer
$array = [ $array = [
'id' => $license->id, 'id' => $license->id,
'name' => e($license->name), 'name' => e($license->name),
'company' => e($license->company->name), 'company' => ($license->company) ? ['id' => $license->company->id,'name'=> e($license->company->name)] : null,
'manufacturer' => ($license->manufacturer) ? $license->manufacturer : null, 'manufacturer' => ($license->manufacturer) ? ['id' => $license->manufacturer->id,'name'=> e($license->manufacturer->name)] : null,
'serial' => e($license->name), 'product_key' => e($license->serial),
'purchase_order' => e($license->order_number), 'order_number' => e($license->order_number),
'purchase_order' => e($license->purchase_order),
'purchase_date' => e($license->purchase_date), 'purchase_date' => e($license->purchase_date),
'purchase_cost' => e($license->purchase_cost), 'purchase_cost' => e($license->purchase_cost),
'depreciation' => ($license->depreciation) ? $license->depreciation : null, 'depreciation' => ($license->depreciation) ? ['id' => $license->depreciation->id,'name'=> e($license->depreciation->name)] : null,
'notes' => e($license->notes), 'notes' => e($license->notes),
'expiration_date' => e($license->expiration_date), 'expiration_date' => e($license->expiration_date),
'totalSeats' => e($license->seats), 'total_seats' => e($license->seats),
'remaining' => $license->remaincount(), 'remaining_qty' => $license->remaincount(),
'license_name' => e($license->license_name), 'min_qty' => $license->remaincount(),
'license_name' => Helper::formatCurrencyOutput($license->purchase_cost),
'license_email' => e($license->license_email), 'license_email' => e($license->license_email),
'maintained' => ($license->maintained == 1) ? true : false, 'maintained' => ($license->maintained == 1) ? true : false,
'supplier' => ($license->supplier) ? $license->supplier : null, 'supplier' => ($license->supplier) ? ['id' => $license->supplier->id,'name'=> e($license->supplier->name)] : null,
'created_at' => $license->created_at, 'created_at' => $license->created_at,
]; ];

View file

@ -25,6 +25,13 @@ class AccessoryPresenter extends Presenter
{ {
$layout = [ $layout = [
[ [
"field" => "id",
"searchable" => false,
"sortable" => true,
"switchable" => true,
"title" => trans('general.id'),
"visible" => false
], [
"field" => "company", "field" => "company",
"searchable" => true, "searchable" => true,
"sortable" => true, "sortable" => true,

View file

@ -16,49 +16,7 @@ use App\Helpers\Helper;
*/ */
class AssetModelPresenter extends Presenter class AssetModelPresenter extends Presenter
{ {
/**
* JSON representation of Accessory for datatable.
* @return array
*/
public function forDataTable()
{
$actions = '<div style="white-space: nowrap;">';
if ($this->deleted_at == '') {
$actions .= Helper::generateDatatableButton('clone', route('clone/model', $this->id));
$actions .= Helper::generateDatatableButton('edit', route('models.edit', $this->id));
$actions .= Helper::generateDatatableButton(
'delete',
route('models.destroy', $this->id),
trans('admin/models/message.delete.confirm'),
$this->name
);
} else {
$actions .= Helper::generateDatatableButton('restore', route('restore/model', $this->id));
}
$actions .="</div>";
$results = [];
$results['id'] = $this->id;
$results['manufacturer'] = $this->manufacturerUrl();
$results['name'] = $this->nameUrl();
$results['image'] = $this->imageUrl();
$results['model_number'] = $this->model_number;
$results['numassets'] = $this->assets()->count();
$results['depreciation'] = trans('general.no_depreciation');
if (($depreciation = $this->model->depreciation) and $depreciation->id > 0) {
$results['depreciation'] = $depreciation->name.' ('.$depreciation->months.')';
}
$results['category'] = $this->categoryUrl();
$results['eol'] = $this->eolText();
$results['note'] = $this->note();
$results['fieldset'] = $this->model->fieldset ? link_to_route('custom_fields/model', $this->model->fieldset->name, $this->model->fieldset->id) : '';
$results['actions'] = $actions;
return $results;
}
/** /**
* Formatted note for this model * Formatted note for this model
* @return string * @return string

View file

@ -10,31 +10,6 @@ use App\Helpers\Helper;
*/ */
class CategoryPresenter extends Presenter class CategoryPresenter extends Presenter
{ {
/**
* JSON representation of category for datatable.
* @return array
*/
public function forDataTable()
{
$actions = Helper::generateDatatableButton('edit', route('categories.edit', $this->id));
$actions .= Helper::generateDatatableButton(
'delete',
route('categories.destroy', $this->id),
$this->itemCount() == 0, /* enabled */
trans('admin/categories/message.delete.confirm'),
$this->name
);
$results = [];
$results['id'] = $this->id;
$results['name'] = $this->nameUrl();
$results['category_type'] = ucwords($this->category_type);
$results['count'] = $this->itemCount();
$results['acceptance'] = ($this->require_acceptance == '1') ? '<i class="fa fa-check"></i>' : '';
$results['eula'] = $this->getEula() ? '<i class="fa fa-check"></i>' : '';
$results['actions'] = $actions;
return $results;
}
/** /**
* Link to this categories name * Link to this categories name

View file

@ -10,28 +10,5 @@ use App\Helpers\Helper;
*/ */
class DepreciationPresenter extends Presenter class DepreciationPresenter extends Presenter
{ {
/**
* Formatted JSON representation of this Depreciation
* @return array
*/
public function forDataTable()
{
$actions = Helper::generateDatatableButton('edit', route('depreciations.edit', $this->id));
$actions .= Helper::generateDatatableButton(
'delete',
route('depreciations.destroy', $this->id),
true, /*enabled*/
trans('admin/depreciations/message.delete.confirm'),
$this->name
);
$results = [
'id' => $this->id,
'name' => $this->name,
'months' => $this->months,
'actions' => $actions
];
return $results;
}
} }

View file

@ -12,60 +12,108 @@ use Illuminate\Support\Facades\Gate;
class LicensePresenter extends Presenter class LicensePresenter extends Presenter
{ {
/** /**
* JSON representation of this license for data table. * Json Column Layout for bootstrap table
* @return array * @return string
*/ */
public function forDataTable() public static function dataTableLayout()
{ {
$actions = '<span style="white-space: nowrap;">'; $layout = [
[
if (Gate::allows('checkout', License::class)) { "field" => "id",
$actions .= Helper::generateDatatableButton( "searchable" => false,
'checkout', "sortable" => true,
route('licenses.freecheckout', $this->id), "switchable" => true,
$this->remaincount() > 0 "title" => trans('general.id'),
); "visible" => false
} ], [
"field" => "company",
if (Gate::allows('create', $this->model)) { "searchable" => true,
$actions .= Helper::generateDatatableButton('clone', route('clone/license', $this->id)); "sortable" => true,
} "switchable" => true,
if (Gate::allows('update', $this->model)) { "title" => trans('admin/companies/table.title'),
$actions .= Helper::generateDatatableButton('edit', route('licenses.edit', $this->id)); "visible" => false,
} "formatter" => "companiesLinkObjFormatter"
if (Gate::allows('delete', $this->model)) { ], [
$actions .= Helper::generateDatatableButton( "field" => "name",
'delete', "searchable" => true,
route('licenses.destroy', $this->id), "sortable" => true,
true, /*enabled*/ "title" => trans('admin/licenses/table.title'),
trans('admin/licenses/message.delete.confirm'), "formatter" => "licensesLinkFormatter"
$this->name ], [
); "field" => "product_key",
} "searchable" => true,
$actions .='</span>'; "sortable" => true,
"title" => trans('admin/licenses/form.license_key'),
$results = [ "formatter" => "licensesLinkFormatter"
'actions' => $actions, ], [
'company' => $this->companyUrl(), "field" => "expiration_date",
'expiration_date' => $this->expiration_date, "searchable" => true,
'id' => $this->id, "sortable" => true,
'license_email' => $this->license_email, "title" => trans('admin/licenses/form.expiration')
'license_name' => $this->license_name, ], [
'manufacturer' => $this->manufacturerUrl(), "field" => "license_email",
'name' => $this->nameUrl(), "searchable" => true,
'notes' => $this->notes, "sortable" => true,
'order_number' => $this->order_number, "title" => trans('admin/licenses/form.to_email')
'purchase_cost' => Helper::formatCurrencyOutput($this->purchase_cost), ], [
'purchase_date' => $this->purchase_date, "field" => "license_name",
'purchase_order' => $this->purchase_order, "searchable" => true,
'remaining' => $this->remaincount(), "sortable" => true,
'serial' => $this->serialUrl(), "title" => trans('admin/licenses/form.to_name'),
'totalSeats' => $this->model->licenseSeatsCount, ], [
"field" => "manufacturer",
"searchable" => true,
"sortable" => true,
"title" => trans('general.manufacturer'),
"formatter" => "manufacturersLinkObjFormatter",
], [
"field" => "total_seats",
"searchable" => false,
"sortable" => false,
"title" => trans('admin/accessories/general.total'),
], [
"field" => "remaining_qty",
"searchable" => false,
"sortable" => false,
"title" => trans('admin/accessories/general.remaining'),
], [
"field" => "purchase_date",
"searchable" => true,
"sortable" => true,
"visible" => false,
"title" => trans('general.purchase_date'),
], [
"field" => "purchase_cost",
"searchable" => true,
"sortable" => true,
"visible" => false,
"title" => trans('general.purchase_cost'),
], [
"field" => "purchase_order",
"searchable" => true,
"sortable" => true,
"visible" => false,
"title" => trans('admin/licenses/form.purchase_order'),
], [
"field" => "order_number",
"searchable" => true,
"sortable" => true,
"visible" => false,
"title" => trans('general.order_number'),
], [
"field" => "actions",
"searchable" => false,
"sortable" => false,
"switchable" => false,
"title" => trans('table.actions'),
"formatter" => "licensesActionsFormatter",
]
]; ];
return $results; return json_encode($layout);
} }
/** /**
* Link to this licenses Name * Link to this licenses Name
* @return string * @return string

View file

@ -10,41 +10,6 @@ use App\Helpers\Helper;
*/ */
class LocationPresenter extends Presenter class LocationPresenter extends Presenter
{ {
/**
* JSON representation of this location for data table.
* @return array
*/
public function forDataTable()
{
$actions = '<nobr>';
$actions .= Helper::generateDatatableButton('edit', route('locations.edit', $this->id));
$actions .= Helper::generateDatatableButton(
'delete',
route('locations.destroy', $this->id),
true, /*enabled*/
trans('admin/locations/message.delete.confirm'),
$this->name
);
$actions .= '</nobr>';
$results = [
'actions' => $actions,
'address' => $this->address,
'assets_checkedout' => $this->model->assets()->count(),
'assets_default' => $this->model->assignedassets()->count(),
'city' => $this->city,
'country' => $this->country,
'currency' => $this->currency,
'id' => $this->id,
'name' => $this->nameUrl(),
'parent' => ($this->model->parent) ? $this->model->parent->present()->nameUrl() : '',
'state' => $this->state,
'zip' => $this->zip,
// 'assets' => ($this->assets->count() + $this->assignedassets->count()),
];
return $results;
}
/** /**
* Link to this locations name * Link to this locations name

View file

@ -11,35 +11,6 @@ use App\Helpers\Helper;
class ManufacturerPresenter extends Presenter class ManufacturerPresenter extends Presenter
{ {
/**
* JSON representation of this manufacturer for data table.
* @return array
*/
public function forDataTable()
{
$actions = '<nobr>';
$actions .= Helper::generateDatatableButton('edit', route('manufacturers.edit', $this->id));
$actions .= Helper::generateDatatableButton(
'delete',
route('manufacturers.destroy', $this->id),
true, /*enabled*/
trans('admin/manufacturers/message.delete.confirm'),
$this->name
);
$actions .= '</nobr>';
$results = [
'accessories' => $this->accessories()->count(),
'actions' => $actions,
'assets' => $this->assets()->count(),
'consumables' => $this->consumables()->count(),
'id' => $this->id,
'licenses' => $this->licenses()->count(),
'name' => $this->nameUrl(),
];
return $results;
}
/** /**
* Link to this manufacturers name * Link to this manufacturers name

View file

@ -35,7 +35,7 @@ class UserPresenter extends Presenter
"field" => "id", "field" => "id",
"searchable" => true, "searchable" => true,
"sortable" => true, "sortable" => true,
"switchable" => true, "switchable" => false,
"title" => trans('general.id'), "title" => trans('general.id'),
"visible" => false, "visible" => false,
"formatter" => null "formatter" => null

View file

@ -31,28 +31,6 @@
data-cookie="true" data-cookie="true"
data-click-to-select="true" data-click-to-select="true"
data-cookie-id-table="licenseTable"> data-cookie-id-table="licenseTable">
<thead>
<tr>
<th data-checkbox="true" data-field="checkbox"></th>
<th data-sortable="true" data-field="id" data-visible="false">{{ trans('general.id') }}</th>
<th data-field="company" data-searchable="true" data-sortable="true" data-switchable="true" data-visible="false" data-formatter="companiesLinkObjFormatter">{{ trans('general.company') }}</th>
<th data-sortable="true" data-field="name" data-visible="false" data-formatter="licensesLinkFormatter">{{ trans('admin/licenses/table.title') }}</th>
<th data-field="manufacturer" data-sortable="true" data-formatter="manufacturersLinkObjFormatter">{{ trans('general.manufacturer') }}</th>
<th data-field="serial" data-sortable="true" >{{ trans('admin/licenses/form.license_key') }}</th>
<th data-field="license_name" data-sortable="true" data-visible="false">{{ trans('admin/licenses/form.to_name') }}</th>
<th data-field="license_email" data-sortable="true" data-visible="false">{{ trans('admin/licenses/form.to_email') }}</th>
<th data-field="totalSeats" data-sortable="false">{{ trans('admin/licenses/form.seats') }}</th>
<th data-field="remaining" data-sortable="false">{{ trans('admin/licenses/form.remaining_seats') }}</th>
<th data-field="purchase_date" data-sortable="true">{{ trans('general.purchase_date') }}</th>
<th data-field="purchase_cost" data-sortable="true">{{ trans('general.purchase_cost') }}</th>
<th data-field="purchase_order" data-sortable="true" data-visible="false">{{ trans('admin/licenses/form.purchase_order') }}</th>
<th data-field="expiration_date" data-sortable="true" data-visible="false">{{ trans('admin/licenses/form.expiration') }}</th>
<th data-sortable="true" data-field="created_at" data-formatter="createdAtFormatter" data-searchable="true" data-visible="false">{{ trans('general.created_at') }}</th>
<th data-field="notes" data-sortable="true" data-visible="false">{{ trans('admin/hardware/form.notes') }}</th>
<th data-switchable="false" data-searchable="false" data-formatter="licensesActionsFormatter" data-sortable="false" data-field="actions" >{{ trans('table.actions') }}</th>
</tr>
</thead>
</table> </table>
</div><!-- /.box-body --> </div><!-- /.box-body -->
@ -64,6 +42,9 @@
@stop @stop
@section('moar_scripts') @section('moar_scripts')
@include ('partials.bootstrap-table', ['exportFile' => 'licenses-export', 'search' => true]) @include ('partials.bootstrap-table', [
'exportFile' => 'licenses-export',
'search' => true,
'columns' => \App\Presenters\LicensePresenter::dataTableLayout()])
@stop @stop