mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-19 05:12:41 +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',
|
0 => 'PhabricatorAuditDAO',
|
||||||
1 => 'PhabricatorInlineCommentInterface',
|
1 => 'PhabricatorInlineCommentInterface',
|
||||||
),
|
),
|
||||||
'PhabricatorAuditListController' =>
|
'PhabricatorAuditListController' => 'PhabricatorAuditController',
|
||||||
array(
|
|
||||||
0 => 'PhabricatorAuditController',
|
|
||||||
1 => 'PhabricatorApplicationSearchResultsControllerInterface',
|
|
||||||
),
|
|
||||||
'PhabricatorAuditListView' => 'AphrontView',
|
'PhabricatorAuditListView' => 'AphrontView',
|
||||||
'PhabricatorAuditMailReceiver' => 'PhabricatorObjectMailReceiver',
|
'PhabricatorAuditMailReceiver' => 'PhabricatorObjectMailReceiver',
|
||||||
'PhabricatorAuditManagementDeleteWorkflow' => 'PhabricatorAuditManagementWorkflow',
|
'PhabricatorAuditManagementDeleteWorkflow' => 'PhabricatorAuditManagementWorkflow',
|
||||||
|
@ -4097,11 +4093,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorCalendarEventDeleteController' => 'PhabricatorCalendarController',
|
'PhabricatorCalendarEventDeleteController' => 'PhabricatorCalendarController',
|
||||||
'PhabricatorCalendarEventEditController' => 'PhabricatorCalendarController',
|
'PhabricatorCalendarEventEditController' => 'PhabricatorCalendarController',
|
||||||
'PhabricatorCalendarEventInvalidEpochException' => 'Exception',
|
'PhabricatorCalendarEventInvalidEpochException' => 'Exception',
|
||||||
'PhabricatorCalendarEventListController' =>
|
'PhabricatorCalendarEventListController' => 'PhabricatorCalendarController',
|
||||||
array(
|
|
||||||
0 => 'PhabricatorCalendarController',
|
|
||||||
1 => 'PhabricatorApplicationSearchResultsControllerInterface',
|
|
||||||
),
|
|
||||||
'PhabricatorCalendarEventQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
'PhabricatorCalendarEventQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
||||||
'PhabricatorCalendarEventSearchEngine' => 'PhabricatorApplicationSearchEngine',
|
'PhabricatorCalendarEventSearchEngine' => 'PhabricatorApplicationSearchEngine',
|
||||||
'PhabricatorCalendarEventViewController' => 'PhabricatorCalendarController',
|
'PhabricatorCalendarEventViewController' => 'PhabricatorCalendarController',
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
final class PhabricatorCalendarEventListController
|
final class PhabricatorCalendarEventListController
|
||||||
extends PhabricatorCalendarController
|
extends PhabricatorCalendarController {
|
||||||
implements PhabricatorApplicationSearchResultsControllerInterface {
|
|
||||||
|
|
||||||
private $queryKey;
|
private $queryKey;
|
||||||
|
|
||||||
|
@ -34,48 +33,4 @@ final class PhabricatorCalendarEventListController
|
||||||
return $nav;
|
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
|
final class PhabricatorCalendarEventSearchEngine
|
||||||
extends PhabricatorApplicationSearchEngine {
|
extends PhabricatorApplicationSearchEngine {
|
||||||
|
|
||||||
|
public function getApplicationClassName() {
|
||||||
|
return 'PhabricatorApplicationCalendar';
|
||||||
|
}
|
||||||
|
|
||||||
public function buildSavedQueryFromRequest(AphrontRequest $request) {
|
public function buildSavedQueryFromRequest(AphrontRequest $request) {
|
||||||
$saved = new PhabricatorSavedQuery();
|
$saved = new PhabricatorSavedQuery();
|
||||||
|
|
||||||
|
@ -160,4 +164,49 @@ final class PhabricatorCalendarEventSearchEngine
|
||||||
return parent::buildSavedQueryFromBuiltin($query_key);
|
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.
|
* creating and storing saved queries.
|
||||||
*
|
*
|
||||||
* @task construct Constructing Engines
|
* @task construct Constructing Engines
|
||||||
|
* @task app Applications
|
||||||
* @task builtin Builtin Queries
|
* @task builtin Builtin Queries
|
||||||
* @task uri Query URIs
|
* @task uri Query URIs
|
||||||
* @task dates Date Filters
|
* @task dates Date Filters
|
||||||
|
@ -16,6 +17,7 @@
|
||||||
*/
|
*/
|
||||||
abstract class PhabricatorApplicationSearchEngine {
|
abstract class PhabricatorApplicationSearchEngine {
|
||||||
|
|
||||||
|
private $application;
|
||||||
private $viewer;
|
private $viewer;
|
||||||
private $errors = array();
|
private $errors = array();
|
||||||
private $customFields = false;
|
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 )----------------------------------------------- */
|
/* -( Constructing Engines )----------------------------------------------- */
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue