Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
b02eb1d
wip
pxpm Apr 1, 2025
418cf70
Apply fixes from StyleCI
StyleCIBot Apr 1, 2025
b5b07e8
wip
pxpm Apr 25, 2025
991a0e0
Apply fixes from StyleCI
StyleCIBot Apr 25, 2025
b31eafd
wip
pxpm May 2, 2025
5524612
Apply fixes from StyleCI
StyleCIBot May 2, 2025
e0489aa
wip
pxpm May 12, 2025
f614449
fix demo filter in icons that makes no sense
tabacitu May 20, 2025
89b5957
wip
pxpm May 21, 2025
7d55d65
Apply fixes from StyleCI
StyleCIBot May 21, 2025
08b2a1c
WIP add datatable widget in places where it makes sense
tabacitu May 26, 2025
9e6671d
Apply fixes from StyleCI
StyleCIBot May 26, 2025
4725ef3
wip
pxpm May 27, 2025
bc51492
Apply fixes from StyleCI
StyleCIBot May 27, 2025
7bbd80b
better demo of datatables component
tabacitu May 27, 2025
f9ccb77
filters that make more sense
tabacitu May 27, 2025
e561494
wip
pxpm May 30, 2025
24e288d
Apply fixes from StyleCI
StyleCIBot May 30, 2025
0e50d52
wip
pxpm May 30, 2025
c78d7e9
Apply fixes from StyleCI
StyleCIBot May 30, 2025
de0139c
wip
pxpm Jun 4, 2025
833b807
Apply fixes from StyleCI
StyleCIBot Jun 4, 2025
b008940
wip
pxpm Jun 4, 2025
88052f6
Apply fixes from StyleCI
StyleCIBot Jun 4, 2025
425cd30
prettier DataTable component on dashboard
tabacitu Jun 5, 2025
bad1775
Apply fixes from StyleCI
StyleCIBot Jun 5, 2025
2267923
add datatable widget to other themes as well
tabacitu Jun 5, 2025
dbccf98
Merge branch 'datatables-component-example' of https://github.com/Lar…
tabacitu Jun 5, 2025
9eb9cfe
wip
pxpm Jun 5, 2025
4f0acac
remove datatable title from dashboard, was not needed
tabacitu Jun 9, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions app/Http/Controllers/Admin/IconCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@ public function setup()
protected function setupListOperation()
{
$this->crud->addColumns(['name', 'icon']);

$this->crud->addFilter([
'type' => 'date_range',
'name' => 'created_at',
'label' => 'Created At',
], null, function ($value) {
$value = json_decode($value, true);

// if the filter is active
if ($value) {
$this->crud->addClause('where', 'created_at', '>=', $value['from']);
$this->crud->addClause('where', 'created_at', '<=', $value['to']);
}
});
}

protected function setupCreateOperation()
Expand Down
50 changes: 49 additions & 1 deletion app/Http/Controllers/Admin/MonsterCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Http\Requests\MonsterRequest as StoreRequest;
// VALIDATION: change the requests to match your own file names if you need form validation
use Backpack\CRUD\app\Http\Controllers\CrudController;
use Backpack\CRUD\app\Library\Widget;
use Illuminate\Support\Collection;

class MonsterCrudController extends CrudController
Expand Down Expand Up @@ -64,7 +65,7 @@ public function fetchPaginatedTypes()
['id' => 'review', 'title' => 'Review', 'location' => 'Hybrid'],
];

