2013-10-01 13:04:47 -07:00
|
|
|
<?php
|
|
|
|
|
2014-07-23 10:03:09 +10:00
|
|
|
final class PhrequentSearchEngine extends PhabricatorApplicationSearchEngine {
|
2013-10-01 13:04:47 -07:00
|
|
|
|
2014-06-12 13:22:20 -07:00
|
|
|
public function getResultTypeDescription() {
|
|
|
|
return pht('Phrequent Time');
|
|
|
|
}
|
|
|
|
|
2015-02-04 15:47:48 -08:00
|
|
|
public function getApplicationClassName() {
|
2014-07-23 10:03:09 +10:00
|
|
|
return 'PhabricatorPhrequentApplication';
|
2014-05-09 12:25:52 -07:00
|
|
|
}
|
|
|
|
|
2013-10-01 13:04:47 -07:00
|
|
|
public function getPageSize(PhabricatorSavedQuery $saved) {
|
|
|
|
return $saved->getParameter('limit', 1000);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function buildSavedQueryFromRequest(AphrontRequest $request) {
|
|
|
|
$saved = new PhabricatorSavedQuery();
|
|
|
|
|
|
|
|
$saved->setParameter(
|
|
|
|
'userPHIDs',
|
|
|
|
$this->readUsersFromRequest($request, 'users'));
|
|
|
|
|
|
|
|
$saved->setParameter('ended', $request->getStr('ended'));
|
|
|
|
|
|
|
|
$saved->setParameter('order', $request->getStr('order'));
|
|
|
|
|
|
|
|
return $saved;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
|
2014-08-11 12:30:48 -07:00
|
|
|
$query = id(new PhrequentUserTimeQuery())
|
|
|
|
->needPreemptingEvents(true);
|
2013-10-01 13:04:47 -07:00
|
|
|
|
|
|
|
$user_phids = $saved->getParameter('userPHIDs');
|
|
|
|
if ($user_phids) {
|
|
|
|
$query->withUserPHIDs($user_phids);
|
|
|
|
}
|
|
|
|
|
|
|
|
$ended = $saved->getParameter('ended');
|
|
|
|
if ($ended != null) {
|
|
|
|
$query->withEnded($ended);
|
|
|
|
}
|
|
|
|
|
|
|
|
$order = $saved->getParameter('order');
|
|
|
|
if ($order != null) {
|
|
|
|
$query->setOrder($order);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $query;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function buildSearchForm(
|
|
|
|
AphrontFormView $form,
|
|
|
|
PhabricatorSavedQuery $saved_query) {
|
|
|
|
|
|
|
|
$user_phids = $saved_query->getParameter('userPHIDs', array());
|
|
|
|
$ended = $saved_query->getParameter(
|
|
|
|
'ended', PhrequentUserTimeQuery::ENDED_ALL);
|
|
|
|
$order = $saved_query->getParameter(
|
|
|
|
'order', PhrequentUserTimeQuery::ORDER_ENDED_DESC);
|
|
|
|
|
|
|
|
$form
|
2015-03-31 14:10:55 -07:00
|
|
|
->appendControl(
|
2013-10-01 13:04:47 -07:00
|
|
|
id(new AphrontFormTokenizerControl())
|
2014-07-17 15:44:18 -07:00
|
|
|
->setDatasource(new PhabricatorPeopleDatasource())
|
2013-10-01 13:04:47 -07:00
|
|
|
->setName('users')
|
|
|
|
->setLabel(pht('Users'))
|
2015-03-31 14:10:55 -07:00
|
|
|
->setValue($user_phids))
|
2013-10-01 13:04:47 -07:00
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormSelectControl())
|
|
|
|
->setLabel(pht('Ended'))
|
|
|
|
->setName('ended')
|
|
|
|
->setValue($ended)
|
|
|
|
->setOptions(PhrequentUserTimeQuery::getEndedSearchOptions()))
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormSelectControl())
|
|
|
|
->setLabel(pht('Order'))
|
|
|
|
->setName('order')
|
|
|
|
->setValue($order)
|
|
|
|
->setOptions(PhrequentUserTimeQuery::getOrderSearchOptions()));
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getURI($path) {
|
|
|
|
return '/phrequent/'.$path;
|
|
|
|
}
|
|
|
|
|
2015-01-07 07:34:51 +11:00
|
|
|
protected function getBuiltinQueryNames() {
|
2014-07-23 10:03:09 +10:00
|
|
|
return array(
|
2013-10-01 13:04:47 -07:00
|
|
|
'tracking' => pht('Currently Tracking'),
|
|
|
|
'all' => pht('All Tracked'),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function buildSavedQueryFromBuiltin($query_key) {
|
|
|
|
$query = $this->newSavedQuery();
|
|
|
|
$query->setQueryKey($query_key);
|
|
|
|
|
|
|
|
switch ($query_key) {
|
|
|
|
case 'all':
|
|
|
|
return $query
|
|
|
|
->setParameter('order', PhrequentUserTimeQuery::ORDER_ENDED_DESC);
|
|
|
|
case 'tracking':
|
|
|
|
return $query
|
|
|
|
->setParameter('ended', PhrequentUserTimeQuery::ENDED_NO)
|
|
|
|
->setParameter('order', PhrequentUserTimeQuery::ORDER_ENDED_DESC);
|
|
|
|
}
|
|
|
|
|
|
|
|
return parent::buildSavedQueryFromBuiltin($query_key);
|
|
|
|
}
|
|
|
|
|
2014-05-09 12:25:52 -07:00
|
|
|
protected function getRequiredHandlePHIDsForResultList(
|
|
|
|
array $usertimes,
|
|
|
|
PhabricatorSavedQuery $query) {
|
|
|
|
return array_mergev(
|
|
|
|
array(
|
|
|
|
mpull($usertimes, 'getUserPHID'),
|
|
|
|
mpull($usertimes, 'getObjectPHID'),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function renderResultList(
|
|
|
|
array $usertimes,
|
|
|
|
PhabricatorSavedQuery $query,
|
|
|
|
array $handles) {
|
|
|
|
assert_instances_of($usertimes, 'PhrequentUserTime');
|
|
|
|
$viewer = $this->requireViewer();
|
|
|
|
|
|
|
|
$view = id(new PHUIObjectItemListView())
|
|
|
|
->setUser($viewer);
|
|
|
|
|
|
|
|
foreach ($usertimes as $usertime) {
|
|
|
|
$item = new PHUIObjectItemView();
|
|
|
|
if ($usertime->getObjectPHID() === null) {
|
|
|
|
$item->setHeader($usertime->getNote());
|
|
|
|
} else {
|
|
|
|
$obj = $handles[$usertime->getObjectPHID()];
|
|
|
|
$item->setHeader($obj->getLinkName());
|
|
|
|
$item->setHref($obj->getURI());
|
|
|
|
}
|
|
|
|
$item->setObject($usertime);
|
|
|
|
|
|
|
|
$item->addByline(
|
|
|
|
pht(
|
|
|
|
'Tracked: %s',
|
|
|
|
$handles[$usertime->getUserPHID()]->renderLink()));
|
|
|
|
|
|
|
|
$started_date = phabricator_date($usertime->getDateStarted(), $viewer);
|
|
|
|
$item->addIcon('none', $started_date);
|
|
|
|
|
2014-08-11 12:30:48 -07:00
|
|
|
$block = new PhrequentTimeBlock(array($usertime));
|
|
|
|
$time_spent = $block->getTimeSpentOnObject(
|
|
|
|
$usertime->getObjectPHID(),
|
|
|
|
PhabricatorTime::getNow());
|
2014-05-09 12:25:52 -07:00
|
|
|
|
|
|
|
$time_spent = $time_spent == 0 ? 'none' :
|
2014-07-13 12:03:17 +10:00
|
|
|
phutil_format_relative_time_detailed($time_spent);
|
2014-05-09 12:25:52 -07:00
|
|
|
|
|
|
|
if ($usertime->getDateEnded() !== null) {
|
|
|
|
$item->addAttribute(
|
|
|
|
pht(
|
|
|
|
'Tracked %s',
|
|
|
|
$time_spent));
|
|
|
|
$item->addAttribute(
|
|
|
|
pht(
|
|
|
|
'Ended on %s',
|
2014-08-11 12:30:48 -07:00
|
|
|
phabricator_datetime($usertime->getDateEnded(), $viewer)));
|
2014-05-09 12:25:52 -07:00
|
|
|
} else {
|
|
|
|
$item->addAttribute(
|
|
|
|
pht(
|
|
|
|
'Tracked %s so far',
|
|
|
|
$time_spent));
|
|
|
|
if ($usertime->getObjectPHID() !== null &&
|
|
|
|
$usertime->getUserPHID() === $viewer->getPHID()) {
|
|
|
|
$item->addAction(
|
|
|
|
id(new PHUIListItemView())
|
Conduit APIs to start and stop tracking time in phrequent
Summary:
This adds methods to start and stop tracking any arbitrary PHID in phrequent. Currently, this uses copy-pasted code from PhrequentTrackController. I had to do this because the code to start/stop was not abstracted into a common class.
Once the code to start/stop working is extracted into a re-usable class, the conduit API can use this as well.
Test Plan: I called the functions with a PHID of a task and ensured that the fields in the phrequent database table was being updated correctly.
Reviewers: skyronic, #blessed_reviewers, epriestley
Reviewed By: #blessed_reviewers, epriestley
Subscribers: maxhodak, erik.fercak, aran, epriestley, Korvin
Maniphest Tasks: T3569, T3970
Differential Revision: https://secure.phabricator.com/D7326
2014-07-12 11:42:32 +10:00
|
|
|
->setIcon('fa-stop')
|
2014-05-09 12:25:52 -07:00
|
|
|
->addSigil('phrequent-stop-tracking')
|
|
|
|
->setWorkflow(true)
|
|
|
|
->setRenderNameAsTooltip(true)
|
2014-06-09 11:36:49 -07:00
|
|
|
->setName(pht('Stop'))
|
2014-05-09 12:25:52 -07:00
|
|
|
->setHref(
|
|
|
|
'/phrequent/track/stop/'.
|
|
|
|
$usertime->getObjectPHID().'/'));
|
|
|
|
}
|
2015-05-28 15:17:34 -07:00
|
|
|
$item->setStatusIcon('fa-clock-o green');
|
2014-05-09 12:25:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
$view->addItem($item);
|
|
|
|
}
|
|
|
|
|
2015-06-19 11:46:20 +01:00
|
|
|
$result = new PhabricatorApplicationSearchResultView();
|
|
|
|
$result->setObjectList($view);
|
|
|
|
|
|
|
|
return $result;
|
2014-05-09 12:25:52 -07:00
|
|
|
}
|
2014-07-23 10:03:09 +10:00
|
|
|
|
2013-10-01 13:04:47 -07:00
|
|
|
}
|