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

Add some fields into the Assets entity #290

Merged
merged 3 commits into from
Apr 15, 2020
Merged
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
17 changes: 12 additions & 5 deletions src/Domain/PlanningDomain.php
Original file line number Diff line number Diff line change
@@ -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();

10 changes: 10 additions & 0 deletions src/Entity/CommissionableAsset.php
Original file line number Diff line number Diff line change
@@ -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;
29 changes: 18 additions & 11 deletions src/Form/Type/CommissionableAssetType.php
Original file line number Diff line number Diff line change
@@ -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;
@@ -32,39 +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' => 'asset.licensePlate',
])
->add('comments', TextareaType::class, [
'label' => 'asset.comments',
])
->add('submit', SubmitType::class)
;
30 changes: 30 additions & 0 deletions src/Migrations/Version20200414132415.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

final class Version20200414132415 extends AbstractMigration
{
public function getDescription(): string
{
return 'Add "license_plate" and "comments" fields to "commissionable_asset"';
}

public function up(Schema $schema): void
{
$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
{
$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');
}
}
22 changes: 22 additions & 0 deletions templates/organization/planning/_availabilities_assets.html.twig
Original file line number Diff line number Diff line change
@@ -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 %}
<th class="item-data">{{ 'asset.planing.hasMobileRadio'|trans }}</th>
<th class="item-data" colspan="2">{{ 'asset.planing.hasFirstAidKit'|trans }}</th>
<th class="item-data">{{ 'asset.planing.contact'|trans }}</th>
<th class="item-data" colspan="2">{{ 'asset.parkingLocation'|trans }}</th>
<th class="item-data">{{ 'asset.planing.seatingCapacity'|trans }}</th>
<th class="item-data">{{ 'asset.planing.licensePlate'|trans }}</th>
{% endblock itemDataHeader %}

{% block itemDataDetails %}
<td class="item-data">{{ item.entity.hasMobileRadio ? 'common.yes' | trans : '-' }}</td>
<td class="item-data" colspan="2">{{ item.entity.hasFirstAidKit ? 'common.yes' | trans : '-' }}</td>
<td class="item-data">{{ item.entity.contact }}</td>
<td class="item-data" colspan="2">{{ item.entity.parkingLocation }}</td>
<td class="item-data">{{ item.entity.seatingCapacity }}</td>
<td class="item-data">{{ item.entity.licensePlate }}</td>
{% endblock itemDataDetails %}
50 changes: 50 additions & 0 deletions templates/organization/planning/_availabilities_base.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<thead>
<tr class="days">
<th rowspan="2"></th>
<th colspan="{{ itemDataRow }}" class="item-data">{{ 'common.informations' | trans }}</th>
{% for item in periodCalculator.days %}
<th colspan="{{ item.slots }}" data-day="{{ item.date|date("Y-m-d") }}" title="{{ 'calendar.sortByDayAvailabilities' | trans }}">
{{ item.date|format_date(pattern="eeee dd MMMM") }}
</th>
{% endfor %}
</tr>
<tr class="hours">
{% block itemDataHeader %}{% endblock itemDataHeader %}

{% for item in periodCalculator.slots %}
<th class="slot-name">
{{ item|format_date(pattern="HH") }}
</th>
{% endfor %}
</tr>
</thead>

{% for type, list in availabilities %}
<tbody>
<tr>
<th class="separator bg-dark">
{% block type %}{% endblock type %}
({{ list|length }})
</th>
<td colspan="{{ itemDataRow + periodCalculator.slots|length }}"></td>
</tr>
</tbody>

<tbody class="item-rows">
{% for item in list %}
<tr data-type="{{ entityType }}" data-id="{{ item.entity.id }}">
<th class="item-detail">
{{ item.entity }}
{% block importantSkills %}{% endblock importantSkills %}
</th>

{% block itemDataDetails %}{% endblock itemDataDetails %}

{% autoescape false %}
{# Table td are rendered in php in order to avoid twig performance issue #}
{{ renderPlanningTable(item.availabilities, displayActions) }}
{% endautoescape %}
</tr>
{% endfor %}
</tbody>
{% endfor %}
35 changes: 35 additions & 0 deletions templates/organization/planning/_availabilities_users.html.twig
Original file line number Diff line number Diff line change
@@ -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 %}
<th class="item-data">{{ 'user.identificationNumber' | trans }}</th>
<th class="item-data">{{ 'common.phoneNumberShort' | trans }}</th>
<th class="item-data">{{ 'user.email' | trans }}</th>
<th class="item-data">{{ 'common.occupation' | trans }}</th>
<th class="item-data">{{ 'common.manager' | trans }}</th>
<th class="item-data">{{ 'user.skills' | trans }}</th>
<th class="item-data">{{ 'user.uniform' | trans }}</th>
<th class="item-data">{{ 'user.detail.vulnerable.label' | trans }}</th>
{% endblock itemDataHeader %}

