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

Release/v1.0.8 #42

Merged
merged 2 commits into from
Mar 6, 2024
Merged
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
1 change: 1 addition & 0 deletions docs/table-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ All Options are as constants in `Table` class.
- - `content_show_result_label`: Boolean, default: `true`
- - `content_show_header`: Boolean, default: `true`
- - `content_show_entry_dropdown`: Boolean, default: `true`
- - `content_show_pagination_if_page_total_less_than_limit`: Boolean, default: `true`


## Column Options
Expand Down
28 changes: 26 additions & 2 deletions src/Filter/Type/DateFilterType.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace araise\TableBundle\Filter\Type;

use Doctrine\ORM\QueryBuilder;

class DateFilterType extends DatetimeFilterType
{
public function getValueField(?string $value = null, ?string $operator = null): string
Expand All @@ -12,19 +14,41 @@ public function getValueField(?string $value = null, ?string $operator = null):
$value = $date->format(static::getDateFormat());

return sprintf(
'<input type="text" name="{name}" value="%s" class="form-control" data-provide="datetimepicker" data-date-format="dd.mm.yyyy" data-min-view="2">',
'<input type="date" name="{name}" value="%s">',
$operator !== static::CRITERIA_IS_EMPTY ? $value : ''
);
}

public function toDql(string $operator, string $value, string $parameterName, QueryBuilder $queryBuilder)
{
if ($operator === static::CRITERIA_EQUAL) {
$date = $this->prepareDateValue($value);
$startOfDate = (clone $date)->setTime(0, 0);
$endOfDate = (clone $date)->setTime(23, 59, 59);
$queryBuilder->setParameter($parameterName.'_start', $startOfDate);
$queryBuilder->setParameter($parameterName.'_end', $endOfDate);
return $queryBuilder->expr()->andX(
$queryBuilder->expr()->gte(
$this->getOption(static::OPT_COLUMN),
sprintf(':%s', $parameterName.'_start')
),
$queryBuilder->expr()->lte(
$this->getOption(static::OPT_COLUMN),
sprintf(':%s', $parameterName.'_end')
)
);
}
return parent::toDql($operator, $value, $parameterName, $queryBuilder);
}

protected function prepareDateValue(string $value): \DateTime
{
return \DateTime::createFromFormat(static::getDateFormat(), $value) ?: new \DateTime();
}

protected static function getDateFormat(): string
{
return 'd.m.Y';
return 'Y-m-d';
}

protected static function getQueryDataFormat(): string
Expand Down
10 changes: 5 additions & 5 deletions src/Filter/Type/DatetimeFilterType.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function getValueField(?string $value = null, ?string $operator = null):
$value = $date->format(static::getDateFormat());

return sprintf(
'<input type="text" name="{name}" value="%s" class="form-control" data-provide="datetimepicker" data-date-format="dd.mm.yyyy HH:ii">',
'<input type="datetime-local" name="{name}" value="%s">',
$operator !== static::CRITERIA_IS_EMPTY ? $value : ''
);
}
Expand Down Expand Up @@ -83,8 +83,8 @@ public function toDql(string $operator, string $value, string $parameterName, Qu
$queryBuilder->setParameter($parameterName.'_end', $endYear->format(static::getQueryDataFormat()));

return $queryBuilder->expr()->andX(
$queryBuilder->expr()->gte($this->getColumn(), sprintf(':%s', $parameterName.'_start')),
$queryBuilder->expr()->lte($this->getColumn(), sprintf(':%s', $parameterName.'_end'))
$queryBuilder->expr()->gte($column, sprintf(':%s', $parameterName.'_start')),
$queryBuilder->expr()->lte($column, sprintf(':%s', $parameterName.'_end'))
);
case static::CRITERIA_IS_EMPTY:
return $queryBuilder->expr()->isNull($column);
Expand All @@ -100,11 +100,11 @@ protected function prepareDateValue(string $value): \DateTime

protected static function getDateFormat(): string
{
return 'd.m.Y H:i';
return 'Y-m-d\TH:i';
}

protected static function getQueryDataFormat(): string
{
return 'Y-m-d H:i:s';
return 'Y-m-d\TH:i';
}
}
4 changes: 2 additions & 2 deletions src/Resources/views/tailwind_2/_filter.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@
{{ stimulus_target('araise/table-bundle/filter', 'filterspanel') }}
>

