1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-10 00:42:41 +01:00

Enable prefilling of some Maniphest fields in task creation

Summary:
This came up in discussions with both ccheever and fratrik so I prototyped a
"send screenshot to maniphest" feature, which needs this:

https://www.facebook.com/video/video.php?v=892599296749

Test Plan:
Sent screenshot to maniphest.

Reviewed By: aran
Reviewers: jungejason, tuomaspelkonen, aran
CC: ccheever, fratrik, aran, epriestley
Differential Revision: 240
This commit is contained in:
epriestley 2011-05-06 09:17:55 -07:00
parent ebbd57771f
commit 7566f50d8f
2 changed files with 57 additions and 1 deletions

View file

@ -29,6 +29,8 @@ class ManiphestTaskEditController extends ManiphestController {
$request = $this->getRequest();
$user = $request->getUser();
$files = array();
if ($this->id) {
$task = id(new ManiphestTask())->load($this->id);
if (!$task) {
@ -38,6 +40,28 @@ class ManiphestTaskEditController extends ManiphestController {
$task = new ManiphestTask();
$task->setPriority(ManiphestTaskPriority::PRIORITY_TRIAGE);
$task->setAuthorPHID($user->getPHID());
// These allow task creation with defaults.
if (!$request->isFormPost()) {
$task->setTitle($request->getStr('title'));
}
$file_phids = $request->getArr('files', array());
if (!$file_phids) {
// Allow a single 'file' key instead, mostly since Mac OS X urlencodes
// square brackets in URLs when passed to 'open', so you can't 'open'
// a URL like '?files[]=xyz' and have PHP interpret it correctly.
$phid = $request->getStr('file');
if ($phid) {
$file_phids = array($phid);
}
}
if ($file_phids) {
$files = id(new PhabricatorFile())->loadAllWhere(
'phid IN (%Ls)',
$file_phids);
}
}
$errors = array();
@ -93,6 +117,14 @@ class ManiphestTaskEditController extends ManiphestController {
= $request->getArr('projects');
}
if ($files) {
$file_map = mpull($files, 'getPHID');
$file_map = array_fill_keys($file_map, true);
$changes[ManiphestTransactionType::TYPE_ATTACH] = array(
PhabricatorPHIDConstants::PHID_TYPE_FILE => $file_map,
);
}
$template = new ManiphestTransaction();
$template->setAuthorPHID($user->getPHID());
$transactions = array();
@ -172,6 +204,7 @@ class ManiphestTaskEditController extends ManiphestController {
$form = new AphrontFormView();
$form
->setUser($user)
->setAction($request->getRequestURI()->getPath())
->appendChild(
id(new AphrontFormTextAreaControl())
->setLabel('Title')
@ -203,7 +236,26 @@ class ManiphestTaskEditController extends ManiphestController {
->setLabel('Projects')
->setName('projects')
->setValue($projects_value)
->setDatasource('/typeahead/common/projects/'))
->setDatasource('/typeahead/common/projects/'));
if ($files) {
$file_display = array();
foreach ($files as $file) {
$file_display[] = phutil_escape_html($file->getName());
}
$file_display = implode('<br />', $file_display);
$form->appendChild(
id(new AphrontFormMarkupControl())
->setLabel('Files')
->setValue($file_display));
foreach ($files as $ii => $file) {
$form->addHiddenInput('files['.$ii.']', $file->getPHID());
}
}
$form
->appendChild(
id(new AphrontFormTextAreaControl())
->setLabel('Description')

View file

@ -8,6 +8,7 @@
phutil_require_module('phabricator', 'aphront/response/404');
phutil_require_module('phabricator', 'aphront/response/redirect');
phutil_require_module('phabricator', 'applications/files/storage/file');
phutil_require_module('phabricator', 'applications/maniphest/constants/priority');
phutil_require_module('phabricator', 'applications/maniphest/constants/status');
phutil_require_module('phabricator', 'applications/maniphest/constants/transactiontype');
@ -15,8 +16,10 @@ phutil_require_module('phabricator', 'applications/maniphest/controller/base');
phutil_require_module('phabricator', 'applications/maniphest/editor/transaction');
phutil_require_module('phabricator', 'applications/maniphest/storage/task');
phutil_require_module('phabricator', 'applications/maniphest/storage/transaction');
phutil_require_module('phabricator', 'applications/phid/constants');
phutil_require_module('phabricator', 'applications/phid/handle/data');
phutil_require_module('phabricator', 'view/form/base');
phutil_require_module('phabricator', 'view/form/control/markup');
phutil_require_module('phabricator', 'view/form/control/select');
phutil_require_module('phabricator', 'view/form/control/submit');
phutil_require_module('phabricator', 'view/form/control/textarea');
@ -24,6 +27,7 @@ phutil_require_module('phabricator', 'view/form/control/tokenizer');
phutil_require_module('phabricator', 'view/form/error');
phutil_require_module('phabricator', 'view/layout/panel');
phutil_require_module('phutil', 'markup');
phutil_require_module('phutil', 'utils');