Skip to content

Commit

Permalink
Issue #34 (#35)
Browse files Browse the repository at this point in the history
Fixes #34
  • Loading branch information
Okipa authored Jan 5, 2020
1 parent 341d464 commit 4c0c3e3
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 25 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
},
"require-dev": {
"mockery/mockery": "^1.0",
"nunomaduro/larastan": "^0.4",
"nunomaduro/larastan": "^0.4.3||^0.5",
"orchestra/testbench": "~3.8.0||^4.0",
"php-coveralls/php-coveralls": "^2.1",
"phpmd/phpmd": "^2.7",
Expand Down
55 changes: 34 additions & 21 deletions config/laravel-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,54 @@

return [

/*
* Default classes for each table parts.
*/
'classes' => [
'container' => ['table-responsive'],
'table' => ['table-striped', 'table-hover'],
'tr' => [],
'th' => ['align-middle'],
'td' => ['align-middle'],
'results' => ['table-dark', 'font-weight-bold'],
'disabled' => ['table-danger', 'disabled'],
'table' => ['table-striped', 'table-hover'],
'tr' => [],
'th' => ['align-middle'],
'td' => ['align-middle'],
'results' => ['table-dark', 'font-weight-bold'],
'disabled' => ['table-danger', 'disabled'],
],

/*
* Table action icons are defined here.
*/
'icon' => [
'rowsNumber' => '<i class="fas fa-list"></i>',
'sort' => '<i class="fas fa-sort fa-fw"></i>',
'sortAsc' => '<i class="fas fa-sort-up fa-fw"></i>',
'sortDesc' => '<i class="fas fa-sort-down fa-fw"></i>',
'search' => '<i class="fas fa-search"></i>',
'validate' => '<i class="fas fa-check"></i>',
'cancel' => '<i class="fas fa-times"></i>',
'create' => '<i class="fas fa-plus-circle fa-fw "></i>',
'edit' => '<i class="fas fa-edit fa-fw"></i>',
'destroy' => '<i class="fas fa-trash fa-fw"></i>',
'show' => '<i class="fas fa-eye fa-fw"></i>',
'sort' => '<i class="fas fa-sort fa-fw"></i>',
'sortAsc' => '<i class="fas fa-sort-up fa-fw"></i>',
'sortDesc' => '<i class="fas fa-sort-down fa-fw"></i>',
'search' => '<i class="fas fa-search"></i>',
'validate' => '<i class="fas fa-check"></i>',
'info' => '<i class="fas fa-info-circle fa-fw"></i>',
'cancel' => '<i class="fas fa-times"></i>',
'create' => '<i class="fas fa-plus-circle fa-fw "></i>',
'edit' => '<i class="fas fa-edit fa-fw"></i>',
'destroy' => '<i class="fas fa-trash fa-fw"></i>',
'show' => '<i class="fas fa-eye fa-fw"></i>',
],

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

/*
* Default template paths for each table parts.
*/
'template' => [
'table' => 'bootstrap.table',
'thead' => 'bootstrap.thead',
'tbody' => 'bootstrap.tbody',
'table' => 'bootstrap.table',
'thead' => 'bootstrap.thead',
'tbody' => 'bootstrap.tbody',
'results' => 'bootstrap.results',
'tfoot' => 'bootstrap.tfoot',
'tfoot' => 'bootstrap.tfoot',
],

];
1 change: 1 addition & 0 deletions src/Traits/TableColumnsValidationChecks.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ protected function tableData(Column $column, Builder $query): array
$table = $column->databaseSearchedTable ?: $column->databaseDefaultTable;
if ($column->databaseSearchedTable) {
$fromSqlStatement = last(explode(' from ', (string) $query->toSql()));
$aliases = [];
preg_match_all('/["`]([a-zA-Z0-9_]*)["`] as ["`]([a-zA-Z0-9_]*)["`]/', $fromSqlStatement, $aliases);
if (! empty(array_filter($aliases))) {
$position = array_keys(Arr::where(array_shift($aliases), function ($alias) use ($table) {
Expand Down
2 changes: 2 additions & 0 deletions tests/Unit/EmptyStatusTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public function testEmptyListHtml()
$table->column('name');
$table->render();
$html = view('laravel-table::' . $table->tbodyComponentPath, compact('table'))->render();
$this->assertStringContainsString(config('laravel-table.icon.info'), $html);
$this->assertStringContainsString(__('laravel-table::laravel-table.emptyTable'), $html);
}

Expand All @@ -27,6 +28,7 @@ public function testFilledListHtml()
$table->column('email');
$table->render();
$html = view('laravel-table::' . $table->tbodyComponentPath, compact('table'))->render();
$this->assertStringNotContainsString(config('laravel-table.icon.info'), $html);
$this->assertStringNotContainsString(__('laravel-table::laravel-table.emptyTable'), $html);
}
}
6 changes: 3 additions & 3 deletions views/bootstrap/tbody.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<tr{{ classTag($table->trClasses) }}>
<td{{ classTag($table->tdClasses, 'text-center', 'p-3') }}{{ htmlAttributes($table->columnsCount() > 1 ? ['colspan' => $table->columnsCount()] : null) }} scope="row">
<span class="text-info">
<i class="fa fa-info-circle" aria-hidden="true"></i>
{!! config('laravel-table.icon.info') !!}
</span>
@lang('laravel-table::laravel-table.emptyTable')
</td>
Expand All @@ -16,7 +16,7 @@
$value = $model->{$column->databaseDefaultColumn};
$customValue = $column->valueClosure ? ($column->valueClosure)($model, $column) : null;
$html = $column->htmlClosure ? ($column->htmlClosure)($model, $column) : null;
$link = $column->url instanceof Closure ? ($column->url)($model, $column) : ($column->url !== true
$link = $column->url instanceof Closure ? ($column->url)($model, $column) : ($column->url !== true
? $column->url
: ($customValue ? $customValue : $value));
$showIcon = $column->icon && (($customValue || $value) || $column->displayIconWhenNoValue);
Expand Down Expand Up @@ -52,7 +52,7 @@
{{ Str::limit(strip_tags($value), $column->stringLimit) }}
{{-- datetime format --}}
@elseif($column->dateTimeFormat)
{{ $value
{{ $value
? \Carbon\Carbon::parse($value)->format($column->dateTimeFormat)
: null }}
{{-- basic value --}}
Expand Down

0 comments on commit 4c0c3e3

Please sign in to comment.