Skip to content

Commit

Permalink
Merge pull request #390 from crf-devs/improve-templates
Browse files Browse the repository at this point in the history
Improve templates
  • Loading branch information
mRoca authored May 7, 2020
2 parents ddaf2c6 + 1713456 commit 6ba123d
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 10 deletions.
2 changes: 1 addition & 1 deletion assets/css/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ body {
}

footer {
margin-top: 10rem;
margin-top: 6rem;
padding-top: 3rem;
padding-bottom: 3rem;
padding-left: 4rem;
Expand Down
1 change: 1 addition & 0 deletions assets/css/planning.scss
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ $tableBoxSize: 40px;
.planning {
margin-bottom: 40px;
width: auto;
background-color: white;

thead {
th {
Expand Down
19 changes: 17 additions & 2 deletions src/Form/Type/MissionType.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use App\Repository\CommissionableAssetRepository;
use App\Repository\MissionTypeRepository;
use App\Repository\UserRepository;
use App\Twig\Extension\UserExtension;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
Expand All @@ -21,6 +22,13 @@

class MissionType extends AbstractType
{
private UserExtension $userExtension;

public function __construct(UserExtension $userExtension)
{
$this->userExtension = $userExtension;
}

public function buildForm(FormBuilderInterface $builder, array $options): void
{
$organization = $builder->getData()->organization ?? null;
Expand Down Expand Up @@ -65,6 +73,14 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
'choice_label' => fn (User $user) => (string) $user,
'multiple' => true,
'required' => false,
'choice_attr' => function (User $user) {
return [
'data-content' => $user.' '.implode('', array_map(
fn (string $skill) => $this->userExtension->formatBadge($skill),
$this->userExtension->filterInludedSkills($user->skillSet)
)),
];
},
'attr' => [
'class' => 'selectpicker',
'data-live-search' => 'true',
Expand All @@ -83,8 +99,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
'class' => 'selectpicker',
'data-live-search' => 'true',
],
])
;
]);
}

public function configureOptions(OptionsResolver $resolver): void
Expand Down
16 changes: 15 additions & 1 deletion src/Twig/Extension/TwigTextExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,23 @@ public function getFilters(): array
{
return [
new TwigFilter('truncate', [$this, 'truncate']),
new TwigFilter('emptyIfSmaller', [$this, 'emptyIfSmaller']),
];
}

public function emptyIfSmaller(?string $text, int $maxLen = 50, string $ellipsis = '...'): string
{
if (!\is_string($text)) {
return '';
}

if (\strlen($text) <= $maxLen - \strlen($ellipsis)) {
return '';
}

return $text;
}

public function truncate(?string $text, int $maxLen = 50, string $ellipsis = '...'): string
{
if (!\is_string($text)) {
Expand All @@ -29,6 +43,6 @@ public function truncate(?string $text, int $maxLen = 50, string $ellipsis = '..
return $text;
}

return substr($text, 0, $maxLen - 3).$ellipsis;
return substr($text, 0, $maxLen - \strlen($ellipsis)).$ellipsis;
}
}
12 changes: 12 additions & 0 deletions src/Twig/Extension/UserExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,21 @@ public function getFilters(): array
return [
new TwigFilter('skillBadge', [$this, 'formatBadge'], ['is_safe' => ['html']]),
new TwigFilter('sortBySkills', [$this, 'sortBySkills']),
new TwigFilter('filterSkillsToDisplay', [$this, 'filterSkillsToDisplay']),
new TwigFilter('filterInludedSkills', [$this, 'filterInludedSkills']),
];
}

public function filterSkillsToDisplay(array $skills): array
{
return array_values(array_intersect($skills, $this->skillSetDomain->getSkillsToDisplay()));
}

public function filterInludedSkills(array $skills): array
{
return $this->skillSetDomain->filterIncludedSkills($skills);
}

public function formatBadge(string $skill): string
{
$importantSkills = $this->skillSetDomain->getImportantSkills();
Expand Down
6 changes: 3 additions & 3 deletions templates/organization/home.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
</p>

<hr>
<p><a href="{{ path('app_organization_list') }}" class="btn btn-info">{{ 'organization.editAll' | trans }}</a></p>
<p><a href="{{ path('app_organization_mission_type_index') }}" class="btn btn-info">{{ 'organization.editMissionType' | trans }}</a></p>
<p><a href="{{ path('app_organization_assetType_list') }}" class="btn btn-info">{{ 'organization.editAssetType' | trans }}</a></p>
<p><a href="{{ path('app_organization_list') }}" class="btn btn-outline-info">{{ 'organization.editAll' | trans }}</a></p>
<p><a href="{{ path('app_organization_mission_type_index') }}" class="btn btn-outline-info">{{ 'organization.editMissionType' | trans }}</a></p>
<p><a href="{{ path('app_organization_assetType_list') }}" class="btn btn-outline-info">{{ 'organization.editAssetType' | trans }}</a></p>
{% endif %}
{% endblock %}
4 changes: 4 additions & 0 deletions templates/organization/mission/_form.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
{{ form_row(form.organization) }}
{% endif %}


{{ form_row(form.type) }}
<p class="text-right">
<a href="{{ path('app_organization_mission_type_new') }}">{{ 'organization.mission.newType' | trans }}</a>
</p>

{{ form_row(form.name) }}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@

{% block itemDataRowHeader %}
{{ item.entity }}
{{ item.entity.skillSet | filter(skill => skill != type and skill in importantSkillsToDisplay) | map(skill => skill|skillBadge) | join | raw }}
{{ item.entity.skillSet | filterSkillsToDisplay | filterInludedSkills | map(skill => skill|skillBadge) | join | raw }}
{% endblock itemDataRowHeader %}

{% block itemDataDetails %}
<td class="item-data">{{ item.entity.identificationNumber }}</td>
<td class="item-data">{{ item.entity.phoneNumber|phone_number_format('NATIONAL') }}</td>
<td class="item-data">{{ item.entity.emailAddress }}</td>
<td class="item-data">{{ item.entity.occupation | truncate(50) }}</td>
<td class="item-data">{{ item.entity.organizationOccupation | truncate(50) }}</td>
<td class="item-data" title="{{ item.entity.occupation | emptyIfSmaller(50) }}">{{ item.entity.occupation | truncate(50) }}</td>
<td class="item-data" title="{{ item.entity.occupation | emptyIfSmaller(50) }}">{{ item.entity.organizationOccupation | truncate(50) }}</td>
<td class="item-data">
{% for skill in getDisplayableSkillsInPlanning(item.entity) -%}
{{ skill|skillBadge }}
Expand Down
1 change: 1 addition & 0 deletions translations/messages.fr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ organization:
listFull: Equipages
itemFull: Equipage
listFullChooseDate: Choisissez une période pour afficher les équipages.
newType: Ajouter un nouveau type de mission (cela fermera la page courante)
missionType:
addNew: Ajouter un nouveau type de mission
assetTypes:
Expand Down

0 comments on commit 6ba123d

Please sign in to comment.