Skip to content

Apply fixes from StyleCI #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 27 additions & 17 deletions src/Http/Livewire/Column.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@
use Illuminate\Support\Str;

/**
* Class Column
*
* @package App\Http\Livewire
* Class Column.
*/
class Column
{

/**
* @var
*/
Expand Down Expand Up @@ -53,7 +50,7 @@ class Column
protected $html = false;

/**
* This column is a custom attribute on the model and not a column in the database
* This column is a custom attribute on the model and not a column in the database.
*
* @var bool
*/
Expand Down Expand Up @@ -102,17 +99,19 @@ public static function make($text = null, $attribute = null)
*
* @return $this
*/
public function searchable(callable $callable = null) : self
public function searchable(callable $callable = null): self
{
$this->searchCallback = $callable;
$this->searchable = true;

return $this;
}

/**
* @return bool
*/
public function isSearchable() : bool {
public function isSearchable(): bool
{
return $this->searchable;
}

Expand All @@ -121,64 +120,73 @@ public function isSearchable() : bool {
*
* @return $this
*/
public function sortable(callable $callable = null) : self
public function sortable(callable $callable = null): self
{
$this->sortCallback = $callable;
$this->sortable = true;

return $this;
}

/**
* @return bool
*/
public function isSortable() : bool {
public function isSortable(): bool
{
return $this->sortable;
}

/**
* @return $this
*/
public function unescaped() : self
public function unescaped(): self
{
$this->unescaped = true;

return $this;
}

/**
* @return bool
*/
public function isUnescaped() : bool {
public function isUnescaped(): bool
{
return $this->unescaped;
}

/**
* @return $this
*/
public function html() : self
public function html(): self
{
$this->html = true;

return $this;
}

/**
* @return bool
*/
public function isHtml() : bool {
public function isHtml(): bool
{
return $this->html;
}

/**
* @return $this
*/
public function customAttribute() : self {
public function customAttribute(): self
{
$this->customAttribute = true;

return $this;
}

/**
* @return bool
*/
public function isCustomAttribute() : bool {
public function isCustomAttribute(): bool
{
return $this->customAttribute;
}

Expand All @@ -187,16 +195,18 @@ public function isCustomAttribute() : bool {
*
* @return $this
*/
public function view($view) : self
public function view($view): self
{
$this->view = $view;

return $this;
}

/**
* @return bool
*/
public function isView() : bool {
public function isView(): bool
{
return view()->exists($this->view);
}
}
40 changes: 20 additions & 20 deletions src/Http/Livewire/TableComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

namespace Rappasoft\LivewireTables\Http\Livewire;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Str;
use Illuminate\View\View;
use Livewire\Component;
use Illuminate\Support\Str;
use Livewire\WithPagination;
use Illuminate\Database\Eloquent\Builder;
use Rappasoft\LivewireTables\Http\Livewire\Traits\Checkboxes;
use Rappasoft\LivewireTables\Http\Livewire\Traits\Loading;
use Rappasoft\LivewireTables\Http\Livewire\Traits\Offline;
Expand All @@ -17,13 +17,10 @@
use Rappasoft\LivewireTables\Http\Livewire\Traits\Yajra;

/**
* Class TableComponent
*
* @package App\Http\Livewire
* Class TableComponent.
*/
abstract class TableComponent extends Component
{

use Checkboxes,
Loading,
Offline,
Expand All @@ -35,7 +32,7 @@ abstract class TableComponent extends Component
Yajra;

/**
* The classes applied to the wrapper div
* The classes applied to the wrapper div.
*
* @var string
*/
Expand All @@ -45,23 +42,25 @@ abstract class TableComponent extends Component
* Whether or not to refresh the table at a certain interval
* false is off
* If it's an integer it will be treated as milliseconds (2000 = refresh every 2 seconds)
* If it's a string it will call that function every 5 seconds
* If it's a string it will call that function every 5 seconds.
*
* @var bool|string
*/
public $refresh = false;

/**
* Constructor
* Constructor.
*/
public function mount() {
public function mount()
{
$this->setTranslationStrings();
}

/**
* Sets the initial translations of these items
* Sets the initial translations of these items.
*/
public function setTranslationStrings() {
public function setTranslationStrings()
{
$this->loadingMessage = __('Loading...');
$this->offlineMessage = __('You are not currently connected to the internet.');
$this->noResultsMessage = __('There are no results to display for this query.');
Expand All @@ -72,24 +71,25 @@ public function setTranslationStrings() {
/**
* @return mixed
*/
abstract public function query() : Builder;
abstract public function query(): Builder;

/**
* @return mixed
*/
abstract public function columns() : array ;
abstract public function columns(): array;

/**
* @return string
*/
public function view() : string {
public function view(): string
{
return 'laravel-livewire-tables::table';
}

/**
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function render() : View
public function render(): View
{
return view($this->view(), [
'columns' => $this->columns(),
Expand All @@ -100,7 +100,7 @@ public function render() : View
/**
* @return Builder
*/
public function models() : Builder
public function models(): Builder
{
$models = $this->query();

Expand All @@ -112,12 +112,12 @@ public function models() : Builder
$query = app()->call($column->searchCallback, ['builder' => $query, 'term' => $this->search]);
} elseif (Str::contains($column->attribute, '.')) {
$relationship = $this->relationship($column->attribute);

$query->orWhereHas($relationship->name, function (Builder $query) use ($relationship) {
$query->where($relationship->attribute, 'like', '%' . $this->search . '%');
$query->where($relationship->attribute, 'like', '%'.$this->search.'%');
});
} else {
$query->orWhere($query->getModel()->getTable() . '.' . $column->attribute, 'like', '%' . $this->search . '%');
$query->orWhere($query->getModel()->getTable().'.'.$column->attribute, 'like', '%'.$this->search.'%');
}
}
}
Expand Down
25 changes: 8 additions & 17 deletions src/Http/Livewire/Traits/Checkboxes.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,69 +3,60 @@
namespace Rappasoft\LivewireTables\Http\Livewire\Traits;

/**
* Trait Checkboxes
*
* @package Rappasoft\LivewireTables\Http\Livewire\Traits
* Trait Checkboxes.
*/
trait Checkboxes
{

/**
* Checboxes
* Checboxes.
*/

/**
* Whether or not checkboxes are enabled
* Whether or not checkboxes are enabled.
*
* @var bool
*/
public $checkbox = false;

/**
* The side to put the checkboxes on
* The side to put the checkboxes on.
*
* @var string
*/
public $checkboxLocation = 'left';

/**
* The model attribute to bind to the checkbox array
* The model attribute to bind to the checkbox array.
*
* @var string
*/
public $checkboxAttribute = 'id';

/**
* Whether or not all checkboxes are currently selected
* Whether or not all checkboxes are currently selected.
*
* @var bool
*/
public $checkboxAll = false;

/**
* The currently selected values of the checkboxes
* The currently selected values of the checkboxes.
*
* @var array
*/
public $checkboxValues = [];

/**
*
*/
public function updatedCheckboxAll()
{
$this->checkboxValues = [];

if ($this->checkboxAll) {
$this->models()->each(function ($model) {
$this->checkboxValues[] = (string)$model->{$this->checkboxAttribute};
$this->checkboxValues[] = (string) $model->{$this->checkboxAttribute};
});
}
}

/**
*
*/
public function updatedCheckboxValues()
{
$this->checkboxAll = false;
Expand Down
11 changes: 4 additions & 7 deletions src/Http/Livewire/Traits/Loading.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,23 @@
namespace Rappasoft\LivewireTables\Http\Livewire\Traits;

/**
* Trait Loading
*
* @package Rappasoft\LivewireTables\Http\Livewire\Traits
* Trait Loading.
*/
trait Loading
{

/**
* Loading
* Loading.
*/

/**
* Whether or not to show a loading indicator when searching
* Whether or not to show a loading indicator when searching.
*
* @var bool
*/
public $loadingIndicator = false;

/**
* The loading message that gets displayed
* The loading message that gets displayed.
*
* @var string
*/
Expand Down
Loading