diff --git a/Assets/js/plan.js b/Assets/js/plan.js index e937b68..25934b6 100644 --- a/Assets/js/plan.js +++ b/Assets/js/plan.js @@ -10,7 +10,11 @@ * because that page isn't a "plan" page). */ Mautic.planTaskOnLoad = function (container) { - // The task form isn't a plan-collection; the type dropdown works the same way as in the plan form. + // The dependencies and RACI rows work like the plan form's collections. + mQuery(container).find('.plan-collection').each(function () { + Mautic.planInitCollection(mQuery(this)); + }); + // The type dropdown works the same way as in the plan form. mQuery(container).find('select.plan-item-type').each(function () { var $select = mQuery(this); @@ -26,6 +30,38 @@ Mautic.planTaskOnLoad = function (container) { $scope.find('.plan-item-type-icon').first().attr('class', 'plan-item-type-icon ' + ($option.attr('data-icon') || '')); }); }); + + // Kind rules: a milestone's end date is enslaved to its start date (copied and read-only); + // a phase has no status of its own (the field is left out server-side, nothing to do here). + mQuery(container).find('select[name$="[taskKind]"]').each(function () { + var $kind = mQuery(this); + + if ($kind.data('planKindInitialized')) { + return; + } + $kind.data('planKindInitialized', true); + + var enslave = function () { + var $form = mQuery(this).closest('form'); + var $start = $form.find('input[name$="[startDate]"]').first(); + var $end = $form.find('input[name$="[endDate]"]').first(); + var milestone = 'milestone' === mQuery(this).val(); + + $end.prop('disabled', milestone); + if (milestone) { + $end.val($start.val()); + // While the milestone is selected, the end follows the start. + $start.off('change.planKind').on('change.planKind', function () { + $end.val($start.val()); + }); + } else { + $start.off('change.planKind'); + } + }; + + $kind.on('change', enslave); + enslave.call($kind.get(0)); + }); }; Mautic.planOnLoad = function (container) { mQuery(container).find('.plan-collection').each(function () { diff --git a/Config/config.php b/Config/config.php index 79ca58e..7e382c1 100644 --- a/Config/config.php +++ b/Config/config.php @@ -5,7 +5,7 @@ declare(strict_types=1); return [ 'name' => 'Plan', 'description' => 'Plan plugin for Mautic.', - 'version' => '0.12.0', + 'version' => '0.13.0', 'author' => 'Experiential', 'routes' => [ diff --git a/Entity/Target.php b/Entity/Audience.php similarity index 100% rename from Entity/Target.php rename to Entity/Audience.php diff --git a/Entity/TargetPriority.php b/Entity/AudiencePriority.php similarity index 100% rename from Entity/TargetPriority.php rename to Entity/AudiencePriority.php diff --git a/Entity/TargetRepository.php b/Entity/AudienceRepository.php similarity index 100% rename from Entity/TargetRepository.php rename to Entity/AudienceRepository.php diff --git a/Entity/TargetType.php b/Entity/AudienceType.php similarity index 100% rename from Entity/TargetType.php rename to Entity/AudienceType.php diff --git a/Entity/DependencyType.php b/Entity/DependencyType.php new file mode 100644 index 0000000..a2da727 --- /dev/null +++ b/Entity/DependencyType.php @@ -0,0 +1,21 @@ +value; + } +} diff --git a/Entity/RaciRole.php b/Entity/RaciRole.php new file mode 100644 index 0000000..0ad555f --- /dev/null +++ b/Entity/RaciRole.php @@ -0,0 +1,31 @@ +value; + } + + public function getLabelClass(): string + { + return match ($this) { + self::Responsible => 'label-success', + self::Accountable => 'label-primary', + self::Consulted => 'label-info', + self::Informed => 'label-default', + }; + } +} diff --git a/Entity/Task.php b/Entity/Task.php index 69cac46..78532ad 100644 --- a/Entity/Task.php +++ b/Entity/Task.php @@ -11,16 +11,29 @@ use Doctrine\ORM\Mapping\ClassMetadata as OrmClassMetadata; use Mautic\CoreBundle\Doctrine\Mapping\ClassMetadataBuilder; use Mautic\CoreBundle\Entity\FormEntity; use MauticPlugin\PlanBundle\Validator\Constraints\EndDateAfterStartDate; -use MauticPlugin\PlanBundle\Validator\Constraints\ValidTaskParent; +use MauticPlugin\PlanBundle\Validator\Constraints\TaskDates; +use MauticPlugin\PlanBundle\Validator\Constraints\ValidTaskDependency; use Symfony\Component\Validator\Constraints\Length; use Symfony\Component\Validator\Constraints\NotBlank; +use Symfony\Component\Validator\Constraints\PositiveOrZero; +use Symfony\Component\Validator\Constraints\Range; use Symfony\Component\Validator\Mapping\ClassMetadata; /** - * A task of a plan. Every task belongs to exactly one plan, and may have a parent task in the same plan. + * A task of a plan. Every task belongs to exactly one plan. * - * Database rules: deleting the plan deletes its tasks (ON DELETE CASCADE); deleting a task makes its - * sub-tasks top-level (parent ON DELETE SET NULL). + * Kinds (taskKind): a regular task; a milestone, whose end date is enslaved to its start date; or a + * phase, which has no status of its own — it is a collection of tasks. + * + * Dependencies: a task may depend on other tasks (TaskDependency), with the relation type End2Start, + * End2End, Start2Start or Start2End. The former parent/child tree is replaced by this dependency + * graph. + * + * RACI: a task is assigned to the plan's stakeholders through TaskRaci rows (R/A/C/I), several + * stakeholders per role. + * + * Database rules: deleting the plan deletes its tasks (ON DELETE CASCADE); deleting a task deletes + * its dependencies and RACI rows (ON DELETE CASCADE). */ class Task extends FormEntity implements DateRangeInterface { @@ -28,6 +41,11 @@ class Task extends FormEntity implements DateRangeInterface public const TYPE_MAX_LENGTH = 64; + /** + * The planned work is whole hours, capped to keep the column sane. + */ + public const PLANNED_WORK_MAX = 100000; + private ?int $id = null; private ?Plan $plan = null; @@ -42,28 +60,39 @@ class Task extends FormEntity implements DateRangeInterface private ?string $description = null; - private ?Task $parent = null; - private ?\DateTime $startDate = null; private ?\DateTime $endDate = null; private TaskStatus $status = TaskStatus::New; + private ?TaskKind $taskKind = null; + + private ?string $definitionOfDone = null; + + private ?int $plannedWork = null; + /** - * @var Collection + * @var Collection */ - private Collection $children; + private Collection $dependencies; + + /** + * @var Collection + */ + private Collection $raci; public function __construct() { - $this->children = new ArrayCollection(); + $this->dependencies = new ArrayCollection(); + $this->raci = new ArrayCollection(); } public function __clone() { - $this->id = null; - $this->children = new ArrayCollection(); + $this->id = null; + $this->dependencies = new ArrayCollection(); + $this->raci = new ArrayCollection(); parent::__clone(); } @@ -95,20 +124,6 @@ class Task extends FormEntity implements DateRangeInterface ->nullable() ->build(); - $builder->createManyToOne('parent', self::class) - ->inversedBy('children') - ->addJoinColumn('parent_id', 'id', true, false, 'SET NULL') - ->build(); - - $builder->createOneToMany('children', self::class) - ->mappedBy('parent') - ->setOrderBy(['name' => 'ASC']) - ->fetchExtraLazy() - ->build(); - - $builder->addNamedField('startDate', Types::DATETIME_MUTABLE, 'start_date', true); - $builder->addNamedField('endDate', Types::DATETIME_MUTABLE, 'end_date', true); - // Mapped on the raw metadata: ClassMetadataBuilder::addField() forces every string to VARCHAR(191). $metadata->mapField([ 'fieldName' => 'status', @@ -118,6 +133,58 @@ class Task extends FormEntity implements DateRangeInterface 'options' => ['default' => TaskStatus::New->value], ]); $builder->addIndex(['status'], 'plan_task_status'); + + $metadata->mapField([ + 'fieldName' => 'taskKind', + 'columnName' => 'task_kind', + 'type' => Types::STRING, + 'length' => 20, + 'enumType' => TaskKind::class, + 'options' => ['default' => TaskKind::Task->value], + ]); + + // Dates are DATE (no time): tasks are planned at day granularity. + $metadata->mapField([ + 'fieldName' => 'startDate', + 'columnName' => 'start_date', + 'type' => Types::DATE_MUTABLE, + 'nullable' => true, + ]); + $metadata->mapField([ + 'fieldName' => 'endDate', + 'columnName' => 'end_date', + 'type' => Types::DATE_MUTABLE, + 'nullable' => true, + ]); + + $builder->createField('definitionOfDone', Types::TEXT) + ->columnName('definition_of_done') + ->nullable() + ->build(); + + $builder->createField('plannedWork', Types::INTEGER) + ->columnName('planned_work') + ->nullable() + ->option('unsigned', true) + ->build(); + + // Dependencies: outgoing edges (this task depends on those) and incoming edges (those depend + // on this task). Both sides are owned by the rows; deleting a task deletes its edges. + $builder->createOneToMany('dependencies', TaskDependency::class) + ->mappedBy('task') + ->setOrderBy(['position' => 'ASC']) + ->cascadePersist() + ->cascadeRemove() + ->orphanRemoval() + ->build(); + + $builder->createOneToMany('raci', TaskRaci::class) + ->mappedBy('task') + ->setOrderBy(['position' => 'ASC']) + ->cascadePersist() + ->cascadeRemove() + ->orphanRemoval() + ->build(); } public static function loadValidatorMetadata(ClassMetadata $metadata): void @@ -127,8 +194,11 @@ class Task extends FormEntity implements DateRangeInterface $metadata->addPropertyConstraint('plan', new NotBlank(message: 'mautic.plan.task.plan.required')); $metadata->addPropertyConstraint('type', new NotBlank(message: 'mautic.plan.task.type.required')); $metadata->addPropertyConstraint('type', new Length(max: self::TYPE_MAX_LENGTH)); - $metadata->addConstraint(new ValidTaskParent()); + $metadata->addPropertyConstraint('plannedWork', new PositiveOrZero(message: 'mautic.plan.task.planned_work.invalid')); + $metadata->addPropertyConstraint('plannedWork', new Range(notInRangeMessage: 'mautic.plan.task.planned_work.range', min: 0, max: self::PLANNED_WORK_MAX)); $metadata->addConstraint(new EndDateAfterStartDate()); + $metadata->addConstraint(new TaskDates()); + $metadata->addConstraint(new ValidTaskDependency()); } public function getId(): ?int @@ -190,19 +260,6 @@ class Task extends FormEntity implements DateRangeInterface return $this; } - public function getParent(): ?Task - { - return $this->parent; - } - - public function setParent(?Task $parent): static - { - $this->isChanged('parent', $parent); - $this->parent = $parent; - - return $this; - } - public function getStartDate(): ?\DateTime { return $this->startDate; @@ -245,37 +302,158 @@ class Task extends FormEntity implements DateRangeInterface return $this; } - /** - * @return Collection - */ - public function getChildren(): Collection + public function getTaskKind(): TaskKind { - return $this->children; + // Never null once stored (the column defaults to 'task'); a new entity reads as a plain task. + return $this->taskKind ?? TaskKind::Task; } - /** - * True when $task is this task or one of its ancestors. - */ - public function hasAncestorOrSelf(Task $task): bool + public function setTaskKind(TaskKind $taskKind): static { - $seen = []; - $current = $this; - - while (null !== $current) { - if ($current === $task || (null !== $task->getId() && $current->getId() === $task->getId())) { - return true; - } - - // Guard against a cycle that is already stored. - $key = null !== $current->getId() ? 'id'.$current->getId() : spl_object_id($current); - if (isset($seen[$key])) { - return false; - } - $seen[$key] = true; - - $current = $current->getParent(); + if ($taskKind !== $this->taskKind) { + // isChanged() can't log enums (they aren't stringable), so log the backing values. + $this->addChange('taskKind', [$this->taskKind?->value, $taskKind->value]); + $taskKind->enslaveDates($this); + $this->taskKind = $taskKind; } - return false; + return $this; + } + + public function getDefinitionOfDone(): ?string + { + return $this->definitionOfDone; + } + + public function setDefinitionOfDone(?string $definitionOfDone): static + { + $this->isChanged('definitionOfDone', $definitionOfDone); + $this->definitionOfDone = $definitionOfDone; + + return $this; + } + + public function getPlannedWork(): ?int + { + return $this->plannedWork; + } + + public function setPlannedWork(?int $plannedWork): static + { + $this->isChanged('plannedWork', $this->plannedWork); + $this->plannedWork = $plannedWork; + + return $this; + } + + /** + * @return Collection + */ + public function getDependencies(): Collection + { + return $this->dependencies; + } + + public function addDependency(TaskDependency $dependency): static + { + if (!$this->dependencies->contains($dependency)) { + $dependency->setTask($this); + $this->dependencies->add($dependency); + } + + return $this; + } + + public function removeDependency(TaskDependency $dependency): static + { + $this->dependencies->removeElement($dependency); + + return $this; + } + + /** + * @return Collection + */ + public function getRaci(): Collection + { + return $this->raci; + } + + /** + * Replaces the RACI rows. The form writes the whole collection: the inflector singularizes + * "raci" to "racus", so PropertyAccess can't find addRaci/removeRaci for the collection write + * and needs this setter. The back-reference is set here, so the rows persist with their task. + * + * @param iterable $raci + */ + public function setRaci(iterable $raci): static + { + $this->raci = new ArrayCollection(); + + foreach (is_array($raci) ? $raci : iterator_to_array($raci) as $row) { + $this->addRaci($row); + } + + return $this; + } + + public function addRaci(TaskRaci $raci): static + { + if (!$this->raci->contains($raci)) { + $raci->setTask($this); + $this->raci->add($raci); + } + + return $this; + } + + public function removeRaci(TaskRaci $raci): static + { + $this->raci->removeElement($raci); + + return $this; + } + + /** + * A textual summary of the dependencies, the transitively blocked tasks and the RACI roles — + * used by the tab tables and the list. Formerly the parent/children tree, removed in 0.13.0. + */ + public function getDependencySummary(): string + { + $parts = []; + + foreach ($this->dependencies as $dependency) { + if (null === $dependency->getDependsOn()) { + continue; + } + $parts[] = sprintf( + '%s (%s)', + $dependency->getDependsOn()->getName(), + $dependency->getDependencyType()->getLabelKey(), + ); + } + + return implode(', ', $parts); + } + + /** + * A textual summary of the task's RACI rows, for the tables. + */ + public function getRaciSummary(): string + { + $parts = []; + + foreach ($this->raci as $raci) { + $names = []; + foreach ($raci->getStakeholders() as $stakeholder) { + $names[] = $stakeholder->getName(); + } + if ([] === $names) { + continue; + } + $parts[] = sprintf('%s: %s', $raci->getRole()->getLabelKey(), implode(', ', $names)); + } + + return implode(' · ', $parts); } } diff --git a/Entity/TaskDependency.php b/Entity/TaskDependency.php new file mode 100644 index 0000000..635f0c3 --- /dev/null +++ b/Entity/TaskDependency.php @@ -0,0 +1,119 @@ +setTable(self::TABLE_NAME) + ->setCustomRepositoryClass(TaskDependencyRepository::class); + + $builder->addId(); + + $builder->createManyToOne('task', Task::class) + ->inversedBy('dependencies') + ->addJoinColumn('task_id', 'id', false, false, 'CASCADE') + ->build(); + + $builder->createManyToOne('dependsOn', Task::class) + ->addJoinColumn('depends_on_id', 'id', false, false, 'CASCADE') + ->build(); + + $metadata->mapField([ + 'fieldName' => 'dependencyType', + 'columnName' => 'dependency_type', + 'type' => Types::STRING, + 'length' => 20, + 'enumType' => DependencyType::class, + 'options' => ['default' => DependencyType::EndToStart->value], + ]); + + $builder->createField('position', Types::INTEGER) + ->option('default', 0) + ->build(); + } + + public function getId(): ?int + { + return $this->id; + } + + public function getTask(): ?Task + { + return $this->task; + } + + public function setTask(?Task $task): static + { + $this->task = $task; + + return $this; + } + + public function getDependsOn(): ?Task + { + return $this->dependsOn; + } + + public function setDependsOn(?Task $dependsOn): static + { + $this->dependsOn = $dependsOn; + + return $this; + } + + public function getDependencyType(): DependencyType + { + return $this->dependencyType; + } + + public function setDependencyType(DependencyType $dependencyType): static + { + $this->dependencyType = $dependencyType; + + return $this; + } + + public function getPosition(): int + { + return $this->position; + } + + public function setPosition(?int $position): static + { + $this->position = $position ?? 0; + + return $this; + } +} diff --git a/Entity/TaskDependencyRepository.php b/Entity/TaskDependencyRepository.php new file mode 100644 index 0000000..e091adf --- /dev/null +++ b/Entity/TaskDependencyRepository.php @@ -0,0 +1,18 @@ + + */ +class TaskDependencyRepository extends CommonRepository +{ + public function getTableAlias(): string + { + return 'td'; + } +} diff --git a/Entity/TaskKind.php b/Entity/TaskKind.php new file mode 100644 index 0000000..e99f7f7 --- /dev/null +++ b/Entity/TaskKind.php @@ -0,0 +1,40 @@ +value; + } + + /** + * True when this kind has no status of its own: a phase is a collection of tasks, its state comes + * from them. + */ + public function hasStatus(): bool + { + return self::Phase !== $this; + } + + /** + * Applies the kind's rules to the task's dates. A milestone's end date is enslaved to its start + * date: whatever is set, the end becomes the start. + */ + public function enslaveDates(Task $task): void + { + if (self::Milestone === $this && null !== $task->getStartDate()) { + $task->setEndDate(clone $task->getStartDate()); + } + } +} diff --git a/Entity/TaskRaci.php b/Entity/TaskRaci.php new file mode 100644 index 0000000..62f1103 --- /dev/null +++ b/Entity/TaskRaci.php @@ -0,0 +1,154 @@ + Stakeholder). + */ + public const JOIN_TABLE_NAME = 'plan_task_raci_stakeholders'; + + private ?int $id = null; + + private ?Task $task = null; + + private RaciRole $role = RaciRole::Responsible; + + /** + * @var Collection + */ + private Collection $stakeholders; + + /** + * Display order within the task's RACI list, from 0. + */ + private int $position = 0; + + public function __construct() + { + $this->stakeholders = new ArrayCollection(); + } + + public function __clone() + { + $this->id = null; + $this->task = null; + $this->stakeholders = new ArrayCollection(); + } + + public static function loadMetadata(OrmClassMetadata $metadata): void + { + $builder = new ClassMetadataBuilder($metadata); + + $builder->setTable(self::TABLE_NAME) + ->setCustomRepositoryClass(TaskRaciRepository::class); + + $builder->addId(); + + $builder->createManyToOne('task', Task::class) + ->inversedBy('raci') + ->addJoinColumn('task_id', 'id', false, false, 'CASCADE') + ->build(); + + $metadata->mapField([ + 'fieldName' => 'role', + 'type' => Types::STRING, + 'length' => 20, + 'enumType' => RaciRole::class, + 'options' => ['default' => RaciRole::Responsible->value], + ]); + + $builder->createManyToMany('stakeholders', Stakeholder::class) + ->setJoinTable(self::JOIN_TABLE_NAME) + ->addJoinColumn('raci_id', 'id', false, false, 'CASCADE') + ->addInverseJoinColumn('stakeholder_id', 'id', false, false, 'CASCADE') + ->build(); + + $builder->createField('position', Types::INTEGER) + ->option('default', 0) + ->build(); + } + + public function getId(): ?int + { + return $this->id; + } + + public function getTask(): ?Task + { + return $this->task; + } + + public function setTask(?Task $task): static + { + $this->task = $task; + + return $this; + } + + public function getRole(): RaciRole + { + return $this->role; + } + + public function setRole(RaciRole $role): static + { + $this->role = $role; + + return $this; + } + + /** + * @return Collection + */ + public function getStakeholders(): Collection + { + return $this->stakeholders; + } + + public function addStakeholder(Stakeholder $stakeholder): static + { + if (!$this->stakeholders->contains($stakeholder)) { + $this->stakeholders->add($stakeholder); + } + + return $this; + } + + public function removeStakeholder(Stakeholder $stakeholder): static + { + $this->stakeholders->removeElement($stakeholder); + + return $this; + } + + public function getPosition(): int + { + return $this->position; + } + + public function setPosition(?int $position): static + { + $this->position = $position ?? 0; + + return $this; + } +} diff --git a/Entity/TaskRaciRepository.php b/Entity/TaskRaciRepository.php new file mode 100644 index 0000000..34029ee --- /dev/null +++ b/Entity/TaskRaciRepository.php @@ -0,0 +1,18 @@ + + */ +class TaskRaciRepository extends CommonRepository +{ + public function getTableAlias(): string + { + return 'tr'; + } +} diff --git a/Entity/TaskRepository.php b/Entity/TaskRepository.php index b104a63..21ba5f5 100644 --- a/Entity/TaskRepository.php +++ b/Entity/TaskRepository.php @@ -19,7 +19,8 @@ class TaskRepository extends CommonRepository } /** - * Loads the plan and the parent with the tasks, so that the list doesn't query them one by one. + * Loads the plan, the dependencies (with their depends-on task) and the RACI rows (with their + * stakeholders) with the tasks, so that the list doesn't query them one by one. * * @param array $args */ @@ -28,21 +29,29 @@ class TaskRepository extends CommonRepository $alias = $this->getTableAlias(); $args['qb'] = $this->createQueryBuilder($alias) - ->select($alias, 'pl', 'pa') + ->select($alias, 'pl', 'dep', 'depTask', 'raci', 'raciStakeholder') ->leftJoin($alias.'.plan', 'pl') - ->leftJoin($alias.'.parent', 'pa'); + ->leftJoin($alias.'.dependencies', 'dep') + ->leftJoin('dep.dependsOn', 'depTask') + ->leftJoin($alias.'.raci', 'raci') + ->leftJoin('raci.stakeholders', 'raciStakeholder'); return parent::getEntities($args); } /** - * All tasks of a plan, ordered by name. + * All tasks of a plan, ordered by name, with their dependencies and RACI rows loaded. * * @return Task[] */ public function findByPlan(Plan $plan): array { return $this->createQueryBuilder('t') + ->select('t', 'dep', 'depTask', 'raci', 'raciStakeholder') + ->leftJoin('t.dependencies', 'dep') + ->leftJoin('dep.dependsOn', 'depTask') + ->leftJoin('t.raci', 'raci') + ->leftJoin('raci.stakeholders', 'raciStakeholder') ->where('t.plan = :plan') ->setParameter('plan', $plan) ->orderBy('t.name', 'ASC') diff --git a/Form/Type/TaskDependencyType.php b/Form/Type/TaskDependencyType.php new file mode 100644 index 0000000..1a49159 --- /dev/null +++ b/Form/Type/TaskDependencyType.php @@ -0,0 +1,87 @@ + + */ +class TaskDependencyType extends AbstractType +{ + public function buildForm(FormBuilderInterface $builder, array $options): void + { + /** @var Plan|null $plan */ + $plan = $options['plan']; + /** @var Task|null $task */ + $task = $options['task']; + + $builder->add('dependsOn', EntityType::class, [ + 'label' => 'mautic.plan.task.dependency.field.depends_on', + 'label_attr' => ['class' => 'control-label'], + 'attr' => ['class' => 'form-control'], + 'class' => Task::class, + 'choice_label' => 'name', + 'query_builder' => function (EntityRepository $er) use ($plan, $task) { + $qb = $er->createQueryBuilder('t') + ->orderBy('t.name', 'ASC'); + + if (null !== $plan) { + $qb->andWhere('t.plan = :plan')->setParameter('plan', $plan); + } + + if (null !== $task?->getId()) { + $qb->andWhere('t.id != :self')->setParameter('self', $task->getId()); + } + + return $qb; + }, + 'placeholder' => 'mautic.core.form.chooseone', + 'required' => true, + ]); + + $builder->add('dependencyType', EnumType::class, [ + 'label' => 'mautic.plan.task.dependency.field.type', + 'label_attr' => ['class' => 'control-label'], + 'attr' => ['class' => 'form-control'], + 'class' => DependencyType::class, + 'choice_label' => fn (DependencyType $type): string => $type->getLabelKey(), + ]); + + // The row's order in the collection, rewritten by plan.js after each change. + $builder->add('position', HiddenType::class, [ + 'attr' => ['class' => 'plan-row-position'], + ]); + } + + public function configureOptions(OptionsResolver $resolver): void + { + $resolver->setDefaults([ + 'data_class' => TaskDependency::class, + ]); + $resolver->setDefined(['plan', 'task']); + $resolver->setAllowedTypes('plan', [Plan::class, 'null']); + $resolver->setAllowedTypes('task', [Task::class, 'null']); + } + + public function getBlockPrefix(): string + { + return 'plan_task_dependency'; + } +} diff --git a/Form/Type/TaskRaciType.php b/Form/Type/TaskRaciType.php new file mode 100644 index 0000000..676c1b3 --- /dev/null +++ b/Form/Type/TaskRaciType.php @@ -0,0 +1,83 @@ + + */ +class TaskRaciType extends AbstractType +{ + public function buildForm(FormBuilderInterface $builder, array $options): void + { + /** @var Plan|null $plan */ + $plan = $options['plan']; + + $builder->add('role', EnumType::class, [ + 'label' => 'mautic.plan.task.raci.field.role', + 'label_attr' => ['class' => 'control-label'], + 'attr' => ['class' => 'form-control'], + 'class' => RaciRole::class, + 'choice_label' => fn (RaciRole $role): string => $role->getLabelKey(), + ]); + + $builder->add('stakeholders', EntityType::class, [ + 'label' => 'mautic.plan.task.raci.field.stakeholders', + 'label_attr' => ['class' => 'control-label'], + 'attr' => ['class' => 'form-control'], + 'class' => Stakeholder::class, + 'choice_label' => 'name', + 'query_builder' => function (EntityRepository $er) use ($plan) { + $qb = $er->createQueryBuilder('s') + ->orderBy('s.name', 'ASC'); + + // The plan's assigned stakeholders, when the plan is known. + if (null !== $plan) { + $qb->join('s.planLinks', 'l') + ->andWhere('l.plan = :plan') + ->setParameter('plan', $plan); + } + + return $qb; + }, + 'multiple' => true, + 'expanded' => false, + 'required' => false, + ]); + + // The row's order in the collection, rewritten by plan.js after each change. + $builder->add('position', HiddenType::class, [ + 'attr' => ['class' => 'plan-row-position'], + ]); + } + + public function configureOptions(OptionsResolver $resolver): void + { + $resolver->setDefaults([ + 'data_class' => TaskRaci::class, + ]); + $resolver->setDefined(['plan']); + $resolver->setAllowedTypes('plan', [Plan::class, 'null']); + } + + public function getBlockPrefix(): string + { + return 'plan_task_raci'; + } +} diff --git a/Form/Type/TaskType.php b/Form/Type/TaskType.php index 780ba5c..0cd19b0 100644 --- a/Form/Type/TaskType.php +++ b/Form/Type/TaskType.php @@ -6,22 +6,31 @@ namespace MauticPlugin\PlanBundle\Form\Type; use Doctrine\ORM\EntityRepository; use Mautic\CoreBundle\Form\EventListener\CleanFormSubscriber; -use Mautic\CoreBundle\Form\Type\DatePickerType; use Mautic\CoreBundle\Form\Type\FormButtonsType; use MauticPlugin\PlanBundle\Entity\Plan; use MauticPlugin\PlanBundle\Entity\Task; +use MauticPlugin\PlanBundle\Entity\TaskKind; use MauticPlugin\PlanBundle\Entity\TaskStatus; use MauticPlugin\PlanBundle\Service\ItemTypeProvider; use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\Type\ChoiceType; +use Symfony\Component\Form\Extension\Core\Type\CollectionType; +use Symfony\Component\Form\Extension\Core\Type\DateType; use Symfony\Component\Form\Extension\Core\Type\EnumType; +use Symfony\Component\Form\Extension\Core\Type\IntegerType; use Symfony\Component\Form\Extension\Core\Type\TextareaType; use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; /** + * The create and edit form of a task (Planning > Tasks). + * + * Kind rules: a milestone's end date is enslaved to its start date (the entity's setTaskKind copies + * the start onto the end, and the TaskDates validator keeps it in step); a phase has no status + * field — its state comes from its tasks. + * * @extends AbstractType */ class TaskType extends AbstractType @@ -41,6 +50,17 @@ class TaskType extends AbstractType $kind = ItemTypeProvider::KIND_TASK; + // The kind drives what the form offers: milestones enslave the end date, phases have no status. + $taskKind = $task->getTaskKind(); + + $builder->add('taskKind', EnumType::class, [ + 'label' => 'mautic.plan.task.field.kind', + 'label_attr' => ['class' => 'control-label'], + 'attr' => ['class' => 'form-control'], + 'class' => TaskKind::class, + 'choice_label' => fn (TaskKind $k): string => $k->getLabelKey(), + ]); + $builder->add('type', ChoiceType::class, [ 'label' => 'mautic.plan.task.field.type', 'label_attr' => ['class' => 'control-label'], @@ -79,51 +99,78 @@ class TaskType extends AbstractType 'required' => true, ]); - // Offers the tasks of the task's plan when it is known, otherwise all tasks grouped by plan. - // ValidTaskParent rejects a parent from another plan, and loops. - $builder->add('parent', EntityType::class, [ - 'label' => 'mautic.plan.task.field.parent', - 'label_attr' => ['class' => 'control-label'], - 'attr' => ['class' => 'form-control'], - 'class' => Task::class, - 'choice_label' => 'name', - 'group_by' => null === $plan ? fn (Task $t): string => (string) $t->getPlan()?->getName() : null, - 'query_builder' => function (EntityRepository $er) use ($task, $plan) { - $qb = $er->createQueryBuilder('t') - ->leftJoin('t.plan', 'p') - ->addSelect('p') - ->orderBy('p.name', 'ASC') - ->addOrderBy('t.name', 'ASC'); - - if (null !== $plan) { - $qb->andWhere('t.plan = :plan')->setParameter('plan', $plan); - } - - if (null !== $task->getId()) { - $qb->andWhere('t.id != :self')->setParameter('self', $task->getId()); - } - - return $qb; - }, - 'placeholder' => 'mautic.plan.task.parent.none', - 'required' => false, + // Simple dates, no time (the columns are DATE since 0.13.0). + $builder->add('startDate', DateType::class, [ + 'label' => 'mautic.plan.task.field.start_date', + 'widget' => 'single_text', + 'format' => 'yyyy-MM-dd', + 'html5' => true, + 'attr' => ['class' => 'form-control', 'data-toggle' => 'date'], ]); - // Dropdown in the order of the TaskStatus cases: New, To do, In progress, Done. - $builder->add('status', EnumType::class, [ - 'label' => 'mautic.plan.task.field.status', - 'label_attr' => ['class' => 'control-label'], - 'attr' => ['class' => 'form-control'], - 'class' => TaskStatus::class, - 'choice_label' => fn (TaskStatus $status): string => $status->getLabelKey(), + // End date: a milestone's is enslaved to the start date (same day), so it stays read-only. + $isMilestone = TaskKind::Milestone === $task->getTaskKind(); + $isPhase = TaskKind::Phase === $task->getTaskKind(); + $builder->add('endDate', DateType::class, [ + 'label' => 'mautic.plan.task.field.end_date', + 'widget' => 'single_text', + 'format' => 'yyyy-MM-dd', + 'html5' => true, + 'disabled' => $isMilestone, + 'attr' => ['class' => 'form-control', 'data-toggle' => 'date'], ]); - $builder->add('startDate', DatePickerType::class, [ - 'label' => 'mautic.plan.task.field.start_date', + // Status: a phase has none of its own — it comes from its tasks. + if (!$isPhase) { + $builder->add('status', EnumType::class, [ + 'label' => 'mautic.plan.task.field.status', + 'label_attr' => ['class' => 'control-label'], + 'attr' => ['class' => 'form-control'], + 'class' => TaskStatus::class, + 'choice_label' => fn (TaskStatus $status): string => $status->getLabelKey(), + ]); + } + + $builder->add('definitionOfDone', TextareaType::class, [ + 'label' => 'mautic.plan.task.field.definition_of_done', + 'label_attr' => ['class' => 'control-label'], + 'attr' => ['class' => 'form-control', 'rows' => 3], + 'required' => false, ]); - $builder->add('endDate', DatePickerType::class, [ - 'label' => 'mautic.plan.task.field.end_date', + $builder->add('plannedWork', IntegerType::class, [ + 'label' => 'mautic.plan.task.field.planned_work', + 'label_attr' => ['class' => 'control-label'], + 'attr' => ['class' => 'form-control', 'min' => 0, 'step' => 1, 'postaddon_text' => 'h'], + 'required' => false, + ]); + + // Dependencies: several edges, each another task of the plan with the relation type. The + // rows are added and removed by the form template; cycles and self-edges are refused by + // ValidTaskDependency. + $builder->add('dependencies', CollectionType::class, [ + 'label' => 'mautic.plan.task.field.dependencies', + 'entry_type' => TaskDependencyType::class, + 'entry_options' => ['label' => false, 'plan' => $plan, 'task' => $task], + 'allow_add' => true, + 'allow_delete' => true, + 'by_reference' => false, + 'prototype' => true, + 'prototype_name' => '__dependency__', + 'required' => false, + ]); + + // RACI: one row per role, several stakeholders per role, picked from the plan's stakeholders. + $builder->add('raci', CollectionType::class, [ + 'label' => 'mautic.plan.task.field.raci', + 'entry_type' => TaskRaciType::class, + 'entry_options' => ['label' => false, 'plan' => $plan], + 'allow_add' => true, + 'allow_delete' => true, + 'by_reference' => false, + 'prototype' => true, + 'prototype_name' => '__raci__', + 'required' => false, ]); $builder->add('buttons', FormButtonsType::class); diff --git a/Migrations/Version_0_13_0.php b/Migrations/Version_0_13_0.php new file mode 100644 index 0000000..ecd0ddb --- /dev/null +++ b/Migrations/Version_0_13_0.php @@ -0,0 +1,137 @@ +concatPrefix(Task::TABLE_NAME); + + if (!$schema->hasTable($tasks)) { + return false; + } + + $table = $schema->getTable($tasks); + + return !$table->hasColumn('task_kind') + || !$table->hasColumn('definition_of_done') + || !$table->hasColumn('planned_work') + || $table->hasColumn('parent_id') + || !$schema->hasTable($this->concatPrefix(TaskDependency::TABLE_NAME)) + || !$schema->hasTable($this->concatPrefix(TaskRaci::TABLE_NAME)) + || !$schema->hasTable($this->concatPrefix(TaskRaci::JOIN_TABLE_NAME)); + } + + protected function up(): void + { + $tasks = $this->concatPrefix(Task::TABLE_NAME); + $table = $this->entityManager->getConnection()->createSchemaManager()->introspectTable($tasks); + + // New columns. + if (!$table->hasColumn('task_kind')) { + $this->addSql(sprintf( + "ALTER TABLE %s ADD task_kind VARCHAR(20) NOT NULL DEFAULT '%s'", + $tasks, + \MauticPlugin\PlanBundle\Entity\TaskKind::Task->value + )); + } + if (!$table->hasColumn('definition_of_done')) { + $this->addSql("ALTER TABLE {$tasks} ADD definition_of_done LONGTEXT DEFAULT NULL"); + } + if (!$table->hasColumn('planned_work')) { + $this->addSql("ALTER TABLE {$tasks} ADD planned_work INT UNSIGNED DEFAULT NULL"); + } + + // Dates: DATETIME -> DATE, truncating the time part. + $start = $table->getColumn('start_date'); + $end = $table->getColumn('end_date'); + if ('datetime' === $start->getType()->getName()) { + $this->addSql("ALTER TABLE {$tasks} MODIFY start_date DATE DEFAULT NULL"); + $this->addSql("UPDATE {$tasks} SET start_date = DATE(start_date)"); + } + if ('datetime' === $end->getType()->getName()) { + $this->addSql("ALTER TABLE {$tasks} MODIFY end_date DATE DEFAULT NULL"); + $this->addSql("UPDATE {$tasks} SET end_date = DATE(end_date)"); + } + + // Drop the parent/child tree. + if ($table->hasColumn('parent_id')) { + $this->addSql("ALTER TABLE {$tasks} DROP COLUMN parent_id"); + } + + // New tables. Each is created when missing on its own, so a partial earlier run is repaired. + if (!$this->introspectSchema()->hasTable($this->concatPrefix(TaskDependency::TABLE_NAME))) { + foreach ($this->getCreateTableSqls(TaskDependency::class, TaskDependency::TABLE_NAME) as $sql) { + $this->addSql($sql); + } + } + if (!$this->introspectSchema()->hasTable($this->concatPrefix(TaskRaci::TABLE_NAME))) { + foreach ($this->getCreateTableSqls(TaskRaci::class, TaskRaci::TABLE_NAME) as $sql) { + $this->addSql($sql); + } + } + // The RACI join table comes with the TaskRaci entity's SQL (CREATE TABLE plan_task_raci_stakeholders), + // but it may be missing while plan_task_raci exists (a partial earlier run). + if (!$this->introspectSchema()->hasTable($this->concatPrefix(TaskRaci::JOIN_TABLE_NAME))) { + foreach ($this->getCreateTableSqls(TaskRaci::class, TaskRaci::JOIN_TABLE_NAME) as $sql) { + $this->addSql($sql); + } + } + } + + private function introspectSchema(): Schema + { + return $this->entityManager->getConnection()->createSchemaManager()->introspectSchema(); + } + + /** + * The CREATE TABLE statements of one of this migration's entities, from Doctrine's SchemaTool — + * the entity's table and, for TaskRaci, its join table plan_task_raci_stakeholders too. + * + * @param class-string $entityClass + * + * @return string[] + */ + private function getCreateTableSqls(string $entityClass, string $table): array + { + $schemaTool = new SchemaTool($this->entityManager); + $prefix = 'CREATE TABLE '; + $prefixes = [$prefix.$this->concatPrefix($table).' ', $prefix.$this->concatPrefix($table).'_']; + + $statements = []; + foreach ($schemaTool->getCreateSchemaSql([$this->entityManager->getClassMetadata($entityClass)]) as $sql) { + foreach ($prefixes as $candidate) { + if (str_starts_with($sql, $candidate)) { + $statements[] = $sql; + } + } + } + + if ([] === $statements) { + throw new \RuntimeException('SchemaTool returned no CREATE TABLE statement for '.$table.'.'); + } + + return $statements; + } +} diff --git a/Migrations/Version_0_4_0.php b/Migrations/Version_0_4_0.php index 6cb21f8..5100606 100644 --- a/Migrations/Version_0_4_0.php +++ b/Migrations/Version_0_4_0.php @@ -26,10 +26,12 @@ class Version_0_4_0 extends AbstractMigration { /** * Local column => [referenced table, ON DELETE action]. + * + * parent_id is gone since 0.13.0 (the parent/child tree was replaced by the dependency graph), + * so only plan_id is repaired here. */ private const FOREIGN_KEYS = [ - 'plan_id' => [Plan::TABLE_NAME, 'CASCADE'], - 'parent_id' => [Task::TABLE_NAME, 'SET NULL'], + 'plan_id' => [Plan::TABLE_NAME, 'CASCADE'], ]; protected function isApplicable(Schema $schema): bool @@ -40,7 +42,9 @@ class Version_0_4_0 extends AbstractMigration $tasks = $this->concatPrefix(Task::TABLE_NAME); - return !$schema->hasTable($tasks) || [] !== $this->getMissingForeignKeys($schema->getTable($tasks)); + $table = $schema->hasTable($tasks) ? $schema->getTable($tasks) : null; + + return null === $table || [] !== $this->getMissingForeignKeys($table); } protected function up(): void diff --git a/Model/TaskModel.php b/Model/TaskModel.php index 9e1460c..6612c4b 100644 --- a/Model/TaskModel.php +++ b/Model/TaskModel.php @@ -45,30 +45,18 @@ class TaskModel extends FormModel } /** - * The plan's tasks as a tree: top-level tasks first, each with its sub-tasks, ordered by name. + * The plan's tasks as rows for the plan's Tasks tab: the tasks ordered by name, each with its + * dependencies and RACI rows loaded. The former parent/child tree is gone; the tab lists the + * tasks flat, and the dependencies are shown per task. * * @return array */ public function getTaskTree(Plan $plan): array { - $byParent = []; - foreach ($this->getRepository()->findByPlan($plan) as $task) { - $byParent[$task->getParent()?->getId() ?? 0][] = $task; - } - $rows = []; - $seen = []; - $walk = function (int $parentId, int $depth) use (&$walk, &$rows, &$seen, $byParent): void { - foreach ($byParent[$parentId] ?? [] as $task) { - if (isset($seen[$task->getId()])) { - continue; - } - $seen[$task->getId()] = true; - $rows[] = ['task' => $task, 'depth' => $depth]; - $walk((int) $task->getId(), $depth + 1); - } - }; - $walk(0, 0); + foreach ($this->getRepository()->findByPlan($plan) as $task) { + $rows[] = ['task' => $task, 'depth' => 0]; + } return $rows; } diff --git a/Resources/views/Plan/_task_table.html.twig b/Resources/views/Plan/_task_table.html.twig index ceaae05..60e8945 100644 --- a/Resources/views/Plan/_task_table.html.twig +++ b/Resources/views/Plan/_task_table.html.twig @@ -50,8 +50,7 @@ {% for row in taskTree %} {% set task = row.task %} {% set canEdit = not readOnly and securityHasEntityAccess(taskPermissions['plan:tasks:editown']|default(false), taskPermissions['plan:tasks:editother']|default(false), task.createdBy) %} - {% set childCount = taskTree|filter(r => r.task.parent and r.task.parent.id == task.id)|length %} - + {% set taskTypeIcon = plan_item_type_icon('task', task.type) %} {% if taskTypeIcon %}{% endif %} @@ -60,19 +59,16 @@ {{ plan_item_type_name('task', task.type) ?? 'mautic.plan.description_item.type.unknown'|trans({'%key%': task.type}) }} - - {% if row.depth > 0 %} - - {% endif %} - {% if canEdit %} - {{ task.name }} - {% else %} - {{ task.name }} - {% endif %} - {% if childCount > 0 %} - ({{ childCount }}) - {% endif %} - + {% if canEdit %} + {{ task.name }} + {% else %} + {{ task.name }} + {% endif %} + {% if task.taskKind == constant('MauticPlugin\\PlanBundle\\Entity\\TaskKind::Milestone') %} + {{ 'mautic.plan.task.kind.milestone_short'|trans }} + {% elseif task.taskKind == constant('MauticPlugin\\PlanBundle\\Entity\\TaskKind::Phase') %} + {{ 'mautic.plan.task.kind.phase_short'|trans }} + {% endif %} {# Same 10-line clamp and read-more as the Description tab; URLs become links. #} @@ -81,9 +77,14 @@ 'id': 'plan-task-desc-' ~ task.id, }) }} - {{ task.startDate ? dateToFull(task.startDate) : '' }} - {{ task.endDate ? dateToFull(task.endDate) : '' }} - {{ task.status.labelKey|trans }} + {{ task.startDate ? task.startDate|date('Y-m-d') : '' }} + {{ task.endDate ? task.endDate|date('Y-m-d') : '' }} + + {# A phase has no status of its own — skip the column value. #} + {% if task.taskKind != constant('MauticPlugin\\PlanBundle\\Entity\\TaskKind::Phase') %} + {{ task.status.labelKey|trans }} + {% endif %} + {% endfor %} diff --git a/Resources/views/Task/form.html.twig b/Resources/views/Task/form.html.twig index 9f77734..eebe8f1 100644 --- a/Resources/views/Task/form.html.twig +++ b/Resources/views/Task/form.html.twig @@ -10,6 +10,57 @@ {% endif %} {% endblock %} +{# The dependencies and the RACI rows: the same editable, sortable rows as the plan form's + collections. Adding, removing and reordering is handled by Assets/js/plan.js through the + plan-collection-* classes. #} +{% macro dependency_row(dependency) %} +
  • +
    +
    + + + +
    +
    +
    +
    {{ form_row(dependency.dependsOn) }}
    +
    {{ form_row(dependency.dependencyType) }}
    +
    + {{ form_widget(dependency.position) }} +
    +
    + +
    +
    +
  • +{% endmacro %} + +{% macro raci_row(raci) %} +
  • +
    +
    + + + +
    +
    +
    +
    {{ form_row(raci.role) }}
    +
    {{ form_row(raci.stakeholders) }}
    +
    + {{ form_widget(raci.position) }} +
    +
    + +
    +
    +
  • +{% endmacro %} + {% block content %} {{ form_start(form) }}
    @@ -28,18 +79,70 @@
    {{ form_row(form.description) }} + {{ form_row(form.definitionOfDone) }}
    - {{ form_row(form.status) }} + {{ form_row(form.plan) }} + {{ form_row(form.taskKind) }} {{ form_row(form.startDate) }} {{ form_row(form.endDate) }} - {{ form_row(form.plan) }} - {{ form_row(form.parent) }} -

    {{ 'mautic.plan.task.parent.help'|trans }}

    + {% if form.status is defined %} + {{ form_row(form.status) }} + {% else %} + {# A phase has no status of its own: its state comes from its tasks. #} +

    {{ 'mautic.plan.task.kind.phase_status_note'|trans }}

    + {% endif %} + {{ form_row(form.plannedWork) }}
    - {{ form_end(form) }} +
    +
    + {# Dependencies: several edges, each another task of the plan with the relation type. #} +
    +

    {{ 'mautic.plan.task.field.dependencies'|trans }}

    + {{ form_errors(form.dependencies) }} +

    + {{ 'mautic.plan.task.dependency.empty'|trans }} +

    +
      + {% for dependency in form.dependencies %} + {{ _self.dependency_row(dependency) }} + {% endfor %} +
    + +
    + {% do form.dependencies.setRendered %} + + {# RACI: one row per role, several stakeholders per role, picked from the plan's. #} +
    +

    {{ 'mautic.plan.task.field.raci'|trans }}

    + {{ form_errors(form.raci) }} +

    + {{ 'mautic.plan.task.raci.empty'|trans }} +

    +
      + {% for raci in form.raci %} + {{ _self.raci_row(raci) }} + {% endfor %} +
    + +
    + {% do form.raci.setRendered %} +
    +
    + {{ form_row(form.buttons) }} + {# render_rest is false, so the hidden CSRF token must be rendered explicitly. #} + {{ form_widget(form._token) }} + {{ form_end(form, {'render_rest': false}) }} {% endblock %} diff --git a/Resources/views/Task/list.html.twig b/Resources/views/Task/list.html.twig index ab813e4..6b18bbb 100644 --- a/Resources/views/Task/list.html.twig +++ b/Resources/views/Task/list.html.twig @@ -117,9 +117,16 @@ {% set description = item.description|default('')|striptags|trim %} {{ (description|length > 120 ? description|slice(0, 120) ~ '…' : description)|plan_linkify }} - {{ item.startDate ? dateToFull(item.startDate) : '' }} - {{ item.endDate ? dateToFull(item.endDate) : '' }} - {{ item.status.labelKey|trans }} + {{ item.startDate ? item.startDate|date('Y-m-d') : '' }} + {{ item.endDate ? item.endDate|date('Y-m-d') : '' }} + + {# A phase has no status of its own: its state comes from its tasks. #} + {% if item.taskKind != constant('MauticPlugin\\PlanBundle\\Entity\\TaskKind::Phase') %} + {{ item.status.labelKey|trans }} + {% else %} + {{ 'mautic.plan.task.kind.phase_short'|trans }} + {% endif %} + {% endfor %} diff --git a/Translations/en_US/messages.ini b/Translations/en_US/messages.ini index f06b812..d24e5b2 100644 --- a/Translations/en_US/messages.ini +++ b/Translations/en_US/messages.ini @@ -119,28 +119,58 @@ mautic.plan.task.header.index="Tasks" mautic.plan.task.header.new="New task" mautic.plan.task.header.edit="Edit task - %name%" mautic.plan.task.error.notfound="No task with the ID %id% was found." -mautic.plan.task.form.confirmdelete="Delete the task, %name%? Its sub-tasks are kept and become top-level tasks." -mautic.plan.task.form.confirmbatchdelete="Delete the selected tasks? Their sub-tasks are kept and become top-level tasks." +mautic.plan.task.form.confirmdelete="Delete the task, %name%? Its dependencies on other tasks and its RACI assignments are removed too." +mautic.plan.task.form.confirmbatchdelete="Delete the selected tasks? Their dependencies on other tasks and their RACI assignments are removed too." mautic.plan.task.onboarding.heading="No tasks yet" mautic.plan.task.onboarding.subheading="Tasks break a plan down into work to do." -mautic.plan.task.onboarding.copy="Use the New button above, or Add task on a plan's Tasks tab. A task belongs to one plan and can be a sub-task of another task in the same plan." +mautic.plan.task.onboarding.copy="Use the New button above, or Add task on a plan's Tasks tab. A task belongs to one plan, may depend on other tasks of that plan (start to start, end to end and so on), and is assigned to the plan's stakeholders through RACI roles." mautic.plan.task.field.name="Name" mautic.plan.task.field.type="Type" mautic.plan.task.field.pictogram="Pictogram" mautic.plan.task.field.description="Description" mautic.plan.task.field.plan="Plan" -mautic.plan.task.field.parent="Parent task" +mautic.plan.task.field.kind="Kind" mautic.plan.task.field.start_date="Start date" mautic.plan.task.field.end_date="End date" mautic.plan.task.field.status="Status" +mautic.plan.task.field.definition_of_done="Definition of Done" +mautic.plan.task.field.planned_work="Planned work" +mautic.plan.task.field.dependencies="Dependencies" +mautic.plan.task.field.raci="RACI" mautic.plan.task.status.new="New" mautic.plan.task.status.todo="To do" mautic.plan.task.status.in_progress="In progress" mautic.plan.task.status.done="Done" -mautic.plan.task.parent.none="None (top-level task)" -mautic.plan.task.parent.help="A parent task must be in the same plan." +mautic.plan.task.kind.task="Task" +mautic.plan.task.kind.milestone="Milestone" +mautic.plan.task.kind.milestone_short="M" +mautic.plan.task.kind.phase="Phase" +mautic.plan.task.kind.phase_short="P" +mautic.plan.task.kind.task_short="T" +mautic.plan.task.kind.phase_status_note="A phase has no status of its own: its state comes from its tasks." +mautic.plan.task.kind.milestone_end_note="A milestone ends on its start date: the end date is the start date." +mautic.plan.task.planned_work_unit="hours" +mautic.plan.task.dependency.add="Add dependency" +mautic.plan.task.dependency.remove="Remove dependency" +mautic.plan.task.dependency.drag="Drag to reorder" +mautic.plan.task.dependency.empty="No dependencies yet." +mautic.plan.task.dependency.field.depends_on="Depends on" +mautic.plan.task.dependency.field.type="Relation" +mautic.plan.task.dependency_type.end_to_start="End to Start" +mautic.plan.task.dependency_type.end_to_end="End to End" +mautic.plan.task.dependency_type.start_to_start="Start to Start" +mautic.plan.task.dependency_type.start_to_end="Start to End" +mautic.plan.task.raci.add="Add RACI role" +mautic.plan.task.raci.remove="Remove" +mautic.plan.task.raci.drag="Drag to reorder" +mautic.plan.task.raci.empty="No RACI assignments yet." +mautic.plan.task.raci.field.role="Role" +mautic.plan.task.raci.field.stakeholders="Stakeholders" +mautic.plan.task.raci_role.responsible="Responsible" +mautic.plan.task.raci_role.accountable="Accountable" +mautic.plan.task.raci_role.consulted="Consulted" +mautic.plan.task.raci_role.informed="Informed" mautic.plan.task.add="Add task" -mautic.plan.task.save_plan_first="Save the plan first, then add tasks from its page." mautic.plan.task.manage_from_plan_page="Add and edit tasks from the plan's page, after saving." mautic.plan.field.name="Name" @@ -223,8 +253,7 @@ mautic.plan.header.total_real="Real: %amount% %currency%" mautic.plan.header.total_real.tooltip="Total real cost of the allocation items, within the planned cost" mautic.plan.header.total_real.over="Total real cost of the allocation items, above the planned cost" -mautic.plan.task.subtask_of="Sub-task of %parent%" -mautic.plan.task.subtasks="Number of sub-tasks" +mautic.plan.task.save_plan_first="Save the plan first, then add tasks from its page." 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 Allocations 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." diff --git a/Translations/en_US/validators.ini b/Translations/en_US/validators.ini index 74967a5..8f3f82b 100644 --- a/Translations/en_US/validators.ini +++ b/Translations/en_US/validators.ini @@ -10,8 +10,12 @@ mautic.plan.stakeholder.email.invalid="This email address is not valid." mautic.plan.stakeholder_link.stakeholder.required="Choose a stakeholder." mautic.plan.task.plan.required="A task must be assigned to a plan." mautic.plan.task.type.required="Choose a type." -mautic.plan.task.parent.other_plan="The parent task must be in the same plan." -mautic.plan.task.parent.loop="A task can't be its own parent, or a sub-task of one of its sub-tasks." +mautic.plan.task.planned_work.invalid="The planned work must be a whole number of hours, 0 or more." +mautic.plan.task.planned_work.range="The planned work must be a whole number of hours from 0 to %max%." +mautic.plan.task.milestone.end_enslaved="A milestone ends on its start date." +mautic.plan.task.dependency.self="A task can't depend on itself." +mautic.plan.task.dependency.cycle="A task can't depend on a task that (directly or not) depends on it." +mautic.plan.task.dependency.other_plan="A task can only depend on tasks of the same plan." mautic.plan.description_item.type.required="Choose a type." mautic.plan.config.type.name.required="A type needs a name in the default language." mautic.plan.config.type.in_use="These types are in use and can't be removed: %types%. Change the items or tasks that use them to another type first." diff --git a/Validator/Constraints/TaskDates.php b/Validator/Constraints/TaskDates.php new file mode 100644 index 0000000..e0e67b8 --- /dev/null +++ b/Validator/Constraints/TaskDates.php @@ -0,0 +1,25 @@ +getTaskKind() && null !== $task->getStartDate()) { + $task->setEndDate(clone $task->getStartDate()); + } + } +} diff --git a/Validator/Constraints/ValidTaskDependency.php b/Validator/Constraints/ValidTaskDependency.php new file mode 100644 index 0000000..26392f3 --- /dev/null +++ b/Validator/Constraints/ValidTaskDependency.php @@ -0,0 +1,22 @@ +getDependencies() as $dependency) { + $this->validateEdge($task, $dependency, $constraint); + } + } + + private function validateEdge(Task $task, TaskDependency $dependency, Constraint $constraint): void + { + $dependsOn = $dependency->getDependsOn(); + + if (null === $dependsOn) { + return; + } + + if ($dependsOn === $task || $dependsOn->getId() === $task->getId()) { + $this->context->buildViolation($constraint::SELF_REFERENCE)->atPath('dependencies')->addViolation(); + + return; + } + + if (null !== $task->getPlan() && null !== $dependsOn->getPlan() && $task->getPlan()->getId() !== $dependsOn->getPlan()->getId()) { + $this->context->buildViolation($constraint::OTHER_PLAN)->atPath('dependencies')->addViolation(); + + return; + } + + // Cycle check: walk the edges from the depends-on task; if we come back to this task, it's a cycle. + $seen = []; + $queue = [$dependsOn]; + + while (null !== ($current = array_shift($queue))) { + $key = $current->getId() ?? spl_object_id($current); + if ($key === ($task->getId() ?? spl_object_id($task))) { + $this->context->buildViolation($constraint::CYCLE)->atPath('dependencies')->addViolation(); + + return; + } + if (isset($seen[$key])) { + continue; + } + $seen[$key] = true; + + // Follow the edges of the current task, from the database (they may belong to other tasks). + $edges = $this->em->getRepository(TaskDependency::class)->findBy(['task' => $current]); + foreach ($edges as $edge) { + if (null !== $edge->getDependsOn()) { + $queue[] = $edge->getDependsOn(); + } + } + } + } +} diff --git a/Validator/Constraints/ValidTaskParent.php b/Validator/Constraints/ValidTaskParent.php deleted file mode 100644 index a904d84..0000000 --- a/Validator/Constraints/ValidTaskParent.php +++ /dev/null @@ -1,23 +0,0 @@ -getParent(); - - if (null === $parent) { - return; - } - - // The parent's ancestors include the task itself: the task is its own parent or a sub-task's child. - if ($parent->hasAncestorOrSelf($value)) { - $this->context->buildViolation($constraint->loopMessage) - ->atPath('parent') - ->addViolation(); - - return; - } - - $plan = $value->getPlan(); - $parentPlan = $parent->getPlan(); - - if (null !== $plan && null !== $parentPlan && $plan->getId() !== $parentPlan->getId()) { - $this->context->buildViolation($constraint->otherPlanMessage) - ->atPath('parent') - ->addViolation(); - } - } -} diff --git a/readme.md b/readme.md index f710084..89d6137 100644 --- a/readme.md +++ b/readme.md @@ -63,7 +63,7 @@ The plugin uses the IntegrationsBundle conventions: - `Controller/PlanController.php`: list, detail page, create, edit and delete (single and batch), built on core's `AbstractStandardFormController` - `Resources/views/Plan/list.html.twig`: the list. A plan's name opens its detail page. - `Resources/views/Plan/form.html.twig` and `details.html.twig`: the create/edit form and the detail page. Both have the same six tabs, from `_tabs.html.twig`: **Details**, **Description** (description items), **Objectives**, **Allocations** (planned budget, currency and allocation items), **Targets** and **Tasks**. -- `Resources/views/Plan/_task_table.html.twig`: the plan's tasks in the Tasks tab. It has the harmonized tab columns (pictogram, Type, Name, Description, Start date, End date, Status — no ID), in tree order: each task is followed by its sub-tasks, indented, and a task's name shows its number of sub-tasks. On the detail page it has an **Add task** button, links to each task and the filter/sort of the other tabs. On the plan form it is read-only (no links, no filter), so that following a link doesn't drop unsaved changes. +- `Resources/views/Plan/_task_table.html.twig`: the plan's tasks in the Tasks tab. It has the harmonized tab columns (pictogram, Type, Name with kind badge for milestones and phases, Description, Start date, End date, Status — no ID), one row per task, no tree: a phase's or milestone's badge marks it in the name column. On the detail page it has an **Add task** button, links to each task and the filter/sort of the other tabs. On the plan form it is read-only (no links, no filter), so that following a link doesn't drop unsaved changes. - `Controller/TaskController.php` and `Resources/views/Task/`: the task list, and the create/edit form (**Planning > Tasks**). `new?plan=ID` preselects the plan. After Save or Cancel, the user goes back to where the form was opened from. Opened from **Planning > Tasks**, that's the task list. Opened from a plan's Tasks tab, whose links carry `returnTo=plan`, that's the plan (its new plan, if the task was moved). The origin is stored in the session when the form is opened, because the form posts without the query string. - `Assets/js/plan.js`: on the form, the objectives editor (add, remove, drag-and-drop ordering), and after a failed save, marking the tabs that contain errors with an icon and opening the first one. Started by `Mautic.planOnLoad()`. @@ -155,11 +155,11 @@ Behaviour to know about: ### The Task object -- `Entity/Task.php` and `TaskRepository.php`: a task (table `plan_tasks`): type (with its pictogram), name, description, plan, optional parent task, optional start and end dates, and status +- `Entity/Task.php` and `TaskRepository.php`: a task (table `plan_tasks`): type (with its pictogram), name, description, plan, kind (task, milestone or phase), optional start and end dates (plain dates, no time), definition of done, planned work in whole hours, status (not for phases), dependencies (table `plan_task_dependencies`) and RACI assignments (table `plan_task_raci` with its `plan_task_raci_stakeholders` join table) - `Entity/TaskStatus.php`: the status enum. The order of its cases is the order of the dropdown: `new` (New, the default), `todo` (To do), `in_progress` (In progress), `done` (Done). Stored as `VARCHAR(20)`, indexed. -- `Model/TaskModel.php`: the model, available as `mautic.plan.model.task` or with `getModel('plan.task')`. `getTaskTree($plan)` returns a plan's tasks in tree order, with their depth. +- `Model/TaskModel.php`: the model, available as `mautic.plan.model.task` or with `getModel('plan.task')`. `getTaskTree($plan)` returns a plan's tasks as flat rows for the Tasks tab, ordered by name, with their dependencies and RACI rows fully loaded. - `Form/Type/TaskType.php`: the create and edit form -- `Validator/Constraints/ValidTaskParent.php`: the parent task must be in the same plan, and must not be the task itself or one of its sub-tasks +- `Validator/Constraints/ValidTaskDependency.php`: a dependency must point at another task of the same plan, and the dependency graph must not form a cycle (followed through the database, so a cycle crossing other tasks is caught too) Behaviour to know about: @@ -168,8 +168,10 @@ Behaviour to know about: - The task list (**Planning > Tasks**) shows these columns, in this order: ID, Pictogram, Type, Name, Description (first 120 characters), Start date, End date, Status. Every column except Pictogram and Description can be sorted. - A task's type is required. It's the key of a task type set up in **Settings > Configuration > Plan Settings** (parameter `plan_task_types`); on the task form the type's pictogram appears next to the dropdown and its description under it. The plan's Tasks tab shows the same Pictogram and Type columns as the task list, without the ID column. - Deleting a plan deletes its tasks (`plan_id` `ON DELETE CASCADE`). -- Deleting a task keeps its sub-tasks, which become top-level tasks (`parent_id` `ON DELETE SET NULL`). -- Tasks are edited on their own pages, not inside the plan form: a task can only be picked as a parent once it exists. +- Deleting a task removes its dependency edges and RACI rows too (`ON DELETE CASCADE`). +- Tasks are edited on their own pages, not inside the plan form: a task can only be picked as a dependency once it exists. +- Kinds: a **milestone**'s end date is enslaved to its start date (same day — the entity's `setTaskKind` copies it, the `TaskDates` validator keeps it in step, the form shows it disabled); a **phase** has no status of its own, it comes from its tasks (the form shows no status field). +- RACI: one row per role (Responsible, Accountable, Consulted, Informed), each with several stakeholders picked from the plan's stakeholders. After you change `Assets/js/plan.js`, run `php bin/console mautic:assets:generate` (in the dev environment, `./dev.sh console mautic:assets:generate`), because production mode bundles plugin scripts into `app.js`.