mirror of
https://github.com/snipe/snipe-it.git
synced 2025-02-21 03:15:45 -08:00
Fixes #3724 - adds edit/delete button back to companies listing
This commit is contained in:
parent
06c04bf271
commit
31cabaa4db
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
namespace App\Http\Controllers\Api;
|
namespace App\Http\Controllers\Api;
|
||||||
|
|
||||||
use App\Http\Transformers\DatatablesTransformer;
|
use App\Http\Transformers\CompaniesTransformer;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Helpers\Helper;
|
use App\Helpers\Helper;
|
||||||
|
@ -23,7 +23,10 @@ class CompaniesController extends Controller
|
||||||
|
|
||||||
$allowed_columns = ['id','name'];
|
$allowed_columns = ['id','name'];
|
||||||
|
|
||||||
$companies = Company::withCount('assets','licenses','accessories','consumables','components','users');
|
$companies = Company::withCount('assets','licenses','accessories','consumables','components','users')
|
||||||
|
->withCount('users')->withCount('users')->withCount('assets')
|
||||||
|
->withCount('licenses')->withCount('accessories')
|
||||||
|
->withCount('consumables')->withCount('components');
|
||||||
|
|
||||||
if ($request->has('search')) {
|
if ($request->has('search')) {
|
||||||
$companies->TextSearch($request->input('search'));
|
$companies->TextSearch($request->input('search'));
|
||||||
|
@ -37,7 +40,7 @@ class CompaniesController extends Controller
|
||||||
|
|
||||||
$total = $companies->count();
|
$total = $companies->count();
|
||||||
$companies = $companies->skip($offset)->take($limit)->get();
|
$companies = $companies->skip($offset)->take($limit)->get();
|
||||||
return (new DatatablesTransformer)->transformDatatables($companies, $total);
|
return (new CompaniesTransformer)->transformCompanies($companies, $total);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
53
app/Http/Transformers/CompaniesTransformer.php
Normal file
53
app/Http/Transformers/CompaniesTransformer.php
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
<?php
|
||||||
|
namespace App\Http\Transformers;
|
||||||
|
|
||||||
|
use App\Models\Company;
|
||||||
|
use Illuminate\Database\Eloquent\Collection;
|
||||||
|
use Gate;
|
||||||
|
use App\Helpers\Helper;
|
||||||
|
|
||||||
|
class CompaniesTransformer
|
||||||
|
{
|
||||||
|
|
||||||
|
public function transformCompanies (Collection $companies, $total)
|
||||||
|
{
|
||||||
|
$array = array();
|
||||||
|
foreach ($companies as $company) {
|
||||||
|
$array[] = self::transformCompany($company);
|
||||||
|
}
|
||||||
|
return (new DatatablesTransformer)->transformDatatables($array, $total);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function transformCompany (Company $company = null)
|
||||||
|
{
|
||||||
|
if ($company) {
|
||||||
|
|
||||||
|
$array = [
|
||||||
|
'id' => e($company->id),
|
||||||
|
'name' => e($company->name),
|
||||||
|
"created_at" => Helper::getFormattedDateObject($company->created_at, 'datetime'),
|
||||||
|
"updated_at" => Helper::getFormattedDateObject($company->updated_at, 'datetime'),
|
||||||
|
"assets_count" => $company->assets_count,
|
||||||
|
"licenses_count" => $company->licenses_count,
|
||||||
|
"accessories_count" => $company->accessories_count,
|
||||||
|
"consumables_count" => $company->consumables_count,
|
||||||
|
"components_count" => $company->components_count,
|
||||||
|
"users_count" => $company->users_count
|
||||||
|
];
|
||||||
|
|
||||||
|
$permissions_array['available_actions'] = [
|
||||||
|
'update' => Gate::allows('update', Company::class) ? true : false,
|
||||||
|
'delete' => Gate::allows('delete', Company::class) ? true : false,
|
||||||
|
];
|
||||||
|
|
||||||
|
$array += $permissions_array;
|
||||||
|
|
||||||
|
return $array;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -8,6 +8,93 @@ namespace App\Presenters;
|
||||||
*/
|
*/
|
||||||
class CompanyPresenter extends Presenter
|
class CompanyPresenter 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,
|
||||||
|
"switchable" => true,
|
||||||
|
"title" => trans('admin/companies/table.name'),
|
||||||
|
"visible" => true,
|
||||||
|
"formatter" => 'companiesLinkFormatter',
|
||||||
|
],[
|
||||||
|
"field" => "users_count",
|
||||||
|
"searchable" => false,
|
||||||
|
"sortable" => false,
|
||||||
|
"title" => '<span class="hidden-xs"><i class="fa fa-users"></i></span><span class="hidden-md hidden-lg">'.trans('general.users').'</span></th>',
|
||||||
|
"visible" => true,
|
||||||
|
|
||||||
|
],[
|
||||||
|
"field" => "assets_count",
|
||||||
|
"searchable" => false,
|
||||||
|
"sortable" => false,
|
||||||
|
"title" => '<span class="hidden-xs"><i class="fa fa-barcode"></i></span><span class="hidden-md hidden-lg">'.trans('general.assets').'</span>',
|
||||||
|
"visible" => true,
|
||||||
|
|
||||||
|
],[
|
||||||
|
"field" => "licenses_count",
|
||||||
|
"searchable" => false,
|
||||||
|
"sortable" => false,
|
||||||
|
"visible" => true,
|
||||||
|
"title" => ' <span class="hidden-xs"><i class="fa fa-floppy-o"></i></span><span class="hidden-md hidden-lg">'.trans('general.licenses').'</span>',
|
||||||
|
],[
|
||||||
|
"field" => "accessories_count",
|
||||||
|
"searchable" => false,
|
||||||
|
"sortable" => false,
|
||||||
|
"visible" => true,
|
||||||
|
"title" => ' <span class="hidden-xs"><i class="fa fa-keyboard-o"></i></span><span class="hidden-md hidden-lg">'.trans('general.accessories').'</span>',
|
||||||
|
],[
|
||||||
|
"field" => "consumables_count",
|
||||||
|
"searchable" => false,
|
||||||
|
"sortable" => false,
|
||||||
|
"visible" => true,
|
||||||
|
"title" => ' <span class="hidden-xs"><i class="fa fa-tint"></i></span><span class="hidden-md hidden-lg">'.trans('general.consumables').'</span>',
|
||||||
|
],[
|
||||||
|
"field" => "components_count",
|
||||||
|
"searchable" => false,
|
||||||
|
"sortable" => false,
|
||||||
|
"visible" => true,
|
||||||
|
"title" => ' <span class="hidden-xs"><i class="fa fa-hdd-o"></i></span><span class="hidden-md hidden-lg">'.trans('general.components').'</span>',
|
||||||
|
],[
|
||||||
|
"field" => "updated_at",
|
||||||
|
"searchable" => false,
|
||||||
|
"sortable" => false,
|
||||||
|
"visible" => false,
|
||||||
|
"title" => trans('general.updated_at'),
|
||||||
|
],[
|
||||||
|
"field" => "created_at",
|
||||||
|
"searchable" => false,
|
||||||
|
"sortable" => false,
|
||||||
|
"visible" => false,
|
||||||
|
"title" => trans('general.created_at'),
|
||||||
|
],[
|
||||||
|
"field" => "actions",
|
||||||
|
"searchable" => false,
|
||||||
|
"sortable" => false,
|
||||||
|
"switchable" => false,
|
||||||
|
"title" => trans('table.actions'),
|
||||||
|
"visible" => true,
|
||||||
|
"formatter" => "companiesActionsFormatter",
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
return json_encode($layout);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Link to this companies name
|
* Link to this companies name
|
||||||
* @return string
|
* @return string
|
||||||
|
|
|
@ -25,36 +25,6 @@
|
||||||
data-cookie="true"
|
data-cookie="true"
|
||||||
data-click-to-select="true"
|
data-click-to-select="true"
|
||||||
data-cookie-id-table="companiesTable-{{ config('version.hash_version') }}">
|
data-cookie-id-table="companiesTable-{{ config('version.hash_version') }}">
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th data-sortable="true" data-field="id" data-visible="false">{{ trans('general.id') }}</th>
|
|
||||||
<th data-sortable="true" data-formatter="companiesLinkFormatter" data-field="name" data-searchable="true">{{ trans('admin/companies/table.name') }}</th>
|
|
||||||
<th data-sortable="false" data-field="users_count" data-formatter="usersCompanyObjFilterFormatter" data-searchable="false">
|
|
||||||
<span class="hidden-xs"><i class="fa fa-users"></i></span>
|
|
||||||
<span class="hidden-md hidden-lg">{{ trans('general.users') }}</span></th>
|
|
||||||
<th data-sortable="false" data-field="assets_count" data-searchable="false" data-formatter="assetCompanyFilterFormatter">
|
|
||||||
<span class="hidden-xs"><i class="fa fa-barcode"></i></span>
|
|
||||||
<span class="hidden-md hidden-lg">{{ trans('general.assets') }}</span></th>
|
|
||||||
</th>
|
|
||||||
<th data-sortable="false" data-field="licenses_count" data-searchable="false">
|
|
||||||
<span class="hidden-xs"><i class="fa fa-floppy-o"></i></span>
|
|
||||||
<span class="hidden-md hidden-lg">{{ trans('general.licenses') }}</span></th>
|
|
||||||
</th>
|
|
||||||
<th data-sortable="false" data-field="accessories_count" data-searchable="false">
|
|
||||||
<span class="hidden-xs"><i class="fa fa-keyboard-o"></i></span>
|
|
||||||
<span class="hidden-md hidden-lg">{{ trans('general.accessories') }}</span></th>
|
|
||||||
</th>
|
|
||||||
<th data-sortable="false" data-field="consumables_count" data-searchable="false">
|
|
||||||
<span class="hidden-xs"><i class="fa fa-tint"></i></span>
|
|
||||||
<span class="hidden-md hidden-lg">{{ trans('general.consumables') }}</span></th>
|
|
||||||
</th>
|
|
||||||
<th data-sortable="false" data-field="components_count" data-searchable="false">
|
|
||||||
<span class="hidden-xs"><i class="fa fa-hdd-o"></i></span>
|
|
||||||
<span class="hidden-md hidden-lg">{{ trans('general.users') }}</span></th>
|
|
||||||
</th>
|
|
||||||
<th data-switchable="false" data-formatter="companiesActionsFormatter" data-searchable="false" data-sortable="false" data-field="actions">{{ trans('table.actions') }}</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -71,6 +41,10 @@
|
||||||
@stop
|
@stop
|
||||||
|
|
||||||
@section('moar_scripts')
|
@section('moar_scripts')
|
||||||
@include ('partials.bootstrap-table', ['exportFile' => 'companies-export', 'search' => true])
|
@include ('partials.bootstrap-table', [
|
||||||
|
'exportFile' => 'companies-export',
|
||||||
|
'search' => true,
|
||||||
|
'columns' => \App\Presenters\CompanyPresenter::dataTableLayout()
|
||||||
|
])
|
||||||
|
|
||||||
@stop
|
@stop
|
||||||
|
|
Loading…
Reference in a new issue