-
-
Notifications
You must be signed in to change notification settings - Fork 337
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
141 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
namespace Rappasoft\LaravelLivewireTables\Traits\Core\QueryStrings; | ||
|
||
use Livewire\Attributes\Locked; | ||
|
||
trait HasQueryString | ||
{ | ||
#[Locked] | ||
public array $queryStringConfig = [ | ||
'columns' => [], | ||
'filter' => [], | ||
'search' => [], | ||
'sorts' => [], | ||
]; | ||
|
||
protected function getQueryStringConfig(string $type): array | ||
{ | ||
return array_merge(['status' => null, 'alias' => null], ($this->queryStringConfig[$type] ?? [])); | ||
} | ||
|
||
protected function hasQueryStringConfigStatus(string $type): bool | ||
{ | ||
return isset($this->getQueryStringConfig($type)['status']); | ||
} | ||
|
||
protected function getQueryStringConfigStatus(string $type): bool | ||
{ | ||
return $this->getQueryStringConfig($type)['status'] ?? $this->getQueryStringStatus(); | ||
} | ||
|
||
protected function hasQueryStringConfigAlias(string $type): bool | ||
{ | ||
return isset($this->getQueryStringConfig($type)['alias']); | ||
} | ||
|
||
protected function getQueryStringConfigAlias(string $type): string | ||
{ | ||
return $this->getQueryStringConfig($type)['alias'] ?? $this->getQueryStringAlias()."-".$type; | ||
} | ||
|
||
|
||
protected function setQueryStringConfig(string $type, array $config): self | ||
{ | ||
$this->queryStringConfig[$type] = array_merge($this->getQueryStringConfig($type), $config); | ||
|
||
return $this; | ||
} | ||
|
||
protected function setQueryStringConfigStatus(string $type, bool $status): self | ||
{ | ||
return $this->setQueryStringConfig($type, ['status' => $status]); | ||
|
||
} | ||
|
||
protected function setQueryStringConfigAlias(string $type, string $alias): self | ||
{ | ||
return $this->setQueryStringConfig($type,['alias' => $alias]); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,77 +1,66 @@ | ||
<?php | ||
|
||
namespace Rappasoft\LaravelLivewireTables\Traits\Core\QueryStrings; | ||
|
||
use Livewire\Attributes\Locked; | ||
|
||
trait HasQueryStringForSort | ||
{ | ||
#[Locked] | ||
public ?bool $queryStringStatusForSort; | ||
|
||
protected ?string $queryStringAliasForSort; | ||
|
||
protected function queryStringHasQueryStringForSort(): array | ||
{ | ||
return ($this->queryStringForSortEnabled() && $this->sortingIsEnabled()) ? ['sorts' => ['except' => null, 'history' => false, 'keep' => false, 'as' => $this->getQueryStringAliasForSort()]] : []; | ||
|
||
} | ||
|
||
public function setupQueryStringStatusForSort(): void | ||
{ | ||
if (! $this->hasQueryStringStatusForSort()) { | ||
$this->setQueryStringForSortEnabled(); | ||
} | ||
} | ||
|
||
public function hasQueryStringStatusForSort(): bool | ||
{ | ||
return isset($this->queryStringStatusForSort); | ||
} | ||
|
||
public function getQueryStringStatusForSort(): bool | ||
{ | ||
return $this->queryStringStatusForSort ?? true; | ||
} | ||
|
||
public function queryStringForSortEnabled(): bool | ||
{ | ||
$this->setupQueryStringStatusForSort(); | ||
|
||
return $this->getQueryStringStatusForSort() && $this->sortingIsEnabled(); | ||
} | ||
|
||
public function setQueryStringStatusForSort(bool $status): self | ||
{ | ||
$this->queryStringStatusForSort = $status; | ||
|
||
return $this; | ||
} | ||
|
||
public function setQueryStringForSortEnabled(): self | ||
{ | ||
return $this->setQueryStringStatusForSort(true); | ||
} | ||
|
||
public function setQueryStringForSortDisabled(): self | ||
{ | ||
return $this->setQueryStringStatusForSort(false); | ||
} | ||
|
||
public function hasQueryStringAliasForSort(): bool | ||
{ | ||
return isset($this->queryStringAliasForSort); | ||
} | ||
|
||
public function getQueryStringAliasForSort(): string | ||
{ | ||
return $this->queryStringAliasForSort ?? $this->getQueryStringAlias().'-sorts'; | ||
} | ||
|
||
public function setQueryStringAliasForSort(string $alias): self | ||
{ | ||
$this->queryStringAliasForSort = $alias; | ||
|
||
return $this; | ||
} | ||
} | ||
<?php | ||
|
||
namespace Rappasoft\LaravelLivewireTables\Traits\Core\QueryStrings; | ||
|
||
trait HasQueryStringForSort | ||
{ | ||
|
||
protected function queryStringHasQueryStringForSort(): array | ||
{ | ||
return ($this->queryStringForSortEnabled() && $this->sortingIsEnabled()) ? ['sorts' => ['except' => null, 'history' => false, 'keep' => false, 'as' => $this->getQueryStringAliasForSort()]] : []; | ||
|
||
} | ||
public function setupQueryStringStatusForSort(): void | ||
{ | ||
if (! $this->hasQueryStringStatusForSort()) { | ||
$this->setQueryStringForSortEnabled(); | ||
} | ||
} | ||
|
||
protected function hasQueryStringStatusForSort(): bool | ||
{ | ||
return $this->hasQueryStringConfigStatus('sorts'); | ||
} | ||
|
||
protected function getQueryStringStatusForSort(): bool | ||
{ | ||
return $this->getQueryStringConfigStatus("sorts"); | ||
} | ||
|
||
protected function queryStringForSortEnabled(): bool | ||
{ | ||
$this->setupQueryStringStatusForSort(); | ||
|
||
return $this->getQueryStringStatusForSort() && $this->sortingIsEnabled(); | ||
} | ||
|
||
public function setQueryStringStatusForSort(bool $status): self | ||
{ | ||
return $this->setQueryStringConfigStatus("sorts", $status); | ||
} | ||
|
||
public function setQueryStringForSortEnabled(): self | ||
{ | ||
return $this->setQueryStringStatusForSort(true); | ||
} | ||
|
||
public function setQueryStringForSortDisabled(): self | ||
{ | ||
return $this->setQueryStringStatusForSort(false); | ||
} | ||
|
||
protected function hasQueryStringAliasForSort(): bool | ||
{ | ||
return $this->hasQueryStringConfigAlias('sorts'); | ||
} | ||
|
||
protected function getQueryStringAliasForSort(): string | ||
{ | ||
return $this->getQueryStringConfigAlias("sorts"); | ||
} | ||
|
||
public function setQueryStringAliasForSort(string $alias): self | ||
{ | ||
return $this->setQueryStringConfigAlias("sorts", $alias); | ||
} | ||
} |