diff --git a/src/__celerity_resource_map__.php b/src/__celerity_resource_map__.php index ce9378af48..71ca1d216a 100644 --- a/src/__celerity_resource_map__.php +++ b/src/__celerity_resource_map__.php @@ -448,6 +448,20 @@ celerity_register_resource_map(array( 'disk' => '/rsrc/image/menu_texture.png', 'type' => 'png', ), + '/rsrc/image/phrequent_active.png' => + array( + 'hash' => '716cddc08630eaa33934b2008723cac0', + 'uri' => '/res/716cddc0/rsrc/image/phrequent_active.png', + 'disk' => '/rsrc/image/phrequent_active.png', + 'type' => 'png', + ), + '/rsrc/image/phrequent_inactive.png' => + array( + 'hash' => 'f9099683873c01c5de1dc6650bd668fe', + 'uri' => '/res/f9099683/rsrc/image/phrequent_inactive.png', + 'disk' => '/rsrc/image/phrequent_inactive.png', + 'type' => 'png', + ), '/rsrc/image/search.png' => array( 'hash' => 'ff7da044e6f923b8f569dec11f97e5e5', @@ -3439,6 +3453,15 @@ celerity_register_resource_map(array( ), 'disk' => '/rsrc/css/application/pholio/pholio-inline-comments.css', ), + 'phrequent-css' => + array( + 'uri' => '/res/8fc8f63c/rsrc/css/application/phrequent/phrequent.css', + 'type' => 'css', + 'requires' => + array( + ), + 'disk' => '/rsrc/css/application/phrequent/phrequent.css', + ), 'phriction-document-css' => array( 'uri' => '/res/e71e4a67/rsrc/css/application/phriction/phriction-document-css.css', diff --git a/src/applications/phrequent/controller/PhrequentTrackController.php b/src/applications/phrequent/controller/PhrequentTrackController.php index 5c8c1c5f52..6aec035c60 100644 --- a/src/applications/phrequent/controller/PhrequentTrackController.php +++ b/src/applications/phrequent/controller/PhrequentTrackController.php @@ -1,7 +1,7 @@ isStoppingTracking()) { $this->stopTracking($user, $this->phid); } + return id(new AphrontRedirectResponse()); } diff --git a/src/applications/phrequent/event/PhrequentUIEventListener.php b/src/applications/phrequent/event/PhrequentUIEventListener.php index ed43ab3caf..3f563c03ad 100644 --- a/src/applications/phrequent/event/PhrequentUIEventListener.php +++ b/src/applications/phrequent/event/PhrequentUIEventListener.php @@ -38,16 +38,24 @@ final class PhrequentUIEventListener $object->getPHID()); if (!$tracking) { $track_action = id(new PhabricatorActionView()) - ->setName(pht('Track Time')) - ->setIcon('history') - ->setWorkflow(true) - ->setHref('/phrequent/track/start/'.$object->getPHID().'/'); + ->setUser($user) + ->setName(pht('Start Tracking Time')) + ->setIcon('history') + ->setWorkflow(true) + ->setRenderAsForm(true) + ->setHref('/phrequent/track/start/'.$object->getPHID().'/'); } else { $track_action = id(new PhabricatorActionView()) - ->setName(pht('Stop Tracking')) - ->setIcon('history') - ->setWorkflow(true) - ->setHref('/phrequent/track/stop/'.$object->getPHID().'/'); + ->setUser($user) + ->setName(pht('Stop Tracking Time')) + ->setIcon('history') + ->setWorkflow(true) + ->setRenderAsForm(true) + ->setHref('/phrequent/track/stop/'.$object->getPHID().'/'); + } + + if (!$user->isLoggedIn()) { + $track_action->setDisabled(true); } $actions = $event->getValue('actions'); @@ -69,13 +77,51 @@ final class PhrequentUIEventListener return; } + $depth = false; + + $stack = PhrequentUserTimeQuery::loadUserStack($user); + if ($stack) { + $stack = array_values($stack); + for ($ii = 0; $ii < count($stack); $ii++) { + if ($stack[$ii]->getObjectPHID() == $object->getPHID()) { + $depth = ($ii + 1); + break; + } + } + } + $time_spent = PhrequentUserTimeQuery::getTotalTimeSpentOnObject( $object->getPHID()); + + if (!$depth && !$time_spent) { + return; + } + + require_celerity_resource('phrequent-css'); + + $property = array(); + if ($depth == 1) { + $property[] = phutil_tag( + 'div', + array( + 'class' => 'phrequent-tracking-property phrequent-active', + ), + pht('Currently Tracking')); + } else if ($depth > 1) { + $property[] = phutil_tag( + 'div', + array( + 'class' => 'phrequent-tracking-property phrequent-on-stack', + ), + pht('On Stack')); + } + + if ($time_spent) { + $property[] = phabricator_format_relative_time_detailed($time_spent); + } + $view = $event->getValue('view'); - $view->addProperty( - pht('Time Spent'), - $time_spent == 0 ? 'none' : - phabricator_format_relative_time_detailed($time_spent)); + $view->addProperty(pht('Time Spent'), $property); } } diff --git a/src/applications/phrequent/query/PhrequentUserTimeQuery.php b/src/applications/phrequent/query/PhrequentUserTimeQuery.php index b4660a60b6..c659b9556b 100644 --- a/src/applications/phrequent/query/PhrequentUserTimeQuery.php +++ b/src/applications/phrequent/query/PhrequentUserTimeQuery.php @@ -114,6 +114,17 @@ final class PhrequentUserTimeQuery extends PhabricatorOffsetPagedQuery { return $count['N'] > 0; } + public static function loadUserStack(PhabricatorUser $user) { + if (!$user->isLoggedIn()) { + return array(); + } + + return id(new PhrequentUserTime())->loadAllWhere( + 'userPHID = %s AND dateEnded IS NULL + ORDER BY dateStarted DESC, id DESC', + $user->getPHID()); + } + public static function getTotalTimeSpentOnObject($phid) { $usertime_dao = new PhrequentUserTime(); $conn = $usertime_dao->establishConnection('r'); diff --git a/webroot/rsrc/css/application/phrequent/phrequent.css b/webroot/rsrc/css/application/phrequent/phrequent.css new file mode 100644 index 0000000000..0e5c280605 --- /dev/null +++ b/webroot/rsrc/css/application/phrequent/phrequent.css @@ -0,0 +1,20 @@ +/** + * @provides phrequent-css + */ + +.phrequent-tracking-property { + padding: 6px 6px 6px 28px; + margin-bottom: 2px; + background: #e9e9e9; + background-repeat: no-repeat; + background-position: 6px center; +} + +.phrequent-active { + background-image: url(/rsrc/image/phrequent_active.png); +} + +.phrequent-on-stack { + color: #777777; + background-image: url(/rsrc/image/phrequent_inactive.png); +} diff --git a/webroot/rsrc/image/phrequent_active.png b/webroot/rsrc/image/phrequent_active.png new file mode 100755 index 0000000000..c315b965af Binary files /dev/null and b/webroot/rsrc/image/phrequent_active.png differ diff --git a/webroot/rsrc/image/phrequent_inactive.png b/webroot/rsrc/image/phrequent_inactive.png new file mode 100644 index 0000000000..2c46cf4b53 Binary files /dev/null and b/webroot/rsrc/image/phrequent_inactive.png differ