Skip to content
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

Data Types: Add support for dynamically setting the filter view template #23

Open
wants to merge 2 commits into
base: 3.x
Choose a base branch
from
Open
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
24 changes: 23 additions & 1 deletion src/BaseFeatures/Data/Types/Bases/BaseType.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ abstract class BaseType

protected ?string $formatter = null;

protected string $filterView = 'report-engine::partials.base-filter';

/**
* @param mixed $value
* @param object|null $result
Expand Down Expand Up @@ -99,6 +101,26 @@ public function setDefaultValue($default_value) : self
return $this;
}

/**
* @return string
*/
public function getFilterView() : string
{
return $this->filterView;
}

/**
* @param string $filterView
*
* @return $this
*/
public function setFilterView(string $filterView) : self
{
$this->filterView = $filterView;

return $this;
}

public function getDefaultComparisonOperators() : array
{
return $this->default_comparison_operators;
Expand Down Expand Up @@ -162,7 +184,7 @@ public function placeholder() : string
*/
public function renderFilter(string $label, string $name, array $action_types, self $columnType, Collection $value)
{
return view('report-engine::partials.base-filter')
return view($this->filterView)
->with(
$this->getConfig($label, $name, $action_types, $columnType, $value)
);
Expand Down
4 changes: 3 additions & 1 deletion src/BaseFeatures/Data/Types/DateTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class DateTime extends BaseType

protected ?string $formatter = 'datetime';

protected string $filterView = 'report-engine::partials.date-filter';

public function __construct(
string|null $outputFormat = null,
string|null $placeholder = null,
Expand Down Expand Up @@ -139,7 +141,7 @@ public function renderFilter(string $label, string $name, array $action_types, B
return Carbon::parse($value)->isoFormat($this->outputFormat);
});

return view('report-engine::partials.date-filter')->with([
return view($this->filterView)->with([
'label' => $label,
'field' => $name,
'value' => $value,
Expand Down
3 changes: 2 additions & 1 deletion src/BaseFeatures/Data/Types/Enum.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class Enum extends BaseType
protected $prepend_all = true;
protected $default_value;
protected $use_keys = false;
protected string $filterView = 'report-engine::partials.enum-filter';

/**
* Enum constructor.
Expand Down Expand Up @@ -117,7 +118,7 @@ public function getOptions(): array
*/
public function renderFilter(string $label, string $name, array $action_types, BaseType $columnType, Collection $value)
{
return view('report-engine::partials.enum-filter')->with([
return view($this->filterView)->with([
'label' => $label,
'field' => $name,
'options' => $this->options,
Expand Down
4 changes: 3 additions & 1 deletion src/BaseFeatures/Data/Types/NullableDateTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

class NullableDateTime extends DateTime
{
protected string $filterView = 'report-engine::partials.empty-not-empty-filter';

public function __construct(?string $date_time_format = null, ?string $placeholder = null, ?string $output_tz_name = null)
{
parent::__construct($date_time_format, $placeholder, $output_tz_name);
Expand All @@ -27,7 +29,7 @@ public function __construct(?string $date_time_format = null, ?string $placehold
*/
public function renderFilter(string $label, string $name, array $action_types, BaseType $columnType, Collection $value)
{
return view('report-engine::partials.empty-not-empty-filter')->with([
return view($this->filterView)->with([
'label' => $label,
'field' => $name,
'options' => collect($this->getOptions()),
Expand Down
4 changes: 3 additions & 1 deletion src/BaseFeatures/Data/Types/YesNo.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

class YesNo extends BaseType
{
protected string $filterView = 'report-engine::partials.yes-no-filter';

/**
* @param mixed $value
* @param object|null $result
Expand Down Expand Up @@ -44,7 +46,7 @@ public static function availableFilters(): array
*/
public function renderFilter(string $label, string $name, array $action_types, BaseType $columnType, Collection $value)
{
return view('report-engine::partials.yes-no-filter')->with([
return view($this->filterView)->with([
'label' => $label,
'field' => $name,
'options' => collect($this->getOptions()),
Expand Down