diff --git a/app/Http/Controllers/Api/CompaniesController.php b/app/Http/Controllers/Api/CompaniesController.php index ee63e34b0a..89b56995cd 100644 --- a/app/Http/Controllers/Api/CompaniesController.php +++ b/app/Http/Controllers/Api/CompaniesController.php @@ -2,7 +2,7 @@ namespace App\Http\Controllers\Api; -use App\Http\Transformers\DatatablesTransformer; +use App\Http\Transformers\CompaniesTransformer; use Illuminate\Http\Request; use App\Http\Controllers\Controller; use App\Helpers\Helper; @@ -23,7 +23,10 @@ class CompaniesController extends Controller $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')) { $companies->TextSearch($request->input('search')); @@ -37,7 +40,7 @@ class CompaniesController extends Controller $total = $companies->count(); $companies = $companies->skip($offset)->take($limit)->get(); - return (new DatatablesTransformer)->transformDatatables($companies, $total); + return (new CompaniesTransformer)->transformCompanies($companies, $total); } diff --git a/app/Http/Transformers/CompaniesTransformer.php b/app/Http/Transformers/CompaniesTransformer.php new file mode 100644 index 0000000000..e4ad3a47b0 --- /dev/null +++ b/app/Http/Transformers/CompaniesTransformer.php @@ -0,0 +1,53 @@ +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; + } + + + } + + + +} diff --git a/app/Presenters/CompanyPresenter.php b/app/Presenters/CompanyPresenter.php index 7bae7ffeda..caf1690dd6 100644 --- a/app/Presenters/CompanyPresenter.php +++ b/app/Presenters/CompanyPresenter.php @@ -8,6 +8,93 @@ namespace App\Presenters; */ 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" => '', + "visible" => true, + + ],[ + "field" => "assets_count", + "searchable" => false, + "sortable" => false, + "title" => '', + "visible" => true, + + ],[ + "field" => "licenses_count", + "searchable" => false, + "sortable" => false, + "visible" => true, + "title" => ' ', + ],[ + "field" => "accessories_count", + "searchable" => false, + "sortable" => false, + "visible" => true, + "title" => ' ', + ],[ + "field" => "consumables_count", + "searchable" => false, + "sortable" => false, + "visible" => true, + "title" => ' ', + ],[ + "field" => "components_count", + "searchable" => false, + "sortable" => false, + "visible" => true, + "title" => ' ', + ],[ + "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 * @return string diff --git a/resources/views/companies/index.blade.php b/resources/views/companies/index.blade.php index 49e3db042d..37f0653f3e 100644 --- a/resources/views/companies/index.blade.php +++ b/resources/views/companies/index.blade.php @@ -25,36 +25,6 @@ data-cookie="true" data-click-to-select="true" data-cookie-id-table="companiesTable-{{ config('version.hash_version') }}"> - - - {{ trans('general.id') }} - {{ trans('admin/companies/table.name') }} - - - - - - - - - - - - - - - - - - - - - - - - {{ trans('table.actions') }} - - @@ -71,6 +41,10 @@ @stop @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