mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-19 20:10:55 +01:00
Move notifications to ApplicationSearch
Summary: Ref T5891. This just modernizes infrastructure. Test Plan: Viewed "All" and "Unread" notifications. Reviewers: btrahan, chad Reviewed By: chad Subscribers: epriestley Maniphest Tasks: T5891 Differential Revision: https://secure.phabricator.com/D10281
This commit is contained in:
parent
98a847a36c
commit
fce43179e7
7 changed files with 171 additions and 89 deletions
|
@ -1759,6 +1759,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorNotificationListController' => 'applications/notification/controller/PhabricatorNotificationListController.php',
|
'PhabricatorNotificationListController' => 'applications/notification/controller/PhabricatorNotificationListController.php',
|
||||||
'PhabricatorNotificationPanelController' => 'applications/notification/controller/PhabricatorNotificationPanelController.php',
|
'PhabricatorNotificationPanelController' => 'applications/notification/controller/PhabricatorNotificationPanelController.php',
|
||||||
'PhabricatorNotificationQuery' => 'applications/notification/query/PhabricatorNotificationQuery.php',
|
'PhabricatorNotificationQuery' => 'applications/notification/query/PhabricatorNotificationQuery.php',
|
||||||
|
'PhabricatorNotificationSearchEngine' => 'applications/notification/query/PhabricatorNotificationSearchEngine.php',
|
||||||
'PhabricatorNotificationStatusController' => 'applications/notification/controller/PhabricatorNotificationStatusController.php',
|
'PhabricatorNotificationStatusController' => 'applications/notification/controller/PhabricatorNotificationStatusController.php',
|
||||||
'PhabricatorNotificationStatusView' => 'applications/notification/view/PhabricatorNotificationStatusView.php',
|
'PhabricatorNotificationStatusView' => 'applications/notification/view/PhabricatorNotificationStatusView.php',
|
||||||
'PhabricatorNotificationTestController' => 'applications/notification/controller/PhabricatorNotificationTestController.php',
|
'PhabricatorNotificationTestController' => 'applications/notification/controller/PhabricatorNotificationTestController.php',
|
||||||
|
@ -4591,6 +4592,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorNotificationListController' => 'PhabricatorNotificationController',
|
'PhabricatorNotificationListController' => 'PhabricatorNotificationController',
|
||||||
'PhabricatorNotificationPanelController' => 'PhabricatorNotificationController',
|
'PhabricatorNotificationPanelController' => 'PhabricatorNotificationController',
|
||||||
'PhabricatorNotificationQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
'PhabricatorNotificationQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
||||||
|
'PhabricatorNotificationSearchEngine' => 'PhabricatorApplicationSearchEngine',
|
||||||
'PhabricatorNotificationStatusController' => 'PhabricatorNotificationController',
|
'PhabricatorNotificationStatusController' => 'PhabricatorNotificationController',
|
||||||
'PhabricatorNotificationStatusView' => 'AphrontTagView',
|
'PhabricatorNotificationStatusView' => 'AphrontTagView',
|
||||||
'PhabricatorNotificationTestController' => 'PhabricatorNotificationController',
|
'PhabricatorNotificationTestController' => 'PhabricatorNotificationController',
|
||||||
|
|
|
@ -17,7 +17,7 @@ final class PhabricatorNotificationsApplication extends PhabricatorApplication {
|
||||||
public function getRoutes() {
|
public function getRoutes() {
|
||||||
return array(
|
return array(
|
||||||
'/notification/' => array(
|
'/notification/' => array(
|
||||||
'(?:(?P<filter>all|unread)/)?'
|
'(?:query/(?P<queryKey>[^/]+)/)?'
|
||||||
=> 'PhabricatorNotificationListController',
|
=> 'PhabricatorNotificationListController',
|
||||||
'panel/' => 'PhabricatorNotificationPanelController',
|
'panel/' => 'PhabricatorNotificationPanelController',
|
||||||
'individual/' => 'PhabricatorNotificationIndividualController',
|
'individual/' => 'PhabricatorNotificationIndividualController',
|
||||||
|
|
|
@ -9,7 +9,7 @@ final class PhabricatorNotificationIndividualController
|
||||||
|
|
||||||
$stories = id(new PhabricatorNotificationQuery())
|
$stories = id(new PhabricatorNotificationQuery())
|
||||||
->setViewer($user)
|
->setViewer($user)
|
||||||
->setUserPHID($user->getPHID())
|
->withUserPHIDs(array($user->getPHID()))
|
||||||
->withKeys(array($request->getStr('key')))
|
->withKeys(array($request->getStr('key')))
|
||||||
->execute();
|
->execute();
|
||||||
|
|
||||||
|
|
|
@ -3,89 +3,34 @@
|
||||||
final class PhabricatorNotificationListController
|
final class PhabricatorNotificationListController
|
||||||
extends PhabricatorNotificationController {
|
extends PhabricatorNotificationController {
|
||||||
|
|
||||||
private $filter;
|
private $queryKey;
|
||||||
|
|
||||||
public function willProcessRequest(array $data) {
|
public function willProcessRequest(array $data) {
|
||||||
$this->filter = idx($data, 'filter');
|
$this->queryKey = idx($data, 'queryKey');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function processRequest() {
|
public function processRequest() {
|
||||||
$request = $this->getRequest();
|
$request = $this->getRequest();
|
||||||
$user = $request->getUser();
|
$controller = id(new PhabricatorApplicationSearchController($request))
|
||||||
|
->setQueryKey($this->queryKey)
|
||||||
|
->setSearchEngine(new PhabricatorNotificationSearchEngine())
|
||||||
|
->setNavigation($this->buildSideNavView());
|
||||||
|
|
||||||
|
return $this->delegateToController($controller);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function buildSideNavView() {
|
||||||
|
$user = $this->getRequest()->getUser();
|
||||||
|
|
||||||
$nav = new AphrontSideNavFilterView();
|
$nav = new AphrontSideNavFilterView();
|
||||||
$nav->setBaseURI(new PhutilURI('/notification/'));
|
$nav->setBaseURI(new PhutilURI($this->getApplicationURI()));
|
||||||
$nav->addFilter('all', pht('All Notifications'));
|
|
||||||
$nav->addFilter('unread', pht('Unread Notifications'));
|
|
||||||
$filter = $nav->selectFilter($this->filter, 'all');
|
|
||||||
|
|
||||||
$pager = new AphrontPagerView();
|
id(new PhabricatorNotificationSearchEngine())
|
||||||
$pager->setURI($request->getRequestURI(), 'offset');
|
->setViewer($user)
|
||||||
$pager->setOffset($request->getInt('offset'));
|
->addNavigationItems($nav->getMenu());
|
||||||
|
$nav->selectFilter(null);
|
||||||
|
|
||||||
$query = new PhabricatorNotificationQuery();
|
return $nav;
|
||||||
$query->setViewer($user);
|
|
||||||
$query->setUserPHID($user->getPHID());
|
|
||||||
|
|
||||||
switch ($filter) {
|
|
||||||
case 'unread':
|
|
||||||
$query->withUnread(true);
|
|
||||||
$header = pht('Unread Notifications');
|
|
||||||
$no_data = pht('You have no unread notifications.');
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
$header = pht('Notifications');
|
|
||||||
$no_data = pht('You have no notifications.');
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
$image = id(new PHUIIconView())
|
|
||||||
->setIconFont('fa-eye-slash');
|
|
||||||
$button = id(new PHUIButtonView())
|
|
||||||
->setTag('a')
|
|
||||||
->addSigil('workflow')
|
|
||||||
->setColor(PHUIButtonView::SIMPLE)
|
|
||||||
->setIcon($image)
|
|
||||||
->setText(pht('Mark All Read'));
|
|
||||||
|
|
||||||
$notifications = $query->executeWithOffsetPager($pager);
|
|
||||||
$clear_uri = id(new PhutilURI('/notification/clear/'));
|
|
||||||
if ($notifications) {
|
|
||||||
$builder = new PhabricatorNotificationBuilder($notifications);
|
|
||||||
$builder->setUser($user);
|
|
||||||
$view = $builder->buildView()->render();
|
|
||||||
$clear_uri->setQueryParam(
|
|
||||||
'chronoKey',
|
|
||||||
head($notifications)->getChronologicalKey());
|
|
||||||
} else {
|
|
||||||
$view = phutil_tag_div(
|
|
||||||
'phabricator-notification no-notifications',
|
|
||||||
$no_data);
|
|
||||||
$button->setDisabled(true);
|
|
||||||
}
|
|
||||||
$button->setHref((string) $clear_uri);
|
|
||||||
|
|
||||||
$view = id(new PHUIBoxView())
|
|
||||||
->addPadding(PHUI::PADDING_MEDIUM)
|
|
||||||
->addClass('phabricator-notification-list')
|
|
||||||
->appendChild($view);
|
|
||||||
|
|
||||||
$notif_header = id(new PHUIHeaderView())
|
|
||||||
->setHeader($header)
|
|
||||||
->addActionLink($button);
|
|
||||||
|
|
||||||
$box = id(new PHUIObjectBoxView())
|
|
||||||
->setHeader($notif_header)
|
|
||||||
->appendChild($view);
|
|
||||||
|
|
||||||
$nav->appendChild($box);
|
|
||||||
$nav->appendChild($pager);
|
|
||||||
|
|
||||||
return $this->buildApplicationPage(
|
|
||||||
$nav,
|
|
||||||
array(
|
|
||||||
'title' => pht('Notifications'),
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,10 +8,10 @@ final class PhabricatorNotificationPanelController
|
||||||
$request = $this->getRequest();
|
$request = $this->getRequest();
|
||||||
$user = $request->getUser();
|
$user = $request->getUser();
|
||||||
|
|
||||||
$query = new PhabricatorNotificationQuery();
|
$query = id(new PhabricatorNotificationQuery())
|
||||||
$query->setViewer($user);
|
->setViewer($user)
|
||||||
$query->setUserPHID($user->getPHID());
|
->withUserPHIDs(array($user->getPHID()))
|
||||||
$query->setLimit(15);
|
->setLimit(15);
|
||||||
|
|
||||||
$stories = $query->execute();
|
$stories = $query->execute();
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
final class PhabricatorNotificationQuery
|
final class PhabricatorNotificationQuery
|
||||||
extends PhabricatorCursorPagedPolicyAwareQuery {
|
extends PhabricatorCursorPagedPolicyAwareQuery {
|
||||||
|
|
||||||
private $userPHID;
|
private $userPHIDs;
|
||||||
private $keys;
|
private $keys;
|
||||||
private $unread;
|
private $unread;
|
||||||
|
|
||||||
|
@ -15,8 +15,8 @@ final class PhabricatorNotificationQuery
|
||||||
/* -( Configuring the Query )---------------------------------------------- */
|
/* -( Configuring the Query )---------------------------------------------- */
|
||||||
|
|
||||||
|
|
||||||
public function setUserPHID($user_phid) {
|
public function withUserPHIDs(array $user_phids) {
|
||||||
$this->userPHID = $user_phid;
|
$this->userPHIDs = $user_phids;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,10 +46,6 @@ final class PhabricatorNotificationQuery
|
||||||
|
|
||||||
|
|
||||||
protected function loadPage() {
|
protected function loadPage() {
|
||||||
if (!$this->userPHID) {
|
|
||||||
throw new Exception('Call setUser() before executing the query');
|
|
||||||
}
|
|
||||||
|
|
||||||
$story_table = new PhabricatorFeedStoryData();
|
$story_table = new PhabricatorFeedStoryData();
|
||||||
$notification_table = new PhabricatorFeedStoryNotification();
|
$notification_table = new PhabricatorFeedStoryNotification();
|
||||||
|
|
||||||
|
@ -83,11 +79,11 @@ final class PhabricatorNotificationQuery
|
||||||
private function buildWhereClause(AphrontDatabaseConnection $conn_r) {
|
private function buildWhereClause(AphrontDatabaseConnection $conn_r) {
|
||||||
$where = array();
|
$where = array();
|
||||||
|
|
||||||
if ($this->userPHID) {
|
if ($this->userPHIDs !== null) {
|
||||||
$where[] = qsprintf(
|
$where[] = qsprintf(
|
||||||
$conn_r,
|
$conn_r,
|
||||||
'notif.userPHID = %s',
|
'notif.userPHID IN (%Ls)',
|
||||||
$this->userPHID);
|
$this->userPHIDs);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->unread !== null) {
|
if ($this->unread !== null) {
|
||||||
|
|
|
@ -0,0 +1,139 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
final class PhabricatorNotificationSearchEngine
|
||||||
|
extends PhabricatorApplicationSearchEngine {
|
||||||
|
|
||||||
|
public function getResultTypeDescription() {
|
||||||
|
return pht('Notifications');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getApplicationClassName() {
|
||||||
|
return 'PhabricatorNotificationsApplication';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function buildSavedQueryFromRequest(AphrontRequest $request) {
|
||||||
|
$saved = new PhabricatorSavedQuery();
|
||||||
|
|
||||||
|
$saved->setParameter(
|
||||||
|
'unread',
|
||||||
|
$this->readBoolFromRequest($request, 'unread'));
|
||||||
|
|
||||||
|
return $saved;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
|
||||||
|
$query = id(new PhabricatorNotificationQuery())
|
||||||
|
->withUserPHIDs(array($this->requireViewer()->getPHID()));
|
||||||
|
|
||||||
|
if ($saved->getParameter('unread')) {
|
||||||
|
$query->withUnread(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $query;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function buildSearchForm(
|
||||||
|
AphrontFormView $form,
|
||||||
|
PhabricatorSavedQuery $saved) {
|
||||||
|
|
||||||
|
$unread = $saved->getParameter('unread');
|
||||||
|
|
||||||
|
$form->appendChild(
|
||||||
|
id(new AphrontFormCheckboxControl())
|
||||||
|
->setLabel(pht('Unread'))
|
||||||
|
->addCheckbox(
|
||||||
|
'unread',
|
||||||
|
1,
|
||||||
|
pht('Show only unread notifications.'),
|
||||||
|
$unread));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getURI($path) {
|
||||||
|
return '/notification/'.$path;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBuiltinQueryNames() {
|
||||||
|
|
||||||
|
$names = array(
|
||||||
|
'all' => pht('All Notifications'),
|
||||||
|
'unread' => pht('Unread Notifications'),
|
||||||
|
);
|
||||||
|
|
||||||
|
return $names;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function buildSavedQueryFromBuiltin($query_key) {
|
||||||
|
$query = $this->newSavedQuery();
|
||||||
|
$query->setQueryKey($query_key);
|
||||||
|
|
||||||
|
switch ($query_key) {
|
||||||
|
case 'all':
|
||||||
|
return $query;
|
||||||
|
case 'unread':
|
||||||
|
return $query->setParameter('unread', true);
|
||||||
|
}
|
||||||
|
|
||||||
|
return parent::buildSavedQueryFromBuiltin($query_key);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function renderResultList(
|
||||||
|
array $notifications,
|
||||||
|
PhabricatorSavedQuery $query,
|
||||||
|
array $handles) {
|
||||||
|
assert_instances_of($notifications, 'PhabricatorFeedStory');
|
||||||
|
|
||||||
|
$viewer = $this->requireViewer();
|
||||||
|
|
||||||
|
$image = id(new PHUIIconView())
|
||||||
|
->setIconFont('fa-eye-slash');
|
||||||
|
|
||||||
|
$button = id(new PHUIButtonView())
|
||||||
|
->setTag('a')
|
||||||
|
->addSigil('workflow')
|
||||||
|
->setColor(PHUIButtonView::SIMPLE)
|
||||||
|
->setIcon($image)
|
||||||
|
->setText(pht('Mark All Read'));
|
||||||
|
|
||||||
|
switch ($query->getQueryKey()) {
|
||||||
|
case 'unread':
|
||||||
|
$header = pht('Unread Notifications');
|
||||||
|
$no_data = pht('You have no unread notifications.');
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$header = pht('Notifications');
|
||||||
|
$no_data = pht('You have no notifications.');
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
$clear_uri = id(new PhutilURI('/notification/clear/'));
|
||||||
|
if ($notifications) {
|
||||||
|
$builder = id(new PhabricatorNotificationBuilder($notifications))
|
||||||
|
->setUser($viewer);
|
||||||
|
|
||||||
|
$view = $builder->buildView();
|
||||||
|
$clear_uri->setQueryParam(
|
||||||
|
'chronoKey',
|
||||||
|
head($notifications)->getChronologicalKey());
|
||||||
|
} else {
|
||||||
|
$view = phutil_tag_div(
|
||||||
|
'phabricator-notification no-notifications',
|
||||||
|
$no_data);
|
||||||
|
$button->setDisabled(true);
|
||||||
|
}
|
||||||
|
$button->setHref((string)$clear_uri);
|
||||||
|
|
||||||
|
$view = id(new PHUIBoxView())
|
||||||
|
->addPadding(PHUI::PADDING_MEDIUM)
|
||||||
|
->addClass('phabricator-notification-list')
|
||||||
|
->appendChild($view);
|
||||||
|
|
||||||
|
$notif_header = id(new PHUIHeaderView())
|
||||||
|
->setHeader($header)
|
||||||
|
->addActionLink($button);
|
||||||
|
|
||||||
|
return id(new PHUIObjectBoxView())
|
||||||
|
->setHeader($notif_header)
|
||||||
|
->appendChild($view);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue