mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-19 03:50:54 +01:00
Move rendering to SearchEngine for Calendar
Summary: Ref T4986. This one needs `getApplicationURI()` so make it a little beefier to deal with that. (It would be vaguely nice to somehow share the handle and application stuff between Controllers and Engine classes like this, but I don't immediately see a clean way to do it without traits. Not a big deal, in any case.) Test Plan: - Viewed Calendar. - Made a Calendar panel. - Viewed feed. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T4986 Differential Revision: https://secure.phabricator.com/D9012
This commit is contained in:
parent
c72b753e54
commit
684805a88a
4 changed files with 87 additions and 56 deletions
|
@ -3983,11 +3983,7 @@ phutil_register_library_map(array(
|
|||
0 => 'PhabricatorAuditDAO',
|
||||
1 => 'PhabricatorInlineCommentInterface',
|
||||
),
|
||||
'PhabricatorAuditListController' =>
|
||||
array(
|
||||
0 => 'PhabricatorAuditController',
|
||||
1 => 'PhabricatorApplicationSearchResultsControllerInterface',
|
||||
),
|
||||
'PhabricatorAuditListController' => 'PhabricatorAuditController',
|
||||
'PhabricatorAuditListView' => 'AphrontView',
|
||||
'PhabricatorAuditMailReceiver' => 'PhabricatorObjectMailReceiver',
|
||||
'PhabricatorAuditManagementDeleteWorkflow' => 'PhabricatorAuditManagementWorkflow',
|
||||
|
@ -4097,11 +4093,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorCalendarEventDeleteController' => 'PhabricatorCalendarController',
|
||||
'PhabricatorCalendarEventEditController' => 'PhabricatorCalendarController',
|
||||
'PhabricatorCalendarEventInvalidEpochException' => 'Exception',
|
||||
'PhabricatorCalendarEventListController' =>
|
||||
array(
|
||||
0 => 'PhabricatorCalendarController',
|
||||
1 => 'PhabricatorApplicationSearchResultsControllerInterface',
|
||||
),
|
||||
'PhabricatorCalendarEventListController' => 'PhabricatorCalendarController',
|
||||
'PhabricatorCalendarEventQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
||||
'PhabricatorCalendarEventSearchEngine' => 'PhabricatorApplicationSearchEngine',
|
||||
'PhabricatorCalendarEventViewController' => 'PhabricatorCalendarController',
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorCalendarEventListController
|
||||
extends PhabricatorCalendarController
|
||||
implements PhabricatorApplicationSearchResultsControllerInterface {
|
||||
extends PhabricatorCalendarController {
|
||||
|
||||
private $queryKey;
|
||||
|
||||
|
@ -34,48 +33,4 @@ final class PhabricatorCalendarEventListController
|
|||
return $nav;
|
||||
}
|
||||
|
||||
public function renderResultsList(
|
||||
array $events,
|
||||
PhabricatorSavedQuery $query) {
|
||||
assert_instances_of($events, 'PhabricatorCalendarEvent');
|
||||
|
||||
$viewer = $this->getRequest()->getUser();
|
||||
|
||||
$list = new PHUIObjectItemListView();
|
||||
foreach ($events as $event) {
|
||||
if ($event->getUserPHID() == $viewer->getPHID()) {
|
||||
$href = $this->getApplicationURI('/event/edit/'.$event->getID().'/');
|
||||
} else {
|
||||
$from = $event->getDateFrom();
|
||||
$month = phabricator_format_local_time($from, $viewer, 'm');
|
||||
$year = phabricator_format_local_time($from, $viewer, 'Y');
|
||||
$uri = new PhutilURI($this->getApplicationURI());
|
||||
$uri->setQueryParams(
|
||||
array(
|
||||
'month' => $month,
|
||||
'year' => $year,
|
||||
));
|
||||
$href = (string) $uri;
|
||||
}
|
||||
$from = phabricator_datetime($event->getDateFrom(), $viewer);
|
||||
$to = phabricator_datetime($event->getDateTo(), $viewer);
|
||||
|
||||
$color = ($event->getStatus() == PhabricatorCalendarEvent::STATUS_AWAY)
|
||||
? 'red'
|
||||
: 'yellow';
|
||||
|
||||
$item = id(new PHUIObjectItemView())
|
||||
->setHeader($event->getTerseSummary($viewer))
|
||||
->setHref($href)
|
||||
->setBarColor($color)
|
||||
->addAttribute(pht('From %s to %s', $from, $to))
|
||||
->addAttribute(
|
||||
phutil_utf8_shorten($event->getDescription(), 64));
|
||||
|
||||
$list->addItem($item);
|
||||
}
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,6 +3,10 @@
|
|||
final class PhabricatorCalendarEventSearchEngine
|
||||
extends PhabricatorApplicationSearchEngine {
|
||||
|
||||
public function getApplicationClassName() {
|
||||
return 'PhabricatorApplicationCalendar';
|
||||
}
|
||||
|
||||
public function buildSavedQueryFromRequest(AphrontRequest $request) {
|
||||
$saved = new PhabricatorSavedQuery();
|
||||
|
||||
|
@ -160,4 +164,49 @@ final class PhabricatorCalendarEventSearchEngine
|
|||
return parent::buildSavedQueryFromBuiltin($query_key);
|
||||
}
|
||||
|
||||
protected function renderResultList(
|
||||
array $events,
|
||||
PhabricatorSavedQuery $query,
|
||||
array $handles) {
|
||||
assert_instances_of($events, 'PhabricatorCalendarEvent');
|
||||
|
||||
$viewer = $this->requireViewer();
|
||||
|
||||
$list = new PHUIObjectItemListView();
|
||||
foreach ($events as $event) {
|
||||
if ($event->getUserPHID() == $viewer->getPHID()) {
|
||||
$href = $this->getApplicationURI('/event/edit/'.$event->getID().'/');
|
||||
} else {
|
||||
$from = $event->getDateFrom();
|
||||
$month = phabricator_format_local_time($from, $viewer, 'm');
|
||||
$year = phabricator_format_local_time($from, $viewer, 'Y');
|
||||
$uri = new PhutilURI($this->getApplicationURI());
|
||||
$uri->setQueryParams(
|
||||
array(
|
||||
'month' => $month,
|
||||
'year' => $year,
|
||||
));
|
||||
$href = (string) $uri;
|
||||
}
|
||||
$from = phabricator_datetime($event->getDateFrom(), $viewer);
|
||||
$to = phabricator_datetime($event->getDateTo(), $viewer);
|
||||
|
||||
$color = ($event->getStatus() == PhabricatorCalendarEvent::STATUS_AWAY)
|
||||
? 'red'
|
||||
: 'yellow';
|
||||
|
||||
$item = id(new PHUIObjectItemView())
|
||||
->setHeader($event->getTerseSummary($viewer))
|
||||
->setHref($href)
|
||||
->setBarColor($color)
|
||||
->addAttribute(pht('From %s to %s', $from, $to))
|
||||
->addAttribute(
|
||||
phutil_utf8_shorten($event->getDescription(), 64));
|
||||
|
||||
$list->addItem($item);
|
||||
}
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
* creating and storing saved queries.
|
||||
*
|
||||
* @task construct Constructing Engines
|
||||
* @task app Applications
|
||||
* @task builtin Builtin Queries
|
||||
* @task uri Query URIs
|
||||
* @task dates Date Filters
|
||||
|
@ -16,6 +17,7 @@
|
|||
*/
|
||||
abstract class PhabricatorApplicationSearchEngine {
|
||||
|
||||
private $application;
|
||||
private $viewer;
|
||||
private $errors = array();
|
||||
private $customFields = false;
|
||||
|
@ -177,6 +179,39 @@ abstract class PhabricatorApplicationSearchEngine {
|
|||
}
|
||||
|
||||
|
||||
/* -( Applications )------------------------------------------------------- */
|
||||
|
||||
|
||||
protected function getApplicationURI($path = '') {
|
||||
return $this->getApplication()->getApplicationURI($path);
|
||||
}
|
||||
|
||||
protected function getApplication() {
|
||||
if (!$this->application) {
|
||||
$class = $this->getApplicationClassName();
|
||||
|
||||
$this->application = id(new PhabricatorApplicationQuery())
|
||||
->setViewer($this->requireViewer())
|
||||
->withClasses(array($class))
|
||||
->withInstalled(true)
|
||||
->executeOne();
|
||||
|
||||
if (!$this->application) {
|
||||
throw new Exception(
|
||||
pht(
|
||||
'Application "%s" is not installed!',
|
||||
$class));
|
||||
}
|
||||
}
|
||||
|
||||
return $this->application;
|
||||
}
|
||||
|
||||
protected function getApplicationClassName() {
|
||||
throw new Exception(pht('Not implemented for this SearchEngine yet!'));
|
||||
}
|
||||
|
||||
|
||||
/* -( Constructing Engines )----------------------------------------------- */
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue