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

next release #66

Open
wants to merge 57 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
773069a
feat: remove dropdown when only one action is set and show icon with …
marcwieland95 May 16, 2024
8c2914d
fix: check if target exists before trying to update it
marcwieland95 May 16, 2024
369985e
refactor: introduce Stimulus Class API for Table Select Controller an…
marcwieland95 May 22, 2024
1217973
Merge pull request #52 from araise-dev/feature/58-single-table-action
marcwieland95 May 23, 2024
a633aa7
Merge pull request #51 from araise-dev/feature/79-bulk-edit-stimulus-…
marcwieland95 May 23, 2024
20f9b62
feat: listens for global event to close dropdown when another is opened
marcwieland95 May 15, 2024
6460979
Merge pull request #50 from araise-dev/feature/59-dropdown-close
marcwieland95 May 23, 2024
9643267
feat: refactor accordion stimulus controller, adjust subtable and imp…
marcwieland95 May 17, 2024
9bcd700
Merge pull request #49 from araise-dev/feature/72-subtable-accordion
marcwieland95 May 23, 2024
f72cbcb
fix: Fix export for relation content
ArnoEgli Apr 30, 2024
9e2207b
fix: Make if statement more readable
ArnoEgli May 31, 2024
a8ee9a0
fix: Fix export table of same definition
ArnoEgli May 31, 2024
724d9ed
Merge pull request #48 from araise-dev/feature/relation-content-export
tuxes3 Jun 3, 2024
7d75d05
chore: removed deprecations in tests
tuxes3 Jun 10, 2024
1a3b31c
feature(test): added strategy matrix for php and symfony
tuxes3 Jun 11, 2024
d445d45
Merge pull request #53 from araise-dev/feature/test-matrix
tuxes3 Jun 11, 2024
5e6b914
fix: undefined table actions visibility
Jun 18, 2024
3da90aa
Merge pull request #54 from araise-dev/fix/undefined-table-actions-vi…
dowitsch Jun 18, 2024
8810d74
chore: set orm to max version 2.x (only require-dev) as gedmo does no…
tuxes3 Jun 27, 2024
41978d1
feat: add sub_table_collapsed option to table
Ruesa18 Jun 25, 2024
6267045
Merge pull request #55 from araise-dev/feature/13-table-toggle-option
tuxes3 Jun 27, 2024
1fa733c
fix: Fix export for relation content
ArnoEgli Jun 26, 2024
1eb6490
Merge pull request #57 from araise-dev/feature/relation-content-export
tuxes3 Jun 27, 2024
b6a6aed
feat(footer): allow adding footer to table
Ruesa18 Jun 27, 2024
e510734
feat(footer): Add doc
Ruesa18 Jun 27, 2024
f8b7b9e
docs: change theme of mermaid diagrams
Ruesa18 Jun 27, 2024
e8c020e
Merge pull request #28 from araise-dev/feature/footer-columns
tuxes3 Jun 27, 2024
edaf358
Merge pull request #58 from araise-dev/feature/24-documentation-desig…
tuxes3 Jun 27, 2024
9017d44
fix: use subselect to count results
Ruesa18 Jul 2, 2024
de5b5a1
Merge pull request #59 from araise-dev/fix/112-count-incorrect-when-g…
tuxes3 Jul 3, 2024
c20882b
chore: updated zenstruck/foundry to ^2.0
tuxes3 Jul 22, 2024
a7d6449
Merge pull request #64 from araise-dev/feature/update-zenstruck-foundry
tuxes3 Jul 22, 2024
5e04665
fix: multiple subtables are possible, toggle them correctly within th…
marcwieland95 Jul 17, 2024
9796bb0
refactor(accordion): more DRY, clearer functions and helpful comments
marcwieland95 Jul 18, 2024
47c5282
fix: remove border on the left of the subtable
marcwieland95 Jul 18, 2024
d8d2030
feat(export): improve styling of export dropdown
marcwieland95 Jul 18, 2024
e8e85bb
feat: add utility class to checkbox to align with global styling
marcwieland95 Jul 18, 2024
10470f4
feat: lightbox content for add button into header
marcwieland95 Jul 20, 2024
19d3acc
fix: adjust styling in header and add tooltips to buttons in table he…
marcwieland95 Jul 20, 2024
965e20d
fix: translate strings and make buttons/dropdown more accessible
marcwieland95 Jul 22, 2024
cd1fc15
refactor(subtables): use proper if-condition instead of JSX style check
marcwieland95 Jul 22, 2024
8bc17c2
refactor: simplify conditionals inside element
marcwieland95 Jul 22, 2024
c34722b
docs: add information from where this code is coming from
marcwieland95 Jul 23, 2024
f48a1fc
refactor: simplify if/else statement for attributes
marcwieland95 Jul 23, 2024
f7d8e00
Merge pull request #60 from araise-dev/feature/126-subtables
marcwieland95 Jul 23, 2024
f071171
Merge pull request #63 from araise-dev/feature/119-table-header
marcwieland95 Jul 23, 2024
a413789
Merge pull request #62 from araise-dev/feature/116-export-box
marcwieland95 Jul 23, 2024
81b3dd0
fix: add datepicker to filters with `datetime` & `date` input fields
marcwieland95 Jul 18, 2024
72b3966
feat: add dynamic locale to Filter Date Type
marcwieland95 Jul 19, 2024
b4046bb
chore: code style
tuxes3 Jul 23, 2024
5a3eb42
refactor: use StimulusHelper to generate Stimulus Attributes
tuxes3 Jul 24, 2024
3cc6982
Merge pull request #61 from araise-dev/feature/124-filter-datepicker
tuxes3 Jul 24, 2024
808517d
fix: style on mobile, add spacing on the left
marcwieland95 Sep 18, 2024
671846d
Merge pull request #65 from araise-dev/feature/119-style-fix
marcwieland95 Sep 19, 2024
df9fcc9
feat(table): check view.route and add button visibilty
tuxes3 Oct 7, 2024
2c3786e
chore: added Changelog for v1.2.0
tuxes3 Oct 8, 2024
0d8df6a
Merge branch 'release/v1.2.0' into develop
tuxes3 Oct 8, 2024
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
52 changes: 41 additions & 11 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,26 +1,56 @@
name: tableBundle
name: PHP Symfony CI

