From 6abf51be4ba6b44b0d348550e7fd6a073e9ff89d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Fri, 5 Oct 2018 11:45:46 +0200 Subject: [PATCH 1/4] [export] layout of page "export list" --- CHANGELOG.md | 1 + .../modules/export-list/export-list.scss | 21 ++++++++++++++++ Resources/views/Export/layout.html.twig | 25 ++++++++----------- .../UI/notification_user_counter.html.twig | 2 +- chill.webpack.config.js | 1 + 5 files changed, 35 insertions(+), 15 deletions(-) create mode 100644 Resources/public/modules/export-list/export-list.scss diff --git a/CHANGELOG.md b/CHANGELOG.md index 6278f42a6..6fd31b832 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,4 +17,5 @@ Master branch ============= - fix error when interval is hour only +- layout of page "list exports" diff --git a/Resources/public/modules/export-list/export-list.scss b/Resources/public/modules/export-list/export-list.scss new file mode 100644 index 000000000..c1db247f1 --- /dev/null +++ b/Resources/public/modules/export-list/export-list.scss @@ -0,0 +1,21 @@ +.container-export { + margin-left: 1rem; + margin-right: 1rem; + + .export-list { + display: flex; + flex-direction: row; + flex-wrap: wrap; + justify-content: space-between; + + .export-list__element { + min-width: 18rem; + max-width: 20rem; + padding: 1rem; + margin: 1rem; + flex-grow: 1; + + border: 1px solid var(--chill-gray); + } + } +} \ No newline at end of file diff --git a/Resources/views/Export/layout.html.twig b/Resources/views/Export/layout.html.twig index 8a125d4f7..7eb8655d6 100644 --- a/Resources/views/Export/layout.html.twig +++ b/Resources/views/Export/layout.html.twig @@ -16,25 +16,21 @@ * along with this program. If not, see . #} -{% extends "ChillMainBundle::layoutWithVerticalMenu.html.twig" %} +{% extends "ChillMainBundle::layout.html.twig" %} {% block title %}{{ 'Exports list'|trans }}{% endblock %} -{% block vertical_menu_content %} - {{ chill_menu('export', { - 'layout': 'ChillMainBundle::Menu/export.html.twig', - }) }} -{% endblock %} -{% block layout_wvm_content %} - {% block export_content %} -

{{ 'Exports list'|trans }}

- +{% block content %} +
+

{{ 'Exports list'|trans }}

