improved Plan / Allocation items

This commit is contained in:
Alexandre Gain committed 2026-11-07 22:08:06 +01:00
1 parent f6684f3b2e
commit 8c8d7a6f95
12 files changed
+49 -30

No files matched your search

+2 -2
View File
@@ -160,7 +160,7 @@ Mautic.planInitCollection = function ($editor) {
}); });
// Typed items (description, allocation): show the selected type's description under the dropdown, and // Typed items (description, allocation): show the selected type's description under the dropdown, and
// for description items its pictogram next to it. // its pictogram next to it.
$editor.on('change', 'select.plan-item-type', function () { $editor.on('change', 'select.plan-item-type', function () {
var $option = mQuery(this).find('option:selected'); var $option = mQuery(this).find('option:selected');
var $row = mQuery(this).closest('.plan-collection-row'); var $row = mQuery(this).closest('.plan-collection-row');
@@ -201,7 +201,7 @@ Mautic.planInitCollection = function ($editor) {
$row.find('input[type="text"]').first().trigger('focus'); $row.find('input[type="text"]').first().trigger('focus');
}); });
// Pictogram of a description item type: preview the chosen icon. // Pictogram of an item type (description, allocation): preview the chosen icon.
mQuery(document).on('change', '.plan-config-types select.plan-type-icon-select', function () { mQuery(document).on('change', '.plan-config-types select.plan-type-icon-select', function () {
var icon = mQuery(this).find('option:selected').attr('data-icon') || ''; var icon = mQuery(this).find('option:selected').attr('data-icon') || '';
mQuery(this).closest('.plan-config-type').find('.plan-type-icon-preview').first().attr('class', 'plan-type-icon-preview ' + icon); mQuery(this).closest('.plan-config-type').find('.plan-type-icon-preview').first().attr('class', 'plan-type-icon-preview ' + icon);
+1 -1
View File
@@ -90,7 +90,7 @@ return [
// Item types, edited in Settings > Configuration > Plan Settings. Read them through ItemTypeProvider. // Item types, edited in Settings > Configuration > Plan Settings. Read them through ItemTypeProvider.
// Each is a list of ['key' => …, 'names' => [locale => …], 'descriptions' => [locale => …]], // Each is a list of ['key' => …, 'names' => [locale => …], 'descriptions' => [locale => …]],
// plus 'icon' => a Remix Icon class for description item types. // plus 'icon' => a Remix Icon class for description and allocation item types.
'plan_description_item_types' => [], 'plan_description_item_types' => [],
'plan_allocation_item_types' => [], 'plan_allocation_item_types' => [],
], ],
+2 -2
View File
@@ -16,7 +16,7 @@ use Symfony\Component\Validator\Constraints\NotBlank;
/** /**
* The "Plan Settings" tab of Settings > Configuration. Each child is a local.php parameter: * The "Plan Settings" tab of Settings > Configuration. Each child is a local.php parameter:
* - plan_currency: the currency of every amount in the plugin (general setting); * - plan_currency: the currency of every amount in the plugin (general setting);
* - one list of item types per kind (description items, with a pictogram; allocation items). * - one list of item types per kind (description items, allocation items), each with a pictogram.
* *
* @extends AbstractType<array<string, mixed>> * @extends AbstractType<array<string, mixed>>
*/ */
@@ -46,7 +46,7 @@ class ConfigType extends AbstractType
$builder->add($parameter, CollectionType::class, [ $builder->add($parameter, CollectionType::class, [
'label' => false, 'label' => false,
'entry_type' => ItemTypeConfigType::class, 'entry_type' => ItemTypeConfigType::class,
'entry_options' => ['label' => false, 'with_icon' => ItemTypeProvider::KIND_DESCRIPTION === $kind], 'entry_options' => ['label' => false, 'with_icon' => true],
'allow_add' => true, 'allow_add' => true,
'allow_delete' => true, 'allow_delete' => true,
'prototype' => true, 'prototype' => true,
+4 -4
View File
@@ -21,7 +21,7 @@ use Symfony\Component\Validator\Constraints\NotBlank;
/** /**
* One item type (description or allocation) in Settings > Configuration > Plan Settings: a name and a * One item type (description or allocation) in Settings > Configuration > Plan Settings: a name and a
* description per language, and for description item types a pictogram. * description per language, and a pictogram.
* *
* The key is hidden. It is generated when the type is created and never changes, so that renaming a * The key is hidden. It is generated when the type is created and never changes, so that renaming a
* type doesn't affect the items that use it. * type doesn't affect the items that use it.
@@ -70,7 +70,7 @@ class ItemTypeConfigType extends AbstractType
$builder->add($names); $builder->add($names);
$builder->add($descriptions); $builder->add($descriptions);
// Description item types have a pictogram; the preview next to the dropdown is updated by plan.js. // Pictogram; the preview next to the dropdown is updated by plan.js.
if ($options['with_icon']) { if ($options['with_icon']) {
$builder->add('icon', ChoiceType::class, [ $builder->add('icon', ChoiceType::class, [
'label' => 'mautic.plan.config.type.icon', 'label' => 'mautic.plan.config.type.icon',
@@ -96,8 +96,8 @@ class ItemTypeConfigType extends AbstractType
public function configureOptions(OptionsResolver $resolver): void public function configureOptions(OptionsResolver $resolver): void
{ {
$resolver->setDefaults([ $resolver->setDefaults([
// True for description item types: adds the pictogram field. // Adds the pictogram field; both kinds of item types have one.
'with_icon' => false, 'with_icon' => true,
]); ]);
$resolver->setAllowedTypes('with_icon', 'bool'); $resolver->setAllowedTypes('with_icon', 'bool');
} }
+8 -3
View File
@@ -18,8 +18,9 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
/** /**
* One row of the allocation items collection in PlanType: type, name, description, planned cost and * One row of the allocation items collection in PlanType: type, name, description, planned cost and
* real cost (both in the general currency). Works like PlanDescriptionItemType (type description shown under the * real cost (both in the general currency). Works like PlanDescriptionItemType (type description shown
* dropdown, hidden position kept in display order by Assets/js/plan.js). * under the dropdown and its pictogram next to it, hidden position kept in display order by
* Assets/js/plan.js).
* *
* @extends AbstractType<PlanAllocationItem> * @extends AbstractType<PlanAllocationItem>
*/ */
@@ -40,7 +41,11 @@ class PlanAllocationItemType extends AbstractType
'label_attr' => ['class' => 'control-label'], 'label_attr' => ['class' => 'control-label'],
'attr' => ['class' => 'form-control plan-item-type'], 'attr' => ['class' => 'form-control plan-item-type'],
'choices' => $this->typeProvider->getChoices($kind), 'choices' => $this->typeProvider->getChoices($kind),
'choice_attr' => fn (?string $key): array => ['data-description' => (string) $this->typeProvider->getDescription($kind, $key)], // The type's description and pictogram, shown next to the dropdown by plan.js.
'choice_attr' => fn (?string $key): array => [
'data-description' => (string) $this->typeProvider->getDescription($kind, $key),
'data-icon' => (string) $this->typeProvider->getIcon($kind, $key),
],
'placeholder' => 'mautic.core.form.chooseone', 'placeholder' => 'mautic.core.form.chooseone',
'required' => true, 'required' => true,
]); ]);
@@ -1,7 +1,7 @@
{# {#
# Settings > Configuration > Plan Settings: the general currency, the description item types (with a # Settings > Configuration > Plan Settings: the general currency, the description item types and the
# pictogram) and the allocation item types. Adding and removing types, and the pictogram preview, are # allocation item types, each with a pictogram. Adding and removing types, and the pictogram preview,
# handled by Assets/js/plan.js (delegated handlers on .plan-config-types). # are handled by Assets/js/plan.js (delegated handlers on .plan-config-types).
#} #}
{% macro type_row(type) %} {% macro type_row(type) %}
+6 -1
View File
@@ -235,6 +235,7 @@
<table class="table table-hover plan-allocation-items-view"> <table class="table table-hover plan-allocation-items-view">
<thead> <thead>
<tr> <tr>
<th class="text-center" style="width: 1%;">{{ 'mautic.plan.allocation_item.field.pictogram'|trans }}</th>
<th>{{ 'mautic.plan.allocation_item.field.type'|trans }}</th> <th>{{ 'mautic.plan.allocation_item.field.type'|trans }}</th>
<th>{{ 'mautic.plan.allocation_item.field.name'|trans }}</th> <th>{{ 'mautic.plan.allocation_item.field.name'|trans }}</th>
<th class="visible-md visible-lg">{{ 'mautic.plan.allocation_item.field.description'|trans }}</th> <th class="visible-md visible-lg">{{ 'mautic.plan.allocation_item.field.description'|trans }}</th>
@@ -246,7 +247,11 @@
{% for allocationItem in allocationItems %} {% for allocationItem in allocationItems %}
{% set typeName = plan_item_type_name('allocation', allocationItem.type) %} {% set typeName = plan_item_type_name('allocation', allocationItem.type) %}
{% set typeDescription = plan_item_type_description('allocation', allocationItem.type) %} {% set typeDescription = plan_item_type_description('allocation', allocationItem.type) %}
{% set typeIcon = plan_item_type_icon('allocation', allocationItem.type) %}
<tr> <tr>
<td class="text-center">
{% if typeIcon %}<i class="{{ typeIcon }} plan-item-type-icon" style="font-size: 24px;" aria-hidden="true"></i>{% endif %}
</td>
<td{% if typeDescription %} title="{{ typeDescription }}"{% endif %}> <td{% if typeDescription %} title="{{ typeDescription }}"{% endif %}>
{{ typeName ?? 'mautic.plan.description_item.type.unknown'|trans({'%key%': allocationItem.type}) }} {{ typeName ?? 'mautic.plan.description_item.type.unknown'|trans({'%key%': allocationItem.type}) }}
</td> </td>
@@ -263,7 +268,7 @@
</tbody> </tbody>
<tfoot> <tfoot>
<tr class="plan-allocation-total"> <tr class="plan-allocation-total">
<th colspan="3">{{ 'mautic.plan.allocation.total'|trans }}</th> <th colspan="4">{{ 'mautic.plan.allocation.total'|trans }}</th>
<th class="text-right text-nowrap"> <th class="text-right text-nowrap">
{% if allocationTotals.planned is not null %}{{ plan_money(allocationTotals.planned) }} {{ plan_currency() }}{% endif %} {% if allocationTotals.planned is not null %}{{ plan_money(allocationTotals.planned) }} {{ plan_currency() }}{% endif %}
</th> </th>
+13 -5
View File
@@ -67,12 +67,20 @@
{% macro allocation_item_row(item) %} {% macro allocation_item_row(item) %}
{{ _self.row_start('mautic.plan.allocation_item.drag') }} {{ _self.row_start('mautic.plan.allocation_item.drag') }}
<div class="row"> <div class="row">
<div class="col-md-6"> {# The selected type's pictogram; updated by plan.js when the type changes. #}
{{ form_row(item.type) }} <div class="col-xs-1 text-center pt-lg">
{# Filled with the selected type's description by plan.js. #} <i class="plan-item-type-icon {{ plan_item_type_icon('allocation', item.type.vars.value) }}" style="font-size: 28px;" aria-hidden="true"></i>
<p class="help-block plan-item-type-help">{{ plan_item_type_description('allocation', item.type.vars.value) }}</p> </div>
<div class="col-xs-11">
<div class="row">
<div class="col-md-6">
{{ form_row(item.type) }}
{# Filled with the selected type's description by plan.js. #}
<p class="help-block plan-item-type-help">{{ plan_item_type_description('allocation', item.type.vars.value) }}</p>
</div>
<div class="col-md-6">{{ form_row(item.name) }}</div>
</div>
</div> </div>
<div class="col-md-6">{{ form_row(item.name) }}</div>
</div> </div>
{{ form_row(item.description) }} {{ form_row(item.description) }}
<div class="row"> <div class="row">
+2 -2
View File
@@ -104,7 +104,7 @@ class ItemTypeProvider
/** /**
* Pictogram of a type (a Remix Icon class such as "ri-lightbulb-line"), or null when it has none or * Pictogram of a type (a Remix Icon class such as "ri-lightbulb-line"), or null when it has none or
* the key isn't a configured type. Only description item types have pictograms. * the key isn't a configured type.
*/ */
public function getIcon(string $kind, ?string $key): ?string public function getIcon(string $kind, ?string $key): ?string
{ {
@@ -154,7 +154,7 @@ class ItemTypeProvider
'descriptions' => self::texts($type['descriptions'] ?? []), 'descriptions' => self::texts($type['descriptions'] ?? []),
]; ];
// Pictogram (description item types only); kept only when it's one of the offered icons. // Pictogram; kept only when it's one of the offered icons.
if (isset($type['icon']) && is_string($type['icon']) && Pictograms::isValid($type['icon'])) { if (isset($type['icon']) && is_string($type['icon']) && Pictograms::isValid($type['icon'])) {
$entry['icon'] = $type['icon']; $entry['icon'] = $type['icon'];
} }
+3 -3
View File
@@ -5,9 +5,9 @@ declare(strict_types=1);
namespace MauticPlugin\PlanBundle\Service; namespace MauticPlugin\PlanBundle\Service;
/** /**
* Pictograms an administrator can give to a description item type (Settings > Configuration > Plan * Pictograms an administrator can give to an item type — description or allocation (Settings >
* Settings). They are icons of the Remix Icon set that Mautic ships ("ri-*" classes); each one was * Configuration > Plan Settings). They are icons of the Remix Icon set that Mautic ships ("ri-*"
* checked against Mautic 7's icon stylesheet. * classes); each one was checked against Mautic 7's icon stylesheet.
*/ */
final class Pictograms final class Pictograms
{ {
+2 -1
View File
@@ -118,6 +118,7 @@ mautic.plan.config.type.description="Description"
; Allocation items (the plan's Allocation tab). ; Allocation items (the plan's Allocation tab).
mautic.plan.allocation_item.field.type="Type" mautic.plan.allocation_item.field.type="Type"
mautic.plan.allocation_item.field.pictogram="Pictogram"
mautic.plan.allocation_item.field.name="Name" mautic.plan.allocation_item.field.name="Name"
mautic.plan.allocation_item.field.description="Description" mautic.plan.allocation_item.field.description="Description"
mautic.plan.allocation_item.field.planned_cost="Planned cost" mautic.plan.allocation_item.field.planned_cost="Planned cost"
@@ -140,7 +141,7 @@ mautic.plan.task.subtask_of="Sub-task of %parent%"
mautic.plan.task.subtasks="Number of sub-tasks" mautic.plan.task.subtasks="Number of sub-tasks"
mautic.plan.config.section.allocation_item_types="Allocation item types" mautic.plan.config.section.allocation_item_types="Allocation item types"
mautic.plan.config.section.allocation_item_types.help="The types offered for the cost lines of a plan's Allocation tab, in this order. Give each type a name and a description in each language; the default language is required. Users see their own language, or the default language when it's empty." mautic.plan.config.section.allocation_item_types.help="The types offered for the cost lines of a plan's Allocation tab, in this order. Give each type a name and a description in each language, and a pictogram; the default language is required. Users see their own language, or the default language when it's empty."
mautic.plan.description_item.field.pictogram="Pictogram" mautic.plan.description_item.field.pictogram="Pictogram"
mautic.plan.config.section.general="General" mautic.plan.config.section.general="General"
+3 -3
View File
@@ -120,11 +120,11 @@ Behaviour to know about:
### Typed items: description items and allocation items ### Typed items: description items and allocation items
- A **description item** (Description tab, `Entity/PlanDescriptionItem.php`) has a type and a description. More fields are planned. - A **description item** (Description tab, `Entity/PlanDescriptionItem.php`) has a type and a description. More fields are planned.
- An **allocation item** (Allocation tab, `Entity/PlanAllocationItem.php`, table `plan_allocation_items`) is a cost line: type, name (optional), description, planned cost and real cost. Costs are `DECIMAL(12,2)`, in the general currency. - An **allocation item** (Allocation tab, `Entity/PlanAllocationItem.php`, table `plan_allocation_items`) is a cost line: type (with its pictogram), name (optional), description, planned cost and real cost. Costs are `DECIMAL(12,2)`, in the general currency.
- Both kinds are edited inside the plan form, like objectives: add, remove, drag to reorder. They're saved and deleted with the plan. - Both kinds are edited inside the plan form, like objectives: add, remove, drag to reorder. They're saved and deleted with the plan.
- An administrator sets up each kind's types in **Settings > Configuration > Plan Settings**, in two sections. Each type has a name and a description for each language installed in Mautic, and the default language (the `locale` parameter) requires a name. Users see their own language, or the default language when theirs is empty. The order of the types is the order of the dropdown. - An administrator sets up each kind's types in **Settings > Configuration > Plan Settings**, in two sections. Each type has a name and a description for each language installed in Mautic, and the default language (the `locale` parameter) requires a name. Each type also has a pictogram. Users see their own language, or the default language when theirs is empty. The order of the types is the order of the dropdown.
- The types are stored in `config/local.php`, in the `plan_description_item_types` and `plan_allocation_item_types` parameters. Read them with `Service/ItemTypeProvider.php`, passing the kind (`description` or `allocation`). In templates, use the Twig functions `plan_item_type_name(kind, key)`, `plan_item_type_description(kind, key)` and `plan_item_type_icon(kind, key)`, plus `plan_currency()` and `plan_money(amount)` (`Twig/PlanExtension.php`). - The types are stored in `config/local.php`, in the `plan_description_item_types` and `plan_allocation_item_types` parameters. Read them with `Service/ItemTypeProvider.php`, passing the kind (`description` or `allocation`). In templates, use the Twig functions `plan_item_type_name(kind, key)`, `plan_item_type_description(kind, key)` and `plan_item_type_icon(kind, key)`, plus `plan_currency()` and `plan_money(amount)` (`Twig/PlanExtension.php`).
- **Description item types have a pictogram**, chosen by the administrator from a list of Remix Icons that Mautic ships (`Service/Pictograms.php`, each checked against Mautic 7's icon stylesheet), with a live preview. It's stored as `icon` in the type. On the plan form it appears next to the type dropdown when a type is chosen. On the detail page, the Description tab is a table with three columns: Pictogram, Type, Description. Allocation item types have no pictogram. - **Every item type has a pictogram**, chosen by the administrator from a list of Remix Icons that Mautic ships (`Service/Pictograms.php`, each checked against Mautic 7's icon stylesheet), with a live preview. It's stored as `icon` in the type. On the plan form it appears next to the type dropdown when a type is chosen. On the detail page, the Description tab is a table with three columns: Pictogram, Type, Description. The Allocation tab's cost lines list has the same Pictogram column, before Type.
- Each type has a hidden key, generated when it's created and never changed. Items store that key, so renaming a type renames it everywhere. - Each type has a hidden key, generated when it's created and never changed. Items store that key, so renaming a type renames it everywhere.
- A type that items use can't be removed: the configuration isn't saved, and the error lists the types and how many items use them (`EventListener/ConfigSubscriber.php`, on `CONFIG_PRE_SAVE`). - A type that items use can't be removed: the configuration isn't saved, and the error lists the types and how many items use them (`EventListener/ConfigSubscriber.php`, on `CONFIG_PRE_SAVE`).
- On the plan form, the selected type's description is shown under the type dropdown. When no types are set up, the tab says where to set them up. - On the plan form, the selected type's description is shown under the type dropdown. When no types are set up, the tab says where to set them up.