From 7566f50d8fa46ca10312ff8cea7ee1fc6cc8eb2f Mon Sep 17 00:00:00 2001 From: epriestley Date: Fri, 6 May 2011 09:17:55 -0700 Subject: [PATCH] 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 --- .../taskedit/ManiphestTaskEditController.php | 54 ++++++++++++++++++- .../controller/taskedit/__init__.php | 4 ++ 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/src/applications/maniphest/controller/taskedit/ManiphestTaskEditController.php b/src/applications/maniphest/controller/taskedit/ManiphestTaskEditController.php index a948f609f5..bcf43ef7a3 100644 --- a/src/applications/maniphest/controller/taskedit/ManiphestTaskEditController.php +++ b/src/applications/maniphest/controller/taskedit/ManiphestTaskEditController.php @@ -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('
', $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') diff --git a/src/applications/maniphest/controller/taskedit/__init__.php b/src/applications/maniphest/controller/taskedit/__init__.php index e463b29eb0..69d1be5b3f 100644 --- a/src/applications/maniphest/controller/taskedit/__init__.php +++ b/src/applications/maniphest/controller/taskedit/__init__.php @@ -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');