<form action="{{ araise_table_path_replace_arguments({ (araise_table_parameter(table, 'page')) : 1 }) }}" class="w-screen max-w-3xl">
{% for name,value in araise_table_path_replace_arguments({ (araise_table_parameter(table, 'page')) : 1 }, true) %}
<form action="{{ araise_table_path_replace_arguments({ (araise_table_parameter(table, 'page')) : 1 }, false, true) }}" class="w-screen max-w-3xl">
{% for name,value in araise_table_path_replace_arguments({ (araise_table_parameter(table, 'page')) : 1 }, true, true) %}
{# only load filter unrelevant query parameters #}
{% if not (name matches '/.+_filter_(column|operator|value).+/') %}
<input type="hidden" name="{{ name }}" value="{{ value }}">
Expand Down
8 changes: 7 additions & 1 deletion src/Resources/views/tailwind_2/_pagination.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
}]) %}
{% endif %}

{% set hasPagination = paginationLinks|length > 1 %}
{% set hasPagination = table.getOption('content_visibility')['content_show_pagination_if_page_total_less_than_limit'] or paginationLinks|length > 1 %}
{% if (
(table.getOption('content_visibility')['content_show_result_label'] or
table.getOption('content_visibility')['content_show_entry_dropdown'] or
Expand Down Expand Up @@ -153,5 +153,11 @@
{% endif %}
</div>
</footer>
{% else %}
<footer class="whatwedo_table:footer w-full my-3 px-3 flex items-center justify-between">
<p class="whatwedo-utility-paragraph inline-block">
<span class="text-neutral-500 hidden" {{ stimulus_target('@araise/table-bundle/table_select', 'selectedCount') }}/>
</p>
</footer>
{% endif %}
{% endif %}
12 changes: 5 additions & 7 deletions src/Table/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ class Table

public const OPT_CONTENT_SHOW_ENTRY_DROPDOWN = 'content_show_entry_dropdown';

public const OPT_CONTENT_SHOW_PAGINATION_IF_PAGE_TOTAL_LESS_THAN_LIMIT = 'content_show_pagination_if_page_total_less_than_limit';

public const OPT_SUB_TABLE_LOADER = 'sub_table_loader';

protected array $columns = [];
Expand Down Expand Up @@ -96,16 +98,12 @@ public function configureOptions(OptionsResolver $resolver): void
$contentResolver
->setDefaults([
self::OPT_CONTENT_SHOW_PAGINATION => true,
])
->setDefaults([
self::OPT_CONTENT_SHOW_RESULT_LABEL => true,
])
->setDefaults([
self::OPT_CONTENT_SHOW_HEADER => true,
])
->setDefaults([
self::OPT_CONTENT_SHOW_ENTRY_DROPDOWN => true,
]);
self::OPT_CONTENT_SHOW_PAGINATION_IF_PAGE_TOTAL_LESS_THAN_LIMIT => true,
])
;
},
self::OPT_THEME => '@araiseTable/tailwind_2_layout.html.twig',
self::OPT_DEFINITION => null,
Expand Down
8 changes: 6 additions & 2 deletions src/Twig/TableExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,18 @@ public function getFilters(): array
];
}

public function pathReplaceArguments(array $arguments, bool $returnParameters = false): string|array
public function pathReplaceArguments(array $arguments, bool $returnParameters = false, bool $filterPredefined = false): string|array
{
$request = $this->requestStack->getCurrentRequest();

$attributes = $this->filterKeys($request->attributes->all(), fn ($key) => !str_starts_with($key, '_'));
$queryParameters = $this->filterKeys($request->query->all(), fn ($key) => !str_ends_with($key, RouterHelper::PARAMETER_FILTER_PREDEFINED));
$queryParameters = $request->query->all();
if ($filterPredefined) {
$queryParameters = $this->filterKeys($queryParameters, fn ($key) => !str_ends_with($key, RouterHelper::PARAMETER_FILTER_PREDEFINED));
}

$parameters = array_replace(array_merge($attributes, $queryParameters), $arguments);

if ($returnParameters) {
return $this->post2Name($parameters);
}
Expand Down
Loading