Skip to content

Commit

Permalink
feat: Current page sugar
Browse files Browse the repository at this point in the history
  • Loading branch information
lee-to committed Jan 14, 2025
1 parent 85e6e55 commit 38192eb
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Contracts/src/Core/CrudResourceContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,16 @@ public function getDetailPageUrl(
null|string|array $fragment = null
): string;

public function isIndexPage(): bool;

public function isFormPage(): bool;

public function isDetailPage(): bool;

public function isCreateFormPage(): bool;

public function isUpdateFormPage(): bool;

public function setQueryParams(iterable $params): static;

public function getQueryParams(): Collection;
Expand Down
25 changes: 25 additions & 0 deletions src/Laravel/src/Resources/CrudResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ public function getIndexPage(): ?PageContract
return $this->getPages()->indexPage();
}

public function isIndexPage(): bool
{
return $this->getActivePage() instanceof IndexPage;
}

/**
* @return null|PageContract<TFormPage>|FormPage
*/
Expand All @@ -154,6 +159,21 @@ public function getFormPage(): ?PageContract
return $this->getPages()->formPage();
}

public function isFormPage(): bool
{
return $this->getActivePage() instanceof FormPage;
}

public function isCreateFormPage(): bool
{
return $this->isFormPage() && \is_null($this->getItemID());
}

public function isUpdateFormPage(): bool
{
return $this->isFormPage() && !\is_null($this->getItemID());
}

public function getActivePage(): ?PageContract
{
return $this->getPages()->activePage();
Expand All @@ -167,6 +187,11 @@ public function getDetailPage(): ?PageContract
return $this->getPages()->detailPage();
}

public function isDetailPage(): bool
{
return $this->getActivePage() instanceof DetailPage;
}

public function getCaster(): DataCasterContract
{
return new MixedDataCaster($this->casterKeyName);
Expand Down

0 comments on commit 38192eb

Please sign in to comment.