{% block importantSkills %}
{{ item.entity.skillSet | filter(skill => skill != type and skill in importantSkillsToDisplay) | map(skill => '<span class="badge badge-secondary">' ~skill~ '</span>') | join | raw }}
{% endblock importantSkills %}

{% block itemDataDetails %}
<td class="item-data">{{ item.entity.identificationNumber }}</td>
<td class="item-data">{{ item.entity.phoneNumber }}</td>
<td class="item-data">{{ item.entity.emailAddress }}</td>
<td class="item-data">{{ item.entity.occupation }}</td>
<td class="item-data">{{ item.entity.organizationOccupation }}</td>
<td class="item-data">
{% for skill in item.entity.skillSet -%}
<span
class="badge badge-{{ skill in importantSkills ? 'primary' : 'secondary' }}">{{ skill }}</span>
{%- endfor %}
</td>
<td class="item-data">{{ item.entity.fullyEquipped ? 'common.yes' | trans : '-' }}</td>
<td class="item-data">{{ item.entity.vulnerable ? 'common.yes' | trans : '-' }}</td>
{% endblock itemDataDetails %}
78 changes: 2 additions & 76 deletions templates/organization/planning/_results.html.twig
Original file line number Diff line number Diff line change
@@ -54,82 +54,8 @@
{% set availabilities = getAvailabilities(periodCalculator, filters) %}
<div class="planning-container">
<table class="planning table table-sm table-bordered availability-table" data-availability-mode="planning" style="display: none;">
<thead>
<tr class="days">
<th rowspan="2"></th>
<th colspan="{{ itemDataRow }}" class="item-data">{{ 'common.informations' | trans }}</th>
{% for item in periodCalculator.days %}
<th colspan="{{ item.slots }}" data-day="{{ item.date|date("Y-m-d") }}" title="{{ 'calendar.sortByDayAvailabilities' | trans }}">
{{ item.date|format_date(pattern="eeee dd MMMM") }}
</th>
{% endfor %}
</tr>
<tr class="hours">
<th class="item-data">{{ 'user.identificationNumber' | trans }}</th>
<th class="item-data">{{ 'common.phoneNumberShort' | trans }}</th>
<th class="item-data">{{ 'user.email' | trans }}</th>
<th class="item-data">{{ 'common.occupation' | trans }}</th>
<th class="item-data">{{ 'common.manager' | trans }}</th>
<th class="item-data">{{ 'user.skills' | trans }}</th>
<th class="item-data">{{ 'user.uniform' | trans }}</th>
<th class="item-data">{{ 'user.detail.vulnerable.label' | trans }}</th>
{% for item in periodCalculator.slots %}
<th class="slot-name">
{{ item|format_date(pattern="HH") }}
</th>
{% endfor %}
</tr>
</thead>
{% for type, list in availabilities %}
{% set isAsset = type in (assetsTypes|keys) %}
{% set entityType = isAsset ? 'assets' : 'users' %}
<tbody>
<tr>
<th class="separator bg-dark">
{% if isAsset %}
{{ type }}
{% else %}
{{ usersSkills[type] | default('organization.users' | trans) }}
{% endif %}
({{ list|length }})
</th>
<td colspan="{{ itemDataRow + periodCalculator.slots|length }}"></td>
</tr>
</tbody>

<tbody class="item-rows">
{% for item in list %}
<tr data-type="{{ entityType }}" data-id="{{ item.entity.id }}">
<th class="item-detail">
{{ item.entity }}
{% if not isAsset %}
{{ item.entity.skillSet | filter(skill => skill != type and skill in importantSkillsToDisplay) | map(skill => '<span class="badge badge-secondary">' ~skill~ '</span>') | join | raw }}
{% endif %}
</th>
{% if not isAsset %}
<td class="item-data">{{ item.entity.identificationNumber }}</td>
<td class="item-data">{{ item.entity.phoneNumber }}</td>
<td class="item-data">{{ item.entity.emailAddress }}</td>
<td class="item-data">{{ item.entity.occupation }}</td>
<td class="item-data">{{ item.entity.organizationOccupation }}</td>
<td class="item-data">
{% for skill in item.entity.skillSet -%}
<span class="badge badge-{{ skill in importantSkills ? 'primary' : 'secondary' }}">{{ skill }}</span>
{%- endfor %}
</td>
<td class="item-data">{{ item.entity.fullyEquipped ? 'common.yes' | trans : '-' }}</td>
<td class="item-data">{{ item.entity.vulnerable ? 'common.yes' | trans : '-' }}</td>
{% else %}
<td class="item-data" colspan="{{ itemDataRow }}"></td>
{% endif %}
{% autoescape false %}
{# Table td are rendered in php in order to avoid twig performance issue #}
{{ renderPlanningTable(item.availabilities, displayActions) }}
{% endautoescape %}
</tr>
{% endfor %}
</tbody>
{% 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'} %}
<tfoot>
<tr>
<td colspan="{{ 1 + itemDataRow + periodCalculator.slots|length }}" class="separator"></td>
16 changes: 16 additions & 0 deletions translations/messages.fr.yaml
Original file line number Diff line number Diff line change
@@ -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