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

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
This commit is contained in:
epriestley 2018-12-22 03:54:21 -08:00
parent 15df57f1c8
commit 10db27833b
2 changed files with 11 additions and 97 deletions

View file

@ -29,6 +29,7 @@ final class PhrequentCurtainExtension
$handles = $viewer->loadHandles(array_keys($event_groups)); $handles = $viewer->loadHandles(array_keys($event_groups));
$status_view = new PHUIStatusListView(); $status_view = new PHUIStatusListView();
$now = PhabricatorTime::getNow();
foreach ($event_groups as $user_phid => $event_group) { foreach ($event_groups as $user_phid => $event_group) {
$item = new PHUIStatusItemView(); $item = new PHUIStatusItemView();
@ -68,16 +69,20 @@ final class PhrequentCurtainExtension
} }
$block = new PhrequentTimeBlock($event_group); $block = new PhrequentTimeBlock($event_group);
$item->setNote(
phutil_format_relative_time( $duration = $block->getTimeSpentOnObject(
$block->getTimeSpentOnObject( $object->getPHID(),
$object->getPHID(), $now);
time())));
$duration_display = phutil_format_relative_time_detailed(
$duration,
$levels = 3);
$item->setNote($duration_display);
$status_view->addItem($item); $status_view->addItem($item);
} }
return $this->newPanel() return $this->newPanel()
->setHeaderText(pht('Time Spent')) ->setHeaderText(pht('Time Spent'))
->setOrder(40000) ->setOrder(40000)

View file

@ -5,7 +5,6 @@ final class PhrequentUIEventListener
public function register() { public function register() {
$this->listen(PhabricatorEventType::TYPE_UI_DIDRENDERACTIONS); $this->listen(PhabricatorEventType::TYPE_UI_DIDRENDERACTIONS);
$this->listen(PhabricatorEventType::TYPE_UI_WILLRENDERPROPERTIES);
} }
public function handleEvent(PhutilEvent $event) { public function handleEvent(PhutilEvent $event) {
@ -13,9 +12,6 @@ final class PhrequentUIEventListener
case PhabricatorEventType::TYPE_UI_DIDRENDERACTIONS: case PhabricatorEventType::TYPE_UI_DIDRENDERACTIONS:
$this->handleActionEvent($event); $this->handleActionEvent($event);
break; break;
case PhabricatorEventType::TYPE_UI_WILLRENDERPROPERTIES:
$this->handlePropertyEvent($event);
break;
} }
} }
@ -61,91 +57,4 @@ final class PhrequentUIEventListener
$this->addActionMenuItems($event, $track_action); $this->addActionMenuItems($event, $track_action);
} }
private function handlePropertyEvent($ui_event) {
$user = $ui_event->getUser();
$object = $ui_event->getValue('object');
if (!$object || !$object->getPHID()) {
// No object, or the object has no PHID yet..
return;
}
if (!($object instanceof PhrequentTrackableInterface)) {
// This object isn't a time trackable object.
return;
}
if (!$this->canUseApplication($ui_event->getUser())) {
return;
}
$events = id(new PhrequentUserTimeQuery())
->setViewer($user)
->withObjectPHIDs(array($object->getPHID()))
->needPreemptingEvents(true)
->execute();
$event_groups = mgroup($events, 'getUserPHID');
if (!$events) {
return;
}
$handles = id(new PhabricatorHandleQuery())
->setViewer($user)
->withPHIDs(array_keys($event_groups))
->execute();
$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);
}
$view = $ui_event->getValue('view');
$view->addProperty(pht('Time Spent'), $status_view);
}
} }