From d511308a79a58111c63d15e14416c23283616f32 Mon Sep 17 00:00:00 2001 From: epriestley Date: Thu, 10 Mar 2016 18:11:12 -0800 Subject: [PATCH] Add a Phrequent curtain extension Summary: Fixes T10546. Some day, decades from now, we can revisit this when we iterate on Phrequent. Just don't regress for no real reason in the meantime, since it's easy enough to keep it working in reasonable shape. Test Plan: {F1169096} Reviewers: chad Reviewed By: chad Maniphest Tasks: T10546 Differential Revision: https://secure.phabricator.com/D15461 --- src/__phutil_library_map__.php | 2 + .../PhrequentCurtainExtension.php | 87 +++++++++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 src/applications/phrequent/engineextension/PhrequentCurtainExtension.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 0d86575126..bfad24494a 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -3794,6 +3794,7 @@ phutil_register_library_map(array( 'PhragmentZIPController' => 'applications/phragment/controller/PhragmentZIPController.php', 'PhrequentConduitAPIMethod' => 'applications/phrequent/conduit/PhrequentConduitAPIMethod.php', 'PhrequentController' => 'applications/phrequent/controller/PhrequentController.php', + 'PhrequentCurtainExtension' => 'applications/phrequent/engineextension/PhrequentCurtainExtension.php', 'PhrequentDAO' => 'applications/phrequent/storage/PhrequentDAO.php', 'PhrequentListController' => 'applications/phrequent/controller/PhrequentListController.php', 'PhrequentPopConduitAPIMethod' => 'applications/phrequent/conduit/PhrequentPopConduitAPIMethod.php', @@ -8498,6 +8499,7 @@ phutil_register_library_map(array( 'PhragmentZIPController' => 'PhragmentController', 'PhrequentConduitAPIMethod' => 'ConduitAPIMethod', 'PhrequentController' => 'PhabricatorController', + 'PhrequentCurtainExtension' => 'PHUICurtainExtension', 'PhrequentDAO' => 'PhabricatorLiskDAO', 'PhrequentListController' => 'PhrequentController', 'PhrequentPopConduitAPIMethod' => 'PhrequentConduitAPIMethod', diff --git a/src/applications/phrequent/engineextension/PhrequentCurtainExtension.php b/src/applications/phrequent/engineextension/PhrequentCurtainExtension.php new file mode 100644 index 0000000000..25d0e424a6 --- /dev/null +++ b/src/applications/phrequent/engineextension/PhrequentCurtainExtension.php @@ -0,0 +1,87 @@ +getViewer(); + + $events = id(new PhrequentUserTimeQuery()) + ->setViewer($viewer) + ->withObjectPHIDs(array($object->getPHID())) + ->needPreemptingEvents(true) + ->execute(); + $event_groups = mgroup($events, 'getUserPHID'); + + if (!$events) { + return; + } + + $handles = $viewer->loadHandles(array_keys($event_groups)); + $status_view = new PHUIStatusListView(); + + foreach ($event_groups as $user_phid => $event_group) { + $item = new PHUIStatusItemView(); + $item->setTarget($handles[$user_phid]->renderLink()); + + $state = 'stopped'; + foreach ($event_group as $event) { + if ($event->getDateEnded() === null) { + if ($event->isPreempted()) { + $state = 'suspended'; + } else { + $state = 'active'; + break; + } + } + } + + switch ($state) { + case 'active': + $item->setIcon( + PHUIStatusItemView::ICON_CLOCK, + 'green', + pht('Working Now')); + break; + case 'suspended': + $item->setIcon( + PHUIStatusItemView::ICON_CLOCK, + 'yellow', + pht('Interrupted')); + break; + case 'stopped': + $item->setIcon( + PHUIStatusItemView::ICON_CLOCK, + 'bluegrey', + pht('Not Working Now')); + break; + } + + $block = new PhrequentTimeBlock($event_group); + $item->setNote( + phutil_format_relative_time( + $block->getTimeSpentOnObject( + $object->getPHID(), + time()))); + + $status_view->addItem($item); + } + + + return $this->newPanel() + ->setHeaderText(pht('Time Spent')) + ->setOrder(40000) + ->appendChild($status_view); + } + +}