mirror of
https://github.com/snipe/snipe-it.git
synced 2025-01-11 22:07:29 -08:00
Moving license index to new API format
This commit is contained in:
parent
eb3767890e
commit
c67b44b3d5
|
@ -29,7 +29,7 @@ class LicensesController extends Controller
|
|||
$offset = request('offset', 0);
|
||||
$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';
|
||||
$sort = in_array($request->input('sort'), $allowed_columns) ? e($request->input('sort')) : 'created_at';
|
||||
|
||||
|
@ -45,7 +45,6 @@ class LicensesController extends Controller
|
|||
break;
|
||||
}
|
||||
|
||||
|
||||
$total = $licenses->count();
|
||||
$licenses = $licenses->skip($offset)->take($limit)->get();
|
||||
return (new LicensesTransformer)->transformLicenses($licenses, $total);
|
||||
|
|
|
@ -4,6 +4,7 @@ namespace App\Http\Transformers;
|
|||
use App\Models\License;
|
||||
use Gate;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use App\Helpers\Helper;
|
||||
|
||||
class LicensesTransformer
|
||||
{
|
||||
|
@ -22,21 +23,23 @@ class LicensesTransformer
|
|||
$array = [
|
||||
'id' => $license->id,
|
||||
'name' => e($license->name),
|
||||
'company' => e($license->company->name),
|
||||
'manufacturer' => ($license->manufacturer) ? $license->manufacturer : null,
|
||||
'serial' => e($license->name),
|
||||
'purchase_order' => e($license->order_number),
|
||||
'company' => ($license->company) ? ['id' => $license->company->id,'name'=> e($license->company->name)] : null,
|
||||
'manufacturer' => ($license->manufacturer) ? ['id' => $license->manufacturer->id,'name'=> e($license->manufacturer->name)] : null,
|
||||
'product_key' => e($license->serial),
|
||||
'order_number' => e($license->order_number),
|
||||
'purchase_order' => e($license->purchase_order),
|
||||
'purchase_date' => e($license->purchase_date),
|
||||
'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),
|
||||
'expiration_date' => e($license->expiration_date),
|
||||
'totalSeats' => e($license->seats),
|
||||
'remaining' => $license->remaincount(),
|
||||
'license_name' => e($license->license_name),
|
||||
'total_seats' => e($license->seats),
|
||||
'remaining_qty' => $license->remaincount(),
|
||||
'min_qty' => $license->remaincount(),
|
||||
'license_name' => Helper::formatCurrencyOutput($license->purchase_cost),
|
||||
'license_email' => e($license->license_email),
|
||||
'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,
|
||||
];
|
||||
|
||||
|
|
|
@ -25,6 +25,13 @@ class AccessoryPresenter extends Presenter
|
|||
{
|
||||
$layout = [
|
||||
[
|
||||
"field" => "id",
|
||||
"searchable" => false,
|
||||
"sortable" => true,
|
||||
"switchable" => true,
|
||||
"title" => trans('general.id'),
|
||||
"visible" => false
|
||||
], [
|
||||
"field" => "company",
|
||||
"searchable" => true,
|
||||
"sortable" => true,
|
||||
|
|
|
@ -16,48 +16,6 @@ use App\Helpers\Helper;
|
|||
*/
|
||||
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
|
||||
|
|
|
@ -10,31 +10,6 @@ use App\Helpers\Helper;
|
|||
*/
|
||||
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
|
||||
|
|
|
@ -10,28 +10,5 @@ use App\Helpers\Helper;
|
|||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,60 +12,108 @@ use Illuminate\Support\Facades\Gate;
|
|||
class LicensePresenter extends Presenter
|
||||
{
|
||||
/**
|
||||
* JSON representation of this license for data table.
|
||||
* @return array
|
||||
* Json Column Layout for bootstrap table
|
||||
* @return string
|
||||
*/
|
||||
public function forDataTable()
|
||||
public static function dataTableLayout()
|
||||
{
|
||||
$actions = '<span style="white-space: nowrap;">';
|
||||
|
||||
if (Gate::allows('checkout', License::class)) {
|
||||
$actions .= Helper::generateDatatableButton(
|
||||
'checkout',
|
||||
route('licenses.freecheckout', $this->id),
|
||||
$this->remaincount() > 0
|
||||
);
|
||||
}
|
||||
|
||||
if (Gate::allows('create', $this->model)) {
|
||||
$actions .= Helper::generateDatatableButton('clone', route('clone/license', $this->id));
|
||||
}
|
||||
if (Gate::allows('update', $this->model)) {
|
||||
$actions .= Helper::generateDatatableButton('edit', route('licenses.edit', $this->id));
|
||||
}
|
||||
if (Gate::allows('delete', $this->model)) {
|
||||
$actions .= Helper::generateDatatableButton(
|
||||
'delete',
|
||||
route('licenses.destroy', $this->id),
|
||||
true, /*enabled*/
|
||||
trans('admin/licenses/message.delete.confirm'),
|
||||
$this->name
|
||||
);
|
||||
}
|
||||
$actions .='</span>';
|
||||
|
||||
$results = [
|
||||
'actions' => $actions,
|
||||
'company' => $this->companyUrl(),
|
||||
'expiration_date' => $this->expiration_date,
|
||||
'id' => $this->id,
|
||||
'license_email' => $this->license_email,
|
||||
'license_name' => $this->license_name,
|
||||
'manufacturer' => $this->manufacturerUrl(),
|
||||
'name' => $this->nameUrl(),
|
||||
'notes' => $this->notes,
|
||||
'order_number' => $this->order_number,
|
||||
'purchase_cost' => Helper::formatCurrencyOutput($this->purchase_cost),
|
||||
'purchase_date' => $this->purchase_date,
|
||||
'purchase_order' => $this->purchase_order,
|
||||
'remaining' => $this->remaincount(),
|
||||
'serial' => $this->serialUrl(),
|
||||
'totalSeats' => $this->model->licenseSeatsCount,
|
||||
$layout = [
|
||||
[
|
||||
"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,
|
||||
"title" => trans('admin/licenses/table.title'),
|
||||
"formatter" => "licensesLinkFormatter"
|
||||
], [
|
||||
"field" => "product_key",
|
||||
"searchable" => true,
|
||||
"sortable" => true,
|
||||
"title" => trans('admin/licenses/form.license_key'),
|
||||
"formatter" => "licensesLinkFormatter"
|
||||
], [
|
||||
"field" => "expiration_date",
|
||||
"searchable" => true,
|
||||
"sortable" => true,
|
||||
"title" => trans('admin/licenses/form.expiration')
|
||||
], [
|
||||
"field" => "license_email",
|
||||
"searchable" => true,
|
||||
"sortable" => true,
|
||||
"title" => trans('admin/licenses/form.to_email')
|
||||
], [
|
||||
"field" => "license_name",
|
||||
"searchable" => true,
|
||||
"sortable" => true,
|
||||
"title" => trans('admin/licenses/form.to_name'),
|
||||
], [
|
||||
"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
|
||||
* @return string
|
||||
|
|
|
@ -10,41 +10,6 @@ use App\Helpers\Helper;
|
|||
*/
|
||||
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
|
||||
|
|
|
@ -11,35 +11,6 @@ use App\Helpers\Helper;
|
|||
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
|
||||
|
|
|
@ -35,7 +35,7 @@ class UserPresenter extends Presenter
|
|||
"field" => "id",
|
||||
"searchable" => true,
|
||||
"sortable" => true,
|
||||
"switchable" => true,
|
||||
"switchable" => false,
|
||||
"title" => trans('general.id'),
|
||||
"visible" => false,
|
||||
"formatter" => null
|
||||
|
|
|
@ -31,28 +31,6 @@
|
|||
data-cookie="true"
|
||||
data-click-to-select="true"
|
||||
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>
|
||||
</div><!-- /.box-body -->
|
||||
|
||||
|
@ -64,6 +42,9 @@
|
|||
@stop
|
||||
|
||||
@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
|
||||
|
|
Loading…
Reference in a new issue