From 9b3df5985ad0c09572e2dc85492cab69f5f65572 Mon Sep 17 00:00:00 2001 From: Nicolas PHILIPPE Date: Tue, 14 Apr 2020 16:33:12 +0200 Subject: [PATCH 1/3] Added fields CommissionableAsset.{licensePlate, comments} --- src/Entity/CommissionableAsset.php | 10 +++++++ src/Form/Type/CommissionableAssetType.php | 7 +++++ src/Migrations/Version20200414132415.php | 35 +++++++++++++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 src/Migrations/Version20200414132415.php diff --git a/src/Entity/CommissionableAsset.php b/src/Entity/CommissionableAsset.php index e3fba8b3..5dada448 100644 --- a/src/Entity/CommissionableAsset.php +++ b/src/Entity/CommissionableAsset.php @@ -81,6 +81,16 @@ class CommissionableAsset implements AvailabilitableInterface */ public int $seatingCapacity = 1; + /** + * @ORM\Column(type="string", nullable=true) + */ + public ?string $licensePlate = null; + + /** + * @ORM\Column(type="text", nullable=true) + */ + public ?string $comments = null; + public function __toString(): string { return $this->type.' - '.$this->name; diff --git a/src/Form/Type/CommissionableAssetType.php b/src/Form/Type/CommissionableAssetType.php index 99b948bd..0c685129 100644 --- a/src/Form/Type/CommissionableAssetType.php +++ b/src/Form/Type/CommissionableAssetType.php @@ -11,6 +11,7 @@ use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\Extension\Core\Type\IntegerType; use Symfony\Component\Form\Extension\Core\Type\SubmitType; +use Symfony\Component\Form\Extension\Core\Type\TextareaType; use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormEvent; @@ -66,6 +67,12 @@ public function buildForm(FormBuilderInterface $builder, array $options): void ->add('seatingCapacity', IntegerType::class, [ 'label' => 'Combien de places ?', ]) + ->add('licensePlate', TextType::class, [ + 'label' => 'Plaque d\'immatriculation', + ]) + ->add('comments', TextareaType::class, [ + 'label' => 'Commentaires', + ]) ->add('submit', SubmitType::class) ; diff --git a/src/Migrations/Version20200414132415.php b/src/Migrations/Version20200414132415.php new file mode 100644 index 00000000..064df0e8 --- /dev/null +++ b/src/Migrations/Version20200414132415.php @@ -0,0 +1,35 @@ +abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.'); + + $this->addSql('ALTER TABLE commissionable_asset ADD license_plate VARCHAR(255) DEFAULT NULL, ADD comments TEXT DEFAULT NULL'); + } + + public function down(Schema $schema) : void + { + // this down() migration is auto-generated, please modify it to your needs + $this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.'); + + $this->addSql('ALTER TABLE commissionable_asset DROP license_plate, DROP comments'); + } +} From c3006338a68f90911079f5a66bdfbd907c71eaa7 Mon Sep 17 00:00:00 2001 From: Nicolas PHILIPPE Date: Tue, 14 Apr 2020 17:31:55 +0200 Subject: [PATCH 2/3] Refacto planning template to add another header --- src/Domain/PlanningDomain.php | 17 ++-- src/Migrations/Version20200414132415.php | 12 +-- .../planning/_availabilities_assets.html.twig | 22 ++++++ .../planning/_availabilities_base.html.twig | 50 ++++++++++++ .../planning/_availabilities_users.html.twig | 35 +++++++++ .../organization/planning/_results.html.twig | 78 +------------------ 6 files changed, 127 insertions(+), 87 deletions(-) create mode 100644 templates/organization/planning/_availabilities_assets.html.twig create mode 100644 templates/organization/planning/_availabilities_base.html.twig create mode 100644 templates/organization/planning/_availabilities_users.html.twig diff --git a/src/Domain/PlanningDomain.php b/src/Domain/PlanningDomain.php index ff8df790..92dcc50d 100644 --- a/src/Domain/PlanningDomain.php +++ b/src/Domain/PlanningDomain.php @@ -99,10 +99,10 @@ public function generateAvailabilities(array $filters, \DatePeriod $datePeriod): $users = $filters['hideUsers'] ?? false ? [] : $this->userRepository->findByFilters($filters, false); $assets = $filters['hideAssets'] ?? false ? [] : $this->assetRepository->findByFilters($filters, false); - return $this->splitAvailabilities( - $this->prepareAvailabilities($this->userAvailabilityRepository, $users, $datePeriod), - $this->prepareAvailabilities($this->assetAvailabilityRepository, $assets, $datePeriod) - ); + return [ + 'assets' => $this->splitAssets($this->prepareAvailabilities($this->assetAvailabilityRepository, $assets, $datePeriod)), + 'users' => $this->splitUsers($this->prepareAvailabilities($this->userAvailabilityRepository, $users, $datePeriod)), + ]; } public function generateLastUpdateAndCount(array $filters): array @@ -184,7 +184,7 @@ protected function parseRawSlots(array $rawSlots): array return $slots; } - protected function splitAvailabilities(array $usersAvailabilities, array $assetsAvailabilities): array + protected function splitAssets(array $assetsAvailabilities): array { $result = []; // Ordered associative array @@ -198,6 +198,13 @@ protected function splitAvailabilities(array $usersAvailabilities, array $assets $result[$item['entity']->type][] = $item; } + return array_filter($result); + } + + protected function splitUsers(array $usersAvailabilities): array + { + $result = []; // Ordered associative array + // Users $importantSkills = $this->skillSetDomain->getImportantSkills(); diff --git a/src/Migrations/Version20200414132415.php b/src/Migrations/Version20200414132415.php index 064df0e8..e03cdc4f 100644 --- a/src/Migrations/Version20200414132415.php +++ b/src/Migrations/Version20200414132415.php @@ -12,23 +12,23 @@ */ final class Version20200414132415 extends AbstractMigration { - public function getDescription() : string + public function getDescription(): string { - return ''; + return 'Add "license_plate" and "comments" fields to "commissionable_asset"'; } - public function up(Schema $schema) : void + public function up(Schema $schema): void { // this up() migration is auto-generated, please modify it to your needs - $this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.'); + $this->abortIf('postgresql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'postgresql\'.'); $this->addSql('ALTER TABLE commissionable_asset ADD license_plate VARCHAR(255) DEFAULT NULL, ADD comments TEXT DEFAULT NULL'); } - public function down(Schema $schema) : void + public function down(Schema $schema): void { // this down() migration is auto-generated, please modify it to your needs - $this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.'); + $this->abortIf('postgresql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'postgresql\'.'); $this->addSql('ALTER TABLE commissionable_asset DROP license_plate, DROP comments'); } diff --git a/templates/organization/planning/_availabilities_assets.html.twig b/templates/organization/planning/_availabilities_assets.html.twig new file mode 100644 index 00000000..d246913f --- /dev/null +++ b/templates/organization/planning/_availabilities_assets.html.twig @@ -0,0 +1,22 @@ +{% extends 'organization/planning/_availabilities_base.html.twig' %} + +{% block type %}{{ type }}{% endblock type %} + +{# columns number of blocks itemDataHeader and itemDataDetails should be the same than in _availabilities_users.html.twig #} +{% block itemDataHeader %} + Radio mobile? + Kit de premiers soins? + Contact + Lieu de stationnement + Places + Immatriculation +{% endblock itemDataHeader %} + +{% block itemDataDetails %} + {{ item.entity.hasMobileRadio ? 'Oui' : '-' }} + {{ item.entity.hasFirstAidKit ? 'Oui' : '-' }} + {{ item.entity.contact }} + {{ item.entity.parkingLocation }} + {{ item.entity.seatingCapacity }} + {{ item.entity.licensePlate }} +{% endblock itemDataDetails %} diff --git a/templates/organization/planning/_availabilities_base.html.twig b/templates/organization/planning/_availabilities_base.html.twig new file mode 100644 index 00000000..5d83d61a --- /dev/null +++ b/templates/organization/planning/_availabilities_base.html.twig @@ -0,0 +1,50 @@ + + + + {{ 'common.informations' | trans }} + {% for item in periodCalculator.days %} + + {{ item.date|format_date(pattern="eeee dd MMMM") }} + + {% endfor %} + + + {% block itemDataHeader %}{% endblock itemDataHeader %} + + {% for item in periodCalculator.slots %} + + {{ item|format_date(pattern="HH") }} + + {% endfor %} + + + +{% for type, list in availabilities %} + + + + {% block type %}{% endblock type %} + ({{ list|length }}) + + + + + + + {% for item in list %} + + + {{ item.entity }} + {% block importantSkills %}{% endblock importantSkills %} + + + {% block itemDataDetails %}{% endblock itemDataDetails %} + + {% autoescape false %} + {# Table td are rendered in php in order to avoid twig performance issue #} + {{ renderPlanningTable(item.availabilities, displayActions) }} + {% endautoescape %} + + {% endfor %} + +{% endfor %} diff --git a/templates/organization/planning/_availabilities_users.html.twig b/templates/organization/planning/_availabilities_users.html.twig new file mode 100644 index 00000000..bf1d48ed --- /dev/null +++ b/templates/organization/planning/_availabilities_users.html.twig @@ -0,0 +1,35 @@ +{% extends 'organization/planning/_availabilities_base.html.twig' %} + +{% block type %}{{ usersSkills[type] | default('organization.users' | trans) }}{% endblock type %} + +{# columns number of blocks itemDataHeader and itemDataDetails should be the same than in _availabilities_assets.html.twig #} +{% block itemDataHeader %} + {{ 'user.identificationNumber' | trans }} + {{ 'common.phoneNumberShort' | trans }} + {{ 'user.email' | trans }} + {{ 'common.occupation' | trans }} + {{ 'common.manager' | trans }} + {{ 'user.skills' | trans }} + {{ 'user.uniform' | trans }} + {{ 'user.detail.vulnerable.label' | trans }} +{% endblock itemDataHeader %} + +{% block importantSkills %} + {{ item.entity.skillSet | filter(skill => skill != type and skill in importantSkillsToDisplay) | map(skill => '' ~skill~ '') | join | raw }} +{% endblock importantSkills %} + +{% block itemDataDetails %} + {{ item.entity.identificationNumber }} + {{ item.entity.phoneNumber }} + {{ item.entity.emailAddress }} + {{ item.entity.occupation }} + {{ item.entity.organizationOccupation }} + + {% for skill in item.entity.skillSet -%} + {{ skill }} + {%- endfor %} + + {{ item.entity.fullyEquipped ? 'common.yes' | trans : '-' }} + {{ item.entity.vulnerable ? 'common.yes' | trans : '-' }} +{% endblock itemDataDetails %} diff --git a/templates/organization/planning/_results.html.twig b/templates/organization/planning/_results.html.twig index 83d8acf3..93de7ff1 100644 --- a/templates/organization/planning/_results.html.twig +++ b/templates/organization/planning/_results.html.twig @@ -54,82 +54,8 @@ {% set availabilities = getAvailabilities(periodCalculator, filters) %}
- - - - - {% for item in periodCalculator.days %} - - {% endfor %} - - - - - - - - - - - {% for item in periodCalculator.slots %} - - {% endfor %} - - - {% for type, list in availabilities %} - {% set isAsset = type in (assetsTypes|keys) %} - {% set entityType = isAsset ? 'assets' : 'users' %} - - - - - - - - - {% for item in list %} - - - {% if not isAsset %} - - - - - - - - - {% else %} - - {% endif %} - {% autoescape false %} - {# Table td are rendered in php in order to avoid twig performance issue #} - {{ renderPlanningTable(item.availabilities, displayActions) }} - {% endautoescape %} - - {% endfor %} - - {% endfor %} + {% include 'organization/planning/_availabilities_assets.html.twig' with {availabilities: availabilities.assets, entityType: 'assets'} %} + {% include 'organization/planning/_availabilities_users.html.twig' with {availabilities: availabilities.users, entityType: 'users'} %} From 0b71b8472389822135b5a639b745b07f2f9da2cb Mon Sep 17 00:00:00 2001 From: Nicolas PHILIPPE Date: Wed, 15 Apr 2020 09:27:05 +0200 Subject: [PATCH 3/3] Assets: use translations in form & planing --- src/Form/Type/CommissionableAssetType.php | 26 +++++++++---------- src/Migrations/Version20200414132415.php | 5 ---- .../planning/_availabilities_assets.html.twig | 16 ++++++------ translations/messages.fr.yaml | 16 ++++++++++++ 4 files changed, 37 insertions(+), 26 deletions(-) diff --git a/src/Form/Type/CommissionableAssetType.php b/src/Form/Type/CommissionableAssetType.php index 0c685129..b5372253 100644 --- a/src/Form/Type/CommissionableAssetType.php +++ b/src/Form/Type/CommissionableAssetType.php @@ -33,45 +33,45 @@ public function buildForm(FormBuilderInterface $builder, array $options): void $builder ->add('type', ChoiceType::class, [ 'choices' => self::TYPES, - 'label' => 'Type', + 'label' => 'asset.type', ]) ->add('name', TextType::class, [ - 'label' => 'Identifiant', + 'label' => 'asset.name', ]) ->add('hasMobileRadio', ChoiceType::class, [ 'choices' => [ - 'Oui' => true, - 'Non' => false, + 'common.yes' => true, + 'common.no' => false, ], 'expanded' => true, 'multiple' => false, - 'label' => 'Présence d\'un mobile radio ?', + 'label' => 'asset.hasMobileRadio', ]) ->add('hasFirstAidKit', ChoiceType::class, [ 'choices' => [ - 'Oui' => true, - 'Non' => false, + 'common.yes' => true, + 'common.no' => false, ], 'expanded' => true, 'multiple' => false, - 'label' => 'Présence d\'un lot de secours ?', + 'label' => 'asset.hasFirstAidKit', ]) ->add('parkingLocation', TextType::class, [ 'required' => false, - 'label' => 'Lieu de stationnement', + 'label' => 'asset.parkingLocation', ]) ->add('contact', TextType::class, [ 'required' => false, - 'label' => 'Qui contacter ?', + 'label' => 'asset.contact', ]) ->add('seatingCapacity', IntegerType::class, [ - 'label' => 'Combien de places ?', + 'label' => 'asset.seatingCapacity', ]) ->add('licensePlate', TextType::class, [ - 'label' => 'Plaque d\'immatriculation', + 'label' => 'asset.licensePlate', ]) ->add('comments', TextareaType::class, [ - 'label' => 'Commentaires', + 'label' => 'asset.comments', ]) ->add('submit', SubmitType::class) ; diff --git a/src/Migrations/Version20200414132415.php b/src/Migrations/Version20200414132415.php index e03cdc4f..b3d205e9 100644 --- a/src/Migrations/Version20200414132415.php +++ b/src/Migrations/Version20200414132415.php @@ -7,9 +7,6 @@ use Doctrine\DBAL\Schema\Schema; use Doctrine\Migrations\AbstractMigration; -/** - * Auto-generated Migration: Please modify to your needs! - */ final class Version20200414132415 extends AbstractMigration { public function getDescription(): string @@ -19,7 +16,6 @@ public function getDescription(): string public function up(Schema $schema): void { - // this up() migration is auto-generated, please modify it to your needs $this->abortIf('postgresql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'postgresql\'.'); $this->addSql('ALTER TABLE commissionable_asset ADD license_plate VARCHAR(255) DEFAULT NULL, ADD comments TEXT DEFAULT NULL'); @@ -27,7 +23,6 @@ public function up(Schema $schema): void public function down(Schema $schema): void { - // this down() migration is auto-generated, please modify it to your needs $this->abortIf('postgresql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'postgresql\'.'); $this->addSql('ALTER TABLE commissionable_asset DROP license_plate, DROP comments'); diff --git a/templates/organization/planning/_availabilities_assets.html.twig b/templates/organization/planning/_availabilities_assets.html.twig index d246913f..97f00a62 100644 --- a/templates/organization/planning/_availabilities_assets.html.twig +++ b/templates/organization/planning/_availabilities_assets.html.twig @@ -4,17 +4,17 @@ {# columns number of blocks itemDataHeader and itemDataDetails should be the same than in _availabilities_users.html.twig #} {% block itemDataHeader %} - - - - - - + + + + + + {% endblock itemDataHeader %} {% block itemDataDetails %} - - + + diff --git a/translations/messages.fr.yaml b/translations/messages.fr.yaml index a442fd7f..5c41d38c 100644 --- a/translations/messages.fr.yaml +++ b/translations/messages.fr.yaml @@ -124,3 +124,19 @@ user: skills: Compétences uniform: Uniforme welcome: Bienvenue, %name% +asset: + type: Type + name: Identifiant + hasMobileRadio: Présence d'un mobile radio ? + hasFirstAidKit: Présence d'un lot de secours ? + contact: Qui contacter ? + parkingLocation: Lieu de stationnement + seatingCapacity: Combien de places ? + licensePlate: Plaque d'immatriculation + comments: Commentaires + planing: + hasMobileRadio: Mobile radio ? + hasFirstAidKit: Kit de premiers soins ? + contact: Contact + seatingCapacity: Places + licensePlate: Immatriculation