mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-01 03:02:43 +01:00
468f785845
Summary: Ref T9132. Ref T9908. Fixes T5622. This allows you to copy some fields (projects, subscribers, custom fields, some per-application) from another object when creating a new object by passing the `?template=xyz` parameter. Extend "copy" support to work with all custom fields. Test Plan: - Created new pastes, packages, tasks using `?template=...` - Viewed new template docs page. Reviewers: chad Reviewed By: chad Maniphest Tasks: T5622, T9132, T9908 Differential Revision: https://secure.phabricator.com/D14699
185 lines
5.8 KiB
PHP
185 lines
5.8 KiB
PHP
<?php
|
|
|
|
final class ManiphestEditEngine
|
|
extends PhabricatorEditEngine {
|
|
|
|
const ENGINECONST = 'maniphest.task';
|
|
|
|
public function getEngineName() {
|
|
return pht('Maniphest Tasks');
|
|
}
|
|
|
|
public function getEngineApplicationClass() {
|
|
return 'PhabricatorManiphestApplication';
|
|
}
|
|
|
|
protected function newEditableObject() {
|
|
return ManiphestTask::initializeNewTask($this->getViewer());
|
|
}
|
|
|
|
protected function newObjectQuery() {
|
|
return id(new ManiphestTaskQuery());
|
|
}
|
|
|
|
protected function getObjectCreateTitleText($object) {
|
|
return pht('Create New Task');
|
|
}
|
|
|
|
protected function getObjectEditTitleText($object) {
|
|
return pht('Edit %s %s', $object->getMonogram(), $object->getTitle());
|
|
}
|
|
|
|
protected function getObjectEditShortText($object) {
|
|
return $object->getMonogram();
|
|
}
|
|
|
|
protected function getObjectCreateShortText() {
|
|
return pht('Create Task');
|
|
}
|
|
|
|
protected function getCommentViewHeaderText($object) {
|
|
$is_serious = PhabricatorEnv::getEnvConfig('phabricator.serious-business');
|
|
if (!$is_serious) {
|
|
return pht('Weigh In');
|
|
}
|
|
|
|
return parent::getCommentViewHeaderText($object);
|
|
}
|
|
|
|
protected function getObjectViewURI($object) {
|
|
return '/'.$object->getMonogram();
|
|
}
|
|
|
|
protected function buildCustomEditFields($object) {
|
|
$status_map = $this->getTaskStatusMap($object);
|
|
$priority_map = $this->getTaskPriorityMap($object);
|
|
|
|
if ($object->isClosed()) {
|
|
$priority_label = null;
|
|
$default_status = ManiphestTaskStatus::getDefaultStatus();
|
|
} else {
|
|
$priority_label = pht('Change Priority');
|
|
$default_status = ManiphestTaskStatus::getDefaultClosedStatus();
|
|
}
|
|
|
|
if ($object->getOwnerPHID()) {
|
|
$owner_value = array($object->getOwnerPHID());
|
|
} else {
|
|
$owner_value = array($this->getViewer()->getPHID());
|
|
}
|
|
|
|
return array(
|
|
id(new PhabricatorTextEditField())
|
|
->setKey('title')
|
|
->setLabel(pht('Title'))
|
|
->setDescription(pht('Name of the task.'))
|
|
->setTransactionType(ManiphestTransaction::TYPE_TITLE)
|
|
->setIsRequired(true)
|
|
->setValue($object->getTitle()),
|
|
id(new PhabricatorSelectEditField())
|
|
->setKey('status')
|
|
->setLabel(pht('Status'))
|
|
->setDescription(pht('Status of the task.'))
|
|
->setTransactionType(ManiphestTransaction::TYPE_STATUS)
|
|
->setIsCopyable(true)
|
|
->setValue($object->getStatus())
|
|
->setOptions($status_map)
|
|
->setCommentActionLabel(pht('Change Status'))
|
|
->setCommentActionDefaultValue($default_status),
|
|
id(new PhabricatorUsersEditField())
|
|
->setKey('owner')
|
|
->setAliases(array('ownerPHID', 'assign', 'assigned'))
|
|
->setLabel(pht('Assigned To'))
|
|
->setDescription(pht('User who is responsible for the task.'))
|
|
->setTransactionType(ManiphestTransaction::TYPE_OWNER)
|
|
->setIsCopyable(true)
|
|
->setSingleValue($object->getOwnerPHID())
|
|
->setCommentActionLabel(pht('Assign / Claim'))
|
|
->setCommentActionDefaultValue($owner_value),
|
|
id(new PhabricatorSelectEditField())
|
|
->setKey('priority')
|
|
->setLabel(pht('Priority'))
|
|
->setDescription(pht('Priority of the task.'))
|
|
->setTransactionType(ManiphestTransaction::TYPE_PRIORITY)
|
|
->setIsCopyable(true)
|
|
->setValue($object->getPriority())
|
|
->setOptions($priority_map)
|
|
->setCommentActionLabel($priority_label),
|
|
id(new PhabricatorRemarkupEditField())
|
|
->setKey('description')
|
|
->setLabel(pht('Description'))
|
|
->setDescription(pht('Task description.'))
|
|
->setTransactionType(ManiphestTransaction::TYPE_DESCRIPTION)
|
|
->setValue($object->getDescription()),
|
|
);
|
|
}
|
|
|
|
protected function getEditorURI() {
|
|
// TODO: Remove when cutting over.
|
|
return $this->getApplication()->getApplicationURI('editpro/');
|
|
}
|
|
|
|
private function getTaskStatusMap(ManiphestTask $task) {
|
|
$status_map = ManiphestTaskStatus::getTaskStatusMap();
|
|
|
|
$current_status = $task->getStatus();
|
|
|
|
// If the current status is something we don't recognize (maybe an older
|
|
// status which was deleted), put a dummy entry in the status map so that
|
|
// saving the form doesn't destroy any data by accident.
|
|
if (idx($status_map, $current_status) === null) {
|
|
$status_map[$current_status] = pht('<Unknown: %s>', $current_status);
|
|
}
|
|
|
|
$dup_status = ManiphestTaskStatus::getDuplicateStatus();
|
|
foreach ($status_map as $status => $status_name) {
|
|
// Always keep the task's current status.
|
|
if ($status == $current_status) {
|
|
continue;
|
|
}
|
|
|
|
// Don't allow tasks to be changed directly into "Closed, Duplicate"
|
|
// status. Instead, you have to merge them. See T4819.
|
|
if ($status == $dup_status) {
|
|
unset($status_map[$status]);
|
|
continue;
|
|
}
|
|
|
|
// Don't let new or existing tasks be moved into a disabled status.
|
|
if (ManiphestTaskStatus::isDisabledStatus($status)) {
|
|
unset($status_map[$status]);
|
|
continue;
|
|
}
|
|
}
|
|
|
|
return $status_map;
|
|
}
|
|
|
|
private function getTaskPriorityMap(ManiphestTask $task) {
|
|
$priority_map = ManiphestTaskPriority::getTaskPriorityMap();
|
|
$current_priority = $task->getPriority();
|
|
|
|
// If the current value isn't a legitimate one, put it in the dropdown
|
|
// anyway so saving the form doesn't cause a side effects.
|
|
if (idx($priority_map, $current_priority) === null) {
|
|
$priority_map[$current_priority] = pht(
|
|
'<Unknown: %s>',
|
|
$current_priority);
|
|
}
|
|
|
|
foreach ($priority_map as $priority => $priority_name) {
|
|
// Always keep the current priority.
|
|
if ($priority == $current_priority) {
|
|
continue;
|
|
}
|
|
|
|
if (ManiphestTaskPriority::isDisabledPriority($priority)) {
|
|
unset($priority_map[$priority]);
|
|
continue;
|
|
}
|
|
}
|
|
|
|
return $priority_map;
|
|
}
|
|
|
|
}
|