improved Plan / Allocation items
This commit is contained in:
1 parent
f6684f3b2e
commit
8c8d7a6f95
12 files changed
+44
-25
No files matched your search
+2
-2
@@ -160,7 +160,7 @@ Mautic.planInitCollection = function ($editor) {
|
||||
});
|
||||
|
||||
// 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 () {
|
||||
var $option = mQuery(this).find('option:selected');
|
||||
var $row = mQuery(this).closest('.plan-collection-row');
|
||||
@@ -201,7 +201,7 @@ Mautic.planInitCollection = function ($editor) {
|
||||
$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 () {
|
||||
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);
|
||||
|
||||
+1
-1
@@ -90,7 +90,7 @@ return [
|
||||
|
||||
// Item types, edited in Settings > Configuration > Plan Settings. Read them through ItemTypeProvider.
|
||||
// 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_allocation_item_types' => [],
|
||||
],
|
||||
|
||||
@@ -16,7 +16,7 @@ use Symfony\Component\Validator\Constraints\NotBlank;
|
||||
/**
|
||||
* 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);
|
||||
* - 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>>
|
||||
*/
|
||||
@@ -46,7 +46,7 @@ class ConfigType extends AbstractType
|
||||
$builder->add($parameter, CollectionType::class, [
|
||||
'label' => false,
|
||||
'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_delete' => true,
|
||||
'prototype' => true,
|
||||
|
||||
@@ -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
|
||||
* 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
|
||||
* type doesn't affect the items that use it.
|
||||
@@ -70,7 +70,7 @@ class ItemTypeConfigType extends AbstractType
|
||||
$builder->add($names);
|
||||
$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']) {
|
||||
$builder->add('icon', ChoiceType::class, [
|
||||
'label' => 'mautic.plan.config.type.icon',
|
||||
@@ -96,8 +96,8 @@ class ItemTypeConfigType extends AbstractType
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
// True for description item types: adds the pictogram field.
|
||||
'with_icon' => false,
|
||||
// Adds the pictogram field; both kinds of item types have one.
|
||||
'with_icon' => true,
|
||||
]);
|
||||
$resolver->setAllowedTypes('with_icon', 'bool');
|
||||
}
|
||||
|
||||
@@ -18,8 +18,9 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
/**
|
||||
* 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
|
||||
* dropdown, hidden position kept in display order by Assets/js/plan.js).
|
||||
* real cost (both in the general currency). Works like PlanDescriptionItemType (type description shown
|
||||
* under the dropdown and its pictogram next to it, hidden position kept in display order by
|
||||
* Assets/js/plan.js).
|
||||
*
|
||||
* @extends AbstractType<PlanAllocationItem>
|
||||
*/
|
||||
@@ -40,7 +41,11 @@ class PlanAllocationItemType extends AbstractType
|
||||
'label_attr' => ['class' => 'control-label'],
|
||||
'attr' => ['class' => 'form-control plan-item-type'],
|
||||
'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',
|
||||
'required' => true,
|
||||
]);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{#
|
||||
# Settings > Configuration > Plan Settings: the general currency, the description item types (with a
|
||||
# pictogram) and the allocation item types. Adding and removing types, and the pictogram preview, are
|
||||
# handled by Assets/js/plan.js (delegated handlers on .plan-config-types).
|
||||
# Settings > Configuration > Plan Settings: the general currency, the description item types and the
|
||||
# allocation item types, each with a pictogram. Adding and removing types, and the pictogram preview,
|
||||
# are handled by Assets/js/plan.js (delegated handlers on .plan-config-types).
|
||||
#}
|
||||
|
||||
{% macro type_row(type) %}
|
||||
|
||||
@@ -235,6 +235,7 @@
|
||||
<table class="table table-hover plan-allocation-items-view">
|
||||
<thead>
|
||||
<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.name'|trans }}</th>
|
||||
<th class="visible-md visible-lg">{{ 'mautic.plan.allocation_item.field.description'|trans }}</th>
|
||||
@@ -246,7 +247,11 @@
|
||||
{% for allocationItem in allocationItems %}
|
||||
{% set typeName = plan_item_type_name('allocation', allocationItem.type) %}
|
||||
{% set typeDescription = plan_item_type_description('allocation', allocationItem.type) %}
|
||||
{% set typeIcon = plan_item_type_icon('allocation', allocationItem.type) %}
|
||||
<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 %}>
|
||||
{{ typeName ?? 'mautic.plan.description_item.type.unknown'|trans({'%key%': allocationItem.type}) }}
|
||||
</td>
|
||||
@@ -263,7 +268,7 @@
|
||||
</tbody>
|
||||
<tfoot>
|
||||
<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">
|
||||
{% if allocationTotals.planned is not null %}{{ plan_money(allocationTotals.planned) }} {{ plan_currency() }}{% endif %}
|
||||
</th>
|
||||
|
||||
@@ -66,6 +66,12 @@
|
||||
|
||||
{% macro allocation_item_row(item) %}
|
||||
{{ _self.row_start('mautic.plan.allocation_item.drag') }}
|
||||
<div class="row">
|
||||
{# The selected type's pictogram; updated by plan.js when the type changes. #}
|
||||
<div class="col-xs-1 text-center pt-lg">
|
||||
<i class="plan-item-type-icon {{ plan_item_type_icon('allocation', item.type.vars.value) }}" style="font-size: 28px;" aria-hidden="true"></i>
|
||||
</div>
|
||||
<div class="col-xs-11">
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
{{ form_row(item.type) }}
|
||||
@@ -74,6 +80,8 @@
|
||||
</div>
|
||||
<div class="col-md-6">{{ form_row(item.name) }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{{ form_row(item.description) }}
|
||||
<div class="row">
|
||||
<div class="col-md-6">{{ form_row(item.plannedCost) }}</div>
|
||||
|
||||
@@ -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
|
||||
* 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
|
||||
{
|
||||
@@ -154,7 +154,7 @@ class ItemTypeProvider
|
||||
'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'])) {
|
||||
$entry['icon'] = $type['icon'];
|
||||
}
|
||||
|
||||
@@ -5,9 +5,9 @@ declare(strict_types=1);
|
||||
namespace MauticPlugin\PlanBundle\Service;
|
||||
|
||||
/**
|
||||
* Pictograms an administrator can give to a description item type (Settings > Configuration > Plan
|
||||
* Settings). They are icons of the Remix Icon set that Mautic ships ("ri-*" classes); each one was
|
||||
* checked against Mautic 7's icon stylesheet.
|
||||
* Pictograms an administrator can give to an item type — description or allocation (Settings >
|
||||
* Configuration > Plan Settings). They are icons of the Remix Icon set that Mautic ships ("ri-*"
|
||||
* classes); each one was checked against Mautic 7's icon stylesheet.
|
||||
*/
|
||||
final class Pictograms
|
||||
{
|
||||
|
||||
@@ -118,6 +118,7 @@ mautic.plan.config.type.description="Description"
|
||||
|
||||
; Allocation items (the plan's Allocation tab).
|
||||
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.description="Description"
|
||||
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.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.config.section.general="General"
|
||||
|
||||
@@ -120,11 +120,11 @@ Behaviour to know about:
|
||||
### 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.
|
||||
- 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.
|
||||
- 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`).
|
||||
- **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.
|
||||
- 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.
|
||||
|
||||
Reference in new issue
Block a user