on:
push:
branches: [ main ]
pull_request:
branches: [ main, develop ]

env:
DATABASE_URL: mysql://root:[email protected]:3306/table_bundle
DATABASE_DRIVER: pdo_mysql

jobs:
phpunit:
build:
runs-on: ubuntu-latest

strategy:
matrix:
php: [8.1, 8.2, 8.3]
symfony: [6.4.*, 7.0.*, 7.1.*]
exclude:
- php: 8.1
symfony: 7.1.*
- php: 8.1
symfony: 7.0.*

services:
mysql:
image: mysql:latest
env:
MYSQL_ROOT_PASSWORD: root
ports:
- 3306:3306
options: >-
--health-cmd "mysqladmin ping --silent"
--health-interval 10s
--health-timeout 5s
--health-retries 3

steps:
- uses: shivammathur/setup-php@2cb9b829437ee246e9b3cac53555a39208ca6d28
- uses: actions/checkout@v4
- name: Setup PHP ${{ matrix.php }}
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
- uses: actions/checkout@v2
- name: Install Dependencies
run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
- name: Execute tests (Unit and Feature tests) via PHPUnit
php-version: ${{ matrix.php }}
tools: flex
- name: Download dependencies
env:
DATABASE_URL: sqlite:///%kernel.project_dir%/var/app.db
SYMFONY_REQUIRE: ${{ matrix.symfony }}
uses: ramsey/composer-install@v2
- name: Run test suite on PHP ${{ matrix.php }} and Symfony ${{ matrix.symfony }}
run: vendor/bin/simple-phpunit
- name: Check Code Styles
- name: Run ECS
run: vendor/bin/ecs
- name: Check PHP Stan
- name: Run PHPStan
run: vendor/bin/phpstan analyse src tests
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# CHANGELOG

## v1.2.0
- Removed symfony ^5.4 support
- Added Table option `OPT_SUB_TABLE_COLLAPSED`. This will collapse the sub table by default, you can also pass a callable to determine if the sub table should be collapsed or not
- Added footer columns to the table. This can be used to display totals or other information
- Fixed a bug where the table count would be of when using group by in the default query builder
- Date filters now use the `datetime_controller.js` provided by the core-bundle
- UX improvements

