Skip to content

Commit

Permalink
Refacto planning template to add another header
Browse files Browse the repository at this point in the history
  • Loading branch information
nikophil committed Apr 15, 2020
1 parent 9b3df59 commit c300633
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 87 deletions.
17 changes: 12 additions & 5 deletions src/Domain/PlanningDomain.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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();

Expand Down
12 changes: 6 additions & 6 deletions src/Migrations/Version20200414132415.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down
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">Radio mobile?</th>
<th class="item-data" colspan="2">Kit de premiers soins?</th>
<th class="item-data">Contact</th>
<th class="item-data" colspan="2">Lieu de stationnement</th>
<th class="item-data">Places</th>
<th class="item-data">Immatriculation</th>
{% endblock itemDataHeader %}

{% block itemDataDetails %}
<td class="item-data">{{ item.entity.hasMobileRadio ? 'Oui' : '-' }}</td>
<td class="item-data" colspan="2">{{ item.entity.hasFirstAidKit ? 'Oui' : '-' }}</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
Expand Up @@ -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>
Expand Down

0 comments on commit c300633

Please sign in to comment.