+ +
{% for export_alias,export in exports %} - +
+{% endblock %} diff --git a/Resources/views/UI/notification_user_counter.html.twig b/Resources/views/UI/notification_user_counter.html.twig index aa5e6bde1..e4e899ba6 100644 --- a/Resources/views/UI/notification_user_counter.html.twig +++ b/Resources/views/UI/notification_user_counter.html.twig @@ -1 +1 @@ -{% if nb > 0 %}{{ nb }}{% endif %} \ No newline at end of file +{% if nb > 0 %}{{ nb }}{% endif %} \ No newline at end of file diff --git a/chill.webpack.config.js b/chill.webpack.config.js index ba21e486b..9fb9200a7 100644 --- a/chill.webpack.config.js +++ b/chill.webpack.config.js @@ -28,6 +28,7 @@ require('./Resources/public/modules/download-report/index.js'); //require('./Resources/public/css/select2/select2.css'); require('select2/dist/css/select2.css'); require('./Resources/public/modules/select_interactive_loading/index.js'); +require('./Resources/public/modules/export-list/export-list.scss'); // img require('./Resources/public/img/favicon.ico'); From 2ff30ae6564fe3002eb5532b90cb3f00ad3b853c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Mon, 8 Oct 2018 21:27:10 +0200 Subject: [PATCH 2/4] fix php typo --- Controller/UserController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Controller/UserController.php b/Controller/UserController.php index 7b2b013e6..83465366a 100644 --- a/Controller/UserController.php +++ b/Controller/UserController.php @@ -210,7 +210,7 @@ class UserController extends Controller try { $user->removeGroupCenter($groupCenter); } catch (\RuntimeException $ex) { - $this->addFlash('error', $this->get('translator')->trans($ex-getMessage())); + $this->addFlash('error', $this->get('translator')->trans($ex->getMessage())); return $this->redirect($this->generateUrl('admin_user_edit', array('id' => $uid))); } From 25f550303047272ac8e5b09748605fc44649d4d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Thu, 18 Oct 2018 09:41:40 +0200 Subject: [PATCH 3/4] Add overlaps date/time operator and similarity --- CHANGELOG.md | 3 + DependencyInjection/ChillMainExtension.php | 6 +- Doctrine/DQL/OverlapsI.php | 110 +++++++++++++++++++++ Doctrine/DQL/Similarity.php | 54 ++++++++++ 4 files changed, 172 insertions(+), 1 deletion(-) create mode 100644 Doctrine/DQL/OverlapsI.php create mode 100644 Doctrine/DQL/Similarity.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 6fd31b832..58162daed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,4 +18,7 @@ Master branch - fix error when interval is hour only - layout of page "list exports" +- create function "SIMILARITY" (see [posgtgresql documentation](https://www.postgresql.org/docs/9.6/static/pgtrgm.html)) +- create function "OVERLAPSI", which will detect period of date overlapping, replacing NULL date by infinity or -infinity (see [postgresql page for date time function and operators](https://www.postgresql.org/docs/9.6/static/functions-datetime.html)) + diff --git a/DependencyInjection/ChillMainExtension.php b/DependencyInjection/ChillMainExtension.php index 27449454b..8d7e1e202 100644 --- a/DependencyInjection/ChillMainExtension.php +++ b/DependencyInjection/ChillMainExtension.php @@ -30,6 +30,8 @@ use Chill\MainBundle\Doctrine\DQL\GetJsonFieldByKey; use Chill\MainBundle\Doctrine\DQL\Unaccent; use Chill\MainBundle\Doctrine\DQL\JsonAggregate; use Chill\MainBundle\Doctrine\DQL\JsonbExistsInArray; +use Chill\MainBundle\Doctrine\DQL\Similarity; +use Chill\MainBundle\Doctrine\DQL\OverlapsI; /** * This class load config for chillMainExtension. @@ -159,7 +161,9 @@ class ChillMainExtension extends Extension implements PrependExtensionInterface, 'AGGREGATE' => JsonAggregate::class ), 'numeric_functions' => [ - 'JSONB_EXISTS_IN_ARRAY' => JsonbExistsInArray::class + 'JSONB_EXISTS_IN_ARRAY' => JsonbExistsInArray::class, + 'SIMILARITY' => Similarity::class, + 'OVERLAPSI' => OverlapsI::class ] ) ) diff --git a/Doctrine/DQL/OverlapsI.php b/Doctrine/DQL/OverlapsI.php new file mode 100644 index 000000000..ae9df72f4 --- /dev/null +++ b/Doctrine/DQL/OverlapsI.php @@ -0,0 +1,110 @@ + + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +namespace Chill\MainBundle\Doctrine\DQL; + +use Doctrine\ORM\Query\AST\Functions\FunctionNode; +use Doctrine\ORM\Query\Lexer; + +/** + * DQL function for OVERLAPS function in postgresql + * + * If a value is null in period start, it will be replaced by -infinity. + * If a value is null in period end, it will be replaced by infinity + * + */ +class OverlapsI extends FunctionNode +{ + private $firstPeriodStart; + + private $firstPeriodEnd; + + private $secondPeriodStart; + + private $secondPeriodEnd; + + public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker) + { + return '(' + .$this->makeCase($sqlWalker, $this->firstPeriodStart, 'start').', ' + .$this->makeCase($sqlWalker, $this->firstPeriodEnd, 'end'). + ') OVERLAPS (' + .$this->makeCase($sqlWalker, $this->secondPeriodStart, 'start').', ' + .$this->makeCase($sqlWalker, $this->secondPeriodEnd, 'end').')' + ; + } + + protected function makeCase($sqlWalker, $part, $position) + { + //return $part->dispatch($sqlWalker); + + switch ($position) { + case 'start' : + $p = '-infinity'; + break; + case 'end': + $p = 'infinity'; + break; + } + + if ($part instanceof \Doctrine\ORM\Query\AST\PathExpression) { + return 'CASE WHEN ' + .' '.$part->dispatch($sqlWalker).' IS NOT NULL ' + . 'THEN '. + $part->dispatch($sqlWalker) + . ' ELSE '. + "'".$p."'::date " + . 'END'; + } else { + return 'CASE WHEN ' + .' '.$part->dispatch($sqlWalker).'::date IS NOT NULL ' + . 'THEN '. + $part->dispatch($sqlWalker) + . '::date ELSE '. + "'".$p."'::date " + . 'END'; + } + } + + public function parse(\Doctrine\ORM\Query\Parser $parser) + { + $parser->match(Lexer::T_IDENTIFIER); + + $parser->match(Lexer::T_OPEN_PARENTHESIS); + + $this->firstPeriodStart = $parser->StringPrimary(); + + $parser->match(Lexer::T_COMMA); + + $this->firstPeriodEnd = $parser->StringPrimary(); + + $parser->match(Lexer::T_CLOSE_PARENTHESIS); + + $parser->match(Lexer::T_COMMA); + + $parser->match(Lexer::T_OPEN_PARENTHESIS); + + $this->secondPeriodStart = $parser->StringPrimary(); + + $parser->match(Lexer::T_COMMA); + + $this->secondPeriodEnd = $parser->StringPrimary(); + + $parser->match(Lexer::T_CLOSE_PARENTHESIS); + } +} diff --git a/Doctrine/DQL/Similarity.php b/Doctrine/DQL/Similarity.php new file mode 100644 index 000000000..988e55f5f --- /dev/null +++ b/Doctrine/DQL/Similarity.php @@ -0,0 +1,54 @@ + + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +namespace Chill\MainBundle\Doctrine\DQL; + +use Doctrine\ORM\Query\AST\Functions\FunctionNode; +use Doctrine\ORM\Query\Lexer; + +/** + * + * + * + */ +class Similarity extends FunctionNode +{ + private $firstPart; + + private $secondPart; + + public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker) + { + return 'SIMILARITY('.$this->firstPart->dispatch($sqlWalker). + ', ' . $this->secondPart->dispatch($sqlWalker) .")"; + } + + public function parse(\Doctrine\ORM\Query\Parser $parser) + { + $parser->match(Lexer::T_IDENTIFIER); + $parser->match(Lexer::T_OPEN_PARENTHESIS); + + $this->firstPart = $parser->StringPrimary(); + + $parser->match(Lexer::T_COMMA); + + $this->secondPart = $parser->StringPrimary(); + + $parser->match(Lexer::T_CLOSE_PARENTHESIS); + } +} From 62ee90f671b38766cdba0fbd852ed62ecfe53637 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Fri, 19 Oct 2018 14:27:46 +0200 Subject: [PATCH 4/4] add repository for center --- CHANGELOG.md | 2 +- Repository/CenterRepository.php | 27 ++++++++++++++++++++++ Resources/config/doctrine/Center.orm.yml | 1 + Resources/config/services/repositories.yml | 8 +++++++ 4 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 Repository/CenterRepository.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 58162daed..19e1ccf23 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,5 +20,5 @@ Master branch - layout of page "list exports" - create function "SIMILARITY" (see [posgtgresql documentation](https://www.postgresql.org/docs/9.6/static/pgtrgm.html)) - create function "OVERLAPSI", which will detect period of date overlapping, replacing NULL date by infinity or -infinity (see [postgresql page for date time function and operators](https://www.postgresql.org/docs/9.6/static/functions-datetime.html)) - +- add repository for Center class diff --git a/Repository/CenterRepository.php b/Repository/CenterRepository.php new file mode 100644 index 000000000..05a439bfd --- /dev/null +++ b/Repository/CenterRepository.php @@ -0,0 +1,27 @@ + + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +namespace Chill\MainBundle\Repository; + +/** + * + * + */ +class CenterRepository extends \Doctrine\ORM\EntityRepository +{ + +} diff --git a/Resources/config/doctrine/Center.orm.yml b/Resources/config/doctrine/Center.orm.yml index 8ac4355cc..c09a18bf7 100644 --- a/Resources/config/doctrine/Center.orm.yml +++ b/Resources/config/doctrine/Center.orm.yml @@ -1,6 +1,7 @@ Chill\MainBundle\Entity\Center: type: entity table: centers + repositoryClass: Chill\MainBundle\Repository\CenterRepository id: id: type: integer diff --git a/Resources/config/services/repositories.yml b/Resources/config/services/repositories.yml index 56ea84656..897fd4313 100644 --- a/Resources/config/services/repositories.yml +++ b/Resources/config/services/repositories.yml @@ -24,4 +24,12 @@ services: - "Chill\\MainBundle\\Entity\\PostalCode" Chill\MainBundle\Repository\PostalCodeRepository: '@chill.main.postalcode_repository' + + chill.main.center_repository: + class: Doctrine\ORM\EntityRepository + factory: ["@doctrine.orm.entity_manager", getRepository] + arguments: + - "Chill\\MainBundle\\Entity\\Center" + + Chill\MainBundle\Repository\CenterRepository: '@chill.main.center_repository' \ No newline at end of file