Skip to content

Commit

Permalink
Add mission comment (crf-devs#368)
Browse files Browse the repository at this point in the history
  • Loading branch information
mRoca authored May 3, 2020
1 parent ce14e41 commit 6fa9d1d
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/Entity/Mission.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ class Mission
*/
public ?\DateTimeImmutable $endTime = null;

/**
* @ORM\Column(type="text", options={"default": ""})
*/
public string $comment = '';

/**
* @var User[]|Collection
*
Expand Down
5 changes: 5 additions & 0 deletions src/Form/Type/MissionType.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

Expand Down Expand Up @@ -44,6 +45,10 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
'label' => 'common.start',
'required' => false,
])
->add('comment', TextareaType::class, [
'label' => 'organization.mission.comment',
'required' => false,
])
->add('endTime', DateTimeType::class, [
'widget' => 'single_text',
'input' => 'datetime_immutable',
Expand Down
30 changes: 30 additions & 0 deletions src/Migrations/Version20200503083535.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 Version20200503083535 extends AbstractMigration
{
public function getDescription(): string
{
return 'Add mission comment';
}

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 mission ADD comment TEXT DEFAULT \'\' NOT 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 mission DROP comment');
}
}
5 changes: 5 additions & 0 deletions templates/organization/mission/_show.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
<p>{{ 'common.end' | trans }}: <strong>{{ mission.endTime | format_datetime(date_format='full', time_format='short') }}</strong></p>
{% endif %}

{% if mission.comment %}
<h3 class="mt-4">{{ 'organization.mission.comment' | trans }}</h3>
{{ mission.comment | nl2br }}
{% endif %}

<h3 class="mt-4">{{ 'organization.users' | trans }}</h3>
{{ include('organization/user/_list.html.twig', {users: mission.users | sortBySkills, organization: mission.organization, showActions: false}) }}

Expand Down
22 changes: 20 additions & 2 deletions templates/organization/mission/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,23 @@

{% block title %}{{ 'organization.mission.listTitle' | trans }}{% endblock %}

{% macro missionDates(mission) %}
{% if mission.startTime and mission.endTime %}
{% if mission.startTime.format('Y-m-d') == mission.endTime.format('Y-m-d') %}
{{ mission.startTime | format_date('full') }}
<br>
{{ 'calendar.hoursPeriod' | trans({
'%from%': mission.startTime | format_time('short'),
'%to%': mission.endTime | format_time('short'),
}) }}
{% else %}
{{ mission.startTime | format_datetime(date_format='full', time_format='short') }}
<br>
{{ mission.endTime | format_datetime(date_format='full', time_format='short') }}
{% endif %}
{% endif %}
{% endmacro %}

{% block body %}
<h1>{{ 'organization.mission.listTitle' | trans }}</h1>

Expand All @@ -20,6 +37,7 @@
<th>{{ 'organization.mission.duration' | trans }}</th>
<th>{{ 'organization.users' | trans }}</th>
<th>{{ 'organization.assets' | trans }}</th>
<th>{{ 'organization.mission.comment' | trans }}</th>
<th>{{ 'common.actions' | trans }}</th>
</tr>
</thead>
Expand All @@ -29,11 +47,11 @@
<td><span class="badge badge-secondary">{{ mission.type.name | default('') }}</span></td>
<td>{{ mission.name }}</td>
<td>
{{ mission.startTime ? mission.startTime | format_datetime(date_format='full', time_format='short') : '' }}<br>
{{ mission.endTime ? mission.endTime | format_datetime(date_format='full', time_format='short') : '' }}
{{ _self.missionDates(mission) }}
</td>
<td>{{ mission.users | length }}</td>
<td>{{ mission.assets | length }}</td>
<td>{{ mission.comment | truncate }}</td>
<td>
<a class="btn btn-primary" href="{{ path('app_organization_mission_show', {'id': mission.id}) }}">{{ 'action.show' | trans }}</a>
<a class="btn btn-secondary" href="{{ path('app_organization_mission_edit', {'id': mission.id}) }}">{{ 'action.edit' | trans }}</a>
Expand Down
2 changes: 2 additions & 0 deletions translations/messages.fr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ calendar:
displayedPeriod: Période affichée
hours: heures
period: du %from% au %to%
hoursPeriod: de %from% à %to%
planning: Planning
showAvailableOnly: Afficher seulement si disponible sur la période
sortByDayAvailabilities: Trier par nombre de disponibilités sur le jour
Expand Down Expand Up @@ -105,6 +106,7 @@ organization:
deleteSuccessMessage: La mission a été supprimée avec succès
editFormTitle: Modifier une mission
name: Identifiant de la mission
comment: Commentaires
duration: Date et durée
missionType:
addNew: Ajouter un nouveau type de mission
Expand Down

0 comments on commit 6fa9d1d

Please sign in to comment.