Skip to content

Commit e178bf1

Browse files
authored
Merge pull request #23 from solflare/feature/add-support-for-dynamic-filter-views
Data Types: Add support for dynamically setting the filter view template
2 parents cc81824 + 521098a commit e178bf1

File tree

5 files changed

+34
-5
lines changed

5 files changed

+34
-5
lines changed

src/BaseFeatures/Data/Types/Bases/BaseType.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ abstract class BaseType
2222

2323
protected ?string $formatter = null;
2424

25+
protected string $filterView = 'report-engine::partials.base-filter';
26+
2527
/**
2628
* @param mixed $value
2729
* @param object|null $result
@@ -99,6 +101,26 @@ public function setDefaultValue($default_value) : self
99101
return $this;
100102
}
101103

104+
/**
105+
* @return string
106+
*/
107+
public function getFilterView() : string
108+
{
109+
return $this->filterView;
110+
}
111+
112+
/**
113+
* @param string $filterView
114+
*
115+
* @return $this
116+
*/
117+
public function setFilterView(string $filterView) : self
118+
{
119+
$this->filterView = $filterView;
120+
121+
return $this;
122+
}
123+
102124
public function getDefaultComparisonOperators() : array
103125
{
104126
return $this->default_comparison_operators;
@@ -162,7 +184,7 @@ public function placeholder() : string
162184
*/
163185
public function renderFilter(string $label, string $name, array $action_types, self $columnType, Collection $value)
164186
{
165-
return view('report-engine::partials.base-filter')
187+
return view($this->filterView)
166188
->with(
167189
$this->getConfig($label, $name, $action_types, $columnType, $value)
168190
);

src/BaseFeatures/Data/Types/DateTime.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ class DateTime extends BaseType
2525

2626
protected ?string $formatter = 'datetime';
2727

28+
protected string $filterView = 'report-engine::partials.date-filter';
29+
2830
public function __construct(
2931
string|null $outputFormat = null,
3032
string|null $placeholder = null,
@@ -139,7 +141,7 @@ public function renderFilter(string $label, string $name, array $action_types, B
139141
return Carbon::parse($value)->isoFormat($this->outputFormat);
140142
});
141143

142-
return view('report-engine::partials.date-filter')->with([
144+
return view($this->filterView)->with([
143145
'label' => $label,
144146
'field' => $name,
145147
'value' => $value,

src/BaseFeatures/Data/Types/Enum.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class Enum extends BaseType
1212
protected $prepend_all = true;
1313
protected $default_value;
1414
protected $use_keys = false;
15+
protected string $filterView = 'report-engine::partials.enum-filter';
1516

1617
/**
1718
* Enum constructor.
@@ -117,7 +118,7 @@ public function getOptions(): array
117118
*/
118119
public function renderFilter(string $label, string $name, array $action_types, BaseType $columnType, Collection $value)
119120
{
120-
return view('report-engine::partials.enum-filter')->with([
121+
return view($this->filterView)->with([
121122
'label' => $label,
122123
'field' => $name,
123124
'options' => $this->options,

src/BaseFeatures/Data/Types/NullableDateTime.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
class NullableDateTime extends DateTime
1111
{
12+
protected string $filterView = 'report-engine::partials.empty-not-empty-filter';
13+
1214
public function __construct(?string $date_time_format = null, ?string $placeholder = null, ?string $output_tz_name = null)
1315
{
1416
parent::__construct($date_time_format, $placeholder, $output_tz_name);
@@ -27,7 +29,7 @@ public function __construct(?string $date_time_format = null, ?string $placehold
2729
*/
2830
public function renderFilter(string $label, string $name, array $action_types, BaseType $columnType, Collection $value)
2931
{
30-
return view('report-engine::partials.empty-not-empty-filter')->with([
32+
return view($this->filterView)->with([
3133
'label' => $label,
3234
'field' => $name,
3335
'options' => collect($this->getOptions()),

src/BaseFeatures/Data/Types/YesNo.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
class YesNo extends BaseType
1111
{
12+
protected string $filterView = 'report-engine::partials.yes-no-filter';
13+
1214
/**
1315
* @param mixed $value
1416
* @param object|null $result
@@ -44,7 +46,7 @@ public static function availableFilters(): array
4446
*/
4547
public function renderFilter(string $label, string $name, array $action_types, BaseType $columnType, Collection $value)
4648
{
47-
return view('report-engine::partials.yes-no-filter')->with([
49+
return view($this->filterView)->with([
4850
'label' => $label,
4951
'field' => $name,
5052
'options' => collect($this->getOptions()),

0 commit comments

Comments
 (0)