Skip to content

Commit

Permalink
add isBadge() for table badge & pagainte() to base
Browse files Browse the repository at this point in the history
  • Loading branch information
3x1io committed Sep 16, 2022
1 parent a23767d commit 97825d8
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Services/Concerns/HasColor.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ trait HasColor
* @var ?string
* @example 12
*/
public ?string $color = "green";
public ?string $color = null;

public function color($color): static
{
Expand Down
8 changes: 4 additions & 4 deletions Services/Concerns/IsReactive.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ trait IsReactive
public ?string $reactiveRow = null;

/**
* @var ?string
* @var string|bool|array|int|null
* @example 'name'
*/
public ?string $reactiveWhere = null;
public string|bool|array|int|null|object $reactiveWhere = null;


/**
Expand All @@ -42,10 +42,10 @@ public function reactiveRow(string $reactiveRow): static
}

/**
* @param string $reactiveWhere
* @param string|bool|array|int|object $reactiveWhere
* @return $this
*/
public function reactiveWhere(string $reactiveWhere): static
public function reactiveWhere(string|bool|array|int|object $reactiveWhere): static
{
$this->reactiveWhere = $reactiveWhere;
return $this;
Expand Down
20 changes: 20 additions & 0 deletions Services/Concerns/IsUrl.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Modules\Base\Services\Concerns;

trait IsUrl
{
/**
* @var ?bool
*/
public ?bool $url = false;

/**
* @return $this
*/
public function url(bool $url = true): static
{
$this->url = $url;
return $this;
}
}
18 changes: 10 additions & 8 deletions Services/Resource/Concerns/Actions/Show.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ public function show(Request $request, $id): JsonResponse | \Inertia\Response
*/
$query->find($id);

/*
* Set JOIN to relation
*/
$this->filterRelation($query);

/*
* Make a Hook before get Query
*/
Expand All @@ -47,12 +42,19 @@ public function show(Request $request, $id): JsonResponse | \Inertia\Response
/*
* Get Query
*/
$record = $query->select(collect($this->rows())->where('view', true)
$query->select(collect($this->rows())->where('view', true)
->where('vue', '!=', 'ViltMedia.vue')
->where('vue', '!=', 'ViltRelation.vue')
->where('over', '!=', true)
->pluck('name')->toArray())->first();

/*
* Set JOIN to relation
*/
$this->filterRelation($query);

$record = $query->first();

/*
* Make a Hook after get Query
*/
Expand Down Expand Up @@ -111,9 +113,9 @@ public function show(Request $request, $id): JsonResponse | \Inertia\Response
public function unsetShowData($record): void
{
foreach($this->rows() as $row) {
if (($row->vue === 'ViltHasOne.vue' || $row->vue === 'ViltRelation.vue') && !empty($row->relation)) {
if (($row->vue === 'ViltHasOne.vue') && !empty($row->relation)) {
$record->{$row->name} = $record->{$row->relation};
unset($record->{$row->relation});
unset($record->{$row->name});
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Services/Resource/Concerns/Filters/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ trait Query
public function filterQuery(array $rows, LengthAwarePaginator $data, bool $isAPI): LengthAwarePaginator
{
foreach ($rows as $row) {
if (($row->vue === 'ViltHasOne.vue' || $row->vue === 'ViltRelation.vue') && $row->list && !empty($row->relation)) {
if (($row->vue === 'ViltHasOne.vue') && $row->list && !empty($row->relation)) {
foreach($data as $i=>$item){
$item->{$row->name} = $item->{$row->relation};
unset($item->{$row->relation});
Expand Down
2 changes: 1 addition & 1 deletion Services/Resource/Concerns/Handlers/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function modifyQuery($query, Request $request, bool $isAPI, array $rows):
*/
if ($isAPI) {
if (($row->vue === 'ViltRelation.vue') ) {
$query->with($row->name);
$query->with($row->relation);
}
if (($row->vue === 'ViltHasOne.vue')) {
$query->with($row->relation);
Expand Down
2 changes: 2 additions & 0 deletions Services/Rows/Abstracts/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
use Modules\Base\Services\Concerns\IsSearchable;
use Modules\Base\Services\Concerns\IsSortable;
use Modules\Base\Services\Concerns\IsUnique;
use Modules\Base\Services\Concerns\IsUrl;
use Modules\Base\Services\Rows\Interfaces\Component;

abstract class Base implements Component
Expand Down Expand Up @@ -61,6 +62,7 @@ abstract class Base implements Component
use HasOptions;
use HasTrack;
use HasValidation;
use IsUrl;
use IsMulti;
use IsOver;
use IsDisabled;
Expand Down

0 comments on commit 97825d8

Please sign in to comment.