1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-24 14:30:56 +01:00

Allow users to specify whether Maniphest custom fields should be copied or not when creating a "Similar Task"

Summary:
When you create a new task, the UI gives you the option to create another similar task. We copy some fields, but not others.

Currently, the field list is hard-coded and excludes auxiliary fields. Instead, allow auxiliary fields to elect to be copied.

Test Plan:
  - Created a new task, verified appropriate field defuaults.
  - Created a new "similar" task, verified 'copy' fields copied in.
  - Edited an existing task, verified appropriate values.
  - Edited-with-errors, verified new values didn't get reverted in the form.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T1193

Differential Revision: https://secure.phabricator.com/D2410
This commit is contained in:
epriestley 2012-05-07 13:38:27 -07:00
parent 191f6d904f
commit 758db327d3
5 changed files with 54 additions and 12 deletions

View file

@ -91,6 +91,20 @@ abstract class ManiphestAuxiliaryFieldSpecification {
} }
/**
* When the user creates a task, the UI prompts them to "Create another
* similar task". This copies some fields (e.g., Owner and CCs) but not other
* fields (e.g., description). If this custom field should also be copied,
* return true from this method.
*
* @return bool True to copy the default value from the template task when
* creating a new similar task.
*/
public function shouldCopyWhenCreatingSimilarTask() {
return false;
}
/** /**
* Render a verb to appear in email titles when a transaction involving this * Render a verb to appear in email titles when a transaction involving this
* field occurs. Specifically, Maniphest emails are formatted like this: * field occurs. Specifically, Maniphest emails are formatted like this:

View file

@ -29,6 +29,7 @@ class ManiphestAuxiliaryFieldDefaultSpecification
private $checkboxLabel; private $checkboxLabel;
private $checkboxValue; private $checkboxValue;
private $error; private $error;
private $shouldCopyWhenCreatingSimilarTask;
const TYPE_SELECT = 'select'; const TYPE_SELECT = 'select';
const TYPE_STRING = 'string'; const TYPE_STRING = 'string';
@ -178,6 +179,7 @@ class ManiphestAuxiliaryFieldDefaultSpecification
return parent::renderForDetailView(); return parent::renderForDetailView();
} }
public function renderTransactionDescription( public function renderTransactionDescription(
ManiphestTransaction $transaction, ManiphestTransaction $transaction,
$target) { $target) {
@ -224,4 +226,13 @@ class ManiphestAuxiliaryFieldDefaultSpecification
return $desc; return $desc;
} }
public function setShouldCopyWhenCreatingSimilarTask($copy) {
$this->shouldCopyWhenCreatingSimilarTask = $copy;
return $this;
}
public function shouldCopyWhenCreatingSimilarTask() {
return $this->shouldCopyWhenCreatingSimilarTask;
}
} }

View file

@ -277,6 +277,15 @@ final class ManiphestTaskEditController extends ManiphestController {
->setURI($redirect_uri); ->setURI($redirect_uri);
} }
} else { } else {
if ($aux_fields) {
$task->loadAndAttachAuxiliaryAttributes();
foreach ($aux_fields as $aux_field) {
$aux_key = $aux_field->getAuxiliaryKey();
$value = $task->getAuxiliaryAttribute($aux_key);
$aux_field->setValueFromStorage($value);
}
}
if (!$task->getID()) { if (!$task->getID()) {
$task->setCCPHIDs(array( $task->setCCPHIDs(array(
$user->getPHID(), $user->getPHID(),
@ -287,6 +296,19 @@ final class ManiphestTaskEditController extends ManiphestController {
$task->setCCPHIDs($template_task->getCCPHIDs()); $task->setCCPHIDs($template_task->getCCPHIDs());
$task->setProjectPHIDs($template_task->getProjectPHIDs()); $task->setProjectPHIDs($template_task->getProjectPHIDs());
$task->setOwnerPHID($template_task->getOwnerPHID()); $task->setOwnerPHID($template_task->getOwnerPHID());
if ($aux_fields) {
$template_task->loadAndAttachAuxiliaryAttributes();
foreach ($aux_fields as $aux_field) {
if (!$aux_field->shouldCopyWhenCreatingSimilarTask()) {
continue;
}
$aux_key = $aux_field->getAuxiliaryKey();
$value = $template_task->getAuxiliaryAttribute($aux_key);
$aux_field->setValueFromStorage($value);
}
}
} }
} }
} }
@ -438,16 +460,6 @@ final class ManiphestTaskEditController extends ManiphestController {
->setDatasource('/typeahead/common/projects/')); ->setDatasource('/typeahead/common/projects/'));
if ($aux_fields) { if ($aux_fields) {
if (!$request->isFormPost()) {
$task->loadAndAttachAuxiliaryAttributes();
foreach ($aux_fields as $aux_field) {
$aux_key = $aux_field->getAuxiliaryKey();
$value = $task->getAuxiliaryAttribute($aux_key);
$aux_field->setValueFromStorage($value);
}
}
foreach ($aux_fields as $aux_field) { foreach ($aux_fields as $aux_field) {
if ($aux_field->isRequired() && if ($aux_field->isRequired() &&
!$aux_field->getError() && !$aux_field->getError() &&

View file

@ -1,7 +1,7 @@
<?php <?php
/* /*
* Copyright 2011 Facebook, Inc. * Copyright 2012 Facebook, Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -41,6 +41,7 @@ final class ManiphestDefaultTaskExtensions
$spec->setSelectOptions(idx($info, 'options')); $spec->setSelectOptions(idx($info, 'options'));
} }
$spec->setShouldCopyWhenCreatingSimilarTask(idx($info, 'copy'));
$specs[] = $spec; $specs[] = $spec;
} }

View file

@ -53,6 +53,10 @@ the field. These options are available:
show next to the checkbox. show next to the checkbox.
- **checkbox-value**: If type is set to **bool**, the value to show on - **checkbox-value**: If type is set to **bool**, the value to show on
the detail view when the checkbox is selected. the detail view when the checkbox is selected.
- **copy**: When a user creates a task, the UI gives them an option to
"Create Another Similar Task". Some fields from the original task are copied
into the new task, while others are not; by default, fields are not copied.
If you want this field to be copied, specify `true` for the `copy` property.
= Advanced Field Customization = = Advanced Field Customization =
@ -63,7 +67,7 @@ rendering logic, you can do so with a little work:
your specialized rendering, validation, storage, etc., logic. your specialized rendering, validation, storage, etc., logic.
- Extend @{class:ManiphestTaskExtensions} and return a list of fields which - Extend @{class:ManiphestTaskExtensions} and return a list of fields which
includes your custom field objects. includes your custom field objects.
- Set 'maniphest.custom-extensions' to the name of your new extensions - Set `maniphest.custom-extensions` to the name of your new extensions
class. class.
This is relatively advanced but should give you significant flexibility in This is relatively advanced but should give you significant flexibility in