From dc95ed79c1e9f35a421d4466bc839a2e5451a854 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Tue, 7 Feb 2023 09:42:54 +0800 Subject: [PATCH 001/148] build: laravel 10 deps --- composer.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index 4d2db56..a8068ba 100644 --- a/composer.json +++ b/composer.json @@ -16,14 +16,14 @@ } ], "require": { - "php": "^8.0.2", + "php": "^8.1", "ext-json": "*", "yajra/laravel-datatables-oracle": "^10.0", "laravelcollective/html": "^6.3.0" }, "require-dev": { - "nunomaduro/larastan": "^2.1", - "orchestra/testbench": "^7.3" + "nunomaduro/larastan": "^2.4", + "orchestra/testbench": "^7.21" }, "autoload": { "psr-4": { @@ -37,7 +37,7 @@ }, "extra": { "branch-alias": { - "dev-master": "9.0-dev" + "dev-master": "10.0-dev" }, "laravel": { "providers": [ From c995acdbc85cfc8fafccddabd53ee6c9ea8f24cf Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Tue, 7 Feb 2023 09:48:05 +0800 Subject: [PATCH 002/148] chore: drop 8, add 8.2 --- .github/workflows/continuous-integration.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index c58ccce..49033a2 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -14,7 +14,7 @@ jobs: strategy: fail-fast: true matrix: - php: [8.0, 8.1] + php: [8.1, 8.2] stability: [prefer-stable] name: PHP ${{ matrix.php }} - ${{ matrix.stability }} From bf41fbad3a75a594b87439b0c4445758e3fcefb2 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Tue, 7 Feb 2023 11:47:39 +0800 Subject: [PATCH 003/148] docs: laravel 10 --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 31e0985..97e7542 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Laravel DataTables Html Plugin. -[![Laravel 9.x](https://img.shields.io/badge/Laravel-9.x-orange.svg)](http://laravel.com) +[![Laravel 10.x](https://img.shields.io/badge/Laravel-10.x-orange.svg)](http://laravel.com) [![Latest Stable Version](https://img.shields.io/packagist/v/yajra/laravel-datatables-html.svg)](https://packagist.org/packages/yajra/laravel-datatables-html) ![Build Status](https://github.com/yajra/laravel-datatables-html/workflows/tests/badge.svg) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/yajra/laravel-datatables-html/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/yajra/laravel-datatables-html/?branch=master) @@ -25,10 +25,11 @@ This package is a plugin of [Laravel DataTables](https://github.com/yajra/larave |:--------------|:--------| | 8.x and below | 4.x | | 9.x | 9.x | +| 10.x | 10.x | ## Quick Installation -`composer require yajra/laravel-datatables-html:^9.0` +`composer require yajra/laravel-datatables-html:^10` #### Service Provider (Optional on Laravel 5.5+) From 92cefae7c2b7877f7c334571f9c57a509459af4e Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Tue, 7 Feb 2023 11:47:51 +0800 Subject: [PATCH 004/148] docs: laravel 10 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 97e7542..968c17b 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ This package is a plugin of [Laravel DataTables](https://github.com/yajra/larave ## Requirements -- [Laravel 9.x](https://github.com/laravel/framework) +- [Laravel 10.x](https://github.com/laravel/framework) - [Laravel DataTables](https://github.com/yajra/laravel-datatables) ## Documentations From f0135260c9e0d454dfaa369716e5efdfd59231c6 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Tue, 7 Feb 2023 11:50:22 +0800 Subject: [PATCH 005/148] chore: release v10.0.0 :rocket: --- CHANGELOG.md | 87 ++-------------------------------------------------- 1 file changed, 2 insertions(+), 85 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 66cc0b5..b529ece 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,89 +8,6 @@ ## CHANGELOG -### v9.3.4 - 2022-10-06 +### v10.0.0 - 2023-02-07 -- fix(editor): Fix typehint to match value helper #172 - -### v9.3.3 - 2022-10-05 - -- Fix ajax form search with textarea #171 - -### v9.3.2 - 2022-07-04 - -- Fix collection key - value - -### v9.3.1 - 2022-07-04 - -- Fix magic property type - -### v9.3.0 - 2022-07-01 - -- Add nullDefault() method #166 - -### v9.2.6 - 2022-06-30 - -- Allow array on default() method #165 - -### v9.2.5 - 2022-06-02 - -- Added: Builder addButton method -- Changed: Builder buttons method will reset existing buttons - -### v9.2.4 - 2022-05-21 - -- Use $this in Editor events magic method #164 - -### v9.2.3 - 2022-05-21 - -- Add option to override results wrap key - -### v9.2.2 - 2022-05-20 - -- Fix select2 paginated results and ajax setter - -### v9.2.1 - 2022-05-19 - -- Fix select2 placeholder default id value -- Add select2 tests -- Fix select2 placeholder compatibility - -### v9.2.0 - 2022-05-19 - -- Add postAjaxWithForm -- Fix multiple form values for select and checkbox #163 - -### v9.1.2 - 2022-05-14 - -- Fix Undefined property: Yajra\DataTables\Html\Builder::$instance - -### v9.1.1 - 2022-05-14 - -- Fix Undefined array key "{plugin_name}" -- More tests - -### v9.1.0 - 2022-05-14 - -- A lot of tests and fixes -- Fix #https://github.com/yajra/laravel-datatables-html/issues/162 -- Added Column authorization - -### v9.0.3 - 2022-05-13 - -- Fix attr setter - -### v9.0.2 - 2022-05-13 - -- Fix opts and attr setter - -### v9.0.1 - 2022-05-08 - -- Allow array for orthogonal column data -- REF: https://github.com/yajra/laravel-datatables/pull/2380 - -### v9.0.0 - 2022-05-08 - -- Add Laravel 9 support -- Remove Laravel 8 and below support -- Add phpstan static analysis -- Improve tests \ No newline at end of file +- Add Laravel 10 specific support From 1559b635c6451ec21c96c32dbeee0d0a13d7c716 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Tue, 7 Feb 2023 13:08:59 +0800 Subject: [PATCH 006/148] build: drop collective html dependency --- composer.json | 3 +-- src/Html/Builder.php | 2 +- src/Html/HtmlBuilder.php | 32 ++++++++++++++++++++++++++++++++ src/HtmlServiceProvider.php | 3 --- 4 files changed, 34 insertions(+), 6 deletions(-) create mode 100644 src/Html/HtmlBuilder.php diff --git a/composer.json b/composer.json index a8068ba..2b9d3e5 100644 --- a/composer.json +++ b/composer.json @@ -18,8 +18,7 @@ "require": { "php": "^8.1", "ext-json": "*", - "yajra/laravel-datatables-oracle": "^10.0", - "laravelcollective/html": "^6.3.0" + "yajra/laravel-datatables-oracle": "^10.0" }, "require-dev": { "nunomaduro/larastan": "^2.4", diff --git a/src/Html/Builder.php b/src/Html/Builder.php index f63dca7..6ab72f6 100644 --- a/src/Html/Builder.php +++ b/src/Html/Builder.php @@ -2,7 +2,7 @@ namespace Yajra\DataTables\Html; -use Collective\Html\HtmlBuilder; +use Yajra\DataTables\Html\HtmlBuilder; use Illuminate\Contracts\Config\Repository; use Illuminate\Contracts\View\Factory; use Illuminate\Support\Collection; diff --git a/src/Html/HtmlBuilder.php b/src/Html/HtmlBuilder.php new file mode 100644 index 0000000..043d6ad --- /dev/null +++ b/src/Html/HtmlBuilder.php @@ -0,0 +1,32 @@ + $value) { + $element = $this->attributeElement($key, $value); + if (! is_null($element)) { + $html[] = $element; + } + } + + return count($html) > 0 ? ' '.implode(' ', $html) : ''; + } + + private function attributeElement(int|string $key, mixed $value): ?string + { + if (is_numeric($key)) { + $key = $value; + } + + if (! is_null($value)) { + return $key.'="'.e($value).'"'; + } + + return null; + } +} diff --git a/src/HtmlServiceProvider.php b/src/HtmlServiceProvider.php index ad60316..cb219dc 100644 --- a/src/HtmlServiceProvider.php +++ b/src/HtmlServiceProvider.php @@ -2,7 +2,6 @@ namespace Yajra\DataTables; -use Collective\Html\HtmlServiceProvider as CollectiveHtml; use Illuminate\Support\ServiceProvider; class HtmlServiceProvider extends ServiceProvider @@ -41,8 +40,6 @@ public function register(): void { $this->mergeConfigFrom(__DIR__.'/resources/config/config.php', 'datatables-html'); - $this->app->register(CollectiveHtml::class); - $this->app->bind('datatables.html', function () { return $this->app->make(Html\Builder::class); }); From 5365bbecee94694512633173b2f1e6d84be9f440 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Tue, 7 Feb 2023 13:24:42 +0800 Subject: [PATCH 007/148] feat: copy html builder from collective --- src/Html/HtmlBuilder.php | 529 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 525 insertions(+), 4 deletions(-) diff --git a/src/Html/HtmlBuilder.php b/src/Html/HtmlBuilder.php index 043d6ad..c1f194e 100644 --- a/src/Html/HtmlBuilder.php +++ b/src/Html/HtmlBuilder.php @@ -2,13 +2,88 @@ namespace Yajra\DataTables\Html; +use Illuminate\Contracts\Routing\UrlGenerator; +use Illuminate\Contracts\View\Factory; +use Illuminate\Support\HtmlString; + class HtmlBuilder { + /** + * The URL generator instance. + * + * @var \Illuminate\Contracts\Routing\UrlGenerator + */ + protected UrlGenerator $url; + + /** + * The View Factory instance. + * + * @var \Illuminate\Contracts\View\Factory + */ + protected Factory $view; + + /** + * Create a new HTML builder instance. + * + * @param \Illuminate\Contracts\Routing\UrlGenerator $url + * @param \Illuminate\Contracts\View\Factory $view + */ + public function __construct(UrlGenerator $url, Factory $view) + { + $this->url = $url; + $this->view = $view; + } + + /** + * Convert entities to HTML characters. + * + * @param string $value + * @return string + */ + public function decode(string $value): string + { + return html_entity_decode($value, ENT_QUOTES, 'UTF-8'); + } + + /** + * Generate a link to a JavaScript file. + * + * @param string $url + * @param array $attributes + * @param bool|null $secure + * @return \Illuminate\Support\HtmlString + */ + public function script(string $url, array $attributes = [], bool $secure = null): HtmlString + { + $attributes['src'] = $this->url->asset($url, $secure); + + return $this->toHtmlString('attributes($attributes).'>'); + } + + /** + * Transform the string to an Html serializable object + * + * @param $html + * @return \Illuminate\Support\HtmlString + */ + protected function toHtmlString($html): HtmlString + { + return new HtmlString($html); + } + + /** + * Build an HTML attribute string from an array. + * + * @param array $attributes + * @return string + */ public function attributes(array $attributes): string { $html = []; + foreach ($attributes as $key => $value) { $element = $this->attributeElement($key, $value); + if (! is_null($element)) { $html[] = $element; } @@ -17,16 +92,462 @@ public function attributes(array $attributes): string return count($html) > 0 ? ' '.implode(' ', $html) : ''; } - private function attributeElement(int|string $key, mixed $value): ?string + /** + * Build a single attribute element. + * + * @param string $key + * @param mixed $value + * @return string + */ + protected function attributeElement(string $key, mixed $value): string { + // For numeric keys we will assume that the value is a boolean attribute + // where the presence of the attribute represents a true value and the + // absence represents a false value. + // This will convert HTML attributes such as "required" to a correct + // form instead of using incorrect numerics. if (is_numeric($key)) { - $key = $value; + return $value; + } + + // Treat boolean attributes as HTML properties + if (is_bool($value) && $key !== 'value') { + return $value ? $key : ''; + } + + if (is_array($value) && $key === 'class') { + return 'class="'.implode(' ', $value).'"'; } if (! is_null($value)) { - return $key.'="'.e($value).'"'; + return $key.'="'.e($value, false).'"'; + } + + return ''; + } + + /** + * Generate a link to a CSS file. + * + * @param string $url + * @param array $attributes + * @param bool|null $secure + * @return \Illuminate\Support\HtmlString + */ + public function style(string $url, array $attributes = [], bool $secure = null): HtmlString + { + $defaults = ['media' => 'all', 'type' => 'text/css', 'rel' => 'stylesheet']; + + $attributes = array_merge($defaults, $attributes); + + $attributes['href'] = $this->url->asset($url, $secure); + + return $this->toHtmlString('attributes($attributes).'>'); + } + + /** + * Generate an HTML image element. + * + * @param string $url + * @param string|null $alt + * @param array $attributes + * @param bool|null $secure + * @return \Illuminate\Support\HtmlString + */ + public function image(string $url, string $alt = null, array $attributes = [], bool $secure = null): HtmlString + { + $attributes['alt'] = $alt; + + return $this->toHtmlString('attributes($attributes).'>'); + } + + /** + * Generate a link to a Favicon file. + * + * @param string $url + * @param array $attributes + * @param bool|null $secure + * @return \Illuminate\Support\HtmlString + */ + public function favicon(string $url, array $attributes = [], bool $secure = null): HtmlString + { + $defaults = ['rel' => 'shortcut icon', 'type' => 'image/x-icon']; + + $attributes = array_merge($defaults, $attributes); + + $attributes['href'] = $this->url->asset($url, $secure); + + return $this->toHtmlString('attributes($attributes).'>'); + } + + /** + * Generate a HTTPS HTML link. + * + * @param string $url + * @param string|null $title + * @param array $attributes + * @param bool $escape + * @return \Illuminate\Support\HtmlString + */ + public function secureLink( + string $url, + string $title = null, + array $attributes = [], + bool $escape = true + ): HtmlString { + return $this->link($url, $title, $attributes, true, $escape); + } + + /** + * Generate a HTML link. + * + * @param string $url + * @param string|null $title + * @param array $attributes + * @param bool|null $secure + * @param bool $escape + * @return \Illuminate\Support\HtmlString + */ + public function link( + string $url, + string $title = null, + array $attributes = [], + bool $secure = null, + bool $escape = true + ): HtmlString { + $url = $this->url->to($url, [], $secure); + + if (is_null($title)) { + $title = $url; + } + + if ($escape) { + $title = $this->entities($title); } - return null; + return $this->toHtmlString('attributes($attributes).'>'.$title.''); + } + + /** + * Convert an HTML string to entities. + * + * @param string $value + * @return string + */ + public function entities(string $value): string + { + return htmlentities($value, ENT_QUOTES, 'UTF-8', false); + } + + /** + * Generate a HTTPS HTML link to an asset. + * + * @param string $url + * @param string|null $title + * @param array $attributes + * @param bool $escape + * @return \Illuminate\Support\HtmlString + */ + public function linkSecureAsset( + string $url, + string $title = null, + array $attributes = [], + bool $escape = true + ): HtmlString { + return $this->linkAsset($url, $title, $attributes, true, $escape); + } + + /** + * Generate a HTML link to an asset. + * + * @param string $url + * @param string|null $title + * @param array $attributes + * @param bool|null $secure + * @param bool $escape + * @return \Illuminate\Support\HtmlString + */ + public function linkAsset( + string $url, + string $title = null, + array $attributes = [], + bool $secure = null, + bool $escape = true + ): HtmlString { + $url = $this->url->asset($url, $secure); + + return $this->link($url, $title ?: $url, $attributes, $secure, $escape); + } + + /** + * Generate a HTML link to a named route. + * + * @param string $name + * @param string|null $title + * @param array $parameters + * @param array $attributes + * @param bool|null $secure + * @param bool $escape + * @return \Illuminate\Support\HtmlString + */ + public function linkRoute( + string $name, + string $title = null, + array $parameters = [], + array $attributes = [], + bool $secure = null, + bool $escape = true + ): HtmlString { + return $this->link($this->url->route($name, $parameters), $title, $attributes, $secure, $escape); + } + + /** + * Generate a HTML link to a controller action. + * + * @param string $action + * @param string|null $title + * @param array $parameters + * @param array $attributes + * @param bool|null $secure + * @param bool $escape + * @return \Illuminate\Support\HtmlString + */ + public function linkAction( + string $action, + string $title = null, + array $parameters = [], + array $attributes = [], + bool $secure = null, + bool $escape = true + ): HtmlString { + return $this->link($this->url->action($action, $parameters), $title, $attributes, $secure, $escape); + } + + /** + * Generate a HTML link to an email address. + * + * @param string $email + * @param string|null $title + * @param array $attributes + * @param bool $escape + * @return \Illuminate\Support\HtmlString + */ + public function mailto(string $email, string $title = null, array $attributes = [], bool $escape = true): HtmlString + { + $email = $this->email($email); + + $title = $title ?: $email; + + if ($escape) { + $title = $this->entities($title); + } + + $email = $this->obfuscate('mailto:').$email; + + return $this->toHtmlString('attributes($attributes).'>'.$title.''); + } + + /** + * Obfuscate an e-mail address to prevent spam-bots from sniffing it. + * + * @param string $email + * @return string + */ + public function email(string $email): string + { + return str_replace('@', '@', $this->obfuscate($email)); + } + + /** + * Obfuscate a string to prevent spam-bots from sniffing it. + * + * @param string $value + * @return string + */ + public function obfuscate(string $value): string + { + $safe = ''; + + foreach (str_split($value) as $letter) { + if (ord($letter) > 128) { + return $letter; + } + + // To properly obfuscate the value, we will randomly convert each letter to + // its entity or hexadecimal representation, keeping a bot from sniffing + // the randomly obfuscated letters out of the string on the responses. + switch (rand(1, 3)) { + case 1: + $safe .= '&#'.ord($letter).';'; + break; + + case 2: + $safe .= '&#x'.dechex(ord($letter)).';'; + break; + + case 3: + $safe .= $letter; + } + } + + return $safe; + } + + /** + * Generates non-breaking space entities based on number supplied. + * + * @param int $num + * @return string + */ + public function nbsp(int $num = 1): string + { + return str_repeat(' ', $num); + } + + /** + * Generate an ordered list of items. + * + * @param array $list + * @param array $attributes + * @return \Illuminate\Support\HtmlString|string + */ + public function ol(array $list, array $attributes = []): HtmlString|string + { + return $this->listing('ol', $list, $attributes); + } + + /** + * Create a listing HTML element. + * + * @param string $type + * @param array $list + * @param array $attributes + * @return \Illuminate\Support\HtmlString|string + */ + protected function listing(string $type, array $list, array $attributes = []): HtmlString|string + { + $html = ''; + + if (count($list) === 0) { + return $html; + } + + // Essentially we will just spin through the list and build the list of the HTML + // elements from the array. We will also handled nested lists in case that is + // present in the array. Then we will build out the final listing elements. + foreach ($list as $key => $value) { + $html .= $this->listingElement($key, $type, $value); + } + + $attributes = $this->attributes($attributes); + + return $this->toHtmlString("<{$type}{$attributes}>{$html}"); + } + + /** + * Create the HTML for a listing element. + * + * @param mixed $key + * @param string $type + * @param mixed $value + * @return \Illuminate\Support\HtmlString|string + */ + protected function listingElement(mixed $key, string $type, mixed $value): HtmlString|string + { + if (is_array($value)) { + return $this->nestedListing($key, $type, $value); + } else { + return '
  • '.e($value, false).'
  • '; + } + } + + /** + * Create the HTML for a nested listing attribute. + * + * @param mixed $key + * @param string $type + * @param mixed $value + * @return \Illuminate\Support\HtmlString|string + */ + protected function nestedListing(mixed $key, string $type, mixed $value): HtmlString|string + { + if (is_int($key)) { + return $this->listing($type, $value); + } else { + return '
  • '.$key.$this->listing($type, $value).'
  • '; + } + } + + /** + * Generate an un-ordered list of items. + * + * @param array $list + * @param array $attributes + * @return \Illuminate\Support\HtmlString|string + */ + public function ul(array $list, array $attributes = []): HtmlString|string + { + return $this->listing('ul', $list, $attributes); + } + + /** + * Generate a description list of items. + * + * @param array $list + * @param array $attributes + * @return \Illuminate\Support\HtmlString + */ + public function dl(array $list, array $attributes = []): HtmlString + { + $attributes = $this->attributes($attributes); + + $html = ""; + + foreach ($list as $key => $value) { + $value = (array) $value; + + $html .= "
    $key
    "; + + foreach ($value as $v_key => $v_value) { + $html .= "
    $v_value
    "; + } + } + + $html .= ''; + + return $this->toHtmlString($html); + } + + /** + * Generate a meta tag. + * + * @param string $name + * @param string $content + * @param array $attributes + * @return \Illuminate\Support\HtmlString + */ + public function meta(string $name, string $content, array $attributes = []): HtmlString + { + $defaults = compact('name', 'content'); + + $attributes = array_merge($defaults, $attributes); + + return $this->toHtmlString('attributes($attributes).'>'); + } + + /** + * Generate an html tag. + * + * @param string $tag + * @param mixed $content + * @param array $attributes + * @return \Illuminate\Support\HtmlString + */ + public function tag(string $tag, mixed $content, array $attributes = []): HtmlString + { + $content = is_array($content) ? implode('', $content) : $content; + + return $this->toHtmlString('<'.$tag.$this->attributes($attributes).'>'.$this->toHtmlString($content).''); } } From bc18af06ddfc42a352bed036ab8ef23094333e3c Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Tue, 7 Feb 2023 13:31:40 +0800 Subject: [PATCH 008/148] fix: php stan issues --- src/Html/HtmlBuilder.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Html/HtmlBuilder.php b/src/Html/HtmlBuilder.php index c1f194e..b49cc4c 100644 --- a/src/Html/HtmlBuilder.php +++ b/src/Html/HtmlBuilder.php @@ -63,10 +63,10 @@ public function script(string $url, array $attributes = [], bool $secure = null) /** * Transform the string to an Html serializable object * - * @param $html + * @param string $html * @return \Illuminate\Support\HtmlString */ - protected function toHtmlString($html): HtmlString + protected function toHtmlString(string $html): HtmlString { return new HtmlString($html); } @@ -97,9 +97,9 @@ public function attributes(array $attributes): string * * @param string $key * @param mixed $value - * @return string + * @return mixed */ - protected function attributeElement(string $key, mixed $value): string + protected function attributeElement(string $key, mixed $value): mixed { // For numeric keys we will assume that the value is a boolean attribute // where the presence of the attribute represents a true value and the @@ -120,10 +120,10 @@ protected function attributeElement(string $key, mixed $value): string } if (! is_null($value)) { - return $key.'="'.e($value, false).'"'; + return $key.'="'.e(strval($value), false).'"'; } - return ''; + return null; } /** @@ -458,7 +458,7 @@ protected function listingElement(mixed $key, string $type, mixed $value): HtmlS if (is_array($value)) { return $this->nestedListing($key, $type, $value); } else { - return '
  • '.e($value, false).'
  • '; + return '
  • '.e(strval($value), false).'
  • '; } } @@ -467,10 +467,10 @@ protected function listingElement(mixed $key, string $type, mixed $value): HtmlS * * @param mixed $key * @param string $type - * @param mixed $value + * @param array $value * @return \Illuminate\Support\HtmlString|string */ - protected function nestedListing(mixed $key, string $type, mixed $value): HtmlString|string + protected function nestedListing(mixed $key, string $type, array $value): HtmlString|string { if (is_int($key)) { return $this->listing($type, $value); @@ -548,6 +548,6 @@ public function tag(string $tag, mixed $content, array $attributes = []): HtmlSt { $content = is_array($content) ? implode('', $content) : $content; - return $this->toHtmlString('<'.$tag.$this->attributes($attributes).'>'.$this->toHtmlString($content).''); + return $this->toHtmlString('<'.$tag.$this->attributes($attributes).'>'.$this->toHtmlString(strval($content)).''); } } From 493bc1d2897dcfc1a6c6e28d75aa194244464733 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Tue, 7 Feb 2023 13:35:13 +0800 Subject: [PATCH 009/148] fix: sonarcloud security issue Make sure that using this pseudorandom number generator is safe here. --- src/Html/HtmlBuilder.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Html/HtmlBuilder.php b/src/Html/HtmlBuilder.php index b49cc4c..f9170c3 100644 --- a/src/Html/HtmlBuilder.php +++ b/src/Html/HtmlBuilder.php @@ -364,6 +364,7 @@ public function email(string $email): string * * @param string $value * @return string + * @throws \Exception */ public function obfuscate(string $value): string { @@ -377,7 +378,7 @@ public function obfuscate(string $value): string // To properly obfuscate the value, we will randomly convert each letter to // its entity or hexadecimal representation, keeping a bot from sniffing // the randomly obfuscated letters out of the string on the responses. - switch (rand(1, 3)) { + switch (random_int(1, 3)) { case 1: $safe .= '&#'.ord($letter).';'; break; From 8d090013403da96e4d03ec76a1f21ffe32be76ea Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Tue, 7 Feb 2023 13:43:11 +0800 Subject: [PATCH 010/148] build: bump testbench 8 --- .gitignore | 1 + composer.json | 2 +- phpunit.xml | 11 +++++------ 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index df0e1ea..7e74d0e 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ /coverage composer.phar composer.lock +/.phpunit.cache/ diff --git a/composer.json b/composer.json index 2b9d3e5..0afc122 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ }, "require-dev": { "nunomaduro/larastan": "^2.4", - "orchestra/testbench": "^7.21" + "orchestra/testbench": "^8" }, "autoload": { "psr-4": { diff --git a/phpunit.xml b/phpunit.xml index 422eeac..793e30a 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,14 +1,13 @@ - + xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd" + cacheDirectory=".phpunit.cache" + backupStaticProperties="false"> ./tests/ From edf2592b4c0d8a9886fd3632d8fd9543990af460 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Tue, 7 Feb 2023 13:48:27 +0800 Subject: [PATCH 011/148] Revert "build: bump testbench 8" This reverts commit 8d090013403da96e4d03ec76a1f21ffe32be76ea. --- .gitignore | 1 - composer.json | 2 +- phpunit.xml | 11 ++++++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 7e74d0e..df0e1ea 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,3 @@ /coverage composer.phar composer.lock -/.phpunit.cache/ diff --git a/composer.json b/composer.json index 0afc122..2b9d3e5 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ }, "require-dev": { "nunomaduro/larastan": "^2.4", - "orchestra/testbench": "^8" + "orchestra/testbench": "^7.21" }, "autoload": { "psr-4": { diff --git a/phpunit.xml b/phpunit.xml index 793e30a..422eeac 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,13 +1,14 @@ - +> ./tests/ From 69d62579f20c02999bf4df22718de873a278bbae Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Tue, 7 Feb 2023 13:52:55 +0800 Subject: [PATCH 012/148] chore: release v10.1.0 :rocket: --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b529ece..50f8509 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,11 @@ ## CHANGELOG +### v10.1.0 - 2023-02-07 + +- Drop Collective\Html dependency #183 +- Copy Collective HtmlBuilder class and implemented php-stan + ### v10.0.0 - 2023-02-07 - Add Laravel 10 specific support From dc8d8071797368742c7092a4bcf7bbb68a017174 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Mon, 20 Feb 2023 15:46:38 +0800 Subject: [PATCH 013/148] chore: release v10.2.0 :rocket: --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 50f8509..8242682 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ ## CHANGELOG +### v10.2.0 - 2023-02-20 + +- feat: allow callable exportFormat parameter #167 + ### v10.1.0 - 2023-02-07 - Drop Collective\Html dependency #183 From 36f8d45f9bcc83b48f376b6d08c38fd8bb624264 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Mon, 20 Feb 2023 20:32:17 +0800 Subject: [PATCH 014/148] feat: add ability to use vitejs by default --- src/Html/Builder.php | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/Html/Builder.php b/src/Html/Builder.php index 6ab72f6..d95f795 100644 --- a/src/Html/Builder.php +++ b/src/Html/Builder.php @@ -2,7 +2,6 @@ namespace Yajra\DataTables\Html; -use Yajra\DataTables\Html\HtmlBuilder; use Illuminate\Contracts\Config\Repository; use Illuminate\Contracts\View\Factory; use Illuminate\Support\Collection; @@ -30,26 +29,27 @@ class Builder const SELECT_ITEMS_COLUMN = 'column'; const SELECT_ITEMS_CELL = 'cell'; + /** + * The default type to use for the DataTables javascript. + */ + protected static string $jsType = 'text/javascript'; + /** * @var Collection */ public Collection $collection; - /** * @var array */ protected array $tableAttributes = []; - /** * @var string */ protected string $template = ''; - /** * @var array */ protected array $attributes = []; - /** * @var string|array */ @@ -73,6 +73,14 @@ public function __construct(public Repository $config, public Factory $view, pub ]; } + /** + * Set the default type to module or the DataTables javascript. + */ + public static function useVite(): void + { + static::$jsType = 'module'; + } + /** * Generate DataTable javascript. * @@ -83,7 +91,9 @@ public function __construct(public Repository $config, public Factory $view, pub public function scripts(string $script = null, array $attributes = ['type' => 'text/javascript']): HtmlString { $script = $script ?: $this->generateScripts(); - $attributes = $this->html->attributes($attributes); + $attributes = $this->html->attributes( + array_merge($attributes, ['type' => static::$jsType]) + ); return new HtmlString("$script"); } From daf21cade8ec2e67d7c47d90f1104aa8c25ace96 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Mon, 20 Feb 2023 20:37:37 +0800 Subject: [PATCH 015/148] tests: useVite --- tests/BuilderTest.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/BuilderTest.php b/tests/BuilderTest.php index 685a1bc..2c6e559 100644 --- a/tests/BuilderTest.php +++ b/tests/BuilderTest.php @@ -11,6 +11,14 @@ class BuilderTest extends TestCase { + /** @test */ + public function it_can_use_vitejs_module_script() + { + Builder::useVite(); + + $this->assertStringContainsString('type="module"', $this->getHtmlBuilder()->scripts()->toHtml()); + } + /** @test */ public function it_can_resolved_builder_class() { From f84728008b2dcb5a6c16cf251198bc345bd542ff Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Mon, 20 Feb 2023 20:56:19 +0800 Subject: [PATCH 016/148] feat: add useWebpack --- src/Html/Builder.php | 10 +++++++++- tests/BuilderTest.php | 2 ++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Html/Builder.php b/src/Html/Builder.php index d95f795..98b5599 100644 --- a/src/Html/Builder.php +++ b/src/Html/Builder.php @@ -74,13 +74,21 @@ public function __construct(public Repository $config, public Factory $view, pub } /** - * Set the default type to module or the DataTables javascript. + * Set the default type to module for the DataTables javascript. */ public static function useVite(): void { static::$jsType = 'module'; } + /** + * Set the default type to text/javascript for the DataTables javascript. + */ + public static function useWebpack(): void + { + static::$jsType = 'text/javascript'; + } + /** * Generate DataTable javascript. * diff --git a/tests/BuilderTest.php b/tests/BuilderTest.php index 2c6e559..c2196b8 100644 --- a/tests/BuilderTest.php +++ b/tests/BuilderTest.php @@ -17,6 +17,8 @@ public function it_can_use_vitejs_module_script() Builder::useVite(); $this->assertStringContainsString('type="module"', $this->getHtmlBuilder()->scripts()->toHtml()); + + Builder::useWebpack(); } /** @test */ From 3db00e154eda1d55ce52ac59352ddce7eab70fe1 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Mon, 20 Feb 2023 21:00:07 +0800 Subject: [PATCH 017/148] fix: new line --- src/Html/Builder.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Html/Builder.php b/src/Html/Builder.php index 98b5599..0eb8e77 100644 --- a/src/Html/Builder.php +++ b/src/Html/Builder.php @@ -38,18 +38,22 @@ class Builder * @var Collection */ public Collection $collection; + /** * @var array */ protected array $tableAttributes = []; + /** * @var string */ protected string $template = ''; + /** * @var array */ protected array $attributes = []; + /** * @var string|array */ From c38e8cff3e79bd8f47accca0b9725311f7ff148b Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Mon, 20 Feb 2023 21:05:45 +0800 Subject: [PATCH 018/148] docs: usage with vitejs --- README.md | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 968c17b..4384075 100644 --- a/README.md +++ b/README.md @@ -31,9 +31,29 @@ This package is a plugin of [Laravel DataTables](https://github.com/yajra/larave `composer require yajra/laravel-datatables-html:^10` -#### Service Provider (Optional on Laravel 5.5+) - -`Yajra\DataTables\HtmlServiceProvider::class` +#### Setup scripts with ViteJS + +Set the default javascript type to `module` by setting `Builder::useVite()` in the `AppServiceProvider`. + +```php +namespace App\Providers; + +use Illuminate\Pagination\Paginator; +use Illuminate\Support\ServiceProvider; +use Yajra\DataTables\Html\Builder; + +class AppServiceProvider extends ServiceProvider +{ + /** + * Bootstrap any application services. + */ + public function boot(): void + { + Paginator::useBootstrapFive(); + Builder::useVite(); + } +} +``` #### Publish Assets (Optional) From 1bfeb8d9ab151732321c24dce19b00c5584ce18a Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Mon, 20 Feb 2023 21:05:59 +0800 Subject: [PATCH 019/148] chore: release v10.3.0 :rocket: --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8242682..c9e28c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ ## CHANGELOG +### v10.3.0 - 2023-02-20 + +- feat: add builder ability to use viteJs by default #184 + ### v10.2.0 - 2023-02-20 - feat: allow callable exportFormat parameter #167 From 7bac3b197c5510728d4ba0a9d16f484ce4488710 Mon Sep 17 00:00:00 2001 From: Furkan Akkoc Date: Mon, 20 Feb 2023 14:26:21 +0100 Subject: [PATCH 020/148] fix: too long file name check for column render --- src/Html/Column.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Html/Column.php b/src/Html/Column.php index a574f54..e4818ce 100644 --- a/src/Html/Column.php +++ b/src/Html/Column.php @@ -512,7 +512,7 @@ public function parseRender(mixed $value): ?string return $value($parameters); } elseif ($this->isBuiltInRenderFunction($value)) { return $value; - } elseif ($view->exists($value)) { + } elseif (strlen($value) < 256 && $view->exists($value)) { return $view->make($value)->with($parameters)->render(); } From 51a6dbff86a0890578ea5b6828233dc0d6d37041 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Mon, 20 Feb 2023 23:23:23 +0800 Subject: [PATCH 021/148] chore: release v10.3.1 :rocket: --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c9e28c5..28c28e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ ## CHANGELOG +### v10.3.1 - 2023-02-20 + +- fix: too long file name check for column render #185 + ### v10.3.0 - 2023-02-20 - feat: add builder ability to use viteJs by default #184 From 2cc4ca2094dc1648dd0b26f2c9e88be688334b54 Mon Sep 17 00:00:00 2001 From: Huzair Saputra Date: Fri, 24 Feb 2023 17:08:38 +0700 Subject: [PATCH 022/148] Update HasAjax.php Change `url()->full()` method to `url()->current()` to solve Mixed Content when using forceScheme('https') function in Laravel --- src/Html/Options/HasAjax.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Html/Options/HasAjax.php b/src/Html/Options/HasAjax.php index 8252663..4a8282d 100644 --- a/src/Html/Options/HasAjax.php +++ b/src/Html/Options/HasAjax.php @@ -142,7 +142,7 @@ public function minifiedAjax( $this->ajax = []; $appendData = $this->makeDataScript($data); - $this->ajax['url'] = empty($url) ? url()->full() : $url; + $this->ajax['url'] = empty($url) ? url()->current() : $url; $this->ajax['type'] = 'GET'; if (! isset($this->attributes['serverSide']) || $this->attributes['serverSide']) { $this->ajax['data'] = 'function(data) { From 38a6379d9f03de63029d8addb4a8c48181e803ce Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Thu, 2 Mar 2023 12:22:37 +0800 Subject: [PATCH 023/148] feat: add datetime specific options --- src/Html/Editor/Fields/DateTime.php | 55 +++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/src/Html/Editor/Fields/DateTime.php b/src/Html/Editor/Fields/DateTime.php index 680e80f..92cfa82 100644 --- a/src/Html/Editor/Fields/DateTime.php +++ b/src/Html/Editor/Fields/DateTime.php @@ -109,4 +109,59 @@ public function minutesAvailable(array $minutes): static { return $this->opts(['minutesAvailable' => $minutes]); } + + /** + * The format of the date string loaded from the server for the field's + * value and also for sending to the server on form submission. + * The formatting options are defined by Moment.js. + * + * @param string $format + * @return $this + * @see https://editor.datatables.net/reference/field/datetime#Options + * @see https://momentjs.com/docs/#/displaying/format/ + */ + public function wireFormat(string $format = 'YYYY-MM-DDTHH:mm:ss.000000Z'): static + { + $this->attributes['wireFormat'] = $format; + + return $this; + } + + /** + * Allow (default), or disallow, the end user to type into the date / time input element. + * If disallowed, they must use the calendar picker to enter data. This can be useful + * if you are using a more complex date format and wish to disallow the user from + * potentially making typing mistakes, although note that it does also disallow + * pasting of data. + * + * @param bool $state + * @return $this + * @see https://editor.datatables.net/reference/field/datetime#Options + * @see https://momentjs.com/docs/#/displaying/format/ + */ + public function keyInput(bool $state = true): static + { + $this->attributes['keyInput'] = $state; + + return $this; + } + + /** + * The format of the date string that will be shown to the end user in the input element. + * The formatting options are defined by Moment.js. If a format is used that is not + * ISO8061 (i.e. YYYY-MM-DD) and Moment.js has not been included, Editor will + * throw an error stating that Moment.js must be included for custom + * formatting to be used. + * + * @param string $format + * @return $this + * @see https://editor.datatables.net/reference/field/datetime#Options + * @see https://momentjs.com/docs/#/displaying/format/ + */ + public function displayFormat(string $format = 'YYYY-MM-DD hh:mm a'): static + { + $this->attributes['displayFormat'] = $format; + + return $this; + } } From 6e8a831529eb8bff9cdad860f26e280fca6ec29e Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Thu, 2 Mar 2023 12:24:56 +0800 Subject: [PATCH 024/148] fix: remove momentjs link --- src/Html/Editor/Fields/DateTime.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Html/Editor/Fields/DateTime.php b/src/Html/Editor/Fields/DateTime.php index 92cfa82..990be77 100644 --- a/src/Html/Editor/Fields/DateTime.php +++ b/src/Html/Editor/Fields/DateTime.php @@ -137,7 +137,6 @@ public function wireFormat(string $format = 'YYYY-MM-DDTHH:mm:ss.000000Z'): stat * @param bool $state * @return $this * @see https://editor.datatables.net/reference/field/datetime#Options - * @see https://momentjs.com/docs/#/displaying/format/ */ public function keyInput(bool $state = true): static { From b64cbf4b6d82939800cc3db39b1cbebd208da7be Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Thu, 2 Mar 2023 12:35:53 +0800 Subject: [PATCH 025/148] test: add new datetime options test --- tests/FieldTest.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/FieldTest.php b/tests/FieldTest.php index 15ff477..6c31822 100644 --- a/tests/FieldTest.php +++ b/tests/FieldTest.php @@ -107,6 +107,15 @@ public function it_can_create_datetime_field() $field->minutesAvailable([1, 2]); $this->assertEquals([1, 2], $field->opts['minutesAvailable']); + + $field->keyInput(false); + $this->assertEquals(false, $field->getAttributes()['keyInput']); + + $field->displayFormat('LLL'); + $this->assertEquals('LLL', $field->getAttributes()['displayFormat']); + + $field->wireFormat('LLL'); + $this->assertEquals('LLL', $field->getAttributes()['wireFormat']); } /** @test */ From 25fe850b2d72d794f5a46b92a4f8eb53e7871fb3 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Thu, 2 Mar 2023 12:41:49 +0800 Subject: [PATCH 026/148] chore: release v10.4.0 :rocket: --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 28c28e9..052ef4d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,13 @@ ## CHANGELOG +### v10.4.0 - 2023-03-02 + +- feat: add datetime field options #187 + - wireFormat + - keyInput + - displayFormat + ### v10.3.1 - 2023-02-20 - fix: too long file name check for column render #185 From d13c80cb3caa951dd95071bf760d7492af8a728b Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Thu, 2 Mar 2023 13:15:45 +0800 Subject: [PATCH 027/148] feat: hide/show fields based on editor action --- src/Html/Editor/Editor.php | 86 ++++++++++++++++++++++++++++++++------ 1 file changed, 73 insertions(+), 13 deletions(-) diff --git a/src/Html/Editor/Editor.php b/src/Html/Editor/Editor.php index 396bc55..fad4fd8 100644 --- a/src/Html/Editor/Editor.php +++ b/src/Html/Editor/Editor.php @@ -24,14 +24,14 @@ class Editor extends Fluent use HasEvents; use HasAuthorizations; - public array $events = []; - const DISPLAY_LIGHTBOX = 'lightbox'; const DISPLAY_ENVELOPE = 'envelope'; const DISPLAY_BOOTSTRAP = 'bootstrap'; const DISPLAY_FOUNDATION = 'foundation'; const DISPLAY_JQUERYUI = 'jqueryui'; + public array $events = []; + /** * Editor constructor. * @@ -156,30 +156,30 @@ public function fields(array $fields): static } /** - * Set Editor's formOptions. + * Set Editor's bubble formOptions. * * @param array $formOptions * @return $this - * @see https://editor.datatables.net/reference/option/formOptions - * @see https://editor.datatables.net/reference/type/form-options + * @see https://editor.datatables.net/reference/option/formOptions.bubble */ - public function formOptions(array $formOptions): static + public function formOptionsBubble(array $formOptions): static { - $this->attributes['formOptions'] = $formOptions; - - return $this; + return $this->formOptions(['bubble' => Helper::castToArray($formOptions)]); } /** - * Set Editor's bubble formOptions. + * Set Editor's formOptions. * * @param array $formOptions * @return $this - * @see https://editor.datatables.net/reference/option/formOptions.bubble + * @see https://editor.datatables.net/reference/option/formOptions + * @see https://editor.datatables.net/reference/type/form-options */ - public function formOptionsBubble(array $formOptions): static + public function formOptions(array $formOptions): static { - return $this->formOptions(['bubble' => Helper::castToArray($formOptions)]); + $this->attributes['formOptions'] = $formOptions; + + return $this; } /** @@ -272,4 +272,64 @@ public function toJson($options = 0): string return Helper::toJsonScript($parameters, $options); } + + /** + * Hide fields on create action. + * + * @param array $fields + * @return $this + */ + public function hiddenOnCreate(array $fields): static + { + return $this->hiddenOn('create', $fields); + } + + /** + * Hide fields on specific action. + * + * @param string $action + * @param array $fields + * @return $this + */ + public function hiddenOn(string $action, array $fields): static + { + $script = 'function(e, mode, action) {'.PHP_EOL; + $script .= "if (action === '{$action}') {".PHP_EOL; + foreach ($fields as $field) { + $script .= "this.hide('{$field}');".PHP_EOL; + } + $script .= '} else {'.PHP_EOL; + foreach ($fields as $field) { + $script .= "this.show('{$field}');".PHP_EOL; + } + $script .= '}'.PHP_EOL; + $script .= 'return true;'.PHP_EOL; + $script .= '}'.PHP_EOL; + + $this->onPreOpen($script); + + return $this; + } + + /** + * Hide fields on edit action. + * + * @param array $fields + * @return $this + */ + public function hiddenOnEdit(array $fields): static + { + return $this->hiddenOn('edit', $fields); + } + + /** + * Hide fields on remove action. + * + * @param array $fields + * @return $this + */ + public function hiddenOnRemove(array $fields): static + { + return $this->hiddenOn('remove', $fields); + } } From 5325c79a42e7b60f1927741301735d2b068c4aea Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Thu, 2 Mar 2023 13:27:05 +0800 Subject: [PATCH 028/148] chore: no fields on remove action by default --- src/Html/Editor/Editor.php | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/Html/Editor/Editor.php b/src/Html/Editor/Editor.php index fad4fd8..890d271 100644 --- a/src/Html/Editor/Editor.php +++ b/src/Html/Editor/Editor.php @@ -321,15 +321,4 @@ public function hiddenOnEdit(array $fields): static { return $this->hiddenOn('edit', $fields); } - - /** - * Hide fields on remove action. - * - * @param array $fields - * @return $this - */ - public function hiddenOnRemove(array $fields): static - { - return $this->hiddenOn('remove', $fields); - } } From ffe27848171b0c494d4017aa778dee46be68cc26 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Thu, 2 Mar 2023 13:43:47 +0800 Subject: [PATCH 029/148] test: hiddenOn event tests --- tests/EditorTest.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/EditorTest.php b/tests/EditorTest.php index e7e2ce9..b17e296 100644 --- a/tests/EditorTest.php +++ b/tests/EditorTest.php @@ -59,6 +59,25 @@ public function it_can_have_events() $this->assertEquals($event, $editor->events[0]); } + /** @test */ + public function it_can_show_hide_fields() + { + $editor = $this->getEditor(); + + $editor->hiddenOnCreate(['name']); + $editor->hiddenOnEdit(['email']); + + $this->assertCount(2, $editor->events); + + $this->assertEquals('preOpen', $editor->events[0]['event']); + $this->assertStringContainsString("action === 'create'", $editor->events[0]['script']); + $this->assertStringContainsString("this.hide('name')", $editor->events[0]['script']); + + $this->assertEquals('preOpen', $editor->events[1]['event']); + $this->assertStringContainsString("action === 'edit'", $editor->events[1]['script']); + $this->assertStringContainsString("this.hide('email')", $editor->events[1]['script']); + } + /** @test */ public function it_has_authorizations() { From 039027371023e68cdddb4bc6faac3faae34fa7c4 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Thu, 2 Mar 2023 14:51:50 +0800 Subject: [PATCH 030/148] chore: remove new line --- src/Html/Editor/Editor.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Html/Editor/Editor.php b/src/Html/Editor/Editor.php index 890d271..ee791f4 100644 --- a/src/Html/Editor/Editor.php +++ b/src/Html/Editor/Editor.php @@ -293,18 +293,18 @@ public function hiddenOnCreate(array $fields): static */ public function hiddenOn(string $action, array $fields): static { - $script = 'function(e, mode, action) {'.PHP_EOL; - $script .= "if (action === '{$action}') {".PHP_EOL; + $script = 'function(e, mode, action) {'; + $script .= "if (action === '{$action}') {"; foreach ($fields as $field) { - $script .= "this.hide('{$field}');".PHP_EOL; + $script .= "this.hide('{$field}');"; } - $script .= '} else {'.PHP_EOL; + $script .= '} else {'; foreach ($fields as $field) { - $script .= "this.show('{$field}');".PHP_EOL; + $script .= "this.show('{$field}');"; } - $script .= '}'.PHP_EOL; - $script .= 'return true;'.PHP_EOL; - $script .= '}'.PHP_EOL; + $script .= '}'; + $script .= 'return true;'; + $script .= '}'; $this->onPreOpen($script); From ff2819f10dd1d21d9a9ed25e964023cf5980f6f2 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Thu, 2 Mar 2023 14:58:44 +0800 Subject: [PATCH 031/148] chore: remove curly brace --- src/Html/Editor/Editor.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Html/Editor/Editor.php b/src/Html/Editor/Editor.php index ee791f4..29816ee 100644 --- a/src/Html/Editor/Editor.php +++ b/src/Html/Editor/Editor.php @@ -294,13 +294,13 @@ public function hiddenOnCreate(array $fields): static public function hiddenOn(string $action, array $fields): static { $script = 'function(e, mode, action) {'; - $script .= "if (action === '{$action}') {"; + $script .= "if (action === '$action') {"; foreach ($fields as $field) { - $script .= "this.hide('{$field}');"; + $script .= "this.hide('$field');"; } $script .= '} else {'; foreach ($fields as $field) { - $script .= "this.show('{$field}');"; + $script .= "this.show('$field');"; } $script .= '}'; $script .= 'return true;'; From 47d1848e84dac338d427abcabba63afe60d45a10 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Thu, 2 Mar 2023 15:06:31 +0800 Subject: [PATCH 032/148] chore: release v10.5.0 :rocket: --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 052ef4d..5056975 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,13 @@ ## CHANGELOG +### v10.5.0 - 2023-03-02 + +- feat: hide/show fields based on editor action #188 + - hiddenOnCreate + - hiddenOnEdit + - hiddenOn + ### v10.4.0 - 2023-03-02 - feat: add datetime field options #187 From a2c334f5bfbb5c22ad8bfe331bccab9c64fc8c6c Mon Sep 17 00:00:00 2001 From: Antonio Date: Tue, 28 Mar 2023 00:41:14 +0200 Subject: [PATCH 033/148] The attributes parameter is never used. I was following the Quick Starter and it always gave me the jquery(ReferenceError: $ is not defined) error. when we used this code( {{ $dataTable->scripts(attributes: ['type' => 'module']) }} ) , the type was always type="text/javascript" not 'module' as expected. --- src/Html/Builder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Html/Builder.php b/src/Html/Builder.php index 0eb8e77..3041350 100644 --- a/src/Html/Builder.php +++ b/src/Html/Builder.php @@ -104,7 +104,7 @@ public function scripts(string $script = null, array $attributes = ['type' => 't { $script = $script ?: $this->generateScripts(); $attributes = $this->html->attributes( - array_merge($attributes, ['type' => static::$jsType]) + array_merge($attributes, ['type' => $attributes['type'] ?? static::$jsType]) ); return new HtmlString("$script"); From 5f3d5265913d18ffcb536523b5db08ead82c3ab6 Mon Sep 17 00:00:00 2001 From: Antonio Date: Tue, 28 Mar 2023 09:15:40 +0200 Subject: [PATCH 034/148] test: fix script html --- src/Html/Builder.php | 2 +- tests/BuilderTest.php | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/Html/Builder.php b/src/Html/Builder.php index 3041350..d624138 100644 --- a/src/Html/Builder.php +++ b/src/Html/Builder.php @@ -100,7 +100,7 @@ public static function useWebpack(): void * @param array $attributes * @return \Illuminate\Support\HtmlString */ - public function scripts(string $script = null, array $attributes = ['type' => 'text/javascript']): HtmlString + public function scripts(string $script = null, array $attributes = []): HtmlString { $script = $script ?: $this->generateScripts(); $attributes = $this->html->attributes( diff --git a/tests/BuilderTest.php b/tests/BuilderTest.php index c2196b8..ae255c4 100644 --- a/tests/BuilderTest.php +++ b/tests/BuilderTest.php @@ -11,6 +11,31 @@ class BuilderTest extends TestCase { + /** @test */ + public function it_can_get_script_default_type_attribute() + { + $html = $this->getHtmlBuilder()->scripts()->toHtml(); + + $this->assertStringContainsString('type="text/javascript"', $html); + } + + /** @test */ + public function it_can_set_script_type_attribute() + { + $html = $this->getHtmlBuilder()->scripts(attributes: ['type' => 'module'])->toHtml(); + + $this->assertStringContainsString('type="module"', $html); + } + + /** @test */ + public function it_can_set_multiple_script_attributes() + { + $html = $this->getHtmlBuilder()->scripts(attributes: ['prop1' => 'val1', 'prop2' => 'val2'])->toHtml(); + + $this->assertStringContainsString('prop1="val1"', $html); + $this->assertStringContainsString('prop2="val2"', $html); + } + /** @test */ public function it_can_use_vitejs_module_script() { From c8bedb6f63a11655b647090cdb909d469eeaf52e Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Tue, 28 Mar 2023 15:56:29 +0800 Subject: [PATCH 035/148] chore: release v10.5.1 :rocket: --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5056975..c3baac3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ ## CHANGELOG +### v10.5.1 - 2023-03-28 + +- fix: scripts attributes not working #189 + ### v10.5.0 - 2023-03-02 - feat: hide/show fields based on editor action #188 From 32df111459f60b8cad574527559c1b723279a474 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Fri, 31 Mar 2023 09:43:54 +0800 Subject: [PATCH 036/148] fix: compatibility with FormOptions class --- src/Html/Editor/Editor.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Html/Editor/Editor.php b/src/Html/Editor/Editor.php index 29816ee..a6be8bf 100644 --- a/src/Html/Editor/Editor.php +++ b/src/Html/Editor/Editor.php @@ -158,11 +158,11 @@ public function fields(array $fields): static /** * Set Editor's bubble formOptions. * - * @param array $formOptions + * @param array|FormOptions $formOptions * @return $this * @see https://editor.datatables.net/reference/option/formOptions.bubble */ - public function formOptionsBubble(array $formOptions): static + public function formOptionsBubble(array|FormOptions $formOptions): static { return $this->formOptions(['bubble' => Helper::castToArray($formOptions)]); } @@ -170,7 +170,7 @@ public function formOptionsBubble(array $formOptions): static /** * Set Editor's formOptions. * - * @param array $formOptions + * @param array $formOptions * @return $this * @see https://editor.datatables.net/reference/option/formOptions * @see https://editor.datatables.net/reference/type/form-options @@ -185,11 +185,11 @@ public function formOptions(array $formOptions): static /** * Set Editor's inline formOptions. * - * @param array $formOptions + * @param array|FormOptions $formOptions * @return $this * @see https://editor.datatables.net/reference/option/formOptions.inline */ - public function formOptionsInline(array $formOptions): static + public function formOptionsInline(array|FormOptions $formOptions): static { return $this->formOptions(['inline' => Helper::castToArray($formOptions)]); } @@ -197,11 +197,11 @@ public function formOptionsInline(array $formOptions): static /** * Set Editor's main formOptions. * - * @param array $formOptions + * @param array|FormOptions $formOptions * @return $this * @see https://editor.datatables.net/reference/option/formOptions.main */ - public function formOptionsMain(array $formOptions): static + public function formOptionsMain(array|FormOptions $formOptions): static { return $this->formOptions(['main' => Helper::castToArray($formOptions)]); } From 28761fc2e77ce39b80b4e4d84819709603cf6362 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Fri, 31 Mar 2023 09:50:52 +0800 Subject: [PATCH 037/148] fix: docs --- src/Html/Editor/Editor.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Html/Editor/Editor.php b/src/Html/Editor/Editor.php index a6be8bf..f12000d 100644 --- a/src/Html/Editor/Editor.php +++ b/src/Html/Editor/Editor.php @@ -170,7 +170,7 @@ public function formOptionsBubble(array|FormOptions $formOptions): static /** * Set Editor's formOptions. * - * @param array $formOptions + * @param array $formOptions * @return $this * @see https://editor.datatables.net/reference/option/formOptions * @see https://editor.datatables.net/reference/type/form-options From d4f9aa3b5943dddea78089053d6b44e8ea8e21a5 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Fri, 31 Mar 2023 09:53:12 +0800 Subject: [PATCH 038/148] chore: release v10.5.2 :rocket: --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c3baac3..0d7b2e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ ## CHANGELOG +### v10.5.2 - 2023-03-31 + +- fix: backward compatibility with FormOptions class #190 + ### v10.5.1 - 2023-03-28 - fix: scripts attributes not working #189 From 94168243dd3a41610423de87518ea9e0bed0acb4 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Fri, 31 Mar 2023 15:17:47 +0800 Subject: [PATCH 039/148] feat: thead class builder fix: https://github.com/yajra/laravel-datatables-html/pull/169 fix: https://github.com/yajra/laravel-datatables/issues/2706 --- src/Html/Builder.php | 11 ++++++--- src/Html/HasTable.php | 55 +++++++++++++++++++++++++++---------------- tests/BuilderTest.php | 7 ++++-- 3 files changed, 48 insertions(+), 25 deletions(-) diff --git a/src/Html/Builder.php b/src/Html/Builder.php index d624138..c38aa27 100644 --- a/src/Html/Builder.php +++ b/src/Html/Builder.php @@ -198,13 +198,18 @@ public function table(array $attributes = [], bool $drawFooter = false, bool $dr $htmlAttr = $this->html->attributes($this->tableAttributes); $tableHtml = ''; - $searchHtml = $drawSearch ? ''.implode('', - $this->compileTableSearchHeaders()).'' : ''; - $tableHtml .= ''.implode('', $th).''.$searchHtml.''; + $searchHtml = $drawSearch + ? ''.implode('', $this->compileTableSearchHeaders()).'' + : ''; + + $tableHtml .= 'theadClass ?? '').'>'; + $tableHtml .= ''.implode('', $th).''.$searchHtml.''; + if ($drawFooter) { $tf = $this->compileTableFooter(); $tableHtml .= ''.implode('', $tf).''; } + $tableHtml .= ''; return new HtmlString($tableHtml); diff --git a/src/Html/HasTable.php b/src/Html/HasTable.php index 4ae6bd0..c434e2e 100644 --- a/src/Html/HasTable.php +++ b/src/Html/HasTable.php @@ -6,16 +6,7 @@ trait HasTable { - /** - * Retrieves HTML table attribute value. - * - * @param string $attribute - * @return string - */ - public function getTableAttribute(string $attribute): string - { - return $this->tableAttributes[$attribute] ?? ''; - } + protected ?string $theadClass = null; /** * Get table computed table attributes. @@ -38,16 +29,6 @@ public function setTableId(string $id): static return $this->setTableAttribute('id', $id); } - /** - * Get HTML table "id" attribute. - * - * @return string - */ - public function getTableId(): string - { - return $this->getTableAttribute('id'); - } - /** * Sets HTML table attribute(s). * @@ -81,6 +62,27 @@ public function setTableAttributes(array $attributes): static return $this; } + /** + * Get HTML table "id" attribute. + * + * @return string + */ + public function getTableId(): string + { + return $this->getTableAttribute('id'); + } + + /** + * Retrieves HTML table attribute value. + * + * @param string $attribute + * @return string + */ + public function getTableAttribute(string $attribute): string + { + return $this->tableAttributes[$attribute] ?? ''; + } + /** * Add class names to the "class" attribute of HTML table. * @@ -98,6 +100,19 @@ public function addTableClass(array|string $class): static return $this->setTableAttribute('class', $class); } + /** + * Set table > thead class names. + * + * @param string $class + * @return $this + */ + public function setTableHeadClass(string $class): static + { + $this->theadClass = " class=\"$class\""; + + return $this; + } + /** * Remove class names from the "class" attribute of HTML table. * diff --git a/tests/BuilderTest.php b/tests/BuilderTest.php index ae255c4..71a11ee 100644 --- a/tests/BuilderTest.php +++ b/tests/BuilderTest.php @@ -15,7 +15,7 @@ class BuilderTest extends TestCase public function it_can_get_script_default_type_attribute() { $html = $this->getHtmlBuilder()->scripts()->toHtml(); - + $this->assertStringContainsString('type="text/javascript"', $html); } @@ -23,7 +23,7 @@ public function it_can_get_script_default_type_attribute() public function it_can_set_script_type_attribute() { $html = $this->getHtmlBuilder()->scripts(attributes: ['type' => 'module'])->toHtml(); - + $this->assertStringContainsString('type="module"', $html); } @@ -267,6 +267,9 @@ public function it_has_table_options() $this->assertInstanceOf(HtmlString::class, $builder->table()); $this->assertEquals('
    ', $builder->table()->toHtml()); + + $builder->setTableHeadClass('thead-dark'); + $this->assertEquals('
    ', $builder->table()->toHtml()); } /** @test */ From eee4dac665d8f854233212eab3840f16c57ceaa8 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Fri, 31 Mar 2023 15:26:51 +0800 Subject: [PATCH 040/148] chore: release v10.6.0 :rocket: --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d7b2e1..c9dac23 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,12 @@ ## CHANGELOG +### v10.6.0 - 2023-03-31 + +- feat: thead class builder #191 +- fix: #169 +- fix: [yajra/laravel-datatables#2706](https://github.com/yajra/laravel-datatables/issues/2706) + ### v10.5.2 - 2023-03-31 - fix: backward compatibility with FormOptions class #190 From d48dc1bbe8bc860070240d6f1444e7a861c53789 Mon Sep 17 00:00:00 2001 From: Mohammad Reza Golestan Date: Sun, 7 May 2023 11:49:16 +0330 Subject: [PATCH 041/148] add exportRender method to be used in datatable-buttons for render print + exports as expected --- src/Html/Column.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/Html/Column.php b/src/Html/Column.php index e4818ce..8e157a5 100644 --- a/src/Html/Column.php +++ b/src/Html/Column.php @@ -491,6 +491,20 @@ public function render(mixed $value): static return $this; } + /** + * Set Callback function to render column for Print + Export + * + * @param function $callback + * @return $this + + */ + public function exportRender(callable $callback): static + { + $this->attributes['exportRender'] = $callback; + + return $this; + } + /** * Parse render attribute. * From dea7bb24d7becae3d4216760f488d52bbeb311a5 Mon Sep 17 00:00:00 2001 From: Mohammad Reza Golestan Date: Mon, 8 May 2023 10:24:04 +0330 Subject: [PATCH 042/148] add exportRender method to be used in datatable-buttons for render print + exports as expected: bugfix for static analysis with phpstan --- src/Html/Column.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Html/Column.php b/src/Html/Column.php index 8e157a5..61cc1b2 100644 --- a/src/Html/Column.php +++ b/src/Html/Column.php @@ -494,7 +494,7 @@ public function render(mixed $value): static /** * Set Callback function to render column for Print + Export * - * @param function $callback + * @param callable $callback * @return $this */ From ad6d66d3df7372ea1ede5447a303685f6cd343a9 Mon Sep 17 00:00:00 2001 From: Renier <17608701+fugazi-code@users.noreply.github.com> Date: Thu, 8 Jun 2023 14:25:31 +0800 Subject: [PATCH 043/148] Create new Method enum options This will fetch and arrange enum cases to key value pair in datatables. Also, it help to remove custom key value pair inside your Enums. --- src/Html/Editor/Fields/Field.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/Html/Editor/Fields/Field.php b/src/Html/Editor/Fields/Field.php index 3d4b64a..34850ea 100644 --- a/src/Html/Editor/Fields/Field.php +++ b/src/Html/Editor/Fields/Field.php @@ -121,6 +121,25 @@ public function modelOptions(Builder|string $model, string $value, string $key = ); } + /** + * Get options from a Enum::cases(). + * + * @param array|Arrayable $options + * @return $this + */ + public function enumOptions(array|Arrayable $cases): static + { + $options = []; + foreach ($cases as $case) { + $options[] = [ + 'value' => $case->value, + 'label' => $case->value, + ]; + } + + return $this->options($options); + } + /** * Set select options. * From 3a32fdcae22f3c64bd8b8a7bd20b1423aa20e98e Mon Sep 17 00:00:00 2001 From: Renier <17608701+fugazi-code@users.noreply.github.com> Date: Thu, 8 Jun 2023 14:35:51 +0800 Subject: [PATCH 044/148] Stan checking: update @params --- src/Html/Editor/Fields/Field.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Html/Editor/Fields/Field.php b/src/Html/Editor/Fields/Field.php index 34850ea..b654260 100644 --- a/src/Html/Editor/Fields/Field.php +++ b/src/Html/Editor/Fields/Field.php @@ -124,7 +124,7 @@ public function modelOptions(Builder|string $model, string $value, string $key = /** * Get options from a Enum::cases(). * - * @param array|Arrayable $options + * @param array|Arrayable $cases * @return $this */ public function enumOptions(array|Arrayable $cases): static From 8b403bd4d2231022cefae35131f73a7ae7532856 Mon Sep 17 00:00:00 2001 From: Renier <17608701+fugazi-code@users.noreply.github.com> Date: Thu, 8 Jun 2023 14:38:36 +0800 Subject: [PATCH 045/148] remove Arrayable --- src/Html/Editor/Fields/Field.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Html/Editor/Fields/Field.php b/src/Html/Editor/Fields/Field.php index b654260..a5f100b 100644 --- a/src/Html/Editor/Fields/Field.php +++ b/src/Html/Editor/Fields/Field.php @@ -124,10 +124,10 @@ public function modelOptions(Builder|string $model, string $value, string $key = /** * Get options from a Enum::cases(). * - * @param array|Arrayable $cases + * @param array $cases * @return $this */ - public function enumOptions(array|Arrayable $cases): static + public function enumOptions(array $cases): static { $options = []; foreach ($cases as $case) { From 3aaf1c19eb70713858e0ff88ac872e3386bbb4c1 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Thu, 8 Jun 2023 14:45:23 +0800 Subject: [PATCH 046/148] chore: bump v10.7.0 :rocket: --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c9dac23..1a40f5f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ ## CHANGELOG +### v10.7.0 - 2023-06-08 + +- feat: new method for enum options #196 + ### v10.6.0 - 2023-03-31 - feat: thead class builder #191 From 6b6c97fead0bb5ab615caa9dbfa2c68b0c4750b9 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Mon, 31 Jul 2023 11:06:49 +0800 Subject: [PATCH 047/148] chore: bump v10.8.0 :rocket: --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a40f5f..46191bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,12 @@ ## CHANGELOG +### v10.8.0 - 2023-07-31 + +- fix: Mixed Content problem with updating minifiedAjax method and get current url based on http or https scheme #186 +- fix: #194 +- feat: add exportRender method #195 + ### v10.7.0 - 2023-06-08 - feat: new method for enum options #196 From dd4b461a27bb8f91ea3450bc3be796ca206bb53f Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Wed, 16 Aug 2023 13:18:05 +0800 Subject: [PATCH 048/148] Revert "fix: Mixed Content problem with updating minifiedAjax method and get current url based on http or https scheme" --- src/Html/Options/HasAjax.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Html/Options/HasAjax.php b/src/Html/Options/HasAjax.php index 4a8282d..8252663 100644 --- a/src/Html/Options/HasAjax.php +++ b/src/Html/Options/HasAjax.php @@ -142,7 +142,7 @@ public function minifiedAjax( $this->ajax = []; $appendData = $this->makeDataScript($data); - $this->ajax['url'] = empty($url) ? url()->current() : $url; + $this->ajax['url'] = empty($url) ? url()->full() : $url; $this->ajax['type'] = 'GET'; if (! isset($this->attributes['serverSide']) || $this->attributes['serverSide']) { $this->ajax['data'] = 'function(data) { From 31500e3fd0ea6c18153a4122eb001abf6f04dd2a Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Wed, 16 Aug 2023 13:20:32 +0800 Subject: [PATCH 049/148] chore: bump v10.8.1 :rocket: --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 46191bd..8e63587 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,12 @@ ## CHANGELOG +### v10.8.1 - 2023-08-16 + +- Revert "fix: Mixed Content problem with updating minifiedAjax method and get current url based on http or https scheme" #202 +- Reverts #186 +- fix: #201 + ### v10.8.0 - 2023-07-31 - fix: Mixed Content problem with updating minifiedAjax method and get current url based on http or https scheme #186 From a70c9184174ed7c3ddac5917d03f659710dc6cd0 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Sat, 30 Sep 2023 15:12:30 +0800 Subject: [PATCH 050/148] fix: show searchPanes by default when initialized fixes the ff: - https://github.com/yajra/laravel-datatables/pull/2475#issuecomment-1645043408 - https://github.com/yajra/laravel-datatables-docs/pull/74#issuecomment-1645043870 --- src/Html/SearchPane.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Html/SearchPane.php b/src/Html/SearchPane.php index 18a6436..b93d023 100644 --- a/src/Html/SearchPane.php +++ b/src/Html/SearchPane.php @@ -10,6 +10,11 @@ class SearchPane extends Fluent { + public function __construct($attributes = []) + { + parent::__construct(['show' => true] + $attributes); + } + /** * @param array $options * @return static From 8dbfa912a20c82f8d462b5af0e4ac328c71dd190 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Mon, 2 Oct 2023 15:22:14 +0800 Subject: [PATCH 051/148] chore: release v10.8.2 :rocket: --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e63587..11b2331 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ ## CHANGELOG +### v10.8.2 - 2023-10-02 + +- fix: show searchPanes by default #205 + ### v10.8.1 - 2023-08-16 - Revert "fix: Mixed Content problem with updating minifiedAjax method and get current url based on http or https scheme" #202 From 7589b66af2c45e9894da21f040f5e3f8f8cf72c8 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Mon, 2 Oct 2023 18:20:28 +0800 Subject: [PATCH 052/148] fix: cs --- src/Html/SearchPane.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/Html/SearchPane.php b/src/Html/SearchPane.php index b93d023..a462ba8 100644 --- a/src/Html/SearchPane.php +++ b/src/Html/SearchPane.php @@ -223,9 +223,7 @@ public function hideTotal(bool $value = true): static */ public function modelOptions(EloquentBuilder|string $model, string $value, string $key = 'id'): SearchPane { - return $this->options( - Options::model($model, $value, $key) - ); + return $this->options(Options::model($model, $value, $key)); } /** @@ -261,9 +259,7 @@ public function tableOptions( Closure $callback = null, string $connection = null ): static { - return $this->options( - Options::table($table, $value, $key, $callback, $connection) - ); + return $this->options(Options::table($table, $value, $key, $callback, $connection)); } /** From 30e1e16db78cc2f5e74d89eb331022ac57ee4031 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Mon, 2 Oct 2023 18:22:40 +0800 Subject: [PATCH 053/148] feat: add collapse method --- src/Html/SearchPane.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/Html/SearchPane.php b/src/Html/SearchPane.php index a462ba8..7589b6d 100644 --- a/src/Html/SearchPane.php +++ b/src/Html/SearchPane.php @@ -321,4 +321,16 @@ public function orthogonal(array|string $value): static return $this; } + + /** + * @param boolean $value + * @return $this + * @see https://datatables.net/reference/option/searchPanes.collapse + */ + public function collapse(bool $value = true): static + { + $this->attributes['collapse'] = $value; + + return $this; + } } From 432477d75798c477021485137d828bacd0915820 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Mon, 2 Oct 2023 18:27:33 +0800 Subject: [PATCH 054/148] feat: add initCollapsed option setter --- src/Html/SearchPane.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/Html/SearchPane.php b/src/Html/SearchPane.php index 7589b6d..653820a 100644 --- a/src/Html/SearchPane.php +++ b/src/Html/SearchPane.php @@ -333,4 +333,16 @@ public function collapse(bool $value = true): static return $this; } + + /** + * @param boolean $value + * @return $this + * @see https://datatables.net/reference/option/searchPanes.initCollapsed + */ + public function initCollapsed(bool $value = false): static + { + $this->attributes['initCollapsed'] = $value; + + return $this; + } } From 92c228a70050dc0f1cecf41112f052de34cfa829 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Mon, 2 Oct 2023 18:30:16 +0800 Subject: [PATCH 055/148] chore: release v10.9.0 :rocket: --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 11b2331..5056de6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,11 @@ ## CHANGELOG +### v10.9.0 - 2023-10-02 + +- feat: add dtsp collapse option setter #206 +- feat: add initCollapsed option setter #207 + ### v10.8.2 - 2023-10-02 - fix: show searchPanes by default #205 From 263f288e958e4ec1243370b1c533d81eeda85157 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Wed, 4 Oct 2023 11:12:21 +0800 Subject: [PATCH 056/148] fix: add Arrayable fix: Parameter #1 $value of method Yajra\DataTables\Html\Builder::searchPanes() expects array|bool|(callable(): mixed), Yajra\DataTables\Html\SearchPane given. --- src/Html/Options/Plugins/SearchPanes.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Html/Options/Plugins/SearchPanes.php b/src/Html/Options/Plugins/SearchPanes.php index 0bc9e4a..754dc1e 100644 --- a/src/Html/Options/Plugins/SearchPanes.php +++ b/src/Html/Options/Plugins/SearchPanes.php @@ -16,7 +16,7 @@ trait SearchPanes /** * Set searchPane option value. * - * @param array|bool|callable $value + * @param array|Arrayable|bool|callable $value * @return $this * @see https://datatables.net/reference/option/searchPanes */ From daee4c1c3f42da277dc2fc12d8b5928fc3329715 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Wed, 4 Oct 2023 11:17:37 +0800 Subject: [PATCH 057/148] chore: release v10.9.1 :rocket: --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5056de6..09e3042 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,11 @@ ## CHANGELOG +### v10.9.1 - 2023-10-04 + +- fix: add missing Arrayable param #208 +- fix phpstan error: Parameter #1 $value of method Yajra\DataTables\Html\Builder::searchPanes() expects array|bool|(callable(): mixed), Yajra\DataTables\Html\SearchPane given. + ### v10.9.0 - 2023-10-02 - feat: add dtsp collapse option setter #206 From 99448262657e5bb23db9fb398004d0d86e50fb67 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Wed, 4 Oct 2023 12:35:35 +0800 Subject: [PATCH 058/148] fix: failing phpstan checks fix: function strval expects bool|float|int|resource|string|null, mixed given. --- src/Html/HtmlBuilder.php | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/src/Html/HtmlBuilder.php b/src/Html/HtmlBuilder.php index f9170c3..a96daf6 100644 --- a/src/Html/HtmlBuilder.php +++ b/src/Html/HtmlBuilder.php @@ -119,7 +119,7 @@ protected function attributeElement(string $key, mixed $value): mixed return 'class="'.implode(' ', $value).'"'; } - if (! is_null($value)) { + if (is_bool($value) || is_float($value) || is_int($value) || is_resource($value) || is_string($value)) { return $key.'="'.e(strval($value), false).'"'; } @@ -459,8 +459,18 @@ protected function listingElement(mixed $key, string $type, mixed $value): HtmlS if (is_array($value)) { return $this->nestedListing($key, $type, $value); } else { - return '
  • '.e(strval($value), false).'
  • '; + if (is_bool($value) + || is_float($value) + || is_int($value) + || is_resource($value) + || is_string($value) + || is_null($value) + ) { + return '
  • '.e(strval($value), false).'
  • '; + } } + + return '
  • '.$value.'
  • '; } /** @@ -549,6 +559,18 @@ public function tag(string $tag, mixed $content, array $attributes = []): HtmlSt { $content = is_array($content) ? implode('', $content) : $content; - return $this->toHtmlString('<'.$tag.$this->attributes($attributes).'>'.$this->toHtmlString(strval($content)).''); + if (is_bool($content) + || is_float($content) + || is_int($content) + || is_resource($content) + || is_string($content) + || is_null($content) + ) { + return $this->toHtmlString( + '<'.$tag.$this->attributes($attributes).'>'.$this->toHtmlString(strval($content)).'' + ); + } + + return $this->toHtmlString('<'.$tag.$this->attributes($attributes).'>'.$content.''); } } From 9d261deb6a72c9281bf1fbf4d8cb1326a3effa22 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Wed, 4 Oct 2023 12:37:43 +0800 Subject: [PATCH 059/148] fix: fix sonarcloud issues --- src/Html/HtmlBuilder.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Html/HtmlBuilder.php b/src/Html/HtmlBuilder.php index a96daf6..6bbed55 100644 --- a/src/Html/HtmlBuilder.php +++ b/src/Html/HtmlBuilder.php @@ -89,7 +89,7 @@ public function attributes(array $attributes): string } } - return count($html) > 0 ? ' '.implode(' ', $html) : ''; + return ! empty($html) ? ' '.implode(' ', $html) : ''; } /** @@ -226,7 +226,9 @@ public function link( $title = $this->entities($title); } - return $this->toHtmlString('attributes($attributes).'>'.$title.''); + return $this->toHtmlString( + 'attributes($attributes).'>'.$title.'' + ); } /** @@ -430,7 +432,7 @@ protected function listing(string $type, array $list, array $attributes = []): H { $html = ''; - if (count($list) === 0) { + if (empty($list)) { return $html; } @@ -520,7 +522,7 @@ public function dl(array $list, array $attributes = []): HtmlString $html .= "
    $key
    "; - foreach ($value as $v_key => $v_value) { + foreach ($value as $v_value) { $html .= "
    $v_value
    "; } } From 60fc09b131ee7cde976f74b925656af3a4b5686c Mon Sep 17 00:00:00 2001 From: Furkan Akkoc Date: Sat, 28 Oct 2023 00:59:40 +0200 Subject: [PATCH 060/148] Added optional scout js script if scout search engine is used (see yajra/laravel-datatables#3082) --- src/Html/Builder.php | 20 +++++++++++++++++++- src/resources/views/scout.blade.php | 23 +++++++++++++++++++++++ src/resources/views/script.blade.php | 3 +++ 3 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 src/resources/views/scout.blade.php diff --git a/src/Html/Builder.php b/src/Html/Builder.php index c38aa27..5335e06 100644 --- a/src/Html/Builder.php +++ b/src/Html/Builder.php @@ -59,6 +59,11 @@ class Builder */ protected string|array $ajax = ''; + /** + * @var array + */ + protected array $additionalScripts = []; + /** * @param Repository $config * @param Factory $view @@ -179,7 +184,7 @@ protected function template(): string $template = $this->template ?: $configTemplate; - return $this->view->make($template, ['editors' => $this->editors])->render(); + return $this->view->make($template, ['editors' => $this->editors, 'scripts' => $this->additionalScripts])->render(); } /** @@ -291,4 +296,17 @@ public function getAjax(string $key = null): array|string return $this->ajax; } + + /** + * Add additional scripts to the DataTables JS initialization. + * + * @param string $view + * @return $this + */ + public function addScript(string $view): static + { + $this->additionalScripts[] = $view; + + return $this; + } } diff --git a/src/resources/views/scout.blade.php b/src/resources/views/scout.blade.php new file mode 100644 index 0000000..cce4aab --- /dev/null +++ b/src/resources/views/scout.blade.php @@ -0,0 +1,23 @@ +$(function(){ + $('#%1$s').on('xhr.dt', function (e, settings, json, xhr) { + if (json == null || !('disableOrdering' in json)) return; + + let table = LaravelDataTables[$(this).attr('id')]; + if (json.disableOrdering) { + table.settings()[0].aoColumns.forEach(function(column) { + column.bSortable = false; + $(column.nTh).removeClass('sorting_asc sorting_desc sorting').addClass('sorting_disabled'); + }); + } else { + let changed = false; + table.settings()[0].aoColumns.forEach(function(column) { + if (column.bSortable) return; + column.bSortable = true; + changed = true; + }); + if (changed) { + table.draw(); + } + } + }); +}); diff --git a/src/resources/views/script.blade.php b/src/resources/views/script.blade.php index 82b3282..b01ac74 100644 --- a/src/resources/views/script.blade.php +++ b/src/resources/views/script.blade.php @@ -1 +1,4 @@ $(function(){window.{{ config('datatables-html.namespace', 'LaravelDataTables') }}=window.{{ config('datatables-html.namespace', 'LaravelDataTables') }}||{};window.{{ config('datatables-html.namespace', 'LaravelDataTables') }}["%1$s"]=$("#%1$s").DataTable(%2$s);}); +@foreach ($scripts as $script) +@include($script) +@endforeach From 594ca35cbdf38de736f53400e8e11f8448be588d Mon Sep 17 00:00:00 2001 From: Furkan Akkoc Date: Fri, 3 Nov 2023 02:03:52 +0100 Subject: [PATCH 061/148] Made namespace of scout script adaptable Co-authored-by: Arjay Angeles --- src/resources/views/scout.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/resources/views/scout.blade.php b/src/resources/views/scout.blade.php index cce4aab..506ad40 100644 --- a/src/resources/views/scout.blade.php +++ b/src/resources/views/scout.blade.php @@ -2,7 +2,7 @@ $('#%1$s').on('xhr.dt', function (e, settings, json, xhr) { if (json == null || !('disableOrdering' in json)) return; - let table = LaravelDataTables[$(this).attr('id')]; + let table = {{ config('datatables-html.namespace', 'LaravelDataTables') }}[$(this).attr('id')]; if (json.disableOrdering) { table.settings()[0].aoColumns.forEach(function(column) { column.bSortable = false; From 56b2c27564e5a83e76792cb7e969e148f12f0068 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Sat, 4 Nov 2023 09:25:27 +0800 Subject: [PATCH 062/148] feat: add script support using editor --- src/resources/views/editor.blade.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/resources/views/editor.blade.php b/src/resources/views/editor.blade.php index 3a464d5..70ab919 100644 --- a/src/resources/views/editor.blade.php +++ b/src/resources/views/editor.blade.php @@ -9,4 +9,7 @@ @endforeach @endforeach window.{{ config('datatables-html.namespace', 'LaravelDataTables') }}["%1$s"] = $("#%1$s").DataTable(%2$s); -}); \ No newline at end of file +}); +@foreach ($scripts as $script) +@include($script) +@endforeach From 2d7e73cc627923c56cdb26d04863ddc07fb8f1e6 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Sat, 4 Nov 2023 09:30:28 +0800 Subject: [PATCH 063/148] chore: release v10.10.0 :rocket: --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 09e3042..f9917f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,11 @@ ## CHANGELOG +### v10.10.0 - 2023-11-04 + +- feat: Add optional scout js script #210 +- feat: add script support when using editor #211 + ### v10.9.1 - 2023-10-04 - fix: add missing Arrayable param #208 From e02253ac420dc2df8f60045789ca47ccebe5e288 Mon Sep 17 00:00:00 2001 From: Furkan Akkoc Date: Mon, 6 Nov 2023 05:58:23 +0100 Subject: [PATCH 064/148] Added batch remove script --- .../views/functions/batch_remove.blade.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 src/resources/views/functions/batch_remove.blade.php diff --git a/src/resources/views/functions/batch_remove.blade.php b/src/resources/views/functions/batch_remove.blade.php new file mode 100644 index 0000000..192a7e5 --- /dev/null +++ b/src/resources/views/functions/batch_remove.blade.php @@ -0,0 +1,14 @@ +$(function(){ + @foreach($editors as $editor) + {{ config('datatables-html.namespace', 'LaravelDataTables') }}["%1$s-{{$editor->instance}}"].on('preSubmit', function(e, data, action) { + if (action !== 'remove') return; + + for (let row_id of Object.keys(data.data)) + { + data.data[row_id] = { + DT_RowId: data.data[row_id].DT_RowId + }; + } + }); + @endforeach +}); From f1154f4ba0c3d228ec70a965315a471e57ca57f2 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Mon, 6 Nov 2023 13:50:20 +0800 Subject: [PATCH 065/148] chore: release v10.11.0 :rocket: --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f9917f8..7bea929 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ ## CHANGELOG +### v10.11.0 - 2023-11-06 + +- feat: add batch remove optimization script (optional) #212 + ### v10.10.0 - 2023-11-04 - feat: Add optional scout js script #210 From 8fcda6e52bd22b04e0731ca8ff4501e68719a951 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Fri, 15 Dec 2023 12:36:51 +0800 Subject: [PATCH 066/148] feat: allow macro on field --- src/Html/Editor/Fields/Field.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Html/Editor/Fields/Field.php b/src/Html/Editor/Fields/Field.php index a5f100b..eb9c4b5 100644 --- a/src/Html/Editor/Fields/Field.php +++ b/src/Html/Editor/Fields/Field.php @@ -8,6 +8,7 @@ use Illuminate\Database\Query\Builder as QueryBuilder; use Illuminate\Support\Fluent; use Illuminate\Support\Str; +use Illuminate\Support\Traits\Macroable; use Yajra\DataTables\Html\HasAuthorizations; /** @@ -16,6 +17,7 @@ class Field extends Fluent { use HasAuthorizations; + use Macroable; /** * Field type. From 1c0fc1ff2026457ff29ab1a6a3433a44d59b251d Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Fri, 15 Dec 2023 12:41:00 +0800 Subject: [PATCH 067/148] chore: release v10.12.0 :rocket: --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7bea929..12afe79 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ ## CHANGELOG +### v10.12.0 - 2023-12-15 + +- feat: allow macro on Field #213 + ### v10.11.0 - 2023-11-06 - feat: add batch remove optimization script (optional) #212 From 21e81f537756b096f18c4ad2d5b9d437793e15b7 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Tue, 27 Feb 2024 12:17:28 +0800 Subject: [PATCH 068/148] feat: laravel 11 --- composer.json | 11 ++++++----- phpstan.neon.dist | 4 ++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/composer.json b/composer.json index 2b9d3e5..11de354 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,8 @@ { "name": "yajra/laravel-datatables-html", - "description": "Laravel DataTables HTML builder plugin for Laravel 5.4+.", + "description": "Laravel DataTables HTML builder plugin", "keywords": [ + "yajra", "laravel", "dataTables", "jquery", @@ -16,13 +17,13 @@ } ], "require": { - "php": "^8.1", + "php": "^8.2", "ext-json": "*", - "yajra/laravel-datatables-oracle": "^10.0" + "yajra/laravel-datatables-oracle": "^11.0" }, "require-dev": { - "nunomaduro/larastan": "^2.4", - "orchestra/testbench": "^7.21" + "larastan/larastan": "^2.9.1", + "orchestra/testbench": "^9" }, "autoload": { "psr-4": { diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 73b4990..08605d3 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -1,5 +1,5 @@ includes: - - ./vendor/nunomaduro/larastan/extension.neon + - ./vendor/larastan/larastan/extension.neon parameters: @@ -15,4 +15,4 @@ parameters: checkMissingIterableValueType: false - checkGenericClassInNonGenericObjectType: false \ No newline at end of file + checkGenericClassInNonGenericObjectType: false From ea04643b8095c2bfb2f208d1ded146be09daaacb Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Tue, 27 Feb 2024 12:20:55 +0800 Subject: [PATCH 069/148] fix: fluent scope method compatibility --- CHANGELOG.md | 94 ++------------------------------- UPGRADE.md | 4 ++ src/Html/Editor/FormOptions.php | 2 +- tests/EditorFormOptionsTest.php | 4 +- 4 files changed, 12 insertions(+), 92 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 12afe79..7e5509d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,94 +8,10 @@ ## CHANGELOG -### v10.12.0 - 2023-12-15 +### UNRELEASED -- feat: allow macro on Field #213 +- Add support for Laravel 11.x +- Fix editor scope compatibility with Fluent class scope +- Rename Editor `scope` method to `formScope` -### v10.11.0 - 2023-11-06 - -- feat: add batch remove optimization script (optional) #212 - -### v10.10.0 - 2023-11-04 - -- feat: Add optional scout js script #210 -- feat: add script support when using editor #211 - -### v10.9.1 - 2023-10-04 - -- fix: add missing Arrayable param #208 -- fix phpstan error: Parameter #1 $value of method Yajra\DataTables\Html\Builder::searchPanes() expects array|bool|(callable(): mixed), Yajra\DataTables\Html\SearchPane given. - -### v10.9.0 - 2023-10-02 - -- feat: add dtsp collapse option setter #206 -- feat: add initCollapsed option setter #207 - -### v10.8.2 - 2023-10-02 - -- fix: show searchPanes by default #205 - -### v10.8.1 - 2023-08-16 - -- Revert "fix: Mixed Content problem with updating minifiedAjax method and get current url based on http or https scheme" #202 -- Reverts #186 -- fix: #201 - -### v10.8.0 - 2023-07-31 - -- fix: Mixed Content problem with updating minifiedAjax method and get current url based on http or https scheme #186 -- fix: #194 -- feat: add exportRender method #195 - -### v10.7.0 - 2023-06-08 - -- feat: new method for enum options #196 - -### v10.6.0 - 2023-03-31 - -- feat: thead class builder #191 -- fix: #169 -- fix: [yajra/laravel-datatables#2706](https://github.com/yajra/laravel-datatables/issues/2706) - -### v10.5.2 - 2023-03-31 - -- fix: backward compatibility with FormOptions class #190 - -### v10.5.1 - 2023-03-28 - -- fix: scripts attributes not working #189 - -### v10.5.0 - 2023-03-02 - -- feat: hide/show fields based on editor action #188 - - hiddenOnCreate - - hiddenOnEdit - - hiddenOn - -### v10.4.0 - 2023-03-02 - -- feat: add datetime field options #187 - - wireFormat - - keyInput - - displayFormat - -### v10.3.1 - 2023-02-20 - -- fix: too long file name check for column render #185 - -### v10.3.0 - 2023-02-20 - -- feat: add builder ability to use viteJs by default #184 - -### v10.2.0 - 2023-02-20 - -- feat: allow callable exportFormat parameter #167 - -### v10.1.0 - 2023-02-07 - -- Drop Collective\Html dependency #183 -- Copy Collective HtmlBuilder class and implemented php-stan - -### v10.0.0 - 2023-02-07 - -- Add Laravel 10 specific support +### v11.0.0 (2024-0X-0X) diff --git a/UPGRADE.md b/UPGRADE.md index 453dc3e..011b035 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1 +1,5 @@ # Upgrade Notes + +## v10 to v11 + +- Editor `scope` method has been renamed to `formScope`. diff --git a/src/Html/Editor/FormOptions.php b/src/Html/Editor/FormOptions.php index 24397f8..0b8f984 100644 --- a/src/Html/Editor/FormOptions.php +++ b/src/Html/Editor/FormOptions.php @@ -131,7 +131,7 @@ public function submit(string $value = 'changed'): static * @return $this * @see https://editor.datatables.net/reference/type/form-options#scope */ - public function scope(string $value = 'row'): static + public function formScope(string $value = 'row'): static { $this->attributes['scope'] = $value; diff --git a/tests/EditorFormOptionsTest.php b/tests/EditorFormOptionsTest.php index 3896eb0..804912c 100644 --- a/tests/EditorFormOptionsTest.php +++ b/tests/EditorFormOptionsTest.php @@ -24,7 +24,7 @@ public function it_has_setters() ->submit('submit') ->title('title') ->drawType('drawType') - ->scope('scope') + ->formScope('scope') ->nest(false) ->buttons([]) ->submitTrigger(1) @@ -47,4 +47,4 @@ public function it_has_setters() $this->assertEquals(1, $options->submitTrigger); $this->assertEquals('submitHtml', $options->submitHtml); } -} \ No newline at end of file +} From cdbc740cc3e000cab269a68d4a6c2a212fa0e124 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Tue, 27 Feb 2024 12:24:21 +0800 Subject: [PATCH 070/148] fix: use Test attribute --- phpunit.xml | 21 ++++---------- tests/BuilderOptionsLanguageTest.php | 10 ++++--- tests/BuilderOptionsPluginsTest.php | 25 +++++++++-------- tests/BuilderOptionsTest.php | 15 +++++----- tests/BuilderTest.php | 41 ++++++++++++++-------------- tests/ColumnDefinitionTest.php | 5 ++-- tests/ColumnTest.php | 27 +++++++++--------- tests/EditorFormOptionsTest.php | 3 +- tests/EditorTest.php | 19 +++++++------ tests/FieldOptionsTest.php | 15 +++++----- tests/FieldTest.php | 41 ++++++++++++++-------------- tests/SearchPaneTest.php | 5 ++-- tests/TestCase.php | 6 ++-- 13 files changed, 118 insertions(+), 115 deletions(-) diff --git a/phpunit.xml b/phpunit.xml index 422eeac..2cb7512 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,17 +1,8 @@ - - - - ./tests/ - - + + + + ./tests/ + + diff --git a/tests/BuilderOptionsLanguageTest.php b/tests/BuilderOptionsLanguageTest.php index d1a467b..c65c45b 100644 --- a/tests/BuilderOptionsLanguageTest.php +++ b/tests/BuilderOptionsLanguageTest.php @@ -2,9 +2,11 @@ namespace Yajra\DataTables\Html\Tests; +use PHPUnit\Framework\Attributes\Test; + class BuilderOptionsLanguageTest extends TestCase { - /** @test */ + #[Test] public function it_has_language_aria_options() { $builder = $this->getHtmlBuilder(); @@ -33,7 +35,7 @@ public function it_has_language_aria_options() $this->assertEquals('languageAriaSortDescending', $builder->getLanguage('aria')['sortDescending']); } - /** @test */ + #[Test] public function it_has_language_autofill_options() { $builder = $this->getHtmlBuilder(); @@ -62,7 +64,7 @@ public function it_has_language_autofill_options() $this->assertEquals('languageAutoFillInfo', $builder->getLanguage('autoFill')['info']); } - /** @test */ + #[Test] public function it_has_language_paginate_options() { $builder = $this->getHtmlBuilder(); @@ -82,7 +84,7 @@ public function it_has_language_paginate_options() $this->assertEquals('languagePaginatePrevious', $builder->getLanguage('paginate')['previous']); } - /** @test */ + #[Test] public function it_has_language_select_options() { $builder = $this->getHtmlBuilder(); diff --git a/tests/BuilderOptionsPluginsTest.php b/tests/BuilderOptionsPluginsTest.php index a6f93ef..5101464 100644 --- a/tests/BuilderOptionsPluginsTest.php +++ b/tests/BuilderOptionsPluginsTest.php @@ -2,13 +2,14 @@ namespace Yajra\DataTables\Html\Tests; +use PHPUnit\Framework\Attributes\Test; use Yajra\DataTables\Html\Builder; use Yajra\DataTables\Html\Button; use Yajra\DataTables\Html\SearchPane; class BuilderOptionsPluginsTest extends TestCase { - /** @test */ + #[Test] public function it_has_autofill_plugin() { $builder = $this->getHtmlBuilder(); @@ -43,7 +44,7 @@ public function it_has_autofill_plugin() $this->assertEquals([1, 2], $builder->getAutoFill('columns')); } - /** @test */ + #[Test] public function it_has_buttons_plugin() { $builder = $this->getHtmlBuilder(); @@ -63,7 +64,7 @@ public function it_has_buttons_plugin() $this->assertCount(2, $builder->getButtons()); } - /** @test */ + #[Test] public function it_has_col_reorder_plugin() { $builder = $this->getHtmlBuilder(); @@ -85,7 +86,7 @@ public function it_has_col_reorder_plugin() $this->assertEquals(true, $builder->getColReorder('realtime')); } - /** @test */ + #[Test] public function it_has_fixed_columns_plugin() { $builder = $this->getHtmlBuilder(); @@ -103,7 +104,7 @@ public function it_has_fixed_columns_plugin() $this->assertEquals(0, $builder->getFixedColumns('rightColumns')); } - /** @test */ + #[Test] public function it_has_fixed_header_plugin() { $builder = $this->getHtmlBuilder(); @@ -123,7 +124,7 @@ public function it_has_fixed_header_plugin() $this->assertEquals(0, $builder->getFixedHeader('headerOffset')); } - /** @test */ + #[Test] public function it_has_keys_plugin() { @@ -160,7 +161,7 @@ public function it_has_keys_plugin() $this->assertEquals(1, $builder->getKeys('tabIndex')); } - /** @test */ + #[Test] public function it_has_responsive_plugin() { $builder = $this->getHtmlBuilder(); @@ -183,7 +184,7 @@ public function it_has_responsive_plugin() $this->assertEquals('orthogonal', $builder->getResponsive('orthogonal')); } - /** @test */ + #[Test] public function it_has_row_group_plugin() { $builder = $this->getHtmlBuilder(); @@ -209,7 +210,7 @@ public function it_has_row_group_plugin() $this->assertEquals(null, $builder->getRowGroup('startRender')); } - /** @test */ + #[Test] public function it_has_row_reorder_plugin() { $builder = $this->getHtmlBuilder(); @@ -235,7 +236,7 @@ public function it_has_row_reorder_plugin() $this->assertEquals(true, $builder->getRowReorder('update')); } - /** @test */ + #[Test] public function it_has_scroller_plugin() { $builder = $this->getHtmlBuilder(); @@ -257,7 +258,7 @@ public function it_has_scroller_plugin() $this->assertEquals(200, $builder->getScroller('serverWait')); } - /** @test */ + #[Test] public function it_has_search_panes_plugin() { $builder = $this->getHtmlBuilder(); @@ -281,7 +282,7 @@ public function it_has_search_panes_plugin() $this->assertEquals(['show' => true, 'cascadePanes' => true], $builder->getAttribute('searchPanes')); } - /** @test */ + #[Test] public function it_has_select_plugin() { $builder = $this->getHtmlBuilder(); diff --git a/tests/BuilderOptionsTest.php b/tests/BuilderOptionsTest.php index 4b47691..e7f1462 100644 --- a/tests/BuilderOptionsTest.php +++ b/tests/BuilderOptionsTest.php @@ -2,12 +2,13 @@ namespace Yajra\DataTables\Html\Tests; +use PHPUnit\Framework\Attributes\Test; use Yajra\DataTables\Html\Builder; use Yajra\DataTables\Html\Column; class BuilderOptionsTest extends TestCase { - /** @test */ + #[Test] public function it_has_callbacks_options() { $builder = $this->getHtmlBuilder(); @@ -45,7 +46,7 @@ public function it_has_callbacks_options() $this->assertStringContainsString('test livewire', $builder->getAttribute('drawCallback')); } - /** @test */ + #[Test] public function it_has_columns_options() { $builder = $this->getHtmlBuilder(); @@ -103,7 +104,7 @@ public function it_has_columns_options() $this->assertCount(4, $builder->getColumns()); } - /** @test */ + #[Test] public function it_has_ajax_options() { $builder = $this->getHtmlBuilder(); @@ -147,7 +148,7 @@ public function it_has_ajax_options() $this->assertStringContainsString('#formId', $builder->getAjax('data')); } - /** @test */ + #[Test] public function it_has_features_options() { $builder = $this->getHtmlBuilder(); @@ -181,7 +182,7 @@ public function it_has_features_options() $this->assertEquals('50vh', $builder->getAttribute('scrollY')); } - /** @test */ + #[Test] public function it_has_internationalisation_options() { $builder = $this->getHtmlBuilder(); @@ -220,7 +221,7 @@ public function it_has_internationalisation_options() $this->assertEquals('languageUrl', $builder->getLanguage('url')); } - /** @test */ + #[Test] public function it_has_plugin_attribute_getter() { $builder = $this->getHtmlBuilder(); @@ -230,7 +231,7 @@ public function it_has_plugin_attribute_getter() $this->assertEquals(Builder::SELECT_STYLE_SINGLE, $builder->getPluginAttribute('select', 'style')); } - /** @test */ + #[Test] public function it_has_options() { $builder = $this->getHtmlBuilder(); diff --git a/tests/BuilderTest.php b/tests/BuilderTest.php index 71a11ee..e7c8aac 100644 --- a/tests/BuilderTest.php +++ b/tests/BuilderTest.php @@ -3,6 +3,7 @@ namespace Yajra\DataTables\Html\Tests; use Illuminate\Support\HtmlString; +use PHPUnit\Framework\Attributes\Test; use Yajra\DataTables\Html\Builder; use Yajra\DataTables\Html\Column; use Yajra\DataTables\Html\ColumnDefinition; @@ -11,7 +12,7 @@ class BuilderTest extends TestCase { - /** @test */ + #[Test] public function it_can_get_script_default_type_attribute() { $html = $this->getHtmlBuilder()->scripts()->toHtml(); @@ -19,7 +20,7 @@ public function it_can_get_script_default_type_attribute() $this->assertStringContainsString('type="text/javascript"', $html); } - /** @test */ + #[Test] public function it_can_set_script_type_attribute() { $html = $this->getHtmlBuilder()->scripts(attributes: ['type' => 'module'])->toHtml(); @@ -27,7 +28,7 @@ public function it_can_set_script_type_attribute() $this->assertStringContainsString('type="module"', $html); } - /** @test */ + #[Test] public function it_can_set_multiple_script_attributes() { $html = $this->getHtmlBuilder()->scripts(attributes: ['prop1' => 'val1', 'prop2' => 'val2'])->toHtml(); @@ -36,7 +37,7 @@ public function it_can_set_multiple_script_attributes() $this->assertStringContainsString('prop2="val2"', $html); } - /** @test */ + #[Test] public function it_can_use_vitejs_module_script() { Builder::useVite(); @@ -46,7 +47,7 @@ public function it_can_use_vitejs_module_script() Builder::useWebpack(); } - /** @test */ + #[Test] public function it_can_resolved_builder_class() { $builder = $this->getHtmlBuilder(); @@ -57,7 +58,7 @@ public function it_can_resolved_builder_class() $this->assertInstanceOf(Builder::class, $builder); } - /** @test */ + #[Test] public function it_can_read_table_id_from_config() { $this->assertEquals('dataTableBuilder', $this->getHtmlBuilder()->getTableId()); @@ -67,7 +68,7 @@ public function it_can_read_table_id_from_config() $this->assertEquals('test', $this->getHtmlBuilder()->getTableId()); } - /** @test */ + #[Test] public function it_can_change_namespace() { $builder = $this->getHtmlBuilder(); @@ -79,7 +80,7 @@ public function it_can_change_namespace() $this->assertStringContainsString('TestDataTables', $builder->scripts()->toHtml()); } - /** @test */ + #[Test] public function it_can_generate_table_html_and_scripts() { $builder = $this->getHtmlBuilder(); @@ -103,7 +104,7 @@ public function it_can_generate_table_html_and_scripts() $this->assertEquals($expected, $builder->generateScripts()->toHtml()); } - /** @test */ + #[Test] public function it_can_set_table_attribute() { $builder = $this->getHtmlBuilder(); @@ -113,7 +114,7 @@ public function it_can_set_table_attribute() $this->assertEquals('val', $builder->getTableAttribute('attr')); } - /** @test */ + #[Test] public function it_can_set_table_id_attribute() { $builder = $this->getHtmlBuilder(); @@ -123,7 +124,7 @@ public function it_can_set_table_id_attribute() $this->assertEquals('val', $builder->getTableAttribute('id')); } - /** @test */ + #[Test] public function it_can_set_multiple_table_attributes() { $builder = $this->getHtmlBuilder(); @@ -134,7 +135,7 @@ public function it_can_set_multiple_table_attributes() $this->assertEquals('val2', $builder->getTableAttribute('prop2')); } - /** @test */ + #[Test] public function it_can_get_inexistent_table_attribute_throws() { $builder = $this->getHtmlBuilder(); @@ -144,7 +145,7 @@ public function it_can_get_inexistent_table_attribute_throws() $this->assertEmpty($attr); } - /** @test */ + #[Test] public function it_can_add_table_class_attribute() { $builder = $this->getHtmlBuilder(); @@ -160,7 +161,7 @@ public function it_can_add_table_class_attribute() $this->assertEquals('table foo bar a-b c value', $builder->getTableAttribute('class')); } - /** @test */ + #[Test] public function it_can_remove_table_class_attribute() { $builder = $this->getHtmlBuilder(); @@ -176,7 +177,7 @@ public function it_can_remove_table_class_attribute() $this->assertEquals('a', $builder->getTableAttribute('class')); } - /** @test */ + #[Test] public function it_can_add_checkbox() { $builder = $this->getHtmlBuilder(); @@ -192,7 +193,7 @@ public function it_can_add_checkbox() $this->assertEquals(true, $column->printable); } - /** @test */ + #[Test] public function it_can_add_index_column() { $builder = $this->getHtmlBuilder(); @@ -208,7 +209,7 @@ public function it_can_add_index_column() $this->assertEquals(true, $column->printable); } - /** @test */ + #[Test] public function it_can_add_action_column() { $builder = $this->getHtmlBuilder(); @@ -224,7 +225,7 @@ public function it_can_add_action_column() $this->assertEquals(true, $column->printable); } - /** @test */ + #[Test] public function it_has_column_defs() { $builder = $this->getHtmlBuilder(); @@ -247,7 +248,7 @@ public function it_has_column_defs() $this->assertCount(1, $builder->getAttribute('columnDefs')); } - /** @test */ + #[Test] public function it_has_table_options() { $builder = $this->getHtmlBuilder(); @@ -272,7 +273,7 @@ public function it_has_table_options() $this->assertEquals('
    ', $builder->table()->toHtml()); } - /** @test */ + #[Test] public function it_has_editors() { $builder = $this->getHtmlBuilder(); diff --git a/tests/ColumnDefinitionTest.php b/tests/ColumnDefinitionTest.php index 9842b38..9eb0fdc 100644 --- a/tests/ColumnDefinitionTest.php +++ b/tests/ColumnDefinitionTest.php @@ -2,11 +2,12 @@ namespace Yajra\DataTables\Html\Tests; +use PHPUnit\Framework\Attributes\Test; use Yajra\DataTables\Html\ColumnDefinition; class ColumnDefinitionTest extends TestCase { - /** @test */ + #[Test] public function it_has_property_setters() { $def = ColumnDefinition::make() @@ -25,4 +26,4 @@ public function it_has_property_setters() $this->assertEquals('fn', $def->createdCell); } -} \ No newline at end of file +} diff --git a/tests/ColumnTest.php b/tests/ColumnTest.php index cf958e8..00e385f 100644 --- a/tests/ColumnTest.php +++ b/tests/ColumnTest.php @@ -2,11 +2,12 @@ namespace Yajra\DataTables\Html\Tests; +use PHPUnit\Framework\Attributes\Test; use Yajra\DataTables\Html\Column; class ColumnTest extends TestCase { - /** @test */ + #[Test] public function it_can_create_column() { $column = Column::make('name'); @@ -14,7 +15,7 @@ public function it_can_create_column() $this->assertInstanceOf(Column::class, $column); } - /** @test */ + #[Test] public function it_has_default_properties() { $column = Column::make('name'); @@ -31,13 +32,13 @@ public function it_has_default_properties() $this->assertEquals('', $column->footer); } - /** @test */ + #[Test] public function it_can_format_title() { $this->assertEquals('Title', Column::titleFormat('title')); } - /** @test */ + #[Test] public function it_can_make_computed_column() { $column = Column::computed('name'); @@ -55,7 +56,7 @@ public function it_can_make_computed_column() } - /** @test */ + #[Test] public function it_can_make_formatted_column() { $column = Column::formatted('name'); @@ -72,7 +73,7 @@ public function it_can_make_formatted_column() $this->assertEquals('', $column->footer); } - /** @test */ + #[Test] public function it_can_make_a_checkbox() { $column = Column::checkbox('name'); @@ -90,7 +91,7 @@ public function it_can_make_a_checkbox() $this->assertEquals('', $column->footer); } - /** @test */ + #[Test] public function it_has_property_setters() { $column = Column::checkbox('name'); @@ -138,7 +139,7 @@ public function it_has_property_setters() $this->assertEquals('test', $column->exportFormat); } - /** @test */ + #[Test] public function it_can_render_scripts() { $column = Column::make('name'); @@ -156,7 +157,7 @@ public function it_can_render_scripts() $this->assertEquals('test', $column->render); } - /** @test */ + #[Test] public function it_allows_orthogonal_data() { $expected = [ @@ -170,7 +171,7 @@ public function it_allows_orthogonal_data() $this->assertEquals($expected, $column->data); } - /** @test */ + #[Test] public function it_has_responsive_priority() { $column = Column::make('name'); @@ -179,7 +180,7 @@ public function it_has_responsive_priority() $this->assertEquals(1, $column->responsivePriority); } - /** @test */ + #[Test] public function it_can_add_class() { $column = Column::make('name')->className('text-sm'); @@ -189,7 +190,7 @@ public function it_can_add_class() $this->assertEquals('text-sm font-bold', $column->className); } - /** @test */ + #[Test] public function it_has_authorizations() { $column = Column::makeIf(true, 'name'); @@ -206,7 +207,7 @@ public function it_has_authorizations() $this->assertEquals([], $column->toArray()); } - /** @test */ + #[Test] public function it_can_be_serialized() { $column = Column::make('name'); diff --git a/tests/EditorFormOptionsTest.php b/tests/EditorFormOptionsTest.php index 804912c..e10ece6 100644 --- a/tests/EditorFormOptionsTest.php +++ b/tests/EditorFormOptionsTest.php @@ -2,11 +2,12 @@ namespace Yajra\DataTables\Html\Tests; +use PHPUnit\Framework\Attributes\Test; use Yajra\DataTables\Html\Editor\FormOptions; class EditorFormOptionsTest extends TestCase { - /** @test */ + #[Test] public function it_has_setters() { $options = FormOptions::make(); diff --git a/tests/EditorTest.php b/tests/EditorTest.php index b17e296..16ce1d7 100644 --- a/tests/EditorTest.php +++ b/tests/EditorTest.php @@ -2,12 +2,13 @@ namespace Yajra\DataTables\Html\Tests; +use PHPUnit\Framework\Attributes\Test; use Yajra\DataTables\Html\Editor\Editor; use Yajra\DataTables\Html\Editor\Fields\Text; class EditorTest extends TestCase { - /** @test */ + #[Test] public function it_can_create_an_editor() { $editor = $this->getEditor(); @@ -41,7 +42,7 @@ protected function getEditor(string $instance = 'editor'): Editor return Editor::make($instance); } - /** @test */ + #[Test] public function it_can_have_events() { $editor = $this->getEditor(); @@ -59,7 +60,7 @@ public function it_can_have_events() $this->assertEquals($event, $editor->events[0]); } - /** @test */ + #[Test] public function it_can_show_hide_fields() { $editor = $this->getEditor(); @@ -78,7 +79,7 @@ public function it_can_show_hide_fields() $this->assertStringContainsString("this.hide('email')", $editor->events[1]['script']); } - /** @test */ + #[Test] public function it_has_authorizations() { $editor = Editor::makeIf(true, 'editor') @@ -114,7 +115,7 @@ public function it_has_authorizations() $this->assertEquals([], $editor->toArray()); } - /** @test */ + #[Test] public function it_can_be_serialized_to_array() { $editor = Editor::make() @@ -132,7 +133,7 @@ public function it_can_be_serialized_to_array() ], $editor->toArray()); } - /** @test */ + #[Test] public function it_can_be_serialized_to_json_string() { $editor = Editor::make() @@ -145,7 +146,7 @@ public function it_can_be_serialized_to_json_string() $this->assertEquals($expected, $editor->toJson()); } - /** @test */ + #[Test] public function it_has_form_options() { $editor = Editor::make() @@ -171,7 +172,7 @@ public function it_has_form_options() $this->assertEquals(['esc' => true], $editor->formOptions['inline']); } - /** @test */ + #[Test] public function it_has_display_constants() { $editor = Editor::make()->display(Editor::DISPLAY_BOOTSTRAP); @@ -190,7 +191,7 @@ public function it_has_display_constants() $this->assertEquals('lightbox', $editor->display); } - /** @test */ + #[Test] public function it_has_scripts() { $editor = Editor::make()->scripts('fn'); diff --git a/tests/FieldOptionsTest.php b/tests/FieldOptionsTest.php index 6a122b2..082217e 100644 --- a/tests/FieldOptionsTest.php +++ b/tests/FieldOptionsTest.php @@ -4,6 +4,7 @@ use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Support\Facades\DB; +use PHPUnit\Framework\Attributes\Test; use Yajra\DataTables\Html\Editor\Fields\Options; use Yajra\DataTables\Html\Tests\Models\User; @@ -11,7 +12,7 @@ class FieldOptionsTest extends TestCase { use DatabaseTransactions; - /** @test */ + #[Test] public function it_has_true_false() { $options = Options::trueFalse(); @@ -22,7 +23,7 @@ public function it_has_true_false() ], $options->toArray()); } - /** @test */ + #[Test] public function it_has_yes_no() { $options = Options::yesNo(); @@ -33,7 +34,7 @@ public function it_has_yes_no() ], $options->toArray()); } - /** @test */ + #[Test] public function it_can_append_and_prepend() { $options = Options::yesNo(); @@ -59,28 +60,28 @@ public function it_can_append_and_prepend() ], $options->toArray()); } - /** @test */ + #[Test] public function it_can_get_options_from_table() { $options = Options::table('users', 'name'); $this->assertCount(20, $options); } - /** @test */ + #[Test] public function it_can_get_options_from_query() { $options = Options::table(DB::table('users')->where('id', 1), 'name'); $this->assertCount(1, $options); } - /** @test */ + #[Test] public function it_can_get_options_from_model() { $options = Options::model(User::class, 'name'); $this->assertCount(20, $options); } - /** @test */ + #[Test] public function it_can_get_options_from_model_builder() { $options = Options::model(User::query()->whereKey(1), 'name'); diff --git a/tests/FieldTest.php b/tests/FieldTest.php index 6c31822..996e1f9 100644 --- a/tests/FieldTest.php +++ b/tests/FieldTest.php @@ -2,12 +2,13 @@ namespace Yajra\DataTables\Html\Tests; +use PHPUnit\Framework\Attributes\Test; use Yajra\DataTables\Html\Editor\Fields; use Yajra\DataTables\Html\Tests\Models\User; class FieldTest extends TestCase { - /** @test */ + #[Test] public function it_can_create_a_field() { $field = Fields\Field::make('name'); @@ -18,7 +19,7 @@ public function it_can_create_a_field() $this->assertEquals('text', $field->getType()); } - /** @test */ + #[Test] public function it_can_set_properties() { $field = Fields\Field::make('name'); @@ -34,7 +35,7 @@ public function it_can_set_properties() $this->assertEquals('Test', $field->getType()); } - /** @test */ + #[Test] public function it_can_create_belongs_to_field() { $field = Fields\BelongsTo::model(User::class, 'name'); @@ -44,7 +45,7 @@ public function it_can_create_belongs_to_field() $this->assertEquals('User', $field->label); } - /** @test */ + #[Test] public function it_can_create_boolean_field() { $field = Fields\Boolean::make('name'); @@ -56,7 +57,7 @@ public function it_can_create_boolean_field() $this->assertEquals([['label' => '', 'value' => 1]], $field->options); } - /** @test */ + #[Test] public function it_can_create_date_field() { $field = Fields\Date::make('name'); @@ -67,7 +68,7 @@ public function it_can_create_date_field() $this->assertEquals('YYYY-MM-DD', $field->format); } - /** @test */ + #[Test] public function it_can_create_datetime_field() { $field = Fields\DateTime::make('name'); @@ -118,7 +119,7 @@ public function it_can_create_datetime_field() $this->assertEquals('LLL', $field->getAttributes()['wireFormat']); } - /** @test */ + #[Test] public function it_can_create_file_field() { $field = Fields\File::make('name'); @@ -127,7 +128,7 @@ public function it_can_create_file_field() // TODO: add more file field test } - /** @test */ + #[Test] public function it_can_create_hidden_field() { $field = Fields\Hidden::make('name'); @@ -135,7 +136,7 @@ public function it_can_create_hidden_field() $this->assertEquals('hidden', $field->getType()); } - /** @test */ + #[Test] public function it_can_create_image_field() { $field = Fields\Image::make('name'); @@ -143,7 +144,7 @@ public function it_can_create_image_field() $this->assertEquals('upload', $field->getType()); } - /** @test */ + #[Test] public function it_can_create_number_field() { $field = Fields\Number::make('name'); @@ -151,7 +152,7 @@ public function it_can_create_number_field() $this->assertEquals('text', $field->getType()); } - /** @test */ + #[Test] public function it_can_create_password_field() { $field = Fields\Password::make('name'); @@ -159,7 +160,7 @@ public function it_can_create_password_field() $this->assertEquals('password', $field->getType()); } - /** @test */ + #[Test] public function it_can_create_radio_field() { $field = Fields\Radio::make('name'); @@ -167,7 +168,7 @@ public function it_can_create_radio_field() $this->assertEquals('radio', $field->getType()); } - /** @test */ + #[Test] public function it_can_create_read_only_field() { $field = Fields\ReadOnlyField::make('name'); @@ -175,7 +176,7 @@ public function it_can_create_read_only_field() $this->assertEquals('readonly', $field->getType()); } - /** @test */ + #[Test] public function it_can_create_select_field() { $field = Fields\Select::make('name'); @@ -183,7 +184,7 @@ public function it_can_create_select_field() $this->assertEquals('select', $field->getType()); } - /** @test */ + #[Test] public function it_can_create_select2_field() { $field = Fields\Select2::make('name') @@ -227,7 +228,7 @@ public function it_can_create_select2_field() $this->assertEquals('/test', $field->opts['ajax']['url']);; } - /** @test */ + #[Test] public function it_can_create_text_field() { $field = Fields\Text::make('name') @@ -238,7 +239,7 @@ public function it_can_create_text_field() $this->assertEquals('display: none;', $field->attr['style']); } - /** @test */ + #[Test] public function it_can_create_textarea_field() { $field = Fields\TextArea::make('name'); @@ -252,7 +253,7 @@ public function it_can_create_textarea_field() $this->assertEquals('5', $field->attr['cols']); } - /** @test */ + #[Test] public function it_can_create_time_field() { $field = Fields\Time::make('name'); @@ -263,7 +264,7 @@ public function it_can_create_time_field() $this->assertEquals('hh:mm a', $field->format); } - /** @test */ + #[Test] public function it_has_authorizations() { $field = Fields\Text::makeIf(true, 'name'); @@ -277,7 +278,7 @@ public function it_has_authorizations() $this->assertEquals([], $field->toArray()); } - /** @test */ + #[Test] public function it_can_be_serialized() { $field = Fields\Text::make('name')->data('user.name'); diff --git a/tests/SearchPaneTest.php b/tests/SearchPaneTest.php index 329c396..b5962b3 100644 --- a/tests/SearchPaneTest.php +++ b/tests/SearchPaneTest.php @@ -3,6 +3,7 @@ namespace Yajra\DataTables\Html\Tests; use Illuminate\Foundation\Testing\DatabaseTransactions; +use PHPUnit\Framework\Attributes\Test; use Yajra\DataTables\Html\SearchPane; use Yajra\DataTables\Html\Tests\Models\User; @@ -10,7 +11,7 @@ class SearchPaneTest extends TestCase { use DatabaseTransactions; - /** @test */ + #[Test] public function it_has_setters() { $pane = SearchPane::make(); @@ -51,7 +52,7 @@ public function it_has_setters() $this->assertEquals(true, $pane->viewTotal); } - /** @test */ + #[Test] public function it_has_options() { $pane = SearchPane::make()->options([1, 2, 3]); diff --git a/tests/TestCase.php b/tests/TestCase.php index ef9de21..1a03505 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -20,7 +20,7 @@ protected function setUp(): void $this->seedDatabase(); } - protected function migrateDatabase() + protected function migrateDatabase(): void { /** @var \Illuminate\Database\Schema\Builder $schemaBuilder */ $schemaBuilder = $this->app['db']->connection()->getSchemaBuilder(); @@ -59,7 +59,7 @@ protected function migrateDatabase() } } - protected function seedDatabase() + protected function seedDatabase(): void { $adminRole = Role::create(['role' => 'Administrator']); $userRole = Role::create(['role' => 'User']); @@ -90,7 +90,7 @@ protected function seedDatabase() * * @param \Illuminate\Foundation\Application $app */ - protected function getEnvironmentSetUp($app) + protected function getEnvironmentSetUp($app): void { $app['config']->set('app.debug', true); $app['config']->set('database.default', 'sqlite'); From b80307da37f32cbfb583b77c25387e15b18d270f Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Tue, 27 Feb 2024 12:26:22 +0800 Subject: [PATCH 071/148] chore: pint workflow --- .github/workflows/pint.yml | 21 +++++++++++++++++++++ pint.json | 3 +++ 2 files changed, 24 insertions(+) create mode 100644 .github/workflows/pint.yml create mode 100644 pint.json diff --git a/.github/workflows/pint.yml b/.github/workflows/pint.yml new file mode 100644 index 0000000..7844b88 --- /dev/null +++ b/.github/workflows/pint.yml @@ -0,0 +1,21 @@ +name: PHP Linting +on: + pull_request: + push: + branches: + - master +jobs: + phplint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: "laravel-pint" + uses: aglipanci/laravel-pint-action@2.0.0 + with: + preset: laravel + verboseMode: true + testMode: false + onlyDirty: true + - uses: stefanzweifel/git-auto-commit-action@v5 + with: + commit_message: "fix: pint" diff --git a/pint.json b/pint.json new file mode 100644 index 0000000..93061b6 --- /dev/null +++ b/pint.json @@ -0,0 +1,3 @@ +{ + "preset": "laravel" +} From 4eefa56cc9de25dfdc9931f2eb929d8737058e3a Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Tue, 27 Feb 2024 12:28:27 +0800 Subject: [PATCH 072/148] chore: update php versions --- .github/workflows/continuous-integration.yml | 2 +- .github/workflows/static-analysis.yml | 30 ++++++++++++-------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 49033a2..056482b 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -14,7 +14,7 @@ jobs: strategy: fail-fast: true matrix: - php: [8.1, 8.2] + php: [8.2, 8.3] stability: [prefer-stable] name: PHP ${{ matrix.php }} - ${{ matrix.stability }} diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index 59f0a2c..8e9365d 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -22,27 +22,33 @@ on: jobs: static-analysis-phpstan: + name: "Static Analysis with PHPStan" runs-on: ubuntu-latest strategy: + fail-fast: true matrix: - php-version: - - "8.1" + php: [8.2, 8.3] + stability: [prefer-stable] steps: - - name: "Checkout code" - uses: "actions/checkout@v2" + - name: Checkout code + uses: actions/checkout@v2 - - 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 with Composer" - uses: "ramsey/composer-install@v1" + - name: Install dependencies + uses: nick-invision/retry@v1 + with: + timeout_minutes: 5 + max_attempts: 5 + command: COMPOSER_ROOT_VERSION=dev-master composer update --${{ matrix.stability }} --prefer-dist --no-interaction --no-progress - name: "Run a static analysis with phpstan/phpstan" - run: "vendor/bin/phpstan --error-format=checkstyle | cs2pr" + run: "vendor/bin/phpstan --error-format=table" From 56f14e8719e8f72a3f3bd72dd31a3fba0e226902 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Tue, 27 Feb 2024 12:30:14 +0800 Subject: [PATCH 073/148] fix: pint --- .gitignore | 1 + src/Html/Builder.php | 73 ++------ src/Html/Button.php | 53 +++--- src/Html/Column.php | 98 ++++------- src/Html/ColumnDefinition.php | 7 +- src/Html/ColumnDefinitions.php | 1 - src/Html/Columns/Action.php | 2 - src/Html/Columns/Checkbox.php | 1 - src/Html/Columns/Index.php | 1 - src/Html/Editor/Editor.php | 40 ++--- src/Html/Editor/Fields/BelongsTo.php | 8 +- src/Html/Editor/Fields/Boolean.php | 4 - src/Html/Editor/Fields/Date.php | 4 - src/Html/Editor/Fields/DateTime.php | 28 ++- src/Html/Editor/Fields/Field.php | 58 +++---- src/Html/Editor/Fields/File.php | 24 +-- src/Html/Editor/Fields/Image.php | 5 - src/Html/Editor/Fields/Options.php | 27 +-- src/Html/Editor/Fields/Select.php | 6 - src/Html/Editor/Fields/Select2.php | 12 -- src/Html/Editor/Fields/TextArea.php | 8 - src/Html/Editor/Fields/Time.php | 4 - src/Html/Editor/FormOptions.php | 39 ++--- src/Html/Editor/HasEvents.php | 3 +- src/Html/HasAuthorizations.php | 27 +-- src/Html/HasEditor.php | 8 +- src/Html/HasOptions.php | 65 +++---- src/Html/HasTable.php | 22 +-- src/Html/HtmlBuilder.php | 169 ++----------------- src/Html/Options/HasAjax.php | 24 +-- src/Html/Options/HasCallbacks.php | 32 ++-- src/Html/Options/HasColumns.php | 10 +- src/Html/Options/HasFeatures.php | 24 +-- src/Html/Options/HasInternationalisation.php | 38 ++--- src/Html/Options/Languages/Aria.php | 16 +- src/Html/Options/Languages/AutoFill.php | 16 +- src/Html/Options/Languages/Paginate.php | 10 +- src/Html/Options/Languages/Select.php | 8 +- src/Html/Options/Plugins/AutoFill.php | 26 ++- src/Html/Options/Plugins/Buttons.php | 4 +- src/Html/Options/Plugins/ColReorder.php | 18 +- src/Html/Options/Plugins/FixedColumns.php | 14 +- src/Html/Options/Plugins/FixedHeader.php | 18 +- src/Html/Options/Plugins/KeyTable.php | 34 ++-- src/Html/Options/Plugins/Responsive.php | 22 +-- src/Html/Options/Plugins/RowGroup.php | 26 ++- src/Html/Options/Plugins/RowReorder.php | 24 ++- src/Html/Options/Plugins/Scroller.php | 18 +- src/Html/Options/Plugins/SearchPanes.php | 8 +- src/Html/Options/Plugins/Select.php | 29 ++-- src/Html/SearchPane.php | 61 +++---- src/HtmlServiceProvider.php | 4 - src/resources/config/config.php | 2 +- tests/BuilderOptionsPluginsTest.php | 109 ++++++------ tests/BuilderOptionsTest.php | 118 +++++++------ tests/BuilderTest.php | 30 ++-- tests/ColumnDefinitionTest.php | 13 +- tests/ColumnTest.php | 1 - tests/EditorFormOptionsTest.php | 30 ++-- tests/EditorTest.php | 42 +++-- tests/FieldTest.php | 16 +- tests/SearchPaneTest.php | 28 +-- tests/TestCase.php | 3 - 63 files changed, 578 insertions(+), 1096 deletions(-) diff --git a/.gitignore b/.gitignore index df0e1ea..c2e4bf9 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ /coverage composer.phar composer.lock +/.phpunit.cache/test-results diff --git a/src/Html/Builder.php b/src/Html/Builder.php index 5335e06..d7a8ac4 100644 --- a/src/Html/Builder.php +++ b/src/Html/Builder.php @@ -11,22 +11,29 @@ class Builder { - use Macroable; - use HasOptions; - use HasTable; - use HasEditor; - use Columns\Index; use Columns\Action; use Columns\Checkbox; + use Columns\Index; + use HasEditor; + use HasOptions; + use HasTable; + use Macroable; // Select plugin constants. const SELECT_STYLE_API = 'api'; + const SELECT_STYLE_SINGLE = 'single'; + const SELECT_STYLE_MULTI = 'multi'; + const SELECT_STYLE_OS = 'os'; + const SELECT_STYLE_MULTI_SHIFT = 'multi+shift'; + const SELECT_ITEMS_ROW = 'row'; + const SELECT_ITEMS_COLUMN = 'column'; + const SELECT_ITEMS_CELL = 'cell'; /** @@ -44,31 +51,14 @@ class Builder */ protected array $tableAttributes = []; - /** - * @var string - */ protected string $template = ''; - /** - * @var array - */ protected array $attributes = []; - /** - * @var string|array - */ protected string|array $ajax = ''; - /** - * @var array - */ protected array $additionalScripts = []; - /** - * @param Repository $config - * @param Factory $view - * @param HtmlBuilder $html - */ public function __construct(public Repository $config, public Factory $view, public HtmlBuilder $html) { /** @var array $defaults */ @@ -100,12 +90,8 @@ public static function useWebpack(): void /** * Generate DataTable javascript. - * - * @param string|null $script - * @param array $attributes - * @return \Illuminate\Support\HtmlString */ - public function scripts(string $script = null, array $attributes = []): HtmlString + public function scripts(?string $script = null, array $attributes = []): HtmlString { $script = $script ?: $this->generateScripts(); $attributes = $this->html->attributes( @@ -117,8 +103,6 @@ public function scripts(string $script = null, array $attributes = []): HtmlStri /** * Get generated raw scripts. - * - * @return \Illuminate\Support\HtmlString */ public function generateScripts(): HtmlString { @@ -131,8 +115,6 @@ public function generateScripts(): HtmlString /** * Get generated json configuration. - * - * @return string */ public function generateJson(): string { @@ -141,9 +123,6 @@ public function generateJson(): string /** * Generate DataTables js parameters. - * - * @param array $attributes - * @return string */ public function parameterize(array $attributes = []): string { @@ -154,8 +133,6 @@ public function parameterize(array $attributes = []): string /** * Get DataTable options array. - * - * @return array */ public function getOptions(): array { @@ -174,8 +151,6 @@ public function getOptions(): array /** * Get javascript template to use. - * - * @return string */ protected function template(): string { @@ -189,11 +164,6 @@ protected function template(): string /** * Generate DataTable's table html. - * - * @param array $attributes - * @param bool $drawFooter - * @param bool $drawSearch - * @return \Illuminate\Support\HtmlString */ public function table(array $attributes = [], bool $drawFooter = false, bool $drawSearch = false): HtmlString { @@ -223,7 +193,6 @@ public function table(array $attributes = [], bool $drawFooter = false, bool $dr /** * Configure DataTable's parameters. * - * @param array $attributes * @return $this */ public function parameters(array $attributes = []): static @@ -246,7 +215,6 @@ public function asOptions(): static /** * Set custom javascript template. * - * @param string $template * @return $this */ public function setTemplate(string $template): static @@ -266,29 +234,17 @@ public function asFunction(): static return $this->setTemplate('datatables::function'); } - /** - * @return array - */ public function getAttributes(): array { return $this->attributes; } - /** - * @param string $key - * @param mixed $default - * @return mixed - */ public function getAttribute(string $key, mixed $default = ''): mixed { return $this->attributes[$key] ?? $default; } - /** - * @param string|null $key - * @return array|string - */ - public function getAjax(string $key = null): array|string + public function getAjax(?string $key = null): array|string { if (! is_null($key)) { return $this->ajax[$key] ?? ''; @@ -300,7 +256,6 @@ public function getAjax(string $key = null): array|string /** * Add additional scripts to the DataTables JS initialization. * - * @param string $view * @return $this */ public function addScript(string $view): static diff --git a/src/Html/Button.php b/src/Html/Button.php index 0b3b7f2..7a42ca6 100755 --- a/src/Html/Button.php +++ b/src/Html/Button.php @@ -11,9 +11,6 @@ class Button extends Fluent implements Arrayable /** * Make a new button instance. - * - * @param array|string $options - * @return static */ public static function make(array|string $options = []): static { @@ -26,9 +23,6 @@ public static function make(array|string $options = []): static /** * Make a raw button that does not extend anything. - * - * @param array|string $options - * @return static */ public static function raw(array|string $options = []): static { @@ -42,8 +36,8 @@ public static function raw(array|string $options = []): static /** * Set attr option value. * - * @param array $value * @return $this + * * @see https://datatables.net/reference/option/buttons.buttons.attr */ public function attr(array $value): static @@ -56,8 +50,8 @@ public function attr(array $value): static /** * Set available option value. * - * @param string $value * @return $this + * * @see https://datatables.net/reference/option/buttons.buttons.available */ public function available(string $value): static @@ -73,9 +67,6 @@ public function available(string $value): static /** * Check if a given value is a function. - * - * @param string $value - * @return bool */ protected function isFunction(string $value): bool { @@ -85,8 +76,8 @@ protected function isFunction(string $value): bool /** * Set enabled option value. * - * @param bool $value * @return $this + * * @see https://datatables.net/reference/option/buttons.buttons.enabled */ public function enabled(bool $value = true): static @@ -99,8 +90,8 @@ public function enabled(bool $value = true): static /** * Set init option value. * - * @param string $value * @return $this + * * @see https://datatables.net/reference/option/buttons.buttons.init */ public function init(string $value): static @@ -117,8 +108,8 @@ public function init(string $value): static /** * Set key option value. * - * @param array|string $value * @return $this + * * @see https://datatables.net/reference/option/buttons.buttons.key */ public function key(array|string $value): static @@ -131,8 +122,8 @@ public function key(array|string $value): static /** * Set extend option value. * - * @param string $value * @return $this + * * @see https://datatables.net/reference/option/buttons.buttons.extend */ public function extend(string $value): static @@ -145,8 +136,8 @@ public function extend(string $value): static /** * Set editor option value. * - * @param string $value * @return $this + * * @see https://editor.datatables.net/reference/button */ public function editor(string $value): static @@ -159,8 +150,8 @@ public function editor(string $value): static /** * Set buttons option value. * - * @param array $buttons * @return $this + * * @see https://datatables.net/reference/option/buttons.buttons */ public function buttons(array $buttons): static @@ -177,8 +168,8 @@ public function buttons(array $buttons): static } /** - * @param array $buttons * @return $this + * * @see https://editor.datatables.net/examples/api/cancelButton */ public function formButtons(array $buttons): static @@ -195,8 +186,8 @@ public function formButtons(array $buttons): static } /** - * @param string $message * @return $this + * * @see https://editor.datatables.net/examples/api/removeMessage * @see https://editor.datatables.net/reference/button/create * @see https://editor.datatables.net/reference/button/edit @@ -210,8 +201,8 @@ public function formMessage(string $message): static } /** - * @param string $title * @return $this + * * @see https://editor.datatables.net/reference/button/create * @see https://editor.datatables.net/reference/button/edit * @see https://editor.datatables.net/reference/button/remove @@ -226,8 +217,8 @@ public function formTitle(string $title): static /** * Set className option value. * - * @param string $value * @return $this + * * @see https://datatables.net/reference/option/buttons.buttons.className */ public function className(string $value): static @@ -240,8 +231,8 @@ public function className(string $value): static /** * Set destroy option value. * - * @param string $value * @return $this + * * @see https://datatables.net/reference/option/buttons.buttons.destroy */ public function destroy(string $value): static @@ -258,8 +249,8 @@ public function destroy(string $value): static /** * Set customize option value. * - * @param string $value * @return $this + * * @see https://datatables.net/reference/button/excelHtml5 */ public function customize(string $value): static @@ -272,7 +263,6 @@ public function customize(string $value): static /** * Append a class name to column. * - * @param string $class * @return $this */ public function addClass(string $class): static @@ -289,8 +279,8 @@ public function addClass(string $class): static /** * Set text option value. * - * @param string $value * @return $this + * * @see https://datatables.net/reference/option/buttons.buttons.text */ public function text(string $value): static @@ -303,8 +293,8 @@ public function text(string $value): static /** * Set titleAttr option value. * - * @param string $value * @return $this + * * @see https://datatables.net/reference/option/buttons.buttons.titleAttr */ public function titleAttr(string $value): static @@ -317,8 +307,8 @@ public function titleAttr(string $value): static /** * Set name option value. * - * @param string $value * @return $this + * * @see https://datatables.net/reference/option/buttons.buttons.name */ public function name(string $value): static @@ -331,8 +321,8 @@ public function name(string $value): static /** * Set namespace option value. * - * @param string $value * @return $this + * * @see https://datatables.net/reference/option/buttons.buttons.namespace */ public function namespace(string $value): static @@ -345,8 +335,8 @@ public function namespace(string $value): static /** * Set tag option value. * - * @param string $value * @return $this + * * @see https://datatables.net/reference/option/buttons.buttons.tag */ public function tag(string $value): static @@ -359,7 +349,6 @@ public function tag(string $value): static /** * Set columns option value. * - * @param array|string $value * @return $this */ public function columns(array|string $value): static @@ -372,7 +361,6 @@ public function columns(array|string $value): static /** * Set exportOptions option value. * - * @param array|string $value * @return $this */ public function exportOptions(array|string $value): static @@ -395,7 +383,6 @@ public function actionSubmit(): static /** * Set action option value. * - * @param string $value * @return $this */ public function action(string $value): static @@ -412,7 +399,6 @@ public function action(string $value): static /** * Set editor class action handler. * - * @param string $action * @return $this */ public function actionHandler(string $action): static @@ -433,7 +419,6 @@ public function actionClose(): static /** * Set button alignment. * - * @param string $align * @return $this */ public function align(string $align = 'button-left'): static diff --git a/src/Html/Column.php b/src/Html/Column.php index 61cc1b2..4797ad9 100644 --- a/src/Html/Column.php +++ b/src/Html/Column.php @@ -29,12 +29,13 @@ * @property string $contentPadding * @property string $createdCell * @property string $exportFormat + * * @see https://datatables.net/reference/option/#columns */ class Column extends Fluent { - use SearchPanes; use HasAuthorizations; + use SearchPanes; /** * @param array $attributes @@ -66,9 +67,6 @@ public function __construct($attributes = []) /** * Format string to title case. - * - * @param string $value - * @return string */ public static function titleFormat(string $value): string { @@ -78,8 +76,8 @@ public static function titleFormat(string $value): string /** * Set column title. * - * @param string $value * @return $this + * * @see https://datatables.net/reference/option/columns.title */ public function title(string $value): static @@ -91,12 +89,8 @@ public function title(string $value): static /** * Create a computed column that is not searchable/orderable. - * - * @param string $data - * @param string|null $title - * @return Column */ - public static function computed(string $data, string $title = null): Column + public static function computed(string $data, ?string $title = null): Column { if (is_null($title)) { $title = self::titleFormat($data); @@ -108,8 +102,8 @@ public static function computed(string $data, string $title = null): Column /** * Set column searchable flag. * - * @param bool $flag * @return $this + * * @see https://datatables.net/reference/option/columns.searchable */ public function searchable(bool $flag = true): static @@ -122,8 +116,8 @@ public function searchable(bool $flag = true): static /** * Set column orderable flag. * - * @param bool $flag * @return $this + * * @see https://datatables.net/reference/option/columns.orderable */ public function orderable(bool $flag = true): static @@ -135,10 +129,6 @@ public function orderable(bool $flag = true): static /** * Make a new column instance. - * - * @param array|string $data - * @param string $name - * @return static */ public static function make(array|string $data = [], string $name = ''): static { @@ -155,9 +145,6 @@ public static function make(array|string $data = [], string $name = ''): static /** * Make a new formatted column instance. - * - * @param string $name - * @return static */ public static function formatted(string $name): static { @@ -173,25 +160,21 @@ public static function formatted(string $name): static /** * Create a checkbox column. - * - * @param string $title - * @return static */ public static function checkbox(string $title = ''): static { return static::make('') - ->content('') - ->title($title) - ->className('select-checkbox') - ->orderable(false) - ->exportable(false) - ->searchable(false); + ->content('') + ->title($title) + ->className('select-checkbox') + ->orderable(false) + ->exportable(false) + ->searchable(false); } /** * Set column exportable flag. * - * @param bool $flag * @return $this */ public function exportable(bool $flag = true): static @@ -204,8 +187,8 @@ public function exportable(bool $flag = true): static /** * Set column class name. * - * @param string $class * @return $this + * * @see https://datatables.net/reference/option/columns.className */ public function className(string $class): static @@ -218,8 +201,8 @@ public function className(string $class): static /** * Set column default content. * - * @param string $value * @return $this + * * @see https://datatables.net/reference/option/columns.defaultContent */ public function content(string $value): static @@ -232,8 +215,8 @@ public function content(string $value): static /** * Set column responsive priority. * - * @param int|string $value * @return $this + * * @see https://datatables.net/reference/option/columns.responsivePriority */ public function responsivePriority(int|string $value): static @@ -247,6 +230,7 @@ public function responsivePriority(int|string $value): static * Set column hidden state. * * @return $this + * * @see https://datatables.net/reference/option/columns.visible */ public function hidden(): static @@ -257,8 +241,8 @@ public function hidden(): static /** * Set column visible flag. * - * @param bool $flag * @return $this + * * @see https://datatables.net/reference/option/columns.visible */ public function visible(bool $flag = true): static @@ -271,7 +255,6 @@ public function visible(bool $flag = true): static /** * Append a class name to field. * - * @param string $class * @return $this */ public function addClass(string $class): static @@ -288,7 +271,6 @@ public function addClass(string $class): static /** * Set column printable flag. * - * @param bool $flag * @return $this */ public function printable(bool $flag = true): static @@ -301,8 +283,8 @@ public function printable(bool $flag = true): static /** * Set column width value. * - * @param int|string $value * @return $this + * * @see https://datatables.net/reference/option/columns.width */ public function width(int|string $value): static @@ -315,8 +297,8 @@ public function width(int|string $value): static /** * Set column data option value. * - * @param array|string $value * @return $this + * * @see https://datatables.net/reference/option/columns.data * @see https://datatables.net/manual/data/orthogonal-data */ @@ -330,8 +312,8 @@ public function data(array|string $value): static /** * Set column name option value. * - * @param string $value * @return $this + * * @see https://datatables.net/reference/option/columns.name */ public function name(string $value): static @@ -344,8 +326,8 @@ public function name(string $value): static /** * Set column edit field option value. * - * @param array|string $value * @return $this + * * @see https://datatables.net/reference/option/columns.editField */ public function editField(array|string $value): static @@ -358,8 +340,8 @@ public function editField(array|string $value): static /** * Set column orderData option value. * - * @param array|int $value * @return $this + * * @see https://datatables.net/reference/option/columns.orderData */ public function orderData(array|int $value): static @@ -372,8 +354,8 @@ public function orderData(array|int $value): static /** * Set column orderDataType option value. * - * @param string $value * @return $this + * * @see https://datatables.net/reference/option/columns.orderDataType */ public function orderDataType(string $value): static @@ -386,8 +368,8 @@ public function orderDataType(string $value): static /** * Set column orderSequence option value. * - * @param array $value * @return $this + * * @see https://datatables.net/reference/option/columns.orderSequence */ public function orderSequence(array $value): static @@ -400,8 +382,8 @@ public function orderSequence(array $value): static /** * Set column cellType option value. * - * @param string $value * @return $this + * * @see https://datatables.net/reference/option/columns.cellType */ public function cellType(string $value = 'th'): static @@ -414,8 +396,8 @@ public function cellType(string $value = 'th'): static /** * Set column type option value. * - * @param string $value * @return $this + * * @see https://datatables.net/reference/option/columns.type */ public function type(string $value): static @@ -428,8 +410,8 @@ public function type(string $value): static /** * Set column contentPadding option value. * - * @param string $value * @return $this + * * @see https://datatables.net/reference/option/columns.contentPadding */ public function contentPadding(string $value): static @@ -442,8 +424,8 @@ public function contentPadding(string $value): static /** * Set column createdCell option value. * - * @param string $value * @return $this + * * @see https://datatables.net/reference/option/columns.createdCell */ public function createdCell(string $value): static @@ -456,9 +438,9 @@ public function createdCell(string $value): static /** * Use the js renderer "$.fn.dataTable.render.". * - * @param string $value * @param int|string|null ...$params * @return $this + * * @see https://datatables.net/reference/option/columns.render */ public function renderJs(string $value, ...$params): static @@ -480,8 +462,8 @@ public function renderJs(string $value, ...$params): static /** * Set column renderer. * - * @param mixed $value * @return $this + * * @see https://datatables.net/reference/option/columns.render */ public function render(mixed $value): static @@ -494,9 +476,7 @@ public function render(mixed $value): static /** * Set Callback function to render column for Print + Export * - * @param callable $callback * @return $this - */ public function exportRender(callable $callback): static { @@ -507,9 +487,6 @@ public function exportRender(callable $callback): static /** * Parse render attribute. - * - * @param mixed $value - * @return string|null */ public function parseRender(mixed $value): ?string { @@ -535,9 +512,6 @@ public function parseRender(mixed $value): ?string /** * Check if given key & value is a valid datatables built-in renderer function. - * - * @param string $value - * @return bool */ private function isBuiltInRenderFunction(string $value): bool { @@ -550,9 +524,6 @@ private function isBuiltInRenderFunction(string $value): bool /** * Display render value as is. - * - * @param string $value - * @return string */ private function parseRenderAsString(string $value): string { @@ -562,8 +533,8 @@ private function parseRenderAsString(string $value): string /** * Set column renderer with give raw value. * - * @param mixed $value * @return $this + * * @see https://datatables.net/reference/option/columns.render */ public function renderRaw(mixed $value): static @@ -576,7 +547,6 @@ public function renderRaw(mixed $value): static /** * Set column footer. * - * @param mixed $value * @return $this */ public function footer(mixed $value): static @@ -589,7 +559,6 @@ public function footer(mixed $value): static /** * Set custom html title instead default label. * - * @param mixed $value * @return $this */ public function titleAttr(mixed $value): static @@ -602,8 +571,8 @@ public function titleAttr(mixed $value): static /** * Set excel column format when exporting. * - * @param string|callable $format * @return $this + * * @see https://github.com/yajra/laravel-datatables-export */ public function exportFormat(string|callable $format): static @@ -613,9 +582,6 @@ public function exportFormat(string|callable $format): static return $this; } - /** - * @return array - */ public function toArray(): array { if (! $this->isAuthorized()) { diff --git a/src/Html/ColumnDefinition.php b/src/Html/ColumnDefinition.php index 418f7a3..a05cf29 100644 --- a/src/Html/ColumnDefinition.php +++ b/src/Html/ColumnDefinition.php @@ -18,8 +18,8 @@ public function __construct($attributes = []) } /** - * @param array|string|int $value * @return $this + * * @see https://datatables.net/reference/option/columnDefs.targets */ public function targets(array|string|int $value): static @@ -30,8 +30,8 @@ public function targets(array|string|int $value): static } /** - * @param array $value * @return $this + * * @see https://datatables.net/reference/option/columns */ public function columns(array $value): static @@ -41,9 +41,6 @@ public function columns(array $value): static return $this; } - /** - * @return array - */ public function toArray(): array { $array = parent::toArray(); diff --git a/src/Html/ColumnDefinitions.php b/src/Html/ColumnDefinitions.php index 83816de..8058990 100644 --- a/src/Html/ColumnDefinitions.php +++ b/src/Html/ColumnDefinitions.php @@ -6,5 +6,4 @@ class ColumnDefinitions extends Collection { - } diff --git a/src/Html/Columns/Action.php b/src/Html/Columns/Action.php index 848cc51..d18be02 100644 --- a/src/Html/Columns/Action.php +++ b/src/Html/Columns/Action.php @@ -9,8 +9,6 @@ trait Action /** * Add an action column. * - * @param array $attributes - * @param bool $prepend * @return $this */ public function addAction(array $attributes = [], bool $prepend = false): static diff --git a/src/Html/Columns/Checkbox.php b/src/Html/Columns/Checkbox.php index aaa76d6..dc29677 100644 --- a/src/Html/Columns/Checkbox.php +++ b/src/Html/Columns/Checkbox.php @@ -9,7 +9,6 @@ trait Checkbox /** * Add a checkbox column. * - * @param array $attributes * @param bool|int $position true to prepend, false to append or a zero-based index for positioning * @return $this */ diff --git a/src/Html/Columns/Index.php b/src/Html/Columns/Index.php index 41e9ee5..3bdfa6c 100644 --- a/src/Html/Columns/Index.php +++ b/src/Html/Columns/Index.php @@ -9,7 +9,6 @@ trait Index /** * Add a index column. * - * @param array $attributes * @return $this */ public function addIndex(array $attributes = []): static diff --git a/src/Html/Editor/Editor.php b/src/Html/Editor/Editor.php index f12000d..eee7962 100644 --- a/src/Html/Editor/Editor.php +++ b/src/Html/Editor/Editor.php @@ -21,13 +21,17 @@ */ class Editor extends Fluent { - use HasEvents; use HasAuthorizations; + use HasEvents; const DISPLAY_LIGHTBOX = 'lightbox'; + const DISPLAY_ENVELOPE = 'envelope'; + const DISPLAY_BOOTSTRAP = 'bootstrap'; + const DISPLAY_FOUNDATION = 'foundation'; + const DISPLAY_JQUERYUI = 'jqueryui'; public array $events = []; @@ -46,9 +50,6 @@ public function __construct($instance = 'editor') /** * Make new Editor instance. - * - * @param array|string $instance - * @return static */ public static function make(array|string $instance = 'editor'): static { @@ -62,7 +63,6 @@ public static function make(array|string $instance = 'editor'): static /** * Append raw scripts. * - * @param string $scripts * @return $this */ public function scripts(string $scripts): static @@ -75,7 +75,6 @@ public function scripts(string $scripts): static /** * Set Editor's variable name / instance. * - * @param string $instance * @return $this */ public function instance(string $instance): static @@ -88,8 +87,8 @@ public function instance(string $instance): static /** * Set Editor's ajax parameter. * - * @param array|string $ajax * @return $this + * * @see https://editor.datatables.net/reference/option/ajax */ public function ajax(array|string $ajax): static @@ -102,8 +101,8 @@ public function ajax(array|string $ajax): static /** * Set Editor's table source. * - * @param string $table * @return $this + * * @see https://editor.datatables.net/reference/option/table */ public function table(string $table): static @@ -116,8 +115,8 @@ public function table(string $table): static /** * Set Editor's idSrc option. * - * @param string $idSrc * @return $this + * * @see https://editor.datatables.net/reference/option/idSrc */ public function idSrc(string $idSrc = 'DT_RowId'): static @@ -130,8 +129,8 @@ public function idSrc(string $idSrc = 'DT_RowId'): static /** * Set Editor's display option. * - * @param string $display * @return $this + * * @see https://editor.datatables.net/reference/option/display */ public function display(string $display): static @@ -144,8 +143,8 @@ public function display(string $display): static /** * Set Editor's fields. * - * @param array $fields * @return $this + * * @see https://editor.datatables.net/reference/option/fields */ public function fields(array $fields): static @@ -158,8 +157,8 @@ public function fields(array $fields): static /** * Set Editor's bubble formOptions. * - * @param array|FormOptions $formOptions * @return $this + * * @see https://editor.datatables.net/reference/option/formOptions.bubble */ public function formOptionsBubble(array|FormOptions $formOptions): static @@ -170,8 +169,8 @@ public function formOptionsBubble(array|FormOptions $formOptions): static /** * Set Editor's formOptions. * - * @param array $formOptions * @return $this + * * @see https://editor.datatables.net/reference/option/formOptions * @see https://editor.datatables.net/reference/type/form-options */ @@ -185,8 +184,8 @@ public function formOptions(array $formOptions): static /** * Set Editor's inline formOptions. * - * @param array|FormOptions $formOptions * @return $this + * * @see https://editor.datatables.net/reference/option/formOptions.inline */ public function formOptionsInline(array|FormOptions $formOptions): static @@ -197,8 +196,8 @@ public function formOptionsInline(array|FormOptions $formOptions): static /** * Set Editor's main formOptions. * - * @param array|FormOptions $formOptions * @return $this + * * @see https://editor.datatables.net/reference/option/formOptions.main */ public function formOptionsMain(array|FormOptions $formOptions): static @@ -209,8 +208,8 @@ public function formOptionsMain(array|FormOptions $formOptions): static /** * Set Editor's language. * - * @param array $language * @return $this + * * @see https://editor.datatables.net/reference/option/i18n */ public function language(array $language): static @@ -223,8 +222,8 @@ public function language(array $language): static /** * Set Editor's template. * - * @param string $template * @return $this + * * @see https://editor.datatables.net/reference/option/template */ public function template(string $template): static @@ -236,8 +235,6 @@ public function template(string $template): static /** * Convert the fluent instance to an array. - * - * @return array */ public function toArray(): array { @@ -262,7 +259,6 @@ public function toArray(): array * Convert the fluent instance to JSON. * * @param int $options - * @return string */ public function toJson($options = 0): string { @@ -276,7 +272,6 @@ public function toJson($options = 0): string /** * Hide fields on create action. * - * @param array $fields * @return $this */ public function hiddenOnCreate(array $fields): static @@ -287,8 +282,6 @@ public function hiddenOnCreate(array $fields): static /** * Hide fields on specific action. * - * @param string $action - * @param array $fields * @return $this */ public function hiddenOn(string $action, array $fields): static @@ -314,7 +307,6 @@ public function hiddenOn(string $action, array $fields): static /** * Hide fields on edit action. * - * @param array $fields * @return $this */ public function hiddenOnEdit(array $fields): static diff --git a/src/Html/Editor/Fields/BelongsTo.php b/src/Html/Editor/Fields/BelongsTo.php index 3177f34..e10c4e2 100644 --- a/src/Html/Editor/Fields/BelongsTo.php +++ b/src/Html/Editor/Fields/BelongsTo.php @@ -9,12 +9,8 @@ class BelongsTo extends Select { /** * @param class-string<\Illuminate\Database\Eloquent\Model>|Builder $class - * @param string $text - * @param string $id - * @param string|null $foreign - * @return static */ - public static function model(Builder|string $class, string $text, string $id = 'id', string $foreign = null): static + public static function model(Builder|string $class, string $text, string $id = 'id', ?string $foreign = null): static { if ($class instanceof Builder) { $table = $class->getModel()->getTable(); @@ -26,6 +22,6 @@ public static function model(Builder|string $class, string $text, string $id = ' $foreign = $foreign ?? $table.'_id'; return self::make($foreign, Str::title($table)) - ->modelOptions($class, $text, $id); + ->modelOptions($class, $text, $id); } } diff --git a/src/Html/Editor/Fields/Boolean.php b/src/Html/Editor/Fields/Boolean.php index 281b9ab..9259d24 100644 --- a/src/Html/Editor/Fields/Boolean.php +++ b/src/Html/Editor/Fields/Boolean.php @@ -6,10 +6,6 @@ class Boolean extends Checkbox { /** * Make a new instance of a field. - * - * @param array|string $name - * @param string $label - * @return static */ public static function make(array|string $name, string $label = ''): static { diff --git a/src/Html/Editor/Fields/Date.php b/src/Html/Editor/Fields/Date.php index 89fdf54..99f7e8f 100644 --- a/src/Html/Editor/Fields/Date.php +++ b/src/Html/Editor/Fields/Date.php @@ -6,10 +6,6 @@ class Date extends DateTime { /** * Make a new instance of a field. - * - * @param array|string $name - * @param string $label - * @return static */ public static function make(array|string $name, string $label = ''): static { diff --git a/src/Html/Editor/Fields/DateTime.php b/src/Html/Editor/Fields/DateTime.php index 990be77..de9824a 100644 --- a/src/Html/Editor/Fields/DateTime.php +++ b/src/Html/Editor/Fields/DateTime.php @@ -8,10 +8,6 @@ class DateTime extends Field /** * Make a new instance of a field. - * - * @param array|string $name - * @param string $label - * @return static */ public static function make(array|string $name, string $label = ''): static { @@ -29,9 +25,8 @@ public function military(): static } /** - * @param \DateTime $dateTime - * @param string $format * @return $this + * * @see https://editor.datatables.net/examples/dates/options-min-max.html */ public function minDate(\DateTime $dateTime, string $format = 'Y-m-d'): static @@ -40,9 +35,8 @@ public function minDate(\DateTime $dateTime, string $format = 'Y-m-d'): static } /** - * @param \DateTime $dateTime - * @param string $format * @return $this + * * @see https://editor.datatables.net/examples/dates/options-min-max.html */ public function maxDate(\DateTime $dateTime, string $format = 'Y-m-d'): static @@ -51,8 +45,8 @@ public function maxDate(\DateTime $dateTime, string $format = 'Y-m-d'): static } /** - * @param bool $state * @return $this + * * @see https://editor.datatables.net/examples/dates/options-week-numbers.html */ public function showWeekNumber(bool $state = true): static @@ -61,8 +55,8 @@ public function showWeekNumber(bool $state = true): static } /** - * @param array $days * @return $this + * * @see https://editor.datatables.net/examples/dates/options-disable-days.html */ public function disableDays(array $days): static @@ -71,8 +65,8 @@ public function disableDays(array $days): static } /** - * @param int $minutes * @return $this + * * @see https://editor.datatables.net/examples/dates/time-increment.html */ public function minutesIncrement(int $minutes): static @@ -81,8 +75,8 @@ public function minutesIncrement(int $minutes): static } /** - * @param int $seconds * @return $this + * * @see https://editor.datatables.net/examples/dates/time-increment.html */ public function secondsIncrement(int $seconds): static @@ -91,8 +85,8 @@ public function secondsIncrement(int $seconds): static } /** - * @param array $hours * @return $this + * * @see https://editor.datatables.net/examples/dates/datetime.html */ public function hoursAvailable(array $hours): static @@ -101,8 +95,8 @@ public function hoursAvailable(array $hours): static } /** - * @param array $minutes * @return $this + * * @see https://editor.datatables.net/examples/dates/datetime.html */ public function minutesAvailable(array $minutes): static @@ -115,8 +109,8 @@ public function minutesAvailable(array $minutes): static * value and also for sending to the server on form submission. * The formatting options are defined by Moment.js. * - * @param string $format * @return $this + * * @see https://editor.datatables.net/reference/field/datetime#Options * @see https://momentjs.com/docs/#/displaying/format/ */ @@ -134,8 +128,8 @@ public function wireFormat(string $format = 'YYYY-MM-DDTHH:mm:ss.000000Z'): stat * potentially making typing mistakes, although note that it does also disallow * pasting of data. * - * @param bool $state * @return $this + * * @see https://editor.datatables.net/reference/field/datetime#Options */ public function keyInput(bool $state = true): static @@ -152,8 +146,8 @@ public function keyInput(bool $state = true): static * throw an error stating that Moment.js must be included for custom * formatting to be used. * - * @param string $format * @return $this + * * @see https://editor.datatables.net/reference/field/datetime#Options * @see https://momentjs.com/docs/#/displaying/format/ */ diff --git a/src/Html/Editor/Fields/Field.php b/src/Html/Editor/Fields/Field.php index eb9c4b5..12ff437 100644 --- a/src/Html/Editor/Fields/Field.php +++ b/src/Html/Editor/Fields/Field.php @@ -21,8 +21,6 @@ class Field extends Fluent /** * Field type. - * - * @var string */ protected string $type = 'text'; @@ -40,10 +38,6 @@ public function __construct($attributes = []) /** * Make a new instance of a field. - * - * @param array|string $name - * @param string $label - * @return static */ public static function make(array|string $name, string $label = ''): static { @@ -60,8 +54,8 @@ public static function make(array|string $name, string $label = ''): static } /** - * @param string $label * @return $this + * * @see https://editor.datatables.net/reference/option/fields.label */ public function label(string $label): static @@ -72,8 +66,8 @@ public function label(string $label): static } /** - * @param string $name * @return $this + * * @see https://editor.datatables.net/reference/option/fields.name */ public function name(string $name): static @@ -84,8 +78,8 @@ public function name(string $name): static } /** - * @param string $data * @return $this + * * @see https://editor.datatables.net/reference/option/fields.data */ public function data(string $data): static @@ -96,8 +90,8 @@ public function data(string $data): static } /** - * @param string $type * @return $this + * * @see https://editor.datatables.net/reference/option/fields.type */ public function type(string $type): static @@ -112,8 +106,6 @@ public function type(string $type): static * Get options from a model. * * @param \Illuminate\Database\Eloquent\Builder|class-string<\Illuminate\Database\Eloquent\Model> $model - * @param string $value - * @param string $key * @return $this */ public function modelOptions(Builder|string $model, string $value, string $key = 'id'): static @@ -126,7 +118,6 @@ public function modelOptions(Builder|string $model, string $value, string $key = /** * Get options from a Enum::cases(). * - * @param array $cases * @return $this */ public function enumOptions(array $cases): static @@ -145,7 +136,6 @@ public function enumOptions(array $cases): static /** * Set select options. * - * @param array|Arrayable $options * @return $this */ public function options(array|Arrayable $options): static @@ -162,19 +152,14 @@ public function options(array|Arrayable $options): static /** * Get options from a table. * - * @param QueryBuilder|\Closure|string $table - * @param string $value - * @param string $key - * @param \Closure|null $whereCallback - * @param string|null $connection * @return $this */ public function tableOptions( QueryBuilder|Closure|string $table, string $value, string $key = 'id', - Closure $whereCallback = null, - string $connection = null + ?Closure $whereCallback = null, + ?string $connection = null ): static { return $this->options( Options::table($table, $value, $key, $whereCallback, $connection) @@ -184,7 +169,6 @@ public function tableOptions( /** * Set checkbox separator. * - * @param string $separator * @return $this */ public function separator(string $separator = ','): static @@ -197,8 +181,8 @@ public function separator(string $separator = ','): static /** * Set dateTime format. * - * @param string $format * @return $this + * * @see https://editor.datatables.net/reference/field/datetime */ public function format(string $format): static @@ -211,8 +195,8 @@ public function format(string $format): static /** * Set field default value. * - * @param float|bool|int|string|array $value * @return $this + * * @see https://editor.datatables.net/reference/option/fields.def */ public function default(float|bool|int|string|array $value): static @@ -225,8 +209,8 @@ public function default(float|bool|int|string|array $value): static /** * Set field message value. * - * @param string $value * @return $this + * * @see https://editor.datatables.net/reference/option/fields.message */ public function message(string $value): static @@ -239,8 +223,8 @@ public function message(string $value): static /** * Set field fieldInfo value. * - * @param string $value * @return $this + * * @see https://editor.datatables.net/reference/option/fields.fieldInfo */ public function fieldInfo(string $value): static @@ -253,8 +237,8 @@ public function fieldInfo(string $value): static /** * Set field labelInfo value. * - * @param string $value * @return $this + * * @see https://editor.datatables.net/reference/option/fields.labelInfo */ public function labelInfo(string $value): static @@ -267,8 +251,8 @@ public function labelInfo(string $value): static /** * Set field entityDecode value. * - * @param bool $value * @return $this + * * @see https://editor.datatables.net/reference/option/fields.entityDecode */ public function entityDecode(bool $value): static @@ -281,8 +265,8 @@ public function entityDecode(bool $value): static /** * Set field multiEditable value. * - * @param bool $value * @return $this + * * @see https://editor.datatables.net/reference/option/fields.multiEditable */ public function multiEditable(bool $value): static @@ -295,8 +279,8 @@ public function multiEditable(bool $value): static /** * Set field id value. * - * @param string $value * @return $this + * * @see https://editor.datatables.net/reference/option/fields.id */ public function id(string $value): static @@ -309,8 +293,8 @@ public function id(string $value): static /** * Set field submit value. * - * @param bool $value * @return $this + * * @see https://editor.datatables.net/reference/option/fields.submit */ public function submit(bool $value): static @@ -323,8 +307,8 @@ public function submit(bool $value): static /** * Set field compare value. * - * @param bool $value * @return $this + * * @see https://editor.datatables.net/reference/option/fields.compare */ public function compare(bool $value): static @@ -337,8 +321,8 @@ public function compare(bool $value): static /** * Set field opts value. * - * @param array $value * @return $this + * * @see https://datatables.net/forums/discussion/comment/156581/#Comment_156581 */ public function opts(array $value): static @@ -355,9 +339,8 @@ public function opts(array $value): static /** * Set field element html attributes. * - * @param string $attribute - * @param int|bool|string $value * @return $this + * * @see https://datatables.net/forums/discussion/comment/156581/#Comment_156581 */ public function attr(string $attribute, int|bool|string $value): static @@ -374,9 +357,6 @@ public function attr(string $attribute, int|bool|string $value): static return $this; } - /** - * @return string - */ public function getType(): string { return $this->type; @@ -385,8 +365,8 @@ public function getType(): string /** * Replace null values with the field's default on edit. * - * @param bool $value * @return $this + * * @see https://editor.datatables.net/reference/option/fields.nullDefault */ public function nullDefault(bool $value = true): static diff --git a/src/Html/Editor/Fields/File.php b/src/Html/Editor/Fields/File.php index 41df4a7..a10a8c6 100644 --- a/src/Html/Editor/Fields/File.php +++ b/src/Html/Editor/Fields/File.php @@ -13,16 +13,9 @@ class File extends Field /** * Editor instance variable name. - * - * @var string */ protected string $editor = 'editor'; - /** - * @param array|string $name - * @param string $label - * @return static - */ public static function make(array|string $name, string $label = ''): static { $field = parent::make($name, $label); @@ -31,7 +24,6 @@ public static function make(array|string $name, string $label = ''): static } /** - * @param string $value * @return $this */ public function ajax(string $value): static @@ -42,7 +34,6 @@ public function ajax(string $value): static } /** - * @param string $value * @return $this */ public function ajaxData(string $value): static @@ -53,7 +44,6 @@ public function ajaxData(string $value): static } /** - * @param bool $value * @return $this */ public function dragDrop(bool $value = true): static @@ -64,7 +54,6 @@ public function dragDrop(bool $value = true): static } /** - * @param string $value * @return $this */ public function dragDropText(string $value): static @@ -75,7 +64,6 @@ public function dragDropText(string $value): static } /** - * @param string $value * @return $this */ public function fileReadText(string $value): static @@ -86,7 +74,6 @@ public function fileReadText(string $value): static } /** - * @param string $value * @return $this */ public function noFileText(string $value): static @@ -97,7 +84,6 @@ public function noFileText(string $value): static } /** - * @param string $value * @return $this */ public function processingText(string $value): static @@ -108,7 +94,6 @@ public function processingText(string $value): static } /** - * @param string $value * @return $this */ public function uploadText(string $value): static @@ -121,7 +106,6 @@ public function uploadText(string $value): static /** * Set editor instance for file upload. * - * @param string $editor * @return $this */ public function editor(string $editor): static @@ -139,7 +123,7 @@ public function editor(string $editor): static public function displayImage(): static { // TODO: Use Laravel filesystem instead of hard coded storage path - return $this->display(<<'; + $expected = ''; $this->assertEquals($expected, $script); - $expected = '$(function(){window.LaravelDataTables=window.LaravelDataTables||{};window.LaravelDataTables["foo-table"]=$("#foo-table").DataTable({"serverSide":true,"processing":true,"ajax":"","columns":[{"data":"foo","name":"foo","title":"Foo","orderable":true,"searchable":true},{"data":"baz","name":"baz","title":"Baz","orderable":true,"searchable":true}]});});'; + $expected = 'document.addEventListener("DOMContentLoaded",function(){window.LaravelDataTables=window.LaravelDataTables||{};window.LaravelDataTables["foo-table"]=$("#foo-table").DataTable({"serverSide":true,"processing":true,"ajax":"","columns":[{"data":"foo","name":"foo","title":"Foo","orderable":true,"searchable":true},{"data":"baz","name":"baz","title":"Baz","orderable":true,"searchable":true}]});});'; $this->assertEquals($expected, $builder->generateScripts()->toHtml()); } From 1f495cfd4561e0b4fb71ae73eb07fa6f3c7d0782 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Mon, 28 Apr 2025 16:07:05 +0800 Subject: [PATCH 148/148] chore: release v12.0.2 :rocket: --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9986ed0..04d08aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ ### UNRELEASED +### v12.0.2 (2025-04-28) + +- fix: use DOMContentLoaded #237 +- fix: https://github.com/yajra/laravel-datatables-html/pull/235 + ### v12.0.1 (2025-03-31) - feat: select keyboard navigation and selection #236