From e9cb7627f48725498b26939f8488e9a30b9a5aa5 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Fri, 6 May 2022 14:58:03 +0800 Subject: [PATCH 001/260] Rename to ReadOnlyField --- src/Html/Editor/Fields/{ReadOnly.php => ReadOnlyField.php} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename src/Html/Editor/Fields/{ReadOnly.php => ReadOnlyField.php} (73%) diff --git a/src/Html/Editor/Fields/ReadOnly.php b/src/Html/Editor/Fields/ReadOnlyField.php similarity index 73% rename from src/Html/Editor/Fields/ReadOnly.php rename to src/Html/Editor/Fields/ReadOnlyField.php index d1b6f6e..8a15519 100644 --- a/src/Html/Editor/Fields/ReadOnly.php +++ b/src/Html/Editor/Fields/ReadOnlyField.php @@ -2,7 +2,7 @@ namespace Yajra\DataTables\Html\Editor\Fields; -class ReadOnly extends Field +class ReadOnlyField extends Field { protected $type = 'readonly'; } From 550274f59666b0ae58b269198743190d0faeab8d Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Fri, 6 May 2022 15:01:22 +0800 Subject: [PATCH 002/260] Add phpstan --- composer.json | 10 +++++----- phpstan.neon.dist | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 phpstan.neon.dist diff --git a/composer.json b/composer.json index 81f5b85..03b94dc 100644 --- a/composer.json +++ b/composer.json @@ -16,14 +16,14 @@ } ], "require": { - "php": "^7.1.3|^8", + "php": "^8.0.2", "ext-json": "*", - "yajra/laravel-datatables-oracle": "~9.0", - "laravelcollective/html": "^5.4|^6" + "yajra/laravel-datatables-oracle": "^10.0", + "laravelcollective/html": "^6.3.0" }, "require-dev": { - "mockery/mockery": "^1.3.1", - "phpunit/phpunit": "^9.3" + "nunomaduro/larastan": "^2.1", + "orchestra/testbench": "^7.3" }, "autoload": { "psr-4": { diff --git a/phpstan.neon.dist b/phpstan.neon.dist new file mode 100644 index 0000000..a61a97b --- /dev/null +++ b/phpstan.neon.dist @@ -0,0 +1,18 @@ +includes: + - ./vendor/nunomaduro/larastan/extension.neon + +parameters: + + paths: + - src + + level: max + + ignoreErrors: + - "#Cannot access offset '[a-zA-Z]+' on mixed.#" + + excludePaths: + + checkMissingIterableValueType: false + + checkGenericClassInNonGenericObjectType: false \ No newline at end of file From fbebe76ccdf5788fda59ced88541bdd0b7333e00 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Fri, 6 May 2022 15:03:05 +0800 Subject: [PATCH 003/260] Add phpstan workflow --- .../{tests.yml => continuous-integration.yml} | 8 ++-- .github/workflows/static-analysis.yml | 48 +++++++++++++++++++ 2 files changed, 52 insertions(+), 4 deletions(-) rename .github/workflows/{tests.yml => continuous-integration.yml} (90%) create mode 100644 .github/workflows/static-analysis.yml diff --git a/.github/workflows/tests.yml b/.github/workflows/continuous-integration.yml similarity index 90% rename from .github/workflows/tests.yml rename to .github/workflows/continuous-integration.yml index 85e883a..c58ccce 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/continuous-integration.yml @@ -1,4 +1,4 @@ -name: tests +name: "Continuous Integration" on: push: @@ -7,15 +7,15 @@ on: - cron: '0 0 * * *' jobs: - tests: + phpunit: runs-on: ubuntu-latest strategy: fail-fast: true matrix: - php: [7.3, 7.4, 8.0] - stability: [prefer-lowest, prefer-stable] + php: [8.0, 8.1] + stability: [prefer-stable] name: PHP ${{ matrix.php }} - ${{ matrix.stability }} diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml new file mode 100644 index 0000000..59f0a2c --- /dev/null +++ b/.github/workflows/static-analysis.yml @@ -0,0 +1,48 @@ +name: "Static Analysis" + +on: + push: + paths: + - .github/workflows/static-analysis.yml + - composer.* + - phpstan.neon.dist + - src/** + - tests/** + + pull_request: + paths: + - .github/workflows/static-analysis.yml + - composer.* + - phpstan.neon.dist + - src/** + - tests/** + + schedule: + - cron: '0 0 * * *' + +jobs: + static-analysis-phpstan: + name: "Static Analysis with PHPStan" + runs-on: ubuntu-latest + + strategy: + matrix: + php-version: + - "8.1" + + steps: + - name: "Checkout code" + uses: "actions/checkout@v2" + + - name: "Install PHP" + uses: "shivammathur/setup-php@v2" + with: + coverage: "none" + php-version: "${{ matrix.php-version }}" + tools: "cs2pr" + + - name: "Install dependencies with Composer" + uses: "ramsey/composer-install@v1" + + - name: "Run a static analysis with phpstan/phpstan" + run: "vendor/bin/phpstan --error-format=checkstyle | cs2pr" From 2df1f014c7b6180b16855d1e031aaa16095a16b8 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Fri, 6 May 2022 15:03:21 +0800 Subject: [PATCH 004/260] wip --- src/Html/Builder.php | 37 +------ src/Html/ColumnDefinition.php | 4 +- src/Html/Editor/Fields/BelongsTo.php | 42 ++------ src/Html/Editor/Fields/Options.php | 64 ++++++----- src/Html/Editor/Fields/Select.php | 12 +-- src/Html/Editor/Fields/Select2.php | 42 ++++---- src/Html/Options/HasColumns.php | 47 +++++---- src/Html/Options/HasData.php | 135 ++++++++++++++++-------- src/Html/Options/Plugins/Buttons.php | 8 +- src/Html/Options/Plugins/Responsive.php | 18 ++-- src/Html/Options/Plugins/Select.php | 42 ++++---- src/Html/Parameters.php | 8 +- src/Html/SearchPane.php | 127 +++++++++++----------- src/HtmlServiceProvider.php | 2 +- 14 files changed, 299 insertions(+), 289 deletions(-) diff --git a/src/Html/Builder.php b/src/Html/Builder.php index 8edd318..b5360e8 100644 --- a/src/Html/Builder.php +++ b/src/Html/Builder.php @@ -178,24 +178,6 @@ public function parameterize($attributes = []) return $json; } - /** - * Check if given key & value is a valid callback js function. - * - * @param string $value - * @param string $key - * @return bool - */ - protected function isCallbackFunction($value, $key) - { - if (empty($value)) { - return false; - } - - $callbacks = $this->config->get('datatables-html.callback', ['$', '$.', 'function']); - - return Str::startsWith(trim($value), $callbacks) || Str::contains($key, 'editor'); - } - /** * Get javascript template to use. * @@ -262,29 +244,12 @@ public function setTemplate($template) return $this; } - /** - * Make a data script to be appended on ajax request of dataTables. - * - * @param array $data - * @return string - */ - protected function makeDataScript(array $data) - { - $script = ''; - foreach ($data as $key => $value) { - $dataValue = $this->isCallbackFunction($value, $key) ? $value : "'{$value}'"; - $script .= PHP_EOL . "data.{$key} = {$dataValue};"; - } - - return $script; - } - /** * Generate scripts that sets the dataTables options into a variable. * * @return $this */ - public function asOptions() + public function asOptions(): static { return $this->setTemplate('datatables::options'); } diff --git a/src/Html/ColumnDefinition.php b/src/Html/ColumnDefinition.php index 4a4fba9..ccc5279 100644 --- a/src/Html/ColumnDefinition.php +++ b/src/Html/ColumnDefinition.php @@ -8,9 +8,9 @@ class ColumnDefinition extends Fluent { use HasOptions; - public function targets($value) + public function targets(array $value): self { - $this->attributes['targets'] = (array) $value; + $this->attributes['targets'] = $value; return $this; } diff --git a/src/Html/Editor/Fields/BelongsTo.php b/src/Html/Editor/Fields/BelongsTo.php index b09a29d..cb4c322 100644 --- a/src/Html/Editor/Fields/BelongsTo.php +++ b/src/Html/Editor/Fields/BelongsTo.php @@ -2,19 +2,19 @@ namespace Yajra\DataTables\Html\Editor\Fields; -use Illuminate\Support\Str; use Illuminate\Database\Eloquent\Builder; +use Illuminate\Support\Str; class BelongsTo extends Select { /** - * @param string|Builder $class - * @param string $text - * @param string $id - * @param string|null $foreign - * @return \Yajra\DataTables\Html\Editor\Fields\Field|static + * @param string|Builder $class + * @param string $text + * @param string $id + * @param string|null $foreign + * @return static */ - public static function model($class, $text, $id = 'id', $foreign = null) + public static function model(Builder|string $class, string $text, string $id = 'id', string $foreign = null): self { if ($class instanceof Builder) { $table = $class->getModel()->getTable(); @@ -22,34 +22,10 @@ public static function model($class, $text, $id = 'id', $foreign = null) $table = app($class)->getTable(); } - $table = Str::singular($table); - $foreign = $foreign ?? $table . '_id'; + $table = Str::singular($table); + $foreign = $foreign ?? $table.'_id'; return self::make($foreign, Str::title($table)) ->modelOptions($class, $text, $id); } - - /** - * Add a placeholder and allow clear. - * Note: This requires editor select2 plugin. - * - * @see https://editor.datatables.net/plug-ins/field-type/editor.select2 - * @param string $text - * @param null|string $id - * @param bool $allowClear - * @return $this - */ - public function placeholder($text, $id = null, $allowClear = true) - { - $this->type('select2') - ->opts([ - 'allowClear' => $allowClear, - 'placeholder' => [ - 'id' => $id, - 'text' => $text, - ], - ]); - - return $this; - } } diff --git a/src/Html/Editor/Fields/Options.php b/src/Html/Editor/Fields/Options.php index 97eafde..a7216f3 100644 --- a/src/Html/Editor/Fields/Options.php +++ b/src/Html/Editor/Fields/Options.php @@ -2,16 +2,25 @@ namespace Yajra\DataTables\Html\Editor\Fields; +use Closure; +use Illuminate\Database\Connection; use Illuminate\Database\Eloquent\Builder; +use Illuminate\Database\Eloquent\Builder as EloquentBuilder; +use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Query\Builder as QueryBuilder; use Illuminate\Support\Collection; use Illuminate\Support\Facades\DB; +/** + * @template TKey of array-key + * @template TValue + */ class Options extends Collection { /** * Return a Yes/No options. * - * @return Options + * @return static */ public static function yesNo() { @@ -26,12 +35,12 @@ public static function yesNo() /** * Get options from a model. * - * @param mixed $model - * @param string $value - * @param string $key + * @param \Illuminate\Database\Eloquent\Model|EloquentBuilder $model + * @param string $value + * @param string $key * @return Collection */ - public static function model($model, $value, $key = 'id') + public static function model(Model|EloquentBuilder $model, string $value, string $key = 'id'): Collection { if (! $model instanceof Builder) { $model = $model::query(); @@ -48,21 +57,26 @@ public static function model($model, $value, $key = 'id') /** * Get options from a table. * - * @param mixed $table - * @param string $value - * @param string $key - * @param \Closure $whereCallback - * @param string|null $key + * @param string|\Closure|\Illuminate\Database\Query\Builder $table + * @param string $value + * @param string $key + * @param \Closure|null $callback + * @param \Illuminate\Database\Connection|null $connection * @return Collection */ - public static function table($table, $value, $key = 'id', \Closure $whereCallback = null, $connection = null) - { + public static function table( + string|Closure|QueryBuilder $table, + string $value, + string $key = 'id', + Closure $callback = null, + ?Connection $connection = null + ): Collection { $query = DB::connection($connection) ->table($table) - ->select("{$value} as label", "{$key} as value"); + ->select("{$value} as label", "$key as value"); - if ($whereCallback) { - $query->where($whereCallback); + if (is_callable($callback)) { + $callback($query); } return $query->get(); @@ -71,9 +85,9 @@ public static function table($table, $value, $key = 'id', \Closure $whereCallbac /** * Return a True/False options. * - * @return Options + * @return static */ - public static function trueFalse() + public static function trueFalse(): self { $data = [ ['label' => __('True'), 'value' => 1], @@ -86,11 +100,11 @@ public static function trueFalse() /** * Push an item onto the end of the collection. * - * @param mixed $value - * @param mixed $key - * @return Options + * @param string $value + * @param string $key + * @return static */ - public function append($value, $key) + public function append(string $value, string $key): self { return $this->push(['label' => $value, 'value' => $key]); } @@ -98,11 +112,11 @@ public function append($value, $key) /** * Push an item onto the beginning of the collection. * - * @param mixed $value - * @param mixed $key - * @return \Illuminate\Support\Collection + * @param TValue $value + * @param TKey $key + * @return static */ - public function prepend($value, $key = null) + public function prepend($value, $key = null): self { $data = ['label' => $value, 'value' => $key]; diff --git a/src/Html/Editor/Fields/Select.php b/src/Html/Editor/Fields/Select.php index 26f940d..510565d 100644 --- a/src/Html/Editor/Fields/Select.php +++ b/src/Html/Editor/Fields/Select.php @@ -15,7 +15,7 @@ class Select extends Field * @param bool $value * @return $this */ - public function multiple(bool $value = true) + public function multiple(bool $value = true): self { $this->attributes['multiple'] = $value; @@ -25,11 +25,11 @@ public function multiple(bool $value = true) /** * Set field optionsPair value. * - * @param string|array $label + * @param array|string $label * @param string $value * @return $this */ - public function optionsPair($label = 'label', $value = 'value') + public function optionsPair(array|string $label = 'label', string $value = 'value'): self { if (is_array($label)) { $this->attributes['optionsPair'] = $label; @@ -47,7 +47,7 @@ public function optionsPair($label = 'label', $value = 'value') * @param string $value * @return $this */ - public function placeholder($value) + public function placeholder(string $value): self { $this->attributes['placeholder'] = $value; @@ -60,7 +60,7 @@ public function placeholder($value) * @param bool $value * @return $this */ - public function placeholderDisabled(bool $value) + public function placeholderDisabled(bool $value): self { $this->attributes['placeholderDisabled'] = $value; @@ -73,7 +73,7 @@ public function placeholderDisabled(bool $value) * @param string $value * @return $this */ - public function placeholderValue($value) + public function placeholderValue(string $value): self { $this->attributes['placeholderValue'] = $value; diff --git a/src/Html/Editor/Fields/Select2.php b/src/Html/Editor/Fields/Select2.php index 4d28b12..cc1b2ee 100644 --- a/src/Html/Editor/Fields/Select2.php +++ b/src/Html/Editor/Fields/Select2.php @@ -10,10 +10,10 @@ class Select2 extends Select protected $type = 'select2'; /** - * @param bool $state + * @param bool $state * @return $this */ - public function allowClear($state = true) + public function allowClear(bool $state = true): self { $this->attributes['opts']['allowClear'] = $state; @@ -21,15 +21,15 @@ public function allowClear($state = true) } /** - * @param string $text - * @param string|null $id + * @param string $value + * @param string $id * @return $this */ - public function placeholder($text = '', $id = null) + public function optsPlaceholder(string $value = '', string $id = 'id'): self { $this->attributes['opts']['placeholder'] = [ - 'id' => $id, - 'text' => $text, + 'id' => $id, + 'text' => $value, ]; return $this; @@ -38,10 +38,10 @@ public function placeholder($text = '', $id = null) /** * Set select2 ajax option. * - * @param mixed $value + * @param array|string $value * @return $this */ - public function ajax($value) + public function ajax(array|string $value): self { if (is_array($value)) { $this->attributes['opts']['ajax'] = $value; @@ -55,10 +55,10 @@ public function ajax($value) /** * Set select2 ajax url option. * - * @param mixed $value + * @param string $value * @return $this */ - public function ajaxUrl($value) + public function ajaxUrl(string $value): self { $this->attributes['opts']['ajax']['url'] = $value; @@ -68,10 +68,10 @@ public function ajaxUrl($value) /** * Set select2 ajaxDelay option. * - * @param mixed $value + * @param int $value * @return $this */ - public function ajaxDelay($value = 250) + public function ajaxDelay(int $value = 250): self { $this->attributes['opts']['ajax']['delay'] = $value; @@ -81,15 +81,15 @@ public function ajaxDelay($value = 250) /** * Set select2 ajax data option. * - * @param mixed $data + * @param array|string $data * @return $this */ - public function ajaxData($data) + public function ajaxData(array|string $data): self { if (is_array($data)) { $script = 'function(params) {'; foreach ($data as $key => $value) { - $value = json_encode($value); + $value = json_encode($value); $script .= " params.{$key} = {$value}; "; } $script .= 'return params; }'; @@ -105,11 +105,11 @@ public function ajaxData($data) /** * Set select2 ajax processResults option to process a paginated results. * - * @param string $display - * @param string $id + * @param string $display + * @param string $id * @return $this */ - public function processPaginatedResults($display = 'text', $id = 'id') + public function processPaginatedResults(string $display = 'text', string $id = 'id'): self { $script = 'function(data, params) { '; $script .= 'params.page = params.page || 1; '; @@ -123,10 +123,10 @@ public function processPaginatedResults($display = 'text', $id = 'id') /** * Set select2 ajax processResults option. * - * @param string $value + * @param string $value * @return $this */ - public function processResults($value) + public function processResults(string $value): self { $this->attributes['opts']['ajax']['processResults'] = $value; diff --git a/src/Html/Options/HasColumns.php b/src/Html/Options/HasColumns.php index f477a90..1bf5308 100644 --- a/src/Html/Options/HasColumns.php +++ b/src/Html/Options/HasColumns.php @@ -2,14 +2,15 @@ namespace Yajra\DataTables\Html\Options; +use Illuminate\Contracts\Support\Arrayable; use Illuminate\Support\Collection; use Illuminate\Support\Str; use Yajra\DataTables\Html\Column; -use Illuminate\Contracts\Support\Arrayable; /** * DataTables - Columns option builder. * + * @property Collection $collection * @see https://datatables.net/reference/option/ */ trait HasColumns @@ -17,11 +18,11 @@ trait HasColumns /** * Set columnDefs option value. * - * @param mixed $value + * @param mixed $value * @return $this * @see https://datatables.net/reference/option/columnDefs */ - public function columnDefs($value) + public function columnDefs(mixed $value): static { if (is_callable($value)) { $value = app()->call($value); @@ -39,11 +40,11 @@ public function columnDefs($value) /** * Add a columnDef option. * - * @param mixed $value + * @param mixed $value * @return $this * @see https://datatables.net/reference/option/columnDefs */ - public function addColumnDef($value) + public function addColumnDef(mixed $value): static { if (is_callable($value)) { $value = app()->call($value); @@ -61,11 +62,11 @@ public function addColumnDef($value) /** * Set columns option value. * - * @param array $columns + * @param array $columns * @return $this * @see https://datatables.net/reference/option/columns */ - public function columns(array $columns) + public function columns(array $columns): static { $this->collection = new Collection; @@ -99,11 +100,11 @@ public function columns(array $columns) /** * Set title attribute of an array if not set. * - * @param string $title - * @param array $attributes + * @param string $title + * @param array $attributes * @return array */ - public function setTitle($title, array $attributes) + public function setTitle(string $title, array $attributes): array { if (! isset($attributes['title'])) { $attributes['title'] = $this->getQualifiedTitle($title); @@ -115,10 +116,10 @@ public function setTitle($title, array $attributes) /** * Convert string into a readable title. * - * @param string $title + * @param string $title * @return string */ - public function getQualifiedTitle($title) + public function getQualifiedTitle(string $title): string { return Str::title(str_replace(['.', '_'], ' ', Str::snake($title))); } @@ -126,10 +127,10 @@ public function getQualifiedTitle($title) /** * Add a column in collection usingsl attributes. * - * @param array $attributes + * @param array $attributes * @return $this */ - public function addColumn(array $attributes) + public function addColumn(array $attributes): static { $this->collection->push(new Column($attributes)); @@ -139,10 +140,10 @@ public function addColumn(array $attributes) /** * Add a Column object at the beginning of collection. * - * @param \Yajra\DataTables\Html\Column $column + * @param \Yajra\DataTables\Html\Column $column * @return $this */ - public function addBefore(Column $column) + public function addBefore(Column $column): static { $this->collection->prepend($column); @@ -152,10 +153,10 @@ public function addBefore(Column $column) /** * Add a column at the beginning of collection using attributes. * - * @param array $attributes + * @param array $attributes * @return $this */ - public function addColumnBefore(array $attributes) + public function addColumnBefore(array $attributes): static { $this->collection->prepend(new Column($attributes)); @@ -165,10 +166,10 @@ public function addColumnBefore(array $attributes) /** * Add a Column object in collection. * - * @param \Yajra\DataTables\Html\Column $column + * @param \Yajra\DataTables\Html\Column $column * @return $this */ - public function add(Column $column) + public function add(Column $column): static { $this->collection->push($column); @@ -180,7 +181,7 @@ public function add(Column $column) * * @return \Illuminate\Support\Collection */ - public function getColumns() + public function getColumns(): Collection { return $this->collection; } @@ -188,10 +189,10 @@ public function getColumns() /** * Remove column by name. * - * @param array $names + * @param array $names * @return $this */ - public function removeColumn(...$names) + public function removeColumn(...$names): static { foreach ($names as $name) { $this->collection = $this->collection->filter(function (Column $column) use ($name) { diff --git a/src/Html/Options/HasData.php b/src/Html/Options/HasData.php index 21e750b..6333361 100644 --- a/src/Html/Options/HasData.php +++ b/src/Html/Options/HasData.php @@ -3,10 +3,14 @@ namespace Yajra\DataTables\Html\Options; use Illuminate\Support\Arr; +use Illuminate\Support\Str; +use Yajra\DataTables\Exceptions\Exception; /** * DataTables - Data option builder. * + * @property \Illuminate\Contracts\Config\Repository $config + * * @see https://datatables.net/reference/option/ */ trait HasData @@ -14,28 +18,15 @@ trait HasData /** * @var string|array */ - protected $ajax = ''; - - /** - * Setup ajax parameter. - * - * @param string|array $attributes - * @return $this - */ - public function ajax($attributes = '') - { - $this->ajax = $attributes; - - return $this; - } + protected string|array $ajax = ''; /** * Setup "ajax" parameter with POST method. * - * @param string|array $attributes + * @param array|string $attributes * @return $this */ - public function postAjax($attributes = '') + public function postAjax(array|string $attributes = ''): static { if (! is_array($attributes)) { $attributes = ['url' => (string) $attributes]; @@ -48,38 +39,88 @@ public function postAjax($attributes = '') return $this->ajax($attributes); } + /** + * Setup ajax parameter. + * + * @param array|string $attributes + * @return $this + */ + public function ajax(array|string $attributes = ''): static + { + $this->ajax = $attributes; + + return $this; + } + /** * Setup ajax parameter for datatables pipeline plugin. * - * @param string $url - * @param string $pages + * @param string $url + * @param string $pages * @return $this */ - public function pipeline($url, $pages) + public function pipeline(string $url, string $pages): static { $this->ajax = "$.fn.dataTable.pipeline({ url: '{$url}', pages: {$pages} })"; return $this; } + /** + * Get ajax url. + * + * @return string + */ + public function getAjaxUrl(): string + { + if (is_array($this->ajax)) { + return $this->ajax['url'] ?: url()->current(); + } + + return $this->ajax ?: url()->current(); + } + + /** + * Set ajax url with data added from form. + * + * @param string $url + * @param string $formSelector + * @return $this + */ + public function ajaxWithForm(string $url, string $formSelector): static + { + $script = <<minifiedAjax($url, $script); + } + /** * Minify ajax url generated when using get request * by deleting unnecessary url params. * - * @param string $url - * @param string $script - * @param array $data - * @param array $ajaxParameters + * @param string $url + * @param string|null $script + * @param array $data + * @param array $ajaxParameters * @return $this */ - public function minifiedAjax($url = '', $script = null, $data = [], $ajaxParameters = []) - { + public function minifiedAjax( + string $url = '', + string $script = null, + array $data = [], + array $ajaxParameters = [] + ): static { $this->ajax = []; $appendData = $this->makeDataScript($data); $this->ajax['url'] = empty($url) ? url()->full() : $url; $this->ajax['type'] = 'GET'; - if (isset($this->attributes['serverSide']) ? $this->attributes['serverSide'] : true) { + if (! isset($this->attributes['serverSide']) || $this->attributes['serverSide']) { $this->ajax['data'] = 'function(data) { for (var i = 0, len = data.columns.length; i < len; i++) { if (!data.columns[i].search.value) delete data.columns[i].search; @@ -108,35 +149,41 @@ public function minifiedAjax($url = '', $script = null, $data = [], $ajaxParamet } /** - * Get ajax url. + * Make a data script to be appended on ajax request of dataTables. * - * @return array|mixed|string + * @param array $data + * @return string */ - public function getAjaxUrl() + protected function makeDataScript(array $data): string { - if (is_array($this->ajax)) { - return $this->ajax['url'] ?: url()->current(); + $script = ''; + foreach ($data as $key => $value) { + $dataValue = $this->isCallbackFunction($value, $key) ? $value : "'{$value}'"; + $script .= PHP_EOL."data.{$key} = {$dataValue};"; } - return $this->ajax ?: url()->current(); + return $script; } /** - * Set ajax url with data added from form. + * Check if given key & value is a valid callback js function. * - * @param string $url - * @param string $formSelector - * @return $this + * @param string $value + * @param string $key + * @return bool */ - public function ajaxWithForm($url, $formSelector) + protected function isCallbackFunction(string $value, string $key): bool { - $script = <<minifiedAjax($url, $script); + $callbacks = $this->config->get('datatables-html.callback', ['$', '$.', 'function']); + + if (! is_array($callbacks)) { + return false; + } + + return Str::startsWith(trim($value), $callbacks) || Str::contains($key, 'editor'); } } diff --git a/src/Html/Options/Plugins/Buttons.php b/src/Html/Options/Plugins/Buttons.php index fbced7c..f35f749 100644 --- a/src/Html/Options/Plugins/Buttons.php +++ b/src/Html/Options/Plugins/Buttons.php @@ -7,6 +7,10 @@ /** * DataTables - Buttons plugin option builder. * + * @template TKey of array-key + * @template TValue + * @property array $attributes + * * @see https://datatables.net/extensions/buttons/ * @see https://datatables.net/reference/option/buttons */ @@ -15,11 +19,11 @@ trait Buttons /** * Attach multiple buttons to builder. * - * @param array|mixed ...$buttons + * @param array|mixed ...$buttons * @return $this * @see https://www.datatables.net/extensions/buttons/ */ - public function buttons(...$buttons) + public function buttons(...$buttons): static { if (is_array($buttons[0])) { $buttons = $buttons[0]; diff --git a/src/Html/Options/Plugins/Responsive.php b/src/Html/Options/Plugins/Responsive.php index afd678d..844e776 100644 --- a/src/Html/Options/Plugins/Responsive.php +++ b/src/Html/Options/Plugins/Responsive.php @@ -14,11 +14,11 @@ trait Responsive /** * Set responsive option value. * - * @param bool|array $value + * @param bool|array $value * @return $this * @see https://datatables.net/reference/option/responsive */ - public function responsive($value = true) + public function responsive(bool|array $value = true): static { $this->attributes['responsive'] = $value; @@ -32,7 +32,7 @@ public function responsive($value = true) * @return $this * @see https://datatables.net/reference/option/responsive.breakpoints */ - public function responsiveBreakpoints($value) + public function responsiveBreakpoints(mixed $value): static { $this->attributes['responsive']['breakpoints'] = $value; @@ -46,7 +46,7 @@ public function responsiveBreakpoints($value) * @return $this * @see https://datatables.net/reference/option/responsive.details */ - public function responsiveDetails($value) + public function responsiveDetails(mixed $value): static { $this->attributes['responsive']['details'] = $value; @@ -60,7 +60,7 @@ public function responsiveDetails($value) * @return $this * @see https://datatables.net/reference/option/responsive.details.display */ - public function responsiveDetailsDisplay($value) + public function responsiveDetailsDisplay(mixed $value): static { $this->attributes['responsive']['details']['display'] = $value; @@ -74,7 +74,7 @@ public function responsiveDetailsDisplay($value) * @return $this * @see https://datatables.net/reference/option/responsive.details.renderer */ - public function responsiveDetailsRenderer($value) + public function responsiveDetailsRenderer(mixed $value): static { $this->attributes['responsive']['details']['renderer'] = $value; @@ -88,7 +88,7 @@ public function responsiveDetailsRenderer($value) * @return $this * @see https://datatables.net/reference/option/responsive.details.target */ - public function responsiveDetailsTarget($value) + public function responsiveDetailsTarget(mixed $value): static { $this->attributes['responsive']['details']['target'] = $value; @@ -102,7 +102,7 @@ public function responsiveDetailsTarget($value) * @return $this * @see https://datatables.net/reference/option/responsive.details.type */ - public function responsiveDetailsType($value) + public function responsiveDetailsType(mixed $value): static { $this->attributes['responsive']['details']['type'] = $value; @@ -116,7 +116,7 @@ public function responsiveDetailsType($value) * @return $this * @see https://datatables.net/reference/option/responsive.orthogonal */ - public function responsiveOrthogonal($value) + public function responsiveOrthogonal(mixed $value): static { $this->attributes['responsive']['orthogonal'] = $value; diff --git a/src/Html/Options/Plugins/Select.php b/src/Html/Options/Plugins/Select.php index ac971c8..3010b2c 100644 --- a/src/Html/Options/Plugins/Select.php +++ b/src/Html/Options/Plugins/Select.php @@ -15,11 +15,11 @@ trait Select /** * Set select option value. * - * @param bool|array $value + * @param bool|array $value * @return $this * @see https://datatables.net/reference/option/select */ - public function select($value = true) + public function select(bool|array $value = true): static { $this->attributes['select'] = $value; @@ -33,7 +33,7 @@ public function select($value = true) * @return $this * @see https://datatables.net/reference/option/select.blurable */ - public function selectBlurable(bool $value = true) + public function selectBlurable(bool $value = true): static { $this->attributes['select']['blurable'] = $value; @@ -43,11 +43,11 @@ public function selectBlurable(bool $value = true) /** * Set select className option value. * - * @param string $value + * @param string $value * @return $this * @see https://datatables.net/reference/option/select.className */ - public function selectClassName($value = 'selected') + public function selectClassName(string $value = 'selected'): static { $this->attributes['select']['className'] = $value; @@ -60,7 +60,7 @@ public function selectClassName($value = 'selected') * @param string $class * @return $this */ - public function selectAddClassName($class) + public function selectAddClassName($class): static { if (! isset($this->attributes['select']['className'])) { $this->attributes['select']['className'] = $class; @@ -77,7 +77,7 @@ public function selectAddClassName($class) * @return $this * @see https://datatables.net/reference/option/select.info */ - public function selectInfo(bool $value = true) + public function selectInfo(bool $value = true): static { $this->attributes['select']['info'] = $value; @@ -87,11 +87,11 @@ public function selectInfo(bool $value = true) /** * Set select items option value. * - * @param string $value + * @param string $value * @return $this * @see https://datatables.net/reference/option/select.items */ - public function selectItems($value = 'row') + public function selectItems(string $value = 'row'): static { $this->attributes['select']['items'] = $value; @@ -104,7 +104,7 @@ public function selectItems($value = 'row') * @return $this * @see https://datatables.net/reference/option/select.items */ - public function selectItemsRow() + public function selectItemsRow(): static { $this->attributes['select']['items'] = Builder::SELECT_ITEMS_ROW; @@ -117,7 +117,7 @@ public function selectItemsRow() * @return $this * @see https://datatables.net/reference/option/select.items */ - public function selectItemsColumn() + public function selectItemsColumn(): static { $this->attributes['select']['items'] = Builder::SELECT_ITEMS_COLUMN; @@ -130,7 +130,7 @@ public function selectItemsColumn() * @return $this * @see https://datatables.net/reference/option/select.items */ - public function selectItemsCell() + public function selectItemsCell(): static { $this->attributes['select']['items'] = Builder::SELECT_ITEMS_CELL; @@ -140,11 +140,11 @@ public function selectItemsCell() /** * Set select selector option value. * - * @param string $value + * @param string $value * @return $this * @see https://datatables.net/reference/option/select.selector */ - public function selectSelector($value = 'td') + public function selectSelector(string $value = 'td'): static { $this->attributes['select']['selector'] = $value; @@ -154,11 +154,11 @@ public function selectSelector($value = 'td') /** * Set select style option value. * - * @param string $value + * @param string $value * @return $this * @see https://datatables.net/reference/option/select.style */ - public function selectStyle($value = 'os') + public function selectStyle(string $value = 'os'): static { $this->attributes['select']['style'] = $value; @@ -171,7 +171,7 @@ public function selectStyle($value = 'os') * @return $this * @see https://datatables.net/reference/option/select.style */ - public function selectStyleApi() + public function selectStyleApi(): static { $this->attributes['select']['style'] = Builder::SELECT_STYLE_API; @@ -184,7 +184,7 @@ public function selectStyleApi() * @return $this * @see https://datatables.net/reference/option/select.style */ - public function selectStyleSingle() + public function selectStyleSingle(): static { $this->attributes['select']['style'] = Builder::SELECT_STYLE_SINGLE; @@ -197,7 +197,7 @@ public function selectStyleSingle() * @return $this * @see https://datatables.net/reference/option/select.style */ - public function selectStyleMulti() + public function selectStyleMulti(): static { $this->attributes['select']['style'] = Builder::SELECT_STYLE_MULTI; @@ -210,7 +210,7 @@ public function selectStyleMulti() * @return $this * @see https://datatables.net/reference/option/select.style */ - public function selectStyleOS() + public function selectStyleOS(): static { $this->attributes['select']['style'] = Builder::SELECT_STYLE_OS; @@ -223,7 +223,7 @@ public function selectStyleOS() * @return $this * @see https://datatables.net/reference/option/select.style */ - public function selectStyleMultiShift() + public function selectStyleMultiShift(): static { $this->attributes['select']['style'] = Builder::SELECT_STYLE_MULTI_SHIFT; diff --git a/src/Html/Parameters.php b/src/Html/Parameters.php index ca93fba..7b6b0c4 100644 --- a/src/Html/Parameters.php +++ b/src/Html/Parameters.php @@ -4,16 +4,10 @@ use Illuminate\Support\Fluent; -/** - * @property bool serverSide - * @property bool processing - * @property mixed ajax - * @property array columns - */ class Parameters extends Fluent { /** - * @var array + * @var array */ protected $attributes = [ 'serverSide' => true, diff --git a/src/Html/SearchPane.php b/src/Html/SearchPane.php index 7b2a0bc..f5fac94 100644 --- a/src/Html/SearchPane.php +++ b/src/Html/SearchPane.php @@ -2,27 +2,31 @@ namespace Yajra\DataTables\Html; -use Illuminate\Support\Fluent; +use Closure; use Illuminate\Contracts\Support\Arrayable; +use Illuminate\Database\Connection; +use Illuminate\Database\Eloquent\Builder as EloquentBuilder; +use Illuminate\Database\Eloquent\Model; +use Illuminate\Support\Fluent; use Yajra\DataTables\Html\Editor\Fields\Options; -class SearchPane extends Fluent +final class SearchPane extends Fluent { /** - * @param array $options + * @param array $options * @return static */ - public static function make(array $options = []) + public static function make(array $options = []): self { - return new static($options); + return new self($options); } /** - * @param bool $value + * @param bool $value * @return static * @see https://datatables.net/reference/option/searchPanes.cascadePanes */ - public function cascadePanes($value = true) + public function cascadePanes(bool $value = true): self { $this->attributes['cascadePanes'] = $value; @@ -30,11 +34,11 @@ public function cascadePanes($value = true) } /** - * @param bool $value + * @param bool $value * @return static * @see https://datatables.net/reference/option/searchPanes.clear */ - public function clear($value = true) + public function clear(bool $value = true): self { $this->attributes['clear'] = $value; @@ -42,11 +46,11 @@ public function clear($value = true) } /** - * @param array $value + * @param array $value * @return static * @see https://datatables.net/reference/option/searchPanes.columns */ - public function columns(array $value = []) + public function columns(array $value = []): self { $this->attributes['columns'] = $value; @@ -54,11 +58,11 @@ public function columns(array $value = []) } /** - * @param bool $value + * @param bool $value * @return static * @see https://datatables.net/reference/option/searchPanes.controls */ - public function controls($value = true) + public function controls(bool $value = true): self { $this->attributes['controls'] = $value; @@ -66,12 +70,12 @@ public function controls($value = true) } /** - * @param array $value + * @param array $value * @return static * @see https://datatables.net/reference/option/searchPanes.dtOpts * @see https://datatables.net/reference/option/columns.searchPanes.dtOpts */ - public function dtOpts(array $value = []) + public function dtOpts(array $value = []): self { $this->attributes['dtOpts'] = $value; @@ -79,11 +83,11 @@ public function dtOpts(array $value = []) } /** - * @param mixed $value + * @param string $value * @return static * @see https://datatables.net/reference/option/searchPanes.emptyMessage */ - public function emptyMessage($value) + public function emptyMessage(string $value): self { $this->attributes['emptyMessage'] = $value; @@ -91,11 +95,11 @@ public function emptyMessage($value) } /** - * @param mixed $value + * @param string $value * @return static * @see https://datatables.net/reference/option/searchPanes.filterChanged */ - public function filterChanged($value) + public function filterChanged(string $value): self { $this->attributes['filterChanged'] = $value; @@ -103,11 +107,11 @@ public function filterChanged($value) } /** - * @param bool $value + * @param bool $value * @return static * @see https://datatables.net/reference/option/searchPanes.hideCount */ - public function hideCount($value = true) + public function hideCount(bool $value = true): self { $this->attributes['hideCount'] = $value; @@ -115,11 +119,11 @@ public function hideCount($value = true) } /** - * @param mixed $value + * @param string $value * @return static * @see https://datatables.net/reference/option/searchPanes.layout */ - public function layout($value) + public function layout(string $value): self { $this->attributes['layout'] = $value; @@ -127,11 +131,11 @@ public function layout($value) } /** - * @param mixed $value + * @param array $value * @return static * @see https://datatables.net/reference/option/searchPanes.order */ - public function order($value) + public function order(array $value): self { $this->attributes['order'] = $value; @@ -139,11 +143,11 @@ public function order($value) } /** - * @param boolean $value + * @param boolean $value * @return static * @see https://datatables.net/reference/option/searchPanes.orderable */ - public function orderable($value = true) + public function orderable(bool $value = true): self { $this->attributes['orderable'] = $value; @@ -151,11 +155,11 @@ public function orderable($value = true) } /** - * @param array $value + * @param array $value * @return static * @see https://datatables.net/reference/option/searchPanes.panes */ - public function panes(array $value) + public function panes(array $value): self { $panes = collect($value)->map(function ($pane) { if ($pane instanceof Arrayable) { @@ -171,11 +175,11 @@ public function panes(array $value) } /** - * @param mixed $value + * @param float $value * @return static * @see https://datatables.net/reference/option/searchPanes.threshold */ - public function threshold($value) + public function threshold(float $value): static { $this->attributes['threshold'] = $value; @@ -183,11 +187,11 @@ public function threshold($value) } /** - * @param boolean $value + * @param boolean $value * @return static * @see https://datatables.net/reference/option/searchPanes.viewTotal */ - public function viewTotal($value = true) + public function viewTotal(bool $value = true): self { $this->attributes['viewTotal'] = $value; @@ -195,11 +199,11 @@ public function viewTotal($value = true) } /** - * @param boolean $value + * @param boolean $value * @return static * @see https://datatables.net/reference/option/searchPanes.viewTotal */ - public function hideTotal($value = true) + public function hideTotal(bool $value = true): self { $this->attributes['viewTotal'] = ! $value; @@ -209,12 +213,12 @@ public function hideTotal($value = true) /** * Get options from a model. * - * @param mixed $model - * @param string $value - * @param string $key + * @param \Illuminate\Database\Eloquent\Model|EloquentBuilder $model + * @param string $value + * @param string $key * @return $this */ - public function modelOptions($model, $value, $key = 'id') + public function modelOptions(Model|EloquentBuilder $model, string $value, string $key = 'id'): self { return $this->options( Options::model($model, $value, $key) @@ -222,7 +226,7 @@ public function modelOptions($model, $value, $key = 'id') } /** - * @param mixed $value + * @param mixed $value * @return static * @see https://datatables.net/reference/option/columns.searchPanes.options */ @@ -240,26 +244,31 @@ public function options($value) /** * Get options from a table. * - * @param mixed $table - * @param string $value - * @param string $key - * @param \Closure $whereCallback - * @param string|null $key - * @return $this + * @param string $table + * @param string $value + * @param string $key + * @param \Closure|null $callback + * @param \Illuminate\Database\Connection|null $connection + * @return static */ - public function tableOptions($table, $value, $key = 'id', \Closure $whereCallback = null, $connection = null) - { + public function tableOptions( + string $table, + string $value, + string $key = 'id', + Closure $callback = null, + ?Connection $connection = null + ): self { return $this->options( - Options::table($table, $value, $key, $whereCallback, $connection) + Options::table($table, $value, $key, $callback, $connection) ); } /** - * @param mixed $value + * @param string $value * @return static * @see https://datatables.net/reference/option/columns.searchPanes.className */ - public function className($value) + public function className(string $value): self { $this->attributes['className'] = $value; @@ -267,11 +276,11 @@ public function className($value) } /** - * @param mixed $value + * @param string $value * @return static * @see https://datatables.net/reference/option/searchPanes.panes.header */ - public function header($value) + public function header(string $value): self { $this->attributes['header'] = $value; @@ -279,11 +288,11 @@ public function header($value) } /** - * @param bool $value + * @param bool $value * @return static * @see https://datatables.net/reference/option/columns.searchPanes.show */ - public function show($value = true) + public function show(bool $value = true): self { $this->attributes['show'] = $value; @@ -291,11 +300,11 @@ public function show($value = true) } /** - * @param mixed $value + * @param string $value * @return static * @see https://datatables.net/reference/option/columns.searchPanes.name */ - public function name($value) + public function name(string $value): self { $this->attributes['name'] = $value; @@ -303,11 +312,11 @@ public function name($value) } /** - * @param mixed $value + * @param array|string $value * @return static * @see https://datatables.net/reference/option/columns.searchPanes.orthogonal */ - public function orthogonal($value) + public function orthogonal(array|string $value): self { $this->attributes['orthogonal'] = $value; diff --git a/src/HtmlServiceProvider.php b/src/HtmlServiceProvider.php index 343278b..affb23c 100644 --- a/src/HtmlServiceProvider.php +++ b/src/HtmlServiceProvider.php @@ -24,7 +24,7 @@ public function boot() /** * Publish datatables assets. */ - protected function publishAssets() + protected function publishAssets(): void { $this->publishes([ __DIR__ . '/resources/views' => base_path('/resources/views/vendor/datatables'), From f332472f779d26bdc704a142fa5963b9deb44a63 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Fri, 6 May 2022 16:18:45 +0800 Subject: [PATCH 005/260] wip --- phpstan.neon.dist | 2 +- src/Html/Column.php | 140 ++++++++++++------------ src/Html/Options/HasCallbacks.php | 2 +- src/Html/Options/HasColumns.php | 5 +- src/Html/Options/Languages/Aria.php | 56 ++++------ src/Html/Options/Languages/AutoFill.php | 62 ++++------- src/Html/Options/Languages/Paginate.php | 38 +++---- src/Html/Options/Languages/Select.php | 32 ++---- src/Html/Options/Plugins/Responsive.php | 42 +++---- src/Html/SearchPane.php | 92 ++++++++-------- 10 files changed, 204 insertions(+), 267 deletions(-) diff --git a/phpstan.neon.dist b/phpstan.neon.dist index a61a97b..398f8ad 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -9,7 +9,7 @@ parameters: level: max ignoreErrors: - - "#Cannot access offset '[a-zA-Z]+' on mixed.#" + - '#Unsafe usage of new static\(\).#' excludePaths: diff --git a/src/Html/Column.php b/src/Html/Column.php index c98ab6b..1a11388 100644 --- a/src/Html/Column.php +++ b/src/Html/Column.php @@ -8,14 +8,14 @@ use Yajra\DataTables\Html\Options\Plugins\SearchPanes; /** - * @property string data - * @property string name - * @property string orderable - * @property string searchable - * @property string printable - * @property string exportable - * @property string footer - * @property array attributes + * @property string $data + * @property string $name + * @property string $orderable + * @property string $searchable + * @property string $printable + * @property string $exportable + * @property string $footer + * @property array $attributes * @see https://datatables.net/reference/option/#columns */ class Column extends Fluent @@ -27,23 +27,23 @@ class Column extends Fluent */ public function __construct($attributes = []) { - $attributes['title'] = isset($attributes['title']) ? $attributes['title'] : self::titleFormat($attributes['data']); - $attributes['orderable'] = isset($attributes['orderable']) ? $attributes['orderable'] : true; - $attributes['searchable'] = isset($attributes['searchable']) ? $attributes['searchable'] : true; - $attributes['exportable'] = isset($attributes['exportable']) ? $attributes['exportable'] : true; - $attributes['printable'] = isset($attributes['printable']) ? $attributes['printable'] : true; - $attributes['footer'] = isset($attributes['footer']) ? $attributes['footer'] : ''; - $attributes['attributes'] = isset($attributes['attributes']) ? $attributes['attributes'] : []; + $attributes['title'] ??= self::titleFormat($attributes['data']); + $attributes['orderable'] ??= true; + $attributes['searchable'] ??= true; + $attributes['exportable'] ??= true; + $attributes['printable'] ??= true; + $attributes['footer'] ??= ''; + $attributes['attributes'] ??= []; // Allow methods override attribute value foreach ($attributes as $attribute => $value) { - $method = 'parse' . ucfirst(strtolower($attribute)); - if (!is_null($value) && method_exists($this, $method)) { + $method = 'parse'.ucfirst(strtolower($attribute)); + if (! is_null($value) && method_exists($this, $method)) { $attributes[$attribute] = $this->$method($value); } } - if (!isset($attributes['name']) && isset($attributes['data'])) { + if (! isset($attributes['name']) && isset($attributes['data'])) { $attributes['name'] = $attributes['data']; } @@ -56,7 +56,7 @@ public function __construct($attributes = []) * @param string $value * @return string */ - public static function titleFormat($value) + public static function titleFormat(string $value): string { return Str::title(str_replace('_', ' ', $value)); } @@ -68,7 +68,7 @@ public static function titleFormat($value) * @param string|null $title * @return Column */ - public static function computed($data, $title = null) + public static function computed(string $data, string $title = null): Column { if (is_null($title)) { $title = self::titleFormat($data); @@ -84,7 +84,7 @@ public static function computed($data, $title = null) * @return $this * @see https://datatables.net/reference/option/columns.searchable */ - public function searchable(bool $flag = true) + public function searchable(bool $flag = true): static { $this->attributes['searchable'] = $flag; @@ -98,7 +98,7 @@ public function searchable(bool $flag = true) * @return $this * @see https://datatables.net/reference/option/columns.orderable */ - public function orderable(bool $flag = true) + public function orderable(bool $flag = true): static { $this->attributes['orderable'] = $flag; @@ -112,7 +112,7 @@ public function orderable(bool $flag = true) * @return $this * @see https://datatables.net/reference/option/columns.title */ - public function title($value) + public function title($value): static { $this->attributes['title'] = $value; @@ -124,9 +124,9 @@ public function title($value) * * @param string $data * @param string $name - * @return Column + * @return static */ - public static function make($data, $name = '') + public static function make(string $data, string $name = ''): static { $attr = [ 'data' => $data, @@ -140,15 +140,15 @@ public static function make($data, $name = '') * Make a new formatted column instance. * * @param string $name - * @return Column + * @return static */ - public static function formatted($name) + public static function formatted(string $name): static { $attr = [ 'data' => $name, 'name' => $name, 'title' => self::titleFormat($name), - 'render' => 'full.' . $name . '_formatted', + 'render' => 'full.'.$name.'_formatted', ]; return new static($attr); @@ -158,17 +158,17 @@ public static function formatted($name) * Create a checkbox column. * * @param string $title - * @return Column + * @return static */ - public static function checkbox($title = '') + 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); } /** @@ -177,7 +177,7 @@ public static function checkbox($title = '') * @param bool $flag * @return $this */ - public function exportable(bool $flag = true) + public function exportable(bool $flag = true): static { $this->attributes['exportable'] = $flag; @@ -191,7 +191,7 @@ public function exportable(bool $flag = true) * @return $this * @see https://datatables.net/reference/option/columns.className */ - public function className($class) + public function className($class): static { $this->attributes['className'] = $class; @@ -205,7 +205,7 @@ public function className($class) * @return $this * @see https://datatables.net/reference/option/columns.defaultContent */ - public function content($value) + public function content(string $value): static { $this->attributes['defaultContent'] = $value; @@ -219,7 +219,7 @@ public function content($value) * @return $this * @see https://datatables.net/reference/option/columns.responsivePriority */ - public function responsivePriority($value) + public function responsivePriority(int|string $value): static { $this->attributes['responsivePriority'] = $value; @@ -232,7 +232,7 @@ public function responsivePriority($value) * @return $this * @see https://datatables.net/reference/option/columns.visible */ - public function hidden() + public function hidden(): static { return $this->visible(false); } @@ -244,7 +244,7 @@ public function hidden() * @return $this * @see https://datatables.net/reference/option/columns.visible */ - public function visible(bool $flag = true) + public function visible(bool $flag = true): static { $this->attributes['visible'] = $flag; @@ -257,9 +257,9 @@ public function visible(bool $flag = true) * @param string $class * @return $this */ - public function addClass($class) + public function addClass($class): static { - if (!isset($this->attributes['className'])) { + if (! isset($this->attributes['className'])) { $this->attributes['className'] = $class; } else { $this->attributes['className'] .= " $class"; @@ -274,7 +274,7 @@ public function addClass($class) * @param bool $flag * @return $this */ - public function printable(bool $flag = true) + public function printable(bool $flag = true): static { $this->attributes['printable'] = $flag; @@ -288,7 +288,7 @@ public function printable(bool $flag = true) * @return $this * @see https://datatables.net/reference/option/columns.width */ - public function width($value) + public function width(int|string $value): static { $this->attributes['width'] = $value; @@ -302,7 +302,7 @@ public function width($value) * @return $this * @see https://datatables.net/reference/option/columns.data */ - public function data($value) + public function data(string $value): static { $this->attributes['data'] = $value; @@ -316,7 +316,7 @@ public function data($value) * @return $this * @see https://datatables.net/reference/option/columns.name */ - public function name($value) + public function name(string $value): static { $this->attributes['name'] = $value; @@ -326,11 +326,11 @@ public function name($value) /** * Set column edit field option value. * - * @param string|array $value + * @param array|string $value * @return $this * @see https://datatables.net/reference/option/columns.editField */ - public function editField($value) + public function editField(array|string $value): static { $this->attributes['editField'] = $value; @@ -344,7 +344,7 @@ public function editField($value) * @return $this * @see https://datatables.net/reference/option/columns.orderData */ - public function orderData($value) + public function orderData(mixed $value): static { $this->attributes['orderData'] = $value; @@ -358,7 +358,7 @@ public function orderData($value) * @return $this * @see https://datatables.net/reference/option/columns.orderDataType */ - public function orderDataType($value) + public function orderDataType(mixed $value): static { $this->attributes['orderDataType'] = $value; @@ -372,7 +372,7 @@ public function orderDataType($value) * @return $this * @see https://datatables.net/reference/option/columns.orderSequence */ - public function orderSequence($value) + public function orderSequence(mixed $value): static { $this->attributes['orderSequence'] = $value; @@ -386,7 +386,7 @@ public function orderSequence($value) * @return $this * @see https://datatables.net/reference/option/columns.cellType */ - public function cellType($value) + public function cellType(mixed $value): static { $this->attributes['cellType'] = $value; @@ -400,7 +400,7 @@ public function cellType($value) * @return $this * @see https://datatables.net/reference/option/columns.type */ - public function type($value) + public function type(mixed $value): static { $this->attributes['type'] = $value; @@ -414,7 +414,7 @@ public function type($value) * @return $this * @see https://datatables.net/reference/option/columns.contentPadding */ - public function contentPadding($value) + public function contentPadding(mixed $value): static { $this->attributes['contentPadding'] = $value; @@ -428,7 +428,7 @@ public function contentPadding($value) * @return $this * @see https://datatables.net/reference/option/columns.createdCell */ - public function createdCell($value) + public function createdCell(mixed $value): static { $this->attributes['createdCell'] = $value; @@ -443,7 +443,7 @@ public function createdCell($value) * @return $this * @see https://datatables.net/reference/option/columns.render */ - public function renderJs($value, ...$params) + public function renderJs(mixed $value, ...$params): static { if ($params) { $value .= '('; @@ -454,7 +454,7 @@ public function renderJs($value, ...$params) $value .= ')'; } - $renderer = '$.fn.dataTable.render.' . $value; + $renderer = '$.fn.dataTable.render.'.$value; return $this->render($renderer); } @@ -466,7 +466,7 @@ public function renderJs($value, ...$params) * @return $this * @see https://datatables.net/reference/option/columns.render */ - public function render($value) + public function render(mixed $value): static { $this->attributes['render'] = $this->parseRender($value); @@ -479,7 +479,7 @@ public function render($value) * @param mixed $value * @return string|null */ - public function parseRender($value) + public function parseRender(mixed $value): ?string { /** @var \Illuminate\Contracts\View\Factory $view */ $view = app('view'); @@ -507,7 +507,7 @@ public function parseRender($value) * @param string $value * @return bool */ - private function isBuiltInRenderFunction($value) + private function isBuiltInRenderFunction(string $value): bool { if (empty($value)) { return false; @@ -522,7 +522,7 @@ private function isBuiltInRenderFunction($value) * @param mixed $value * @return string */ - private function parseRenderAsString($value) + private function parseRenderAsString(mixed $value): string { return "function(data,type,full,meta){return $value;}"; } @@ -534,7 +534,7 @@ private function parseRenderAsString($value) * @return $this * @see https://datatables.net/reference/option/columns.render */ - public function renderRaw($value) + public function renderRaw(mixed $value): static { $this->attributes['render'] = $value; @@ -547,7 +547,7 @@ public function renderRaw($value) * @param mixed $value * @return $this */ - public function footer($value) + public function footer(mixed $value): static { $this->attributes['footer'] = $value; @@ -555,12 +555,12 @@ public function footer($value) } /** - * Set custom html title instead defult label. + * Set custom html title instead default label. * * @param mixed $value * @return $this */ - public function titleAttr($value) + public function titleAttr(mixed $value): static { $this->attributes['titleAttr'] = $value; @@ -570,11 +570,11 @@ public function titleAttr($value) /** * Set excel column format when exporting. * - * @param string $format + * @param string $format * @return $this * @see https://github.com/yajra/laravel-datatables-export */ - public function exportFormat($format) + public function exportFormat(string $format): static { $this->attributes['exportFormat'] = $format; @@ -584,7 +584,7 @@ public function exportFormat($format) /** * @return array */ - public function toArray() + public function toArray(): array { return Arr::except($this->attributes, [ 'printable', diff --git a/src/Html/Options/HasCallbacks.php b/src/Html/Options/HasCallbacks.php index 5bb200c..fc4b663 100644 --- a/src/Html/Options/HasCallbacks.php +++ b/src/Html/Options/HasCallbacks.php @@ -16,7 +16,7 @@ trait HasCallbacks * @return $this * @see https://datatables.net/reference/option/createdRow */ - public function createdRow($script) + public function createdRow(mixed $script): static { $this->attributes['createdRow'] = $script; diff --git a/src/Html/Options/HasColumns.php b/src/Html/Options/HasColumns.php index 1bf5308..2b50451 100644 --- a/src/Html/Options/HasColumns.php +++ b/src/Html/Options/HasColumns.php @@ -10,7 +10,7 @@ /** * DataTables - Columns option builder. * - * @property Collection $collection + * @property Collection $collection * @see https://datatables.net/reference/option/ */ trait HasColumns @@ -125,7 +125,7 @@ public function getQualifiedTitle(string $title): string } /** - * Add a column in collection usingsl attributes. + * Add a column in collection using attributes. * * @param array $attributes * @return $this @@ -195,6 +195,7 @@ public function getColumns(): Collection public function removeColumn(...$names): static { foreach ($names as $name) { + // @phpstan-ignore-next-line $this->collection = $this->collection->filter(function (Column $column) use ($name) { return $column->name !== $name; })->flatten(); diff --git a/src/Html/Options/Languages/Aria.php b/src/Html/Options/Languages/Aria.php index 0ca389c..4826076 100644 --- a/src/Html/Options/Languages/Aria.php +++ b/src/Html/Options/Languages/Aria.php @@ -7,112 +7,96 @@ trait Aria /** * Set language aria option value. * - * @param array $value + * @param array $value * @return $this * @see https://datatables.net/reference/option/language.aria */ public function languageAria(array $value) { - $this->attributes['language']['aria'] = $value; - - return $this; + return $this->language(['aria' => $value]); } /** * Set language aria paginate option value. * - * @param array $value + * @param array $value * @return $this * @see https://datatables.net/reference/option/language.aria.paginate */ public function languageAriaPaginate(array $value) { - $this->attributes['language']['aria']['paginate'] = $value; - - return $this; + return $this->languageAria(['paginate' => $value]); } /** * Set language aria paginate first option value. * - * @param string $value + * @param string $value * @return $this * @see https://datatables.net/reference/option/language.aria.paginate.first */ - public function languageAriaPaginateFirst($value) + public function languageAriaPaginateFirst(string $value) { - $this->attributes['language']['aria']['paginate']['first'] = $value; - - return $this; + return $this->languageAriaPaginate(['first' => $value]); } /** * Set language aria paginate last option value. * - * @param string $value + * @param string $value * @return $this * @see https://datatables.net/reference/option/language.aria.paginate.last */ - public function languageAriaPaginateLast($value) + public function languageAriaPaginateLast(string $value) { - $this->attributes['language']['aria']['paginate']['last'] = $value; - - return $this; + return $this->languageAriaPaginate(['last' => $value]); } /** * Set language aria paginate next option value. * - * @param string $value + * @param string $value * @return $this * @see https://datatables.net/reference/option/language.aria.paginate.next */ - public function languageAriaPaginateNext($value) + public function languageAriaPaginateNext(string $value) { - $this->attributes['language']['aria']['paginate']['next'] = $value; - - return $this; + return $this->languageAriaPaginate(['next' => $value]); } /** * Set language aria paginate previous option value. * - * @param string $value + * @param string $value * @return $this * @see https://datatables.net/reference/option/language.aria.paginate.previous */ - public function languageAriaPaginatePrevious($value) + public function languageAriaPaginatePrevious(string $value) { - $this->attributes['language']['aria']['paginate']['previous'] = $value; - - return $this; + return $this->languageAriaPaginate(['previous' => $value]); } /** * Set language aria sortAscending option value. * - * @param string $value + * @param string $value * @return $this * @see https://datatables.net/reference/option/language.aria.sortAscending */ public function languageAriaSortAscending($value) { - $this->attributes['language']['aria']['sortAscending'] = $value; - - return $this; + return $this->languageAria(['sortAscending' => $value]); } /** * Set language aria sortDescending option value. * - * @param string $value + * @param string $value * @return $this * @see https://datatables.net/reference/option/language.aria.sortDescending */ public function languageAriaSortDescending($value) { - $this->attributes['language']['aria']['sortDescending'] = $value; - - return $this; + return $this->languageAria(['sortDescending' => $value]); } } diff --git a/src/Html/Options/Languages/AutoFill.php b/src/Html/Options/Languages/AutoFill.php index 5207d9a..0859be7 100644 --- a/src/Html/Options/Languages/AutoFill.php +++ b/src/Html/Options/Languages/AutoFill.php @@ -7,112 +7,96 @@ trait AutoFill /** * Set language autoFill option value. * - * @param array $value + * @param array $value * @return $this * @see https://datatables.net/reference/option/language.autoFill */ public function languageAutoFill(array $value) { - $this->attributes['language']['autoFill'] = $value; - - return $this; + return $this->language(['autoFill' => $value]); } /** * Set language autoFill button option value. * - * @param string $value + * @param string $value * @return $this * @see https://datatables.net/reference/option/language.autoFill.button */ - public function languageAutoFillButton($value) + public function languageAutoFillButton(string $value) { - $this->attributes['language']['autoFill']['button'] = $value; - - return $this; + return $this->languageAutoFill(['button' => $value]); } /** * Set language autoFill cancel option value. * - * @param string $value + * @param string $value * @return $this * @see https://datatables.net/reference/option/language.autoFill.cancel */ - public function languageAutoFillCancel($value) + public function languageAutoFillCancel(string $value) { - $this->attributes['language']['autoFill']['cancel'] = $value; - - return $this; + return $this->languageAutoFill(['cancel' => $value]); } /** * Set language autoFill fill option value. * - * @param string $value + * @param string $value * @return $this * @see https://datatables.net/reference/option/language.autoFill.fill */ - public function languageAutoFillFill($value) + public function languageAutoFillFill(string $value) { - $this->attributes['language']['autoFill']['fill'] = $value; - - return $this; + return $this->languageAutoFill(['fill' => $value]); } /** * Set language autoFill fillHorizontal option value. * - * @param string $value + * @param string $value * @return $this * @see https://datatables.net/reference/option/language.autoFill.fillHorizontal */ - public function languageAutoFillFillHorizontal($value) + public function languageAutoFillFillHorizontal(string $value) { - $this->attributes['language']['autoFill']['fillHorizontal'] = $value; - - return $this; + return $this->languageAutoFill(['fillHorizontal' => $value]); } /** * Set language autoFill fillVertical option value. * - * @param string $value + * @param string $value * @return $this * @see https://datatables.net/reference/option/language.autoFill.fillVertical */ - public function languageAutoFillFillVertical($value) + public function languageAutoFillFillVertical(string $value) { - $this->attributes['language']['autoFill']['fillVertical'] = $value; - - return $this; + return $this->languageAutoFill(['fillVertical' => $value]); } /** * Set language autoFill increment option value. * - * @param string $value + * @param string $value * @return $this * @see https://datatables.net/reference/option/language.autoFill.increment */ - public function languageAutoFillIncrement($value) + public function languageAutoFillIncrement(string $value) { - $this->attributes['language']['autoFill']['increment'] = $value; - - return $this; + return $this->languageAutoFill(['increment' => $value]); } /** * Set language autoFill info option value. * - * @param string $value + * @param string $value * @return $this * @see https://datatables.net/reference/option/language.autoFill.info */ - public function languageAutoFillInfo($value) + public function languageAutoFillInfo(string $value) { - $this->attributes['language']['autoFill']['info'] = $value; - - return $this; + return $this->languageAutoFill(['info' => $value]); } } diff --git a/src/Html/Options/Languages/Paginate.php b/src/Html/Options/Languages/Paginate.php index 46fa9a8..08941ac 100644 --- a/src/Html/Options/Languages/Paginate.php +++ b/src/Html/Options/Languages/Paginate.php @@ -7,70 +7,60 @@ trait Paginate /** * Set language aria paginate option value. * - * @param array $value + * @param array $value * @return $this * @see https://datatables.net/reference/option/language.paginate */ public function languagePaginate(array $value) { - $this->attributes['language']['paginate'] = $value; - - return $this; + return $this->language(['paginate' => $value]); } /** * Set language aria paginate first option value. * - * @param string $value + * @param string $value * @return $this * @see https://datatables.net/reference/option/language.paginate.first */ - public function languagePaginateFirst($value) + public function languagePaginateFirst(string $value) { - $this->attributes['language']['paginate']['first'] = $value; - - return $this; + return $this->languagePaginate(['first' => $value]); } /** * Set language aria paginate last option value. * - * @param string $value + * @param string $value * @return $this * @see https://datatables.net/reference/option/language.paginate.last */ - public function languagePaginateLast($value) + public function languagePaginateLast(string $value) { - $this->attributes['language']['paginate']['last'] = $value; - - return $this; + return $this->languagePaginate(['last' => $value]); } /** * Set language aria paginate next option value. * - * @param string $value + * @param string $value * @return $this * @see https://datatables.net/reference/option/language.paginate.next */ - public function languagePaginateNext($value) + public function languagePaginateNext(string $value) { - $this->attributes['language']['paginate']['next'] = $value; - - return $this; + return $this->languagePaginate(['next' => $value]); } /** * Set language aria paginate previous option value. * - * @param string $value + * @param string $value * @return $this * @see https://datatables.net/reference/option/language.paginate.previous */ - public function languagePaginatePrevious($value) + public function languagePaginatePrevious(string $value) { - $this->attributes['language']['paginate']['previous'] = $value; - - return $this; + return $this->languagePaginate(['previous' => $value]); } } diff --git a/src/Html/Options/Languages/Select.php b/src/Html/Options/Languages/Select.php index 910c897..944e76e 100644 --- a/src/Html/Options/Languages/Select.php +++ b/src/Html/Options/Languages/Select.php @@ -7,56 +7,48 @@ trait Select /** * Set language select option value. * - * @param array $value + * @param array $value * @return $this * @see https://datatables.net/reference/option/language.select */ - public function languageSelect($value) + public function languageSelect(array $value) { - $this->attributes['language']['select'] = $value; - - return $this; + return $this->language(['select' => $value]); } /** * Set language select cells option value. * - * @param string|array $value + * @param array|string $value * @return $this * @see https://datatables.net/reference/option/language.select.cells */ - public function languageSelectCells($value) + public function languageSelectCells(array|string $value) { - $this->attributes['language']['select']['cells'] = $value; - - return $this; + return $this->languageSelect(['cells' => $value]); } /** * Set language select columns option value. * - * @param string|array $value + * @param array|string $value * @return $this * @see https://datatables.net/reference/option/language.select.columns */ - public function languageSelectColumns($value) + public function languageSelectColumns(array|string $value) { - $this->attributes['language']['select']['columns'] = $value; - - return $this; + return $this->languageSelect(['columns' => $value]); } /** * Set language select rows option value. * - * @param string|array $value + * @param array|string $value * @return $this * @see https://datatables.net/reference/option/language.select.rows */ - public function languageSelectRows($value) + public function languageSelectRows(array|string $value) { - $this->attributes['language']['select']['rows'] = $value; - - return $this; + return $this->languageSelect(['rows' => $value]); } } diff --git a/src/Html/Options/Plugins/Responsive.php b/src/Html/Options/Plugins/Responsive.php index 844e776..9be04ba 100644 --- a/src/Html/Options/Plugins/Responsive.php +++ b/src/Html/Options/Plugins/Responsive.php @@ -28,98 +28,84 @@ public function responsive(bool|array $value = true): static /** * Set responsive breakpoints option value. * - * @param mixed $value + * @param mixed $value * @return $this * @see https://datatables.net/reference/option/responsive.breakpoints */ public function responsiveBreakpoints(mixed $value): static { - $this->attributes['responsive']['breakpoints'] = $value; - - return $this; + return $this->responsive(['breakpoints' => $value]); } /** * Set responsive details option value. * - * @param mixed $value + * @param mixed $value * @return $this * @see https://datatables.net/reference/option/responsive.details */ public function responsiveDetails(mixed $value): static { - $this->attributes['responsive']['details'] = $value; - - return $this; + return $this->responsive(['details' => $value]); } /** * Set responsive details display option value. * - * @param mixed $value + * @param mixed $value * @return $this * @see https://datatables.net/reference/option/responsive.details.display */ public function responsiveDetailsDisplay(mixed $value): static { - $this->attributes['responsive']['details']['display'] = $value; - - return $this; + return $this->responsiveDetails(['display' => $value]); } /** * Set responsive details renderer option value. * - * @param mixed $value + * @param mixed $value * @return $this * @see https://datatables.net/reference/option/responsive.details.renderer */ public function responsiveDetailsRenderer(mixed $value): static { - $this->attributes['responsive']['details']['renderer'] = $value; - - return $this; + return $this->responsiveDetails(['renderer' => $value]); } /** * Set responsive details target option value. * - * @param mixed $value + * @param mixed $value * @return $this * @see https://datatables.net/reference/option/responsive.details.target */ public function responsiveDetailsTarget(mixed $value): static { - $this->attributes['responsive']['details']['target'] = $value; - - return $this; + return $this->responsiveDetails(['target' => $value]); } /** * Set responsive details type option value. * - * @param mixed $value + * @param mixed $value * @return $this * @see https://datatables.net/reference/option/responsive.details.type */ public function responsiveDetailsType(mixed $value): static { - $this->attributes['responsive']['details']['type'] = $value; - - return $this; + return $this->responsiveDetails(['type' => $value]); } /** * Set responsive orthogonal option value. * - * @param mixed $value + * @param mixed $value * @return $this * @see https://datatables.net/reference/option/responsive.orthogonal */ public function responsiveOrthogonal(mixed $value): static { - $this->attributes['responsive']['orthogonal'] = $value; - - return $this; + return $this->responsive(['orthogonal' => $value]); } } diff --git a/src/Html/SearchPane.php b/src/Html/SearchPane.php index f5fac94..bf113ea 100644 --- a/src/Html/SearchPane.php +++ b/src/Html/SearchPane.php @@ -10,23 +10,23 @@ use Illuminate\Support\Fluent; use Yajra\DataTables\Html\Editor\Fields\Options; -final class SearchPane extends Fluent +class SearchPane extends Fluent { /** * @param array $options * @return static */ - public static function make(array $options = []): self + public static function make(array $options = []): static { - return new self($options); + return new static($options); } /** * @param bool $value - * @return static + * @return $this * @see https://datatables.net/reference/option/searchPanes.cascadePanes */ - public function cascadePanes(bool $value = true): self + public function cascadePanes(bool $value = true): static { $this->attributes['cascadePanes'] = $value; @@ -35,10 +35,10 @@ public function cascadePanes(bool $value = true): self /** * @param bool $value - * @return static + * @return $this * @see https://datatables.net/reference/option/searchPanes.clear */ - public function clear(bool $value = true): self + public function clear(bool $value = true): static { $this->attributes['clear'] = $value; @@ -47,10 +47,10 @@ public function clear(bool $value = true): self /** * @param array $value - * @return static + * @return $this * @see https://datatables.net/reference/option/searchPanes.columns */ - public function columns(array $value = []): self + public function columns(array $value = []): static { $this->attributes['columns'] = $value; @@ -59,10 +59,10 @@ public function columns(array $value = []): self /** * @param bool $value - * @return static + * @return $this * @see https://datatables.net/reference/option/searchPanes.controls */ - public function controls(bool $value = true): self + public function controls(bool $value = true): static { $this->attributes['controls'] = $value; @@ -71,11 +71,11 @@ public function controls(bool $value = true): self /** * @param array $value - * @return static + * @return $this * @see https://datatables.net/reference/option/searchPanes.dtOpts * @see https://datatables.net/reference/option/columns.searchPanes.dtOpts */ - public function dtOpts(array $value = []): self + public function dtOpts(array $value = []): static { $this->attributes['dtOpts'] = $value; @@ -84,10 +84,10 @@ public function dtOpts(array $value = []): self /** * @param string $value - * @return static + * @return $this * @see https://datatables.net/reference/option/searchPanes.emptyMessage */ - public function emptyMessage(string $value): self + public function emptyMessage(string $value): static { $this->attributes['emptyMessage'] = $value; @@ -96,10 +96,10 @@ public function emptyMessage(string $value): self /** * @param string $value - * @return static + * @return $this * @see https://datatables.net/reference/option/searchPanes.filterChanged */ - public function filterChanged(string $value): self + public function filterChanged(string $value): static { $this->attributes['filterChanged'] = $value; @@ -108,10 +108,10 @@ public function filterChanged(string $value): self /** * @param bool $value - * @return static + * @return $this * @see https://datatables.net/reference/option/searchPanes.hideCount */ - public function hideCount(bool $value = true): self + public function hideCount(bool $value = true): static { $this->attributes['hideCount'] = $value; @@ -120,10 +120,10 @@ public function hideCount(bool $value = true): self /** * @param string $value - * @return static + * @return $this * @see https://datatables.net/reference/option/searchPanes.layout */ - public function layout(string $value): self + public function layout(string $value): static { $this->attributes['layout'] = $value; @@ -132,10 +132,10 @@ public function layout(string $value): self /** * @param array $value - * @return static + * @return $this * @see https://datatables.net/reference/option/searchPanes.order */ - public function order(array $value): self + public function order(array $value): static { $this->attributes['order'] = $value; @@ -144,10 +144,10 @@ public function order(array $value): self /** * @param boolean $value - * @return static + * @return $this * @see https://datatables.net/reference/option/searchPanes.orderable */ - public function orderable(bool $value = true): self + public function orderable(bool $value = true): static { $this->attributes['orderable'] = $value; @@ -156,10 +156,10 @@ public function orderable(bool $value = true): self /** * @param array $value - * @return static + * @return $this * @see https://datatables.net/reference/option/searchPanes.panes */ - public function panes(array $value): self + public function panes(array $value): static { $panes = collect($value)->map(function ($pane) { if ($pane instanceof Arrayable) { @@ -176,7 +176,7 @@ public function panes(array $value): self /** * @param float $value - * @return static + * @return $this * @see https://datatables.net/reference/option/searchPanes.threshold */ public function threshold(float $value): static @@ -188,10 +188,10 @@ public function threshold(float $value): static /** * @param boolean $value - * @return static + * @return $this * @see https://datatables.net/reference/option/searchPanes.viewTotal */ - public function viewTotal(bool $value = true): self + public function viewTotal(bool $value = true): static { $this->attributes['viewTotal'] = $value; @@ -200,10 +200,10 @@ public function viewTotal(bool $value = true): self /** * @param boolean $value - * @return static + * @return $this * @see https://datatables.net/reference/option/searchPanes.viewTotal */ - public function hideTotal(bool $value = true): self + public function hideTotal(bool $value = true): static { $this->attributes['viewTotal'] = ! $value; @@ -218,7 +218,7 @@ public function hideTotal(bool $value = true): self * @param string $key * @return $this */ - public function modelOptions(Model|EloquentBuilder $model, string $value, string $key = 'id'): self + public function modelOptions(Model|EloquentBuilder $model, string $value, string $key = 'id') { return $this->options( Options::model($model, $value, $key) @@ -227,7 +227,7 @@ public function modelOptions(Model|EloquentBuilder $model, string $value, string /** * @param mixed $value - * @return static + * @return $this * @see https://datatables.net/reference/option/columns.searchPanes.options */ public function options($value) @@ -249,7 +249,7 @@ public function options($value) * @param string $key * @param \Closure|null $callback * @param \Illuminate\Database\Connection|null $connection - * @return static + * @return $this */ public function tableOptions( string $table, @@ -257,7 +257,7 @@ public function tableOptions( string $key = 'id', Closure $callback = null, ?Connection $connection = null - ): self { + ): static { return $this->options( Options::table($table, $value, $key, $callback, $connection) ); @@ -265,10 +265,10 @@ public function tableOptions( /** * @param string $value - * @return static + * @return $this * @see https://datatables.net/reference/option/columns.searchPanes.className */ - public function className(string $value): self + public function className(string $value): static { $this->attributes['className'] = $value; @@ -277,10 +277,10 @@ public function className(string $value): self /** * @param string $value - * @return static + * @return $this * @see https://datatables.net/reference/option/searchPanes.panes.header */ - public function header(string $value): self + public function header(string $value): static { $this->attributes['header'] = $value; @@ -289,10 +289,10 @@ public function header(string $value): self /** * @param bool $value - * @return static + * @return $this * @see https://datatables.net/reference/option/columns.searchPanes.show */ - public function show(bool $value = true): self + public function show(bool $value = true): static { $this->attributes['show'] = $value; @@ -301,10 +301,10 @@ public function show(bool $value = true): self /** * @param string $value - * @return static + * @return $this * @see https://datatables.net/reference/option/columns.searchPanes.name */ - public function name(string $value): self + public function name(string $value): static { $this->attributes['name'] = $value; @@ -313,10 +313,10 @@ public function name(string $value): self /** * @param array|string $value - * @return static + * @return $this * @see https://datatables.net/reference/option/columns.searchPanes.orthogonal */ - public function orthogonal(array|string $value): self + public function orthogonal(array|string $value): static { $this->attributes['orthogonal'] = $value; From 6131078a850998ee38d110cbb910381d26ba1db4 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Sat, 7 May 2022 09:03:13 +0800 Subject: [PATCH 006/260] stan wip --- phpstan.neon.dist | 2 +- src/Html/Builder.php | 55 ++++++++++++++------------- src/Html/Editor/Editor.php | 4 ++ src/Html/HasAuthorizations.php | 35 +++++++++-------- src/Html/HasEditor.php | 28 +++++++------- src/Html/HasTable.php | 62 ++++++++++++++++--------------- src/Html/Options/HasCallbacks.php | 60 +++++++++++++++--------------- 7 files changed, 127 insertions(+), 119 deletions(-) diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 398f8ad..1835b37 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -6,7 +6,7 @@ parameters: paths: - src - level: max + level: 8 ignoreErrors: - '#Unsafe usage of new static\(\).#' diff --git a/src/Html/Builder.php b/src/Html/Builder.php index b5360e8..44be657 100644 --- a/src/Html/Builder.php +++ b/src/Html/Builder.php @@ -8,7 +8,6 @@ use Illuminate\Support\Arr; use Illuminate\Support\Collection; use Illuminate\Support\HtmlString; -use Illuminate\Support\Str; use Illuminate\Support\Traits\Macroable; class Builder @@ -22,14 +21,14 @@ class Builder use Columns\Checkbox; // 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_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'; + const SELECT_ITEMS_ROW = 'row'; + const SELECT_ITEMS_COLUMN = 'column'; + const SELECT_ITEMS_CELL = 'cell'; /** * @var Collection @@ -52,14 +51,14 @@ class Builder public $html; /** - * @var array + * @var array */ protected $tableAttributes = []; /** * @var string */ - protected $template = ''; + protected string $template = ''; /** * @var array @@ -67,9 +66,9 @@ class Builder protected $attributes = []; /** - * @param Repository $config - * @param Factory $view - * @param HtmlBuilder $html + * @param Repository $config + * @param Factory $view + * @param HtmlBuilder $html */ public function __construct(Repository $config, Factory $view, HtmlBuilder $html) { @@ -87,8 +86,8 @@ public function __construct(Repository $config, Factory $view, HtmlBuilder $html /** * Generate DataTable javascript. * - * @param null $script - * @param array $attributes + * @param null $script + * @param array $attributes * @return \Illuminate\Support\HtmlString * @throws \Exception */ @@ -148,7 +147,7 @@ public function getOptions() /** * Generate DataTables js parameters. * - * @param array $attributes + * @param array $attributes * @return string */ public function parameterize($attributes = []) @@ -161,8 +160,8 @@ public function parameterize($attributes = []) foreach (Arr::dot($parameters) as $key => $value) { if ($this->isCallbackFunction($value, $key)) { $values[] = trim($value); - Arr::set($parameters, $key, '%' . $key . '%'); - $replacements[] = '"%' . $key . '%"'; + Arr::set($parameters, $key, '%'.$key.'%'); + $replacements[] = '"%'.$key.'%"'; } } @@ -193,9 +192,9 @@ protected function template() /** * Generate DataTable's table html. * - * @param array $attributes - * @param bool $drawFooter - * @param bool $drawSearch + * @param array $attributes + * @param bool $drawFooter + * @param bool $drawSearch * @return \Illuminate\Support\HtmlString */ public function table(array $attributes = [], $drawFooter = false, $drawSearch = false) @@ -205,13 +204,13 @@ public function table(array $attributes = [], $drawFooter = false, $drawSearch = $th = $this->compileTableHeaders(); $htmlAttr = $this->html->attributes($this->tableAttributes); - $tableHtml = ''; - $searchHtml = $drawSearch ? '' . implode('', - $this->compileTableSearchHeaders()) . '' : ''; - $tableHtml .= '' . implode('', $th) . '' . $searchHtml . ''; + $tableHtml = '
'; + $searchHtml = $drawSearch ? ''.implode('', + $this->compileTableSearchHeaders()).'' : ''; + $tableHtml .= ''.implode('', $th).''.$searchHtml.''; if ($drawFooter) { $tf = $this->compileTableFooter(); - $tableHtml .= '' . implode('', $tf) . ''; + $tableHtml .= ''.implode('', $tf).''; } $tableHtml .= '
'; @@ -221,7 +220,7 @@ public function table(array $attributes = [], $drawFooter = false, $drawSearch = /** * Configure DataTable's parameters. * - * @param array $attributes + * @param array $attributes * @return $this */ public function parameters(array $attributes = []) @@ -234,7 +233,7 @@ public function parameters(array $attributes = []) /** * Set custom javascript template. * - * @param string $template + * @param string $template * @return $this */ public function setTemplate($template) diff --git a/src/Html/Editor/Editor.php b/src/Html/Editor/Editor.php index d6617af..1f1c215 100644 --- a/src/Html/Editor/Editor.php +++ b/src/Html/Editor/Editor.php @@ -9,6 +9,10 @@ use Yajra\DataTables\Utilities\Helper; use Yajra\DataTables\Html\Editor\Fields\Field; +/** + * @property string|null $table + * @property string|array|null $ajax + */ class Editor extends Fluent { use HasEvents; diff --git a/src/Html/HasAuthorizations.php b/src/Html/HasAuthorizations.php index b93f445..0615546 100644 --- a/src/Html/HasAuthorizations.php +++ b/src/Html/HasAuthorizations.php @@ -11,16 +11,16 @@ trait HasAuthorizations * * @var bool */ - protected $authorized = true; + protected bool $authorized = true; /** * Make a button if condition is true. * - * @param bool|callable $condition - * @param string|array $options + * @param callable|bool $condition + * @param array|string $options * @return static */ - public static function makeIf($condition, $options = []) + public static function makeIf(callable|bool $condition, array|string $options = []) { if (value($condition)) { return static::make($options); @@ -32,12 +32,12 @@ public static function makeIf($condition, $options = []) /** * Make a button if the user is authorized. * - * @param string $permission - * @param string|array $options - * @param Authorizable|null $user + * @param string $permission + * @param array|string $options + * @param Authorizable|null $user * @return static */ - public static function makeIfCan($permission, $options = [], Authorizable $user = null) + public static function makeIfCan(string $permission, array|string $options = [], Authorizable $user = null) { if (is_null($user)) { $user = auth()->user(); @@ -53,13 +53,16 @@ public static function makeIfCan($permission, $options = [], Authorizable $user /** * Make a button if the user is not authorized. * - * @param string $permission - * @param string|array $options - * @param Authorizable|null $user + * @param string $permission + * @param array|string $options + * @param Authorizable|null $user * @return static */ - public static function makeIfCannot($permission, $options = [], Authorizable $user = null) - { + public static function makeIfCannot( + string $permission, + array|string $options = [], + Authorizable $user = null + ): static { if (is_null($user)) { $user = auth()->user(); } @@ -74,10 +77,10 @@ public static function makeIfCannot($permission, $options = [], Authorizable $us /** * Set authorization status of the button. * - * @param bool|callable $bool + * @param callable|bool $bool * @return static */ - public function authorized($bool) + public function authorized(callable|bool $bool): static { $this->authorized = value($bool); @@ -89,7 +92,7 @@ public function authorized($bool) * * @return array */ - public function toArray() + public function toArray(): array { if ($this->authorized) { return parent::toArray(); diff --git a/src/Html/HasEditor.php b/src/Html/HasEditor.php index 4b76cfe..5284798 100644 --- a/src/Html/HasEditor.php +++ b/src/Html/HasEditor.php @@ -9,19 +9,19 @@ trait HasEditor /** * Collection of Editors. * - * @var null|Editor + * @var array */ - protected $editors = []; + protected array $editors = []; /** * Attach multiple editors to builder. * - * @param array|mixed ...$editors + * @param array|mixed ...$editors * @return $this - * @see https://editor.datatables.net/ * @throws \Exception + * @see https://editor.datatables.net/ */ - public function editors(...$editors) + public function editors(...$editors): static { if (is_array($editors[0])) { $editors = $editors[0]; @@ -37,12 +37,12 @@ public function editors(...$editors) /** * Integrate with DataTables Editor. * - * @param array|Editor $fields + * @param Editor $fields * @return $this - * @see https://editor.datatables.net/ * @throws \Exception + * @see https://editor.datatables.net/ */ - public function editor($fields) + public function editor(Editor $fields): static { $this->setTemplate($this->config->get('datatables-html.editor', 'datatables::editor')); @@ -54,11 +54,11 @@ public function editor($fields) } /** - * @param array|Editor $fields - * @return array|Editor + * @param array|Editor $fields + * @return Editor * @throws \Exception */ - protected function newEditor($fields) + protected function newEditor(Editor|array $fields): Editor { if ($fields instanceof Editor) { $editor = $fields; @@ -68,7 +68,7 @@ protected function newEditor($fields) } if (! $editor->table) { - $editor->table('#' . $this->getTableAttribute('id')); + $editor->table('#'.$this->getTableAttribute('id')); } if (! $editor->ajax) { @@ -79,9 +79,9 @@ protected function newEditor($fields) } /** - * @return array|null + * @return array */ - public function getEditors() + public function getEditors(): array { return $this->editors; } diff --git a/src/Html/HasTable.php b/src/Html/HasTable.php index 67b85db..9ccf026 100644 --- a/src/Html/HasTable.php +++ b/src/Html/HasTable.php @@ -2,6 +2,7 @@ namespace Yajra\DataTables\Html; +use Exception; use Illuminate\Support\Arr; trait HasTable @@ -9,17 +10,17 @@ trait HasTable /** * Retrieves HTML table attribute value. * - * @param string $attribute - * @return mixed + * @param string $attribute + * @return string * @throws \Exception */ - public function getTableAttribute($attribute) + public function getTableAttribute(string $attribute): string { if (! array_key_exists($attribute, $this->tableAttributes)) { - throw new \Exception("Table attribute '{$attribute}' does not exist."); + throw new Exception("Table attribute '$attribute' does not exist."); } - return $this->tableAttributes[$attribute]; + return $this->tableAttributes[$attribute] ?? ''; } /** @@ -27,7 +28,7 @@ public function getTableAttribute($attribute) * * @return array */ - public function getTableAttributes() + public function getTableAttributes(): array { return $this->tableAttributes; } @@ -35,10 +36,10 @@ public function getTableAttributes() /** * Sets HTML table "id" attribute. * - * @param string $id + * @param string $id * @return $this */ - public function setTableId($id) + public function setTableId(string $id): static { return $this->setTableAttribute('id', $id); } @@ -47,8 +48,9 @@ public function setTableId($id) * Get HTML table "id" attribute. * * @return string + * @throws \Exception */ - public function getTableId() + public function getTableId(): string { return $this->getTableAttribute('id'); } @@ -56,11 +58,11 @@ public function getTableId() /** * Sets HTML table attribute(s). * - * @param string|array $attribute - * @param mixed $value + * @param array|string $attribute + * @param string|null $value * @return $this */ - public function setTableAttribute($attribute, $value = null) + public function setTableAttribute(array|string $attribute, string $value = null): static { if (is_array($attribute)) { return $this->setTableAttributes($attribute); @@ -74,10 +76,10 @@ public function setTableAttribute($attribute, $value = null) /** * Sets multiple HTML table attributes at once. * - * @param array $attributes + * @param array $attributes * @return $this */ - public function setTableAttributes(array $attributes) + public function setTableAttributes(array $attributes): static { foreach ($attributes as $attribute => $value) { $this->tableAttributes[$attribute] = $value; @@ -89,16 +91,16 @@ public function setTableAttributes(array $attributes) /** * Add class names to the "class" attribute of HTML table. * - * @param string|array $class + * @param array|string $class * @return $this */ - public function addTableClass($class) + public function addTableClass(array|string $class): static { $class = is_array($class) ? implode(' ', $class) : $class; $currentClass = Arr::get(array_change_key_case($this->tableAttributes), 'class'); - $classes = preg_split('#\s+#', $currentClass . ' ' . $class, null, PREG_SPLIT_NO_EMPTY); - $class = implode(' ', array_unique($classes)); + $classes = preg_split('#\s+#', $currentClass.' '.$class, -1, PREG_SPLIT_NO_EMPTY); + $class = implode(' ', array_unique((array) $classes)); return $this->setTableAttribute('class', $class); } @@ -106,17 +108,17 @@ public function addTableClass($class) /** * Remove class names from the "class" attribute of HTML table. * - * @param string|array $class + * @param array|string $class * @return $this */ - public function removeTableClass($class) + public function removeTableClass(array|string $class): static { $class = is_array($class) ? implode(' ', $class) : $class; $currentClass = Arr::get(array_change_key_case($this->tableAttributes), 'class'); $classes = array_diff( - preg_split('#\s+#', $currentClass, null, PREG_SPLIT_NO_EMPTY), - preg_split('#\s+#', $class, null, PREG_SPLIT_NO_EMPTY) + (array) preg_split('#\s+#', $currentClass, -1, PREG_SPLIT_NO_EMPTY), + (array) preg_split('#\s+#', $class, -1, PREG_SPLIT_NO_EMPTY) ); $class = implode(' ', array_unique($classes)); @@ -128,7 +130,7 @@ public function removeTableClass($class) * * @return array */ - protected function compileTableHeaders() + protected function compileTableHeaders(): array { $th = []; foreach ($this->collection->toArray() as $row) { @@ -137,7 +139,7 @@ protected function compileTableHeaders() $row['attributes'], isset($row['titleAttr']) ? ['title' => $row['titleAttr']] : [] )); - $th[] = '' . $row['title'] . ''; + $th[] = ''.$row['title'].''; } return $th; @@ -148,11 +150,11 @@ protected function compileTableHeaders() * * @return array */ - protected function compileTableSearchHeaders() + protected function compileTableSearchHeaders(): array { $search = []; foreach ($this->collection->all() as $key => $row) { - $search[] = $row['searchable'] ? '' . (isset($row->search) ? $row->search : '') . '' : ''; + $search[] = $row['searchable'] ? ''.($row->search ?? '').'' : ''; } return $search; @@ -163,17 +165,17 @@ protected function compileTableSearchHeaders() * * @return array */ - protected function compileTableFooter() + protected function compileTableFooter(): array { $footer = []; foreach ($this->collection->all() as $row) { if (is_array($row->footer)) { $footerAttr = $this->html->attributes(Arr::only($row->footer, ['class', 'id', 'title', 'width', 'style', 'data-class', 'data-hide'])); - $title = isset($row->footer['title']) ? $row->footer['title'] : ''; - $footer[] = '' . $title . ''; + $title = $row->footer['title'] ?? ''; + $footer[] = ''.$title.''; } else { - $footer[] = '' . $row->footer . ''; + $footer[] = ''.$row->footer.''; } } diff --git a/src/Html/Options/HasCallbacks.php b/src/Html/Options/HasCallbacks.php index fc4b663..f970c2d 100644 --- a/src/Html/Options/HasCallbacks.php +++ b/src/Html/Options/HasCallbacks.php @@ -12,11 +12,11 @@ trait HasCallbacks /** * Set createdRow option value. * - * @param mixed $script + * @param string $script * @return $this * @see https://datatables.net/reference/option/createdRow */ - public function createdRow(mixed $script): static + public function createdRow(string $script): static { $this->attributes['createdRow'] = $script; @@ -26,11 +26,11 @@ public function createdRow(mixed $script): static /** * Set drawCallback option value. * - * @param mixed $script + * @param string $script * @return $this * @see https://datatables.net/reference/option/drawCallback */ - public function drawCallback($script) + public function drawCallback(string $script): static { $this->attributes['drawCallback'] = $script; @@ -41,11 +41,11 @@ public function drawCallback($script) * Set drawCallback option value with Livewire integration. * Solution as per issue https://github.com/yajra/laravel-datatables/issues/2401. * - * @param mixed|null $script + * @param string|null $script * @return $this * @see https://datatables.net/reference/option/drawCallback */ - public function drawCallbackWithLivewire($script = null) + public function drawCallbackWithLivewire(string $script = null): static { $js = "function(settings) { if (window.livewire) { @@ -63,11 +63,11 @@ public function drawCallbackWithLivewire($script = null) /** * Set footerCallback option value. * - * @param mixed $script + * @param string $script * @return $this * @see https://datatables.net/reference/option/footerCallback */ - public function footerCallback($script) + public function footerCallback(string $script): static { $this->attributes['footerCallback'] = $script; @@ -77,11 +77,11 @@ public function footerCallback($script) /** * Set formatNumber option value. * - * @param mixed $script + * @param string $script * @return $this * @see https://datatables.net/reference/option/formatNumber */ - public function formatNumber($script) + public function formatNumber(string $script): static { $this->attributes['formatNumber'] = $script; @@ -91,11 +91,11 @@ public function formatNumber($script) /** * Set headerCallback option value. * - * @param mixed $script + * @param string $script * @return $this * @see https://datatables.net/reference/option/headerCallback */ - public function headerCallback($script) + public function headerCallback(string $script): static { $this->attributes['headerCallback'] = $script; @@ -105,11 +105,11 @@ public function headerCallback($script) /** * Set infoCallback option value. * - * @param mixed $script + * @param string $script * @return $this * @see https://datatables.net/reference/option/infoCallback */ - public function infoCallback($script) + public function infoCallback(string $script): static { $this->attributes['infoCallback'] = $script; @@ -119,11 +119,11 @@ public function infoCallback($script) /** * Set initComplete option value. * - * @param mixed $script + * @param string $script * @return $this * @see https://datatables.net/reference/option/initComplete */ - public function initComplete($script) + public function initComplete(string $script): static { $this->attributes['initComplete'] = $script; @@ -133,11 +133,11 @@ public function initComplete($script) /** * Set preDrawCallback option value. * - * @param mixed $script + * @param string $script * @return $this * @see https://datatables.net/reference/option/preDrawCallback */ - public function preDrawCallback($script) + public function preDrawCallback(string $script): static { $this->attributes['preDrawCallback'] = $script; @@ -147,11 +147,11 @@ public function preDrawCallback($script) /** * Set rowCallback option value. * - * @param mixed $script + * @param string $script * @return $this * @see https://datatables.net/reference/option/rowCallback */ - public function rowCallback($script) + public function rowCallback(string $script): static { $this->attributes['rowCallback'] = $script; @@ -161,11 +161,11 @@ public function rowCallback($script) /** * Set stateLoadCallback option value. * - * @param mixed $script + * @param string $script * @return $this * @see https://datatables.net/reference/option/stateLoadCallback */ - public function stateLoadCallback($script) + public function stateLoadCallback(string $script): static { $this->attributes['stateLoadCallback'] = $script; @@ -175,11 +175,11 @@ public function stateLoadCallback($script) /** * Set stateLoaded option value. * - * @param mixed $script + * @param string $script * @return $this * @see https://datatables.net/reference/option/stateLoaded */ - public function stateLoaded($script) + public function stateLoaded(string $script): static { $this->attributes['stateLoaded'] = $script; @@ -189,11 +189,11 @@ public function stateLoaded($script) /** * Set stateLoadParams option value. * - * @param mixed $script + * @param string $script * @return $this * @see https://datatables.net/reference/option/stateLoadParams */ - public function stateLoadParams($script) + public function stateLoadParams(string $script): static { $this->attributes['stateLoadParams'] = $script; @@ -203,11 +203,11 @@ public function stateLoadParams($script) /** * Set stateSaveCallback option value. * - * @param mixed $script + * @param string $script * @return $this * @see https://datatables.net/reference/option/stateSaveCallback */ - public function stateSaveCallback($script) + public function stateSaveCallback(string $script): static { $this->attributes['stateSaveCallback'] = $script; @@ -217,11 +217,11 @@ public function stateSaveCallback($script) /** * Set stateSaveParams option value. * - * @param mixed $script + * @param string $script * @return $this * @see https://datatables.net/reference/option/stateSaveParams */ - public function stateSaveParams($script) + public function stateSaveParams(string $script): static { $this->attributes['stateSaveParams'] = $script; From 76a612ff58ab8c0f21e9086d672b54ecfe6a805a Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Sat, 7 May 2022 11:15:45 +0800 Subject: [PATCH 007/260] PHP8 chores --- src/Html/Builder.php | 24 ++-- src/Html/Button.php | 134 +++++++++---------- src/Html/Column.php | 38 +++--- src/Html/ColumnDefinition.php | 2 +- src/Html/Columns/Action.php | 6 +- src/Html/Columns/Checkbox.php | 4 +- src/Html/Columns/Index.php | 4 +- src/Html/Editor/Editor.php | 95 ++++++------- src/Html/Editor/Fields/BelongsTo.php | 4 +- src/Html/Editor/Fields/Boolean.php | 8 +- src/Html/Editor/Fields/Checkbox.php | 2 +- src/Html/Editor/Fields/Date.php | 8 +- src/Html/Editor/Fields/DateTime.php | 52 +++---- src/Html/Editor/Fields/Field.php | 127 ++++++++++-------- src/Html/Editor/Fields/File.php | 78 ++++++----- src/Html/Editor/Fields/Hidden.php | 2 +- src/Html/Editor/Fields/Image.php | 10 +- src/Html/Editor/Fields/Number.php | 2 +- src/Html/Editor/Fields/Options.php | 24 ++-- src/Html/Editor/Fields/Password.php | 2 +- src/Html/Editor/Fields/Radio.php | 2 +- src/Html/Editor/Fields/ReadOnlyField.php | 2 +- src/Html/Editor/Fields/Select.php | 12 +- src/Html/Editor/Fields/Select2.php | 18 +-- src/Html/Editor/Fields/TextArea.php | 10 +- src/Html/Editor/Fields/Time.php | 10 +- src/Html/Editor/FormOptions.php | 54 ++++---- src/Html/Editor/HasEvents.php | 10 +- src/Html/HasAuthorizations.php | 4 +- src/Html/HasOptions.php | 96 ++++++------- src/Html/Options/HasData.php | 5 +- src/Html/Options/HasFeatures.php | 48 +++---- src/Html/Options/HasInternationalisation.php | 116 ++++++---------- 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 | 68 ++++------ src/Html/Options/Plugins/ColReorder.php | 44 +++--- src/Html/Options/Plugins/FixedColumns.php | 28 ++-- src/Html/Options/Plugins/FixedHeader.php | 36 ++--- src/Html/Options/Plugins/KeyTable.php | 102 ++++++-------- src/Html/Options/Plugins/Responsive.php | 28 ++-- src/Html/Options/Plugins/RowGroup.php | 68 ++++------ src/Html/Options/Plugins/RowReorder.php | 60 ++++----- src/Html/Options/Plugins/Scroller.php | 44 +++--- src/Html/Options/Plugins/SearchPanes.php | 6 +- src/Html/Options/Plugins/Select.php | 9 +- src/Html/SearchPane.php | 6 +- src/HtmlServiceProvider.php | 14 +- 50 files changed, 725 insertions(+), 851 deletions(-) diff --git a/src/Html/Builder.php b/src/Html/Builder.php index 44be657..2072128 100644 --- a/src/Html/Builder.php +++ b/src/Html/Builder.php @@ -91,7 +91,7 @@ public function __construct(Repository $config, Factory $view, HtmlBuilder $html * @return \Illuminate\Support\HtmlString * @throws \Exception */ - public function scripts($script = null, array $attributes = ['type' => 'text/javascript']) + public function scripts($script = null, array $attributes = ['type' => 'text/javascript']): HtmlString { $script = $script ?: $this->generateScripts(); $attributes = $this->html->attributes($attributes); @@ -105,7 +105,7 @@ public function scripts($script = null, array $attributes = ['type' => 'text/jav * @return \Illuminate\Support\HtmlString * @throws \Exception */ - public function generateScripts() + public function generateScripts(): HtmlString { $parameters = $this->generateJson(); @@ -119,7 +119,7 @@ public function generateScripts() * * @return string */ - public function generateJson() + public function generateJson(): string { return $this->parameterize($this->getOptions()); } @@ -129,7 +129,7 @@ public function generateJson() * * @return array */ - public function getOptions() + public function getOptions(): array { return array_merge( $this->attributes, [ @@ -150,7 +150,7 @@ public function getOptions() * @param array $attributes * @return string */ - public function parameterize($attributes = []) + public function parameterize(array $attributes = []): string { $parameters = (new Parameters($attributes))->toArray(); @@ -172,9 +172,7 @@ public function parameterize($attributes = []) $json = json_encode($new); - $json = str_replace($replacements, $values, $json); - - return $json; + return str_replace($replacements, $values, $json); } /** @@ -182,7 +180,7 @@ public function parameterize($attributes = []) * * @return string */ - protected function template() + protected function template(): string { $template = $this->template ?: $this->config->get('datatables-html.script', 'datatables::script'); @@ -197,7 +195,7 @@ protected function template() * @param bool $drawSearch * @return \Illuminate\Support\HtmlString */ - public function table(array $attributes = [], $drawFooter = false, $drawSearch = false) + public function table(array $attributes = [], bool $drawFooter = false, bool $drawSearch = false): HtmlString { $this->setTableAttributes($attributes); @@ -223,7 +221,7 @@ public function table(array $attributes = [], $drawFooter = false, $drawSearch = * @param array $attributes * @return $this */ - public function parameters(array $attributes = []) + public function parameters(array $attributes = []): static { $this->attributes = array_merge($this->attributes, $attributes); @@ -236,7 +234,7 @@ public function parameters(array $attributes = []) * @param string $template * @return $this */ - public function setTemplate($template) + public function setTemplate(string $template): static { $this->template = $template; @@ -258,7 +256,7 @@ public function asOptions(): static * * @return $this */ - public function asFunction() + public function asFunction(): static { return $this->setTemplate('datatables::function'); } diff --git a/src/Html/Button.php b/src/Html/Button.php index e63c6a3..755ed30 100755 --- a/src/Html/Button.php +++ b/src/Html/Button.php @@ -2,8 +2,8 @@ namespace Yajra\DataTables\Html; -use Illuminate\Support\Fluent; use Illuminate\Contracts\Support\Arrayable; +use Illuminate\Support\Fluent; class Button extends Fluent implements Arrayable { @@ -12,10 +12,10 @@ class Button extends Fluent implements Arrayable /** * Make a new button instance. * - * @param string|array $options + * @param array|string $options * @return static */ - public static function make($options = []) + public static function make(array|string $options = []): static { if (is_string($options)) { return new static(['extend' => $options]); @@ -27,10 +27,10 @@ public static function make($options = []) /** * Make a raw button that does not extend anything. * - * @param array $options + * @param array $options * @return static */ - public static function raw($options = []) + public static function raw(array $options = []): static { if (is_string($options)) { return new static(['text' => $options]); @@ -42,11 +42,11 @@ public static function raw($options = []) /** * Set attr option value. * - * @param array $value + * @param array $value * @return $this * @see https://datatables.net/reference/option/buttons.buttons.attr */ - public function attr(array $value) + public function attr(array $value): static { $this->attributes['attr'] = $value; @@ -56,11 +56,11 @@ public function attr(array $value) /** * Set available option value. * - * @param string $value + * @param string $value * @return $this * @see https://datatables.net/reference/option/buttons.buttons.available */ - public function available($value) + public function available(string $value): static { if ($this->isFunction($value)) { $this->attributes['available'] = $value; @@ -74,22 +74,22 @@ public function available($value) /** * Check if a given value is a function. * - * @param string $value + * @param string $value * @return bool */ - protected function isFunction($value) + protected function isFunction(string $value): bool { - return substr($value, 0, 8) == 'function'; + return str_starts_with($value, 'function'); } /** * Set enabled option value. * - * @param bool $value + * @param bool $value * @return $this * @see https://datatables.net/reference/option/buttons.buttons.enabled */ - public function enabled($value = true) + public function enabled(bool $value = true): static { $this->attributes['enabled'] = $value; @@ -99,11 +99,11 @@ public function enabled($value = true) /** * Set init option value. * - * @param string $value + * @param string $value * @return $this * @see https://datatables.net/reference/option/buttons.buttons.init */ - public function init($value) + public function init(string $value): static { if ($this->isFunction($value)) { $this->attributes['init'] = $value; @@ -117,11 +117,11 @@ public function init($value) /** * Set key option value. * - * @param string|array $value + * @param array|string $value * @return $this * @see https://datatables.net/reference/option/buttons.buttons.key */ - public function key($value) + public function key(array|string $value): static { $this->attributes['key'] = $value; @@ -131,11 +131,11 @@ public function key($value) /** * Set extend option value. * - * @param string $value + * @param string $value * @return $this * @see https://datatables.net/reference/option/buttons.buttons.extend */ - public function extend($value) + public function extend(string $value): static { $this->attributes['extend'] = $value; @@ -145,11 +145,11 @@ public function extend($value) /** * Set editor option value. * - * @param string $value + * @param string $value * @return $this * @see https://editor.datatables.net/reference/button */ - public function editor($value) + public function editor(string $value): static { $this->attributes['editor'] = $value; @@ -159,11 +159,11 @@ public function editor($value) /** * Set buttons option value. * - * @param array $buttons + * @param array $buttons * @return $this * @see https://datatables.net/reference/option/buttons.buttons */ - public function buttons(array $buttons) + public function buttons(array $buttons): static { foreach ($buttons as $key => $button) { if ($button instanceof Arrayable) { @@ -177,11 +177,11 @@ public function buttons(array $buttons) } /** - * @param array $buttons + * @param array $buttons * @return $this * @see https://editor.datatables.net/examples/api/cancelButton */ - public function formButtons(array $buttons) + public function formButtons(array $buttons): static { foreach ($buttons as $key => $button) { if ($button instanceof Arrayable) { @@ -195,14 +195,14 @@ public function formButtons(array $buttons) } /** - * @param mixed $message + * @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 * @see https://editor.datatables.net/reference/button/remove */ - public function formMessage($message) + public function formMessage(string $message): static { $this->attributes['formMessage'] = $message; @@ -210,13 +210,13 @@ public function formMessage($message) } /** - * @param mixed $title + * @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 */ - public function formTitle($title) + public function formTitle(string $title): static { $this->attributes['formTitle'] = $title; @@ -226,11 +226,11 @@ public function formTitle($title) /** * Set className option value. * - * @param string $value + * @param string $value * @return $this * @see https://datatables.net/reference/option/buttons.buttons.className */ - public function className($value) + public function className(string $value): static { $this->attributes['className'] = $value; @@ -240,11 +240,11 @@ public function className($value) /** * Set destroy option value. * - * @param string $value + * @param string $value * @return $this * @see https://datatables.net/reference/option/buttons.buttons.destroy */ - public function destroy($value) + public function destroy(string $value): static { if ($this->isFunction($value)) { $this->attributes['destroy'] = $value; @@ -258,11 +258,11 @@ public function destroy($value) /** * Set customize option value. * - * @param string $value + * @param string $value * @return $this * @see https://datatables.net/reference/button/excelHtml5 */ - public function customize($value) + public function customize(string $value): static { $this->attributes['customize'] = $value; @@ -272,10 +272,10 @@ public function customize($value) /** * Append a class name to column. * - * @param string $class + * @param string $class * @return $this */ - public function addClass($class) + public function addClass(string $class): static { if (! isset($this->attributes['className'])) { $this->attributes['className'] = $class; @@ -289,11 +289,11 @@ public function addClass($class) /** * Set text option value. * - * @param string $value + * @param string $value * @return $this * @see https://datatables.net/reference/option/buttons.buttons.text */ - public function text($value) + public function text(string $value): static { $this->attributes['text'] = $value; @@ -303,11 +303,11 @@ public function text($value) /** * Set titleAttr option value. * - * @param string $value + * @param string $value * @return $this * @see https://datatables.net/reference/option/buttons.buttons.titleAttr */ - public function titleAttr($value) + public function titleAttr(string $value): static { $this->attributes['titleAttr'] = $value; @@ -317,11 +317,11 @@ public function titleAttr($value) /** * Set name option value. * - * @param string $value + * @param string $value * @return $this * @see https://datatables.net/reference/option/buttons.buttons.name */ - public function name($value) + public function name(string $value): static { $this->attributes['name'] = $value; @@ -331,11 +331,11 @@ public function name($value) /** * Set namespace option value. * - * @param string $value + * @param string $value * @return $this * @see https://datatables.net/reference/option/buttons.buttons.namespace */ - public function namespace($value) + public function namespace(string $value): static { $this->attributes['namespace'] = $value; @@ -345,11 +345,11 @@ public function namespace($value) /** * Set tag option value. * - * @param string $value + * @param string $value * @return $this * @see https://datatables.net/reference/option/buttons.buttons.tag */ - public function tag($value) + public function tag(string $value): static { $this->attributes['tag'] = $value; @@ -359,10 +359,10 @@ public function tag($value) /** * Set columns option value. * - * @param mixed $value + * @param array|string $value * @return $this */ - public function columns($value) + public function columns(array|string $value): static { $this->attributes['columns'] = $value; @@ -372,10 +372,10 @@ public function columns($value) /** * Set exportOptions option value. * - * @param mixed $value + * @param array|string $value * @return $this */ - public function exportOptions($value) + public function exportOptions(array|string $value): static { $this->attributes['exportOptions'] = $value; @@ -387,22 +387,20 @@ public function exportOptions($value) * * @return \Yajra\DataTables\Html\Button */ - public function actionSubmit() + public function actionSubmit(): static { - $this->attributes['action'] = 'function() { this.submit(); }'; - - return $this; + return $this->action('function() { this.submit(); }'); } /** * Set action option value. * - * @param string $value + * @param string $value * @return $this */ - public function action($value) + public function action(string $value): static { - if (substr($value, 0, 8) == 'function') { + if (str_starts_with($value, 'function')) { $this->attributes['action'] = $value; } else { $this->attributes['action'] = "function(e, dt, node, config) { $value }"; @@ -414,14 +412,12 @@ public function action($value) /** * Set editor class action handler. * - * @param string $action + * @param string $action * @return \Yajra\DataTables\Html\Button */ - public function actionHandler($action) + public function actionHandler(string $action): static { - $this->attributes['action'] = "function() { this.submit(null, null, function(data) { data.action = '{$action}'; return data; }) }"; - - return $this; + return $this->action("function() { this.submit(null, null, function(data) { data.action = '{$action}'; return data; }) }"); } /** @@ -429,20 +425,18 @@ public function actionHandler($action) * * @return \Yajra\DataTables\Html\Button */ - public function actionClose() + public function actionClose(): static { - $this->attributes['action'] = 'function() { this.close(); }'; - - return $this; + return $this->action('function() { this.close(); }'); } /** * Set button alignment. * - * @param string $align + * @param string $align * @return \Yajra\DataTables\Html\Button */ - public function align($align = 'button-left') + public function align(string $align = 'button-left'): static { $this->attributes['align'] = $align; diff --git a/src/Html/Column.php b/src/Html/Column.php index 1a11388..e2fc537 100644 --- a/src/Html/Column.php +++ b/src/Html/Column.php @@ -112,7 +112,7 @@ public function orderable(bool $flag = true): static * @return $this * @see https://datatables.net/reference/option/columns.title */ - public function title($value): static + public function title(string $value): static { $this->attributes['title'] = $value; @@ -191,7 +191,7 @@ public function exportable(bool $flag = true): static * @return $this * @see https://datatables.net/reference/option/columns.className */ - public function className($class): static + public function className(string $class): static { $this->attributes['className'] = $class; @@ -257,7 +257,7 @@ public function visible(bool $flag = true): static * @param string $class * @return $this */ - public function addClass($class): static + public function addClass(string $class): static { if (! isset($this->attributes['className'])) { $this->attributes['className'] = $class; @@ -340,11 +340,11 @@ public function editField(array|string $value): static /** * Set column orderData option value. * - * @param mixed $value + * @param array|int $value * @return $this * @see https://datatables.net/reference/option/columns.orderData */ - public function orderData(mixed $value): static + public function orderData(array|int $value): static { $this->attributes['orderData'] = $value; @@ -354,11 +354,11 @@ public function orderData(mixed $value): static /** * Set column orderDataType option value. * - * @param mixed $value + * @param string $value * @return $this * @see https://datatables.net/reference/option/columns.orderDataType */ - public function orderDataType(mixed $value): static + public function orderDataType(string $value): static { $this->attributes['orderDataType'] = $value; @@ -368,11 +368,11 @@ public function orderDataType(mixed $value): static /** * Set column orderSequence option value. * - * @param mixed $value + * @param array $value * @return $this * @see https://datatables.net/reference/option/columns.orderSequence */ - public function orderSequence(mixed $value): static + public function orderSequence(array $value): static { $this->attributes['orderSequence'] = $value; @@ -382,11 +382,11 @@ public function orderSequence(mixed $value): static /** * Set column cellType option value. * - * @param mixed $value + * @param string $value * @return $this * @see https://datatables.net/reference/option/columns.cellType */ - public function cellType(mixed $value): static + public function cellType(string $value): static { $this->attributes['cellType'] = $value; @@ -396,11 +396,11 @@ public function cellType(mixed $value): static /** * Set column type option value. * - * @param mixed $value + * @param string $value * @return $this * @see https://datatables.net/reference/option/columns.type */ - public function type(mixed $value): static + public function type(string $value): static { $this->attributes['type'] = $value; @@ -410,11 +410,11 @@ public function type(mixed $value): static /** * Set column contentPadding option value. * - * @param mixed $value + * @param string $value * @return $this * @see https://datatables.net/reference/option/columns.contentPadding */ - public function contentPadding(mixed $value): static + public function contentPadding(string $value): static { $this->attributes['contentPadding'] = $value; @@ -424,11 +424,11 @@ public function contentPadding(mixed $value): static /** * Set column createdCell option value. * - * @param mixed $value + * @param string $value * @return $this * @see https://datatables.net/reference/option/columns.createdCell */ - public function createdCell(mixed $value): static + public function createdCell(string $value): static { $this->attributes['createdCell'] = $value; @@ -438,12 +438,12 @@ public function createdCell(mixed $value): static /** * Use the js renderer "$.fn.dataTable.render.". * - * @param mixed $value + * @param string $value * @param mixed ...$params * @return $this * @see https://datatables.net/reference/option/columns.render */ - public function renderJs(mixed $value, ...$params): static + public function renderJs(string $value, ...$params): static { if ($params) { $value .= '('; diff --git a/src/Html/ColumnDefinition.php b/src/Html/ColumnDefinition.php index ccc5279..3fc023f 100644 --- a/src/Html/ColumnDefinition.php +++ b/src/Html/ColumnDefinition.php @@ -8,7 +8,7 @@ class ColumnDefinition extends Fluent { use HasOptions; - public function targets(array $value): self + public function targets(array $value): static { $this->attributes['targets'] = $value; diff --git a/src/Html/Columns/Action.php b/src/Html/Columns/Action.php index 2e6d7b3..fcfa2f8 100644 --- a/src/Html/Columns/Action.php +++ b/src/Html/Columns/Action.php @@ -9,11 +9,11 @@ trait Action /** * Add a action column. * - * @param array $attributes - * @param bool $prepend + * @param array $attributes + * @param bool $prepend * @return $this */ - public function addAction(array $attributes = [], $prepend = false) + public function addAction(array $attributes = [], bool $prepend = false): static { $attributes = array_merge([ 'defaultContent' => '', diff --git a/src/Html/Columns/Checkbox.php b/src/Html/Columns/Checkbox.php index 3816a2b..c94c068 100644 --- a/src/Html/Columns/Checkbox.php +++ b/src/Html/Columns/Checkbox.php @@ -10,10 +10,10 @@ 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 + * @param bool|int $position true to prepend, false to append or a zero-based index for positioning * @return $this */ - public function addCheckbox(array $attributes = [], $position = false) + public function addCheckbox(array $attributes = [], bool|int $position = false): static { $attributes = array_merge([ 'defaultContent' => 'html->attributes($attributes) . '/>', diff --git a/src/Html/Columns/Index.php b/src/Html/Columns/Index.php index 9672653..41e9ee5 100644 --- a/src/Html/Columns/Index.php +++ b/src/Html/Columns/Index.php @@ -9,10 +9,10 @@ trait Index /** * Add a index column. * - * @param array $attributes + * @param array $attributes * @return $this */ - public function addIndex(array $attributes = []) + public function addIndex(array $attributes = []): static { $indexColumn = $this->config->get('datatables.index_column', 'DT_RowIndex'); diff --git a/src/Html/Editor/Editor.php b/src/Html/Editor/Editor.php index 1f1c215..f2eb3e8 100644 --- a/src/Html/Editor/Editor.php +++ b/src/Html/Editor/Editor.php @@ -3,11 +3,11 @@ namespace Yajra\DataTables\Html\Editor; use Illuminate\Support\Arr; -use Illuminate\Support\Str; use Illuminate\Support\Fluent; +use Illuminate\Support\Str; +use Yajra\DataTables\Html\Editor\Fields\Field; use Yajra\DataTables\Html\HasAuthorizations; use Yajra\DataTables\Utilities\Helper; -use Yajra\DataTables\Html\Editor\Fields\Field; /** * @property string|null $table @@ -18,16 +18,16 @@ class Editor extends Fluent use HasEvents; use HasAuthorizations; - const DISPLAY_LIGHTBOX = 'lightbox'; - const DISPLAY_ENVELOPE = 'envelope'; - const DISPLAY_BOOTSTRAP = 'bootstrap'; + const DISPLAY_LIGHTBOX = 'lightbox'; + const DISPLAY_ENVELOPE = 'envelope'; + const DISPLAY_BOOTSTRAP = 'bootstrap'; const DISPLAY_FOUNDATION = 'foundation'; - const DISPLAY_JQUERYUI = 'jqueryui'; + const DISPLAY_JQUERYUI = 'jqueryui'; /** * Editor constructor. * - * @param string|array $instance + * @param string|array $instance */ public function __construct($instance = 'editor') { @@ -39,10 +39,10 @@ public function __construct($instance = 'editor') /** * Make new Editor instance. * - * @param string $instance - * @return Editor + * @param string $instance + * @return static */ - public static function make($instance = 'editor') + public static function make(string $instance = 'editor'): static { if (is_array($instance)) { $instance = $instance['editor'] ?? 'editor'; @@ -54,10 +54,10 @@ public static function make($instance = 'editor') /** * Append raw scripts. * - * @param string $scripts + * @param string $scripts * @return Editor */ - public function scripts($scripts) + public function scripts(string $scripts): static { $this->attributes['scripts'] = $scripts; @@ -67,10 +67,10 @@ public function scripts($scripts) /** * Set Editor's variable name / instance. * - * @param $instance + * @param string $instance * @return $this */ - public function instance($instance) + public function instance(string $instance): static { $this->attributes['instance'] = $instance; @@ -80,11 +80,11 @@ public function instance($instance) /** * Set Editor's ajax parameter. * - * @param string|array $ajax + * @param array|string $ajax * @return $this * @see https://editor.datatables.net/reference/option/ajax */ - public function ajax($ajax) + public function ajax(array|string $ajax): static { $this->attributes['ajax'] = $ajax; @@ -94,11 +94,11 @@ public function ajax($ajax) /** * Set Editor's table source. * - * @param string $table + * @param string $table * @return $this * @see https://editor.datatables.net/reference/option/table */ - public function table($table) + public function table(string $table): static { $this->attributes['table'] = $table; @@ -108,11 +108,11 @@ public function table($table) /** * Set Editor's idSrc option. * - * @param string $idSrc + * @param string $idSrc * @return $this * @see https://editor.datatables.net/reference/option/idSrc */ - public function idSrc($idSrc = 'DT_RowId') + public function idSrc(string $idSrc = 'DT_RowId'): static { $this->attributes['idSrc'] = $idSrc; @@ -122,11 +122,11 @@ public function idSrc($idSrc = 'DT_RowId') /** * Set Editor's display option. * - * @param string $display + * @param string $display * @return $this * @see https://editor.datatables.net/reference/option/display */ - public function display($display) + public function display(string $display): static { $this->attributes['display'] = $display; @@ -136,11 +136,11 @@ public function display($display) /** * Set Editor's fields. * - * @param array $fields + * @param array $fields * @return $this * @see https://editor.datatables.net/reference/option/fields */ - public function fields(array $fields) + public function fields(array $fields): static { $this->attributes['fields'] = $fields; @@ -150,12 +150,12 @@ public function fields(array $fields) /** * Set Editor's formOptions. * - * @param mixed $formOptions + * @param array $formOptions * @return $this * @see https://editor.datatables.net/reference/option/formOptions * @see https://editor.datatables.net/reference/type/form-options */ - public function formOptions(array $formOptions) + public function formOptions(array $formOptions): static { $this->attributes['formOptions'] = $formOptions; @@ -165,11 +165,12 @@ public function formOptions(array $formOptions) /** * Set Editor's bubble formOptions. * - * @param mixed $formOptions + * @param mixed $formOptions * @return $this + * @throws \Yajra\DataTables\Exceptions\Exception * @see https://editor.datatables.net/reference/option/formOptions.bubble */ - public function formOptionsBubble(array $formOptions) + public function formOptionsBubble(array $formOptions): static { $this->attributes['formOptions']['bubble'] = Helper::castToArray($formOptions);; @@ -179,11 +180,12 @@ public function formOptionsBubble(array $formOptions) /** * Set Editor's inline formOptions. * - * @param mixed $formOptions + * @param array $formOptions * @return $this + * @throws \Yajra\DataTables\Exceptions\Exception * @see https://editor.datatables.net/reference/option/formOptions.inline */ - public function formOptionsInline($formOptions) + public function formOptionsInline(array $formOptions): static { $this->attributes['formOptions']['inline'] = Helper::castToArray($formOptions); @@ -193,11 +195,12 @@ public function formOptionsInline($formOptions) /** * Set Editor's main formOptions. * - * @param mixed $formOptions + * @param array $formOptions * @return $this + * @throws \Yajra\DataTables\Exceptions\Exception * @see https://editor.datatables.net/reference/option/formOptions.main */ - public function formOptionsMain($formOptions) + public function formOptionsMain(array $formOptions): static { $this->attributes['formOptions']['main'] = Helper::castToArray($formOptions); @@ -207,11 +210,11 @@ public function formOptionsMain($formOptions) /** * Set Editor's language. * - * @param array $language + * @param array $language * @return $this * @see https://editor.datatables.net/reference/option/i18n */ - public function language(array $language) + public function language(array $language): static { $this->attributes['i18n'] = $language; @@ -221,11 +224,11 @@ public function language(array $language) /** * Set Editor's template. * - * @param string $template + * @param string $template * @return $this * @see https://editor.datatables.net/reference/option/template */ - public function template($template) + public function template(string $template): static { $this->attributes['template'] = $template; @@ -237,7 +240,7 @@ public function template($template) * * @return array */ - public function toArray() + public function toArray(): array { $array = parent::toArray(); @@ -255,23 +258,23 @@ public function toArray() /** * Convert the fluent instance to JSON. * - * @param int $options + * @param int $options * @return string */ - public function toJson($options = 0) + public function toJson($options = 0): string { $parameters = $this->jsonSerialize(); unset($parameters['events']); - $values = []; + $values = []; $replacements = []; foreach (Arr::dot($parameters) as $key => $value) { if ($this->isCallbackFunction($value, $key)) { $values[] = trim($value); - Arr::set($parameters, $key, '%' . $key . '%'); - $replacements[] = '"%' . $key . '%"'; + Arr::set($parameters, $key, '%'.$key.'%'); + $replacements[] = '"%'.$key.'%"'; } } @@ -282,16 +285,14 @@ public function toJson($options = 0) $json = json_encode($new, $options); - $json = str_replace($replacements, $values, $json); - - return $json; + return str_replace($replacements, $values, $json); } /** * Check if given key & value is a valid callback js function. * - * @param string $value - * @param string $key + * @param string $value + * @param string $key * @return bool */ protected function isCallbackFunction($value, $key) diff --git a/src/Html/Editor/Fields/BelongsTo.php b/src/Html/Editor/Fields/BelongsTo.php index cb4c322..b8a2c0c 100644 --- a/src/Html/Editor/Fields/BelongsTo.php +++ b/src/Html/Editor/Fields/BelongsTo.php @@ -2,7 +2,7 @@ namespace Yajra\DataTables\Html\Editor\Fields; -use Illuminate\Database\Eloquent\Builder; +use Illuminate\Contracts\Database\Eloquent\Builder; use Illuminate\Support\Str; class BelongsTo extends Select @@ -14,7 +14,7 @@ class BelongsTo extends Select * @param string|null $foreign * @return static */ - public static function model(Builder|string $class, string $text, string $id = 'id', string $foreign = null): self + public static function model(Builder|string $class, string $text, string $id = 'id', string $foreign = null): static { if ($class instanceof Builder) { $table = $class->getModel()->getTable(); diff --git a/src/Html/Editor/Fields/Boolean.php b/src/Html/Editor/Fields/Boolean.php index 86e8e49..281b9ab 100644 --- a/src/Html/Editor/Fields/Boolean.php +++ b/src/Html/Editor/Fields/Boolean.php @@ -7,11 +7,11 @@ class Boolean extends Checkbox /** * Make a new instance of a field. * - * @param string $name - * @param string $label - * @return static|\Yajra\DataTables\Html\Editor\Fields\Field + * @param array|string $name + * @param string $label + * @return static */ - public static function make($name, $label = '') + public static function make(array|string $name, string $label = ''): static { return parent::make($name, $label)->separator(',')->options( Options::make()->append('', 1) diff --git a/src/Html/Editor/Fields/Checkbox.php b/src/Html/Editor/Fields/Checkbox.php index ae02689..f55024e 100644 --- a/src/Html/Editor/Fields/Checkbox.php +++ b/src/Html/Editor/Fields/Checkbox.php @@ -4,5 +4,5 @@ class Checkbox extends Field { - protected $type = 'checkbox'; + protected string $type = 'checkbox'; } diff --git a/src/Html/Editor/Fields/Date.php b/src/Html/Editor/Fields/Date.php index 7c689ba..89fdf54 100644 --- a/src/Html/Editor/Fields/Date.php +++ b/src/Html/Editor/Fields/Date.php @@ -7,11 +7,11 @@ class Date extends DateTime /** * Make a new instance of a field. * - * @param string $name - * @param string $label - * @return static|\Yajra\DataTables\Html\Editor\Fields\Field + * @param array|string $name + * @param string $label + * @return static */ - public static function make($name, $label = '') + public static function make(array|string $name, string $label = ''): static { return parent::make($name, $label)->format('YYYY-MM-DD'); } diff --git a/src/Html/Editor/Fields/DateTime.php b/src/Html/Editor/Fields/DateTime.php index bb64673..5a421fb 100644 --- a/src/Html/Editor/Fields/DateTime.php +++ b/src/Html/Editor/Fields/DateTime.php @@ -4,16 +4,16 @@ class DateTime extends Field { - protected $type = 'datetime'; + protected string $type = 'datetime'; /** * Make a new instance of a field. * - * @param string $name - * @param string $label - * @return static|\Yajra\DataTables\Html\Editor\Fields\Field + * @param array|string $name + * @param string $label + * @return static */ - public static function make($name, $label = '') + public static function make(array|string $name, string $label = ''): static { return parent::make($name, $label)->format('YYYY-MM-DD hh:mm a'); } @@ -23,43 +23,43 @@ public static function make($name, $label = '') * * @return $this */ - public function military() + public function military(): static { return $this->format('YYYY-MM-DD HH:mm'); } /** - * @param \DateTime $dateTime - * @param string $format + * @param \DateTime $dateTime + * @param string $format * @return $this * @see https://editor.datatables.net/examples/dates/options-min-max.html */ - public function minDate(\DateTime $dateTime, $format = 'Y-m-d') + public function minDate(\DateTime $dateTime, string $format = 'Y-m-d'): static { - $this->attributes['opts']['minDate'] = "new Date('" . $dateTime->format($format) . "')"; + $this->attributes['opts']['minDate'] = "new Date('".$dateTime->format($format)."')"; return $this; } /** - * @param \DateTime $dateTime - * @param string $format + * @param \DateTime $dateTime + * @param string $format * @return $this * @see https://editor.datatables.net/examples/dates/options-min-max.html */ - public function maxDate(\DateTime $dateTime, $format = 'Y-m-d') + public function maxDate(\DateTime $dateTime, string $format = 'Y-m-d'): static { - $this->attributes['opts']['maxDate'] = "new Date('" . $dateTime->format($format) . "')"; + $this->attributes['opts']['maxDate'] = "new Date('".$dateTime->format($format)."')"; return $this; } /** - * @param bool $state + * @param bool $state * @return $this * @see https://editor.datatables.net/examples/dates/options-week-numbers.html */ - public function showWeekNumber($state = true) + public function showWeekNumber(bool $state = true): static { $this->attributes['opts']['showWeekNumber'] = $state; @@ -67,11 +67,11 @@ public function showWeekNumber($state = true) } /** - * @param array $days + * @param array $days * @return $this * @see https://editor.datatables.net/examples/dates/options-disable-days.html */ - public function disableDays(array $days) + public function disableDays(array $days): static { $this->attributes['opts']['disableDays'] = $days; @@ -79,11 +79,11 @@ public function disableDays(array $days) } /** - * @param int $minutes + * @param int $minutes * @return $this * @see https://editor.datatables.net/examples/dates/time-increment.html */ - public function minutesIncrement($minutes) + public function minutesIncrement(int $minutes): static { $this->attributes['opts']['minutesIncrement'] = $minutes; @@ -91,11 +91,11 @@ public function minutesIncrement($minutes) } /** - * @param int $seconds + * @param int $seconds * @return $this * @see https://editor.datatables.net/examples/dates/time-increment.html */ - public function secondsIncrement($seconds) + public function secondsIncrement(int $seconds): static { $this->attributes['opts']['secondsIncrement'] = $seconds; @@ -103,11 +103,11 @@ public function secondsIncrement($seconds) } /** - * @param array $hours + * @param array $hours * @return $this * @see https://editor.datatables.net/examples/dates/datetime.html */ - public function hoursAvailable(array $hours) + public function hoursAvailable(array $hours): static { $this->attributes['opts']['hoursAvailable'] = $hours; @@ -115,11 +115,11 @@ public function hoursAvailable(array $hours) } /** - * @param array $minutes + * @param array $minutes * @return $this * @see https://editor.datatables.net/examples/dates/datetime.html */ - public function minutesAvailable(array $minutes) + public function minutesAvailable(array $minutes): static { $this->attributes['opts']['minutesAvailable'] = $minutes; diff --git a/src/Html/Editor/Fields/Field.php b/src/Html/Editor/Fields/Field.php index 0dc37c0..355072e 100644 --- a/src/Html/Editor/Fields/Field.php +++ b/src/Html/Editor/Fields/Field.php @@ -2,9 +2,13 @@ namespace Yajra\DataTables\Html\Editor\Fields; -use Illuminate\Support\Str; -use Illuminate\Support\Fluent; +use Closure; +use Illuminate\Contracts\Database\Eloquent\Builder as EloquentBuilder; +use Illuminate\Contracts\Database\Query\Builder as QueryBuilder; use Illuminate\Contracts\Support\Arrayable; +use Illuminate\Database\Eloquent\Model; +use Illuminate\Support\Fluent; +use Illuminate\Support\Str; use Yajra\DataTables\Html\HasAuthorizations; /** @@ -19,12 +23,12 @@ class Field extends Fluent * * @var string */ - protected $type = 'text'; + protected string $type = 'text'; /** * Password constructor. * - * @param array $attributes + * @param array $attributes */ public function __construct($attributes = []) { @@ -36,18 +40,18 @@ public function __construct($attributes = []) /** * Make a new instance of a field. * - * @param string $name - * @param string $label - * @return static|\Yajra\DataTables\Html\Editor\Fields\Field + * @param array|string $name + * @param string $label + * @return static */ - public static function make($name, $label = '') + public static function make(array|string $name, string $label = ''): static { if (is_array($name)) { return new static($name); } $data = [ - 'name' => $name, + 'name' => $name, 'label' => $label ?: Str::title(str_replace('_', ' ', $name)), ]; @@ -55,11 +59,11 @@ public static function make($name, $label = '') } /** - * @param string $label + * @param string $label * @return $this * @see https://editor.datatables.net/reference/option/fields.label */ - public function label($label) + public function label(string $label): static { $this->attributes['label'] = $label; @@ -67,11 +71,11 @@ public function label($label) } /** - * @param string $name + * @param string $name * @return $this * @see https://editor.datatables.net/reference/option/fields.name */ - public function name($name) + public function name(string $name): static { $this->attributes['name'] = $name; @@ -79,11 +83,11 @@ public function name($name) } /** - * @param string $data + * @param string $data * @return $this * @see https://editor.datatables.net/reference/option/fields.data */ - public function data($data) + public function data(string $data): static { $this->attributes['data'] = $data; @@ -91,11 +95,11 @@ public function data($data) } /** - * @param string $type + * @param string $type * @return $this * @see https://editor.datatables.net/reference/option/fields.type */ - public function type($type) + public function type(string $type): static { $this->attributes['type'] = $type; @@ -105,12 +109,12 @@ public function type($type) /** * Get options from a model. * - * @param mixed $model - * @param string $value - * @param string $key + * @param \Illuminate\Database\Eloquent\Model|\Illuminate\Contracts\Database\Eloquent\Builder $model + * @param string $value + * @param string $key * @return $this */ - public function modelOptions($model, $value, $key = 'id') + public function modelOptions(Model|EloquentBuilder $model, string $value, string $key = 'id'): static { return $this->options( Options::model($model, $value, $key) @@ -120,10 +124,10 @@ public function modelOptions($model, $value, $key = 'id') /** * Set select options. * - * @param array|mixed $options + * @param array|Arrayable $options * @return $this */ - public function options($options) + public function options(array|Arrayable $options): static { if ($options instanceof Arrayable) { $options = $options->toArray(); @@ -137,15 +141,20 @@ public function options($options) /** * Get options from a table. * - * @param mixed $table - * @param string $value - * @param string $key - * @param \Closure $whereCallback - * @param string|null $key + * @param QueryBuilder|\Closure|string $table + * @param string $value + * @param string $key + * @param \Closure|null $whereCallback + * @param string|null $connection * @return $this */ - public function tableOptions($table, $value, $key = 'id', \Closure $whereCallback = null, $connection = null) - { + public function tableOptions( + QueryBuilder|Closure|string $table, + string $value, + string $key = 'id', + Closure $whereCallback = null, + string $connection = null + ): static { return $this->options( Options::table($table, $value, $key, $whereCallback, $connection) ); @@ -154,10 +163,10 @@ public function tableOptions($table, $value, $key = 'id', \Closure $whereCallbac /** * Set checkbox separator. * - * @param string $separator + * @param string $separator * @return $this */ - public function separator($separator = ',') + public function separator(string $separator = ','): static { $this->attributes['separator'] = $separator; @@ -167,11 +176,11 @@ public function separator($separator = ',') /** * Set dateTime format. * - * @param string $format + * @param string $format * @return $this * @see https://editor.datatables.net/reference/field/datetime */ - public function format($format) + public function format(string $format): static { $this->attributes['format'] = $format; @@ -181,11 +190,11 @@ public function format($format) /** * Set field default value. * - * @param mixed $value + * @param string $value * @return $this * @see https://editor.datatables.net/reference/option/fields.def */ - public function default($value) + public function default(string $value): static { $this->attributes['def'] = $value; @@ -195,11 +204,11 @@ public function default($value) /** * Set field message value. * - * @param string $value + * @param string $value * @return $this * @see https://editor.datatables.net/reference/option/fields.message */ - public function message($value) + public function message(string $value): static { $this->attributes['message'] = $value; @@ -209,11 +218,11 @@ public function message($value) /** * Set field fieldInfo value. * - * @param string $value + * @param string $value * @return $this * @see https://editor.datatables.net/reference/option/fields.fieldInfo */ - public function fieldInfo($value) + public function fieldInfo(string $value): static { $this->attributes['fieldInfo'] = $value; @@ -223,11 +232,11 @@ public function fieldInfo($value) /** * Set field labelInfo value. * - * @param string $value + * @param string $value * @return $this * @see https://editor.datatables.net/reference/option/fields.labelInfo */ - public function labelInfo($value) + public function labelInfo(string $value): static { $this->attributes['labelInfo'] = $value; @@ -237,11 +246,11 @@ public function labelInfo($value) /** * Set field entityDecode value. * - * @param mixed|bool $value + * @param bool $value * @return $this * @see https://editor.datatables.net/reference/option/fields.entityDecode */ - public function entityDecode($value) + public function entityDecode(bool $value): static { $this->attributes['entityDecode'] = $value; @@ -251,11 +260,11 @@ public function entityDecode($value) /** * Set field multiEditable value. * - * @param mixed|bool $value + * @param bool $value * @return $this * @see https://editor.datatables.net/reference/option/fields.multiEditable */ - public function multiEditable($value) + public function multiEditable(bool $value): static { $this->attributes['multiEditable'] = $value; @@ -265,11 +274,11 @@ public function multiEditable($value) /** * Set field id value. * - * @param string $value + * @param string $value * @return $this * @see https://editor.datatables.net/reference/option/fields.id */ - public function id($value) + public function id(string $value): static { $this->attributes['id'] = $value; @@ -279,11 +288,11 @@ public function id($value) /** * Set field submit value. * - * @param bool $value + * @param bool $value * @return $this * @see https://editor.datatables.net/reference/option/fields.submit */ - public function submit($value) + public function submit(bool $value): static { $this->attributes['submit'] = $value; @@ -293,11 +302,11 @@ public function submit($value) /** * Set field compare value. * - * @param bool $value + * @param bool $value * @return $this * @see https://editor.datatables.net/reference/option/fields.compare */ - public function compare($value) + public function compare(bool $value): static { $this->attributes['compare'] = $value; @@ -307,10 +316,11 @@ public function compare($value) /** * Set field opts value. * - * @param bool $value + * @param array $value * @return $this + * @see https://datatables.net/forums/discussion/comment/156581/#Comment_156581 */ - public function opts(array $value) + public function opts(array $value): static { $this->attributes['opts'] = $value; @@ -318,13 +328,14 @@ public function opts(array $value) } /** - * Set field attr option. + * Set field element html attributes. * - * @param string $attribute - * @param mixed $value + * @param string $attribute + * @param string $value * @return $this + * @see https://datatables.net/forums/discussion/comment/156581/#Comment_156581 */ - public function attr($attribute, $value) + public function attr(string $attribute, string $value): static { $this->attributes['attr'][$attribute] = $value; diff --git a/src/Html/Editor/Fields/File.php b/src/Html/Editor/Fields/File.php index 265d9fe..22b6a20 100644 --- a/src/Html/Editor/Fields/File.php +++ b/src/Html/Editor/Fields/File.php @@ -9,21 +9,21 @@ */ class File extends Field { - protected $type = 'upload'; + protected string $type = 'upload'; /** - * Editor instance. + * Editor instance variable name. * * @var string */ - protected $editor = 'editor'; + protected string $editor = 'editor'; /** - * @param string $name - * @param string $label - * @return static|\Yajra\DataTables\Html\Editor\Fields\Field + * @param array|string $name + * @param string $label + * @return static */ - public static function make($name, $label = '') + public static function make(array|string $name, string $label = ''): static { /** @var \Yajra\DataTables\Html\Editor\Fields\File $field */ $field = parent::make($name, $label); @@ -32,10 +32,10 @@ public static function make($name, $label = '') } /** - * @param string $value + * @param string $value * @return $this */ - public function ajax($value) + public function ajax(string $value): static { $this->attributes['ajax'] = $value; @@ -43,10 +43,10 @@ public function ajax($value) } /** - * @param string $value + * @param string $value * @return $this */ - public function ajaxData($value) + public function ajaxData(string $value): static { $this->attributes['ajaxData'] = $value; @@ -54,10 +54,10 @@ public function ajaxData($value) } /** - * @param bool $value + * @param bool $value * @return $this */ - public function dragDrop($value = true) + public function dragDrop(bool $value = true): static { $this->attributes['dragDrop'] = $value; @@ -65,10 +65,10 @@ public function dragDrop($value = true) } /** - * @param string $value + * @param string $value * @return $this */ - public function dragDropText($value) + public function dragDropText(string $value): static { $this->attributes['dragDropText'] = $value; @@ -76,10 +76,10 @@ public function dragDropText($value) } /** - * @param string $value + * @param string $value * @return $this */ - public function fileReadText($value) + public function fileReadText(string $value): static { $this->attributes['fileReadText'] = $value; @@ -87,10 +87,10 @@ public function fileReadText($value) } /** - * @param string $value + * @param string $value * @return $this */ - public function noFileText($value) + public function noFileText(string $value): static { $this->attributes['noFileText'] = $value; @@ -98,10 +98,10 @@ public function noFileText($value) } /** - * @param string $value + * @param string $value * @return $this */ - public function processingText($value) + public function processingText(string $value): static { $this->attributes['processingText'] = $value; @@ -109,10 +109,10 @@ public function processingText($value) } /** - * @param string $value + * @param string $value * @return $this */ - public function uploadText($value) + public function uploadText(string $value): static { $this->attributes['uploadText'] = $value; @@ -122,10 +122,10 @@ public function uploadText($value) /** * Set editor instance for file upload. * - * @param string $editor + * @param string $editor * @return $this */ - public function editor($editor) + public function editor(string $editor): static { $this->editor = $editor; @@ -137,16 +137,22 @@ public function editor($editor) * * @return $this */ - public function displayImage() + public function displayImage(): static { - return $this->display("function (file_id) { return file_id ? '' : null; }"); + // TODO: Use Laravel filesystem instead of hard coded storage path + return $this->display(<<\n"); + return new HtmlString("$script"); } /** * Get generated raw scripts. * * @return \Illuminate\Support\HtmlString - * @throws \Exception */ public function generateScripts(): HtmlString { $parameters = $this->generateJson(); return new HtmlString( - sprintf($this->template(), $this->getTableAttribute('id'), $parameters) + trim(sprintf($this->template(), $this->getTableAttribute('id'), $parameters)) ); } @@ -172,7 +170,7 @@ public function table(array $attributes = [], bool $drawFooter = false, bool $dr $th = $this->compileTableHeaders(); $htmlAttr = $this->html->attributes($this->tableAttributes); - $tableHtml = ''; + $tableHtml = ''; $searchHtml = $drawSearch ? ''.implode('', $this->compileTableSearchHeaders()).'' : ''; $tableHtml .= ''.implode('', $th).''.$searchHtml.''; diff --git a/src/Html/HasTable.php b/src/Html/HasTable.php index b324203..cf8ae7f 100644 --- a/src/Html/HasTable.php +++ b/src/Html/HasTable.php @@ -129,12 +129,19 @@ protected function compileTableHeaders(): array $th = []; $this->collection->each(function (Column $column) use (&$th) { - $thAttr = $this->html->attributes(array_merge( - Arr::only($column->toArray(), ['class', 'id', 'title', 'width', 'style', 'data-class', 'data-hide']), - $column->getAttributes(), + $only = Arr::only( + $column->toArray(), + ['class', 'id', 'title', 'width', 'style', 'data-class', 'data-hide'] + ); + + $attributes = array_merge( + $only, + $column->attributes, isset($column['titleAttr']) ? ['title' => $column['titleAttr']] : [] - )); - $th[] = ''; + ); + + $thAttr = $this->html->attributes($attributes); + $th[] = ''.$column['title'].''; }); return $th; diff --git a/tests/HtmlBuilderTest.php b/tests/HtmlBuilderTest.php index cdf28fc..3eb1304 100644 --- a/tests/HtmlBuilderTest.php +++ b/tests/HtmlBuilderTest.php @@ -1,159 +1,49 @@ getHtmlBuilder([ - 'class' => 'table', - 'id' => 'dataTableBuilder', - ]); - - $builder->html->shouldReceive('attributes')->times(10)->andReturn('id="foo"'); - - $builder->columns(['foo', 'bar' => ['data' => 'foo'], 'biz' => ['name' => 'baz']]) - ->addCheckbox(['id' => 'foo']) - ->addColumn(['name' => 'id', 'data' => 'id', 'title' => 'Id']) - ->addColumn(['data' => 'meh', 'title' => 'Muh']) - ->add(new Column(['name' => 'a', 'data' => 'a', 'title' => 'A'])) - ->addAction(['title' => 'Options']) - ->ajax('ajax-url') - ->parameters(['bFilter' => false]); - $table = $builder->table(['id' => 'foo'])->toHtml(); - $expected = '
'.$column['title'].'
FooBarBizIdMuhAOptions
'; - $this->assertEquals($expected, $table); - - $builder->view->shouldReceive('make')->times(2)->andReturn($builder->view); - $builder->config->shouldReceive('get')->times(2)->andReturn('datatables::script'); - $template = file_get_contents(__DIR__ . '/../src/resources/views/script.blade.php'); - $builder->view->shouldReceive('render')->times(2)->andReturn(trim($template)); - $builder->html->shouldReceive('attributes')->once()->andReturn(); - - $script = $builder->scripts()->toHtml(); - $expected = '' . "\n"; - $this->assertEquals($expected, $script); - - $expected = '$(function(){window.{{ config(\'datatables-html.namespace\', \'LaravelDataTables\') }}=window.{{ config(\'datatables-html.namespace\', \'LaravelDataTables\') }}||{};window.{{ config(\'datatables-html.namespace\', \'LaravelDataTables\') }}["foo"]=$("#foo").DataTable({"serverSide":true,"processing":true,"ajax":"ajax-url","columns":[{"name":"foo","data":"foo","title":"Foo","orderable":true,"searchable":true},{"name":"foo","data":"foo","title":"Bar","orderable":true,"searchable":true},{"name":"baz","data":"biz","title":"Biz","orderable":true,"searchable":true},{"defaultContent":"","title":"","data":"checkbox","name":"checkbox","orderable":false,"searchable":false,"width":"10px","id":"foo"},{"name":"id","data":"id","title":"Id","orderable":true,"searchable":true},{"data":"meh","title":"Muh","orderable":true,"searchable":true,"name":"meh"},{"name":"a","data":"a","title":"A","orderable":true,"searchable":true},{"defaultContent":"","data":"action","name":"action","title":"Options","render":null,"orderable":false,"searchable":false}],"bFilter":false});});'; - $this->assertEquals($expected, $builder->generateScripts()->toHtml()); - } - - /** - * @return \Mockery\MockInterface|\Yajra\DataTables\Html\Builder - */ - protected function getHtmlBuilder($config = []) - { - $builder = app('datatables.html', $config); - - return $builder; - } - - public function test_generate_table_html_with_empty_footer() + /** @test */ + public function it_can_resolved_builder_class() { - $builder = $this->getHtmlBuilder([ - 'class' => 'table', - 'id' => 'dataTableBuilder', - ]); - $builder->html->shouldReceive('attributes')->times(8)->andReturn('id="foo"'); - - $builder->columns(['foo', 'bar' => ['data' => 'foo']]) - ->addCheckbox(['id' => 'foo']) - ->addColumn(['name' => 'id', 'data' => 'id', 'title' => 'Id']) - ->add(new Column(['name' => 'a', 'data' => 'a', 'title' => 'A'])) - ->addAction(['title' => 'Options']) - ->ajax('ajax-url') - ->parameters(['bFilter' => false]); - $table = $builder->table(['id' => 'foo'], true)->toHtml(); - $expected = '
FooBarIdAOptions
'; - $this->assertEquals($expected, $table); - - $builder->view->shouldReceive('make')->times(2)->andReturn($builder->view); - $builder->config->shouldReceive('get')->times(2)->andReturn('datatables::script'); - $template = file_get_contents(__DIR__ . '/../src/resources/views/script.blade.php'); - $builder->view->shouldReceive('render')->times(2)->andReturn(trim($template)); - $builder->html->shouldReceive('attributes')->once()->andReturn(); + $builder = $this->getHtmlBuilder(); - $script = $builder->scripts()->toHtml(); - $expected = '' . "\n"; - $this->assertEquals($expected, $script); + $this->assertInstanceOf(Builder::class, $builder); - $expected = '$(function(){window.{{ config(\'datatables-html.namespace\', \'LaravelDataTables\') }}=window.{{ config(\'datatables-html.namespace\', \'LaravelDataTables\') }}||{};window.{{ config(\'datatables-html.namespace\', \'LaravelDataTables\') }}["foo"]=$("#foo").DataTable({"serverSide":true,"processing":true,"ajax":"ajax-url","columns":[{"name":"foo","data":"foo","title":"Foo","orderable":true,"searchable":true},{"name":"foo","data":"foo","title":"Bar","orderable":true,"searchable":true},{"defaultContent":"","title":"","data":"checkbox","name":"checkbox","orderable":false,"searchable":false,"width":"10px","id":"foo"},{"name":"id","data":"id","title":"Id","orderable":true,"searchable":true},{"name":"a","data":"a","title":"A","orderable":true,"searchable":true},{"defaultContent":"","data":"action","name":"action","title":"Options","render":null,"orderable":false,"searchable":false}],"bFilter":false});});'; - $this->assertEquals($expected, $builder->generateScripts()->toHtml()); + $builder = app('datatables.html'); + $this->assertInstanceOf(Builder::class, $builder); } - public function test_generate_table_html_with_footer_content() + /** @test */ + public function it_can_generate_table_html_and_scripts() { - $builder = $this->getHtmlBuilder([ - 'class' => 'table', - 'id' => 'dataTableBuilder', - ]); - $builder->html->shouldReceive('attributes')->times(8)->andReturn('id="foo"'); - - $builder->columns(['foo', 'bar' => ['data' => 'foo']]) - ->addCheckbox(['id' => 'foo', 'footer' => 'test']) - ->addColumn(['name' => 'id', 'data' => 'id', 'title' => 'Id']) - ->add(new Column(['name' => 'a', 'data' => 'a', 'title' => 'A'])) - ->addAction(['title' => 'Options']) - ->ajax('ajax-url') - ->parameters(['bFilter' => false]); - $table = $builder->table(['id' => 'foo'], true)->toHtml(); - $expected = '
FooBarIdAOptions
test
'; - $this->assertEquals($expected, $table); - - $builder->view->shouldReceive('make')->times(2)->andReturn($builder->view); - $builder->config->shouldReceive('get')->times(2)->andReturn('datatables::script'); - $template = file_get_contents(__DIR__ . '/../src/resources/views/script.blade.php'); - $builder->view->shouldReceive('render')->times(2)->andReturn(trim($template)); - $builder->html->shouldReceive('attributes')->once()->andReturn(); + $builder = $this->getHtmlBuilder(); - $script = $builder->scripts()->toHtml(); - $expected = '' . "\n"; - $this->assertEquals($expected, $script); + $builder->setTableId('foo-table') + ->columns([ + Column::make('foo'), + Column::make('baz'), + ]); - $expected = '$(function(){window.{{ config(\'datatables-html.namespace\', \'LaravelDataTables\') }}=window.{{ config(\'datatables-html.namespace\', \'LaravelDataTables\') }}||{};window.{{ config(\'datatables-html.namespace\', \'LaravelDataTables\') }}["foo"]=$("#foo").DataTable({"serverSide":true,"processing":true,"ajax":"ajax-url","columns":[{"name":"foo","data":"foo","title":"Foo","orderable":true,"searchable":true},{"name":"foo","data":"foo","title":"Bar","orderable":true,"searchable":true},{"defaultContent":"","title":"","data":"checkbox","name":"checkbox","orderable":false,"searchable":false,"width":"10px","id":"foo"},{"name":"id","data":"id","title":"Id","orderable":true,"searchable":true},{"name":"a","data":"a","title":"A","orderable":true,"searchable":true},{"defaultContent":"","data":"action","name":"action","title":"Options","render":null,"orderable":false,"searchable":false}],"bFilter":false});});'; - $this->assertEquals($expected, $builder->generateScripts()->toHtml()); - } + $table = $builder->table()->toHtml(); - public function test_generate_table_html_with_render_helpers() - { - $builder = $this->getHtmlBuilder([ - 'class' => 'table', - 'id' => 'dataTableBuilder', - ]); - - $builder->html->shouldReceive('attributes')->times(10)->andReturn('id="foo"'); - - $builder->columns(['foo', 'bar' => ['data' => 'foo'], 'biz' => ['name' => 'baz']]) - ->addCheckbox(['id' => 'foo']) - ->addColumn(['data' => '1.0000', 'title' => 'Num', 'render' => '$.fn.dataTable.render.number( ",", ".", 2, "" )']) - ->addColumn(['data' => '
', 'title' => 'Tex', 'render' => '$.fn.dataTable.render.text()']) - ->addAction(['title' => 'Options']) - ->ajax('ajax-url') - ->parameters(['bFilter' => false]); - $table = $builder->table(['id' => 'foo'])->toHtml(); - $expected = '
FooBarBizNumTexOptions
'; + $expected = '
FooBaz
'; $this->assertEquals($expected, $table); - $builder->view->shouldReceive('make')->times(2)->andReturn($builder->view); - $builder->config->shouldReceive('get')->times(2)->andReturn('datatables::script'); - $template = file_get_contents(__DIR__ . '/../src/resources/views/script.blade.php'); - $builder->view->shouldReceive('render')->times(2)->andReturn(trim($template)); - $builder->html->shouldReceive('attributes')->once()->andReturn(); - - $script = $builder->scripts()->toHtml(); - $expected = '' . "\n"; + $script = $builder->scripts()->toHtml(); + $expected = ''; $this->assertEquals($expected, $script); - $expected = '$(function(){window.{{ config(\'datatables-html.namespace\', \'LaravelDataTables\') }}=window.{{ config(\'datatables-html.namespace\', \'LaravelDataTables\') }}||{};window.{{ config(\'datatables-html.namespace\', \'LaravelDataTables\') }}["foo"]=$("#foo").DataTable({"serverSide":true,"processing":true,"ajax":"ajax-url","columns":[{"name":"foo","data":"foo","title":"Foo","orderable":true,"searchable":true},{"name":"foo","data":"foo","title":"Bar","orderable":true,"searchable":true},{"name":"baz","data":"biz","title":"Biz","orderable":true,"searchable":true},{"defaultContent":"","title":"","data":"checkbox","name":"checkbox","orderable":false,"searchable":false,"width":"10px","id":"foo"},{"data":"1.0000","title":"Num","render":"$.fn.dataTable.render.number( \",\", \".\", 2, \"\" )","orderable":true,"searchable":true,"name":"1.0000"},{"data":"","title":"Tex","render":"$.fn.dataTable.render.text()","orderable":true,"searchable":true,"name":""},{"defaultContent":"","data":"action","name":"action","title":"Options","render":null,"orderable":false,"searchable":false}],"bFilter":false});});'; + $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}]});});'; $this->assertEquals($expected, $builder->generateScripts()->toHtml()); } - public function test_setting_table_attribute() + /** @test */ + public function it_can_set_table_attribute() { $builder = $this->getHtmlBuilder(); @@ -162,7 +52,8 @@ public function test_setting_table_attribute() $this->assertEquals('val', $builder->getTableAttribute('attr')); } - public function test_setting_table_id_attribute() + /** @test */ + public function it_can_set_table_id_attribute() { $builder = $this->getHtmlBuilder(); @@ -171,7 +62,8 @@ public function test_setting_table_id_attribute() $this->assertEquals('val', $builder->getTableAttribute('id')); } - public function test_settings_multiple_table_attributes() + /** @test */ + public function it_can_set_multiple_table_attributes() { $builder = $this->getHtmlBuilder(); @@ -181,30 +73,34 @@ public function test_settings_multiple_table_attributes() $this->assertEquals('val2', $builder->getTableAttribute('prop2')); } - public function test_getting_inexistent_table_attribute_throws() + /** @test */ + public function it_can_get_inexistent_table_attribute_throws() { - $this->expectExceptionMessage('Table attribute \'boohoo\' does not exist.'); - $builder = $this->getHtmlBuilder(); - $builder->getTableAttribute('boohoo'); + $attr = $builder->getTableAttribute('boohoo'); + + $this->assertEmpty($attr); } - public function test_adding_table_class_attribute() + /** @test */ + public function it_can_add_table_class_attribute() { $builder = $this->getHtmlBuilder(); + $this->assertEquals('table', $builder->getTableAttribute('class')); $builder->addTableClass('foo'); - $this->assertEquals('foo', $builder->getTableAttribute('class')); + $this->assertEquals('table foo', $builder->getTableAttribute('class')); $builder->addTableClass(' foo bar '); - $this->assertEquals('foo bar', $builder->getTableAttribute('class')); + $this->assertEquals('table foo bar', $builder->getTableAttribute('class')); $builder->addTableClass([' a-b ', 'foo c bar', 'key' => 'value']); - $this->assertEquals('foo bar a-b c value', $builder->getTableAttribute('class')); + $this->assertEquals('table foo bar a-b c value', $builder->getTableAttribute('class')); } - public function test_removing_table_class_attribute() + /** @test */ + public function it_can_remove_table_class_attribute() { $builder = $this->getHtmlBuilder(); $builder->setTableAttribute('class', ' foo bar a b c '); @@ -220,12 +116,10 @@ public function test_removing_table_class_attribute() } /** - * @return \Yajra\DataTables\Factory + * @return \Yajra\DataTables\Html\Builder */ - protected function getDataTables() + protected function getHtmlBuilder(): Builder { - $factory = new Factory; - - return $factory; + return app(Builder::class); } } diff --git a/tests/TestCase.php b/tests/TestCase.php new file mode 100644 index 0000000..c6263de --- /dev/null +++ b/tests/TestCase.php @@ -0,0 +1,32 @@ +set('app.debug', true); + $app['config']->set('database.default', 'sqlite'); + $app['config']->set('database.connections.sqlite', [ + 'driver' => 'sqlite', + 'database' => ':memory:', + 'prefix' => '', + ]); + } + + protected function getPackageProviders($app): array + { + return [ + \Yajra\DataTables\DataTablesServiceProvider::class, + \Yajra\DataTables\HtmlServiceProvider::class, + ]; + } +} diff --git a/tests/helper.php b/tests/helper.php index 95fe360..ed0381c 100644 --- a/tests/helper.php +++ b/tests/helper.php @@ -1,5 +1,7 @@ Date: Sat, 7 May 2022 15:01:29 +0800 Subject: [PATCH 012/260] Alias to 5.0 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 0bfe62d..c986e52 100644 --- a/composer.json +++ b/composer.json @@ -37,7 +37,7 @@ }, "extra": { "branch-alias": { - "dev-master": "4.0-dev" + "dev-master": "5.0-dev" }, "laravel": { "providers": [ From 0507a6a7f6b21c5f01028d6a3d775b77b23cb8f2 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Sat, 7 May 2022 15:02:19 +0800 Subject: [PATCH 013/260] Remove unused helper --- tests/helper.php | 63 ------------------------------------------------ 1 file changed, 63 deletions(-) delete mode 100644 tests/helper.php diff --git a/tests/helper.php b/tests/helper.php deleted file mode 100644 index ed0381c..0000000 --- a/tests/helper.php +++ /dev/null @@ -1,63 +0,0 @@ -shouldReceive('get')->andReturn($config); - - return new Builder( - $configMock, - m::mock('Illuminate\Contracts\View\Factory'), - m::mock('Collective\Html\HtmlBuilder') - ); - case 'config': - return new Config; - case 'view': - return m::mock('Illuminate\Contracts\View\Factory', function ($mock) { - $mock->shouldReceive('exists')->andReturn(false); - }); - } - - return new Factory(); -} - -function view($view = null, array $data = []) -{ - if (! $view) { - return new BladeView(); - } - - return (new BladeView())->exists($view); -} - -/** - * Blade View Stub. - */ -class BladeView -{ - public function exists($view) - { - return false; - } -} - -class Config -{ - public function get($key) - { - $keys = explode('.', $key); - $config = require __DIR__ . '/../src/config/config.php'; - $config['builders'] = Arr::add($config['builders'], 'Mockery_8_Illuminate_Database_Query_Builder', 'query'); - - return $config[$keys[1]]; - } -} From dde6a9ecd417a966888789d00519d94835a12863 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Sat, 7 May 2022 15:05:44 +0800 Subject: [PATCH 014/260] Log v5 changes --- CHANGELOG.md | 769 +-------------------------------------------------- README.md | 9 +- 2 files changed, 13 insertions(+), 765 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 99a5bba..745d318 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,768 +8,9 @@ ## CHANGELOG -### v4.41.1 - 03-05-2022 +### v5.0.0 - UNRELEASED -- Fix Field::attr() doc block. - -### v4.41.0 - 10-07-2021 - -- Add exportFormat method. #160 - -### v4.40.0 - 10-04-2021 - -- Add method getTableId() #159 - -### v4.39.1 - 09-12-2021 - -- Fix doc block and add array as acceptable Column editField value. - -### v4.39.0 - 09-12-2021 - -- Add missing select field options as of Editor 1.5.4. - -### v4.38.0 - 06-20-2021 - -- Fix fetching of editor table #158 -- Add method to get all editors instances. -- Add method to get dataTable options array. -- Set serverSide and processing option as true by default. - -### v4.37.0 - 05-17-2021 - -- Implement authorizations on Editor builder. - -### v4.36.3 - 04-23-2021 - -- Fix conflicts with createInline button. Use render instead of altering the data. - -### v4.36.2 - 03-19-2021 - -- Fix exportable flag, should be false. - -### v4.36.1 - 12-05-2020 - -- Fix adding of class on Select plugin / extension. [#154] - -### v4.36.0 - 11-14-2020 - -- Add drawCallbackWithLivewire api. -- Solution as per issue https://github.com/yajra/laravel-datatables/issues/2401. - -### v4.35.2 - 11-14-2020 - -- Add missing button options as per [docs](https://datatables.net/reference/option/#buttons). - -### v4.35.1 - 11-03-2020 - -- Add missing upload field options as per doc. [#152] - -### v4.35.0 - 11-03-2020 - -- Add formatted column factory. [#147] - -### v4.34.0 - 10-31-2020 - -- Add support for search panes extension. [#137] - -### v4.33.0 - 10-30-2020 - -- Make LaravelDataTables javascript namespace configurable. [#145], credits to @om3rcitak - -### v4.32.0 - 10-10-2020 - -- Add function argument to override the default options from php scripts. [#144] - -### v4.31.0 - 10-09-2020 - -- Add button customize option value. [#142], credits to @gredimano -- Fix https://github.com/yajra/laravel-datatables/issues/1541 -- Add template and method to wrap scripts with a function. [#143] - -### v4.30.3 - 10-06-2020 - -- Wait for DOM before executing script using jQuery [#138] -- Fix [#133] - -### v4.30.2 - 10-06-2020 - -- Fix chrome bfcache issue with editor. [#139], credits to @jiwom -- Allow using callbacks as a data value. [#127], credits to @mgralikowski - -### v4.30.1 - 09-29-2020 - -- Fix [#134] laravel 8 dependencies [#135], credits to @dyanakiev. - -### v4.30.0 - 06-18-2020 - -- Add button align property setter. - -### v4.29.0 - 06-17-2020 - -- Add column responsive priority setter. [#131], credits to @SamDeimos. - -### v4.28.0 - 06-10-2020 - -- Allow eloquent builder instance on BelongsTo model field. - -### v4.27.0 - 05-29-2020 - -- Add renderRaw method to set render value as is. - -### v4.26.1 - 05-29-2020 - -- Fix array listing and allow customer separator. - -### v4.26.0 - 05-29-2020 - -- Add support for comma separated list from an array of objects. - -### v4.25.1 - 04-17-2020 - -- Fix PR [#125]. - -### v4.25.0 - 04-17-2020 - -- HTML title for columns labels [#125], credits to @mgralikowski. - -### v4.24.0 - 04-02-2020 - -- Add TextArea rows & cols fluent attribute setter. - -### v4.23.1 - 03-04-2020 - -- Improve addClass method. [#117], credits to @matteocostantini. - -### v4.23.0 - 03-04-2020 - -- Allow Laravel 7 [#124], credits to @barryvdh. - -### v4.22.0 - 03-03-2020 - -- Add shortcut method `hidden` to hide column instead of `visible(false)`. - -### v4.21.1 - 02-21-2020 - -- Use full url on ajax if not set. [#122] -- Fix [yajra/laravel-datatables#2322](https://github.com/yajra/laravel-datatables/issues/2322). -- Fix [#121] - -### v4.21.0 - 02-18-2020 - -- Add editor button formMessage and formTitle fluent setter. - -### v4.20.2 - 02-17-2020 - -- Fix export function not working when base url is set on header. - -### v4.20.1 - 11-11-2019 - -- Fix substring to substr [#116]. - -### v4.20.0 - 11-11-2019 - -- Improve adding custom action to buttons. [#114], credits to @om3rcitak. - -### v4.19.4 - 10-02-2019 - -- Fix serialization of renderJs parameters. [#110] -- Allow array parameter on buttons option for api consistency. [#111] -- Allow array parameter on editors option for api consistency. [#112] - -### v4.19.3 - 09-27-2019 - -- Fix Button class doc return type to static. - -### v4.19.2 - 09-27-2019 - -- Fix authorization options to allow null. - -### v4.19.1 - 09-27-2019 - -- Fix missing button name attr setter. - -### v4.19.0 - 09-25-2019 - -- Add Editor formOptions setter as per docs: https://editor.datatables.net/reference/option/formOptions. - -### v4.18.2 - 09-25-2019 - -- Fix ajax data if value is an array. - -### v4.18.1 - 09-25-2019 - -- Add ajax url setter. -- Fix ajax option if array was passed. - -### v4.18.0 - 09-23-2019 - -- Add makeIfCannot authorization. - -```php -Field\Text::makeIfCannot('evaluate', 'evaluator_id')->data('evaluator.name')... -``` - -### v4.17.0 - 09-23-2019 - -- Add support for Field class authorizations. -- Fix doc blocks and phpstorm warnings. - -```php -Field\Select::makeIfCan('evaluate', 'evaluator_id')... -Field\Select::makeIf(true, 'evaluator_id')... -Field\Select::makeIf(function() { return true; }, 'evaluator_id')... -``` - -### v4.16.0 - 09-20-2019 - -- Add action script helpers. -- New actions: `actionSubmit(), actionClose(), actionHandler('editor-method-handler')` - -```php -Button::make('edit') - ->editor('evaluator') - ->text(' Evaluate') - ->formButtons([ - Button::raw('Approve') - ->className('btn btn-success ml-2') - ->actionHandler('approve'), - Button::raw('Decline') - ->className('btn btn-danger ml-2') - ->actionHandler('decline'), - Button::raw('Cancel') - ->className('btn btn-secondary ml-2') - ->actionClose(), - ]) - ->className('btn-success'), -``` - -- Add missing formButtons and action setter. -- Add raw buttons factory. - -```php -Button::make('edit') - ->editor('approver') - ->text(' Approve Leave') - ->formButtons([ - Button::raw('Approve') - ->className('btn btn-success') - ->action('function() { this.submit(); }'), - Button::raw('Cancel') - ->className('btn btn-secondary ml-2') - ->action('function() { this.close(); }'), - ]) - ->className('btn-success'), -``` - -### v4.14.2 - 09-17-2019 - -- Add missing Button buttons setter. - -### v4.14.1 - 09-16-2019 - -- Fix Number field and set type attr to number. -- Add missing attr setter. -- Fix doc blocks for better IDE support. - -### v4.14.0 - 09-16-2019 - -- Add more dateTime opts setter. - -### v4.13.0 - 09-14-2019 - -- Add renderJs ability to pass parameter to js from php argument. -- `->renderJs('prefix', 'hrs')` == `->renderJs('prefix("hrs")')` - -### v4.12.0 - 09-14-2019 - -- Add renderJs helper to use the built-in and custom renderer. -- Ex: `->renderJs("boolean()")`, `->renderJs("number()")`. - -### v4.11.0 - 09-13-2019 - -- Add select2 ajax option support. [#109] - -### v4.10.1 - 09-10-2019 - -- Remove editor dependency when display the image. -- Fix js issue when editing. - -### v4.10.0 - 09-10-2019 - -- Fix displaying of uploaded image preview. -- Add File editor instance setter. - -### v4.9.0 - 09-10-2019 - -- Add File and Image editor fields. [#108] - -### v4.8.0 - 09-04-2019 - -- Add support Laravel 6.0 & remove deprecated functions [#107], credits to @sangnguyenplus. - -### v4.7.1 - 08-31-2019 - -- Unset editor events key when serializing to array or json. -- Fix editor events script builder. - -### v4.7.0 - 08-29-2019 - -- Add BelongsTo field builder. - -```php -BelongsTo::model(Model::class, 'name') -``` - -### v4.6.0 - 08-29-2019 - -- Return static on Field for better IDE support. -- Add initial support for Select2 editor plugin. - -### v4.5.4 - 08-22-2019 - -- Add missing buttons columns & exportOptions setter. - -### v4.5.3 - 08-17-2019 - -- Fix error when no editor fields was defined. [52f0537c5913c84fb5e8a58bbd7db142b987daaf](https://github.com/yajra/laravel-datatables-html/commit/52f0537c5913c84fb5e8a58bbd7db142b987daaf) -- Return false when validating callback value is an array or an object. [b76cdf806c85368fce70a9034153dec6e107dd2f](https://github.com/yajra/laravel-datatables-html/commit/52f0537c5913c84fb5e8a58bbd7db142b987daaf) - -### v4.5.2 - 08-13-2019 - -- Fix [#102] language key and use i18n. [#103], credits to @matteocostantini. - -### v4.5.1 - 07-05-2019 - -- Add fluent column footer setter. [#101] - -### v4.5.0 - 06-27-2019 - -- Add ability to generate dataTables options for external js use. [#99] - -### v4.4.1 - 04-25-2019 - -- Add title attribute for table headers. [#94], credits to @HOFFMACHINE. - - -### v4.4.0 - 02-27-2019 - -- Add support for Laravel 5.8 / DataTables v9.0 [#90]. - -### v4.3.2 - 02-05-2019 - -- Avoid call parseRender when render attribute is null. [#87] credits to @JulianBustamante. - -### v4.3.1 - 11-21-2018 - -- Allow null string computed column title. - -### v4.3.0 - 11-21-2018 - -#### Added - -- Builder Support for the following plugins: - -- [x] AutoFill -- [x] ColReorder -- [x] FixedColumns -- [x] FixedHeader -- [x] KeyTable -- [x] Responsive -- [x] RowGroup -- [x] RowReorder -- [x] Scroller -- [x] Select - -- Builder Support for setting the language: - -- [x] Language -- [x] Language\Aria -- [x] Language\AutoFill -- [x] Language\Paginate -- [x] Language\Select - -- Add missing column option setters: - -- [x] data -- [x] orderData -- [x] orderDataType -- [x] orderSequence -- [x] cellType -- [x] type -- [x] contentPadding -- [x] createdCell -- [x] editField - -### v4.2.1 - 11-21-2018 - -- Fix computed column title if nothing is set. - -### v4.2.0 - 11-20-2018 - -- Add ajaxWithForm api to process dataTables with form data. [#86] - -### v4.1.0 - 11-16-2018 - -- Add full Editor events script builder as per https://editor.datatables.net/reference/event/. - -```php -Editor::make('create') - ->on('create', 'js-script-here') - ->onCreate('js-script-here') // event via magic method. - ->fields([ - Fields\Text::make('name'), - Fields\Text::make('email'), - ]); -``` - -- Add missing `idSrc` Editor option setter. -- Add missing `display` Editor option setter. - -> NOTE: You need to force [publish](https://github.com/yajra/laravel-datatables-html#publish-assets-optional) the blade templates to be able to use the features if needed. - -### v4.0.0 - 11-14-2018 - -#### ADDED - -Add full builder support for the following options based on https://datatables.net/reference/option/. - -##### Add builder support for the following plugins: - -- [x] AutoFill -- [x] Buttons -- [x] ColReorder -- [x] FixedColumns -- [x] FixedHeader -- [x] KeyTable -- [x] Responsive -- [x] RowGroup -- [x] RowReorder -- [x] Scroller -- [x] Select - -> Note: All plugins requires their corresponding asset files. - -##### Add Buttons builder with support for authorization. - -```php -->buttons( - Button::makeIfCan('manage-users', 'create')->editor('editor'), - Button::makeIf(true, 'edit')->editor('editor'), - Button::make('remove')->editor('editor')->className('btn-danger'), - Button::make('colvis')->text(''), - Button::make('export'), - Button::make('print'), - Button::make('reset'), - Button::make('reload') -) -``` - -#### CHANGED - -- `Editor` class was moved from `Yajra\DataTables\Html\Editor` to `Yajra\DataTables\Html\Editor\Editor`. -- All fields were moved from `Yajra\DataTables\Html\Editor` to `Yajra\DataTables\Html\Editor\Fields` namespace. - -### v3.13.0 - 11-10-2018 - -- Add missing visible option setter. [#83] -- Add new fields, fix dateTime field format. [#84] - -#### Changed - -- Fix field and column computed title. - -From `created_at` with title `Created_At` -To `created_at` with title `Created At` - -#### Fixed - -- Fix DateTime field. -- Set format to `YYYY-MM-DD hh:mm a`. -- Add `military()` setter to set the time to military format. - -#### Added New Fields - -- Boolean -- Date -- Time -- Text -- Number - -### v3.12.7 - 11-03-2018 - -- Add checker if className is not yet set when adding class. - -### v3.12.6 - 11-03-2018 - -- Fix setting of title. -- Add title option for checkbox column. - -### v3.12.5 - 11-03-2018 - -- Add name arg for computed column. - -### v3.12.4 - 11-03-2018 - -- Fix options: Use 1 and 0 for true or false. - -### v3.12.3 - Skipped (My Bad) - -### v3.12.2 - 11-03-2018 - -- Add missing field options setter and add docs link. - -### v3.12.1 - 11-03-2018 - -- Add to method to append a class to the field. - -### v3.12.0 - 11-03-2018 - -- Add editor options collection builder. [#80] - -### v3.11.0 - 11-02-2018 - -- Add option to prepend action column. [#77] -- Enhance column fluent builder. [#78] - -### v3.10.0 - 11-02-2018 - -- Add support for DataTables Editor script generation. [#73] -- Fix script template config key `datatables-html.script`. -- Add method to `getAjaxUrl()`. - -### v3.9.0 - 11-02-2018 - -- Add support for [built-in render helpers](https://datatables.net/manual/data/renderers#Built-in-helpers). [#71], credits to @Razoxane. - -### v3.8.1 - 10-30-2018 - -- Fix the default name of index column to follow DT syntax. [#69], credits to @jaydons. -- Fix missing periods. [#70], credits to @jaydons. - -### v3.8.0 - 09-05-2018 - -- Add support for Laravel 5.7 - -### v3.7.2 - 07-06-2018 - -- Fix callback check on empty values. [#62] Credits to @apreiml. - -### v3.7.1 - 03-16-2018 - -- Add parameter in addCheckbox to prepend or append the checkbox column [#55], credits to @karmendra - -### v3.7.0 - 02-21-2018 - -- Adding ajaxParameters to minifiedAjax [#57], credits to @lk77 -- Fixes the issue with the missing name attribute default mentioned in [#58]. PR [#59], credits to @Namoshek - -### v3.6.0 - 02-11-2018 - -- Add support for Laravel 5.6. [#56] - -### v3.5.2 - 01-11-2018 - -- Moving callback condition to config [#54], credits to @lk77. - -### v3.5.1 - 12-27-2017 - -- Allow jQuery functions callback. [#52], credits to @OzanKurt. - -### v3.5.0 - 12-24-2017 - -- Improve handling of function callbacks and better editor support. [#49] - -### v3.4.0 - 12-18-2017 - -- Implement buttons support for editor. [#47] - -### v3.3.0 - 12-15-2017 - -- Add postAjax() to Html Builder [#45], credits to @ElfSundae. -- Fix https://github.com/yajra/laravel-datatables-html/pull/13#issuecomment-337947000. - -### v3.2.1 - 10-18-2017 - -- Fix HtmlServiceProvider. [#38], credits to @ElfSundae. -- Fix changelog PR links. [#39] - -### v3.2.0 - 10-13-2017 - -- Review tableAttributes getter and setter [#31] -- Fix CS. [#36] -- Add setTableId() to Html Builder [#35]. -- Add addTableClass, removeTableClass to Html Builder [#37] -- All changes credits to @ElfSundae. - -### v3.1.0 - 09-14-2017 - -- Added generateJson to Html/Builder [#29], credits to @lk77. - -### v3.0.3 - 09-12-2017 - -- Fix column attributes removed when generate script. [#28], credits to @as247. -- Fix https://github.com/yajra/laravel-datatables/issues/1380. - -### v3.0.2 - 09-09-2017 - -- Fix Request class doc blocks. -- Fix typo Datatables to DataTables. - -### v3.0.1 - 09-09-2017 - -- Add fnServerParams to validCallbacks [#26]. Credits to @cracki. - -### v3.0.0 - 08-31-2017 - -- v3.0 stable release. - -### v2.0.6 - 07-29-2017 - -- Adding type GET to minifiedAjax in Html/Builder [#21], credits to @lk77. - -### v2.0.5 - 06-29-2017 - -- Fix fetching of default table id from config. [#19] - -### v2.0.4 - 06-29-2017 - -- Fix missing semi-colon. - -### v2.0.3 - 06-29-2017 - -- Script cleanup [#18] -- Clean up extra space and floating ; on generated ajax data script. -- Do not include attributes on generated column scripts. - -### v2.0.2 - 06-29-2017 - -- Fix parsing of column functions. [#17] - -### v2.0.1 - 06-29-2017 - -- Fix parsing of ajax data where function is rendered as string. [#16] - -### v2.0.0 - 06-28-2017 - -- Add support for Laravel 5.5 -- Removed unused classes on constructor. - - UrlGenerator - - FormBuilder -- Fix addCheckbox. -- Use HtmlString when generating table and scripts markup. -- Make default table attributes configurable. Fix [#3] -- Use PHPUNIT 6.x, update tests. -- Add macroable trait for builder extension via macro calls. - -### v1.4.1 - 06-26-2017 - -- Set default ajax url to empty string. - -### v1.4.0 - 06-26-2017 - -- Add minifiedAjax method to minify url generated when using get request. [#13] -- Fixes `php artisan serve` and IE issues on long URL. -- Related Issues: - yajra/laravel-datatables#1225 - yajra/laravel-datatables#1205 - yajra/laravel-datatables#826 - yajra/laravel-datatables#671 - etc... - -### v1.3.0 - 06-24-2017 - -- Adding addBefore and addColumnBefore in Builder. -- PR [#12], credits to @lk77. - -### v1.2.0 - 03-28-2017 - -- Add method to remove column by names. [#9] - -### v1.1.1 - 03-28-2017 - -- Fix columns setter. [#8] - -### v1.1.0 - 02-03-2017 - -- Configurable header attributes. [#4] -- Credits to @alfa6661. - -### v1.0.0 - 01-27-2017 - -- First release. - -[#4]: https://github.com/yajra/laravel-datatables-html/pull/4 -[#8]: https://github.com/yajra/laravel-datatables-html/pull/8 -[#9]: https://github.com/yajra/laravel-datatables-html/pull/9 -[#12]: https://github.com/yajra/laravel-datatables-html/pull/12 -[#13]: https://github.com/yajra/laravel-datatables-html/pull/13 -[#16]: https://github.com/yajra/laravel-datatables-html/pull/16 -[#17]: https://github.com/yajra/laravel-datatables-html/pull/17 -[#18]: https://github.com/yajra/laravel-datatables-html/pull/18 -[#19]: https://github.com/yajra/laravel-datatables-html/pull/19 -[#21]: https://github.com/yajra/laravel-datatables-html/pull/21 -[#26]: https://github.com/yajra/laravel-datatables-html/pull/26 -[#28]: https://github.com/yajra/laravel-datatables-html/pull/28 -[#29]: https://github.com/yajra/laravel-datatables-html/pull/29 -[#31]: https://github.com/yajra/laravel-datatables-html/pull/31 -[#35]: https://github.com/yajra/laravel-datatables-html/pull/35 -[#36]: https://github.com/yajra/laravel-datatables-html/pull/36 -[#37]: https://github.com/yajra/laravel-datatables-html/pull/37 -[#38]: https://github.com/yajra/laravel-datatables-html/pull/38 -[#39]: https://github.com/yajra/laravel-datatables-html/pull/39 -[#47]: https://github.com/yajra/laravel-datatables-html/pull/47 -[#49]: https://github.com/yajra/laravel-datatables-html/pull/49 -[#52]: https://github.com/yajra/laravel-datatables-html/pull/52 -[#54]: https://github.com/yajra/laravel-datatables-html/pull/54 -[#56]: https://github.com/yajra/laravel-datatables-html/pull/56 -[#57]: https://github.com/yajra/laravel-datatables-html/pull/57 -[#59]: https://github.com/yajra/laravel-datatables-html/pull/59 -[#55]: https://github.com/yajra/laravel-datatables-html/pull/55 -[#62]: https://github.com/yajra/laravel-datatables-html/pull/62 -[#69]: https://github.com/yajra/laravel-datatables-html/pull/69 -[#70]: https://github.com/yajra/laravel-datatables-html/pull/70 -[#71]: https://github.com/yajra/laravel-datatables-html/pull/71 -[#73]: https://github.com/yajra/laravel-datatables-html/pull/73 -[#77]: https://github.com/yajra/laravel-datatables-html/pull/77 -[#78]: https://github.com/yajra/laravel-datatables-html/pull/78 -[#80]: https://github.com/yajra/laravel-datatables-html/pull/80 -[#83]: https://github.com/yajra/laravel-datatables-html/pull/83 -[#84]: https://github.com/yajra/laravel-datatables-html/pull/84 -[#86]: https://github.com/yajra/laravel-datatables-html/pull/86 -[#87]: https://github.com/yajra/laravel-datatables-html/pull/87 -[#90]: https://github.com/yajra/laravel-datatables-html/pull/90 -[#94]: https://github.com/yajra/laravel-datatables-html/pull/94 -[#99]: https://github.com/yajra/laravel-datatables-html/pull/99 -[#101]: https://github.com/yajra/laravel-datatables-html/pull/101 -[#103]: https://github.com/yajra/laravel-datatables-html/pull/103 -[#107]: https://github.com/yajra/laravel-datatables-html/pull/107 -[#108]: https://github.com/yajra/laravel-datatables-html/pull/108 -[#109]: https://github.com/yajra/laravel-datatables-html/pull/109 -[#110]: https://github.com/yajra/laravel-datatables-html/pull/110 -[#111]: https://github.com/yajra/laravel-datatables-html/pull/111 -[#112]: https://github.com/yajra/laravel-datatables-html/pull/112 -[#114]: https://github.com/yajra/laravel-datatables-html/pull/114 -[#116]: https://github.com/yajra/laravel-datatables-html/pull/116 -[#122]: https://github.com/yajra/laravel-datatables-html/pull/122 -[#124]: https://github.com/yajra/laravel-datatables-html/pull/124 -[#117]: https://github.com/yajra/laravel-datatables-html/pull/117 -[#125]: https://github.com/yajra/laravel-datatables-html/pull/125 -[#131]: https://github.com/yajra/laravel-datatables-html/pull/131 -[#135]: https://github.com/yajra/laravel-datatables-html/pull/135 -[#127]: https://github.com/yajra/laravel-datatables-html/pull/127 -[#139]: https://github.com/yajra/laravel-datatables-html/pull/139 -[#138]: https://github.com/yajra/laravel-datatables-html/pull/138 -[#133]: https://github.com/yajra/laravel-datatables-html/pull/133 -[#142]: https://github.com/yajra/laravel-datatables-html/pull/142 -[#143]: https://github.com/yajra/laravel-datatables-html/pull/143 -[#144]: https://github.com/yajra/laravel-datatables-html/pull/144 -[#137]: https://github.com/yajra/laravel-datatables-html/pull/137 -[#147]: https://github.com/yajra/laravel-datatables-html/pull/147 -[#152]: https://github.com/yajra/laravel-datatables-html/pull/152 -[#154]: https://github.com/yajra/laravel-datatables-html/pull/154 - -[#134]: https://github.com/yajra/laravel-datatables-html/issues/134 -[#3]: https://github.com/yajra/laravel-datatables-html/issues/3 -[#58]: https://github.com/yajra/laravel-datatables-html/issues/58 -[#102]: https://github.com/yajra/laravel-datatables-html/issues/102 -[#121]: https://github.com/yajra/laravel-datatables-html/issues/121 +- Add Laravel 9 support +- Remove Laravel 8 and below support +- Add phpstan static analysis +- Improve tests \ No newline at end of file diff --git a/README.md b/README.md index 2072a3b..6aeb917 100644 --- a/README.md +++ b/README.md @@ -17,8 +17,15 @@ This package is a plugin of [Laravel DataTables](https://github.com/yajra/larave - [Laravel DataTables Documentation](http://yajrabox.com/docs/laravel-datatables) - [Demo Application](http://datatables.yajrabox.com) is available for artisan's reference. +## Laravel Version Compatibility + +| Laravel | Package | +|:--------------|:--------| +| 8.x and below | 4.x | +| 9.x | 5.x | + ## Quick Installation -`composer require yajra/laravel-datatables-html:^4.0` +`composer require yajra/laravel-datatables-html:^5.0` #### Service Provider (Optional on Laravel 5.5+) `Yajra\DataTables\HtmlServiceProvider::class` From a06c93d317217e1747ffc2f10b7b3119b297d140 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Sat, 7 May 2022 15:15:49 +0800 Subject: [PATCH 015/260] Add table id config test --- README.md | 5 +++++ src/Html/HasTable.php | 1 - tests/HtmlBuilderTest.php | 10 ++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6aeb917..36277bf 100644 --- a/README.md +++ b/README.md @@ -10,10 +10,12 @@ This package is a plugin of [Laravel DataTables](https://github.com/yajra/laravel-datatables) for generating dataTables script using PHP. ## Requirements + - [Laravel 5.4+](https://github.com/laravel/framework) - [Laravel DataTables v7.x|v8.x|9.x](https://github.com/yajra/laravel-datatables) ## Documentations + - [Laravel DataTables Documentation](http://yajrabox.com/docs/laravel-datatables) - [Demo Application](http://datatables.yajrabox.com) is available for artisan's reference. @@ -25,12 +27,15 @@ This package is a plugin of [Laravel DataTables](https://github.com/yajra/larave | 9.x | 5.x | ## Quick Installation + `composer require yajra/laravel-datatables-html:^5.0` #### Service Provider (Optional on Laravel 5.5+) + `Yajra\DataTables\HtmlServiceProvider::class` #### Publish Assets (Optional) + `$ php artisan vendor:publish --tag=datatables-html` And that's it! Start building out some awesome DataTables! diff --git a/src/Html/HasTable.php b/src/Html/HasTable.php index cf8ae7f..4ae6bd0 100644 --- a/src/Html/HasTable.php +++ b/src/Html/HasTable.php @@ -42,7 +42,6 @@ public function setTableId(string $id): static * Get HTML table "id" attribute. * * @return string - * @throws \Exception */ public function getTableId(): string { diff --git a/tests/HtmlBuilderTest.php b/tests/HtmlBuilderTest.php index 3eb1304..f4ddea8 100644 --- a/tests/HtmlBuilderTest.php +++ b/tests/HtmlBuilderTest.php @@ -18,6 +18,16 @@ public function it_can_resolved_builder_class() $this->assertInstanceOf(Builder::class, $builder); } + /** @test */ + public function it_can_read_table_id_from_config() + { + $this->assertEquals('dataTableBuilder', $this->getHtmlBuilder()->getTableId()); + + config()->set('datatables-html.table.id', 'test'); + + $this->assertEquals('test', $this->getHtmlBuilder()->getTableId()); + } + /** @test */ public function it_can_generate_table_html_and_scripts() { From db9ff5f32c034756dad9437f1ac4b2b0c0d43329 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Sat, 7 May 2022 15:24:06 +0800 Subject: [PATCH 016/260] Add namespace test --- tests/HtmlBuilderTest.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/HtmlBuilderTest.php b/tests/HtmlBuilderTest.php index f4ddea8..923fa85 100644 --- a/tests/HtmlBuilderTest.php +++ b/tests/HtmlBuilderTest.php @@ -28,6 +28,18 @@ public function it_can_read_table_id_from_config() $this->assertEquals('test', $this->getHtmlBuilder()->getTableId()); } + /** @test */ + public function it_can_change_namespace() + { + $builder = $this->getHtmlBuilder(); + + $this->assertStringContainsString('LaravelDataTables', $builder->scripts()->toHtml()); + + config()->set('datatables-html.namespace', 'TestDataTables'); + + $this->assertStringContainsString('TestDataTables', $builder->scripts()->toHtml()); + } + /** @test */ public function it_can_generate_table_html_and_scripts() { From b35294afb9b2e61d84fb4a484d2b52784bc42dc8 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Sat, 7 May 2022 15:43:14 +0800 Subject: [PATCH 017/260] Add Editor test --- src/Html/Editor/Editor.php | 9 +++--- tests/EditorTest.php | 59 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 4 deletions(-) create mode 100644 tests/EditorTest.php diff --git a/src/Html/Editor/Editor.php b/src/Html/Editor/Editor.php index 5530852..da7b246 100644 --- a/src/Html/Editor/Editor.php +++ b/src/Html/Editor/Editor.php @@ -9,15 +9,19 @@ use Yajra\DataTables\Utilities\Helper; /** + * @property string $instance * @property string|null $table * @property string|array|null $ajax - * @property array $events + * @property array $fields + * @property string|null $template */ class Editor extends Fluent { use HasEvents; use HasAuthorizations; + public array $events = []; + const DISPLAY_LIGHTBOX = 'lightbox'; const DISPLAY_ENVELOPE = 'envelope'; const DISPLAY_BOOTSTRAP = 'bootstrap'; @@ -167,7 +171,6 @@ public function formOptions(array $formOptions): static * * @param array $formOptions * @return $this - * @throws \Yajra\DataTables\Exceptions\Exception * @see https://editor.datatables.net/reference/option/formOptions.bubble */ public function formOptionsBubble(array $formOptions): static @@ -180,7 +183,6 @@ public function formOptionsBubble(array $formOptions): static * * @param array $formOptions * @return $this - * @throws \Yajra\DataTables\Exceptions\Exception * @see https://editor.datatables.net/reference/option/formOptions.inline */ public function formOptionsInline(array $formOptions): static @@ -193,7 +195,6 @@ public function formOptionsInline(array $formOptions): static * * @param array $formOptions * @return $this - * @throws \Yajra\DataTables\Exceptions\Exception * @see https://editor.datatables.net/reference/option/formOptions.main */ public function formOptionsMain(array $formOptions): static diff --git a/tests/EditorTest.php b/tests/EditorTest.php new file mode 100644 index 0000000..8adcfa4 --- /dev/null +++ b/tests/EditorTest.php @@ -0,0 +1,59 @@ +getEditor(); + + $this->assertInstanceOf(Editor::class, $editor); + $this->assertEquals('editor', $editor->instance); + $this->assertEmpty($editor->fields); + $this->assertEmpty($editor->ajax); + $this->assertEmpty($editor->template); + + $editor + ->fields([ + Text::make('name'), + ]) + ->ajax('/test') + ->template('#template'); + + $this->assertCount(1, $editor->fields); + $this->assertEquals('/test', $editor->ajax); + $this->assertEquals('#template', $editor->template); + } + + /** @test */ + public function it_can_have_events() + { + $editor = $this->getEditor(); + + $editor->onPostSubmit('post'); + $editor->onDisplayOrder('display'); + + $this->assertCount(2, $editor->events); + + $event = [ + 'event' => 'postSubmit', + 'script' => 'post', + ]; + + $this->assertEquals($event, $editor->events[0]); + } + + /** + * @param string $instance + * @return \Yajra\DataTables\Html\Editor\Editor + */ + protected function getEditor(string $instance = 'editor'): Editor + { + return Editor::make($instance); + } +} \ No newline at end of file From 812c59a8b9a0933601bd334204f28a6cec0b6962 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Sat, 7 May 2022 15:52:43 +0800 Subject: [PATCH 018/260] Use same major version of Laravel --- CHANGELOG.md | 2 +- README.md | 4 ++-- composer.json | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 745d318..ff27c6c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ ## CHANGELOG -### v5.0.0 - UNRELEASED +### v9.0.0 - UNRELEASED - Add Laravel 9 support - Remove Laravel 8 and below support diff --git a/README.md b/README.md index 36277bf..fa847d0 100644 --- a/README.md +++ b/README.md @@ -24,11 +24,11 @@ This package is a plugin of [Laravel DataTables](https://github.com/yajra/larave | Laravel | Package | |:--------------|:--------| | 8.x and below | 4.x | -| 9.x | 5.x | +| 9.x | 9.x | ## Quick Installation -`composer require yajra/laravel-datatables-html:^5.0` +`composer require yajra/laravel-datatables-html:^9.0` #### Service Provider (Optional on Laravel 5.5+) diff --git a/composer.json b/composer.json index c986e52..4d2db56 100644 --- a/composer.json +++ b/composer.json @@ -37,7 +37,7 @@ }, "extra": { "branch-alias": { - "dev-master": "5.0-dev" + "dev-master": "9.0-dev" }, "laravel": { "providers": [ From 39ed9c6790b3d13df64787ddd412f41c66599b73 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Sat, 7 May 2022 16:00:07 +0800 Subject: [PATCH 019/260] Remove gitkeep --- tests/.gitkeep | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 tests/.gitkeep diff --git a/tests/.gitkeep b/tests/.gitkeep deleted file mode 100644 index e69de29..0000000 From 52605ebcdd4ae4aaf0269822c667541969162aa3 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Sat, 7 May 2022 16:02:36 +0800 Subject: [PATCH 020/260] Add style ci --- .styleci.yml | 1 + 1 file changed, 1 insertion(+) create mode 100644 .styleci.yml diff --git a/.styleci.yml b/.styleci.yml new file mode 100644 index 0000000..0285f17 --- /dev/null +++ b/.styleci.yml @@ -0,0 +1 @@ +preset: laravel From 302abdb7ae01875c5dabe34d39590a4a70bd9228 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Sat, 7 May 2022 16:35:05 +0800 Subject: [PATCH 021/260] Add title attr --- src/Html/Column.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Html/Column.php b/src/Html/Column.php index 3d3edb1..80d156f 100644 --- a/src/Html/Column.php +++ b/src/Html/Column.php @@ -10,6 +10,8 @@ /** * @property string $data * @property string $name + * @property string $title + * @property string $titleAttr * @property string $orderable * @property string $searchable * @property string $printable From 7dcf8e28ec428a13be0094250fe92b80a0837d20 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Sat, 7 May 2022 20:35:59 +0800 Subject: [PATCH 022/260] Patch export-ignore --- .gitattributes | 6 ++-- .php_cs | 77 -------------------------------------------------- 2 files changed, 3 insertions(+), 80 deletions(-) delete mode 100644 .php_cs diff --git a/.gitattributes b/.gitattributes index 1185e15..47ea9b3 100644 --- a/.gitattributes +++ b/.gitattributes @@ -5,7 +5,7 @@ .editorconfig export-ignore .gitattributes export-ignore .gitignore export-ignore -.php_cs export-ignore .scrutinizer.yml export-ignore -.travis.yml export-ignore -phpunit.xml export-ignore +.styleci.yml export-ignore +phpstan.neon.dist export-ignore +phpunit.xml.dist export-ignore diff --git a/.php_cs b/.php_cs deleted file mode 100644 index e8c5a2a..0000000 --- a/.php_cs +++ /dev/null @@ -1,77 +0,0 @@ -finder(DefaultFinder::create()->in(__DIR__)) - ->fixers($fixers) - ->level(FixerInterface::NONE_LEVEL) - ->setUsingCache(true); From 697ff957b11385147c1034ced093cb1da839676f Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Sat, 7 May 2022 21:25:45 +0800 Subject: [PATCH 023/260] Fix model options --- src/Html/Editor/Fields/BelongsTo.php | 3 +-- src/Html/Editor/Fields/Field.php | 13 +++++-------- src/Html/Editor/Fields/Options.php | 4 ++-- src/Html/SearchPane.php | 5 ++--- 4 files changed, 10 insertions(+), 15 deletions(-) diff --git a/src/Html/Editor/Fields/BelongsTo.php b/src/Html/Editor/Fields/BelongsTo.php index 4c64555..3177f34 100644 --- a/src/Html/Editor/Fields/BelongsTo.php +++ b/src/Html/Editor/Fields/BelongsTo.php @@ -19,8 +19,7 @@ public static function model(Builder|string $class, string $text, string $id = ' if ($class instanceof Builder) { $table = $class->getModel()->getTable(); } else { - $class = new $class; - $table = $class->getTable(); + $table = (new $class)->getTable(); } $table = Str::singular($table); diff --git a/src/Html/Editor/Fields/Field.php b/src/Html/Editor/Fields/Field.php index 630b357..88dc9e1 100644 --- a/src/Html/Editor/Fields/Field.php +++ b/src/Html/Editor/Fields/Field.php @@ -109,12 +109,12 @@ public function type(string $type): static /** * Get options from a model. * - * @param \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Builder $model + * @param class-string|\Illuminate\Database\Eloquent\Builder $model * @param string $value * @param string $key * @return $this */ - public function modelOptions(Model|EloquentBuilder $model, string $value, string $key = 'id'): static + public function modelOptions($model, string $value, string $key = 'id'): static { return $this->options( Options::model($model, $value, $key) @@ -331,16 +331,13 @@ public function opts(array $value): static * Set field element html attributes. * * @param string $attribute - * @param int|string $value + * @param int|bool|string $value * @return $this * @see https://datatables.net/forums/discussion/comment/156581/#Comment_156581 */ - public function attr(string $attribute, int|string $value): static + public function attr(string $attribute, int|bool|string $value): static { - if (! is_array($this->attributes['attr'])) { - $this->attributes['attr'] = []; - } - + // @phpstan-ignore-next-line $this->attributes['attr'][$attribute] = $value; return $this; diff --git a/src/Html/Editor/Fields/Options.php b/src/Html/Editor/Fields/Options.php index d5a6c91..2a4d6be 100644 --- a/src/Html/Editor/Fields/Options.php +++ b/src/Html/Editor/Fields/Options.php @@ -33,12 +33,12 @@ public static function yesNo(): static /** * Get options from a model. * - * @param \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Builder $model + * @param class-string|\Illuminate\Database\Eloquent\Builder $model * @param string $value * @param string $key * @return Collection */ - public static function model(Model|EloquentBuilder $model, string $value, string $key = 'id'): Collection + public static function model(string|EloquentBuilder $model, string $value, string $key = 'id'): Collection { if (! $model instanceof EloquentBuilder) { $model = $model::query(); diff --git a/src/Html/SearchPane.php b/src/Html/SearchPane.php index 89dddd0..1695ad0 100644 --- a/src/Html/SearchPane.php +++ b/src/Html/SearchPane.php @@ -5,7 +5,6 @@ use Closure; use Illuminate\Contracts\Support\Arrayable; use Illuminate\Database\Eloquent\Builder as EloquentBuilder; -use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Fluent; use Yajra\DataTables\Html\Editor\Fields\Options; @@ -212,12 +211,12 @@ public function hideTotal(bool $value = true): static /** * Get options from a model. * - * @param \Illuminate\Database\Eloquent\Model|EloquentBuilder $model + * @param class-string|EloquentBuilder $model * @param string $value * @param string $key * @return $this */ - public function modelOptions(Model|EloquentBuilder $model, string $value, string $key = 'id'): static + public function modelOptions(EloquentBuilder|string $model, string $value, string $key = 'id'): SearchPane { return $this->options( Options::model($model, $value, $key) From 65adb0a115b961ae18d664d59e7d091cb4541eac Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Sat, 7 May 2022 21:33:44 +0800 Subject: [PATCH 024/260] Allow diff default values --- 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 88dc9e1..1ca72fd 100644 --- a/src/Html/Editor/Fields/Field.php +++ b/src/Html/Editor/Fields/Field.php @@ -190,11 +190,11 @@ public function format(string $format): static /** * Set field default value. * - * @param string $value + * @param float|bool|int|string $value * @return $this * @see https://editor.datatables.net/reference/option/fields.def */ - public function default(string $value): static + public function default(float|bool|int|string $value): static { $this->attributes['def'] = $value; From 86e2065ef124756e822bf74923bb6fc0221ea0a1 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Sat, 7 May 2022 23:36:52 +0800 Subject: [PATCH 025/260] Add column test --- src/Html/Column.php | 11 +++ tests/ColumnTest.php | 158 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 169 insertions(+) create mode 100644 tests/ColumnTest.php diff --git a/src/Html/Column.php b/src/Html/Column.php index 80d156f..1579dad 100644 --- a/src/Html/Column.php +++ b/src/Html/Column.php @@ -18,6 +18,17 @@ * @property string $exportable * @property array|string $footer * @property array $attributes + * @property string $render + * @property string $className + * @property string $editField + * @property int|array $orderData + * @property string $orderDataType + * @property string $orderSequence + * @property string $cellType + * @property string $type + * @property string $contentPadding + * @property string $createdCell + * @property string $exportFormat * @see https://datatables.net/reference/option/#columns */ class Column extends Fluent diff --git a/tests/ColumnTest.php b/tests/ColumnTest.php new file mode 100644 index 0000000..0416363 --- /dev/null +++ b/tests/ColumnTest.php @@ -0,0 +1,158 @@ +assertInstanceOf(Column::class, $column); + } + + /** @test */ + public function it_has_default_properties() + { + $column = Column::make('name'); + + $this->assertEquals('name', $column->name); + $this->assertEquals('name', $column->data); + $this->assertEquals('Name', $column->title); + $this->assertEquals('', $column->render); + $this->assertEquals(true, $column->exportable); + $this->assertEquals(true, $column->printable); + $this->assertEquals(true, $column->orderable); + $this->assertEquals(true, $column->searchable); + $this->assertEquals([], $column->attributes); + $this->assertEquals('', $column->footer); + } + + /** @test */ + public function it_can_format_title() + { + $this->assertEquals('Title', Column::titleFormat('title')); + } + + /** @test */ + public function it_can_make_computed_column() + { + $column = Column::computed('name'); + + $this->assertEquals('name', $column->name); + $this->assertEquals('name', $column->data); + $this->assertEquals('Name', $column->title); + $this->assertEquals('', $column->render); + $this->assertEquals(true, $column->exportable); + $this->assertEquals(true, $column->printable); + $this->assertEquals(false, $column->orderable); + $this->assertEquals(false, $column->searchable); + $this->assertEquals([], $column->attributes); + $this->assertEquals('', $column->footer); + } + + + /** @test */ + public function it_can_make_formatted_column() + { + $column = Column::formatted('name'); + + $this->assertEquals('name', $column->name); + $this->assertEquals('name', $column->data); + $this->assertEquals('Name', $column->title); + $this->assertEquals('function(data,type,full,meta){return full.name_formatted;}', $column->render); + $this->assertEquals(true, $column->exportable); + $this->assertEquals(true, $column->printable); + $this->assertEquals(true, $column->orderable); + $this->assertEquals(true, $column->searchable); + $this->assertEquals([], $column->attributes); + $this->assertEquals('', $column->footer); + } + + /** @test */ + public function it_can_make_a_checkbox() + { + $column = Column::checkbox('name'); + + $this->assertEquals('', $column->name); + $this->assertEquals('', $column->data); + $this->assertEquals('name', $column->title); + $this->assertEquals('', $column->render); + $this->assertEquals(true, $column->printable); + $this->assertEquals(false, $column->exportable); + $this->assertEquals(false, $column->orderable); + $this->assertEquals(false, $column->searchable); + $this->assertEquals('select-checkbox', $column->className); + $this->assertEquals([], $column->attributes); + $this->assertEquals('', $column->footer); + } + + /** @test */ + public function it_has_property_setters() + { + $column = Column::checkbox('name'); + + $column->name('test'); + $this->assertEquals('test', $column->name); + + $column->data('test'); + $this->assertEquals('test', $column->data); + + $column->title('test'); + $this->assertEquals('test', $column->title); + + $column->editField('test'); + $this->assertEquals('test', $column->editField); + + $column->orderData(1); + $this->assertEquals(1, $column->orderData); + + $column->orderData([1]); + $this->assertEquals([1], $column->orderData); + + $column->orderDataType('test'); + $this->assertEquals('test', $column->orderDataType); + + $column->orderSequence(['test']); + $this->assertEquals(['test'], $column->orderSequence); + + $column->cellType('test'); + $this->assertEquals('test', $column->cellType); + + $column->type('test'); + $this->assertEquals('test', $column->type); + + $column->contentPadding('test'); + $this->assertEquals('test', $column->contentPadding); + + $column->createdCell('test'); + $this->assertEquals('test', $column->createdCell); + + $column->titleAttr('test'); + $this->assertEquals('test', $column->titleAttr); + + $column->exportFormat('test'); + $this->assertEquals('test', $column->exportFormat); + } + + /** @test */ + public function it_can_render_scripts() + { + $column = Column::make('name'); + + $column->render('test'); + $this->assertEquals('function(data,type,full,meta){return test;}', $column->render); + + $column->render('$.fn.dataTable.render.test'); + $this->assertEquals('$.fn.dataTable.render.test', $column->render); + + $column->renderJs('test'); + $this->assertEquals('$.fn.dataTable.render.test', $column->render); + + $column->renderRaw('test'); + $this->assertEquals('test', $column->render); + } +} From 390354b02b2bbabdbbab39a67e59e5d210c754f4 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Sun, 8 May 2022 00:05:39 +0800 Subject: [PATCH 026/260] Add field test --- src/Html/Editor/Fields/Field.php | 9 ++ tests/FieldTest.php | 137 +++++++++++++++++++++++++++++++ tests/Models/Post.php | 21 +++++ tests/Models/Role.php | 16 ++++ tests/Models/User.php | 28 +++++++ tests/TestCase.php | 76 +++++++++++++++++ 6 files changed, 287 insertions(+) create mode 100644 tests/FieldTest.php create mode 100644 tests/Models/Post.php create mode 100644 tests/Models/Role.php create mode 100644 tests/Models/User.php diff --git a/src/Html/Editor/Fields/Field.php b/src/Html/Editor/Fields/Field.php index 1ca72fd..93f25bf 100644 --- a/src/Html/Editor/Fields/Field.php +++ b/src/Html/Editor/Fields/Field.php @@ -102,6 +102,7 @@ public function data(string $data): static public function type(string $type): static { $this->attributes['type'] = $type; + $this->type = $type; return $this; } @@ -342,4 +343,12 @@ public function attr(string $attribute, int|bool|string $value): static return $this; } + + /** + * @return string + */ + public function getType(): string + { + return $this->type; + } } diff --git a/tests/FieldTest.php b/tests/FieldTest.php new file mode 100644 index 0000000..20ecd8e --- /dev/null +++ b/tests/FieldTest.php @@ -0,0 +1,137 @@ +assertInstanceOf(Fields\Field::class, $field); + $this->assertEquals('Name', $field->label); + $this->assertEquals('name', $field->name); + $this->assertEquals('text', $field->getType()); + } + + /** @test */ + public function it_can_set_properties() + { + $field = Fields\Field::make('name'); + + $field->label('Test'); + $field->name('Test'); + $field->data('Test'); + $field->type('Test'); + + $this->assertEquals('Test', $field->label); + $this->assertEquals('Test', $field->name); + $this->assertEquals('Test', $field->data); + $this->assertEquals('Test', $field->getType()); + } + + /** @test */ + public function it_can_create_belongs_to_field() + { + $field = Fields\BelongsTo::model(User::class, 'name'); + $this->assertInstanceOf(Fields\BelongsTo::class, $field); + $this->assertEquals('select', $field->getType()); + $this->assertEquals('user_id', $field->name); + $this->assertEquals('User', $field->label); + } + + /** @test */ + public function it_can_create_boolean_field() + { + $field = Fields\Boolean::make('name'); + $this->assertInstanceOf(Fields\Boolean::class, $field); + $this->assertEquals('checkbox', $field->getType()); + $this->assertEquals('name', $field->name); + $this->assertEquals('Name', $field->label); + $this->assertEquals(',', $field->separator); + $this->assertEquals([['label' => '', 'value' => 1]], $field->options); + } + + /** @test */ + public function it_can_create_date_field() + { + $field = Fields\Date::make('name'); + $this->assertInstanceOf(Fields\Date::class, $field); + $this->assertEquals('datetime', $field->getType()); + $this->assertEquals('name', $field->name); + $this->assertEquals('Name', $field->label); + $this->assertEquals('YYYY-MM-DD', $field->format); + } + + /** @test */ + public function it_can_create_datetime_field() + { + $field = Fields\DateTime::make('name'); + $this->assertInstanceOf(Fields\DateTime::class, $field); + $this->assertEquals('datetime', $field->getType()); + $this->assertEquals('name', $field->name); + $this->assertEquals('Name', $field->label); + $this->assertEquals('YYYY-MM-DD hh:mm a', $field->format); + + $field->military(); + $this->assertEquals('YYYY-MM-DD HH:mm', $field->format); + + $min = now(); + $field->minDate($min); + $date = $min->format('Y-m-d'); + $this->assertEquals("new Date('$date')", $field->opts['minDate']); + + $max = now(); + $field->maxDate($max); + $date = $max->format('Y-m-d'); + $this->assertEquals("new Date('$date')", $field->opts['maxDate']); + + $field->showWeekNumber(false); + $this->assertEquals(false, $field->opts['showWeekNumber']); + + $field->disableDays([1, 2, 3]); + $this->assertEquals([1, 2, 3], $field->opts['disableDays']); + + $field->minutesIncrement(2); + $this->assertEquals(2, $field->opts['minutesIncrement']); + + $field->secondsIncrement(2); + $this->assertEquals(2, $field->opts['secondsIncrement']); + + $field->hoursAvailable([1, 2]); + $this->assertEquals([1, 2], $field->opts['hoursAvailable']); + + $field->minutesAvailable([1, 2]); + $this->assertEquals([1, 2], $field->opts['minutesAvailable']); + } + + /** @test */ + public function it_can_create_text_field() + { + $field = Fields\Text::make('name'); + $this->assertInstanceOf(Fields\Text::class, $field); + $this->assertEquals('text', $field->getType()); + } + + /** @test */ + public function it_can_create_select_field() + { + $field = Fields\Select::make('name'); + $this->assertInstanceOf(Fields\Select::class, $field); + $this->assertEquals('select', $field->getType()); + } + + /** @test */ + public function it_can_create_select2_field() + { + $field = Fields\Select2::make('name'); + $this->assertInstanceOf(Fields\Select2::class, $field); + $this->assertEquals('select2', $field->getType()); + } + + +} \ No newline at end of file diff --git a/tests/Models/Post.php b/tests/Models/Post.php new file mode 100644 index 0000000..49f0df8 --- /dev/null +++ b/tests/Models/Post.php @@ -0,0 +1,21 @@ +belongsTo(User::class); + } +} diff --git a/tests/Models/Role.php b/tests/Models/Role.php new file mode 100644 index 0000000..5a0b4bb --- /dev/null +++ b/tests/Models/Role.php @@ -0,0 +1,16 @@ +belongsToMany(User::class); + } +} diff --git a/tests/Models/User.php b/tests/Models/User.php new file mode 100644 index 0000000..81909d6 --- /dev/null +++ b/tests/Models/User.php @@ -0,0 +1,28 @@ +hasMany(Post::class); + } + + public function roles(): BelongsToMany + { + return $this->belongsToMany(Role::class); + } + + public function user(): MorphTo + { + return $this->morphTo(); + } +} diff --git a/tests/TestCase.php b/tests/TestCase.php index c6263de..c5f65ea 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -2,10 +2,86 @@ namespace Yajra\DataTables\Html\Tests; +use Illuminate\Database\Schema\Blueprint; use Orchestra\Testbench\TestCase as BaseTestCase; +use Yajra\DataTables\Html\Tests\Models\Role; +use Yajra\DataTables\Html\Tests\Models\User; abstract class TestCase extends BaseTestCase { + protected function setUp(): void + { + parent::setUp(); + + $this->migrateDatabase(); + $this->seedDatabase(); + } + + protected function migrateDatabase() + { + /** @var \Illuminate\Database\Schema\Builder $schemaBuilder */ + $schemaBuilder = $this->app['db']->connection()->getSchemaBuilder(); + if (! $schemaBuilder->hasTable('users')) { + $schemaBuilder->create('users', function (Blueprint $table) { + $table->increments('id'); + $table->string('name'); + $table->string('email'); + $table->string('user_type')->nullable(); + $table->unsignedInteger('user_id')->nullable(); + $table->timestamps(); + }); + } + if (! $schemaBuilder->hasTable('posts')) { + $schemaBuilder->create('posts', function (Blueprint $table) { + $table->increments('id'); + $table->string('title'); + $table->unsignedInteger('user_id'); + $table->timestamps(); + $table->softDeletes(); + }); + } + if (! $schemaBuilder->hasTable('roles')) { + $schemaBuilder->create('roles', function (Blueprint $table) { + $table->increments('id'); + $table->string('role'); + $table->timestamps(); + }); + } + if (! $schemaBuilder->hasTable('role_user')) { + $schemaBuilder->create('role_user', function (Blueprint $table) { + $table->unsignedInteger('role_id'); + $table->unsignedInteger('user_id'); + $table->timestamps(); + }); + } + } + + protected function seedDatabase() + { + $adminRole = Role::create(['role' => 'Administrator']); + $userRole = Role::create(['role' => 'User']); + + collect(range(1, 20))->each(function ($i) use ($userRole) { + /** @var User $user */ + $user = User::query()->create([ + 'name' => 'Record-'.$i, + 'email' => 'Email-'.$i.'@example.com', + ]); + + collect(range(1, 3))->each(function ($i) use ($user) { + $user->posts()->create([ + 'title' => "User-{$user->id} Post-{$i}", + ]); + }); + + if ($i % 2) { + $user->roles()->attach(Role::all()); + } else { + $user->roles()->attach($userRole); + } + }); + } + /** * Set up the environment. * From d08d6c82e2cdcf62142a6a9104d98a781854d40a Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Sun, 8 May 2022 00:13:49 +0800 Subject: [PATCH 027/260] Complete field test --- tests/FieldTest.php | 86 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 83 insertions(+), 3 deletions(-) diff --git a/tests/FieldTest.php b/tests/FieldTest.php index 20ecd8e..70ad221 100644 --- a/tests/FieldTest.php +++ b/tests/FieldTest.php @@ -110,13 +110,62 @@ public function it_can_create_datetime_field() } /** @test */ - public function it_can_create_text_field() + public function it_can_create_file_field() { - $field = Fields\Text::make('name'); - $this->assertInstanceOf(Fields\Text::class, $field); + $field = Fields\File::make('name'); + $this->assertInstanceOf(Fields\File::class, $field); + $this->assertEquals('upload', $field->getType()); + // TODO: add more file field test + } + + /** @test */ + public function it_can_create_hidden_field() + { + $field = Fields\Hidden::make('name'); + $this->assertInstanceOf(Fields\Hidden::class, $field); + $this->assertEquals('hidden', $field->getType()); + } + + /** @test */ + public function it_can_create_image_field() + { + $field = Fields\Image::make('name'); + $this->assertInstanceOf(Fields\Image::class, $field); + $this->assertEquals('upload', $field->getType()); + } + + /** @test */ + public function it_can_create_number_field() + { + $field = Fields\Number::make('name'); + $this->assertInstanceOf(Fields\Number::class, $field); $this->assertEquals('text', $field->getType()); } + /** @test */ + public function it_can_create_password_field() + { + $field = Fields\Password::make('name'); + $this->assertInstanceOf(Fields\Password::class, $field); + $this->assertEquals('password', $field->getType()); + } + + /** @test */ + public function it_can_create_radio_field() + { + $field = Fields\Radio::make('name'); + $this->assertInstanceOf(Fields\Radio::class, $field); + $this->assertEquals('radio', $field->getType()); + } + + /** @test */ + public function it_can_create_read_only_field() + { + $field = Fields\ReadOnlyField::make('name'); + $this->assertInstanceOf(Fields\ReadOnlyField::class, $field); + $this->assertEquals('readonly', $field->getType()); + } + /** @test */ public function it_can_create_select_field() { @@ -133,5 +182,36 @@ public function it_can_create_select2_field() $this->assertEquals('select2', $field->getType()); } + /** @test */ + public function it_can_create_text_field() + { + $field = Fields\Text::make('name'); + $this->assertInstanceOf(Fields\Text::class, $field); + $this->assertEquals('text', $field->getType()); + } + /** @test */ + public function it_can_create_textarea_field() + { + $field = Fields\TextArea::make('name'); + $this->assertInstanceOf(Fields\TextArea::class, $field); + $this->assertEquals('textarea', $field->getType()); + + $field->rows(5); + $this->assertEquals('5', $field->attr['rows']); + + $field->cols(5); + $this->assertEquals('5', $field->attr['cols']); + } + + /** @test */ + public function it_can_create_time_field() + { + $field = Fields\Time::make('name'); + $this->assertInstanceOf(Fields\Time::class, $field); + $this->assertEquals('datetime', $field->getType()); + $this->assertEquals('name', $field->name); + $this->assertEquals('Name', $field->label); + $this->assertEquals('hh:mm a', $field->format); + } } \ No newline at end of file From 2bb6875fb01c750f17d2841f704e8079cd46299f Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Sun, 8 May 2022 00:14:11 +0800 Subject: [PATCH 028/260] Field type test --- tests/FieldTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/FieldTest.php b/tests/FieldTest.php index 70ad221..b14ae80 100644 --- a/tests/FieldTest.php +++ b/tests/FieldTest.php @@ -214,4 +214,4 @@ public function it_can_create_time_field() $this->assertEquals('Name', $field->label); $this->assertEquals('hh:mm a', $field->format); } -} \ No newline at end of file +} From 867efcc57ed202f5cdcb7f70d94fd26fdfe228d6 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Sun, 8 May 2022 00:16:11 +0800 Subject: [PATCH 029/260] badge version --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index fa847d0..31e0985 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Laravel DataTables Html Plugin. -[![Laravel 5.4+](https://img.shields.io/badge/Laravel-5.4+-orange.svg)](http://laravel.com) +[![Laravel 9.x](https://img.shields.io/badge/Laravel-9.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) @@ -11,8 +11,8 @@ This package is a plugin of [Laravel DataTables](https://github.com/yajra/larave ## Requirements -- [Laravel 5.4+](https://github.com/laravel/framework) -- [Laravel DataTables v7.x|v8.x|9.x](https://github.com/yajra/laravel-datatables) +- [Laravel 9.x](https://github.com/laravel/framework) +- [Laravel DataTables](https://github.com/yajra/laravel-datatables) ## Documentations From f55471f93d48e3c2b695c3464ee8427979f2f6ee Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Sun, 8 May 2022 00:18:45 +0800 Subject: [PATCH 030/260] Rename --- tests/{HtmlBuilderTest.php => BuilderTest.php} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename tests/{HtmlBuilderTest.php => BuilderTest.php} (99%) diff --git a/tests/HtmlBuilderTest.php b/tests/BuilderTest.php similarity index 99% rename from tests/HtmlBuilderTest.php rename to tests/BuilderTest.php index 923fa85..e20a5e6 100644 --- a/tests/HtmlBuilderTest.php +++ b/tests/BuilderTest.php @@ -5,7 +5,7 @@ use Yajra\DataTables\Html\Builder; use Yajra\DataTables\Html\Column; -class HtmlBuilderTest extends TestCase +class BuilderTest extends TestCase { /** @test */ public function it_can_resolved_builder_class() From 30f7cb48d86e3cf95f41bd5c1ff3ecd2fa5e58f6 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Sun, 8 May 2022 00:19:45 +0800 Subject: [PATCH 031/260] Bump v9.0.0 :rocket: --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ff27c6c..e1a73ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ ## CHANGELOG -### v9.0.0 - UNRELEASED +### v9.0.0 - 2022-05-08 - Add Laravel 9 support - Remove Laravel 8 and below support From c6cc9a707a5a3095bca47adef2bae0614406a254 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Sun, 8 May 2022 23:50:42 +0800 Subject: [PATCH 032/260] Allow array for orthogonal column data https://github.com/yajra/laravel-datatables/pull/2380 --- src/Html/Column.php | 7 ++++--- tests/ColumnTest.php | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/Html/Column.php b/src/Html/Column.php index 1579dad..cc5d0b7 100644 --- a/src/Html/Column.php +++ b/src/Html/Column.php @@ -8,7 +8,7 @@ use Yajra\DataTables\Html\Options\Plugins\SearchPanes; /** - * @property string $data + * @property array|string $data * @property string $name * @property string $title * @property string $titleAttr @@ -311,11 +311,12 @@ public function width(int|string $value): static /** * Set column data option value. * - * @param string $value + * @param array|string $value * @return $this * @see https://datatables.net/reference/option/columns.data + * @see https://datatables.net/manual/data/orthogonal-data */ - public function data(string $value): static + public function data(array|string $value): static { $this->attributes['data'] = $value; diff --git a/tests/ColumnTest.php b/tests/ColumnTest.php index 0416363..c5cfd6e 100644 --- a/tests/ColumnTest.php +++ b/tests/ColumnTest.php @@ -155,4 +155,18 @@ public function it_can_render_scripts() $column->renderRaw('test'); $this->assertEquals('test', $column->render); } + + /** @test */ + public function it_allows_orthogonal_data() + { + $expected = [ + '_' => 'test', + 'sort' => 'test', + 'filter' => 'test', + 'type' => 'test', + ]; + $column = Column::make('name')->data($expected); + + $this->assertEquals($expected, $column->data); + } } From e1e6da2d01d85fefbc9e0c596f0cf1112904975f Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Sun, 8 May 2022 23:51:39 +0800 Subject: [PATCH 033/260] Bump v9.0.1 :rocket: --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e1a73ff..af0f216 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,11 @@ ## CHANGELOG +### 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 From 2768ca28873bd43bc6bc5ac8093420067ac4df5e Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Fri, 13 May 2022 17:16:40 +0800 Subject: [PATCH 034/260] Fix opts and attr setter --- src/Html/Editor/Fields/Field.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/Html/Editor/Fields/Field.php b/src/Html/Editor/Fields/Field.php index 93f25bf..3fe1d5f 100644 --- a/src/Html/Editor/Fields/Field.php +++ b/src/Html/Editor/Fields/Field.php @@ -4,8 +4,6 @@ use Closure; use Illuminate\Contracts\Support\Arrayable; -use Illuminate\Database\Eloquent\Builder as EloquentBuilder; -use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Query\Builder as QueryBuilder; use Illuminate\Support\Fluent; use Illuminate\Support\Str; @@ -323,7 +321,11 @@ public function compare(bool $value): static */ public function opts(array $value): static { - $this->attributes['opts'] = $value; + if (! isset($this->attributes['opts'])) { + $this->attributes['opts'] = $value; + } else { + $this->attributes['opts'] = array_merge_recursive((array) $this->attributes['opts'], $value); + } return $this; } @@ -338,8 +340,10 @@ public function opts(array $value): static */ public function attr(string $attribute, int|bool|string $value): static { - // @phpstan-ignore-next-line - $this->attributes['attr'][$attribute] = $value; + $attributes = (array) $this->attributes['attr']; + $attributes[$attribute] = $value; + + $this->attributes['attr'] = $attributes; return $this; } From 33c4cbb7f5af9f40764886e329878f1a43ad7f3f Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Fri, 13 May 2022 17:17:01 +0800 Subject: [PATCH 035/260] Bump v9.0.2 :rocket: --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index af0f216..1c10519 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ ## CHANGELOG +### v9.0.2 - 2022-05-13 + +- Fix opts and attr setter + ### v9.0.1 - 2022-05-08 - Allow array for orthogonal column data From 3f3ce62ed3c862cd3c06df2ca7883f26a56839cc Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Fri, 13 May 2022 17:39:25 +0800 Subject: [PATCH 036/260] Fix attr --- src/Html/Editor/Fields/Field.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Html/Editor/Fields/Field.php b/src/Html/Editor/Fields/Field.php index 3fe1d5f..91d698c 100644 --- a/src/Html/Editor/Fields/Field.php +++ b/src/Html/Editor/Fields/Field.php @@ -340,6 +340,10 @@ public function opts(array $value): static */ public function attr(string $attribute, int|bool|string $value): static { + if (! isset($this->attributes['attr'])) { + $this->attributes['attr'] = []; + } + $attributes = (array) $this->attributes['attr']; $attributes[$attribute] = $value; From c397600f30a01bfe0421aa6d3e342552bf8a6ef2 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Fri, 13 May 2022 17:39:56 +0800 Subject: [PATCH 037/260] Bump v9.0.3 :rocket: --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c10519..3b9940f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ ## CHANGELOG +### v9.0.3 - 2022-05-13 + +- Fix attr setter + ### v9.0.2 - 2022-05-13 - Fix opts and attr setter From c312c5e64a7a05d263fb87776709a1cb217afa2a Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Sat, 14 May 2022 09:32:15 +0800 Subject: [PATCH 038/260] Select2 field tests --- tests/FieldTest.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tests/FieldTest.php b/tests/FieldTest.php index b14ae80..961f2aa 100644 --- a/tests/FieldTest.php +++ b/tests/FieldTest.php @@ -177,9 +177,18 @@ public function it_can_create_select_field() /** @test */ public function it_can_create_select2_field() { - $field = Fields\Select2::make('name'); + $field = Fields\Select2::make('name') + ->allowClear() + ->optsPlaceholder('Test') + ->modelOptions(User::class, 'name') + ->ajax('/url'); + $this->assertInstanceOf(Fields\Select2::class, $field); $this->assertEquals('select2', $field->getType()); + $this->assertEquals('/url', $field->opts['ajax']['url']); + $this->assertEquals('Test', $field->opts['placeholder']['text']); + $this->assertEquals('id', $field->opts['placeholder']['id']); + $this->assertCount(20, $field->options); } /** @test */ From cbccfd03dd78cf3ed1124550f18fa14e59e377fe Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Sat, 14 May 2022 09:49:23 +0800 Subject: [PATCH 039/260] Add HasCallbacks Test --- src/Html/Builder.php | 60 +++++++++++++++++++++++------------- tests/BuilderOptionsTest.php | 54 ++++++++++++++++++++++++++++++++ tests/FieldTest.php | 5 ++- 3 files changed, 97 insertions(+), 22 deletions(-) create mode 100644 tests/BuilderOptionsTest.php diff --git a/src/Html/Builder.php b/src/Html/Builder.php index ca44400..8e1e38b 100644 --- a/src/Html/Builder.php +++ b/src/Html/Builder.php @@ -107,6 +107,19 @@ public function generateJson(): string return $this->parameterize($this->getOptions()); } + /** + * Generate DataTables js parameters. + * + * @param array $attributes + * @return string + */ + public function parameterize(array $attributes = []): string + { + $parameters = (new Parameters($attributes))->toArray(); + + return Helper::toJsonScript($parameters); + } + /** * Get DataTable options array. * @@ -127,19 +140,6 @@ public function getOptions(): array ); } - /** - * Generate DataTables js parameters. - * - * @param array $attributes - * @return string - */ - public function parameterize(array $attributes = []): string - { - $parameters = (new Parameters($attributes))->toArray(); - - return Helper::toJsonScript($parameters); - } - /** * Get javascript template to use. * @@ -196,6 +196,16 @@ public function parameters(array $attributes = []): static return $this; } + /** + * Generate scripts that set the dataTables options into a variable. + * + * @return $this + */ + public function asOptions(): static + { + return $this->setTemplate('datatables::options'); + } + /** * Set custom javascript template. * @@ -210,22 +220,30 @@ public function setTemplate(string $template): static } /** - * Generate scripts that sets the dataTables options into a variable. + * Wrap dataTable scripts with a function. * * @return $this */ - public function asOptions(): static + public function asFunction(): static { - return $this->setTemplate('datatables::options'); + return $this->setTemplate('datatables::function'); } /** - * Wrap dataTable scripts with a function. - * - * @return $this + * @return array */ - public function asFunction(): static + public function getAttributes(): array { - return $this->setTemplate('datatables::function'); + return $this->attributes; + } + + /** + * @param string $key + * @param mixed $default + * @return mixed + */ + public function getAttribute(string $key, mixed $default = ''): mixed + { + return $this->attributes[$key] ?? $default; } } diff --git a/tests/BuilderOptionsTest.php b/tests/BuilderOptionsTest.php new file mode 100644 index 0000000..9ab2b21 --- /dev/null +++ b/tests/BuilderOptionsTest.php @@ -0,0 +1,54 @@ +getHtmlBuilder(); + + $builder + ->createdRow('function() {}') + ->drawCallback('function() {}') + ->footerCallback('function() {}') + ->formatNumber('function() {}') + ->headerCallback('function() {}') + ->infoCallback('function() {}') + ->initComplete('function() {}') + ->preDrawCallback('function() {}') + ->rowCallback('function() {}') + ->stateLoadCallback('function() {}') + ->stateLoaded('function() {}') + ->stateLoadParams('function() {}') + ->stateSaveCallback('function() {}') + ->stateSaveParams('function() {}'); + + $this->assertEquals('function() {}', $builder->getAttribute('createdRow')); + $this->assertEquals('function() {}', $builder->getAttribute('drawCallback')); + $this->assertEquals('function() {}', $builder->getAttribute('footerCallback')); + $this->assertEquals('function() {}', $builder->getAttribute('formatNumber')); + $this->assertEquals('function() {}', $builder->getAttribute('infoCallback')); + $this->assertEquals('function() {}', $builder->getAttribute('preDrawCallback')); + $this->assertEquals('function() {}', $builder->getAttribute('stateLoaded')); + $this->assertEquals('function() {}', $builder->getAttribute('stateSaveCallback')); + $this->assertEquals('function() {}', $builder->getAttribute('stateSaveParams')); + + $builder->drawCallbackWithLivewire(); + $this->assertStringContainsString('window.livewire.rescan()', $builder->getAttribute('drawCallback')); + + $builder->drawCallbackWithLivewire('test livewire'); + $this->assertStringContainsString('test livewire', $builder->getAttribute('drawCallback')); + } + + /** + * @return \Yajra\DataTables\Html\Builder + */ + protected function getHtmlBuilder(): Builder + { + return app(Builder::class); + } +} diff --git a/tests/FieldTest.php b/tests/FieldTest.php index 961f2aa..f336bab 100644 --- a/tests/FieldTest.php +++ b/tests/FieldTest.php @@ -194,9 +194,12 @@ public function it_can_create_select2_field() /** @test */ public function it_can_create_text_field() { - $field = Fields\Text::make('name'); + $field = Fields\Text::make('name') + ->attr('style', 'display: none;'); + $this->assertInstanceOf(Fields\Text::class, $field); $this->assertEquals('text', $field->getType()); + $this->assertEquals('display: none;', $field->attr['style']); } /** @test */ From 4b82db759a4f814693076d6c9352c3c56f1a29fd Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Sat, 14 May 2022 10:31:20 +0800 Subject: [PATCH 040/260] Add HasColumns test Allow Column on addColumn and addBeforeColumn --- src/Html/Builder.php | 2 +- src/Html/Column.php | 2 +- src/Html/ColumnDefinition.php | 7 ++++ src/Html/Options/HasColumns.php | 73 +++++++++++---------------------- tests/BuilderOptionsTest.php | 59 ++++++++++++++++++++++++++ 5 files changed, 92 insertions(+), 51 deletions(-) diff --git a/src/Html/Builder.php b/src/Html/Builder.php index 8e1e38b..ff7942f 100644 --- a/src/Html/Builder.php +++ b/src/Html/Builder.php @@ -31,7 +31,7 @@ class Builder const SELECT_ITEMS_CELL = 'cell'; /** - * @var Collection + * @var Collection */ public Collection $collection; diff --git a/src/Html/Column.php b/src/Html/Column.php index cc5d0b7..8a509ba 100644 --- a/src/Html/Column.php +++ b/src/Html/Column.php @@ -71,7 +71,7 @@ public function __construct($attributes = []) */ public static function titleFormat(string $value): string { - return Str::title(str_replace('_', ' ', $value)); + return Str::title(str_replace(['.', '_'], ' ', Str::snake($value))); } /** diff --git a/src/Html/ColumnDefinition.php b/src/Html/ColumnDefinition.php index 3fc023f..7624fd6 100644 --- a/src/Html/ColumnDefinition.php +++ b/src/Html/ColumnDefinition.php @@ -2,12 +2,19 @@ namespace Yajra\DataTables\Html; +use Illuminate\Support\Collection; use Illuminate\Support\Fluent; class ColumnDefinition extends Fluent { use HasOptions; + /** + * TODO: Review HasColumns have collection and is not applicable here. + * @var \Illuminate\Support\Collection + */ + protected Collection $collection; + public function targets(array $value): static { $this->attributes['targets'] = $value; diff --git a/src/Html/Options/HasColumns.php b/src/Html/Options/HasColumns.php index 4ba6421..52c9e5b 100644 --- a/src/Html/Options/HasColumns.php +++ b/src/Html/Options/HasColumns.php @@ -4,13 +4,11 @@ use Illuminate\Contracts\Support\Arrayable; use Illuminate\Support\Collection; -use Illuminate\Support\Str; use Yajra\DataTables\Html\Column; /** * DataTables - Columns option builder. * - * @property Collection $collection * @see https://datatables.net/reference/option/ */ trait HasColumns @@ -73,18 +71,14 @@ public function columns(array $columns): static foreach ($columns as $key => $value) { if (! is_a($value, Column::class)) { if (is_array($value)) { - $attributes = array_merge( - [ - 'name' => $value['name'] ?? $value['data'] ?? $key, - 'data' => $value['data'] ?? $key, - ], - $this->setTitle($key, $value) - ); + $attributes = array_merge($value, [ + 'name' => $value['name'] ?? $value['data'] ?? $key, + 'data' => $value['data'] ?? $key, + ]); } else { $attributes = [ 'name' => $value, 'data' => $value, - 'title' => $this->getQualifiedTitle($value), ]; } @@ -98,41 +92,31 @@ public function columns(array $columns): static } /** - * Set title attribute of an array if not set. + * Add a column in collection using attributes. * - * @param string $title - * @param array $attributes - * @return array + * @param array|\Yajra\DataTables\Html\Column $attributes + * @return $this */ - public function setTitle(string $title, array $attributes): array + public function addColumn(array|Column $attributes): static { - if (! isset($attributes['title'])) { - $attributes['title'] = $this->getQualifiedTitle($title); + if (is_array($attributes)) { + $this->collection->push(new Column($attributes)); + } else { + $this->add($attributes); } - return $attributes; - } - - /** - * Convert string into a readable title. - * - * @param string $title - * @return string - */ - public function getQualifiedTitle(string $title): string - { - return Str::title(str_replace(['.', '_'], ' ', Str::snake($title))); + return $this; } /** - * Add a column in collection using attributes. + * Add a Column object in collection. * - * @param array $attributes + * @param \Yajra\DataTables\Html\Column $column * @return $this */ - public function addColumn(array $attributes): static + public function add(Column $column): static { - $this->collection->push(new Column($attributes)); + $this->collection->push($column); return $this; } @@ -153,25 +137,16 @@ public function addBefore(Column $column): static /** * Add a column at the beginning of collection using attributes. * - * @param array $attributes + * @param array|\Yajra\DataTables\Html\Column $attributes * @return $this */ - public function addColumnBefore(array $attributes): static + public function addColumnBefore(array|Column $attributes): static { - $this->collection->prepend(new Column($attributes)); - - return $this; - } - - /** - * Add a Column object in collection. - * - * @param \Yajra\DataTables\Html\Column $column - * @return $this - */ - public function add(Column $column): static - { - $this->collection->push($column); + if (is_array($attributes)) { + $this->collection->prepend(new Column($attributes)); + } else { + $this->addBefore($attributes); + } return $this; } diff --git a/tests/BuilderOptionsTest.php b/tests/BuilderOptionsTest.php index 9ab2b21..64ae4bc 100644 --- a/tests/BuilderOptionsTest.php +++ b/tests/BuilderOptionsTest.php @@ -3,6 +3,7 @@ namespace Yajra\DataTables\Html\Tests; use Yajra\DataTables\Html\Builder; +use Yajra\DataTables\Html\Column; class BuilderOptionsTest extends TestCase { @@ -51,4 +52,62 @@ protected function getHtmlBuilder(): Builder { return app(Builder::class); } + + /** @test */ + public function it_has_columns_options() + { + $builder = $this->getHtmlBuilder(); + + $builder->columnDefs(['target' => [1]]) + ->addColumnDef(['target' => [1]]) + ->addColumnDef(['target' => [2]]) + ->columns([ + Column::make('id'), + Column::make('name'), + ]); + + $this->assertEquals([1], $builder->getAttribute('columnDefs')['target']); + $this->assertEquals([1], $builder->getAttribute('columnDefs')[0]['target']); + $this->assertEquals([2], $builder->getAttribute('columnDefs')[1]['target']); + $this->assertCount(2, $builder->getColumns()); + $this->assertInstanceOf(Column::class, $builder->getColumns()[0]); + $this->assertEquals('id', $builder->getColumns()[0]['data']); + $this->assertEquals('id', $builder->getColumns()[0]['name']); + $this->assertEquals('Id', $builder->getColumns()[0]['title']); + + $builder->addColumn(['data' => 'email']); + + $this->assertCount(3, $builder->getColumns()); + $this->assertInstanceOf(Column::class, $builder->getColumns()[2]); + $this->assertEquals('email', $builder->getColumns()[2]['data']); + $this->assertEquals('email', $builder->getColumns()[2]['name']); + $this->assertEquals('Email', $builder->getColumns()[2]['title']); + + $builder->addColumn(Column::make('created_at')); + + $this->assertCount(4, $builder->getColumns()); + $this->assertInstanceOf(Column::class, $builder->getColumns()[3]); + $this->assertEquals('created_at', $builder->getColumns()[3]['data']); + $this->assertEquals('created_at', $builder->getColumns()[3]['name']); + $this->assertEquals('Created At', $builder->getColumns()[3]['title']); + + $builder->addColumnBefore(['data' => 'updated_at']); + + $this->assertCount(5, $builder->getColumns()); + $this->assertInstanceOf(Column::class, $builder->getColumns()[0]); + $this->assertEquals('updated_at', $builder->getColumns()[0]['data']); + $this->assertEquals('updated_at', $builder->getColumns()[0]['name']); + $this->assertEquals('Updated At', $builder->getColumns()[0]['title']); + + $builder->addBefore(Column::make('deleted_at')); + + $this->assertCount(6, $builder->getColumns()); + $this->assertInstanceOf(Column::class, $builder->getColumns()[0]); + $this->assertEquals('deleted_at', $builder->getColumns()[0]['data']); + $this->assertEquals('deleted_at', $builder->getColumns()[0]['name']); + $this->assertEquals('Deleted At', $builder->getColumns()[0]['title']); + + $builder->removeColumn('created_at', 'updated_at'); + $this->assertCount(4, $builder->getColumns()); + } } From 16a2af8ebf0b0627d00afe655be2199db2e0a72c Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Sat, 14 May 2022 11:10:29 +0800 Subject: [PATCH 041/260] HasAjax tests --- src/Html/Builder.php | 18 +++++++++ src/Html/ColumnDefinition.php | 23 +++++++---- src/Html/HasOptions.php | 2 +- src/Html/Options/{HasData.php => HasAjax.php} | 22 ++++------ tests/BuilderOptionsTest.php | 40 +++++++++++++++++++ 5 files changed, 82 insertions(+), 23 deletions(-) rename src/Html/Options/{HasData.php => HasAjax.php} (89%) diff --git a/src/Html/Builder.php b/src/Html/Builder.php index ff7942f..f63dca7 100644 --- a/src/Html/Builder.php +++ b/src/Html/Builder.php @@ -50,6 +50,11 @@ class Builder */ protected array $attributes = []; + /** + * @var string|array + */ + protected string|array $ajax = ''; + /** * @param Repository $config * @param Factory $view @@ -246,4 +251,17 @@ 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 + { + if (! is_null($key)) { + return $this->ajax[$key] ?? ''; + } + + return $this->ajax; + } } diff --git a/src/Html/ColumnDefinition.php b/src/Html/ColumnDefinition.php index 7624fd6..b8fd031 100644 --- a/src/Html/ColumnDefinition.php +++ b/src/Html/ColumnDefinition.php @@ -2,18 +2,25 @@ namespace Yajra\DataTables\Html; -use Illuminate\Support\Collection; use Illuminate\Support\Fluent; class ColumnDefinition extends Fluent { - use HasOptions; - - /** - * TODO: Review HasColumns have collection and is not applicable here. - * @var \Illuminate\Support\Collection - */ - protected Collection $collection; + use Options\HasFeatures; + use Options\HasCallbacks; + use Options\HasInternationalisation; + use Options\Plugins\AutoFill; + use Options\Plugins\Buttons; + use Options\Plugins\ColReorder; + use Options\Plugins\FixedColumns; + use Options\Plugins\FixedHeader; + use Options\Plugins\KeyTable; + use Options\Plugins\Responsive; + use Options\Plugins\RowGroup; + use Options\Plugins\RowReorder; + use Options\Plugins\Scroller; + use Options\Plugins\Select; + use Options\Plugins\SearchPanes; public function targets(array $value): static { diff --git a/src/Html/HasOptions.php b/src/Html/HasOptions.php index 50adac1..b74a1c7 100644 --- a/src/Html/HasOptions.php +++ b/src/Html/HasOptions.php @@ -12,7 +12,7 @@ trait HasOptions { use Options\HasFeatures; - use Options\HasData; + use Options\HasAjax; use Options\HasCallbacks; use Options\HasColumns; use Options\HasInternationalisation; diff --git a/src/Html/Options/HasData.php b/src/Html/Options/HasAjax.php similarity index 89% rename from src/Html/Options/HasData.php rename to src/Html/Options/HasAjax.php index fa8fc0c..ee9fa17 100644 --- a/src/Html/Options/HasData.php +++ b/src/Html/Options/HasAjax.php @@ -8,17 +8,10 @@ /** * DataTables - Data option builder. * - * @property \Illuminate\Contracts\Config\Repository $config - * * @see https://datatables.net/reference/option/ */ -trait HasData +trait HasAjax { - /** - * @var string|array - */ - protected string|array $ajax = ''; - /** * Setup "ajax" parameter with POST method. * @@ -28,7 +21,7 @@ trait HasData public function postAjax(array|string $attributes = ''): static { if (! is_array($attributes)) { - $attributes = ['url' => (string) $attributes]; + $attributes = ['url' => $attributes]; } unset($attributes['method']); @@ -55,10 +48,11 @@ public function ajax(array|string $attributes = ''): static * Setup ajax parameter for datatables pipeline plugin. * * @param string $url - * @param string $pages + * @param int $pages * @return $this + * @see https://datatables.net/examples/server_side/pipeline.html */ - public function pipeline(string $url, string $pages): static + public function pipeline(string $url, int $pages = 5): static { return $this->ajax("$.fn.dataTable.pipeline({ url: '$url', pages: $pages })"); } @@ -87,7 +81,7 @@ public function getAjaxUrl(): string public function ajaxWithForm(string $url, string $formSelector): static { $script = << $value) { - $dataValue = Helper::isJavascript($value, $key) ? $value : "'{$value}'"; - $script .= PHP_EOL."data.{$key} = {$dataValue};"; + $dataValue = Helper::isJavascript($value, $key) ? $value : (is_string($value) ? "'$value'" : $value); + $script .= PHP_EOL."data.$key = $dataValue;"; } return $script; diff --git a/tests/BuilderOptionsTest.php b/tests/BuilderOptionsTest.php index 64ae4bc..4058ea4 100644 --- a/tests/BuilderOptionsTest.php +++ b/tests/BuilderOptionsTest.php @@ -110,4 +110,44 @@ public function it_has_columns_options() $builder->removeColumn('created_at', 'updated_at'); $this->assertCount(4, $builder->getColumns()); } + + /** @test */ + public function it_has_ajax_options() + { + $builder = $this->getHtmlBuilder(); + + $builder->postAjax('/test'); + + $this->assertEquals('/test', $builder->getAjaxUrl()); + $this->assertEquals([ + "url" => "/test", + "type" => "POST", + "headers" => [ + "X-HTTP-Method-Override" => "GET", + ], + ], $builder->getAjax()); + + $builder->ajax('/test'); + $this->assertEquals('/test', $builder->getAjaxUrl()); + + $builder->ajax(['url' => '/test']); + $this->assertEquals('/test', $builder->getAjax('url')); + + $builder->pipeline('/test'); + $this->assertEquals("$.fn.dataTable.pipeline({ url: '/test', pages: 5 })", $builder->getAjaxUrl()); + + $builder->pipeline('/test', 6); + $this->assertEquals("$.fn.dataTable.pipeline({ url: '/test', pages: 6 })", $builder->getAjaxUrl()); + + $builder->ajaxWithForm('/test', '#formId'); + $this->assertStringContainsString('data.columns.length', $builder->getAjax()['data']); + $this->assertStringContainsString('delete data.columns[i].search;', $builder->getAjax('data')); + $this->assertStringContainsString('#formId', $builder->getAjax('data')); + + $builder->minifiedAjax('/test', 'custom_script', ['id' => 123, 'name' => 'yajra']); + $this->assertEquals('/test', $builder->getAjax('url')); + $this->assertStringContainsString('custom_script', $builder->getAjax('data')); + $this->assertStringContainsString("data.id = 123", $builder->getAjax('data')); + $this->assertStringContainsString("data.name = 'yajra'", $builder->getAjax('data')); + } } From 3c6dbd69e8ccd6e3e6cf320a26e4a26387348927 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Sat, 14 May 2022 11:32:28 +0800 Subject: [PATCH 042/260] Fix language options and add tests --- src/Html/Editor/Fields/Field.php | 2 +- src/Html/Options/HasInternationalisation.php | 43 ++++++++---- tests/BuilderOptionsTest.php | 73 ++++++++++++++++++++ 3 files changed, 104 insertions(+), 14 deletions(-) diff --git a/src/Html/Editor/Fields/Field.php b/src/Html/Editor/Fields/Field.php index 91d698c..95d2977 100644 --- a/src/Html/Editor/Fields/Field.php +++ b/src/Html/Editor/Fields/Field.php @@ -324,7 +324,7 @@ public function opts(array $value): static if (! isset($this->attributes['opts'])) { $this->attributes['opts'] = $value; } else { - $this->attributes['opts'] = array_merge_recursive((array) $this->attributes['opts'], $value); + $this->attributes['opts'] = array_merge((array) $this->attributes['opts'], $value); } return $this; diff --git a/src/Html/Options/HasInternationalisation.php b/src/Html/Options/HasInternationalisation.php index ccdf1da..5849312 100644 --- a/src/Html/Options/HasInternationalisation.php +++ b/src/Html/Options/HasInternationalisation.php @@ -16,6 +16,18 @@ trait HasInternationalisation use Languages\Paginate; use Languages\Select; + /** + * Set language decimal option value. + * + * @param string $value + * @return $this + * @see https://datatables.net/reference/option/language.decimal + */ + public function languageDecimal(string $value): static + { + return $this->language(['decimal' => $value]); + } + /** * Set language option value. * @@ -25,8 +37,12 @@ trait HasInternationalisation */ public function language(array|string $value): static { + if (! isset($this->attributes['language'])) { + $this->attributes['language'] = []; + } + if (is_array($value)) { - $this->attributes['language'] = $value; + $this->attributes['language'] = array_merge($this->attributes['language'], $value); } else { $this->attributes['language']['url'] = $value; } @@ -34,18 +50,6 @@ public function language(array|string $value): static return $this; } - /** - * Set language decimal option value. - * - * @param string $value - * @return $this - * @see https://datatables.net/reference/option/language.decimal - */ - public function languageDecimal(string $value): static - { - return $this->language(['decimal' => $value]); - } - /** * Set language emptyTable option value. * @@ -201,4 +205,17 @@ public function languageZeroRecords(string $value): static { return $this->language(['zeroRecords' => $value]); } + + /** + * @param string|null $key + * @return mixed + */ + public function getLanguage(string $key = null): mixed + { + if (is_null($key)) { + return $this->attributes['language'] ?? []; + } + + return $this->attributes['language'][$key] ?? ''; + } } diff --git a/tests/BuilderOptionsTest.php b/tests/BuilderOptionsTest.php index 4058ea4..ae79bc6 100644 --- a/tests/BuilderOptionsTest.php +++ b/tests/BuilderOptionsTest.php @@ -150,4 +150,77 @@ public function it_has_ajax_options() $this->assertStringContainsString("data.id = 123", $builder->getAjax('data')); $this->assertStringContainsString("data.name = 'yajra'", $builder->getAjax('data')); } + + /** @test */ + public function it_has_features_options() + { + $builder = $this->getHtmlBuilder(); + $builder->autoWidth() + ->deferRender() + ->info() + ->lengthChange() + ->ordering() + ->processing() + ->scrollX() + ->scrollY() + ->paging() + ->searching() + ->serverSide() + ->stateSave(); + + $this->assertEquals(true, $builder->getAttribute('autoWidth')); + $this->assertEquals(true, $builder->getAttribute('deferRender')); + $this->assertEquals(true, $builder->getAttribute('info')); + $this->assertEquals(true, $builder->getAttribute('lengthChange')); + $this->assertEquals(true, $builder->getAttribute('ordering')); + $this->assertEquals(true, $builder->getAttribute('processing')); + $this->assertEquals(true, $builder->getAttribute('scrollX')); + $this->assertEquals(true, $builder->getAttribute('scrollY')); + $this->assertEquals(true, $builder->getAttribute('paging')); + $this->assertEquals(true, $builder->getAttribute('searching')); + $this->assertEquals(true, $builder->getAttribute('serverSide')); + $this->assertEquals(true, $builder->getAttribute('stateSave')); + + $builder->scrollY('50vh'); + $this->assertEquals('50vh', $builder->getAttribute('scrollY')); + } + + /** @test */ + public function it_has_internationalisation_options() + { + $builder = $this->getHtmlBuilder(); + + $builder->language('/language-url') + ->languageDecimal(',') + ->languageEmptyTable('languageEmptyTable') + ->languageInfo('languageInfo') + ->languageInfoEmpty('languageInfoEmpty') + ->languageInfoFiltered('languageInfoFiltered') + ->languageInfoPostFix('languageInfoPostFix') + ->languageLengthMenu('languageLengthMenu') + ->languageLoadingRecords('languageLoadingRecords') + ->languageProcessing('languageProcessing') + ->languageSearch('languageSearch') + ->languageSearchPlaceholder('languageSearchPlaceholder') + ->languageThousands('languageThousands') + ->languageZeroRecords('languageZeroRecords'); + + $this->assertEquals('/language-url', $builder->getAttribute('language')['url']); + $this->assertEquals(',', $builder->getLanguage('decimal')); + $this->assertEquals('languageEmptyTable', $builder->getLanguage('emptyTable')); + $this->assertEquals('languageInfo', $builder->getLanguage('info')); + $this->assertEquals('languageInfoEmpty', $builder->getLanguage('infoEmpty')); + $this->assertEquals('languageInfoFiltered', $builder->getLanguage('infoFiltered')); + $this->assertEquals('languageInfoPostFix', $builder->getLanguage('infoPostFix')); + $this->assertEquals('languageLengthMenu', $builder->getLanguage('lengthMenu')); + $this->assertEquals('languageLoadingRecords', $builder->getLanguage('loadingRecords')); + $this->assertEquals('languageProcessing', $builder->getLanguage('processing')); + $this->assertEquals('languageSearch', $builder->getLanguage('search')); + $this->assertEquals('languageSearchPlaceholder', $builder->getLanguage('searchPlaceholder')); + $this->assertEquals('languageThousands', $builder->getLanguage('thousands')); + $this->assertEquals('languageZeroRecords', $builder->getLanguage('zeroRecords')); + + $builder->languageUrl('languageUrl'); + $this->assertEquals('languageUrl', $builder->getLanguage('url')); + } } From cc5f1b79eb4833e9ab3818cb40899aa6ec0cb02a Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Sat, 14 May 2022 11:55:35 +0800 Subject: [PATCH 043/260] Fix autoFill plugin with tests --- src/Html/Options/Plugins/AutoFill.php | 43 +++++++++++++++++++-------- tests/BuilderOptionsPluginsTest.php | 42 ++++++++++++++++++++++++++ tests/BuilderOptionsTest.php | 8 ----- tests/BuilderTest.php | 8 ----- tests/TestCase.php | 15 ++++++++-- 5 files changed, 85 insertions(+), 31 deletions(-) create mode 100644 tests/BuilderOptionsPluginsTest.php diff --git a/src/Html/Options/Plugins/AutoFill.php b/src/Html/Options/Plugins/AutoFill.php index 4ea4690..face8ee 100644 --- a/src/Html/Options/Plugins/AutoFill.php +++ b/src/Html/Options/Plugins/AutoFill.php @@ -12,30 +12,34 @@ trait AutoFill { /** - * Set autoFill option value. - * Enable and configure the AutoFill extension for DataTables. + * Set autoFill alwaysAsk option value. * - * @param bool|array $value + * @param bool $value * @return $this - * @see https://datatables.net/reference/option/autoFill + * @see https://datatables.net/reference/option/autoFill.alwaysAsk */ - public function autoFill(bool|array $value = true): static + public function autoFillAlwaysAsk(bool $value = true): static { - $this->attributes['autoFill'] = $value; - - return $this; + return $this->autoFill(['alwaysAsk' => $value]); } /** - * Set autoFill alwaysAsk option value. + * Set autoFill option value. + * Enable and configure the AutoFill extension for DataTables. * - * @param bool $value + * @param bool|array $value * @return $this - * @see https://datatables.net/reference/option/autoFill.alwaysAsk + * @see https://datatables.net/reference/option/autoFill */ - public function autoFillAlwaysAsk(bool $value = true): static + public function autoFill(bool|array $value = true): static { - return $this->autoFill(['alwaysAsk' => $value]); + if (is_array($value)) { + $this->attributes['autoFill'] = array_merge((array) $this->attributes['autoFill'], $value); + } else { + $this->attributes['autoFill'] = $value; + } + + return $this; } /** @@ -121,4 +125,17 @@ public function autoFillVertical(bool $value = true): static { return $this->autoFill(['vertical' => $value]); } + + /** + * @param string|null $key + * @return mixed + */ + public function getAutoFill(string $key = null): mixed + { + if (is_null($key)) { + return $this->attributes['autoFill'] ?? true; + } + + return $this->attributes['autoFill'][$key] ?? false; + } } diff --git a/tests/BuilderOptionsPluginsTest.php b/tests/BuilderOptionsPluginsTest.php new file mode 100644 index 0000000..355ad82 --- /dev/null +++ b/tests/BuilderOptionsPluginsTest.php @@ -0,0 +1,42 @@ +getHtmlBuilder(); + + $this->assertTrue($builder->getAutoFill()); + + $builder->autoFill(); + $this->assertTrue($builder->getAttribute('autoFill')); + + $builder->autoFill(false); + $this->assertFalse($builder->getAttribute('autoFill')); + + $builder->autoFillAlwaysAsk() + ->autoFillColumns('autoFillColumns') + ->autoFillEditor('autoFillEditor') + ->autoFillEnable() + ->autoFillFocus('autoFillFocus') + ->autoFillHorizontal() + ->autoFillUpdate() + ->autoFillVertical(); + + $this->assertTrue($builder->getAutoFill('alwaysAsk')); + $this->assertEquals('autoFillColumns', $builder->getAutoFill('columns')); + $this->assertEquals('autoFillEditor', $builder->getAutoFill('editor')); + $this->assertEquals(true, $builder->getAutoFill('enable')); + $this->assertEquals('autoFillFocus', $builder->getAutoFill('focus')); + $this->assertEquals(true, $builder->getAutoFill('horizontal')); + $this->assertEquals(true, $builder->getAutoFill('update')); + $this->assertEquals(true, $builder->getAutoFill('vertical')); + + $builder->autoFillColumns([1, 2]); + $this->assertEquals([1, 2], $builder->getAutoFill('columns')); + } + +} diff --git a/tests/BuilderOptionsTest.php b/tests/BuilderOptionsTest.php index ae79bc6..a671daf 100644 --- a/tests/BuilderOptionsTest.php +++ b/tests/BuilderOptionsTest.php @@ -45,14 +45,6 @@ public function it_has_callbacks_options() $this->assertStringContainsString('test livewire', $builder->getAttribute('drawCallback')); } - /** - * @return \Yajra\DataTables\Html\Builder - */ - protected function getHtmlBuilder(): Builder - { - return app(Builder::class); - } - /** @test */ public function it_has_columns_options() { diff --git a/tests/BuilderTest.php b/tests/BuilderTest.php index e20a5e6..2e6a089 100644 --- a/tests/BuilderTest.php +++ b/tests/BuilderTest.php @@ -136,12 +136,4 @@ public function it_can_remove_table_class_attribute() $builder->removeTableClass(['a' => ' b ', ' foo bar ']); $this->assertEquals('a', $builder->getTableAttribute('class')); } - - /** - * @return \Yajra\DataTables\Html\Builder - */ - protected function getHtmlBuilder(): Builder - { - return app(Builder::class); - } } diff --git a/tests/TestCase.php b/tests/TestCase.php index c5f65ea..ef9de21 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -4,8 +4,11 @@ use Illuminate\Database\Schema\Blueprint; use Orchestra\Testbench\TestCase as BaseTestCase; +use Yajra\DataTables\DataTablesServiceProvider; +use Yajra\DataTables\Html\Builder; use Yajra\DataTables\Html\Tests\Models\Role; use Yajra\DataTables\Html\Tests\Models\User; +use Yajra\DataTables\HtmlServiceProvider; abstract class TestCase extends BaseTestCase { @@ -101,8 +104,16 @@ protected function getEnvironmentSetUp($app) protected function getPackageProviders($app): array { return [ - \Yajra\DataTables\DataTablesServiceProvider::class, - \Yajra\DataTables\HtmlServiceProvider::class, + DataTablesServiceProvider::class, + HtmlServiceProvider::class, ]; } + + /** + * @return \Yajra\DataTables\Html\Builder + */ + protected function getHtmlBuilder(): Builder + { + return app(Builder::class); + } } From 89b630cd544a8539a5e3a1c4fa530557a5c3c1e2 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Sat, 14 May 2022 12:06:32 +0800 Subject: [PATCH 044/260] Fix stan --- src/Html/Options/HasInternationalisation.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/Html/Options/HasInternationalisation.php b/src/Html/Options/HasInternationalisation.php index 5849312..a07b3f5 100644 --- a/src/Html/Options/HasInternationalisation.php +++ b/src/Html/Options/HasInternationalisation.php @@ -37,12 +37,8 @@ public function languageDecimal(string $value): static */ public function language(array|string $value): static { - if (! isset($this->attributes['language'])) { - $this->attributes['language'] = []; - } - if (is_array($value)) { - $this->attributes['language'] = array_merge($this->attributes['language'], $value); + $this->attributes['language'] = array_merge((array) $this->attributes['language'], $value); } else { $this->attributes['language']['url'] = $value; } From 07e4f33b0e44880106783979f94863b3bad5e16d Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Sat, 14 May 2022 12:09:55 +0800 Subject: [PATCH 045/260] Add buttons plugin tests --- src/Html/ColumnDefinition.php | 17 +---------------- src/Html/Options/Plugins/Buttons.php | 14 ++++++++++---- tests/BuilderOptionsPluginsTest.php | 23 +++++++++++++++++++++++ 3 files changed, 34 insertions(+), 20 deletions(-) diff --git a/src/Html/ColumnDefinition.php b/src/Html/ColumnDefinition.php index b8fd031..1c73945 100644 --- a/src/Html/ColumnDefinition.php +++ b/src/Html/ColumnDefinition.php @@ -4,24 +4,9 @@ use Illuminate\Support\Fluent; +// TODO: Review class implementation class ColumnDefinition extends Fluent { - use Options\HasFeatures; - use Options\HasCallbacks; - use Options\HasInternationalisation; - use Options\Plugins\AutoFill; - use Options\Plugins\Buttons; - use Options\Plugins\ColReorder; - use Options\Plugins\FixedColumns; - use Options\Plugins\FixedHeader; - use Options\Plugins\KeyTable; - use Options\Plugins\Responsive; - use Options\Plugins\RowGroup; - use Options\Plugins\RowReorder; - use Options\Plugins\Scroller; - use Options\Plugins\Select; - use Options\Plugins\SearchPanes; - public function targets(array $value): static { $this->attributes['targets'] = $value; diff --git a/src/Html/Options/Plugins/Buttons.php b/src/Html/Options/Plugins/Buttons.php index f35f749..219f440 100644 --- a/src/Html/Options/Plugins/Buttons.php +++ b/src/Html/Options/Plugins/Buttons.php @@ -7,10 +7,6 @@ /** * DataTables - Buttons plugin option builder. * - * @template TKey of array-key - * @template TValue - * @property array $attributes - * * @see https://datatables.net/extensions/buttons/ * @see https://datatables.net/reference/option/buttons */ @@ -35,4 +31,14 @@ public function buttons(...$buttons): static return $this; } + + /** + * Get builder buttons. + * + * @return array + */ + public function getButtons(): array + { + return $this->attributes['buttons'] ?? []; + } } diff --git a/tests/BuilderOptionsPluginsTest.php b/tests/BuilderOptionsPluginsTest.php index 355ad82..c6bdaad 100644 --- a/tests/BuilderOptionsPluginsTest.php +++ b/tests/BuilderOptionsPluginsTest.php @@ -2,6 +2,8 @@ namespace Yajra\DataTables\Html\Tests; +use Yajra\DataTables\Html\Button; + class BuilderOptionsPluginsTest extends TestCase { /** @test */ @@ -39,4 +41,25 @@ public function it_has_autofill_plugin() $this->assertEquals([1, 2], $builder->getAutoFill('columns')); } + /** @test */ + public function it_has_buttons_plugin() + { + $builder = $this->getHtmlBuilder(); + $builder->buttons( + Button::make('create'), + Button::make('edit'), + ); + + $this->assertCount(2, $builder->getAttribute('buttons')); + $this->assertCount(2, $builder->getButtons()); + $this->assertIsArray($builder->getButtons()[0]); + + $builder->buttons([ + Button::make('remove'), + ]); + + $this->assertCount(3, $builder->getButtons()); + } + + } From 1d055c20b107b7c87b628c5426877cf6a1d8d0af Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Sat, 14 May 2022 12:18:15 +0800 Subject: [PATCH 046/260] Fix colReorder plugin with tests --- src/Html/Options/Plugins/ColReorder.php | 43 +++++++++++++++++-------- tests/BuilderOptionsPluginsTest.php | 21 ++++++++++++ 2 files changed, 51 insertions(+), 13 deletions(-) diff --git a/src/Html/Options/Plugins/ColReorder.php b/src/Html/Options/Plugins/ColReorder.php index c910458..4e31c92 100644 --- a/src/Html/Options/Plugins/ColReorder.php +++ b/src/Html/Options/Plugins/ColReorder.php @@ -12,30 +12,34 @@ trait ColReorder { /** - * Set colReorder option value. - * Enable and configure the AutoFill extension for DataTables. + * Set colReorder enable option value. * - * @param bool|array $value + * @param bool $value * @return $this - * @see https://datatables.net/reference/option/colReorder + * @see https://datatables.net/reference/option/colReorder.enable */ - public function colReorder(bool|array $value = true): static + public function colReorderEnable(bool $value = true): static { - $this->attributes['colReorder'] = $value; - - return $this; + return $this->colReorder(['enable' => $value]); } /** - * Set colReorder enable option value. + * Set colReorder option value. + * Enable and configure the AutoFill extension for DataTables. * - * @param bool $value + * @param bool|array $value * @return $this - * @see https://datatables.net/reference/option/colReorder.enable + * @see https://datatables.net/reference/option/colReorder */ - public function colReorderEnable(bool $value = true): static + public function colReorder(bool|array $value = true): static { - return $this->colReorder(['enable' => $value]); + if (is_array($value)) { + $this->attributes['colReorder'] = array_merge((array) $this->attributes['colReorder'], $value); + } else { + $this->attributes['colReorder'] = $value; + } + + return $this; } /** @@ -85,4 +89,17 @@ public function colReorderRealtime(bool $value = true): static { return $this->colReorder(['realtime' => $value]); } + + /** + * @param string|null $key + * @return mixed + */ + public function getColReorder(string $key = null): mixed + { + if (is_null($key)) { + return $this->attributes['colReorder'] ?? true; + } + + return $this->attributes['colReorder'][$key] ?? false; + } } diff --git a/tests/BuilderOptionsPluginsTest.php b/tests/BuilderOptionsPluginsTest.php index c6bdaad..9661378 100644 --- a/tests/BuilderOptionsPluginsTest.php +++ b/tests/BuilderOptionsPluginsTest.php @@ -61,5 +61,26 @@ public function it_has_buttons_plugin() $this->assertCount(3, $builder->getButtons()); } + /** @test */ + public function it_has_col_reorder_plugin() + { + $builder = $this->getHtmlBuilder(); + $builder->colReorder(); + + $this->assertTrue($builder->getAttribute('colReorder')); + $this->assertTrue($builder->getColReorder()); + + $builder->colReorderEnable() + ->colReorderFixedColumnsLeft(1) + ->colReorderFixedColumnsRight(1) + ->colReorderOrder([1]) + ->colReorderRealtime(); + + $this->assertTrue($builder->getColReorder('enable')); + $this->assertEquals(1, $builder->getColReorder('fixedColumnsLeft')); + $this->assertEquals(1, $builder->getColReorder('fixedColumnsRight')); + $this->assertEquals([1], $builder->getColReorder('order')); + $this->assertEquals(true, $builder->getColReorder('realtime')); + } } From 77aa7b54696583a1886c70b7bd0663c16cb09a11 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Sat, 14 May 2022 12:22:18 +0800 Subject: [PATCH 047/260] Fix FixedColumns.php with tests --- src/Html/Options/Plugins/FixedColumns.php | 41 ++++++++++++++++------- tests/BuilderOptionsPluginsTest.php | 19 +++++++++++ 2 files changed, 48 insertions(+), 12 deletions(-) diff --git a/src/Html/Options/Plugins/FixedColumns.php b/src/Html/Options/Plugins/FixedColumns.php index 2625eee..f733b79 100644 --- a/src/Html/Options/Plugins/FixedColumns.php +++ b/src/Html/Options/Plugins/FixedColumns.php @@ -12,29 +12,33 @@ trait FixedColumns { /** - * Set fixedColumns option value. + * Set fixedColumns heightMatch option value. * - * @param bool|array $value + * @param string $value * @return $this - * @see https://datatables.net/reference/option/fixedColumns + * @see https://datatables.net/reference/option/fixedColumns.heightMatch */ - public function fixedColumns(bool|array $value = true): static + public function fixedColumnsHeightMatch(string $value = 'semiauto'): static { - $this->attributes['fixedColumns'] = $value; - - return $this; + return $this->fixedColumns(['heightMatch' => $value]); } /** - * Set fixedColumns heightMatch option value. + * Set fixedColumns option value. * - * @param string $value + * @param bool|array $value * @return $this - * @see https://datatables.net/reference/option/fixedColumns.heightMatch + * @see https://datatables.net/reference/option/fixedColumns */ - public function fixedColumnsHeightMatch(string $value = 'semiauto'): static + public function fixedColumns(bool|array $value = true): static { - return $this->fixedColumns(['heightMatch' => $value]); + if (is_array($value)) { + $this->attributes['fixedColumns'] = array_merge((array) $this->attributes['fixedColumns'], $value); + } else { + $this->attributes['fixedColumns'] = $value; + } + + return $this; } /** @@ -60,4 +64,17 @@ public function fixedColumnsRightColumns(int $value = 0): static { return $this->fixedColumns(['rightColumns' => $value]); } + + /** + * @param string|null $key + * @return mixed + */ + public function getFixedColumns(string $key = null): mixed + { + if (is_null($key)) { + return $this->attributes['fixedColumns'] ?? true; + } + + return $this->attributes['fixedColumns'][$key] ?? false; + } } diff --git a/tests/BuilderOptionsPluginsTest.php b/tests/BuilderOptionsPluginsTest.php index 9661378..eb39a7c 100644 --- a/tests/BuilderOptionsPluginsTest.php +++ b/tests/BuilderOptionsPluginsTest.php @@ -83,4 +83,23 @@ public function it_has_col_reorder_plugin() $this->assertEquals(true, $builder->getColReorder('realtime')); } + /** @test */ + public function it_has_fixed_columns_plugin() + { + $builder = $this->getHtmlBuilder(); + $builder->fixedColumns(); + + $this->assertTrue($builder->getAttribute('fixedColumns')); + $this->assertTrue($builder->getFixedColumns()); + + $builder->fixedColumnsHeightMatch() + ->fixedColumnsLeftColumns() + ->fixedColumnsRightColumns(); + + $this->assertEquals('semiauto', $builder->getFixedColumns('heightMatch')); + $this->assertEquals(1, $builder->getFixedColumns('leftColumns')); + $this->assertEquals(0, $builder->getFixedColumns('rightColumns')); + } + + } From ffbd25d8322528ef627fe053b51c8144dc7b2de9 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Sat, 14 May 2022 12:26:44 +0800 Subject: [PATCH 048/260] Fix FixedHeader.php with tests --- src/Html/Options/Plugins/FixedHeader.php | 42 +++++++++++++++++------- tests/BuilderOptionsPluginsTest.php | 20 +++++++++++ 2 files changed, 50 insertions(+), 12 deletions(-) diff --git a/src/Html/Options/Plugins/FixedHeader.php b/src/Html/Options/Plugins/FixedHeader.php index af0ee84..9dc45d9 100644 --- a/src/Html/Options/Plugins/FixedHeader.php +++ b/src/Html/Options/Plugins/FixedHeader.php @@ -12,29 +12,34 @@ trait FixedHeader { /** - * Set fixedHeader option value. + * Set fixedHeader footer option value. * - * @param bool|array $value + * @param bool $value * @return $this - * @see https://datatables.net/reference/option/fixedHeader + * @see https://datatables.net/reference/option/fixedHeader.footer */ - public function fixedHeader(bool|array $value = true): static + public function fixedHeaderFooter(bool $value = true): static { - $this->attributes['fixedHeader'] = $value; - - return $this; + return $this->fixedHeader(['footer' => $value]); } /** - * Set fixedHeader footer option value. + * Set fixedHeader option value. * - * @param bool $value + * @param bool|array $value * @return $this - * @see https://datatables.net/reference/option/fixedHeader.footer + * @see https://datatables.net/reference/option/fixedHeader */ - public function fixedHeaderFooter(bool $value = true): static + public function fixedHeader(bool|array $value = true): static { - return $this->fixedHeader(['footer' => $value]); + if (is_array($value)) { + $this->attributes['fixedHeader'] = array_merge((array) $this->attributes['fixedHeader'], $value); + } else { + $this->attributes['fixedHeader'] = $value; + } + + + return $this; } /** @@ -72,4 +77,17 @@ public function fixedHeaderHeaderOffset(int $value = 0): static { return $this->fixedHeader(['headerOffset' => $value]); } + + /** + * @param string|null $key + * @return mixed + */ + public function getFixedHeader(string $key = null): mixed + { + if (is_null($key)) { + return $this->attributes['fixedHeader'] ?? true; + } + + return $this->attributes['fixedHeader'][$key] ?? false; + } } diff --git a/tests/BuilderOptionsPluginsTest.php b/tests/BuilderOptionsPluginsTest.php index eb39a7c..e101c19 100644 --- a/tests/BuilderOptionsPluginsTest.php +++ b/tests/BuilderOptionsPluginsTest.php @@ -101,5 +101,25 @@ public function it_has_fixed_columns_plugin() $this->assertEquals(0, $builder->getFixedColumns('rightColumns')); } + /** @test */ + public function it_has_fixed_header_plugin() + { + $builder = $this->getHtmlBuilder(); + $builder->fixedHeader(); + + $this->assertTrue($builder->getAttribute('fixedHeader')); + $this->assertTrue($builder->getFixedHeader()); + + $builder->fixedHeaderFooter() + ->fixedHeaderFooterOffset() + ->fixedHeaderHeader() + ->fixedHeaderHeaderOffset(); + + $this->assertEquals(true, $builder->getFixedHeader('footer')); + $this->assertEquals(0, $builder->getFixedHeader('offset')); + $this->assertEquals(true, $builder->getFixedHeader('header')); + $this->assertEquals(0, $builder->getFixedHeader('headerOffset')); + } + } From 9179a0c66eac8a3342c5e5f508373512b6f94e20 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Sat, 14 May 2022 12:35:45 +0800 Subject: [PATCH 049/260] Fix keys plugin with tests --- src/Html/Options/Plugins/FixedHeader.php | 1 - src/Html/Options/Plugins/KeyTable.php | 45 ++++++++++++++++-------- tests/BuilderOptionsPluginsTest.php | 37 +++++++++++++++++++ 3 files changed, 68 insertions(+), 15 deletions(-) diff --git a/src/Html/Options/Plugins/FixedHeader.php b/src/Html/Options/Plugins/FixedHeader.php index 9dc45d9..5d9a509 100644 --- a/src/Html/Options/Plugins/FixedHeader.php +++ b/src/Html/Options/Plugins/FixedHeader.php @@ -38,7 +38,6 @@ public function fixedHeader(bool|array $value = true): static $this->attributes['fixedHeader'] = $value; } - return $this; } diff --git a/src/Html/Options/Plugins/KeyTable.php b/src/Html/Options/Plugins/KeyTable.php index c7c2654..0cbb4db 100644 --- a/src/Html/Options/Plugins/KeyTable.php +++ b/src/Html/Options/Plugins/KeyTable.php @@ -12,29 +12,33 @@ trait KeyTable { /** - * Set keys option value. + * Set keys blurable option value. * - * @param bool|array $value + * @param bool $value * @return $this - * @see https://datatables.net/reference/option/keys + * @see https://datatables.net/reference/option/keys.blurable */ - public function keys(bool|array $value = true): static + public function keysBlurable(bool $value = true): static { - $this->attributes['keys'] = $value; - - return $this; + return $this->keys(['blurable' => $value]); } /** - * Set keys blurable option value. + * Set keys option value. * - * @param bool $value + * @param bool|array $value * @return $this - * @see https://datatables.net/reference/option/keys.blurable + * @see https://datatables.net/reference/option/keys */ - public function keysBlurable(bool $value = true): static + public function keys(bool|array $value = true): static { - return $this->keys(['blurable' => $value]); + if (is_array($value)) { + $this->attributes['keys'] = array_merge((array) $this->attributes['keys'], $value); + } else { + $this->attributes['keys'] = $value; + } + + return $this; } /** @@ -148,11 +152,11 @@ public function keysFocus(string $value): static /** * Set key's keys option value. * - * @param array|string $value + * @param array|null $value * @return $this * @see https://datatables.net/reference/option/keys.keys */ - public function keysKeys(array|string $value): static + public function keysKeys(array $value = null): static { return $this->keys(['keys' => $value]); } @@ -168,4 +172,17 @@ public function keysTabIndex(int $value): static { return $this->keys(['tabIndex' => $value]); } + + /** + * @param string|null $key + * @return mixed + */ + public function getKeys(string $key = null): mixed + { + if (is_null($key)) { + return $this->attributes['keys'] ?? true; + } + + return $this->attributes['keys'][$key] ?? false; + } } diff --git a/tests/BuilderOptionsPluginsTest.php b/tests/BuilderOptionsPluginsTest.php index e101c19..2b7ec45 100644 --- a/tests/BuilderOptionsPluginsTest.php +++ b/tests/BuilderOptionsPluginsTest.php @@ -121,5 +121,42 @@ public function it_has_fixed_header_plugin() $this->assertEquals(0, $builder->getFixedHeader('headerOffset')); } + /** @test */ + public function it_has_keys_plugin() + { + + $builder = $this->getHtmlBuilder(); + $builder->keys(); + + $this->assertTrue($builder->getAttribute('keys')); + $this->assertTrue($builder->getKeys()); + + $builder->keysBlurable() + ->keysClassName() + ->keysClipboard() + ->keysClipboardOrthogonal() + ->keysColumns('name') + ->keysEditAutoSelect() + ->keysEditOnFocus() + ->keysEditor('editor') + ->keysEditorKeys() + ->keysFocus(':eq(0)') + ->keysKeys(["charCodeAt(0)"]) + ->keysTabIndex(1); + + $this->assertEquals(true, $builder->getKeys('blurable')); + $this->assertEquals('focus', $builder->getKeys('className')); + $this->assertEquals(true, $builder->getKeys('clipboard')); + $this->assertEquals('display', $builder->getKeys('clipboardOrthogonal')); + $this->assertEquals('name', $builder->getKeys('columns')); + $this->assertEquals(true, $builder->getKeys('editAutoSelect')); + $this->assertEquals(true, $builder->getKeys('editOnFocus')); + $this->assertEquals('editor', $builder->getKeys('editor')); + $this->assertEquals('navigation-only', $builder->getKeys('editorKeys')); + $this->assertEquals(':eq(0)', $builder->getKeys('focus')); + $this->assertEquals(["charCodeAt(0)"], $builder->getKeys('keys')); + $this->assertEquals(1, $builder->getKeys('tabIndex')); + } + } From d929fff329f67c86ea4ffc174617a6cee2c11ed5 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Sat, 14 May 2022 12:52:23 +0800 Subject: [PATCH 050/260] Fix responsive plugin with tests --- src/Html/Options/Plugins/Responsive.php | 60 +++++++++++++++++-------- tests/BuilderOptionsPluginsTest.php | 23 +++++++++- 2 files changed, 64 insertions(+), 19 deletions(-) diff --git a/src/Html/Options/Plugins/Responsive.php b/src/Html/Options/Plugins/Responsive.php index 3eccc6d..08f71f5 100644 --- a/src/Html/Options/Plugins/Responsive.php +++ b/src/Html/Options/Plugins/Responsive.php @@ -11,20 +11,6 @@ */ trait Responsive { - /** - * Set responsive option value. - * - * @param bool|array $value - * @return $this - * @see https://datatables.net/reference/option/responsive - */ - public function responsive(bool|array $value = true): static - { - $this->attributes['responsive'] = $value; - - return $this; - } - /** * Set responsive breakpoints option value. * @@ -38,15 +24,21 @@ public function responsiveBreakpoints(array $value): static } /** - * Set responsive details option value. + * Set responsive option value. * * @param bool|array $value * @return $this - * @see https://datatables.net/reference/option/responsive.details + * @see https://datatables.net/reference/option/responsive */ - public function responsiveDetails(bool|array $value): static + public function responsive(bool|array $value = true): static { - return $this->responsive(['details' => $value]); + if (is_array($value)) { + $this->attributes['responsive'] = array_merge((array) $this->attributes['responsive'], $value); + } else { + $this->attributes['responsive'] = $value; + } + + return $this; } /** @@ -61,6 +53,25 @@ public function responsiveDetailsDisplay(array|string $value): static return $this->responsiveDetails(['display' => $value]); } + /** + * Set responsive details option value. + * + * @param bool|array $value + * @return $this + * @see https://datatables.net/reference/option/responsive.details + */ + public function responsiveDetails(bool|array $value): static + { + $responsive = (array) $this->getResponsive(); + if (is_array($value)) { + $responsive['details'] = array_merge((array) ($responsive['details'] ?? []), $value); + } else { + $responsive['details'] = $value; + } + + return $this->responsive($responsive); + } + /** * Set responsive details renderer option value. * @@ -108,4 +119,17 @@ public function responsiveOrthogonal(string $value): static { return $this->responsive(['orthogonal' => $value]); } + + /** + * @param string|null $key + * @return mixed + */ + public function getResponsive(string $key = null): mixed + { + if (is_null($key)) { + return $this->attributes['responsive'] ?? true; + } + + return $this->attributes['responsive'][$key] ?? false; + } } diff --git a/tests/BuilderOptionsPluginsTest.php b/tests/BuilderOptionsPluginsTest.php index 2b7ec45..924c3c8 100644 --- a/tests/BuilderOptionsPluginsTest.php +++ b/tests/BuilderOptionsPluginsTest.php @@ -158,5 +158,26 @@ public function it_has_keys_plugin() $this->assertEquals(1, $builder->getKeys('tabIndex')); } - + /** @test */ + public function it_has_responsive_plugin() + { + $builder = $this->getHtmlBuilder(); + $builder->responsive(); + + $this->assertTrue($builder->getAttribute('responsive')); + $this->assertTrue($builder->getResponsive()); + + $builder->responsiveBreakpoints([1]) + ->responsiveDetailsDisplay('display') + ->responsiveDetailsRenderer('renderer') + ->responsiveDetailsTarget('target') + ->responsiveDetailsType('type') + ->responsiveOrthogonal('orthogonal'); + $this->assertEquals([1], $builder->getResponsive('breakpoints')); + $this->assertEquals('display', $builder->getResponsive('details')['display']); + $this->assertEquals('renderer', $builder->getResponsive('details')['renderer']); + $this->assertEquals('target', $builder->getResponsive('details')['target']); + $this->assertEquals('type', $builder->getResponsive('details')['type']); + $this->assertEquals('orthogonal', $builder->getResponsive('orthogonal')); + } } From 1480f5696bbc0dedd25ed31504a137b98c635103 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Sat, 14 May 2022 12:58:23 +0800 Subject: [PATCH 051/260] Fix rowGroup plugin with tests --- src/Html/Options/Plugins/RowGroup.php | 41 +++++++++++++++++++-------- tests/BuilderOptionsPluginsTest.php | 28 ++++++++++++++++++ 2 files changed, 57 insertions(+), 12 deletions(-) diff --git a/src/Html/Options/Plugins/RowGroup.php b/src/Html/Options/Plugins/RowGroup.php index ba9b96e..d10a4e4 100644 --- a/src/Html/Options/Plugins/RowGroup.php +++ b/src/Html/Options/Plugins/RowGroup.php @@ -12,29 +12,33 @@ trait RowGroup { /** - * Set rowGroup option value. + * Set rowGroup className option value. * - * @param bool|array $value + * @param string $value * @return $this - * @see https://datatables.net/reference/option/rowGroup + * @see https://datatables.net/reference/option/rowGroup.className */ - public function rowGroup(bool|array $value = true): static + public function rowGroupUpdate(string $value = 'group'): static { - $this->attributes['rowGroup'] = $value; - - return $this; + return $this->rowGroup(['className' => $value]); } /** - * Set rowGroup className option value. + * Set rowGroup option value. * - * @param string $value + * @param bool|array $value * @return $this - * @see https://datatables.net/reference/option/rowGroup.className + * @see https://datatables.net/reference/option/rowGroup */ - public function rowGroupUpdate(string $value = 'group'): static + public function rowGroup(bool|array $value = true): static { - return $this->rowGroup(['className' => $value]); + if (is_array($value)) { + $this->attributes['rowGroup'] = array_merge((array) $this->attributes['rowGroup'], $value); + } else { + $this->attributes['rowGroup'] = $value; + } + + return $this; } /** @@ -120,4 +124,17 @@ public function rowGroupStartRender(string $value = null): static { return $this->rowGroup(['startRender' => $value]); } + + /** + * @param string|null $key + * @return mixed + */ + public function getRowGroup(string $key = null): mixed + { + if (is_null($key)) { + return $this->attributes['rowGroup'] ?? true; + } + + return $this->attributes['rowGroup'][$key] ?? false; + } } diff --git a/tests/BuilderOptionsPluginsTest.php b/tests/BuilderOptionsPluginsTest.php index 924c3c8..2d466d0 100644 --- a/tests/BuilderOptionsPluginsTest.php +++ b/tests/BuilderOptionsPluginsTest.php @@ -180,4 +180,32 @@ public function it_has_responsive_plugin() $this->assertEquals('type', $builder->getResponsive('details')['type']); $this->assertEquals('orthogonal', $builder->getResponsive('orthogonal')); } + + /** @test */ + public function it_has_row_group_plugin() + { + $builder = $this->getHtmlBuilder(); + $builder->rowGroup(); + + $this->assertTrue($builder->getAttribute('rowGroup')); + $this->assertTrue($builder->getRowGroup()); + + $builder->rowGroupDataSrc([1]) + ->rowGroupEmptyDataGroup() + ->rowGroupEnable() + ->rowGroupEndClassName() + ->rowGroupEndRender('fn') + ->rowGroupStartClassName() + ->rowGroupStartRender(); + + $this->assertEquals([1], $builder->getRowGroup('dataSrc')); + $this->assertEquals('No Group', $builder->getRowGroup('emptyDataGroup')); + $this->assertEquals(true, $builder->getRowGroup('enable')); + $this->assertEquals('group-end', $builder->getRowGroup('endClassName')); + $this->assertEquals('fn', $builder->getRowGroup('endRender')); + $this->assertEquals('group-start', $builder->getRowGroup('startClassName')); + $this->assertEquals(null, $builder->getRowGroup('startRender')); + } + + } From aa607b6b8f9ec56634e5ca55a4a50af95f979997 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Sat, 14 May 2022 13:04:28 +0800 Subject: [PATCH 052/260] Fix rowReorder plugin with tests --- src/Html/Options/Plugins/RowReorder.php | 41 +++++++++++++++++-------- tests/BuilderOptionsPluginsTest.php | 28 +++++++++++++++++ 2 files changed, 57 insertions(+), 12 deletions(-) diff --git a/src/Html/Options/Plugins/RowReorder.php b/src/Html/Options/Plugins/RowReorder.php index 05fbc76..6cb8d50 100644 --- a/src/Html/Options/Plugins/RowReorder.php +++ b/src/Html/Options/Plugins/RowReorder.php @@ -12,29 +12,33 @@ trait RowReorder { /** - * Set rowReorder option value. + * Set rowReorder dataSrc option value. * - * @param bool|array $value + * @param array|int $value * @return $this - * @see https://datatables.net/reference/option/rowReorder + * @see https://datatables.net/reference/option/rowReorder.dataSrc */ - public function rowReorder(bool|array $value = true): static + public function rowReorderDataSrc(array|int $value = 0): static { - $this->attributes['rowReorder'] = $value; - - return $this; + return $this->rowReorder(['dataSrc' => $value]); } /** - * Set rowReorder dataSrc option value. + * Set rowReorder option value. * - * @param array|int $value + * @param bool|array $value * @return $this - * @see https://datatables.net/reference/option/rowReorder.dataSrc + * @see https://datatables.net/reference/option/rowReorder */ - public function rowReorderDataSrc(array|int $value = 0): static + public function rowReorder(bool|array $value = true): static { - return $this->rowReorder(['dataSrc' => $value]); + if (is_array($value)) { + $this->attributes['rowReorder'] = array_merge((array) $this->attributes['rowReorder'], $value); + } else { + $this->attributes['rowReorder'] = $value; + } + + return $this; } /** @@ -108,4 +112,17 @@ public function rowReorderUpdate(bool $value = true): static { return $this->rowReorder(['update' => $value]); } + + /** + * @param string|null $key + * @return mixed + */ + public function getRowReorder(string $key = null): mixed + { + if (is_null($key)) { + return $this->attributes['rowReorder'] ?? true; + } + + return $this->attributes['rowReorder'][$key] ?? false; + } } diff --git a/tests/BuilderOptionsPluginsTest.php b/tests/BuilderOptionsPluginsTest.php index 2d466d0..b0f491f 100644 --- a/tests/BuilderOptionsPluginsTest.php +++ b/tests/BuilderOptionsPluginsTest.php @@ -207,5 +207,33 @@ public function it_has_row_group_plugin() $this->assertEquals(null, $builder->getRowGroup('startRender')); } + /** @test */ + public function it_has_row_reorder_plugin() + { + $builder = $this->getHtmlBuilder(); + $builder->rowReorder(); + + $this->assertTrue($builder->getAttribute('rowReorder')); + $this->assertTrue($builder->getRowReorder()); + + $builder->rowReorderDataSrc([1]) + ->rowReorderEditor('editor') + ->rowReorderEnable() + ->rowReorderFormOptions(['main' => []]) + ->rowReorderSelector() + ->rowReorderSnapX() + ->rowReorderUpdate(); + + $this->assertEquals([1], $builder->getRowReorder('dataSrc')); + $this->assertEquals('editor', $builder->getRowReorder('editor')); + $this->assertEquals(true, $builder->getRowReorder('enable')); + $this->assertEquals(['main' => []], $builder->getRowReorder('formOptions')); + $this->assertEquals('td:first-child', $builder->getRowReorder('selector')); + $this->assertEquals(true, $builder->getRowReorder('snapX')); + $this->assertEquals(true, $builder->getRowReorder('update')); + + + } + } From cb5bffe241fc6c4c199a81f9b41a9c0e7ec83473 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Sat, 14 May 2022 13:07:41 +0800 Subject: [PATCH 053/260] Fix scroller plugin with tests --- src/Html/Options/Plugins/Scroller.php | 41 +++++++++++++++++++-------- tests/BuilderOptionsPluginsTest.php | 22 +++++++++++++- 2 files changed, 50 insertions(+), 13 deletions(-) diff --git a/src/Html/Options/Plugins/Scroller.php b/src/Html/Options/Plugins/Scroller.php index 3b0cd62..f0b21e6 100644 --- a/src/Html/Options/Plugins/Scroller.php +++ b/src/Html/Options/Plugins/Scroller.php @@ -12,29 +12,33 @@ trait Scroller { /** - * Set scroller option value. + * Set scroller boundaryScale option value. * - * @param bool|array $value + * @param float $value * @return $this - * @see https://datatables.net/reference/option/scroller + * @see https://datatables.net/reference/option/scroller.boundaryScale */ - public function scroller(bool|array $value = true): static + public function scrollerBoundaryScale(float $value = 0.5): static { - $this->attributes['scroller'] = $value; - - return $this; + return $this->scroller(['boundaryScale' => $value]); } /** - * Set scroller boundaryScale option value. + * Set scroller option value. * - * @param float $value + * @param bool|array $value * @return $this - * @see https://datatables.net/reference/option/scroller.boundaryScale + * @see https://datatables.net/reference/option/scroller */ - public function scrollerBoundaryScale(float $value = 0.5): static + public function scroller(bool|array $value = true): static { - return $this->scroller(['boundaryScale' => $value]); + if (is_array($value)) { + $this->attributes['scroller'] = array_merge((array) $this->attributes['scroller'], $value); + } else { + $this->attributes['scroller'] = $value; + } + + return $this; } /** @@ -84,4 +88,17 @@ public function scrollerServerWait(int $value = 200): static { return $this->scroller(['serverWait' => $value]); } + + /** + * @param string|null $key + * @return mixed + */ + public function getScroller(string $key = null): mixed + { + if (is_null($key)) { + return $this->attributes['scroller'] ?? true; + } + + return $this->attributes['scroller'][$key] ?? false; + } } diff --git a/tests/BuilderOptionsPluginsTest.php b/tests/BuilderOptionsPluginsTest.php index b0f491f..b5c6a34 100644 --- a/tests/BuilderOptionsPluginsTest.php +++ b/tests/BuilderOptionsPluginsTest.php @@ -231,8 +231,28 @@ public function it_has_row_reorder_plugin() $this->assertEquals('td:first-child', $builder->getRowReorder('selector')); $this->assertEquals(true, $builder->getRowReorder('snapX')); $this->assertEquals(true, $builder->getRowReorder('update')); + } - + /** @test */ + public function it_has_scroller_plugin() + { + $builder = $this->getHtmlBuilder(); + $builder->scroller(); + + $this->assertTrue($builder->getAttribute('scroller')); + $this->assertTrue($builder->getScroller()); + + $builder->scrollerBoundaryScale() + ->scrollerDisplayBuffer() + ->scrollerLoadingIndicator() + ->scrollerRowHeight() + ->scrollerServerWait(); + + $this->assertEquals(0.5, $builder->getScroller('boundaryScale')); + $this->assertEquals(9, $builder->getScroller('displayBuffer')); + $this->assertEquals(true, $builder->getScroller('loadingIndicator')); + $this->assertEquals('auto', $builder->getScroller('rowHeight')); + $this->assertEquals(200, $builder->getScroller('serverWait')); } From c6ff6fb57c6cf07e8a28297321345fa9b6156362 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Sat, 14 May 2022 13:21:19 +0800 Subject: [PATCH 054/260] Fix searchPanes plugin with tests --- src/Html/Options/Plugins/SearchPanes.php | 17 +++++++++++++++-- tests/BuilderOptionsPluginsTest.php | 23 +++++++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/Html/Options/Plugins/SearchPanes.php b/src/Html/Options/Plugins/SearchPanes.php index b86206d..0bc9e4a 100644 --- a/src/Html/Options/Plugins/SearchPanes.php +++ b/src/Html/Options/Plugins/SearchPanes.php @@ -16,11 +16,11 @@ trait SearchPanes /** * Set searchPane option value. * - * @param bool|array $value + * @param array|bool|callable $value * @return $this * @see https://datatables.net/reference/option/searchPanes */ - public function searchPanes(bool|array $value = true): static + public function searchPanes(array|Arrayable|bool|callable $value = true): static { if (is_callable($value)) { $value = app()->call($value); @@ -38,4 +38,17 @@ public function searchPanes(bool|array $value = true): static return $this; } + + /** + * @param string|null $key + * @return mixed + */ + public function getSearchPanes(string $key = null): mixed + { + if (is_null($key)) { + return $this->attributes['searchPanes'] ?? true; + } + + return $this->attributes['searchPanes'][$key] ?? false; + } } diff --git a/tests/BuilderOptionsPluginsTest.php b/tests/BuilderOptionsPluginsTest.php index b5c6a34..ffbf03c 100644 --- a/tests/BuilderOptionsPluginsTest.php +++ b/tests/BuilderOptionsPluginsTest.php @@ -3,6 +3,7 @@ namespace Yajra\DataTables\Html\Tests; use Yajra\DataTables\Html\Button; +use Yajra\DataTables\Html\SearchPane; class BuilderOptionsPluginsTest extends TestCase { @@ -255,5 +256,27 @@ public function it_has_scroller_plugin() $this->assertEquals(200, $builder->getScroller('serverWait')); } + /** @test */ + public function it_has_search_panes_plugin() + { + $builder = $this->getHtmlBuilder(); + $builder->searchPanes(); + + $this->assertEquals(['show' => true], $builder->getAttribute('searchPanes')); + $this->assertIsArray($builder->getSearchPanes()); + $builder->searchPanes(false); + $this->assertEquals(['show' => false], $builder->getAttribute('searchPanes')); + + $builder->searchPanes(['hide' => true]); + $this->assertEquals(['hide' => true], $builder->getAttribute('searchPanes')); + + $builder->searchPanes(function () { + return ['show' => true]; + }); + $this->assertEquals(['show' => true], $builder->getAttribute('searchPanes')); + + $builder->searchPanes(SearchPane::make()->show()->cascadePanes()); + $this->assertEquals(['show' => true, 'cascadePanes' => true], $builder->getAttribute('searchPanes')); + } } From 8f1781c55c61bbb869818012c38a7a8612be3506 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Sat, 14 May 2022 13:48:14 +0800 Subject: [PATCH 055/260] Fix select plugin with tests --- src/Html/Options/Plugins/Select.php | 95 +++++++++++++---------------- tests/BuilderOptionsPluginsTest.php | 53 ++++++++++++++++ 2 files changed, 95 insertions(+), 53 deletions(-) diff --git a/src/Html/Options/Plugins/Select.php b/src/Html/Options/Plugins/Select.php index f0373e1..9e67cf3 100644 --- a/src/Html/Options/Plugins/Select.php +++ b/src/Html/Options/Plugins/Select.php @@ -12,20 +12,6 @@ */ trait Select { - /** - * Set select option value. - * - * @param bool|array $value - * @return $this - * @see https://datatables.net/reference/option/select - */ - public function select(bool|array $value = true): static - { - $this->attributes['select'] = $value; - - return $this; - } - /** * Set select blurable option value. * @@ -35,9 +21,7 @@ public function select(bool|array $value = true): static */ public function selectBlurable(bool $value = true): static { - $this->attributes['select']['blurable'] = $value; - - return $this; + return $this->select(['blurable' => $value]); } /** @@ -49,9 +33,7 @@ public function selectBlurable(bool $value = true): static */ public function selectClassName(string $value = 'selected'): static { - $this->attributes['select']['className'] = $value; - - return $this; + return $this->select(['className' => $value]); } /** @@ -80,9 +62,7 @@ public function selectAddClassName(string $class): static */ public function selectInfo(bool $value = true): static { - $this->attributes['select']['info'] = $value; - - return $this; + return $this->select(['info' => $value]); } /** @@ -94,9 +74,7 @@ public function selectInfo(bool $value = true): static */ public function selectItems(string $value = 'row'): static { - $this->attributes['select']['items'] = $value; - - return $this; + return $this->select(['items' => $value]); } /** @@ -107,9 +85,7 @@ public function selectItems(string $value = 'row'): static */ public function selectItemsRow(): static { - $this->attributes['select']['items'] = Builder::SELECT_ITEMS_ROW; - - return $this; + return $this->select(['items' => Builder::SELECT_ITEMS_ROW]); } /** @@ -120,9 +96,7 @@ public function selectItemsRow(): static */ public function selectItemsColumn(): static { - $this->attributes['select']['items'] = Builder::SELECT_ITEMS_COLUMN; - - return $this; + return $this->select(['items' => Builder::SELECT_ITEMS_COLUMN]); } /** @@ -133,9 +107,7 @@ public function selectItemsColumn(): static */ public function selectItemsCell(): static { - $this->attributes['select']['items'] = Builder::SELECT_ITEMS_CELL; - - return $this; + return $this->select(['items' => Builder::SELECT_ITEMS_CELL]); } /** @@ -147,9 +119,7 @@ public function selectItemsCell(): static */ public function selectSelector(string $value = 'td'): static { - $this->attributes['select']['selector'] = $value; - - return $this; + return $this->select(['selector' => $value]); } /** @@ -161,9 +131,7 @@ public function selectSelector(string $value = 'td'): static */ public function selectStyle(string $value = 'os'): static { - $this->attributes['select']['style'] = $value; - - return $this; + return $this->select(['style' => $value]); } /** @@ -174,9 +142,7 @@ public function selectStyle(string $value = 'os'): static */ public function selectStyleApi(): static { - $this->attributes['select']['style'] = Builder::SELECT_STYLE_API; - - return $this; + return $this->select(['style' => Builder::SELECT_STYLE_API]); } /** @@ -187,7 +153,23 @@ public function selectStyleApi(): static */ public function selectStyleSingle(): static { - $this->attributes['select']['style'] = Builder::SELECT_STYLE_SINGLE; + return $this->select(['style' => Builder::SELECT_STYLE_SINGLE]); + } + + /** + * Set select option value. + * + * @param bool|array $value + * @return $this + * @see https://datatables.net/reference/option/select + */ + public function select(bool|array $value = true): static + { + if (is_array($value)) { + $this->attributes['select'] = array_merge((array) $this->attributes['select'], $value); + } else { + $this->attributes['select'] = $value; + } return $this; } @@ -200,9 +182,7 @@ public function selectStyleSingle(): static */ public function selectStyleMulti(): static { - $this->attributes['select']['style'] = Builder::SELECT_STYLE_MULTI; - - return $this; + return $this->select(['style' => Builder::SELECT_STYLE_MULTI]); } /** @@ -213,9 +193,7 @@ public function selectStyleMulti(): static */ public function selectStyleOS(): static { - $this->attributes['select']['style'] = Builder::SELECT_STYLE_OS; - - return $this; + return $this->select(['style' => Builder::SELECT_STYLE_OS]); } /** @@ -226,8 +204,19 @@ public function selectStyleOS(): static */ public function selectStyleMultiShift(): static { - $this->attributes['select']['style'] = Builder::SELECT_STYLE_MULTI_SHIFT; + return $this->select(['style' => Builder::SELECT_STYLE_MULTI_SHIFT]); + } - return $this; + /** + * @param string|null $key + * @return mixed + */ + public function getSelect(string $key = null): mixed + { + if (is_null($key)) { + return $this->attributes['select'] ?? true; + } + + return $this->attributes['select'][$key] ?? false; } } diff --git a/tests/BuilderOptionsPluginsTest.php b/tests/BuilderOptionsPluginsTest.php index ffbf03c..8039707 100644 --- a/tests/BuilderOptionsPluginsTest.php +++ b/tests/BuilderOptionsPluginsTest.php @@ -2,6 +2,7 @@ namespace Yajra\DataTables\Html\Tests; +use Yajra\DataTables\Html\Builder; use Yajra\DataTables\Html\Button; use Yajra\DataTables\Html\SearchPane; @@ -279,4 +280,56 @@ public function it_has_search_panes_plugin() $builder->searchPanes(SearchPane::make()->show()->cascadePanes()); $this->assertEquals(['show' => true, 'cascadePanes' => true], $builder->getAttribute('searchPanes')); } + + /** @test */ + public function it_has_select_plugin() + { + $builder = $this->getHtmlBuilder(); + $builder->select(); + + $this->assertTrue($builder->getAttribute('select')); + $this->assertTrue($builder->getSelect()); + + $builder->selectBlurable() + ->selectClassName() + ->selectInfo() + ->selectItems() + ->selectSelector() + ->selectStyle(); + + $this->assertEquals(true, $builder->getSelect('blurable')); + $this->assertEquals('selected', $builder->getSelect('className')); + $this->assertEquals(true, $builder->getSelect('info')); + $this->assertEquals('row', $builder->getSelect('items')); + $this->assertEquals('td', $builder->getSelect('selector')); + $this->assertEquals('os', $builder->getSelect('style')); + + $builder->selectAddClassName('test'); + $this->assertEquals('selected test', $builder->getSelect('className')); + + $builder->selectItemsRow(); + $this->assertEquals(Builder::SELECT_ITEMS_ROW, $builder->getSelect('items')); + + $builder->selectItemsColumn(); + $this->assertEquals(Builder::SELECT_ITEMS_COLUMN, $builder->getSelect('items')); + + $builder->selectItemsCell(); + $this->assertEquals(Builder::SELECT_ITEMS_CELL, $builder->getSelect('items')); + + $builder->selectStyleSingle(); + $this->assertEquals(Builder::SELECT_STYLE_SINGLE, $builder->getSelect('style')); + + $builder->selectStyleMulti(); + $this->assertEquals(Builder::SELECT_STYLE_MULTI, $builder->getSelect('style')); + + $builder->selectStyleOS(); + $this->assertEquals(Builder::SELECT_STYLE_OS, $builder->getSelect('style')); + + $builder->selectStyleMultiShift(); + $this->assertEquals(Builder::SELECT_STYLE_MULTI_SHIFT, $builder->getSelect('style')); + + $builder->selectStyleApi(); + $this->assertEquals(Builder::SELECT_STYLE_API, $builder->getSelect('style')); + } + } From 34b9cbec0c2c07a69f9013089c0cc2d11545266d Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Sat, 14 May 2022 14:13:36 +0800 Subject: [PATCH 056/260] Fix language options with tests --- src/Html/Options/HasInternationalisation.php | 2 +- tests/BuilderOptionsLanguageTest.php | 110 +++++++++++++++++++ 2 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 tests/BuilderOptionsLanguageTest.php diff --git a/src/Html/Options/HasInternationalisation.php b/src/Html/Options/HasInternationalisation.php index a07b3f5..3c910df 100644 --- a/src/Html/Options/HasInternationalisation.php +++ b/src/Html/Options/HasInternationalisation.php @@ -38,7 +38,7 @@ public function languageDecimal(string $value): static public function language(array|string $value): static { if (is_array($value)) { - $this->attributes['language'] = array_merge((array) $this->attributes['language'], $value); + $this->attributes['language'] = array_merge((array) ($this->attributes['language'] ?? []), $value); } else { $this->attributes['language']['url'] = $value; } diff --git a/tests/BuilderOptionsLanguageTest.php b/tests/BuilderOptionsLanguageTest.php new file mode 100644 index 0000000..d1a467b --- /dev/null +++ b/tests/BuilderOptionsLanguageTest.php @@ -0,0 +1,110 @@ +getHtmlBuilder(); + $builder->languageAria(['paginate' => ['first' => 'First']]); + $this->assertEquals(['paginate' => ['first' => 'First']], $builder->getLanguage('aria')); + + $builder->languageAriaPaginate(['first' => 'First']); + $this->assertEquals(['first' => 'First'], $builder->getLanguage('aria')['paginate']); + + $builder->languageAriaPaginateFirst('First'); + $this->assertEquals('First', $builder->getLanguage('aria')['paginate']['first']); + + $builder->languageAriaPaginateLast('Last'); + $this->assertEquals('Last', $builder->getLanguage('aria')['paginate']['last']); + + $builder->languageAriaPaginateNext('Next'); + $this->assertEquals('Next', $builder->getLanguage('aria')['paginate']['next']); + + $builder->languageAriaPaginatePrevious('Previous'); + $this->assertEquals('Previous', $builder->getLanguage('aria')['paginate']['previous']); + + $builder->languageAriaSortAscending('languageAriaSortAscending'); + $this->assertEquals('languageAriaSortAscending', $builder->getLanguage('aria')['sortAscending']); + + $builder->languageAriaSortDescending('languageAriaSortDescending'); + $this->assertEquals('languageAriaSortDescending', $builder->getLanguage('aria')['sortDescending']); + } + + /** @test */ + public function it_has_language_autofill_options() + { + $builder = $this->getHtmlBuilder(); + $builder->languageAutoFill(['button' => 'button']); + $this->assertEquals(['button' => 'button'], $builder->getLanguage('autoFill')); + + $builder->languageAutoFillButton('button'); + $this->assertEquals('button', $builder->getLanguage('autoFill')['button']); + + $builder->languageAutoFillCancel('cancel'); + $this->assertEquals('cancel', $builder->getLanguage('autoFill')['cancel']); + + $builder->languageAutoFillFill('fill'); + $this->assertEquals('fill', $builder->getLanguage('autoFill')['fill']); + + $builder->languageAutoFillFillHorizontal('languageAutoFillFillHorizontal'); + $this->assertEquals('languageAutoFillFillHorizontal', $builder->getLanguage('autoFill')['fillHorizontal']); + + $builder->languageAutoFillFillVertical('languageAutoFillFillVertical'); + $this->assertEquals('languageAutoFillFillVertical', $builder->getLanguage('autoFill')['fillVertical']); + + $builder->languageAutoFillIncrement('languageAutoFillIncrement'); + $this->assertEquals('languageAutoFillIncrement', $builder->getLanguage('autoFill')['increment']); + + $builder->languageAutoFillInfo('languageAutoFillInfo'); + $this->assertEquals('languageAutoFillInfo', $builder->getLanguage('autoFill')['info']); + } + + /** @test */ + public function it_has_language_paginate_options() + { + $builder = $this->getHtmlBuilder(); + $builder->languagePaginate(['first' => 'First']); + $this->assertEquals(['first' => 'First'], $builder->getLanguage('paginate')); + + $builder->languagePaginateFirst('languagePaginateFirst'); + $this->assertEquals('languagePaginateFirst', $builder->getLanguage('paginate')['first']); + + $builder->languagePaginateLast('languagePaginateLast'); + $this->assertEquals('languagePaginateLast', $builder->getLanguage('paginate')['last']); + + $builder->languagePaginateNext('languagePaginateNext'); + $this->assertEquals('languagePaginateNext', $builder->getLanguage('paginate')['next']); + + $builder->languagePaginatePrevious('languagePaginatePrevious'); + $this->assertEquals('languagePaginatePrevious', $builder->getLanguage('paginate')['previous']); + } + + /** @test */ + public function it_has_language_select_options() + { + $builder = $this->getHtmlBuilder(); + $builder->languageSelect(['cells' => 1]); + $this->assertEquals(['cells' => 1], $builder->getLanguage('select')); + + $builder->languageSelectCells('languageSelectCells'); + $this->assertEquals('languageSelectCells', $builder->getLanguage('select')['cells']); + + $builder->languageSelectCells([1, 2, 3]); + $this->assertEquals([1, 2, 3], $builder->getLanguage('select')['cells']); + + $builder->languageSelectColumns('languageSelectColumns'); + $this->assertEquals('languageSelectColumns', $builder->getLanguage('select')['columns']); + + $builder->languageSelectColumns([1, 2, 3]); + $this->assertEquals([1, 2, 3], $builder->getLanguage('select')['columns']); + + $builder->languageSelectRows('languageSelectRows'); + $this->assertEquals('languageSelectRows', $builder->getLanguage('select')['rows']); + + $builder->languageSelectRows([1, 2, 3]); + $this->assertEquals([1, 2, 3], $builder->getLanguage('select')['rows']); + } +} From e5907ab23af7c0c5a8df91d3abaf36803644f38a Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Sat, 14 May 2022 14:24:43 +0800 Subject: [PATCH 057/260] Fix builder columns with tests --- src/Html/Columns/Action.php | 2 +- src/Html/Columns/Checkbox.php | 8 +++--- tests/BuilderTest.php | 48 +++++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 5 deletions(-) diff --git a/src/Html/Columns/Action.php b/src/Html/Columns/Action.php index fcfa2f8..848cc51 100644 --- a/src/Html/Columns/Action.php +++ b/src/Html/Columns/Action.php @@ -7,7 +7,7 @@ trait Action { /** - * Add a action column. + * Add an action column. * * @param array $attributes * @param bool $prepend diff --git a/src/Html/Columns/Checkbox.php b/src/Html/Columns/Checkbox.php index c94c068..aaa76d6 100644 --- a/src/Html/Columns/Checkbox.php +++ b/src/Html/Columns/Checkbox.php @@ -9,15 +9,15 @@ 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 + * @param array $attributes + * @param bool|int $position true to prepend, false to append or a zero-based index for positioning * @return $this */ public function addCheckbox(array $attributes = [], bool|int $position = false): static { $attributes = array_merge([ - 'defaultContent' => 'html->attributes($attributes) . '/>', - 'title' => 'html->attributes($attributes + ['id' => 'dataTablesCheckbox']) . '/>', + 'defaultContent' => 'html->attributes($attributes).'/>', + 'title' => 'html->attributes($attributes + ['id' => 'dataTablesCheckbox']).'/>', 'data' => 'checkbox', 'name' => 'checkbox', 'orderable' => false, diff --git a/tests/BuilderTest.php b/tests/BuilderTest.php index 2e6a089..e6cba90 100644 --- a/tests/BuilderTest.php +++ b/tests/BuilderTest.php @@ -136,4 +136,52 @@ public function it_can_remove_table_class_attribute() $builder->removeTableClass(['a' => ' b ', ' foo bar ']); $this->assertEquals('a', $builder->getTableAttribute('class')); } + + /** @test */ + public function it_can_add_checkbox() + { + $builder = $this->getHtmlBuilder(); + $builder->addCheckbox(); + + $column = $builder->getColumns()[0]; + + $this->assertCount(1, $builder->getColumns()); + $this->assertInstanceOf(Column::class, $column); + $this->assertEquals(false, $column->orderable); + $this->assertEquals(false, $column->searchable); + $this->assertEquals(false, $column->exportable); + $this->assertEquals(true, $column->printable); + } + + /** @test */ + public function it_can_add_index_column() + { + $builder = $this->getHtmlBuilder(); + $builder->addIndex(); + + $column = $builder->getColumns()[0]; + + $this->assertCount(1, $builder->getColumns()); + $this->assertInstanceOf(Column::class, $column); + $this->assertEquals(false, $column->orderable); + $this->assertEquals(false, $column->searchable); + $this->assertEquals(false, $column->exportable); + $this->assertEquals(true, $column->printable); + } + + /** @test */ + public function it_can_add_action_column() + { + $builder = $this->getHtmlBuilder(); + $builder->addAction(); + + $column = $builder->getColumns()[0]; + + $this->assertCount(1, $builder->getColumns()); + $this->assertInstanceOf(Column::class, $column); + $this->assertEquals(false, $column->orderable); + $this->assertEquals(false, $column->searchable); + $this->assertEquals(false, $column->exportable); + $this->assertEquals(true, $column->printable); + } } From cb19287802615f31e5ad88da55293aebb224c722 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Sat, 14 May 2022 14:29:20 +0800 Subject: [PATCH 058/260] Add column tests --- tests/ColumnTest.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/ColumnTest.php b/tests/ColumnTest.php index c5cfd6e..3c9b6b7 100644 --- a/tests/ColumnTest.php +++ b/tests/ColumnTest.php @@ -169,4 +169,25 @@ public function it_allows_orthogonal_data() $this->assertEquals($expected, $column->data); } + + /** @test */ + public function it_has_responsive_priority() + { + $column = Column::make('name'); + $column->responsivePriority(1); + + $this->assertEquals(1, $column->responsivePriority); + } + + /** @test */ + public function it_can_add_class() + { + $column = Column::make('name')->className('text-sm'); + $this->assertEquals('text-sm', $column->className); + + $column->addClass('font-bold'); + $this->assertEquals('text-sm font-bold', $column->className); + } + + } From c0ed12c35b1e7039f90bf2e053e0c00fe2128161 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Sat, 14 May 2022 14:49:05 +0800 Subject: [PATCH 059/260] Authorization tests --- src/Html/HasAuthorizations.php | 38 +++++++++++++++++++++------------- tests/EditorTest.php | 20 ++++++++++++++++++ 2 files changed, 44 insertions(+), 14 deletions(-) diff --git a/src/Html/HasAuthorizations.php b/src/Html/HasAuthorizations.php index 12cbbd9..84f31ea 100644 --- a/src/Html/HasAuthorizations.php +++ b/src/Html/HasAuthorizations.php @@ -33,6 +33,19 @@ public static function makeIf(callable|bool $condition, array|string $options = return static::make([])->authorized(false); } + /** + * Set authorization status of the button. + * + * @param callable|bool $bool + * @return static + */ + public function authorized(callable|bool $bool): static + { + $this->authorized = (bool) value($bool); + + return $this; + } + /** * Make a button if the user is authorized. * @@ -78,19 +91,6 @@ public static function makeIfCannot( return static::make([])->authorized(false); } - /** - * Set authorization status of the button. - * - * @param callable|bool $bool - * @return static - */ - public function authorized(callable|bool $bool): static - { - $this->authorized = (bool) value($bool); - - return $this; - } - /** * Convert the Fluent instance to an array. * @@ -98,10 +98,20 @@ public function authorized(callable|bool $bool): static */ public function toArray(): array { - if ($this->authorized) { + if ($this->isAuthorized()) { return parent::toArray(); } return []; } + + /** + * Check if instance is authorized + * + * @return bool + */ + public function isAuthorized(): bool + { + return $this->authorized; + } } diff --git a/tests/EditorTest.php b/tests/EditorTest.php index 8adcfa4..24a27ca 100644 --- a/tests/EditorTest.php +++ b/tests/EditorTest.php @@ -48,6 +48,26 @@ public function it_can_have_events() $this->assertEquals($event, $editor->events[0]); } + /** @test */ + public function it_has_authorizations() + { + $editor = Editor::makeIf(true, 'editor'); + $this->assertInstanceOf(Editor::class, $editor); + $this->assertEquals(true, $editor->isAuthorized()); + + $editor = Editor::makeIf(false, 'editor'); + $this->assertInstanceOf(Editor::class, $editor); + $this->assertEquals(false, $editor->isAuthorized()); + + $editor = Editor::makeIfCan('ability', 'editor'); + $this->assertInstanceOf(Editor::class, $editor); + $this->assertEquals(false, $editor->isAuthorized()); + + $editor = Editor::makeIfCannot('ability', 'editor'); + $this->assertInstanceOf(Editor::class, $editor); + $this->assertEquals(false, $editor->isAuthorized()); + } + /** * @param string $instance * @return \Yajra\DataTables\Html\Editor\Editor From 61fc99940792c0f1606404e15f3eb2ecc2c62307 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Sat, 14 May 2022 15:18:35 +0800 Subject: [PATCH 060/260] Authorization and Editor tests --- src/Html/Editor/Editor.php | 8 +++ src/Html/HasAuthorizations.php | 8 +-- tests/EditorTest.php | 121 ++++++++++++++++++++++++++++++--- 3 files changed, 123 insertions(+), 14 deletions(-) diff --git a/src/Html/Editor/Editor.php b/src/Html/Editor/Editor.php index da7b246..396bc55 100644 --- a/src/Html/Editor/Editor.php +++ b/src/Html/Editor/Editor.php @@ -14,6 +14,10 @@ * @property string|array|null $ajax * @property array $fields * @property string|null $template + * @property string $idSrc + * @property string $display + * @property string $scripts + * @property array $formOptions */ class Editor extends Fluent { @@ -237,6 +241,10 @@ public function template(string $template): static */ public function toArray(): array { + if (! $this->isAuthorized()) { + return []; + } + $array = parent::toArray(); unset($array['events']); diff --git a/src/Html/HasAuthorizations.php b/src/Html/HasAuthorizations.php index 84f31ea..a63fec6 100644 --- a/src/Html/HasAuthorizations.php +++ b/src/Html/HasAuthorizations.php @@ -30,7 +30,7 @@ public static function makeIf(callable|bool $condition, array|string $options = return static::make($options); } - return static::make([])->authorized(false); + return app(static::class)->authorized(false); } /** @@ -98,11 +98,11 @@ public static function makeIfCannot( */ public function toArray(): array { - if ($this->isAuthorized()) { - return parent::toArray(); + if (! $this->isAuthorized()) { + return []; } - return []; + return parent::toArray(); } /** diff --git a/tests/EditorTest.php b/tests/EditorTest.php index 24a27ca..e7e2ce9 100644 --- a/tests/EditorTest.php +++ b/tests/EditorTest.php @@ -19,6 +19,7 @@ public function it_can_create_an_editor() $this->assertEmpty($editor->template); $editor + ->idSrc() ->fields([ Text::make('name'), ]) @@ -28,6 +29,16 @@ public function it_can_create_an_editor() $this->assertCount(1, $editor->fields); $this->assertEquals('/test', $editor->ajax); $this->assertEquals('#template', $editor->template); + $this->assertEquals('DT_RowId', $editor->idSrc); + } + + /** + * @param string $instance + * @return \Yajra\DataTables\Html\Editor\Editor + */ + protected function getEditor(string $instance = 'editor'): Editor + { + return Editor::make($instance); } /** @test */ @@ -51,29 +62,119 @@ public function it_can_have_events() /** @test */ public function it_has_authorizations() { - $editor = Editor::makeIf(true, 'editor'); + $editor = Editor::makeIf(true, 'editor') + ->fields([ + Text::make('name'), + ]); $this->assertInstanceOf(Editor::class, $editor); $this->assertEquals(true, $editor->isAuthorized()); - - $editor = Editor::makeIf(false, 'editor'); + $this->assertEquals([ + 'instance' => 'editor', + 'fields' => [ + Text::make('name')->toArray(), + ], + ], $editor->toArray()); + + $editor = Editor::makeIf(false, 'editor') + ->fields([ + Text::make('name'), + ]); $this->assertInstanceOf(Editor::class, $editor); $this->assertEquals(false, $editor->isAuthorized()); + $this->assertCount(1, $editor->fields); + $this->assertEquals([], $editor->toArray()); $editor = Editor::makeIfCan('ability', 'editor'); $this->assertInstanceOf(Editor::class, $editor); $this->assertEquals(false, $editor->isAuthorized()); + $this->assertEquals([], $editor->toArray()); $editor = Editor::makeIfCannot('ability', 'editor'); $this->assertInstanceOf(Editor::class, $editor); $this->assertEquals(false, $editor->isAuthorized()); + $this->assertEquals([], $editor->toArray()); } - /** - * @param string $instance - * @return \Yajra\DataTables\Html\Editor\Editor - */ - protected function getEditor(string $instance = 'editor'): Editor + /** @test */ + public function it_can_be_serialized_to_array() { - return Editor::make($instance); + $editor = Editor::make() + ->ajax('') + ->fields([ + Text::make('name'), + ]); + + $this->assertEquals([ + 'instance' => 'editor', + 'ajax' => '', + 'fields' => [ + Text::make('name')->toArray(), + ], + ], $editor->toArray()); + } + + /** @test */ + public function it_can_be_serialized_to_json_string() + { + $editor = Editor::make() + ->ajax('') + ->fields([ + Text::make('name'), + ]); + + $expected = '{"instance":"editor","ajax":"","fields":[{"name":"name","label":"Name","type":"text"}]}'; + $this->assertEquals($expected, $editor->toJson()); + } + + /** @test */ + public function it_has_form_options() + { + $editor = Editor::make() + ->formOptions([ + 'main' => [ + 'esc' => true, + ], + ]); + + $this->assertEquals([ + 'main' => [ + 'esc' => true, + ], + ], $editor->formOptions); + + $editor->formOptionsMain(['esc' => true]); + $this->assertEquals(['esc' => true], $editor->formOptions['main']); + + $editor->formOptionsBubble(['esc' => true]); + $this->assertEquals(['esc' => true], $editor->formOptions['bubble']); + + $editor->formOptionsInline(['esc' => true]); + $this->assertEquals(['esc' => true], $editor->formOptions['inline']); + } + + /** @test */ + public function it_has_display_constants() + { + $editor = Editor::make()->display(Editor::DISPLAY_BOOTSTRAP); + $this->assertEquals('bootstrap', $editor->display); + + $editor->display(Editor::DISPLAY_ENVELOPE); + $this->assertEquals('envelope', $editor->display); + + $editor->display(Editor::DISPLAY_FOUNDATION); + $this->assertEquals('foundation', $editor->display); + + $editor->display(Editor::DISPLAY_JQUERYUI); + $this->assertEquals('jqueryui', $editor->display); + + $editor->display(Editor::DISPLAY_LIGHTBOX); + $this->assertEquals('lightbox', $editor->display); + } + + /** @test */ + public function it_has_scripts() + { + $editor = Editor::make()->scripts('fn'); + $this->assertEquals('fn', $editor->scripts); } -} \ No newline at end of file +} From 482dfe758a40a0ba6ab8ada34475677440cb2845 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Sat, 14 May 2022 15:43:18 +0800 Subject: [PATCH 061/260] Field authorization tests --- tests/FieldTest.php | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/FieldTest.php b/tests/FieldTest.php index f336bab..9cb7d3d 100644 --- a/tests/FieldTest.php +++ b/tests/FieldTest.php @@ -226,4 +226,33 @@ public function it_can_create_time_field() $this->assertEquals('Name', $field->label); $this->assertEquals('hh:mm a', $field->format); } + + /** @test */ + public function it_has_authorizations() + { + $field = Fields\Text::makeIf(true, 'name'); + $this->assertEquals([ + 'name' => 'name', + 'label' => 'Name', + 'type' => 'text', + ], $field->toArray()); + + $field = Fields\Text::makeIf(false, 'name'); + $this->assertEquals([], $field->toArray()); + } + + /** @test */ + public function it_can_be_serialized() + { + $field = Fields\Text::make('name')->data('user.name'); + + $this->assertEquals([ + 'name' => 'name', + 'data' => 'user.name', + 'label' => 'Name', + 'type' => 'text', + ], $field->toArray()); + + $this->assertEquals('{"name":"name","label":"Name","type":"text","data":"user.name"}', $field->toJson()); + } } From d805449adf83733a11428929ed3391e42c1edac3 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Sat, 14 May 2022 15:54:21 +0800 Subject: [PATCH 062/260] Add column authorization Fix https://github.com/yajra/laravel-datatables-html/issues/162 --- src/Html/Column.php | 50 ++++++++++++++++++++-------------- src/Html/HasAuthorizations.php | 2 +- tests/ColumnTest.php | 32 ++++++++++++++++++++++ 3 files changed, 62 insertions(+), 22 deletions(-) diff --git a/src/Html/Column.php b/src/Html/Column.php index 8a509ba..452a0ab 100644 --- a/src/Html/Column.php +++ b/src/Html/Column.php @@ -34,13 +34,14 @@ class Column extends Fluent { use SearchPanes; + use HasAuthorizations; /** * @param array $attributes */ public function __construct($attributes = []) { - $attributes['title'] ??= self::titleFormat($attributes['data']); + $attributes['title'] ??= self::titleFormat($attributes['data'] ?? ''); $attributes['orderable'] ??= true; $attributes['searchable'] ??= true; $attributes['exportable'] ??= true; @@ -74,6 +75,20 @@ public static function titleFormat(string $value): string return Str::title(str_replace(['.', '_'], ' ', Str::snake($value))); } + /** + * Set column title. + * + * @param string $value + * @return $this + * @see https://datatables.net/reference/option/columns.title + */ + public function title(string $value): static + { + $this->attributes['title'] = $value; + + return $this; + } + /** * Create a computed column that is not searchable/orderable. * @@ -118,33 +133,22 @@ public function orderable(bool $flag = true): static return $this; } - /** - * Set column title. - * - * @param string $value - * @return $this - * @see https://datatables.net/reference/option/columns.title - */ - public function title(string $value): static - { - $this->attributes['title'] = $value; - - return $this; - } - /** * Make a new column instance. * - * @param string $data + * @param array|string $data * @param string $name * @return static */ - public static function make(string $data, string $name = ''): static + public static function make(array|string $data, string $name = ''): static { - $attr = [ - 'data' => $data, - 'name' => $name ?: $data, - ]; + $attr = $data; + if (is_string($data)) { + $attr = [ + 'data' => $data, + 'name' => $name ?: $data, + ]; + } return new static($attr); } @@ -600,6 +604,10 @@ public function exportFormat(string $format): static */ public function toArray(): array { + if (! $this->isAuthorized()) { + return []; + } + return Arr::except($this->attributes, [ 'printable', 'exportable', diff --git a/src/Html/HasAuthorizations.php b/src/Html/HasAuthorizations.php index a63fec6..932a191 100644 --- a/src/Html/HasAuthorizations.php +++ b/src/Html/HasAuthorizations.php @@ -88,7 +88,7 @@ public static function makeIfCannot( return static::make($options); } - return static::make([])->authorized(false); + return app(static::class)->authorized(false); } /** diff --git a/tests/ColumnTest.php b/tests/ColumnTest.php index 3c9b6b7..cf958e8 100644 --- a/tests/ColumnTest.php +++ b/tests/ColumnTest.php @@ -189,5 +189,37 @@ public function it_can_add_class() $this->assertEquals('text-sm font-bold', $column->className); } + /** @test */ + public function it_has_authorizations() + { + $column = Column::makeIf(true, 'name'); + $this->assertEquals([ + 'name' => 'name', + 'data' => 'name', + 'title' => 'Name', + 'orderable' => true, + 'searchable' => true, + 'attributes' => [], + ], $column->toArray()); + + $column = Column::makeIf(false, 'name'); + $this->assertEquals([], $column->toArray()); + } + /** @test */ + public function it_can_be_serialized() + { + $column = Column::make('name'); + $this->assertEquals([ + 'name' => 'name', + 'data' => 'name', + 'title' => 'Name', + 'orderable' => true, + 'searchable' => true, + 'attributes' => [], + ], $column->toArray()); + + $expected = '{"data":"name","name":"name","title":"Name","orderable":true,"searchable":true,"attributes":[]}'; + $this->assertEquals($expected, $column->toJson()); + } } From fd4e9e88faca87543a3a73c2f32e3d65997db617 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Sat, 14 May 2022 16:36:02 +0800 Subject: [PATCH 063/260] Improve ColumnDefs --- src/Html/Column.php | 4 +-- src/Html/ColumnDefinition.php | 49 +++++++++++++++++++++++++++++---- src/Html/Options/HasColumns.php | 8 ++++++ tests/BuilderTest.php | 25 +++++++++++++++++ tests/ColumnDefinitionTest.php | 28 +++++++++++++++++++ 5 files changed, 107 insertions(+), 7 deletions(-) create mode 100644 tests/ColumnDefinitionTest.php diff --git a/src/Html/Column.php b/src/Html/Column.php index 452a0ab..a1b7dca 100644 --- a/src/Html/Column.php +++ b/src/Html/Column.php @@ -140,7 +140,7 @@ public function orderable(bool $flag = true): static * @param string $name * @return static */ - public static function make(array|string $data, string $name = ''): static + public static function make(array|string $data = [], string $name = ''): static { $attr = $data; if (is_string($data)) { @@ -404,7 +404,7 @@ public function orderSequence(array $value): static * @return $this * @see https://datatables.net/reference/option/columns.cellType */ - public function cellType(string $value): static + public function cellType(string $value = 'th'): static { $this->attributes['cellType'] = $value; diff --git a/src/Html/ColumnDefinition.php b/src/Html/ColumnDefinition.php index 1c73945..418f7a3 100644 --- a/src/Html/ColumnDefinition.php +++ b/src/Html/ColumnDefinition.php @@ -2,15 +2,54 @@ namespace Yajra\DataTables\Html; -use Illuminate\Support\Fluent; - -// TODO: Review class implementation -class ColumnDefinition extends Fluent +/** + * @see https://datatables.net/reference/option/columnDefs + */ +class ColumnDefinition extends Column { - public function targets(array $value): static + /** + * @param array $attributes + */ + public function __construct($attributes = []) + { + parent::__construct($attributes); + + $this->attributes = $attributes; + } + + /** + * @param array|string|int $value + * @return $this + * @see https://datatables.net/reference/option/columnDefs.targets + */ + public function targets(array|string|int $value): static { $this->attributes['targets'] = $value; return $this; } + + /** + * @param array $value + * @return $this + * @see https://datatables.net/reference/option/columns + */ + public function columns(array $value): static + { + $this->attributes['columns'] = $value; + + return $this; + } + + /** + * @return array + */ + public function toArray(): array + { + $array = parent::toArray(); + + unset($array['attributes']); + + return $array; + } } diff --git a/src/Html/Options/HasColumns.php b/src/Html/Options/HasColumns.php index 52c9e5b..b6e528b 100644 --- a/src/Html/Options/HasColumns.php +++ b/src/Html/Options/HasColumns.php @@ -30,6 +30,14 @@ public function columnDefs(array|Arrayable|callable $value): static $value = $value->toArray(); } + if (is_array($value)) { + foreach ($value as $key => $def) { + if ($def instanceof Arrayable) { + $value[$key] = $def->toArray(); + } + } + } + $this->attributes['columnDefs'] = $value; return $this; diff --git a/tests/BuilderTest.php b/tests/BuilderTest.php index e6cba90..347077c 100644 --- a/tests/BuilderTest.php +++ b/tests/BuilderTest.php @@ -4,6 +4,8 @@ use Yajra\DataTables\Html\Builder; use Yajra\DataTables\Html\Column; +use Yajra\DataTables\Html\ColumnDefinition; +use Yajra\DataTables\Html\ColumnDefinitions; class BuilderTest extends TestCase { @@ -184,4 +186,27 @@ public function it_can_add_action_column() $this->assertEquals(false, $column->exportable); $this->assertEquals(true, $column->printable); } + + /** @test */ + public function it_has_column_defs() + { + $builder = $this->getHtmlBuilder(); + $builder->columnDefs([['targets' => '_all']]); + + $this->assertEquals([['targets' => '_all']], $builder->getAttribute('columnDefs')); + $this->assertCount(1, $builder->getAttribute('columnDefs')); + + $builder->columnDefs([ColumnDefinition::make()->targets('_all')->visible()]); + + $this->assertEquals([['targets' => '_all', 'visible' => true]], $builder->getAttribute('columnDefs')); + $this->assertCount(1, $builder->getAttribute('columnDefs')); + + $builder->addColumnDef(ColumnDefinition::make()->targets([1])); + $this->assertEquals(['targets' => [1]], $builder->getAttribute('columnDefs')[1]); + $this->assertCount(2, $builder->getAttribute('columnDefs')); + + $builder->columnDefs(ColumnDefinitions::make()->push(ColumnDefinition::make()->targets(1))); + $this->assertEquals([['targets' => 1]], $builder->getAttribute('columnDefs')); + $this->assertCount(1, $builder->getAttribute('columnDefs')); + } } diff --git a/tests/ColumnDefinitionTest.php b/tests/ColumnDefinitionTest.php new file mode 100644 index 0000000..9842b38 --- /dev/null +++ b/tests/ColumnDefinitionTest.php @@ -0,0 +1,28 @@ +targets([1]) + ->columns([]) + ->cellType() + ->className('my-class') + ->contentPadding('mmm') + ->createdCell('fn'); + + $this->assertEquals([1], $def->targets); + $this->assertEquals([], $def->columns); + $this->assertEquals('th', $def->cellType); + $this->assertEquals('my-class', $def->className); + $this->assertEquals('mmm', $def->contentPadding); + $this->assertEquals('fn', $def->createdCell); + } + +} \ No newline at end of file From 15f0df2b13beb3efd412f1766646bfb71c38d92e Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Sat, 14 May 2022 16:41:25 +0800 Subject: [PATCH 064/260] Add table options tests --- tests/BuilderTest.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/BuilderTest.php b/tests/BuilderTest.php index 347077c..428230c 100644 --- a/tests/BuilderTest.php +++ b/tests/BuilderTest.php @@ -2,6 +2,7 @@ namespace Yajra\DataTables\Html\Tests; +use Illuminate\Support\HtmlString; use Yajra\DataTables\Html\Builder; use Yajra\DataTables\Html\Column; use Yajra\DataTables\Html\ColumnDefinition; @@ -209,4 +210,26 @@ public function it_has_column_defs() $this->assertEquals([['targets' => 1]], $builder->getAttribute('columnDefs')); $this->assertCount(1, $builder->getAttribute('columnDefs')); } + + /** @test */ + public function it_has_table_options() + { + $builder = $this->getHtmlBuilder(); + $builder->setTableId('my-table'); + + $this->assertEquals('my-table', $builder->getTableId()); + $this->assertEquals(['id' => 'my-table', 'class' => 'table'], $builder->getTableAttributes()); + + $builder->setTableAttribute('class', 'dTable'); + $this->assertEquals(['id' => 'my-table', 'class' => 'dTable'], $builder->getTableAttributes()); + + $builder->addTableClass('table'); + $this->assertEquals(['id' => 'my-table', 'class' => 'dTable table'], $builder->getTableAttributes()); + + $builder->removeTableClass('dTable'); + $this->assertEquals(['id' => 'my-table', 'class' => 'table'], $builder->getTableAttributes()); + + $this->assertInstanceOf(HtmlString::class, $builder->table()); + $this->assertEquals('
', $builder->table()->toHtml()); + } } From 4da6ba3efbf890f1d725decb4e2a6d28116ac0ff Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Sat, 14 May 2022 16:59:14 +0800 Subject: [PATCH 065/260] Fix search panes and options --- src/Html/Editor/Fields/Options.php | 11 +++-- src/Html/SearchPane.php | 2 +- tests/SearchPaneTest.php | 74 ++++++++++++++++++++++++++++++ 3 files changed, 83 insertions(+), 4 deletions(-) create mode 100644 tests/SearchPaneTest.php diff --git a/src/Html/Editor/Fields/Options.php b/src/Html/Editor/Fields/Options.php index 2a4d6be..f2577df 100644 --- a/src/Html/Editor/Fields/Options.php +++ b/src/Html/Editor/Fields/Options.php @@ -33,7 +33,7 @@ public static function yesNo(): static /** * Get options from a model. * - * @param class-string|\Illuminate\Database\Eloquent\Builder $model + * @param class-string|\Illuminate\Database\Eloquent\Builder $model * @param string $value * @param string $key * @return Collection @@ -71,13 +71,18 @@ public static function table( ): Collection { $query = DB::connection($connection) ->table($table) - ->select("{$value} as label", "$key as value"); + ->select("$value as label", "$key as value"); if (is_callable($callback)) { $callback($query); } - return $query->get(); + return $query->get()->map(function ($row) use ($value, $key) { + return [ + 'value' => $row->value, + 'label' => $row->label, + ]; + }); } /** diff --git a/src/Html/SearchPane.php b/src/Html/SearchPane.php index 1695ad0..18a6436 100644 --- a/src/Html/SearchPane.php +++ b/src/Html/SearchPane.php @@ -211,7 +211,7 @@ public function hideTotal(bool $value = true): static /** * Get options from a model. * - * @param class-string|EloquentBuilder $model + * @param class-string<\Illuminate\Database\Eloquent\Model>|EloquentBuilder $model * @param string $value * @param string $key * @return $this diff --git a/tests/SearchPaneTest.php b/tests/SearchPaneTest.php new file mode 100644 index 0000000..329c396 --- /dev/null +++ b/tests/SearchPaneTest.php @@ -0,0 +1,74 @@ +className('className') + ->header('header') + ->show() + ->name('name') + ->orthogonal('orthogonal') + ->hideTotal() + ->threshold(1) + ->hideCount() + ->filterChanged('filterChanged') + ->emptyMessage('emptyMessage') + ->dtOpts([]) + ->controls() + ->columns([]) + ->clear() + ->cascadePanes(); + + $this->assertInstanceOf(SearchPane::class, $pane); + $this->assertEquals('className', $pane->className); + $this->assertEquals('header', $pane->header); + $this->assertEquals(true, $pane->show); + $this->assertEquals('name', $pane->name); + $this->assertEquals('orthogonal', $pane->orthogonal); + $this->assertEquals(false, $pane->viewTotal); + $this->assertEquals(1, $pane->threshold); + $this->assertEquals(true, $pane->hideCount); + $this->assertEquals('filterChanged', $pane->filterChanged); + $this->assertEquals('emptyMessage', $pane->emptyMessage); + $this->assertEquals([], $pane->dtOpts); + $this->assertEquals(true, $pane->controls); + $this->assertEquals([], $pane->columns); + $this->assertEquals(true, $pane->clear); + $this->assertEquals(true, $pane->cascadePanes); + + $pane->viewTotal(); + $this->assertEquals(true, $pane->viewTotal); + } + + /** @test */ + public function it_has_options() + { + $pane = SearchPane::make()->options([1, 2, 3]); + + $this->assertEquals([1, 2, 3], $pane->options); + $this->assertCount(3, $pane->options); + + $pane->modelOptions(User::class, 'name'); + $this->assertCount(20, $pane->options); + $this->assertIsArray($pane->options[0]); + $this->assertEquals(['value' => 1, 'label' => 'Record-1'], $pane->options[0]); + $this->assertEquals(['value' => 10, 'label' => 'Record-10'], $pane->options[9]); + + $pane->tableOptions('users', 'name'); + $this->assertCount(20, $pane->options); + $this->assertIsArray($pane->options[0]); + $this->assertEquals(['value' => 1, 'label' => 'Record-1'], $pane->options[0]); + $this->assertEquals(['value' => 10, 'label' => 'Record-10'], $pane->options[9]); + } +} From c4292fc29c0047850e780df6bf86c2c2115f8d2e Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Sat, 14 May 2022 17:15:03 +0800 Subject: [PATCH 066/260] Fix editor options implementation --- src/Html/HasEditor.php | 36 +++++++++--------------------------- tests/BuilderTest.php | 18 ++++++++++++++++++ 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/Html/HasEditor.php b/src/Html/HasEditor.php index fa71ad6..cec1870 100644 --- a/src/Html/HasEditor.php +++ b/src/Html/HasEditor.php @@ -18,7 +18,6 @@ trait HasEditor * * @param array|mixed ...$editors * @return $this - * @throws \Exception * @see https://editor.datatables.net/ */ public function editors(...$editors): static @@ -27,49 +26,30 @@ public function editors(...$editors): static $editors = $editors[0]; } + $collection = []; foreach ($editors as $editor) { - $this->editor($editor); + $collection[] = $this->editor($editor); } + $this->editors = $collection; + return $this; } /** * Integrate with DataTables Editor. * - * @param Editor $fields + * @param Editor $editor * @return $this - * @throws \Exception * @see https://editor.datatables.net/ */ - public function editor(Editor $fields): static + public function editor(Editor $editor): static { /** @var string $template */ $template = $this->config->get('datatables-html.editor', 'datatables::editor'); $this->setTemplate($template); - $editor = $this->newEditor($fields); - - $this->editors[] = $editor; - - return $this; - } - - /** - * @param array|Editor $fields - * @return Editor - * @throws \Exception - */ - protected function newEditor(Editor|array $fields): Editor - { - if ($fields instanceof Editor) { - $editor = $fields; - } else { - $editor = new Editor; - $editor->fields($fields); - } - if (! $editor->table) { $editor->table('#'.$this->getTableAttribute('id')); } @@ -78,7 +58,9 @@ protected function newEditor(Editor|array $fields): Editor $editor->ajax($this->getAjaxUrl()); } - return $editor; + $this->editors[] = $editor; + + return $this; } /** diff --git a/tests/BuilderTest.php b/tests/BuilderTest.php index 428230c..685a1bc 100644 --- a/tests/BuilderTest.php +++ b/tests/BuilderTest.php @@ -7,6 +7,7 @@ use Yajra\DataTables\Html\Column; use Yajra\DataTables\Html\ColumnDefinition; use Yajra\DataTables\Html\ColumnDefinitions; +use Yajra\DataTables\Html\Editor\Editor; class BuilderTest extends TestCase { @@ -232,4 +233,21 @@ public function it_has_table_options() $this->assertInstanceOf(HtmlString::class, $builder->table()); $this->assertEquals('
', $builder->table()->toHtml()); } + + /** @test */ + public function it_has_editors() + { + $builder = $this->getHtmlBuilder(); + + $builder->editor(Editor::make()); + $this->assertCount(1, $builder->getEditors()); + + $builder->editors([ + Editor::make(), + Editor::make('edit'), + ]); + $this->assertCount(2, $builder->getEditors()); + } + + } From f7de579c6c1e93cea2f6f69c4cafe52a281a24a1 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Sat, 14 May 2022 17:26:55 +0800 Subject: [PATCH 067/260] Fix field options with tests --- src/Html/Editor/Fields/Field.php | 5 +- src/Html/Editor/Fields/Options.php | 7 +-- tests/FieldOptionsTest.php | 89 ++++++++++++++++++++++++++++++ 3 files changed, 94 insertions(+), 7 deletions(-) create mode 100644 tests/FieldOptionsTest.php diff --git a/src/Html/Editor/Fields/Field.php b/src/Html/Editor/Fields/Field.php index 95d2977..7b9508d 100644 --- a/src/Html/Editor/Fields/Field.php +++ b/src/Html/Editor/Fields/Field.php @@ -4,6 +4,7 @@ use Closure; use Illuminate\Contracts\Support\Arrayable; +use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Query\Builder as QueryBuilder; use Illuminate\Support\Fluent; use Illuminate\Support\Str; @@ -108,12 +109,12 @@ public function type(string $type): static /** * Get options from a model. * - * @param class-string|\Illuminate\Database\Eloquent\Builder $model + * @param \Illuminate\Database\Eloquent\Builder|class-string<\Illuminate\Database\Eloquent\Model> $model * @param string $value * @param string $key * @return $this */ - public function modelOptions($model, string $value, string $key = 'id'): static + public function modelOptions(Builder|string $model, string $value, string $key = 'id'): static { return $this->options( Options::model($model, $value, $key) diff --git a/src/Html/Editor/Fields/Options.php b/src/Html/Editor/Fields/Options.php index f2577df..43e4d1f 100644 --- a/src/Html/Editor/Fields/Options.php +++ b/src/Html/Editor/Fields/Options.php @@ -77,11 +77,8 @@ public static function table( $callback($query); } - return $query->get()->map(function ($row) use ($value, $key) { - return [ - 'value' => $row->value, - 'label' => $row->label, - ]; + return $query->get()->map(function ($row) { + return (array) $row; }); } diff --git a/tests/FieldOptionsTest.php b/tests/FieldOptionsTest.php new file mode 100644 index 0000000..6a122b2 --- /dev/null +++ b/tests/FieldOptionsTest.php @@ -0,0 +1,89 @@ +assertEquals([ + ['label' => __('True'), 'value' => 1], + ['label' => __('False'), 'value' => 0], + ], $options->toArray()); + } + + /** @test */ + public function it_has_yes_no() + { + $options = Options::yesNo(); + + $this->assertEquals([ + ['label' => __('Yes'), 'value' => 1], + ['label' => __('No'), 'value' => 0], + ], $options->toArray()); + } + + /** @test */ + public function it_can_append_and_prepend() + { + $options = Options::yesNo(); + + $this->assertEquals([ + ['label' => __('Yes'), 'value' => 1], + ['label' => __('No'), 'value' => 0], + ], $options->toArray()); + + $options->append(__('Maybe'), 2); + $this->assertEquals([ + ['label' => __('Yes'), 'value' => 1], + ['label' => __('No'), 'value' => 0], + ['label' => __('Maybe'), 'value' => 2], + ], $options->toArray()); + + $options->prepend(__('IDK'), 3); + $this->assertEquals([ + ['label' => __('IDK'), 'value' => 3], + ['label' => __('Yes'), 'value' => 1], + ['label' => __('No'), 'value' => 0], + ['label' => __('Maybe'), 'value' => 2], + ], $options->toArray()); + } + + /** @test */ + public function it_can_get_options_from_table() + { + $options = Options::table('users', 'name'); + $this->assertCount(20, $options); + } + + /** @test */ + public function it_can_get_options_from_query() + { + $options = Options::table(DB::table('users')->where('id', 1), 'name'); + $this->assertCount(1, $options); + } + + /** @test */ + public function it_can_get_options_from_model() + { + $options = Options::model(User::class, 'name'); + $this->assertCount(20, $options); + } + + /** @test */ + public function it_can_get_options_from_model_builder() + { + $options = Options::model(User::query()->whereKey(1), 'name'); + $this->assertCount(1, $options); + } +} From 076619034080c7dfc9e3c8757b2d591dac06784f Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Sat, 14 May 2022 17:46:24 +0800 Subject: [PATCH 068/260] FormOption improvements and tests --- src/Html/Editor/FormOptions.php | 81 ++++++++++++++++++++++++++++----- tests/EditorFormOptionsTest.php | 50 ++++++++++++++++++++ 2 files changed, 120 insertions(+), 11 deletions(-) create mode 100644 tests/EditorFormOptionsTest.php diff --git a/src/Html/Editor/FormOptions.php b/src/Html/Editor/FormOptions.php index a62307f..24397f8 100644 --- a/src/Html/Editor/FormOptions.php +++ b/src/Html/Editor/FormOptions.php @@ -19,10 +19,11 @@ public static function make(array $attributes = []): static } /** - * @param int $value + * @param int|string|null $value * @return $this + * @see https://editor.datatables.net/reference/type/form-options#focus */ - public function focus(int $value = 0): static + public function focus(int|string $value = null): static { $this->attributes['focus'] = $value; @@ -32,10 +33,11 @@ public function focus(int $value = 0): static /** * @param bool $value * @return $this + * @see https://editor.datatables.net/reference/type/form-options#nest */ - public function message(bool $value = false): static + public function nest(bool $value): static { - $this->attributes['message'] = $value; + $this->attributes['nest'] = $value; return $this; } @@ -43,6 +45,7 @@ public function message(bool $value = false): static /** * @param string $value * @return $this + * @see https://editor.datatables.net/reference/type/form-options#onBackground */ public function onBackground(string $value = 'blur'): static { @@ -54,6 +57,7 @@ public function onBackground(string $value = 'blur'): static /** * @param string $value * @return $this + * @see https://editor.datatables.net/reference/type/form-options#onBlur */ public function onBlur(string $value = 'close'): static { @@ -65,6 +69,7 @@ public function onBlur(string $value = 'close'): static /** * @param string $value * @return $this + * @see https://editor.datatables.net/reference/type/form-options#onComplete */ public function onComplete(string $value = 'close'): static { @@ -76,6 +81,7 @@ public function onComplete(string $value = 'close'): static /** * @param string $value * @return $this + * @see https://editor.datatables.net/reference/type/form-options#onEsc */ public function onEsc(string $value = 'close'): static { @@ -87,6 +93,7 @@ public function onEsc(string $value = 'close'): static /** * @param string $value * @return $this + * @see https://editor.datatables.net/reference/type/form-options#onFieldError */ public function onFieldError(string $value = 'focus'): static { @@ -98,6 +105,7 @@ public function onFieldError(string $value = 'focus'): static /** * @param string $value * @return $this + * @see https://editor.datatables.net/reference/type/form-options#onReturn */ public function onReturn(string $value = 'submit'): static { @@ -109,6 +117,7 @@ public function onReturn(string $value = 'submit'): static /** * @param string $value * @return $this + * @see https://editor.datatables.net/reference/type/form-options#submit */ public function submit(string $value = 'changed'): static { @@ -118,34 +127,84 @@ public function submit(string $value = 'changed'): static } /** - * @param bool $value + * @param string $value * @return $this + * @see https://editor.datatables.net/reference/type/form-options#scope */ - public function title(bool $value = false): static + public function scope(string $value = 'row'): static { - $this->attributes['title'] = $value; + $this->attributes['scope'] = $value; return $this; } /** - * @param bool $value + * @param array|string $value + * @return $this + * @see https://editor.datatables.net/reference/type/form-options#buttons + */ + public function buttons(array|string $value): static + { + $this->attributes['buttons'] = $value; + + return $this; + } + /** + * @param string $value * @return $this + * @see https://editor.datatables.net/reference/type/form-options#drawType */ - public function drawType(bool $value = false): static + public function drawType(string $value = ''): static { $this->attributes['drawType'] = $value; return $this; } + /** + * @param bool|string $value + * @return $this + * @see https://editor.datatables.net/reference/type/form-options#message + */ + public function message(bool|string $value = ''): static + { + $this->attributes['message'] = $value; + + return $this; + } + + /** + * @param int|string $value + * @return $this + * @see https://editor.datatables.net/reference/type/form-options#submitTrigger + */ + public function submitTrigger(int|string $value): static + { + $this->attributes['submitTrigger'] = $value; + + return $this; + } + /** * @param string $value * @return $this + * @see https://editor.datatables.net/reference/type/form-options#submitHtml */ - public function scope(string $value = 'row'): static + public function submitHtml(string $value): static { - $this->attributes['scope'] = $value; + $this->attributes['submitHtml'] = $value; + + return $this; + } + + /** + * @param bool|string $value + * @return $this + * @see https://editor.datatables.net/reference/type/form-options#title + */ + public function title(bool|string $value): static + { + $this->attributes['title'] = $value; return $this; } diff --git a/tests/EditorFormOptionsTest.php b/tests/EditorFormOptionsTest.php new file mode 100644 index 0000000..3896eb0 --- /dev/null +++ b/tests/EditorFormOptionsTest.php @@ -0,0 +1,50 @@ +assertInstanceOf(FormOptions::class, $options); + + $options->focus(1) + ->message('message') + ->onBackground('onBackground') + ->onBlur('onBlur') + ->onComplete('onComplete') + ->onEsc('onEsc') + ->onFieldError('onFieldError') + ->onReturn('onReturn') + ->submit('submit') + ->title('title') + ->drawType('drawType') + ->scope('scope') + ->nest(false) + ->buttons([]) + ->submitTrigger(1) + ->submitHtml('submitHtml'); + + $this->assertEquals(1, $options->focus); + $this->assertEquals('message', $options->message); + $this->assertEquals('onBackground', $options->onBackground); + $this->assertEquals('onBlur', $options->onBlur); + $this->assertEquals('onComplete', $options->onComplete); + $this->assertEquals('onEsc', $options->onEsc); + $this->assertEquals('onFieldError', $options->onFieldError); + $this->assertEquals('onReturn', $options->onReturn); + $this->assertEquals('submit', $options->submit); + $this->assertEquals('title', $options->title); + $this->assertEquals('drawType', $options->drawType); + $this->assertEquals('scope', $options->scope); + $this->assertEquals(false, $options->nest); + $this->assertEquals([], $options->buttons); + $this->assertEquals(1, $options->submitTrigger); + $this->assertEquals('submitHtml', $options->submitHtml); + } +} \ No newline at end of file From 80c03058d0a57ab4d173dbe2509323b2e8253cea Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Sat, 14 May 2022 17:52:18 +0800 Subject: [PATCH 069/260] Bump v9.1.0 :rocket: --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3b9940f..3285436 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,12 @@ ## CHANGELOG +### 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 From 5ad04265f9114041aacf7b148aa156b8b613b4e3 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Sat, 14 May 2022 18:38:25 +0800 Subject: [PATCH 070/260] Fix Undefined array key "{plugin_name}" --- src/Html/HasOptions.php | 30 +++++++++++++++++++++++ src/Html/Options/Plugins/AutoFill.php | 12 +++------ src/Html/Options/Plugins/ColReorder.php | 12 +++------ src/Html/Options/Plugins/FixedColumns.php | 12 +++------ src/Html/Options/Plugins/FixedHeader.php | 12 +++------ src/Html/Options/Plugins/KeyTable.php | 12 +++------ src/Html/Options/Plugins/Responsive.php | 12 +++------ src/Html/Options/Plugins/RowGroup.php | 12 +++------ src/Html/Options/Plugins/RowReorder.php | 12 +++------ src/Html/Options/Plugins/Scroller.php | 12 +++------ src/Html/Options/Plugins/Select.php | 10 ++------ tests/BuilderOptionsTest.php | 10 ++++++++ 12 files changed, 69 insertions(+), 89 deletions(-) diff --git a/src/Html/HasOptions.php b/src/Html/HasOptions.php index b74a1c7..f7e43cc 100644 --- a/src/Html/HasOptions.php +++ b/src/Html/HasOptions.php @@ -368,4 +368,34 @@ public function tabIndex(int $value = 0): static return $this; } + + /** + * @param string $key + * @param array|bool $value + * @return $this + */ + public function setPluginAttribute(string $key, array|bool $value): static + { + if (is_array($value)) { + $this->attributes[$key] = array_merge((array) ($this->attributes[$key] ?? []), $value); + } else { + $this->attributes[$key] = $value; + } + + return $this; + } + + /** + * @param string $plugin + * @param string|null $key + * @return mixed + */ + public function getPluginAttribute(string $plugin, string $key = null): mixed + { + if (is_null($key)) { + return $this->attributes[$plugin] ?? true; + } + + return $this->attributes[$plugin][$key] ?? false; + } } diff --git a/src/Html/Options/Plugins/AutoFill.php b/src/Html/Options/Plugins/AutoFill.php index face8ee..97c8ad1 100644 --- a/src/Html/Options/Plugins/AutoFill.php +++ b/src/Html/Options/Plugins/AutoFill.php @@ -27,19 +27,13 @@ public function autoFillAlwaysAsk(bool $value = true): static * Set autoFill option value. * Enable and configure the AutoFill extension for DataTables. * - * @param bool|array $value + * @param array|bool $value * @return $this * @see https://datatables.net/reference/option/autoFill */ - public function autoFill(bool|array $value = true): static + public function autoFill(array|bool $value = true): static { - if (is_array($value)) { - $this->attributes['autoFill'] = array_merge((array) $this->attributes['autoFill'], $value); - } else { - $this->attributes['autoFill'] = $value; - } - - return $this; + return $this->setPluginAttribute('autoFill', $value); } /** diff --git a/src/Html/Options/Plugins/ColReorder.php b/src/Html/Options/Plugins/ColReorder.php index 4e31c92..8a1c424 100644 --- a/src/Html/Options/Plugins/ColReorder.php +++ b/src/Html/Options/Plugins/ColReorder.php @@ -27,19 +27,13 @@ public function colReorderEnable(bool $value = true): static * Set colReorder option value. * Enable and configure the AutoFill extension for DataTables. * - * @param bool|array $value + * @param array|bool $value * @return $this * @see https://datatables.net/reference/option/colReorder */ - public function colReorder(bool|array $value = true): static + public function colReorder(array|bool $value = true): static { - if (is_array($value)) { - $this->attributes['colReorder'] = array_merge((array) $this->attributes['colReorder'], $value); - } else { - $this->attributes['colReorder'] = $value; - } - - return $this; + return $this->setPluginAttribute('colReorder', $value); } /** diff --git a/src/Html/Options/Plugins/FixedColumns.php b/src/Html/Options/Plugins/FixedColumns.php index f733b79..81f3726 100644 --- a/src/Html/Options/Plugins/FixedColumns.php +++ b/src/Html/Options/Plugins/FixedColumns.php @@ -26,19 +26,13 @@ public function fixedColumnsHeightMatch(string $value = 'semiauto'): static /** * Set fixedColumns option value. * - * @param bool|array $value + * @param array|bool $value * @return $this * @see https://datatables.net/reference/option/fixedColumns */ - public function fixedColumns(bool|array $value = true): static + public function fixedColumns(array|bool $value = true): static { - if (is_array($value)) { - $this->attributes['fixedColumns'] = array_merge((array) $this->attributes['fixedColumns'], $value); - } else { - $this->attributes['fixedColumns'] = $value; - } - - return $this; + return $this->setPluginAttribute('fixedColumns', $value); } /** diff --git a/src/Html/Options/Plugins/FixedHeader.php b/src/Html/Options/Plugins/FixedHeader.php index 5d9a509..25eb98d 100644 --- a/src/Html/Options/Plugins/FixedHeader.php +++ b/src/Html/Options/Plugins/FixedHeader.php @@ -26,19 +26,13 @@ public function fixedHeaderFooter(bool $value = true): static /** * Set fixedHeader option value. * - * @param bool|array $value + * @param array|bool $value * @return $this * @see https://datatables.net/reference/option/fixedHeader */ - public function fixedHeader(bool|array $value = true): static + public function fixedHeader(array|bool $value = true): static { - if (is_array($value)) { - $this->attributes['fixedHeader'] = array_merge((array) $this->attributes['fixedHeader'], $value); - } else { - $this->attributes['fixedHeader'] = $value; - } - - return $this; + return $this->setPluginAttribute('fixedHeader', $value); } /** diff --git a/src/Html/Options/Plugins/KeyTable.php b/src/Html/Options/Plugins/KeyTable.php index 0cbb4db..3363c86 100644 --- a/src/Html/Options/Plugins/KeyTable.php +++ b/src/Html/Options/Plugins/KeyTable.php @@ -26,19 +26,13 @@ public function keysBlurable(bool $value = true): static /** * Set keys option value. * - * @param bool|array $value + * @param array|bool $value * @return $this * @see https://datatables.net/reference/option/keys */ - public function keys(bool|array $value = true): static + public function keys(array|bool $value = true): static { - if (is_array($value)) { - $this->attributes['keys'] = array_merge((array) $this->attributes['keys'], $value); - } else { - $this->attributes['keys'] = $value; - } - - return $this; + return $this->setPluginAttribute('keys', $value); } /** diff --git a/src/Html/Options/Plugins/Responsive.php b/src/Html/Options/Plugins/Responsive.php index 08f71f5..81fef46 100644 --- a/src/Html/Options/Plugins/Responsive.php +++ b/src/Html/Options/Plugins/Responsive.php @@ -26,19 +26,13 @@ public function responsiveBreakpoints(array $value): static /** * Set responsive option value. * - * @param bool|array $value + * @param array|bool $value * @return $this * @see https://datatables.net/reference/option/responsive */ - public function responsive(bool|array $value = true): static + public function responsive(array|bool $value = true): static { - if (is_array($value)) { - $this->attributes['responsive'] = array_merge((array) $this->attributes['responsive'], $value); - } else { - $this->attributes['responsive'] = $value; - } - - return $this; + return $this->setPluginAttribute('responsive', $value); } /** diff --git a/src/Html/Options/Plugins/RowGroup.php b/src/Html/Options/Plugins/RowGroup.php index d10a4e4..9893010 100644 --- a/src/Html/Options/Plugins/RowGroup.php +++ b/src/Html/Options/Plugins/RowGroup.php @@ -26,19 +26,13 @@ public function rowGroupUpdate(string $value = 'group'): static /** * Set rowGroup option value. * - * @param bool|array $value + * @param array|bool $value * @return $this * @see https://datatables.net/reference/option/rowGroup */ - public function rowGroup(bool|array $value = true): static + public function rowGroup(array|bool $value = true): static { - if (is_array($value)) { - $this->attributes['rowGroup'] = array_merge((array) $this->attributes['rowGroup'], $value); - } else { - $this->attributes['rowGroup'] = $value; - } - - return $this; + return $this->setPluginAttribute('rowGroup', $value); } /** diff --git a/src/Html/Options/Plugins/RowReorder.php b/src/Html/Options/Plugins/RowReorder.php index 6cb8d50..b7014ea 100644 --- a/src/Html/Options/Plugins/RowReorder.php +++ b/src/Html/Options/Plugins/RowReorder.php @@ -26,19 +26,13 @@ public function rowReorderDataSrc(array|int $value = 0): static /** * Set rowReorder option value. * - * @param bool|array $value + * @param array|bool $value * @return $this * @see https://datatables.net/reference/option/rowReorder */ - public function rowReorder(bool|array $value = true): static + public function rowReorder(array|bool $value = true): static { - if (is_array($value)) { - $this->attributes['rowReorder'] = array_merge((array) $this->attributes['rowReorder'], $value); - } else { - $this->attributes['rowReorder'] = $value; - } - - return $this; + return $this->setPluginAttribute('rowReorder', $value); } /** diff --git a/src/Html/Options/Plugins/Scroller.php b/src/Html/Options/Plugins/Scroller.php index f0b21e6..d6e77a3 100644 --- a/src/Html/Options/Plugins/Scroller.php +++ b/src/Html/Options/Plugins/Scroller.php @@ -26,19 +26,13 @@ public function scrollerBoundaryScale(float $value = 0.5): static /** * Set scroller option value. * - * @param bool|array $value + * @param array|bool $value * @return $this * @see https://datatables.net/reference/option/scroller */ - public function scroller(bool|array $value = true): static + public function scroller(array|bool $value = true): static { - if (is_array($value)) { - $this->attributes['scroller'] = array_merge((array) $this->attributes['scroller'], $value); - } else { - $this->attributes['scroller'] = $value; - } - - return $this; + return $this->setPluginAttribute('scroller', $value); } /** diff --git a/src/Html/Options/Plugins/Select.php b/src/Html/Options/Plugins/Select.php index 9e67cf3..c9fbc7e 100644 --- a/src/Html/Options/Plugins/Select.php +++ b/src/Html/Options/Plugins/Select.php @@ -159,19 +159,13 @@ public function selectStyleSingle(): static /** * Set select option value. * - * @param bool|array $value + * @param array|bool $value * @return $this * @see https://datatables.net/reference/option/select */ public function select(bool|array $value = true): static { - if (is_array($value)) { - $this->attributes['select'] = array_merge((array) $this->attributes['select'], $value); - } else { - $this->attributes['select'] = $value; - } - - return $this; + return $this->setPluginAttribute('select', $value); } /** diff --git a/tests/BuilderOptionsTest.php b/tests/BuilderOptionsTest.php index a671daf..f4e0de5 100644 --- a/tests/BuilderOptionsTest.php +++ b/tests/BuilderOptionsTest.php @@ -215,4 +215,14 @@ public function it_has_internationalisation_options() $builder->languageUrl('languageUrl'); $this->assertEquals('languageUrl', $builder->getLanguage('url')); } + + /** @test */ + public function it_has_plugin_attribute_getter() + { + $builder = $this->getHtmlBuilder(); + + $builder->selectStyleSingle(); + + $this->assertEquals(Builder::SELECT_STYLE_SINGLE, $builder->getPluginAttribute('select', 'style')); + } } From aca330c38e9104846db6638660f66706af405162 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Sat, 14 May 2022 19:00:57 +0800 Subject: [PATCH 071/260] Options tests --- tests/BuilderOptionsTest.php | 55 ++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/tests/BuilderOptionsTest.php b/tests/BuilderOptionsTest.php index f4e0de5..0218f80 100644 --- a/tests/BuilderOptionsTest.php +++ b/tests/BuilderOptionsTest.php @@ -225,4 +225,59 @@ public function it_has_plugin_attribute_getter() $this->assertEquals(Builder::SELECT_STYLE_SINGLE, $builder->getPluginAttribute('select', 'style')); } + + /** @test */ + public function it_has_options() + { + $builder = $this->getHtmlBuilder(); + $builder->deferLoading(10) + ->destroy(true) + ->displayStart(1) + ->dom('Bf') + ->lengthMenu() + ->orders([[1, 'asc']]) + ->orderCellsTop() + ->orderClasses() + ->orderBy(2) + ->orderBy(3, 'asc') + ->orderByFixed(3, 'asc') + ->orderMulti() + ->pageLength() + ->pagingType() + ->renderer() + ->retrieve() + ->rowId() + ->scrollCollapse() + ->search([]) + ->searchCols([]) + ->searchDelay(10) + ->stateDuration(10) + ->stripeClasses(['stripeClasses']) + ->tabIndex(2); + + $this->assertEquals(10, $builder->getAttribute('deferLoading')); + $this->assertEquals(true, $builder->getAttribute('destroy')); + $this->assertEquals(1, $builder->getAttribute('displayStart')); + $this->assertEquals('Bf', $builder->getAttribute('dom')); + $this->assertEquals([10, 25, 50, 100], $builder->getAttribute('lengthMenu')); + $this->assertEquals([1, 'asc'], $builder->getAttribute('order')[0]); + $this->assertEquals([2, 'desc'], $builder->getAttribute('order')[1]); + $this->assertEquals([3, 'asc'], $builder->getAttribute('order')[2]); + $this->assertEquals(false, $builder->getAttribute('orderCellsTop')); + $this->assertEquals(true, $builder->getAttribute('orderClasses')); + $this->assertEquals([[3, 'asc']], $builder->getAttribute('orderFixed')); + $this->assertEquals(true, $builder->getAttribute('orderMulti')); + $this->assertEquals(10, $builder->getAttribute('pageLength')); + $this->assertEquals('simple_numbers', $builder->getAttribute('pagingType')); + $this->assertEquals('bootstrap', $builder->getAttribute('renderer')); + $this->assertEquals(false, $builder->getAttribute('scrollCollapse')); + $this->assertEquals([], $builder->getAttribute('search')); + $this->assertEquals([], $builder->getAttribute('searchCols')); + $this->assertEquals(10, $builder->getAttribute('searchDelay')); + $this->assertEquals(10, $builder->getAttribute('stateDuration')); + $this->assertEquals(['stripeClasses'], $builder->getAttribute('stripeClasses')); + $this->assertEquals(2, $builder->getAttribute('tabIndex')); + } + + } From fe869c98a9d8a4c8cbe83c8ab0699bc306f643be Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Sat, 14 May 2022 19:01:43 +0800 Subject: [PATCH 072/260] Bump v9.1.1 :rocket: --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3285436..902bc6b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,11 @@ ## CHANGELOG +### 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 From 226aa57d0ed380b44eaf5d167f0d42322a154d4b Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Sat, 14 May 2022 19:12:56 +0800 Subject: [PATCH 073/260] Fix Undefined property: Yajra\DataTables\Html\Builder::$instance --- src/Html/HasEditor.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Html/HasEditor.php b/src/Html/HasEditor.php index cec1870..cfa35d8 100644 --- a/src/Html/HasEditor.php +++ b/src/Html/HasEditor.php @@ -26,13 +26,16 @@ public function editors(...$editors): static $editors = $editors[0]; } - $collection = []; + $this->editors = []; + foreach ($editors as $editor) { - $collection[] = $this->editor($editor); + if ($editor instanceof Editor) { + $this->editor($editor); + } else { + $this->editor(new Editor($editor)); + } } - $this->editors = $collection; - return $this; } From 7f33954edaed938043fd04bc392a3bff28e5a551 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Sat, 14 May 2022 19:13:20 +0800 Subject: [PATCH 074/260] Bump v9.1.2 :rocket: --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 902bc6b..4928bc1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ ## CHANGELOG +### 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}" From ee2f42981cf0fe63d3c89f39ebbf393de9ec9706 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Thu, 19 May 2022 11:26:00 +0800 Subject: [PATCH 075/260] Add postAjaxWithForm, fix multiple form values for select and checkbox --- src/Html/Options/HasAjax.php | 49 ++++++++++++++++++++++++++++++------ tests/BuilderOptionsTest.php | 4 +++ 2 files changed, 45 insertions(+), 8 deletions(-) diff --git a/src/Html/Options/HasAjax.php b/src/Html/Options/HasAjax.php index ee9fa17..719ff53 100644 --- a/src/Html/Options/HasAjax.php +++ b/src/Html/Options/HasAjax.php @@ -44,6 +44,46 @@ public function ajax(array|string $attributes = ''): static return $this; } + /** + * @param string $url + * @param string $formSelector + * @return $this + */ + public function postAjaxWithForm(string $url, string $formSelector): static + { + $attributes = ['url' => $url]; + + Arr::set($attributes, 'type', 'POST'); + Arr::set($attributes, 'headers.X-HTTP-Method-Override', 'GET'); + + $script = $this->getScriptWithFormSelector($formSelector); + + $attributes['data'] = "function(data) { $script }"; + + return $this->ajax($attributes); + } + + /** + * @param string $formSelector + * @return string + */ + protected function getScriptWithFormSelector(string $formSelector): string + { + return << 1) { + data[group[0].name] = []; + $.each(group, function(i, obj) { + data[obj.name].push(obj.value) + }) + } else { + data[group[0].name] = group[0].value; + } +}); +CDATA; + } + /** * Setup ajax parameter for datatables pipeline plugin. * @@ -80,14 +120,7 @@ public function getAjaxUrl(): string */ public function ajaxWithForm(string $url, string $formSelector): static { - $script = <<minifiedAjax($url, $script); + return $this->minifiedAjax($url, $this->getScriptWithFormSelector($formSelector)); } /** diff --git a/tests/BuilderOptionsTest.php b/tests/BuilderOptionsTest.php index 0218f80..bf6cca7 100644 --- a/tests/BuilderOptionsTest.php +++ b/tests/BuilderOptionsTest.php @@ -141,6 +141,10 @@ public function it_has_ajax_options() $this->assertStringContainsString('custom_script', $builder->getAjax('data')); $this->assertStringContainsString("data.id = 123", $builder->getAjax('data')); $this->assertStringContainsString("data.name = 'yajra'", $builder->getAjax('data')); + + $builder->postAjaxWithForm('/test', '#formId'); + $this->assertStringContainsString('find("input, select").serializeArray()', $builder->getAjax()['data']); + $this->assertStringContainsString('#formId', $builder->getAjax('data')); } /** @test */ From 5555c302f40b41b6dae326790bd6ee894c8b173b Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Thu, 19 May 2022 12:07:41 +0800 Subject: [PATCH 076/260] Bump v9.2.0 :rocket: --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4928bc1..2e49285 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,11 @@ ## CHANGELOG +### 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 From 824b2a52fc3a292141e3cf9b8de8114eb45c9207 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Thu, 19 May 2022 13:03:32 +0800 Subject: [PATCH 077/260] Fix select2 placeholder default id value --- src/Html/Editor/Fields/Select2.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Html/Editor/Fields/Select2.php b/src/Html/Editor/Fields/Select2.php index 969d022..86515ab 100644 --- a/src/Html/Editor/Fields/Select2.php +++ b/src/Html/Editor/Fields/Select2.php @@ -19,16 +19,16 @@ public function allowClear(bool $state = true): static } /** - * @param string $value + * @param string $text * @param string $id * @return $this */ - public function optsPlaceholder(string $value = '', string $id = 'id'): static + public function optsPlaceholder(string $text = '', string $id = ''): static { return $this->opts([ 'placeholder' => [ 'id' => $id, - 'text' => $value, + 'text' => $text, ], ]); } From 8febf0c1f073fe045a38ba8e746462fad3cebcfb Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Thu, 19 May 2022 13:08:01 +0800 Subject: [PATCH 078/260] Add select2 tests --- src/Html/Editor/Fields/Select2.php | 2 +- tests/FieldTest.php | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Html/Editor/Fields/Select2.php b/src/Html/Editor/Fields/Select2.php index 86515ab..5b47553 100644 --- a/src/Html/Editor/Fields/Select2.php +++ b/src/Html/Editor/Fields/Select2.php @@ -103,7 +103,7 @@ public function processPaginatedResults(string $display = 'text', string $id = ' { $script = 'function(data, params) { '; $script .= 'params.page = params.page || 1; '; - $script .= "data.data.map(function(e) { e.text = e.{$display}; e.id = e.{$id}; return e; }); "; + $script .= "data.data.map(function(e) { e.text = e.$display; e.id = e.$id; return e; }); "; $script .= 'return { results: data.data, pagination: { more: data.current_page < data.last_page } };'; $script .= '}'; diff --git a/tests/FieldTest.php b/tests/FieldTest.php index 9cb7d3d..b1c74a4 100644 --- a/tests/FieldTest.php +++ b/tests/FieldTest.php @@ -187,8 +187,15 @@ public function it_can_create_select2_field() $this->assertEquals('select2', $field->getType()); $this->assertEquals('/url', $field->opts['ajax']['url']); $this->assertEquals('Test', $field->opts['placeholder']['text']); - $this->assertEquals('id', $field->opts['placeholder']['id']); + $this->assertEquals('', $field->opts['placeholder']['id']); $this->assertCount(20, $field->options); + + $field->processResults('fn'); + $this->assertEquals('fn', $field->opts['ajax']['processResults']); + + $field->processPaginatedResults('username', 'user_id'); + $this->assertStringContainsString('e.text = e.username', $field->opts['ajax']['processResults']); + $this->assertStringContainsString('e.id = e.user_id', $field->opts['ajax']['processResults']); } /** @test */ From 7fa73361b0a210042a1d0926eb079d535bfc5602 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Thu, 19 May 2022 13:10:38 +0800 Subject: [PATCH 079/260] Fix placeholder compatibility --- src/Html/Editor/Fields/Select2.php | 9 +++++++++ tests/FieldTest.php | 3 +++ 2 files changed, 12 insertions(+) diff --git a/src/Html/Editor/Fields/Select2.php b/src/Html/Editor/Fields/Select2.php index 5b47553..201a4e4 100644 --- a/src/Html/Editor/Fields/Select2.php +++ b/src/Html/Editor/Fields/Select2.php @@ -18,6 +18,15 @@ public function allowClear(bool $state = true): static return $this->opts(['allowClear' => $state]); } + /** + * @param string $value + * @return $this + */ + public function placeholder(string $value): static + { + return $this->optsPlaceholder($value); + } + /** * @param string $text * @param string $id diff --git a/tests/FieldTest.php b/tests/FieldTest.php index b1c74a4..d6505e5 100644 --- a/tests/FieldTest.php +++ b/tests/FieldTest.php @@ -196,6 +196,9 @@ public function it_can_create_select2_field() $field->processPaginatedResults('username', 'user_id'); $this->assertStringContainsString('e.text = e.username', $field->opts['ajax']['processResults']); $this->assertStringContainsString('e.id = e.user_id', $field->opts['ajax']['processResults']); + + $field->placeholder('New Placeholder'); + $this->assertEquals('New Placeholder', $field->opts['placeholder']['text']); } /** @test */ From 447586a2f909ff811a70797b589f5b75ecec68c4 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Thu, 19 May 2022 13:33:13 +0800 Subject: [PATCH 080/260] Add more select2 tests --- src/Html/Editor/Fields/Select2.php | 2 +- tests/FieldTest.php | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Html/Editor/Fields/Select2.php b/src/Html/Editor/Fields/Select2.php index 201a4e4..5a87f83 100644 --- a/src/Html/Editor/Fields/Select2.php +++ b/src/Html/Editor/Fields/Select2.php @@ -91,7 +91,7 @@ public function ajaxData(array|string $data): static $script = 'function(params) {'; foreach ($data as $key => $value) { $value = json_encode($value); - $script .= " params.{$key} = {$value}; "; + $script .= " params.$key = $value; "; } $script .= 'return params; }'; diff --git a/tests/FieldTest.php b/tests/FieldTest.php index d6505e5..b8053d3 100644 --- a/tests/FieldTest.php +++ b/tests/FieldTest.php @@ -199,6 +199,18 @@ public function it_can_create_select2_field() $field->placeholder('New Placeholder'); $this->assertEquals('New Placeholder', $field->opts['placeholder']['text']); + + $field->ajaxData('fn'); + $this->assertEquals('fn', $field->opts['ajax']['data']); + + $field->ajaxData(['foo' => 'bar']); + $this->assertStringContainsString('params.foo = "bar"', $field->opts['ajax']['data']);; + + $field->ajaxDelay(200); + $this->assertEquals(200, $field->opts['ajax']['delay']);; + + $field->ajaxUrl('/test'); + $this->assertEquals('/test', $field->opts['ajax']['url']);; } /** @test */ From b424731b8c85e0fc7824dac2a4cc37ff2cbe931f Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Thu, 19 May 2022 13:33:56 +0800 Subject: [PATCH 081/260] Bump v9.2.1 :rocket: --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2e49285..8919606 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,12 @@ ## CHANGELOG +### 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 From 3de83225079cfd7b6d2c40ff7a537c683a22537c Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Fri, 20 May 2022 11:49:09 +0800 Subject: [PATCH 082/260] Fix select2 paginated results and ajax setter --- src/Html/Editor/Fields/Select2.php | 8 +++++--- tests/FieldTest.php | 2 ++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Html/Editor/Fields/Select2.php b/src/Html/Editor/Fields/Select2.php index 5a87f83..394de5d 100644 --- a/src/Html/Editor/Fields/Select2.php +++ b/src/Html/Editor/Fields/Select2.php @@ -50,11 +50,13 @@ public function optsPlaceholder(string $text = '', string $id = ''): static */ public function ajax(array|string $value): static { + $ajax = $this->opts['ajax'] ?? []; + if (is_array($value)) { - return $this->opts(['ajax' => $value]); + return $this->opts(['ajax' => array_merge($ajax, $value)]); } - return $this->opts(['ajax' => ['url' => $value]]); + return $this->opts(['ajax' => array_merge($ajax, ['url' => $value])]); } /** @@ -113,7 +115,7 @@ public function processPaginatedResults(string $display = 'text', string $id = ' $script = 'function(data, params) { '; $script .= 'params.page = params.page || 1; '; $script .= "data.data.map(function(e) { e.text = e.$display; e.id = e.$id; return e; }); "; - $script .= 'return { results: data.data, pagination: { more: data.current_page < data.last_page } };'; + $script .= 'return { results: data.data, pagination: { more: data.meta.current_page < data.meta.last_page } };'; $script .= '}'; return $this->processResults($script); diff --git a/tests/FieldTest.php b/tests/FieldTest.php index b8053d3..7b322ca 100644 --- a/tests/FieldTest.php +++ b/tests/FieldTest.php @@ -194,8 +194,10 @@ public function it_can_create_select2_field() $this->assertEquals('fn', $field->opts['ajax']['processResults']); $field->processPaginatedResults('username', 'user_id'); + $this->assertEquals('/url', $field->opts['ajax']['url']); $this->assertStringContainsString('e.text = e.username', $field->opts['ajax']['processResults']); $this->assertStringContainsString('e.id = e.user_id', $field->opts['ajax']['processResults']); + $this->assertStringContainsString('data.meta.current_page < data.meta.last_page', $field->opts['ajax']['processResults']); $field->placeholder('New Placeholder'); $this->assertEquals('New Placeholder', $field->opts['placeholder']['text']); From 2c1ae85fa8b487eaf772ea3948a738ffa8244aea Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Fri, 20 May 2022 11:49:31 +0800 Subject: [PATCH 083/260] Bump v9.2.2 :rocket: --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8919606..ecb7a48 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ ## CHANGELOG +### 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 From 7aea69b67f52e07c36de0b75c329efef28461499 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Sat, 21 May 2022 13:31:15 +0800 Subject: [PATCH 084/260] Add option to override results wrap key --- src/Html/Editor/Fields/Select2.php | 7 ++++--- tests/FieldTest.php | 5 ++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Html/Editor/Fields/Select2.php b/src/Html/Editor/Fields/Select2.php index 394de5d..c7b56ed 100644 --- a/src/Html/Editor/Fields/Select2.php +++ b/src/Html/Editor/Fields/Select2.php @@ -108,14 +108,15 @@ public function ajaxData(array|string $data): static * * @param string $display * @param string $id + * @param string $wrap * @return $this */ - public function processPaginatedResults(string $display = 'text', string $id = 'id'): static + public function processPaginatedResults(string $display = 'text', string $id = 'id', string $wrap = 'results'): static { $script = 'function(data, params) { '; $script .= 'params.page = params.page || 1; '; - $script .= "data.data.map(function(e) { e.text = e.$display; e.id = e.$id; return e; }); "; - $script .= 'return { results: data.data, pagination: { more: data.meta.current_page < data.meta.last_page } };'; + $script .= "data.$wrap.map(function(e) { e.text = e.$display; e.id = e.$id; return e; }); "; + $script .= "return { results: data.$wrap, pagination: { more: data.meta.current_page < data.meta.last_page } };"; $script .= '}'; return $this->processResults($script); diff --git a/tests/FieldTest.php b/tests/FieldTest.php index 7b322ca..15ff477 100644 --- a/tests/FieldTest.php +++ b/tests/FieldTest.php @@ -197,7 +197,10 @@ public function it_can_create_select2_field() $this->assertEquals('/url', $field->opts['ajax']['url']); $this->assertStringContainsString('e.text = e.username', $field->opts['ajax']['processResults']); $this->assertStringContainsString('e.id = e.user_id', $field->opts['ajax']['processResults']); - $this->assertStringContainsString('data.meta.current_page < data.meta.last_page', $field->opts['ajax']['processResults']); + $this->assertStringContainsString('data.results.map', $field->opts['ajax']['processResults']); + + $field->processPaginatedResults('username', 'user_id', 'data'); + $this->assertStringContainsString('data.data.map', $field->opts['ajax']['processResults']); $field->placeholder('New Placeholder'); $this->assertEquals('New Placeholder', $field->opts['placeholder']['text']); From 07f668aa4ee4b25b3ece22eb0dc25ab52c6fa184 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Sat, 21 May 2022 13:31:49 +0800 Subject: [PATCH 085/260] Bump v9.2.3 :rocket: --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ecb7a48..50f9755 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ ## CHANGELOG +### 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 From bf966d35504425cf982ba00a12e98de0142ec5ad Mon Sep 17 00:00:00 2001 From: Renier Date: Sat, 21 May 2022 14:46:36 +0800 Subject: [PATCH 086/260] Use $this in @method This will prevent php stan to detect the magic method especially in chaining. --- src/Html/Editor/HasEvents.php | 68 +++++++++++++++++------------------ 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/src/Html/Editor/HasEvents.php b/src/Html/Editor/HasEvents.php index 32b7117..e06d11a 100644 --- a/src/Html/Editor/HasEvents.php +++ b/src/Html/Editor/HasEvents.php @@ -5,40 +5,40 @@ use Illuminate\Support\Str; /** - * @method Editor onClose($script) - * @method Editor onCreate($script) - * @method Editor onDisplayOrder($script) - * @method Editor onEdit($script) - * @method Editor onInitCreate($script) - * @method Editor onInitEdit($script) - * @method Editor onInitRemove($script) - * @method Editor onInitSubmit($script) - * @method Editor onOpen($script) - * @method Editor onPostCreate($script) - * @method Editor onPostEdit($script) - * @method Editor onPostRemove($script) - * @method Editor onPostSubmit($script) - * @method Editor onPostUpload($script) - * @method Editor onPreBlur($script) - * @method Editor onPreBlurCancelled($script) - * @method Editor onPreCreate($script) - * @method Editor onPreEdit($script) - * @method Editor onPreOpen($script) - * @method Editor onPreOpenCancelled($script) - * @method Editor onPreRemove($script) - * @method Editor onPreSubmit($script) - * @method Editor onPreSubmitCancelled($script) - * @method Editor onPreUpload($script) - * @method Editor onPreUploadCancelled($script) - * @method Editor onProcessing($script) - * @method Editor onRemove($script) - * @method Editor onSetData($script) - * @method Editor onSubmitComplete($script) - * @method Editor onSubmitError($script) - * @method Editor onSubmitSuccess($script) - * @method Editor onSubmitUnsuccessful($script) - * @method Editor onUploadXhrError($script) - * @method Editor onUploadXhrSuccess($script) + * @method $this onClose($script) + * @method $this onCreate($script) + * @method $this onDisplayOrder($script) + * @method $this onEdit($script) + * @method $this onInitCreate($script) + * @method $this onInitEdit($script) + * @method $this onInitRemove($script) + * @method $this onInitSubmit($script) + * @method $this onOpen($script) + * @method $this onPostCreate($script) + * @method $this onPostEdit($script) + * @method $this onPostRemove($script) + * @method $this onPostSubmit($script) + * @method $this onPostUpload($script) + * @method $this onPreBlur($script) + * @method $this onPreBlurCancelled($script) + * @method $this onPreCreate($script) + * @method $this onPreEdit($script) + * @method $this onPreOpen($script) + * @method $this onPreOpenCancelled($script) + * @method $this onPreRemove($script) + * @method $this onPreSubmit($script) + * @method $this onPreSubmitCancelled($script) + * @method $this onPreUpload($script) + * @method $this onPreUploadCancelled($script) + * @method $this onProcessing($script) + * @method $this onRemove($script) + * @method $this onSetData($script) + * @method $this onSubmitComplete($script) + * @method $this onSubmitError($script) + * @method $this onSubmitSuccess($script) + * @method $this onSubmitUnsuccessful($script) + * @method $this onUploadXhrError($script) + * @method $this onUploadXhrSuccess($script) */ trait HasEvents { From 25780f6dfdcdd9f1edce3dafd27b3b19d181ec5f Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Sat, 21 May 2022 14:50:34 +0800 Subject: [PATCH 087/260] Bump v9.2.4 :rocket: --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 50f9755..7af4f7e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ ## CHANGELOG +### 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 From a698a51cb4b5c5d749a97b2a1d5c395ea4d7cf7b Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Thu, 2 Jun 2022 14:47:31 +0800 Subject: [PATCH 088/260] Reset buttons when overridden. --- src/Html/Options/Plugins/Buttons.php | 2 ++ tests/BuilderOptionsPluginsTest.php | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Html/Options/Plugins/Buttons.php b/src/Html/Options/Plugins/Buttons.php index 219f440..3516de5 100644 --- a/src/Html/Options/Plugins/Buttons.php +++ b/src/Html/Options/Plugins/Buttons.php @@ -21,6 +21,8 @@ trait Buttons */ public function buttons(...$buttons): static { + $this->attributes['buttons'] = []; + if (is_array($buttons[0])) { $buttons = $buttons[0]; } diff --git a/tests/BuilderOptionsPluginsTest.php b/tests/BuilderOptionsPluginsTest.php index 8039707..46d98de 100644 --- a/tests/BuilderOptionsPluginsTest.php +++ b/tests/BuilderOptionsPluginsTest.php @@ -60,7 +60,7 @@ public function it_has_buttons_plugin() Button::make('remove'), ]); - $this->assertCount(3, $builder->getButtons()); + $this->assertCount(1, $builder->getButtons()); } /** @test */ From 2ffc4c0f4e6fa319e8462b8ae7bf0852b5290bb8 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Thu, 2 Jun 2022 14:50:22 +0800 Subject: [PATCH 089/260] Add addButton method --- src/Html/Options/Plugins/Buttons.php | 12 ++++++++++++ tests/BuilderOptionsPluginsTest.php | 8 ++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/Html/Options/Plugins/Buttons.php b/src/Html/Options/Plugins/Buttons.php index 3516de5..b4786d3 100644 --- a/src/Html/Options/Plugins/Buttons.php +++ b/src/Html/Options/Plugins/Buttons.php @@ -3,6 +3,7 @@ namespace Yajra\DataTables\Html\Options\Plugins; use Illuminate\Contracts\Support\Arrayable; +use Yajra\DataTables\Html\Button; /** * DataTables - Buttons plugin option builder. @@ -34,6 +35,17 @@ public function buttons(...$buttons): static return $this; } + /** + * @param \Yajra\DataTables\Html\Button $button + * @return $this + */ + public function addButton(Button $button): static + { + $this->attributes['buttons'][] = $button->toArray(); + + return $this; + } + /** * Get builder buttons. * diff --git a/tests/BuilderOptionsPluginsTest.php b/tests/BuilderOptionsPluginsTest.php index 46d98de..a6f93ef 100644 --- a/tests/BuilderOptionsPluginsTest.php +++ b/tests/BuilderOptionsPluginsTest.php @@ -56,11 +56,11 @@ public function it_has_buttons_plugin() $this->assertCount(2, $builder->getButtons()); $this->assertIsArray($builder->getButtons()[0]); - $builder->buttons([ - Button::make('remove'), - ]); - + $builder->buttons([Button::make('remove')]); $this->assertCount(1, $builder->getButtons()); + + $builder->addButton(Button::make('edit')); + $this->assertCount(2, $builder->getButtons()); } /** @test */ From 860648aca6a3a3f64cd203daff65a134c7e950ab Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Thu, 2 Jun 2022 14:52:46 +0800 Subject: [PATCH 090/260] Bump v9.2.5 :rocket: --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7af4f7e..aaf138f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,11 @@ ## CHANGELOG +### 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 From a222232f61ea1d20331888608e9666e58f616580 Mon Sep 17 00:00:00 2001 From: Renier Date: Thu, 30 Jun 2022 11:42:28 +0800 Subject: [PATCH 091/260] Update default() method This is to accept php array in def attribute of datatables --- 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 7b9508d..e5c33e3 100644 --- a/src/Html/Editor/Fields/Field.php +++ b/src/Html/Editor/Fields/Field.php @@ -190,11 +190,11 @@ public function format(string $format): static /** * Set field default value. * - * @param float|bool|int|string $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 $value): static + public function default(float|bool|int|string|array $value): static { $this->attributes['def'] = $value; From abc61626a53e9fb401e1eee7b84f317dddd35a00 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Thu, 30 Jun 2022 11:46:09 +0800 Subject: [PATCH 092/260] Bump v9.2.6 :rocket: --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index aaf138f..2a58ae3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ ## CHANGELOG +### v9.2.6 - 2022-06-30 + +- Allow array on default() method #165 + ### v9.2.5 - 2022-06-02 - Added: Builder addButton method From ecf0f1392ef0a351ebfbcc09ff7a52e792259b34 Mon Sep 17 00:00:00 2001 From: Patrick Torres Date: Fri, 1 Jul 2022 17:17:28 +0800 Subject: [PATCH 093/260] Add nullDefault() method This will prevent php stan from detecting an error when using the fields nullDefault attribute --- src/Html/Editor/Fields/Field.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/Html/Editor/Fields/Field.php b/src/Html/Editor/Fields/Field.php index e5c33e3..3d4b64a 100644 --- a/src/Html/Editor/Fields/Field.php +++ b/src/Html/Editor/Fields/Field.php @@ -360,4 +360,18 @@ public function getType(): string { return $this->type; } + + /** + * 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 + { + $this->attributes['nullDefault'] = $value; + + return $this; + } } From a8a73d8843b8ed9212c9324c347417c4e9ee9d43 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Fri, 1 Jul 2022 17:23:28 +0800 Subject: [PATCH 094/260] Bump v9.3.0 :rocket: --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2a58ae3..af8ff87 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ ## CHANGELOG +### v9.3.0 - 2022-07-01 + +- Add nullDefault() method #166 + ### v9.2.6 - 2022-06-30 - Allow array on default() method #165 From f0a7f5488e0672fff5b45b543d678cbd42872776 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Mon, 4 Jul 2022 18:44:45 +0800 Subject: [PATCH 095/260] Fix magic property type --- src/Html/Column.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Html/Column.php b/src/Html/Column.php index a1b7dca..d76551e 100644 --- a/src/Html/Column.php +++ b/src/Html/Column.php @@ -12,10 +12,10 @@ * @property string $name * @property string $title * @property string $titleAttr - * @property string $orderable - * @property string $searchable - * @property string $printable - * @property string $exportable + * @property bool $orderable + * @property bool $searchable + * @property bool $printable + * @property bool $exportable * @property array|string $footer * @property array $attributes * @property string $render From 8f899d49c3cf9372dcc7d3412caa18bc555c809d Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Mon, 4 Jul 2022 19:03:16 +0800 Subject: [PATCH 096/260] Bump v9.3.1 :rocket: --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index af8ff87..915cabd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ ## CHANGELOG +### v9.3.1 - 2022-07-04 + +- Fix magic property type + ### v9.3.0 - 2022-07-01 - Add nullDefault() method #166 From 20e63f5fbf8dc3fb371d048e7f489da1f71ea579 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Mon, 4 Jul 2022 19:28:41 +0800 Subject: [PATCH 097/260] Fix collection key - value --- src/Html/Options/HasColumns.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Html/Options/HasColumns.php b/src/Html/Options/HasColumns.php index b6e528b..5708efa 100644 --- a/src/Html/Options/HasColumns.php +++ b/src/Html/Options/HasColumns.php @@ -162,7 +162,7 @@ public function addColumnBefore(array|Column $attributes): static /** * Get collection of columns. * - * @return \Illuminate\Support\Collection + * @return \Illuminate\Support\Collection */ public function getColumns(): Collection { From 7190cfdff062a0ad5f273063fde58f01e1c5c597 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Mon, 4 Jul 2022 19:29:01 +0800 Subject: [PATCH 098/260] Bump v9.3.2 :rocket: --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 915cabd..6767a14 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ ## CHANGELOG +### v9.3.2 - 2022-07-04 + +- Fix collection key - value + ### v9.3.1 - 2022-07-04 - Fix magic property type From 254db16db9b6b1d2c23f3178f682b32069cf3e97 Mon Sep 17 00:00:00 2001 From: Patrick Torres Date: Tue, 5 Jul 2022 20:14:20 +0800 Subject: [PATCH 099/260] Fixed exportFormat parameter This update allows the Column exportFormat() method to accept a callable parameter to support the latest functionality in laravel-datatables-export v1. --- src/Html/Column.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Html/Column.php b/src/Html/Column.php index d76551e..a574f54 100644 --- a/src/Html/Column.php +++ b/src/Html/Column.php @@ -588,11 +588,11 @@ public function titleAttr(mixed $value): static /** * Set excel column format when exporting. * - * @param string $format + * @param string|callable $format * @return $this * @see https://github.com/yajra/laravel-datatables-export */ - public function exportFormat(string $format): static + public function exportFormat(string|callable $format): static { $this->attributes['exportFormat'] = $format; From c2867b9b9c1bcc077776f256837d3d9ad7051c78 Mon Sep 17 00:00:00 2001 From: Remon Lumapas Date: Wed, 5 Oct 2022 12:06:44 +0800 Subject: [PATCH 100/260] Add textarea --- 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 719ff53..8252663 100644 --- a/src/Html/Options/HasAjax.php +++ b/src/Html/Options/HasAjax.php @@ -70,7 +70,7 @@ public function postAjaxWithForm(string $url, string $formSelector): static protected function getScriptWithFormSelector(string $formSelector): string { return << 1) { data[group[0].name] = []; From 8b74b1d42dd72fbf86bd4572df3ad6f5ff225e2d Mon Sep 17 00:00:00 2001 From: Remon Lumapas Date: Wed, 5 Oct 2022 13:19:42 +0800 Subject: [PATCH 101/260] Add textarea --- tests/BuilderOptionsTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/BuilderOptionsTest.php b/tests/BuilderOptionsTest.php index bf6cca7..4b47691 100644 --- a/tests/BuilderOptionsTest.php +++ b/tests/BuilderOptionsTest.php @@ -143,7 +143,7 @@ public function it_has_ajax_options() $this->assertStringContainsString("data.name = 'yajra'", $builder->getAjax('data')); $builder->postAjaxWithForm('/test', '#formId'); - $this->assertStringContainsString('find("input, select").serializeArray()', $builder->getAjax()['data']); + $this->assertStringContainsString('find("input, select, textarea").serializeArray()', $builder->getAjax()['data']); $this->assertStringContainsString('#formId', $builder->getAjax('data')); } From c00f984e64805289897ffd15eb54e9fe163657d7 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Wed, 5 Oct 2022 13:22:54 +0800 Subject: [PATCH 102/260] Bump v9.3.3 :rocket: --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6767a14..5d37e65 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ ## CHANGELOG +### v9.3.3 - 2022-10-05 + +- Fix ajax form search with textarea #171 + ### v9.3.2 - 2022-07-04 - Fix collection key - value From 962a32584d54a71f7f5712f2e711cd089c6f9257 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Thu, 6 Oct 2022 13:23:30 +0800 Subject: [PATCH 103/260] fix(events): Fix typehint to mixed --- src/Html/Editor/HasEvents.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Html/Editor/HasEvents.php b/src/Html/Editor/HasEvents.php index e06d11a..93012db 100644 --- a/src/Html/Editor/HasEvents.php +++ b/src/Html/Editor/HasEvents.php @@ -64,11 +64,11 @@ public function __call($method, $parameters) * Add Editor event listener scripts. * * @param string $event - * @param string $script + * @param mixed $script * @return $this * @see https://editor.datatables.net/reference/event */ - public function on(string $event, string $script): static + public function on(string $event, mixed $script): static { $this->events[] = [ 'event' => $event, From f1761861487bd61479f2b13a7f4f5cc634639e9d Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Thu, 6 Oct 2022 13:26:58 +0800 Subject: [PATCH 104/260] Bump v9.3.4 :rocket: --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5d37e65..66cc0b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ ## CHANGELOG +### v9.3.4 - 2022-10-06 + +- fix(editor): Fix typehint to match value helper #172 + ### v9.3.3 - 2022-10-05 - Fix ajax form search with textarea #171 From 507cb369e3a1ca642e49c6b58e4e98338c36afd7 Mon Sep 17 00:00:00 2001 From: jaydons <44308248+jaydons@users.noreply.github.com> Date: Thu, 6 Oct 2022 13:52:06 +0800 Subject: [PATCH 105/260] Add github --- .github/FUNDING.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index a1eb104..87ed63d 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -1,2 +1,3 @@ +github: yajra patreon: yajra custom: https://www.paypal.me/yajra From 833dd908fecca68b50ed5d93ed14e9254de0c482 Mon Sep 17 00:00:00 2001 From: nicacode <87890765+nicacode@users.noreply.github.com> Date: Sat, 8 Oct 2022 09:50:06 +0800 Subject: [PATCH 106/260] Add stale workflow --- .github/workflows/stale.yml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 .github/workflows/stale.yml diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml new file mode 100644 index 0000000..bae8b28 --- /dev/null +++ b/.github/workflows/stale.yml @@ -0,0 +1,22 @@ +name: Close inactive issues +on: + schedule: + - cron: "30 1 * * *" + +jobs: + close-issues: + runs-on: ubuntu-latest + permissions: + issues: write + pull-requests: write + steps: + - uses: actions/stale@v5 + with: + days-before-issue-stale: 30 + days-before-issue-close: 7 + stale-issue-label: "stale" + stale-issue-message: "This issue is stale because it has been open for 30 days with no activity." + close-issue-message: "This issue was closed because it has been inactive for 7 days since being marked as stale." + days-before-pr-stale: -1 + days-before-pr-close: -1 + repo-token: ${{ secrets.GITHUB_TOKEN }} From 0136cb638f6d514586205e0bd63f2c26ed584778 Mon Sep 17 00:00:00 2001 From: Master Suave Date: Tue, 11 Oct 2022 11:02:07 +0800 Subject: [PATCH 107/260] Add onClosed Event This will allow the IDE to suggest the onClosed method when chaining in HTML Editor. Fixed issue with php stan. --- src/Html/Editor/HasEvents.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Html/Editor/HasEvents.php b/src/Html/Editor/HasEvents.php index e06d11a..b3f0462 100644 --- a/src/Html/Editor/HasEvents.php +++ b/src/Html/Editor/HasEvents.php @@ -6,6 +6,7 @@ /** * @method $this onClose($script) + * @method $this onClosed($script) * @method $this onCreate($script) * @method $this onDisplayOrder($script) * @method $this onEdit($script) From d5eb467d0b7c27e641ead58891dac9e8fc997ead Mon Sep 17 00:00:00 2001 From: Patrick Torres Date: Tue, 11 Oct 2022 11:20:29 +0800 Subject: [PATCH 108/260] Add initEditor Event This will allow the IDE to suggest the initEditor method when chaining in HTML Editor. Fixed issue with php stan. Available since Datatables Editor 1.9.1 Reference https://editor.datatables.net/reference/event/initEditor --- src/Html/Editor/HasEvents.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Html/Editor/HasEvents.php b/src/Html/Editor/HasEvents.php index e06d11a..7391671 100644 --- a/src/Html/Editor/HasEvents.php +++ b/src/Html/Editor/HasEvents.php @@ -11,6 +11,7 @@ * @method $this onEdit($script) * @method $this onInitCreate($script) * @method $this onInitEdit($script) + * @method $this onInitEditor($script) * @method $this onInitRemove($script) * @method $this onInitSubmit($script) * @method $this onOpen($script) From 6f55e7ed0a949d5ae46874298d370780bb1815c1 Mon Sep 17 00:00:00 2001 From: Patrick Torres Date: Tue, 11 Oct 2022 11:24:52 +0800 Subject: [PATCH 109/260] Add onOpened Event This will allow the IDE to suggest the onOpened method when chaining in HTML Editor. Fixed issue with php stan. Available since Datatables Editor 1.9.1 Reference https://editor.datatables.net/reference/event/opened --- src/Html/Editor/HasEvents.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Html/Editor/HasEvents.php b/src/Html/Editor/HasEvents.php index e06d11a..080b17a 100644 --- a/src/Html/Editor/HasEvents.php +++ b/src/Html/Editor/HasEvents.php @@ -14,6 +14,7 @@ * @method $this onInitRemove($script) * @method $this onInitSubmit($script) * @method $this onOpen($script) + * @method $this onOpened($script) * @method $this onPostCreate($script) * @method $this onPostEdit($script) * @method $this onPostRemove($script) From 34934cf05e80e2156449a39d1b0c5a238bf98cb1 Mon Sep 17 00:00:00 2001 From: Brylle Baliton <92550259+BrylleBaliton@users.noreply.github.com> Date: Tue, 11 Oct 2022 11:36:51 +0800 Subject: [PATCH 110/260] Update LICENSE.md --- LICENSE.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE.md b/LICENSE.md index 7c2696e..178e525 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,6 +1,6 @@ (The MIT License) -Copyright (c) 2013-2018 Arjay Angeles +Copyright (c) 2013-2022 Arjay Angeles Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the From ad3404971ec2c4a2872e9d165a19bd5416effaf2 Mon Sep 17 00:00:00 2001 From: Patrick Torres Date: Tue, 11 Oct 2022 11:42:29 +0800 Subject: [PATCH 111/260] Add onPreClose Event This will allow the IDE to suggest the onPreClose method when chaining in HTML Editor. Fixed issue with php stan. Available since Datatables Editor 1.0 Reference https://editor.datatables.net/reference/event/preClose --- src/Html/Editor/HasEvents.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Html/Editor/HasEvents.php b/src/Html/Editor/HasEvents.php index 0c0f92c..24c55a8 100644 --- a/src/Html/Editor/HasEvents.php +++ b/src/Html/Editor/HasEvents.php @@ -24,6 +24,7 @@ * @method $this onPostUpload($script) * @method $this onPreBlur($script) * @method $this onPreBlurCancelled($script) + * @method $this onPreClose($script) * @method $this onPreCreate($script) * @method $this onPreEdit($script) * @method $this onPreOpen($script) From dc95ed79c1e9f35a421d4466bc839a2e5451a854 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Tue, 7 Feb 2023 09:42:54 +0800 Subject: [PATCH 112/260] 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 113/260] 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 114/260] 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 115/260] 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 116/260] 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 117/260] 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 118/260] 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 119/260] 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 120/260] 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 121/260] 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 122/260] 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 123/260] 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 cec3e77746ff68f6f51e22250061b59d4ec1311c Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Mon, 20 Feb 2023 15:41:34 +0800 Subject: [PATCH 124/260] chore: release v9.4.0 :rocket: --- CHANGELOG.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 66cc0b5..a41192b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,14 @@ ## CHANGELOG +### v9.4.0 - 2023-02-20 + +- feat: allow callable exportFormat parameter #167 +- feat: Add onPreClose Event #179 +- feat: Add onOpened Event #177 +- feat: Add initEditor Event #176 +- feat: Add onClosed Event #175 + ### v9.3.4 - 2022-10-06 - fix(editor): Fix typehint to match value helper #172 @@ -93,4 +101,4 @@ - Add Laravel 9 support - Remove Laravel 8 and below support - Add phpstan static analysis -- Improve tests \ No newline at end of file +- Improve tests From dc8d8071797368742c7092a4bcf7bbb68a017174 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Mon, 20 Feb 2023 15:46:38 +0800 Subject: [PATCH 125/260] 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 126/260] 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 127/260] 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 128/260] 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 129/260] 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 130/260] 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 131/260] 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 132/260] 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 133/260] 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 134/260] 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 135/260] 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 136/260] 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 137/260] 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 138/260] 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 139/260] 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 140/260] 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 141/260] 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 142/260] 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 143/260] 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 144/260] 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 145/260] 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 146/260] 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 147/260] 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 148/260] 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 149/260] 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 150/260] 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 151/260] 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 152/260] 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 153/260] 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 154/260] 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 155/260] 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 156/260] 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 157/260] 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 158/260] 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 159/260] 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 160/260] 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 161/260] 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 162/260] 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 163/260] 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 164/260] 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 165/260] 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 166/260] 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 167/260] 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 168/260] 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 169/260] 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 170/260] 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 171/260] 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 172/260] 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 173/260] 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 174/260] 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 175/260] 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 176/260] 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 177/260] 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 178/260] 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 179/260] 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 180/260] 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 181/260] 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 182/260] 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 183/260] 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 184/260] 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 185/260] 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 260/260] 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