2015-12-03 23:32:40 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class ManiphestEditEngine
|
|
|
|
extends PhabricatorEditEngine {
|
|
|
|
|
|
|
|
const ENGINECONST = 'maniphest.task';
|
|
|
|
|
|
|
|
public function getEngineName() {
|
|
|
|
return pht('Maniphest Tasks');
|
|
|
|
}
|
|
|
|
|
2015-12-17 16:25:42 +01:00
|
|
|
public function getSummaryHeader() {
|
|
|
|
return pht('Configure Maniphest Task Forms');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getSummaryText() {
|
|
|
|
return pht('Configure how users create and edit tasks.');
|
|
|
|
}
|
|
|
|
|
2015-12-03 23:32:40 +01:00
|
|
|
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');
|
|
|
|
}
|
|
|
|
|
2015-12-09 11:13:36 +01:00
|
|
|
protected function getEditorURI() {
|
|
|
|
return $this->getApplication()->getApplicationURI('task/edit/');
|
|
|
|
}
|
|
|
|
|
2015-12-03 23:32:40 +01:00
|
|
|
protected function getCommentViewHeaderText($object) {
|
2015-12-12 02:03:10 +01:00
|
|
|
return pht('Weigh In');
|
|
|
|
}
|
2015-12-03 23:32:40 +01:00
|
|
|
|
2015-12-12 02:03:10 +01:00
|
|
|
protected function getCommentViewButtonText($object) {
|
|
|
|
return pht('Set Sail for Adventure');
|
2015-12-03 23:32:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function getObjectViewURI($object) {
|
|
|
|
return '/'.$object->getMonogram();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function buildCustomEditFields($object) {
|
2015-12-05 19:40:56 +01:00
|
|
|
$status_map = $this->getTaskStatusMap($object);
|
|
|
|
$priority_map = $this->getTaskPriorityMap($object);
|
2015-12-03 23:32:40 +01:00
|
|
|
|
2015-12-04 16:56:03 +01:00
|
|
|
if ($object->isClosed()) {
|
|
|
|
$default_status = ManiphestTaskStatus::getDefaultStatus();
|
|
|
|
} else {
|
|
|
|
$default_status = ManiphestTaskStatus::getDefaultClosedStatus();
|
|
|
|
}
|
|
|
|
|
2015-12-04 18:30:53 +01:00
|
|
|
if ($object->getOwnerPHID()) {
|
|
|
|
$owner_value = array($object->getOwnerPHID());
|
|
|
|
} else {
|
|
|
|
$owner_value = array($this->getViewer()->getPHID());
|
|
|
|
}
|
|
|
|
|
2016-02-09 00:24:52 +01:00
|
|
|
$fields = array(
|
2015-12-08 16:54:01 +01:00
|
|
|
id(new PhabricatorHandlesEditField())
|
|
|
|
->setKey('parent')
|
|
|
|
->setLabel(pht('Parent Task'))
|
|
|
|
->setDescription(pht('Task to make this a subtask of.'))
|
2015-12-16 14:09:21 +01:00
|
|
|
->setConduitDescription(pht('Create as a subtask of another task.'))
|
|
|
|
->setConduitTypeDescription(pht('PHID of the parent task.'))
|
2015-12-08 16:54:01 +01:00
|
|
|
->setAliases(array('parentPHID'))
|
|
|
|
->setTransactionType(ManiphestTransaction::TYPE_PARENT)
|
2015-12-09 01:30:49 +01:00
|
|
|
->setHandleParameterType(new ManiphestTaskListHTTPParameterType())
|
|
|
|
->setSingleValue(null)
|
|
|
|
->setIsReorderable(false)
|
|
|
|
->setIsDefaultable(false)
|
|
|
|
->setIsLockable(false),
|
|
|
|
id(new PhabricatorHandlesEditField())
|
|
|
|
->setKey('column')
|
|
|
|
->setLabel(pht('Column'))
|
|
|
|
->setDescription(pht('Workboard column to create this task into.'))
|
2015-12-16 14:09:21 +01:00
|
|
|
->setConduitDescription(pht('Create into a workboard column.'))
|
|
|
|
->setConduitTypeDescription(pht('PHID of workboard column.'))
|
2015-12-09 01:30:49 +01:00
|
|
|
->setAliases(array('columnPHID'))
|
|
|
|
->setTransactionType(ManiphestTransaction::TYPE_COLUMN)
|
|
|
|
->setSingleValue(null)
|
|
|
|
->setIsInvisible(true)
|
|
|
|
->setIsReorderable(false)
|
|
|
|
->setIsDefaultable(false)
|
|
|
|
->setIsLockable(false),
|
2015-12-03 23:32:40 +01:00
|
|
|
id(new PhabricatorTextEditField())
|
|
|
|
->setKey('title')
|
|
|
|
->setLabel(pht('Title'))
|
2015-12-04 15:37:36 +01:00
|
|
|
->setDescription(pht('Name of the task.'))
|
2015-12-16 14:09:21 +01:00
|
|
|
->setConduitDescription(pht('Rename the task.'))
|
|
|
|
->setConduitTypeDescription(pht('New task name.'))
|
2015-12-03 23:32:40 +01:00
|
|
|
->setTransactionType(ManiphestTransaction::TYPE_TITLE)
|
|
|
|
->setIsRequired(true)
|
|
|
|
->setValue($object->getTitle()),
|
|
|
|
id(new PhabricatorUsersEditField())
|
2015-12-04 16:21:50 +01:00
|
|
|
->setKey('owner')
|
|
|
|
->setAliases(array('ownerPHID', 'assign', 'assigned'))
|
2015-12-03 23:32:40 +01:00
|
|
|
->setLabel(pht('Assigned To'))
|
|
|
|
->setDescription(pht('User who is responsible for the task.'))
|
2015-12-16 14:09:21 +01:00
|
|
|
->setConduitDescription(pht('Reassign the task.'))
|
|
|
|
->setConduitTypeDescription(
|
|
|
|
pht('New task owner, or `null` to unassign.'))
|
2015-12-03 23:32:40 +01:00
|
|
|
->setTransactionType(ManiphestTransaction::TYPE_OWNER)
|
2015-12-07 20:37:51 +01:00
|
|
|
->setIsCopyable(true)
|
2015-12-04 18:30:53 +01:00
|
|
|
->setSingleValue($object->getOwnerPHID())
|
2015-12-07 19:38:32 +01:00
|
|
|
->setCommentActionLabel(pht('Assign / Claim'))
|
2015-12-15 15:57:32 +01:00
|
|
|
->setCommentActionValue($owner_value),
|
2015-12-08 23:29:53 +01:00
|
|
|
id(new PhabricatorSelectEditField())
|
|
|
|
->setKey('status')
|
|
|
|
->setLabel(pht('Status'))
|
|
|
|
->setDescription(pht('Status of the task.'))
|
2015-12-16 14:09:21 +01:00
|
|
|
->setConduitDescription(pht('Change the task status.'))
|
|
|
|
->setConduitTypeDescription(pht('New task status constant.'))
|
2015-12-08 23:29:53 +01:00
|
|
|
->setTransactionType(ManiphestTransaction::TYPE_STATUS)
|
|
|
|
->setIsCopyable(true)
|
|
|
|
->setValue($object->getStatus())
|
|
|
|
->setOptions($status_map)
|
|
|
|
->setCommentActionLabel(pht('Change Status'))
|
2015-12-15 15:57:32 +01:00
|
|
|
->setCommentActionValue($default_status),
|
2015-12-03 23:32:40 +01:00
|
|
|
id(new PhabricatorSelectEditField())
|
|
|
|
->setKey('priority')
|
|
|
|
->setLabel(pht('Priority'))
|
|
|
|
->setDescription(pht('Priority of the task.'))
|
2015-12-16 14:09:21 +01:00
|
|
|
->setConduitDescription(pht('Change the priority of the task.'))
|
|
|
|
->setConduitTypeDescription(pht('New task priority constant.'))
|
2015-12-03 23:32:40 +01:00
|
|
|
->setTransactionType(ManiphestTransaction::TYPE_PRIORITY)
|
2015-12-07 20:37:51 +01:00
|
|
|
->setIsCopyable(true)
|
2015-12-03 23:32:40 +01:00
|
|
|
->setValue($object->getPriority())
|
2015-12-04 16:56:03 +01:00
|
|
|
->setOptions($priority_map)
|
2015-12-23 22:18:32 +01:00
|
|
|
->setCommentActionLabel(pht('Change Priority')),
|
2015-12-03 23:32:40 +01:00
|
|
|
);
|
2016-02-09 00:24:52 +01:00
|
|
|
|
|
|
|
if (ManiphestTaskPoints::getIsEnabled()) {
|
|
|
|
$points_label = ManiphestTaskPoints::getPointsLabel();
|
|
|
|
$action_label = ManiphestTaskPoints::getPointsActionLabel();
|
|
|
|
|
|
|
|
$fields[] = id(new PhabricatorPointsEditField())
|
|
|
|
->setKey('points')
|
|
|
|
->setLabel($points_label)
|
|
|
|
->setDescription(pht('Point value of the task.'))
|
|
|
|
->setConduitDescription(pht('Change the task point value.'))
|
|
|
|
->setConduitTypeDescription(pht('New task point value.'))
|
|
|
|
->setTransactionType(ManiphestTransaction::TYPE_POINTS)
|
|
|
|
->setIsCopyable(true)
|
|
|
|
->setValue($object->getPoints())
|
|
|
|
->setCommentActionLabel($action_label);
|
|
|
|
}
|
|
|
|
|
|
|
|
$fields[] = id(new PhabricatorRemarkupEditField())
|
|
|
|
->setKey('description')
|
|
|
|
->setLabel(pht('Description'))
|
|
|
|
->setDescription(pht('Task description.'))
|
|
|
|
->setConduitDescription(pht('Update the task description.'))
|
|
|
|
->setConduitTypeDescription(pht('New task description.'))
|
|
|
|
->setTransactionType(ManiphestTransaction::TYPE_DESCRIPTION)
|
|
|
|
->setValue($object->getDescription())
|
|
|
|
->setPreviewPanel(
|
|
|
|
id(new PHUIRemarkupPreviewPanel())
|
|
|
|
->setHeader(pht('Description Preview')));
|
|
|
|
|
|
|
|
return $fields;
|
2015-12-03 23:32:40 +01:00
|
|
|
}
|
|
|
|
|
2015-12-05 19:40:56 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2015-12-08 23:29:53 +01:00
|
|
|
protected function newEditResponse(
|
|
|
|
AphrontRequest $request,
|
|
|
|
$object,
|
|
|
|
array $xactions) {
|
|
|
|
|
|
|
|
if ($request->isAjax()) {
|
|
|
|
// Reload the task to make sure we pick up the final task state.
|
2015-12-08 23:46:16 +01:00
|
|
|
$viewer = $this->getViewer();
|
2015-12-08 23:29:53 +01:00
|
|
|
$task = id(new ManiphestTaskQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->withIDs(array($object->getID()))
|
|
|
|
->needSubscriberPHIDs(true)
|
|
|
|
->needProjectPHIDs(true)
|
|
|
|
->executeOne();
|
|
|
|
|
2015-12-08 23:46:16 +01:00
|
|
|
switch ($request->getStr('responseType')) {
|
|
|
|
case 'card':
|
|
|
|
return $this->buildCardResponse($task);
|
|
|
|
default:
|
|
|
|
return $this->buildListResponse($task);
|
|
|
|
}
|
2015-12-08 23:29:53 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-12-09 01:30:49 +01:00
|
|
|
return parent::newEditResponse($request, $object, $xactions);
|
2015-12-08 23:29:53 +01:00
|
|
|
}
|
|
|
|
|
2015-12-08 23:46:16 +01:00
|
|
|
private function buildListResponse(ManiphestTask $task) {
|
|
|
|
$controller = $this->getController();
|
|
|
|
|
|
|
|
$payload = array(
|
|
|
|
'tasks' => $controller->renderSingleTask($task),
|
|
|
|
'data' => array(),
|
|
|
|
);
|
|
|
|
|
|
|
|
return id(new AphrontAjaxResponse())->setContent($payload);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function buildCardResponse(ManiphestTask $task) {
|
|
|
|
$controller = $this->getController();
|
|
|
|
$request = $controller->getRequest();
|
|
|
|
$viewer = $request->getViewer();
|
|
|
|
|
|
|
|
$column_phid = $request->getStr('columnPHID');
|
|
|
|
$order = $request->getStr('order');
|
|
|
|
|
|
|
|
$column = id(new PhabricatorProjectColumnQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->withPHIDs(array($column_phid))
|
|
|
|
->executeOne();
|
|
|
|
if (!$column) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
2016-02-02 18:53:18 +01:00
|
|
|
// If the workboard's project and all descendant projects have been removed
|
|
|
|
// from the card's project list, we are going to remove it from the board
|
|
|
|
// completely.
|
|
|
|
|
|
|
|
// TODO: If the user did something sneaky and changed a subproject, we'll
|
|
|
|
// currently leave the card where it was but should really move it to the
|
|
|
|
// proper new column.
|
|
|
|
|
2016-02-09 02:31:21 +01:00
|
|
|
$board_phid = $column->getProjectPHID();
|
|
|
|
|
2016-02-02 18:53:18 +01:00
|
|
|
$descendant_projects = id(new PhabricatorProjectQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->withAncestorProjectPHIDs(array($column->getProjectPHID()))
|
|
|
|
->execute();
|
|
|
|
$board_phids = mpull($descendant_projects, 'getPHID', 'getPHID');
|
2016-02-09 02:31:21 +01:00
|
|
|
$board_phids[$board_phid] = $board_phid;
|
2016-02-02 18:53:18 +01:00
|
|
|
|
2015-12-08 23:46:16 +01:00
|
|
|
$project_map = array_fuse($task->getProjectPHIDs());
|
2016-02-02 18:53:18 +01:00
|
|
|
$remove_card = !array_intersect_key($board_phids, $project_map);
|
2015-12-08 23:46:16 +01:00
|
|
|
|
2016-02-09 02:31:21 +01:00
|
|
|
// TODO: Maybe the caller should pass a list of visible task PHIDs so we
|
|
|
|
// know which ones we need to reorder? This is a HUGE overfetch.
|
|
|
|
$objects = id(new ManiphestTaskQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->withEdgeLogicPHIDs(
|
|
|
|
PhabricatorProjectObjectHasProjectEdgeType::EDGECONST,
|
|
|
|
PhabricatorQueryConstraint::OPERATOR_ANCESTOR,
|
|
|
|
array($board_phids))
|
2015-12-08 23:46:16 +01:00
|
|
|
->setViewer($viewer)
|
|
|
|
->execute();
|
2016-02-09 02:31:21 +01:00
|
|
|
$objects = mpull($objects, null, 'getPHID');
|
2015-12-08 23:46:16 +01:00
|
|
|
|
2016-02-09 02:31:21 +01:00
|
|
|
$layout_engine = id(new PhabricatorBoardLayoutEngine())
|
2015-12-08 23:46:16 +01:00
|
|
|
->setViewer($viewer)
|
2016-02-09 02:31:21 +01:00
|
|
|
->setBoardPHIDs(array($board_phid))
|
|
|
|
->setObjectPHIDs(array_keys($objects))
|
|
|
|
->executeLayout();
|
|
|
|
|
|
|
|
$positions = $layout_engine->getColumnObjectPositions(
|
|
|
|
$board_phid,
|
|
|
|
$column_phid);
|
|
|
|
|
|
|
|
$column_phids = $layout_engine->getColumnObjectPHIDs(
|
|
|
|
$board_phid,
|
|
|
|
$column_phid);
|
|
|
|
|
|
|
|
$column_tasks = array_select_keys($objects, $column_phids);
|
2015-12-08 23:46:16 +01:00
|
|
|
|
|
|
|
if ($order == PhabricatorProjectColumn::ORDER_NATURAL) {
|
|
|
|
// TODO: This is a little bit awkward, because PHP and JS use
|
|
|
|
// slightly different sort order parameters to achieve the same
|
|
|
|
// effect. It would be good to unify this a bit at some point.
|
|
|
|
$sort_map = array();
|
|
|
|
foreach ($positions as $position) {
|
|
|
|
$sort_map[$position->getObjectPHID()] = array(
|
|
|
|
-$position->getSequence(),
|
|
|
|
$position->getID(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$sort_map = mpull(
|
|
|
|
$column_tasks,
|
|
|
|
'getPrioritySortVector',
|
|
|
|
'getPHID');
|
|
|
|
}
|
|
|
|
|
|
|
|
$data = array(
|
|
|
|
'removeFromBoard' => $remove_card,
|
|
|
|
'sortMap' => $sort_map,
|
|
|
|
);
|
|
|
|
|
2016-02-06 22:02:13 +01:00
|
|
|
$rendering_engine = id(new PhabricatorBoardRenderingEngine())
|
2015-12-08 23:46:16 +01:00
|
|
|
->setViewer($viewer)
|
2016-02-06 22:02:13 +01:00
|
|
|
->setObjects(array($task))
|
|
|
|
->setExcludedProjectPHIDs($board_phids);
|
2015-12-08 23:46:16 +01:00
|
|
|
|
2016-02-06 22:02:13 +01:00
|
|
|
$card = $rendering_engine->renderCard($task->getPHID());
|
|
|
|
|
|
|
|
$item = $card->getItem();
|
|
|
|
$item->addClass('phui-workcard');
|
2016-02-02 15:26:42 +01:00
|
|
|
|
2015-12-08 23:46:16 +01:00
|
|
|
$payload = array(
|
2016-02-06 22:02:13 +01:00
|
|
|
'tasks' => $item,
|
2015-12-08 23:46:16 +01:00
|
|
|
'data' => $data,
|
|
|
|
);
|
|
|
|
|
2016-02-06 22:02:13 +01:00
|
|
|
return id(new AphrontAjaxResponse())
|
|
|
|
->setContent(
|
|
|
|
array(
|
|
|
|
'tasks' => $item,
|
|
|
|
'data' => $data,
|
|
|
|
));
|
2015-12-08 23:46:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-12-03 23:32:40 +01:00
|
|
|
}
|