Skip to content

Commit

Permalink
1.4.0 (#44)
Browse files Browse the repository at this point in the history
* Added more granularity in the template customization possibilities : the `show`, `edit` and `destroy` actions are now defined in their own component. This way, it becomes easier to customize tiny parts of the table without touching to the others.
  * Added `config('laravel-table.template.show')`, `config('laravel-table.template.edit')` and `config('laravel-table.template.destroy')` configs to set each new default component path.
  * Added `->showTemplate()`, `->editTemplate()` and `->destroyTemplate()` to give the ability to customize these templates on the fly.
* Added fallback path for each template if the config value is not defined, in order to prevent any update breaking change.
  • Loading branch information
Okipa authored Apr 26, 2020
1 parent 1f63c86 commit bb6a13e
Show file tree
Hide file tree
Showing 42 changed files with 389 additions and 173 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

## [1.4.0](https://github.com/Okipa/laravel-table/compare/1.3.0...1.4.0)

2020-04-26

* Added more granularity in the template customization possibilities : the `show`, `edit` and `destroy` actions are now defined in their own component. This way, it becomes easier to customize tiny parts of the table without touching to the others.
* Added `config('laravel-table.template.show')`, `config('laravel-table.template.edit')` and `config('laravel-table.template.destroy')` configs to set each new default component path.
* Added `->showTemplate()`, `->editTemplate()` and `->destroyTemplate()` to give the ability to customize these templates on the fly.
* Added fallback path for each template if the config value is not defined, in order to prevent any update breaking change.

## [1.3.0](https://github.com/Okipa/laravel-table/compare/1.2.7...1.3.0)

2020-04-25
Expand Down
57 changes: 54 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ Then, display it in the view:
* [->tableTemplate()](#table-tableTemplate)
* [->theadTemplate()](#table-theadTemplate)
* [->tbodyTemplate()](#table-tbodyTemplate)
* [->showTemplate()](#table-showTemplate)
* [->editTemplate()](#table-editTemplate)
* [->destroyTemplate()](#table-destroyTemplate)
* [->resultsTemplate()](#table-resultsTemplate)
* [->tfootTemplate()](#table-tfootTemplate)
* [->column()](#table-column)
Expand Down Expand Up @@ -514,7 +517,7 @@ destroyButton.click((e) => {
**Note:**

* Signature: `tableTemplate(string $tableComponentPath): \Okipa\LaravelTable\Table`
* Signature: `tableTemplate(string $tableTemplatePath): \Okipa\LaravelTable\Table`
* Optional

**Use case example:**
Expand All @@ -530,7 +533,7 @@ destroyButton.click((e) => {
**Note:**

* Signature: `theadTemplate(string $theadComponentPath): \Okipa\LaravelTable\Table`
* Signature: `theadTemplate(string $theadTemplatePath): \Okipa\LaravelTable\Table`
* Optional

**Use case example:**
Expand All @@ -546,7 +549,7 @@ destroyButton.click((e) => {
**Note:**

* Signature: `tbodyTemplate(string $tbodyComponentPath): \Okipa\LaravelTable\Table`
* Signature: `tbodyTemplate(string $tbodyTemplatePath): \Okipa\LaravelTable\Table`
* Optional

**Use case example:**
Expand All @@ -555,6 +558,54 @@ destroyButton.click((e) => {
(new Table)->tbodyTemplate('tailwindCss.tbody');
```

<h3 id="table-showTemplate">->showTemplate()</h3>

> Set a custom template path for the show component.
> The default show template path is defined in the `config('laravel-table.template.show')` config value.
**Note:**

* Signature: `showTemplate(string $showTemplatePath): \Okipa\LaravelTable\Table`
* Optional

**Use case example:**

```php
(new Table)->showTemplate('tailwindCss.show');
```

<h3 id="table-editTemplate">->editTemplate()</h3>

> Set a custom template path for the edit component.
> The default edit template path is defined in the `config('laravel-table.template.edit')` config value.
**Note:**

* Signature: `editTemplate(string $editTemplatePath): \Okipa\LaravelTable\Table`
* Optional

**Use case example:**

```php
(new Table)->editTemplate('tailwindCss.edit');
```

<h3 id="table-destroyTemplate">->destroyTemplate()</h3>

> Set a custom template path for the destroy component.
> The default destroy template path is defined in the `config('laravel-table.template.destroy')` config value.
**Note:**

* Signature: `destroyTemplate(string $destroyTemplatePath): \Okipa\LaravelTable\Table`
* Optional

**Use case example:**

```php
(new Table)->destroyTemplate('tailwindCss.destroy');
```

<h3 id="table-resultsTemplate">->resultsTemplate()</h3>

> Set a custom template path for the results component.
Expand Down
9 changes: 6 additions & 3 deletions config/laravel-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
return [

/*
* Default classes for each table parts.
* Default classes for each table part.
*/
'classes' => [
'container' => ['table-responsive'],
Expand Down Expand Up @@ -34,20 +34,23 @@
],

/*
* Default table values
* Default table configuration.
*/
'value' => [
'rowsNumber' => 20,
'rowsNumberSelectionActivation' => true,
],

/*
* Default template paths for each table parts.
* Default template path for each table part.
*/
'template' => [
'table' => 'bootstrap.table',
'thead' => 'bootstrap.thead',
'tbody' => 'bootstrap.tbody',
'show' => 'bootstrap.show',
'edit' => 'bootstrap.edit',
'destroy' => 'bootstrap.destroy',
'results' => 'bootstrap.results',
'tfoot' => 'bootstrap.tfoot',
],
Expand Down
2 changes: 1 addition & 1 deletion lang/en/laravel-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

'rowsNumber' => 'Rows number',
'emptyTable' => 'No results were found.',
'search' => 'Search by :',
'search' => 'Search by:',
'cancelSearch' => 'Cancel research',
'actions' => 'Actions',
'create' => 'Create',
Expand Down
8 changes: 4 additions & 4 deletions src/Column.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ class Column
/** @property string $url */
public $url;

/** @property Closure $valueClosure */
/** @property \Closure $valueClosure */
public $valueClosure;

/** @property Closure $htmlClosure */
/** @property \Closure $htmlClosure */
public $htmlClosure;

/** @property string $icon */
Expand Down Expand Up @@ -234,7 +234,7 @@ public function link($url = null): Column
* The closure let you manipulate the following attributes : \Illuminate\Database\Eloquent\Model $model,
* \Okipa\LaravelTable\Column$column.
*
* @param Closure $valueClosure
* @param \Closure $valueClosure
*
* @return \Okipa\LaravelTable\Column
*/
Expand All @@ -250,7 +250,7 @@ public function value(Closure $valueClosure): Column
* The closure let you manipulate the following attributes : \Illuminate\Database\Eloquent\Model $model,
* \Okipa\LaravelTable\Column $column.
*
* @param Closure $htmlClosure
* @param \Closure $htmlClosure
*
* @return \Okipa\LaravelTable\Column
*/
Expand Down
1 change: 0 additions & 1 deletion src/LaravelTableServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Okipa\LaravelTable;

use Illuminate\Contracts\Foundation\Application;
use Illuminate\Support\ServiceProvider;
use Okipa\LaravelHtmlHelper\HtmlHelperServiceProvider;

Expand Down
7 changes: 6 additions & 1 deletion src/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@

class Result
{
/** @property string $title */
public $title;

/** @property \Closure $htmlClosure */
public $htmlClosure;

/** @property array $classes */
public $classes;

/**
Expand Down Expand Up @@ -36,7 +41,7 @@ public function title(string $title): Result
* Display a HTML output for the result row.
* The closure let you manipulate the following attributes : \Illuminate\Support\Collection $displayedList.
*
* @param Closure $htmlClosure
* @param \Closure $htmlClosure
*
* @return \Okipa\LaravelTable\Result
*/
Expand Down
8 changes: 4 additions & 4 deletions src/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class Table implements Htmlable
/** @property \Illuminate\Support\Collection $columns */
public $columns;

/** @property Closure $queryClosure */
/** @property \Closure $queryClosure */
public $queryClosure;

/** @property \Illuminate\Support\Collection $disableRows */
Expand All @@ -57,7 +57,7 @@ class Table implements Htmlable
/** @property \Illuminate\Pagination\LengthAwarePaginator $list */
public $list;

/** @property Closure $destroyConfirmationClosure */
/** @property \Closure $destroyConfirmationClosure */
public $destroyConfirmationClosure;

/** @property array $appendedValues */
Expand Down Expand Up @@ -184,7 +184,7 @@ public function rowsNumberSelectionActivation(bool $activate = true): Table
* Set the query closure that will be executed during the table generation.
* The closure let you manipulate the following attribute : \Illuminate\Database\Eloquent\Builder $query.
*
* @param Closure $queryClosure
* @param \Closure $queryClosure
*
* @return \Okipa\LaravelTable\Table
*/
Expand Down Expand Up @@ -389,7 +389,7 @@ public function render(): string
$this->handleRequestInteractionValues();
$this->generateEntitiesListFromQuery();

return view('laravel-table::' . $this->tableComponentPath, ['table' => $this]);
return view('laravel-table::' . $this->tableTemplatePath, ['table' => $this]);
}

/**
Expand Down
8 changes: 7 additions & 1 deletion src/Traits/TableClassesCustomizations.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,22 @@ trait TableClassesCustomizations
{
/** @property array $containerClasses */
public $containerClasses;

/** @property array $tableClasses */
public $tableClasses;

/** @property array $trClasses */
public $trClasses;

/** @property array $thClasses */
public $thClasses;

/** @property array $tdClasses */
public $tdClasses;

/** @property array $resultClasses */
public $resultClasses;

/** @property array $rowsConditionalClasses */
public $rowsConditionalClasses;

Expand Down Expand Up @@ -122,7 +128,7 @@ public function resultClasses(array $resultClasses): Table
* The closure let you manipulate the following attribute : \Illuminate\Database\Eloquent\Model $model.
*
* @param \Closure $rowClassesClosure
* @param array $rowClasses
* @param array $rowClasses
*
* @return \Okipa\LaravelTable\Table
*/
Expand Down
18 changes: 9 additions & 9 deletions src/Traits/TableColumnsValidationChecks.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protected function checkModelIsDefined(): void
{
if (! $this->model instanceof Model) {
$errorMessage = 'The table model has not been defined or is not an instance of « '
. Model::class . ' ».';
. Model::class . ' ».';
throw new ErrorException($errorMessage);
}
}
Expand Down Expand Up @@ -70,8 +70,8 @@ protected function checkSortableColumnHasAttribute(Column $column): void
{
if (! $column->databaseDefaultColumn && $column->isSortable) {
$errorMessage = 'One of the sortable table columns has no defined database column. You have to define a '
. 'database column for each sortable table columns by setting a string parameter in the '
. '« column() » method.';
. 'database column for each sortable table columns by setting a string parameter in the '
. '« column() » method.';
throw new ErrorException($errorMessage);
}
}
Expand All @@ -88,8 +88,8 @@ protected function checkSearchableColumnHasAttribute(Column $column): void
{
if (! $column->databaseDefaultColumn) {
$errorMessage = 'One of the searchable table columns has no defined database column. You have to define '
. 'a database column for each searchable table columns by setting a string parameter in '
. 'the « column() » method.';
. 'a database column for each searchable table columns by setting a string parameter in '
. 'the « column() » method.';
throw new ErrorException($errorMessage);
}
}
Expand All @@ -114,9 +114,9 @@ protected function checkSearchedAttributeDoesExistInRelatedTable(Column $column,
? '« ' . $tableData['table'] . ' » (aliased as « ' . $tableAlias . ' ») table'
: '« ' . $tableData['table'] . ' » table';
$errorMessage = 'The table column with related « ' . $searchedDatabaseColumn . ' » database column is '
. 'searchable and does not exist in the ' . $dynamicMessagePart
. '. Set the database searched table and (optionally) columns with the « sortable() » '
. 'method arguments.';
. 'searchable and does not exist in the ' . $dynamicMessagePart
. '. Set the database searched table and (optionally) columns with the « sortable() » '
. 'method arguments.';
throw new ErrorException($errorMessage);
}
}
Expand Down Expand Up @@ -163,7 +163,7 @@ protected function checkIfAtLeastOneColumnIsDeclared(): void
{
if ($this->columns->isEmpty()) {
$errorMessage = 'No column has been added to the table. Please add at least one column by using the '
. '« column() » method on the table object.';
. '« column() » method on the table object.';
throw new ErrorException($errorMessage);
}
}
Expand Down
19 changes: 13 additions & 6 deletions src/Traits/TableInteractions.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,25 @@ trait TableInteractions
{
/** @property int $rows */
public $rows;

/** @property bool $rowsField */
public $rowsField = 'rows';

/** @property string $sortBy */
public $sortBy;

/** @property string $sortByField */
public $sortByField = 'sort_by';

/** @property string $sortDir */
public $sortDir;

/** @property string $sortDirField */
public $sortDirField = 'sort_dir';

/** @property string $search */
public $search;

/** @property string $searchField */
public $searchField = 'search';

Expand Down Expand Up @@ -52,16 +59,16 @@ protected function handleRequestInteractionValues(): void
$this->sortByField,
$this->sortDirField
), [
$this->rowsField => 'required|integer',
$this->searchField => 'nullable|string',
$this->sortByField => 'nullable|string|in:' . $this->columns->implode('databaseDefaultColumn', ','),
$this->rowsField => 'required|integer',
$this->searchField => 'nullable|string',
$this->sortByField => 'nullable|string|in:' . $this->columns->implode('databaseDefaultColumn', ','),
$this->sortDirField => 'nullable|string|in:asc,desc',
]);
if ($validator->fails()) {
$this->request->merge([
$this->rowsField => $this->rows ?? config('laravel-table.value.rows'),
$this->searchField => null,
$this->sortByField => $this->sortBy,
$this->rowsField => $this->rows ?? config('laravel-table.value.rows'),
$this->searchField => null,
$this->sortByField => $this->sortBy,
$this->sortDirField => $this->sortDir,
]);
}
Expand Down
Loading

0 comments on commit bb6a13e

Please sign in to comment.