Collection::macro('paginate', function (int $perPage = 15, int $page = null, array $options = []) {
Collection::macro('paginate', function (int $perPage = 15, ?int $page = null, array $options = []) {
$page ??= \Illuminate\Pagination\Paginator::resolveCurrentPage() ?? 1;

return new \Illuminate\Pagination\LengthAwarePaginator($this->forPage($page, $perPage)->toArray(), $this->count(), $perPage, $page, $options);
Expand Down Expand Up @@ -279,6 +280,53 @@ public function setupListOperation()

public function setupShowOperation()
{
// add a widget
Widget::add([
'type' => 'datatable',
'controller' => 'App\Http\Controllers\Admin\IconCrudController',
'name' => 'icon_crud',
'section' => 'after_content',
'content' => [
'header' => 'Icons for this monster',
],
'wrapper' => ['class'=> 'mb-3'],
]);

Widget::add([
'type' => 'datatable',
'controller' => 'App\Http\Controllers\Admin\ProductCrudController',
'name' => 'products_datatable',
'section' => 'after_content',
'content' => [
'header' => 'Products for this monster',
],
'wrapper' => ['class'=> 'mb-3'],
'configure' => function ($crud, $entry = null) {
// Customize which columns to show
$crud->removeAllColumns();
$crud->addColumn(['name' => 'name', 'label' => 'Product Name']);
$crud->addColumn(['name' => 'price', 'label' => 'Price']);

// Get the current monster's products
if ($entry) {
$productIds = $entry->products->pluck('id')->toArray();
if (count($productIds) > 0) {
// Configure the controller to only show products related to this monster
$crud->addClause('whereIn', 'id', $productIds);
} else {
// Force an empty result when there are no products
$crud->addClause('where', 'id', 0); // This will match no products
}

// Remove buttons that aren't needed for this embedded view

// Disable features that aren't needed
$crud->denyAccess(['create', 'update', 'delete']);
$crud->disableResponsiveTable();
}
},
]);

$this->crud->setOperationSetting('tabsEnabled', true);
$this->setupListOperation();

Expand Down
18 changes: 18 additions & 0 deletions app/Http/Controllers/Admin/PetShop/InvoiceCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,24 @@ protected function setupListOperation()
CRUD::column('due_date');
CRUD::column('total');

CRUD::filter('series')
->type('dropdown')
->values(\App\Models\PetShop\Invoice::select('series')->distinct()->pluck('series', 'series')->toArray())
->label('Series')
->placeholder('Search by series')
->whenActive(function ($value) {
CRUD::addClause('where', 'series', '=', $value);
});

CRUD::filter('issuance_date')
->type('date_range')
->label('Issuance Date')
->placeholder('Search by issuance date')
->whenActive(function ($value) {
$dates = json_decode($value);
CRUD::addClause('whereBetween', 'issuance_date', [$dates->from, $dates->to]);
});

$this->runCustomViews();
}

Expand Down
44 changes: 44 additions & 0 deletions app/Http/Controllers/Admin/PetShop/OwnerCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Http\Requests\OwnerRequest;
use Backpack\CRUD\app\Http\Controllers\CrudController;
use Backpack\CRUD\app\Library\CrudPanel\CrudPanelFacade as CRUD;
use Backpack\CRUD\app\Library\Widget;

/**
* Class OwnerCrudController.
Expand Down Expand Up @@ -99,4 +100,47 @@ protected function setupUpdateOperation()
{
$this->setupCreateOperation();
}

protected function setupShowOperation()
{
$this->setupListOperation();

Widget::add([
'type' => 'datatable',
'controller' => 'App\Http\Controllers\Admin\PetShop\PetCrudController',
'name' => 'pets_crud',
'section' => 'after_content',
'wrapper' => ['class' => 'mt-3'],
'content' => [
'header' => 'Pets for this owner',
// COULD-DO: maybe add support for a subheader?
// 'subheader' => 'This is a list of all pets owned by this owner.',
],
'setup' => function ($crud, $parent) {
// change some column attributes just inside this instance
$crud->column('skills')->label('Pet skills');
$crud->column('passport.number')->label('Passport Number');

// only show the pets of this owner (owner is an n-n relationship)
$crud->addClause('whereHas', 'owners', function ($query) use ($parent) {
$query->where('id', $parent->id);
});
},
]);
Widget::add([
'type' => 'datatable',
'controller' => 'App\Http\Controllers\Admin\PetShop\InvoiceCrudController',
'name' => 'invoices_crud',
'section' => 'after_content',
'wrapper' => ['class' => 'mt-3'],
'content' => [
'header' => 'Invoices for this owner',
],
// MUST-DO: How the fuck do I make this only show related pets?!?!
'setup' => function ($crud, $parent) {
// only show the pets of this owner (owner is an n-n relationship)
$crud->addClause('where', 'owner_id', $parent->id);
},
]);
}
}
13 changes: 13 additions & 0 deletions app/Http/Controllers/Admin/PetShop/PetCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,19 @@ protected function setupListOperation()
CRUD::column('avatar.url')->type('image')->label('Avatar');

CRUD::addButtonFromView('top', 'passports', 'passports');

CRUD::filter('skills')
->type('select2_multiple')
->values(function () {
return \App\Models\Petshop\Skill::all()->keyBy('id')->pluck('name', 'id')->toArray();
})
->whenActive(function ($values) {
$values = json_decode($values, true);

$this->crud->addClause('whereHas', 'skills', function ($query) use ($values) {
$query->whereIn('id', $values);
});
});
}

/**
Expand Down
Loading