From ae0a21457467ca1ab8a5059cd1eedcfd6e5cf19e Mon Sep 17 00:00:00 2001 From: Bob Trahan Date: Tue, 6 Jan 2015 13:28:35 -0800 Subject: [PATCH] Workboards - on edit, remove a task if no longer associated with workboard Summary: Fixes T6179. This makes the interaction where users remove a task from a workboard much more pleasant. Test Plan: Loaded up workboard for "A Project". Edited tasks and if / when I removed "A Project" they disappeared on save. Reviewers: epriestley Reviewed By: epriestley Subscribers: Korvin, epriestley Maniphest Tasks: T6179 Differential Revision: https://secure.phabricator.com/D11259 --- .../controller/ManiphestTaskEditController.php | 14 +++++++++++++- .../projects/behavior-project-boards.js | 8 ++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/applications/maniphest/controller/ManiphestTaskEditController.php b/src/applications/maniphest/controller/ManiphestTaskEditController.php index ece0ca334d..4c5ae0634c 100644 --- a/src/applications/maniphest/controller/ManiphestTaskEditController.php +++ b/src/applications/maniphest/controller/ManiphestTaskEditController.php @@ -383,6 +383,17 @@ final class ManiphestTaskEditController extends ManiphestController { return new Aphront404Response(); } + // re-load projects for accuracy as they are not re-loaded via + // the editor + $project_phids = PhabricatorEdgeQuery::loadDestinationPHIDs( + $task->getPHID(), + PhabricatorProjectObjectHasProjectEdgeType::EDGECONST); + $task->attachProjectPHIDs($project_phids); + $remove_from_board = false; + if (!in_array($column->getProjectPHID(), $project_phids)) { + $remove_from_board = true; + } + $positions = id(new PhabricatorProjectColumnPositionQuery()) ->setViewer($user) ->withColumns(array($column)) @@ -397,7 +408,7 @@ final class ManiphestTaskEditController extends ManiphestController { 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 unify this a bit at some point. + // 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( @@ -414,6 +425,7 @@ final class ManiphestTaskEditController extends ManiphestController { $data = array( 'sortMap' => $sort_map, + 'removeFromBoard' => $remove_from_board, ); break; case 'task': diff --git a/webroot/rsrc/js/application/projects/behavior-project-boards.js b/webroot/rsrc/js/application/projects/behavior-project-boards.js index 4e9ca7ad70..3455b2fac1 100644 --- a/webroot/rsrc/js/application/projects/behavior-project-boards.js +++ b/webroot/rsrc/js/application/projects/behavior-project-boards.js @@ -204,6 +204,7 @@ JX.behavior('project-boards', function(config) { var new_data = JX.Stratcom.getData(new_card); var items = finditems(column); var edited = false; + var remove_index = null; for (var ii = 0; ii < items.length; ii++) { var item = items[ii]; @@ -212,6 +213,9 @@ JX.behavior('project-boards', function(config) { var phid = data.objectPHID; if (phid == new_data.objectPHID) { + if (r.data.removeFromBoard) { + remove_index = ii; + } items[ii] = new_card; data = new_data; edited = true; @@ -226,6 +230,10 @@ JX.behavior('project-boards', function(config) { new_data.sort = r.data.sortMap[new_data.objectPHID] || new_data.sort; } + if (remove_index !== null) { + items.splice(remove_index, 1); + } + items.sort(colsort); JX.DOM.setContent(column, items);