mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-20 13:52:40 +01:00
Added sort order and ended filter to Phrequent.
Summary: Fixed order by duration, wasn't order by duration. Added some sorting and filtering. Test Plan: set some timers, stop them, look at phrequent, sort and filter them. Reviewers: epriestley, hach-que CC: aran, Korvin, hach-que Maniphest Tasks: T2857 Differential Revision: https://secure.phabricator.com/D5554
This commit is contained in:
parent
d5841fe499
commit
7d35625ea9
2 changed files with 92 additions and 6 deletions
|
@ -8,8 +8,70 @@ final class PhrequentListController extends PhrequentController {
|
|||
|
||||
$nav = $this->buildNav('usertime');
|
||||
|
||||
$form = id(new AphrontFormView())
|
||||
->setUser($user)
|
||||
->setNoShading(true);
|
||||
|
||||
$form->appendChild(
|
||||
id(new AphrontFormToggleButtonsControl())
|
||||
->setName('o')
|
||||
->setLabel(pht('Sort Order'))
|
||||
->setBaseURI($request->getRequestURI(), 'o')
|
||||
->setValue($request->getStr('o', 's'))
|
||||
->setButtons(
|
||||
array(
|
||||
's' => pht('Started'),
|
||||
'e' => pht('Ended'),
|
||||
'd' => pht('Duration'),
|
||||
)));
|
||||
|
||||
$form->appendChild(
|
||||
id(new AphrontFormToggleButtonsControl())
|
||||
->setName('e')
|
||||
->setLabel(pht('Ended'))
|
||||
->setBaseURI($request->getRequestURI(), 'e')
|
||||
->setValue($request->getStr('e', 'a'))
|
||||
->setButtons(
|
||||
array(
|
||||
'y' => pht('Yes'),
|
||||
'n' => pht('No'),
|
||||
'a' => pht('All'),
|
||||
)));
|
||||
|
||||
$filter = new AphrontListFilterView();
|
||||
$filter->appendChild($form);
|
||||
|
||||
$query = new PhrequentUserTimeQuery();
|
||||
$query->setOrder(PhrequentUserTimeQuery::ORDER_ENDED);
|
||||
|
||||
switch ($request->getStr('o', 's')) {
|
||||
case 's':
|
||||
$order = PhrequentUserTimeQuery::ORDER_STARTED;
|
||||
break;
|
||||
case 'e':
|
||||
$order = PhrequentUserTimeQuery::ORDER_ENDED;
|
||||
break;
|
||||
case 'd':
|
||||
$order = PhrequentUserTimeQuery::ORDER_DURATION;
|
||||
break;
|
||||
default:
|
||||
throw new Exception("Unknown order!");
|
||||
}
|
||||
$query->setOrder($order);
|
||||
|
||||
switch ($request->getStr('e', 'a')) {
|
||||
case 'a':
|
||||
$ended = PhrequentUserTimeQuery::ENDED_ALL;
|
||||
break;
|
||||
case 'y':
|
||||
$ended = PhrequentUserTimeQuery::ENDED_YES;
|
||||
break;
|
||||
case 'n':
|
||||
$ended = PhrequentUserTimeQuery::ENDED_NO;
|
||||
break;
|
||||
default:
|
||||
throw new Exception("Unknown ended!");
|
||||
}
|
||||
$query->setEnded($ended);
|
||||
|
||||
$pager = new AphrontPagerView();
|
||||
$pager->setPageSize(500);
|
||||
|
@ -20,15 +82,12 @@ final class PhrequentListController extends PhrequentController {
|
|||
|
||||
$title = pht('Time Tracked');
|
||||
|
||||
$header = id(new PhabricatorHeaderView())
|
||||
->setHeader($title);
|
||||
|
||||
$table = $this->buildTableView($logs);
|
||||
$table->appendChild($pager);
|
||||
|
||||
$nav->appendChild(
|
||||
array(
|
||||
$header,
|
||||
$filter,
|
||||
$table,
|
||||
$pager,
|
||||
));
|
||||
|
|
|
@ -7,9 +7,14 @@ final class PhrequentUserTimeQuery extends PhabricatorOffsetPagedQuery {
|
|||
const ORDER_ENDED = 'order-ended';
|
||||
const ORDER_DURATION = 'order-duration';
|
||||
|
||||
const ENDED_YES = "ended-yes";
|
||||
const ENDED_NO = "ended-no";
|
||||
const ENDED_ALL = "ended-all";
|
||||
|
||||
private $userPHIDs;
|
||||
private $objectPHIDs;
|
||||
private $order = self::ORDER_ID;
|
||||
private $ended = self::ENDED_ALL;
|
||||
|
||||
public function setUsers($user_phids) {
|
||||
$this->userPHIDs = $user_phids;
|
||||
|
@ -26,6 +31,11 @@ final class PhrequentUserTimeQuery extends PhabricatorOffsetPagedQuery {
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function setEnded($ended) {
|
||||
$this->ended = $ended;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function execute() {
|
||||
$usertime_dao = new PhrequentUserTime();
|
||||
$conn = $usertime_dao->establishConnection('r');
|
||||
|
@ -58,6 +68,23 @@ final class PhrequentUserTimeQuery extends PhabricatorOffsetPagedQuery {
|
|||
$this->objectPHIDs);
|
||||
}
|
||||
|
||||
switch ($this->ended) {
|
||||
case self::ENDED_ALL:
|
||||
break;
|
||||
case self::ENDED_YES:
|
||||
$where[] = qsprintf(
|
||||
$conn,
|
||||
'dateEnded IS NOT NULL');
|
||||
break;
|
||||
case self::ENDED_NO:
|
||||
$where[] = qsprintf(
|
||||
$conn,
|
||||
'dateEnded IS NULL');
|
||||
break;
|
||||
default:
|
||||
throw new Exception("Unknown ended '{$this->ended}'!");
|
||||
}
|
||||
|
||||
return $this->formatWhereClause($where);
|
||||
}
|
||||
|
||||
|
@ -70,7 +97,7 @@ final class PhrequentUserTimeQuery extends PhabricatorOffsetPagedQuery {
|
|||
case self::ORDER_ENDED:
|
||||
return 'ORDER BY dateEnded IS NULL, dateEnded DESC, dateStarted DESC';
|
||||
case self::ORDER_DURATION:
|
||||
return 'ORDER BY (COALESCE(dateEnded, UNIX_TIMESTAMP() - dateStarted) '.
|
||||
return 'ORDER BY COALESCE(dateEnded, UNIX_TIMESTAMP()) - dateStarted '.
|
||||
'DESC';
|
||||
default:
|
||||
throw new Exception("Unknown order '{$this->order}'!");
|
||||
|
|
Loading…
Reference in a new issue