Skip to content

Commit

Permalink
Tidy ComponentUtilities, Migrate ColumnSelectQueryString (#2135)
Browse files Browse the repository at this point in the history
* Tidy ComponentUtilities, Migrate ColumnSelectQueryString

* Fix styling

---------

Co-authored-by: lrljoe <[email protected]>
  • Loading branch information
lrljoe and lrljoe authored Dec 26, 2024
1 parent ab35e6c commit eda4c5e
Show file tree
Hide file tree
Showing 18 changed files with 576 additions and 523 deletions.
18 changes: 0 additions & 18 deletions src/Traits/ComponentUtilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,8 @@ trait ComponentUtilities

public array $table = [];

protected Builder $builder;

protected $model;

protected ?string $primaryKey;

protected array $relationships = [];

#[Locked]
public string $tableName = 'table';

Expand All @@ -31,20 +25,8 @@ trait ComponentUtilities

protected bool $offlineIndicatorStatus = true;

protected bool $eagerLoadAllRelationsStatus = false;

protected string $emptyMessage = 'No items found, try to broaden your search';

protected array $additionalSelects = [];

protected array $extraWiths = [];

protected array $extraWithCounts = [];

protected array $extraWithSums = [];

protected array $extraWithAvgs = [];

protected bool $useComputedProperties = true;

protected bool $hasRunConfigure = false;
Expand Down
111 changes: 0 additions & 111 deletions src/Traits/Configuration/ComponentConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,6 @@

trait ComponentConfiguration
{
public function setPrimaryKey(?string $key): self
{
$this->primaryKey = $key;

return $this;
}

/**
* Set the empty message
*/
Expand Down Expand Up @@ -42,117 +35,13 @@ public function setOfflineIndicatorDisabled(): self
return $this;
}

public function setEagerLoadAllRelationsStatus(bool $status): self
{
$this->eagerLoadAllRelationsStatus = $status;

return $this;
}

public function setEagerLoadAllRelationsEnabled(): self
{
$this->setEagerLoadAllRelationsStatus(true);

return $this;
}

public function setEagerLoadAllRelationsDisabled(): self
{
$this->setEagerLoadAllRelationsStatus(false);

return $this;
}

/**
* Allows adding a single set of additional selects to the query
*/
public function setAdditionalSelects(string|array $selects): self
{
if (! is_array($selects)) {
$selects = [$selects];
}

$this->additionalSelects = $selects;

return $this;
}

/**
* Allows appending more additional selects
*/
public function addAdditionalSelects(string|array $selects): self
{
if (! is_array($selects)) {
$selects = [$selects];
}
$this->additionalSelects = [...$this->additionalSelects, ...$selects];

return $this;
}

public function setDataTableFingerprint(string $dataTableFingerprint): self
{
$this->dataTableFingerprint = $dataTableFingerprint;

return $this;
}

public function setExtraWiths(array $extraWiths): self
{
$this->extraWiths = $extraWiths;

return $this;
}

public function addExtraWith(string $extraWith): self
{
$this->extraWiths[] = $extraWith;

return $this;
}

public function addExtraWiths(array $extraWiths): self
{
$this->extraWiths = [...$this->extraWiths, ...$extraWiths];

return $this;
}

public function setExtraWithCounts(array $extraWithCounts): self
{
$this->extraWithCounts = $extraWithCounts;

return $this;
}

public function addExtraWithCount(string $extraWithCount): self
{
$this->extraWithCounts[] = $extraWithCount;

return $this;
}

public function addExtraWithCounts(array $extraWithCounts): self
{
$this->extraWithCounts = [...$this->extraWithCounts, ...$extraWithCounts];

return $this;
}

public function addExtraWithSum(string $relationship, string $column): self
{
$this->extraWithSums[] = ['table' => $relationship, 'field' => $column];

return $this;
}

public function addExtraWithAvg(string $relationship, string $column): self
{
$this->extraWithAvgs[] = ['table' => $relationship, 'field' => $column];

return $this;
}

public function useComputedPropertiesEnabled(): self
{
$this->useComputedProperties = true;
Expand Down
124 changes: 124 additions & 0 deletions src/Traits/Configuration/QueryConfiguration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
<?php

namespace Rappasoft\LaravelLivewireTables\Traits\Configuration;

use Illuminate\Database\Eloquent\Builder;

trait QueryConfiguration
{
public function setBuilder(Builder $builder): void
{
$this->builder = $builder;
}

public function setPrimaryKey(?string $key): self
{
$this->primaryKey = $key;

return $this;
}

/**
* Allows adding a single set of additional selects to the query
*/
public function setAdditionalSelects(string|array $selects): self
{
if (! is_array($selects)) {
$selects = [$selects];
}

$this->additionalSelects = $selects;

return $this;
}

/**
* Allows appending more additional selects
*/
public function addAdditionalSelects(string|array $selects): self
{
if (! is_array($selects)) {
$selects = [$selects];
}
$this->additionalSelects = [...$this->additionalSelects, ...$selects];

return $this;
}

public function setExtraWiths(array $extraWiths): self
{
$this->extraWiths = $extraWiths;

return $this;
}

public function addExtraWith(string $extraWith): self
{
$this->extraWiths[] = $extraWith;

return $this;
}

public function addExtraWiths(array $extraWiths): self
{
$this->extraWiths = [...$this->extraWiths, ...$extraWiths];

return $this;
}

public function setExtraWithCounts(array $extraWithCounts): self
{
$this->extraWithCounts = $extraWithCounts;

return $this;
}

public function addExtraWithCount(string $extraWithCount): self
{
$this->extraWithCounts[] = $extraWithCount;

return $this;
}

public function addExtraWithCounts(array $extraWithCounts): self
{
$this->extraWithCounts = [...$this->extraWithCounts, ...$extraWithCounts];

return $this;
}

public function addExtraWithSum(string $relationship, string $column): self
{
$this->extraWithSums[] = ['table' => $relationship, 'field' => $column];

return $this;
}

public function addExtraWithAvg(string $relationship, string $column): self
{
$this->extraWithAvgs[] = ['table' => $relationship, 'field' => $column];

return $this;
}

public function setEagerLoadAllRelationsStatus(bool $status): self
{
$this->eagerLoadAllRelationsStatus = $status;

return $this;
}

public function setEagerLoadAllRelationsEnabled(): self
{
$this->setEagerLoadAllRelationsStatus(true);

return $this;
}

public function setEagerLoadAllRelationsDisabled(): self
{
$this->setEagerLoadAllRelationsStatus(false);

return $this;
}
}
32 changes: 25 additions & 7 deletions src/Traits/Configuration/QueryStringConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,6 @@

trait QueryStringConfiguration
{
public function setQueryStringAlias(string $queryStringAlias): self
{
$this->queryStringAlias = $queryStringAlias;

return $this;
}

public function setupQueryStringStatus(): void
{
if (! $this->hasQueryStringStatus()) {
Expand Down Expand Up @@ -41,4 +34,29 @@ public function setQueryStringDisabled(): self

return $this;
}

public function setQueryStringAlias(string $queryStringAlias): self
{
$this->queryStringAlias = $queryStringAlias;

return $this;
}

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]);
}
}
59 changes: 0 additions & 59 deletions src/Traits/Core/QueryStrings/HasQueryString.php

This file was deleted.

Loading

0 comments on commit eda4c5e

Please sign in to comment.