## v1.0.7
- More documentation and better styling of the documentation
- Added a new optional parameter to the `FilterTypeInterface::getValueField()` method to allow for more complex value fields.
Expand Down
26 changes: 13 additions & 13 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,30 @@
],
"require": {
"php": ">=8.1",
"symfony/framework-bundle": "^5.4|^6.4|^7.0",
"symfony/http-kernel": "^5.4|^6.4|^7.0",
"symfony/validator": "^5.4|^6.4|^7.0",
"symfony/framework-bundle": "^6.4|^7.0",
"symfony/http-kernel": "^6.4|^7.0",
"symfony/validator": "^6.4|^7.0",
"araise/core-bundle": "^1.1",
"araise/search-bundle": "^3.1",
"phpoffice/phpspreadsheet": "^1.22|^2.0",
"symfony/stimulus-bundle": "^2.16"
},
"require-dev": {
"symfony/phpunit-bridge": "^5.4|^6.4|^7.0",
"symfony/config": "^5.4|^6.4|^7.0",
"symfony/dependency-injection": "^5.4|^6.4|^7.0",
"symfony/yaml": "^5.4|^6.4|^7.0",
"symfony/phpunit-bridge": "^6.4|^7.0",
"symfony/config": "^6.4|^7.0",
"symfony/dependency-injection": "^6.4|^7.0",
"symfony/yaml": "^6.4|^7.0",
"doctrine/doctrine-bundle": "^2.5.5",
"doctrine/orm": "^2.11|^3.1",
"doctrine/orm": "^2.11",
"whatwedo/php-coding-standard": "^1.0",
"zenstruck/foundry": "^1.16",
"zenstruck/foundry": "^v2.0.7",
"zenstruck/console-test": "^v1.1.0",
"symfony/translation": "^5.4|^6.4|^7.0",
"symfony/twig-bundle": "^5.4|^6.4|^7.0",
"symfony/translation": "^6.4|^7.0",
"symfony/twig-bundle": "^6.4|^7.0",
"gedmo/doctrine-extensions": "^3.15",
"symfony/webpack-encore-bundle": "^1.14|^2.1",
"symfony/security-core": "^5.4|^6.4|^7.0",
"symfony/security-bundle": "^5.4|^6.4|^7.0",
"symfony/security-core": "^6.4|^7.0",
"symfony/security-bundle": "^6.4|^7.0",
"phpstan/phpstan": "^1.5"
},
"autoload": {
Expand Down
14 changes: 13 additions & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,19 @@
<!-- Source: https://github.com/Leward/mermaid-docsify -->
<script type="module">
import mermaid from "https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.esm.min.mjs";
mermaid.initialize({ startOnLoad: true });
mermaid.initialize({
startOnLoad: true,
theme: 'base',
themeVariables: {
darkMode: true,
primaryColor: '#5b47d1',
primaryTextColor: '#ffffff',
primaryBorderColor: '#1b1447',
lineColor: '#fc00ff',
secondaryColor: '#fc00ff',
tertiaryColor: '#fc00ff',
},
});
window.mermaid = mermaid;
</script>
<script src="https://unpkg.com/[email protected]/dist/docsify-mermaid.js"></script>
Expand Down
53 changes: 53 additions & 0 deletions docs/table-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,32 @@ All Options are as constants in `Table` class.
- - `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`
- `sub_table_collapsed`: Boolean or callable, default: `true`


### Collapse Sub-Tables
By default, sub-tables will be rendered collapsed.
This can be changed by setting the `sub_table_collapsed` option to either `false` or pass a callable that returns a boolean.

```php
$table->setOption(Table::OPT_SUB_TABLE_COLLAPSED, false);
```

Note that if you pass a function, you will get the current row as an argument.
You can use this to only expand certain rows:

```php
// Expand only users with an email
$table->setOption(Table::OPT_SUB_TABLE_COLLAPSED, function(array|object $row) {
if(!$row instanceof User) {
return true;
}
if($row->getEmail() !== null) {
return false;
}
return true;
});
```


## Column Options
Expand All @@ -48,6 +74,33 @@ All Options are as constants in `Column` class.
- `formatter`: [Formatter](formatter.md)
- `sort_expression`: String, example: `'trainerGroup.name'`

## Footer Columns
In this example we would like to add a count of the content at the end of our table.
We can to this by adding a footer column like so:

```php
$data= [
[
'id' => 1,
],
[
'id' => 2,
]
];

$table
->setFooterData(['count' => count($data)])
->addFooterColumn('totalLabel', null, [
Column::OPT_CALLABLE => fn (array $content) => 'Total',
])
->addFooterColumn('count', null, [
Column::OPT_CALLABLE => fn(array $content) => $content['count'],
])
;
```

Note that this is only a simple example. The data could easily be replaced with an array of entities for example.

## Action Columns

Action Columns are here to link to other pages (f.ex. link to edit or view).
Expand Down
1 change: 1 addition & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<server name="SHELL_VERBOSITY" value="-1"/>
<server name="SYMFONY_DEPRECATIONS_HELPER" value="max[self]=0&amp;max[direct]=0"/>
<env name="DATABASE_URL" value="mysql://root:[email protected]:3306/table_bundle" />
<env name="DATABASE_DRIVER" value="pdo_mysql" />

</php>
<testsuites>
Expand Down
22 changes: 19 additions & 3 deletions src/DataLoader/DoctrineDataLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use araise\TableBundle\Extension\PaginationExtension;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Query\Parameter;
use Doctrine\ORM\Query\ResultSetMapping;
use Doctrine\ORM\QueryBuilder;
use Doctrine\ORM\Tools\Pagination\Paginator;
Expand Down Expand Up @@ -43,9 +44,24 @@ public function getResults(): iterable
/** @var QueryBuilder $qb */
$qb = (clone $this->options[self::OPT_QUERY_BUILDER]);
$qb->select('COUNT('.$qb->getRootAliases()[0].')');
$qb->resetDQLPart('groupBy');
$qb->resetDQLPart('orderBy');
$this->paginationExtension->setTotalResults((int) $qb->getQuery()->getSingleScalarResult());

if (count($qb->getDQLPart('groupBy')) > 0) {
$sql = $qb->getQuery()->getSQL();
$params = array_values(
array_map(
static fn (Parameter $parameter) => $parameter->getValue(),
$qb->getParameters()->toArray()
)
);

$sql = sprintf('SELECT COUNT(*) as row_count FROM (%s) AS sub;', $sql);
$rsm = new ResultSetMapping();
$rsm->addScalarResult('row_count', 'row_count', 'integer');
$count = $this->entityManager->createNativeQuery($sql, $rsm)->setParameters($params)->getSingleScalarResult();
$this->paginationExtension->setTotalResults((int) $count);
} else {
$this->paginationExtension->setTotalResults($qb->getQuery()->getSingleScalarResult());
}

if ($this->getOption(self::OPT_SAVE_LAST_QUERY) && $this->requestStack->getCurrentRequest()?->hasSession()) {
/** @var QueryBuilder $qbSave */
Expand Down
2 changes: 1 addition & 1 deletion src/DependencyInjection/araiseTableExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;

class araiseTableExtension extends Extension implements PrependExtensionInterface
{
Expand Down
25 changes: 22 additions & 3 deletions src/Filter/Type/DateFilterType.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,36 @@
namespace araise\TableBundle\Filter\Type;

use Doctrine\ORM\QueryBuilder;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\UX\StimulusBundle\Helper\StimulusHelper;

class DateFilterType extends DatetimeFilterType
{
protected $locale;

public function __construct(
?string $column = null,
array $joins = [],
protected ?RequestStack $requestStack = null
) {
parent::__construct($column, $joins);
$this->locale = $requestStack->getMainRequest()?->getLocale() ?? 'en';
}

public function getValueField(?string $value = null, ?string $operator = null): string
{
$date = \DateTime::createFromFormat(static::getQueryDataFormat(), (string) $value) ?: new \DateTime();
$value = $date->format(static::getDateFormat());

$stimulusAttrs = (new StimulusHelper(null))->createStimulusAttributes();
$stimulusAttrs
->addController('araise/core-bundle/datetime', [
'lang' => $this->locale,
])
;
return sprintf(
'<input type="date" name="{name}" value="%s">',
$operator !== static::CRITERIA_IS_EMPTY ? $value : ''
'<input type="date" name="{name}" value="%s" %s>',
$operator !== static::CRITERIA_IS_EMPTY ? $value : '',
$stimulusAttrs
);
}

Expand Down
23 changes: 20 additions & 3 deletions src/Filter/Type/DatetimeFilterType.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
namespace araise\TableBundle\Filter\Type;

use Doctrine\ORM\QueryBuilder;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\UX\StimulusBundle\Helper\StimulusHelper;

class DatetimeFilterType extends FilterType
{
Expand All @@ -20,6 +22,14 @@ class DatetimeFilterType extends FilterType

public const CRITERIA_IS_EMPTY = 'is_empty';

public function __construct(
?string $column = null,
array $joins = [],
protected ?RequestStack $requestStack = null
) {
parent::__construct($column, $joins);
}

public function getOperators(): array
{
return [
Expand All @@ -38,10 +48,17 @@ public function getValueField(?string $value = null, ?string $operator = null):
{
$date = \DateTime::createFromFormat(static::getQueryDataFormat(), (string) $value) ?: new \DateTime();
$value = $date->format(static::getDateFormat());

$locale = $this->requestStack->getMainRequest()?->getLocale();
$stimulusAttrs = (new StimulusHelper(null))->createStimulusAttributes();
$stimulusAttrs
->addController('araise/core-bundle/datetime', [
'lang' => $locale ?? 'en',
])
;
return sprintf(
'<input type="datetime-local" name="{name}" value="%s">',
$operator !== static::CRITERIA_IS_EMPTY ? $value : ''
'<input type="datetime-local" name="{name}" value="%s" %s>',
$operator !== static::CRITERIA_IS_EMPTY ? $value : '',
$stimulusAttrs
);
}

Expand Down
Loading
Loading