From 9a79e759e7ff7c4ade3d184882eb7aea871b464d Mon Sep 17 00:00:00 2001 From: Lucas Graciano Date: Tue, 18 Jun 2024 11:39:42 -0700 Subject: [PATCH 1/2] Data Types: Add support for dynamically setting the filter view blade template --- .../Data/Types/Bases/BaseType.php | 24 ++++++++++++++++++- src/BaseFeatures/Data/Types/DateTime.php | 4 +++- src/BaseFeatures/Data/Types/Enum.php | 3 ++- .../Data/Types/NullableDateTime.php | 4 +++- src/BaseFeatures/Data/Types/YesNo.php | 4 +++- 5 files changed, 34 insertions(+), 5 deletions(-) diff --git a/src/BaseFeatures/Data/Types/Bases/BaseType.php b/src/BaseFeatures/Data/Types/Bases/BaseType.php index 1508775..53f3a59 100755 --- a/src/BaseFeatures/Data/Types/Bases/BaseType.php +++ b/src/BaseFeatures/Data/Types/Bases/BaseType.php @@ -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 @@ -99,6 +101,26 @@ public function setDefaultValue($default_value) : self return $this; } + /** + * @return string + */ + public function getFilterView() + { + 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; @@ -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) ); diff --git a/src/BaseFeatures/Data/Types/DateTime.php b/src/BaseFeatures/Data/Types/DateTime.php index 1ebb5fa..c5c5977 100755 --- a/src/BaseFeatures/Data/Types/DateTime.php +++ b/src/BaseFeatures/Data/Types/DateTime.php @@ -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, @@ -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, diff --git a/src/BaseFeatures/Data/Types/Enum.php b/src/BaseFeatures/Data/Types/Enum.php index 6c65b8e..35ed7b1 100755 --- a/src/BaseFeatures/Data/Types/Enum.php +++ b/src/BaseFeatures/Data/Types/Enum.php @@ -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. @@ -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, diff --git a/src/BaseFeatures/Data/Types/NullableDateTime.php b/src/BaseFeatures/Data/Types/NullableDateTime.php index f8c2568..f41bbb1 100755 --- a/src/BaseFeatures/Data/Types/NullableDateTime.php +++ b/src/BaseFeatures/Data/Types/NullableDateTime.php @@ -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); @@ -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()), diff --git a/src/BaseFeatures/Data/Types/YesNo.php b/src/BaseFeatures/Data/Types/YesNo.php index 9d2fdb5..6137302 100755 --- a/src/BaseFeatures/Data/Types/YesNo.php +++ b/src/BaseFeatures/Data/Types/YesNo.php @@ -9,6 +9,8 @@ class YesNo extends BaseType { + protected string $filterView = 'report-engine::partials.yes-no-filter'; + /** * @param mixed $value * @param object|null $result @@ -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()), From 521098a1c6794bb0623ddcb9a5da86bf61544c48 Mon Sep 17 00:00:00 2001 From: Lucas Graciano Date: Tue, 18 Jun 2024 12:15:40 -0700 Subject: [PATCH 2/2] [Minor] Add missing return type hint --- src/BaseFeatures/Data/Types/Bases/BaseType.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/BaseFeatures/Data/Types/Bases/BaseType.php b/src/BaseFeatures/Data/Types/Bases/BaseType.php index 53f3a59..88fdc54 100755 --- a/src/BaseFeatures/Data/Types/Bases/BaseType.php +++ b/src/BaseFeatures/Data/Types/Bases/BaseType.php @@ -104,7 +104,7 @@ public function setDefaultValue($default_value) : self /** * @return string */ - public function getFilterView() + public function getFilterView() : string { return $this->filterView; }