@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Remove old Phrequent propery rendering code and show "Time Spent" in higher precision

Summary:
See <https://discourse.phabricator-community.org/t/how-to-get-total-time-spent-on-a-task-in-minutes-or-hours/2241>.

Phrequent has two nearly-identical copies of its rendering code: one for old "property event" objects and one for newer "curtain" objects. In the upstream, both trackable object types (tasks and revisions) use curtains, so throw away the old code since it isn't reachable. Third-party trackable objects can update to the curtain UI, but it's unlikely they exist.

Render the remaining curtain UI with more precision, so we show "Time Spent: 2d, 11h, 49m" instead of "Time Spent: 2d".

Test Plan: {F6074404}

Reviewers: amckinley

Reviewed By: amckinley

Differential Revision: https://secure.phabricator.com/D19927

+11 -97
+11 -6
src/applications/phrequent/engineextension/PhrequentCurtainExtension.php
··· 29 29 30 30 $handles = $viewer->loadHandles(array_keys($event_groups)); 31 31 $status_view = new PHUIStatusListView(); 32 + $now = PhabricatorTime::getNow(); 32 33 33 34 foreach ($event_groups as $user_phid => $event_group) { 34 35 $item = new PHUIStatusItemView(); ··· 68 69 } 69 70 70 71 $block = new PhrequentTimeBlock($event_group); 71 - $item->setNote( 72 - phutil_format_relative_time( 73 - $block->getTimeSpentOnObject( 74 - $object->getPHID(), 75 - time()))); 72 + 73 + $duration = $block->getTimeSpentOnObject( 74 + $object->getPHID(), 75 + $now); 76 + 77 + $duration_display = phutil_format_relative_time_detailed( 78 + $duration, 79 + $levels = 3); 80 + 81 + $item->setNote($duration_display); 76 82 77 83 $status_view->addItem($item); 78 84 } 79 - 80 85 81 86 return $this->newPanel() 82 87 ->setHeaderText(pht('Time Spent'))
-91
src/applications/phrequent/event/PhrequentUIEventListener.php
··· 5 5 6 6 public function register() { 7 7 $this->listen(PhabricatorEventType::TYPE_UI_DIDRENDERACTIONS); 8 - $this->listen(PhabricatorEventType::TYPE_UI_WILLRENDERPROPERTIES); 9 8 } 10 9 11 10 public function handleEvent(PhutilEvent $event) { 12 11 switch ($event->getType()) { 13 12 case PhabricatorEventType::TYPE_UI_DIDRENDERACTIONS: 14 13 $this->handleActionEvent($event); 15 - break; 16 - case PhabricatorEventType::TYPE_UI_WILLRENDERPROPERTIES: 17 - $this->handlePropertyEvent($event); 18 14 break; 19 15 } 20 16 } ··· 59 55 } 60 56 61 57 $this->addActionMenuItems($event, $track_action); 62 - } 63 - 64 - private function handlePropertyEvent($ui_event) { 65 - $user = $ui_event->getUser(); 66 - $object = $ui_event->getValue('object'); 67 - 68 - if (!$object || !$object->getPHID()) { 69 - // No object, or the object has no PHID yet.. 70 - return; 71 - } 72 - 73 - if (!($object instanceof PhrequentTrackableInterface)) { 74 - // This object isn't a time trackable object. 75 - return; 76 - } 77 - 78 - if (!$this->canUseApplication($ui_event->getUser())) { 79 - return; 80 - } 81 - 82 - $events = id(new PhrequentUserTimeQuery()) 83 - ->setViewer($user) 84 - ->withObjectPHIDs(array($object->getPHID())) 85 - ->needPreemptingEvents(true) 86 - ->execute(); 87 - $event_groups = mgroup($events, 'getUserPHID'); 88 - 89 - if (!$events) { 90 - return; 91 - } 92 - 93 - $handles = id(new PhabricatorHandleQuery()) 94 - ->setViewer($user) 95 - ->withPHIDs(array_keys($event_groups)) 96 - ->execute(); 97 - 98 - $status_view = new PHUIStatusListView(); 99 - 100 - foreach ($event_groups as $user_phid => $event_group) { 101 - $item = new PHUIStatusItemView(); 102 - $item->setTarget($handles[$user_phid]->renderLink()); 103 - 104 - $state = 'stopped'; 105 - foreach ($event_group as $event) { 106 - if ($event->getDateEnded() === null) { 107 - if ($event->isPreempted()) { 108 - $state = 'suspended'; 109 - } else { 110 - $state = 'active'; 111 - break; 112 - } 113 - } 114 - } 115 - 116 - switch ($state) { 117 - case 'active': 118 - $item->setIcon( 119 - PHUIStatusItemView::ICON_CLOCK, 120 - 'green', 121 - pht('Working Now')); 122 - break; 123 - case 'suspended': 124 - $item->setIcon( 125 - PHUIStatusItemView::ICON_CLOCK, 126 - 'yellow', 127 - pht('Interrupted')); 128 - break; 129 - case 'stopped': 130 - $item->setIcon( 131 - PHUIStatusItemView::ICON_CLOCK, 132 - 'bluegrey', 133 - pht('Not Working Now')); 134 - break; 135 - } 136 - 137 - $block = new PhrequentTimeBlock($event_group); 138 - $item->setNote( 139 - phutil_format_relative_time( 140 - $block->getTimeSpentOnObject( 141 - $object->getPHID(), 142 - time()))); 143 - 144 - $status_view->addItem($item); 145 - } 146 - 147 - $view = $ui_event->getValue('view'); 148 - $view->addProperty(pht('Time Spent'), $status_view); 149 58 } 150 59 151 60 }