Skip to content

Commit

Permalink
Organisation index page datagrid.
Browse files Browse the repository at this point in the history
  • Loading branch information
suraj-webkul committed Jul 15, 2024
1 parent c81cfa8 commit cfb794e
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 95 deletions.
16 changes: 7 additions & 9 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
.env
.env.testing
.env.backup
.DS_Store
.phpunit.result.cache
docker-compose.override.yml
.idea
.php_cs.cache
.phpunit.result.cache
.vscode
todo.txt
.vagrant
*.hot
/stubs
/data
/docker-compose-collection
Homestead.json
Expand All @@ -17,14 +15,14 @@ Homestead.yaml
/node_modules
npm-debug.log
package-lock.json
/public/css
/public/fonts
/public/css
/public/js
/public/hot
/public/storage
/public/themes
/public/vendor
/lang/vendor
/storage/*.key
/storage/dcc-data/
/stubs
/vendor
yarn.lock
yarn-error.log
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

use Illuminate\Support\Facades\DB;
use Webkul\Contact\Repositories\PersonRepository;
use Webkul\UI\DataGrid\DataGrid;
use Webkul\DataGrid\DataGrid;
use Illuminate\Database\Query\Builder;

class OrganizationDataGrid extends DataGrid
{
Expand All @@ -15,41 +16,33 @@ class OrganizationDataGrid extends DataGrid
*/
public function __construct(protected PersonRepository $personRepository)
{
parent::__construct();
}

/**
* Prepare query builder.
*
* @return void
*/
public function prepareQueryBuilder()
public function prepareQueryBuilder(): Builder
{
$queryBuilder = DB::table('organizations')
return DB::table('organizations')
->addSelect(
'organizations.id',
'organizations.name',
'organizations.address',
'organizations.created_at'
);

$this->addFilter('id', 'organizations.id');

$this->setQueryBuilder($queryBuilder);
}

/**
* Add columns.
*
* @return void
*/
public function addColumns()
public function prepareColumns(): void
{
$this->addColumn([
'index' => 'id',
'label' => trans('admin::app.datagrid.id'),
'type' => 'string',
'sortable' => true,
'index' => 'id',
'label' => trans('admin::app.datagrid.id'),
'type' => 'integer',
'filterable' => true,
'sortable' => true,
]);

$this->addColumn([
Expand All @@ -59,31 +52,6 @@ public function addColumns()
'sortable' => true,
]);

$this->addColumn([
'index' => 'persons_count',
'label' => trans('admin::app.datagrid.persons_count'),
'type' => 'string',
'searchable' => false,
'sortable' => false,
'filterable' => false,
'closure' => function ($row) {
$personsCount = $this->personRepository->findWhere(['organization_id' => $row->id])->count();

$route = urldecode(route('admin.contacts.persons.index', ['organization[in]' => $row->id]));

return "<a href='" . $route . "'>" . $personsCount . "</a>";
},
]);

$this->addColumn([
'index' => 'created_at',
'label' => trans('admin::app.datagrid.created_at'),
'type' => 'date_range',
'sortable' => true,
'closure' => function ($row) {
return core()->formatDate($row->created_at);
},
]);
}

