From 63586c5b1ad8f01047798414b29722460eb85875 Mon Sep 17 00:00:00 2001 From: EJ Beron Date: Thu, 20 Feb 2025 08:26:18 +0800 Subject: [PATCH 01/11] feat: macroable DataTable base class --- src/Services/DataTable.php | 3 +++ tests/DataTableServiceTest.php | 15 +++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/Services/DataTable.php b/src/Services/DataTable.php index 3d2170c..9fd471a 100644 --- a/src/Services/DataTable.php +++ b/src/Services/DataTable.php @@ -15,6 +15,7 @@ use Illuminate\Support\Arr; use Illuminate\Support\Collection; use Illuminate\Support\LazyCollection; +use Illuminate\Support\Traits\Macroable; use Maatwebsite\Excel\ExcelServiceProvider; use OpenSpout\Common\Entity\Style\Style; use Rap2hpoutre\FastExcel\FastExcel; @@ -29,6 +30,8 @@ abstract class DataTable implements DataTableButtons { + use Macroable; + /** * DataTables print preview view. * diff --git a/tests/DataTableServiceTest.php b/tests/DataTableServiceTest.php index 6f82807..91b1b66 100644 --- a/tests/DataTableServiceTest.php +++ b/tests/DataTableServiceTest.php @@ -10,6 +10,7 @@ use Yajra\DataTables\Buttons\Tests\DataTables\UsersDataTable; use Yajra\DataTables\Buttons\Tests\Models\User; use Yajra\DataTables\EloquentDataTable; +use Yajra\DataTables\Services\DataTable; class DataTableServiceTest extends TestCase { @@ -80,6 +81,20 @@ public function it_allows_response_callback(): void $this->assertEquals(1, $response->json('recordsFiltered')); } + #[Test] + public function it_is_macroable(): void + { + $dataTable = new class extends DataTable {}; + + $this->assertObjectHasProperty('macros', $dataTable); + $this->assertTrue(method_exists($dataTable, 'macro'), 'Method macro does not exist.'); + $this->assertTrue(method_exists($dataTable, 'mixin'), 'Method mixin does not exist.'); + + DataTable::macro('macroMethod', fn () => 'macro'); + + $this->assertEquals('macro', $dataTable->macroMethod()); + } + protected function setUp(): void { parent::setUp(); From 45ee406b5140d0fe478b8e944039700e7d104576 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Wed, 26 Feb 2025 15:15:28 +0800 Subject: [PATCH 02/11] chore: release v12.1.0 :rocket: --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cf6e66f..34c9531 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Laravel DataTables Buttons Plugin CHANGELOG. +## v12.1.0 - 2025-02-26 + +- feat: Macroable DataTable Base Class #193 + ## v12.0.0 - 2025-02-26 - Laravel 12.x support From bb4e9b4d1db9da4e0324174e97d5c1825a3d0df0 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Wed, 26 Feb 2025 16:31:07 +0800 Subject: [PATCH 03/11] ci: workflows --- .github/workflows/continuous-integration.yml | 9 ++++--- .github/workflows/pint.yml | 12 +++++++-- .github/workflows/static-analysis.yml | 27 +++++++++++--------- 3 files changed, 31 insertions(+), 17 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 0403887..a521b25 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -2,6 +2,9 @@ name: "Continuous Integration" on: push: + branches: + - master + - 11.x pull_request: schedule: - cron: '0 0 * * *' @@ -14,14 +17,14 @@ jobs: strategy: fail-fast: true matrix: - php: [8.2, 8.3] + php: [8.2, 8.3, 8.4] stability: [prefer-stable] name: PHP ${{ matrix.php }} - ${{ matrix.stability }} steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Setup PHP uses: shivammathur/setup-php@v2 @@ -39,7 +42,7 @@ jobs: with: timeout_minutes: 5 max_attempts: 5 - command: composer update --${{ matrix.stability }} --prefer-dist --no-interaction --no-progress + command: COMPOSER_ROOT_VERSION=dev-master composer update --${{ matrix.stability }} --prefer-dist --no-interaction --no-progress - name: Execute tests run: vendor/bin/phpunit diff --git a/.github/workflows/pint.yml b/.github/workflows/pint.yml index f078347..bac3eab 100644 --- a/.github/workflows/pint.yml +++ b/.github/workflows/pint.yml @@ -7,14 +7,22 @@ on: jobs: phplint: runs-on: ubuntu-latest + + permissions: + contents: write + pull-requests: write + steps: - uses: actions/checkout@v4 + with: + ref: ${{ github.head_ref }} + - name: "laravel-pint" - uses: aglipanci/laravel-pint-action@2.0.0 + uses: aglipanci/laravel-pint-action@latest with: preset: laravel verboseMode: true + - uses: stefanzweifel/git-auto-commit-action@v5 with: commit_message: "fix: pint" - diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index 97dd9ef..bdf913b 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -22,30 +22,33 @@ on: jobs: static-analysis-phpstan: + name: "Static Analysis with PHPStan" runs-on: ubuntu-latest strategy: + fail-fast: true matrix: - php: [8.2, 8.3] + php: [8.2, 8.3, 8.4] + stability: [prefer-stable] steps: - - name: "Checkout code" - uses: "actions/checkout@v4" + - name: Checkout code + uses: actions/checkout@v4 - - name: "Install PHP" - uses: "shivammathur/setup-php@v2" + - name: Setup PHP + uses: shivammathur/setup-php@v2 with: - coverage: "none" - php-version: "${{ matrix.php-version }}" - tools: "cs2pr" + php-version: ${{ matrix.php }} + tools: composer:v2 + coverage: none - name: Install dependencies - uses: nick-fields/retry@v2 + uses: nick-invision/retry@v1 with: timeout_minutes: 5 max_attempts: 5 - command: composer update --prefer-stable --prefer-dist --no-interaction --no-progress + command: COMPOSER_ROOT_VERSION=dev-master composer update --${{ matrix.stability }} --prefer-dist --no-interaction --no-progress - - name: Execute type checking - run: vendor/bin/phpstan --configuration="phpstan.neon.dist" + - name: "Run a static analysis with phpstan/phpstan" + run: "vendor/bin/phpstan --error-format=table" From 0267585b05cb9b9a63785470d5aa3df9dbab97e5 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Wed, 26 Feb 2025 22:53:42 +0800 Subject: [PATCH 04/11] fix: stubs (#195) * fix: stubs * ci: duplicate analysis on push --- .github/workflows/static-analysis.yml | 3 +++ src/Generators/stubs/datatables.stub | 1 - src/Generators/stubs/html.stub | 19 ++++++++++--------- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index bdf913b..5e53d63 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -2,6 +2,9 @@ name: "Static Analysis" on: push: + branches: + - master + - 11.x paths: - .github/workflows/static-analysis.yml - composer.* diff --git a/src/Generators/stubs/datatables.stub b/src/Generators/stubs/datatables.stub index 512be60..bccfede 100644 --- a/src/Generators/stubs/datatables.stub +++ b/src/Generators/stubs/datatables.stub @@ -43,7 +43,6 @@ class DummyClass extends DataTable ->setTableId('DummyTableId') ->columns($this->getColumns()) ->minifiedAjax() - //->dom('DummyDOM') ->orderBy(1) ->selectStyleSingle() ->buttons([ diff --git a/src/Generators/stubs/html.stub b/src/Generators/stubs/html.stub index 37d1dcc..2d1c421 100644 --- a/src/Generators/stubs/html.stub +++ b/src/Generators/stubs/html.stub @@ -2,6 +2,7 @@ namespace DummyNamespace; +use Yajra\DataTables\Html\Builder; use Yajra\DataTables\Html\Button; use Yajra\DataTables\Html\Column; use Yajra\DataTables\Html\DataTableHtml; @@ -17,15 +18,15 @@ class DummyClass extends DataTableHtml */ public function handle(): Builder { - return $this->setTableId('DummyTableId') - ->columns($this->getColumns()) - ->minifiedAjax() - //->dom('DummyDOM') - ->orderBy(1) - ->selectStyleSingle() - ->buttons([ - DummyButtons - ]); + return $this->getHtmlBuilder() + ->setTableId('DummyTableId') + ->columns($this->getColumns()) + ->minifiedAjax() + ->orderBy(1) + ->selectStyleSingle() + ->buttons([ + DummyButtons + ]); } /** From 52bebdaf753abacad0c62368f11403e2a346e3af Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Wed, 26 Feb 2025 22:54:28 +0800 Subject: [PATCH 05/11] chore: release v12.1.1 :rocket: --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 34c9531..99be259 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Laravel DataTables Buttons Plugin CHANGELOG. +## v12.1.1 - 2025-02-26 + +- fix: stubs #195 + ## v12.1.0 - 2025-02-26 - feat: Macroable DataTable Base Class #193 From b0722ca2ec8fa190e7d14c28d102276a24f58db0 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Sat, 1 Mar 2025 14:05:17 +0800 Subject: [PATCH 06/11] ci: workflows --- .github/workflows/continuous-integration.yml | 22 ++++++++----- .github/workflows/pint.yml | 9 ++++-- .github/workflows/static-analysis.yml | 34 +++++--------------- 3 files changed, 29 insertions(+), 36 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index a521b25..800bcb4 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -1,36 +1,42 @@ -name: "Continuous Integration" +name: Continuous Integration on: push: branches: - master - - 11.x + - '*.x' pull_request: schedule: - cron: '0 0 * * *' jobs: - phpunit: - + tests: runs-on: ubuntu-latest + services: + oracle: + image: deepdiver/docker-oracle-xe-11g:2.0 + ports: + - 49160:22 + - 1521:1521 + strategy: fail-fast: true matrix: php: [8.2, 8.3, 8.4] stability: [prefer-stable] - name: PHP ${{ matrix.php }} - ${{ matrix.stability }} + name: PHP ${{ matrix.php }} - STABILITY ${{ matrix.stability }} steps: - name: Checkout code - uses: actions/checkout@v4 + uses: actions/checkout@v2 - name: Setup PHP uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php }} - extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, gd, memcached + extensions: oci8 tools: composer:v2 coverage: none @@ -42,7 +48,7 @@ jobs: with: timeout_minutes: 5 max_attempts: 5 - command: COMPOSER_ROOT_VERSION=dev-master composer update --${{ matrix.stability }} --prefer-dist --no-interaction --no-progress + command: composer update --${{ matrix.stability }} --prefer-dist --no-interaction --no-progress - name: Execute tests run: vendor/bin/phpunit diff --git a/.github/workflows/pint.yml b/.github/workflows/pint.yml index bac3eab..c07577f 100644 --- a/.github/workflows/pint.yml +++ b/.github/workflows/pint.yml @@ -1,11 +1,16 @@ name: PHP Linting + on: pull_request: push: branches: - master + - '*.x' + jobs: - phplint: + pint: + name: Pint + runs-on: ubuntu-latest permissions: @@ -25,4 +30,4 @@ jobs: - uses: stefanzweifel/git-auto-commit-action@v5 with: - commit_message: "fix: pint" + commit_message: "fix: pint :robot:" diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index 5e53d63..4dccad0 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -1,24 +1,12 @@ -name: "Static Analysis" +name: Static Analysis on: push: branches: - master - - 11.x - paths: - - .github/workflows/static-analysis.yml - - composer.* - - phpstan.neon.dist - - src/** - - tests/** + - '*.x' pull_request: - paths: - - .github/workflows/static-analysis.yml - - composer.* - - phpstan.neon.dist - - src/** - - tests/** schedule: - cron: '0 0 * * *' @@ -26,15 +14,9 @@ on: jobs: static-analysis-phpstan: - name: "Static Analysis with PHPStan" + name: Source Code runs-on: ubuntu-latest - strategy: - fail-fast: true - matrix: - php: [8.2, 8.3, 8.4] - stability: [prefer-stable] - steps: - name: Checkout code uses: actions/checkout@v4 @@ -42,16 +24,16 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: ${{ matrix.php }} + php-version: 8.2 tools: composer:v2 coverage: none - name: Install dependencies - uses: nick-invision/retry@v1 + uses: nick-fields/retry@v3 with: timeout_minutes: 5 max_attempts: 5 - command: COMPOSER_ROOT_VERSION=dev-master composer update --${{ matrix.stability }} --prefer-dist --no-interaction --no-progress + command: composer update --prefer-stable --prefer-dist --no-interaction --no-progress - - name: "Run a static analysis with phpstan/phpstan" - run: "vendor/bin/phpstan --error-format=table" + - name: Run Static Analysis + run: vendor/bin/phpstan From 3dd16ee4c86a10ecac05fd6a41fe5e1e59a3bd2e Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Sat, 1 Mar 2025 14:15:05 +0800 Subject: [PATCH 07/11] ci: rm service --- .github/workflows/continuous-integration.yml | 7 ------- 1 file changed, 7 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 800bcb4..fe75aa3 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -13,13 +13,6 @@ jobs: tests: runs-on: ubuntu-latest - services: - oracle: - image: deepdiver/docker-oracle-xe-11g:2.0 - ports: - - 49160:22 - - 1521:1521 - strategy: fail-fast: true matrix: From 9f85d7a75bb2b131b3df7c025f71ef8b887ebe2b Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Tue, 18 Mar 2025 14:37:33 +0800 Subject: [PATCH 08/11] fix: stubs with generics --- src/Generators/stubs/builder.stub | 4 +++- src/Generators/stubs/datatables.stub | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Generators/stubs/builder.stub b/src/Generators/stubs/builder.stub index 2ed2af7..511be79 100644 --- a/src/Generators/stubs/builder.stub +++ b/src/Generators/stubs/builder.stub @@ -13,7 +13,7 @@ class DummyClass extends DataTable /** * Build the DataTable class. * - * @param QueryBuilder $query Results from query() method. + * @param QueryBuilder $query Results from query() method. */ public function dataTable(QueryBuilder $query): EloquentDataTable { @@ -24,6 +24,8 @@ class DummyClass extends DataTable /** * Get the query source of dataTable. + * + * @return QueryBuilder */ public function query(ModelName $model): QueryBuilder { diff --git a/src/Generators/stubs/datatables.stub b/src/Generators/stubs/datatables.stub index bccfede..1a574c1 100644 --- a/src/Generators/stubs/datatables.stub +++ b/src/Generators/stubs/datatables.stub @@ -17,7 +17,7 @@ class DummyClass extends DataTable /** * Build the DataTable class. * - * @param QueryBuilder $query Results from query() method. + * @param QueryBuilder $query Results from query() method. */ public function dataTable(QueryBuilder $query): EloquentDataTable { @@ -28,6 +28,8 @@ class DummyClass extends DataTable /** * Get the query source of dataTable. + * + * @return QueryBuilder */ public function query(ModelName $model): QueryBuilder { From 8f388e3c6890442d9d85368b2a84a414e281b4ae Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Tue, 18 Mar 2025 21:39:50 +0800 Subject: [PATCH 09/11] chore: release v12.1.2 :rocket: --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 99be259..f1b3da5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Laravel DataTables Buttons Plugin CHANGELOG. +## v12.1.2 - 2025-03-18 + +- fix: stubs with generics #196 + ## v12.1.1 - 2025-02-26 - fix: stubs #195 From 999ad17684af282158f0900336e463492f2a9b9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Alfaiate?= Date: Thu, 3 Apr 2025 12:41:25 +0700 Subject: [PATCH 10/11] fix: custom ajax action --- src/Services/DataTable.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Services/DataTable.php b/src/Services/DataTable.php index 9fd471a..64b1a3e 100644 --- a/src/Services/DataTable.php +++ b/src/Services/DataTable.php @@ -172,10 +172,6 @@ public function __construct() */ public function render(?string $view = null, array $data = [], array $mergeData = []) { - if ($this->request()->ajax() && $this->request()->wantsJson()) { - return app()->call($this->ajax(...)); - } - /** @var string $action */ $action = $this->request()->get('action'); $actionMethod = $action === 'print' ? 'printPreview' : $action; @@ -187,6 +183,10 @@ public function render(?string $view = null, array $data = [], array $mergeData return app()->call($callback); } + if ($this->request()->ajax() && $this->request()->wantsJson()) { + return app()->call($this->ajax(...)); + } + /** @phpstan-ignore-next-line */ return view($view, $data, $mergeData)->with($this->dataTableVariable, $this->getHtmlBuilder()); } From 205653ab2c6498d0496dcbb661650b8975ecb55a Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Mon, 7 Apr 2025 23:02:59 +0800 Subject: [PATCH 11/11] chore: release v12.1.3 :rocket: --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f1b3da5..954868c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Laravel DataTables Buttons Plugin CHANGELOG. +## v12.1.3 - 2025-04-07 + +- fix: custom ajax action #197 + ## v12.1.2 - 2025-03-18 - fix: stubs with generics #196