2012-06-11 09:37:06 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorNotificationPanelController
|
|
|
|
extends PhabricatorNotificationController {
|
|
|
|
|
|
|
|
public function processRequest() {
|
|
|
|
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$user = $request->getUser();
|
|
|
|
|
2014-08-16 11:14:32 -07:00
|
|
|
$query = id(new PhabricatorNotificationQuery())
|
|
|
|
->setViewer($user)
|
|
|
|
->withUserPHIDs(array($user->getPHID()))
|
|
|
|
->setLimit(15);
|
2012-06-11 09:37:06 -07:00
|
|
|
|
|
|
|
$stories = $query->execute();
|
|
|
|
|
2014-08-01 16:39:05 -07:00
|
|
|
$clear_ui_class = 'phabricator-notification-clear-all';
|
|
|
|
$clear_uri = id(new PhutilURI('/notification/clear/'));
|
2012-06-17 11:35:18 -07:00
|
|
|
if ($stories) {
|
|
|
|
$builder = new PhabricatorNotificationBuilder($stories);
|
|
|
|
$notifications_view = $builder->buildView();
|
|
|
|
$content = $notifications_view->render();
|
2014-08-01 16:39:05 -07:00
|
|
|
$clear_uri->setQueryParam(
|
|
|
|
'chronoKey',
|
|
|
|
head($stories)->getChronologicalKey());
|
2012-06-17 11:35:18 -07:00
|
|
|
} else {
|
2013-11-11 09:23:23 -08:00
|
|
|
$content = phutil_tag_div(
|
|
|
|
'phabricator-notification no-notifications',
|
2013-02-13 14:50:15 -08:00
|
|
|
pht('You have no notifications.'));
|
2014-08-01 16:39:05 -07:00
|
|
|
$clear_ui_class .= ' disabled';
|
2012-06-11 17:49:32 -07:00
|
|
|
}
|
2014-08-01 16:39:05 -07:00
|
|
|
$clear_ui = javelin_tag(
|
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'sigil' => 'workflow',
|
2015-05-20 07:06:07 +10:00
|
|
|
'href' => (string)$clear_uri,
|
2014-08-01 16:39:05 -07:00
|
|
|
'class' => $clear_ui_class,
|
|
|
|
),
|
|
|
|
pht('Mark All Read'));
|
2012-06-11 17:49:32 -07:00
|
|
|
|
2014-06-23 16:26:16 -07:00
|
|
|
$notifications_link = phutil_tag(
|
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'href' => '/notification/',
|
|
|
|
),
|
|
|
|
pht('Notifications'));
|
|
|
|
|
2014-08-14 17:19:01 -07:00
|
|
|
if (PhabricatorEnv::getEnvConfig('notification.enabled')) {
|
|
|
|
$connection_status = new PhabricatorNotificationStatusView();
|
|
|
|
} else {
|
|
|
|
$connection_status = phutil_tag(
|
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'href' => PhabricatorEnv::getDoclink(
|
|
|
|
'Notifications User Guide: Setup and Configuration'),
|
|
|
|
),
|
|
|
|
pht('Notification Server not enabled.'));
|
|
|
|
}
|
|
|
|
$connection_ui = phutil_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
2014-10-08 00:01:04 +11:00
|
|
|
'class' => 'phabricator-notification-footer',
|
2014-08-14 17:19:01 -07:00
|
|
|
),
|
|
|
|
$connection_status);
|
2014-06-23 16:26:16 -07:00
|
|
|
|
|
|
|
$header = phutil_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'class' => 'phabricator-notification-header',
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
$notifications_link,
|
2014-08-14 17:19:01 -07:00
|
|
|
$clear_ui,
|
2014-06-23 16:26:16 -07:00
|
|
|
));
|
|
|
|
|
2013-02-13 14:50:15 -08:00
|
|
|
$content = hsprintf(
|
2014-08-14 17:19:01 -07:00
|
|
|
'%s%s%s',
|
2014-06-23 16:26:16 -07:00
|
|
|
$header,
|
|
|
|
$content,
|
2014-08-14 17:19:01 -07:00
|
|
|
$connection_ui);
|
2012-06-18 14:07:38 -07:00
|
|
|
|
2012-06-20 13:20:41 -07:00
|
|
|
$unread_count = id(new PhabricatorFeedStoryNotification())
|
|
|
|
->countUnread($user);
|
|
|
|
|
2012-06-11 09:37:06 -07:00
|
|
|
$json = array(
|
2012-06-17 11:35:18 -07:00
|
|
|
'content' => $content,
|
2013-05-21 15:44:44 -07:00
|
|
|
'number' => (int)$unread_count,
|
2012-06-11 09:37:06 -07:00
|
|
|
);
|
|
|
|
|
|
|
|
return id(new AphrontAjaxResponse())->setContent($json);
|
|
|
|
}
|
|
|
|
}
|