/**
Expand All @@ -94,18 +62,21 @@ public function addColumns()
public function prepareActions()
{
$this->addAction([
'title' => trans('ui::app.datagrid.edit'),
'icon' => 'icon-edit',
'title' => trans('admin::app.catalog.attributes.index.datagrid.edit'),
'method' => 'GET',
'route' => 'admin.contacts.organizations.edit',
'icon' => 'pencil-icon',
'url' => function ($row) {
return route('admin.contacts.organizations.edit', $row->id);
},
]);

$this->addAction([
'title' => trans('ui::app.datagrid.delete'),
'method' => 'DELETE',
'route' => 'admin.contacts.organizations.delete',
'confirm_text' => trans('ui::app.datagrid.mass-action.delete', ['resource' => 'user']),
'icon' => 'trash-icon',
'icon' => 'icon-delete',
'title' => trans('admin::app.catalog.attributes.index.datagrid.delete'),
'method' => 'DELETE',
'url' => function ($row) {
return route('admin.contacts.organizations.delete', $row->id);
},
]);
}

Expand All @@ -117,10 +88,10 @@ public function prepareActions()
public function prepareMassActions()
{
$this->addMassAction([
'type' => 'delete',
'label' => trans('ui::app.datagrid.delete'),
'action' => route('admin.contacts.organizations.mass_delete'),
'icon' => 'icon-delete',
'title' => trans('ui::app.datagrid.delete'),
'method' => 'PUT',
'url' => route('admin.contacts.organizations.mass_delete'),
]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@

namespace Webkul\Admin\Http\Controllers\Contact;

use Illuminate\Http\JsonResponse;
use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Facades\Event;
use Illuminate\View\View;
use Webkul\Admin\Http\Controllers\Controller;
use Webkul\Attribute\Http\Requests\AttributeForm;
use Webkul\Contact\Repositories\OrganizationRepository;
use Webkul\Admin\DataGrids\Contact\OrganizationDataGrid;

class OrganizationController extends Controller
{
Expand All @@ -21,13 +25,11 @@ public function __construct(protected OrganizationRepository $organizationReposi

/**
* Display a listing of the resource.
*
* @return \Illuminate\View\View
*/
public function index()
public function index(): View|JsonResponse
{
if (request()->ajax()) {
return app(\Webkul\Admin\DataGrids\Contact\OrganizationDataGrid::class)->toJson();
return datagrid(OrganizationDataGrid::class)->process();
}

return view('admin::contacts.organizations.index');
Expand All @@ -43,14 +45,10 @@ public function create()
return view('admin::contacts.organizations.create');
}


/**
* Store a newly created resource in storage.
*
* @param \Webkul\Attribute\Http\Requests\AttributeForm $request
* @return \Illuminate\Http\Response
*/
public function store(AttributeForm $request)
public function store(AttributeForm $request): RedirectResponse
{
Event::dispatch('contacts.organization.create.before');

Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
@extends('admin::layouts.master')
<x-admin::layouts>
<x-slot:title>
@lang('admin::app.customers.customers.index.title')
</x-slot>

@section('page_title')
{{ __('admin::app.contacts.organizations.title') }}
@stop
<div class="flex items-center justify-between">
<p class="text-xl font-bold text-gray-800 dark:text-white">
Organizations
</p>

@section('content-wrapper')
<div class="content full-page">
<table-component data-src="{{ route('admin.contacts.organizations.index') }}">
<template v-slot:table-header>
<h1>
{!! view_render_event('admin.contacts.organizations.index.header.before') !!}

{{ Breadcrumbs::render('contacts.organizations') }}
<div class="flex items-center gap-x-2.5">
<!-- Create button for person -->
<div class="flex items-center gap-x-2.5">
<button
class="primary-button"
@click="$refs.createCustomerComponent.openModal()"
>
Create
</button>
</div>
</div>
</div>

{{ __('admin::app.contacts.organizations.title') }}
{!! view_render_event('krayin.admin.organizations.datagrid.index.before') !!}

{!! view_render_event('admin.contacts.organizations.index.header.after') !!}
</h1>
</template>
<x-admin::datagrid src="{{ route('admin.contacts.organizations.index') }}" />

@if (bouncer()->hasPermission('contacts.organizations.create'))
<template v-slot:table-action>
<a href="{{ route('admin.contacts.organizations.create') }}" class="btn btn-md btn-primary">{{ __('admin::app.contacts.organizations.create-title') }}</a>
</template>
@endif
<table-component>
</div>
@stop
{!! view_render_event('krayin.admin.organizations.datagrid.index.after') !!}
</x-admin::layouts>

0 comments on commit cfb794e

Please sign in to comment.