mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-09 22:31:03 +01:00
Expand ApplicationSearch on Calendar
Summary: Ref T7927, Expand ApplicationSearch on Calendar Test Plan: Open Calendar application, month view should be a saved query. Reviewers: epriestley, #blessed_reviewers Reviewed By: epriestley, #blessed_reviewers Subscribers: Korvin, epriestley Maniphest Tasks: T7927 Differential Revision: https://secure.phabricator.com/D12659
This commit is contained in:
parent
5b0aa49800
commit
52a461a75c
5 changed files with 97 additions and 146 deletions
|
@ -1519,7 +1519,6 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorCalendarRemarkupRule' => 'applications/calendar/remarkup/PhabricatorCalendarRemarkupRule.php',
|
'PhabricatorCalendarRemarkupRule' => 'applications/calendar/remarkup/PhabricatorCalendarRemarkupRule.php',
|
||||||
'PhabricatorCalendarReplyHandler' => 'applications/calendar/mail/PhabricatorCalendarReplyHandler.php',
|
'PhabricatorCalendarReplyHandler' => 'applications/calendar/mail/PhabricatorCalendarReplyHandler.php',
|
||||||
'PhabricatorCalendarSchemaSpec' => 'applications/calendar/storage/PhabricatorCalendarSchemaSpec.php',
|
'PhabricatorCalendarSchemaSpec' => 'applications/calendar/storage/PhabricatorCalendarSchemaSpec.php',
|
||||||
'PhabricatorCalendarViewController' => 'applications/calendar/controller/PhabricatorCalendarViewController.php',
|
|
||||||
'PhabricatorCampfireProtocolAdapter' => 'infrastructure/daemon/bot/adapter/PhabricatorCampfireProtocolAdapter.php',
|
'PhabricatorCampfireProtocolAdapter' => 'infrastructure/daemon/bot/adapter/PhabricatorCampfireProtocolAdapter.php',
|
||||||
'PhabricatorCelerityApplication' => 'applications/celerity/application/PhabricatorCelerityApplication.php',
|
'PhabricatorCelerityApplication' => 'applications/celerity/application/PhabricatorCelerityApplication.php',
|
||||||
'PhabricatorCelerityTestCase' => '__tests__/PhabricatorCelerityTestCase.php',
|
'PhabricatorCelerityTestCase' => '__tests__/PhabricatorCelerityTestCase.php',
|
||||||
|
@ -4874,7 +4873,6 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorCalendarRemarkupRule' => 'PhabricatorObjectRemarkupRule',
|
'PhabricatorCalendarRemarkupRule' => 'PhabricatorObjectRemarkupRule',
|
||||||
'PhabricatorCalendarReplyHandler' => 'PhabricatorApplicationTransactionReplyHandler',
|
'PhabricatorCalendarReplyHandler' => 'PhabricatorApplicationTransactionReplyHandler',
|
||||||
'PhabricatorCalendarSchemaSpec' => 'PhabricatorConfigSchemaSpec',
|
'PhabricatorCalendarSchemaSpec' => 'PhabricatorConfigSchemaSpec',
|
||||||
'PhabricatorCalendarViewController' => 'PhabricatorCalendarController',
|
|
||||||
'PhabricatorCampfireProtocolAdapter' => 'PhabricatorBotBaseStreamingProtocolAdapter',
|
'PhabricatorCampfireProtocolAdapter' => 'PhabricatorBotBaseStreamingProtocolAdapter',
|
||||||
'PhabricatorCelerityApplication' => 'PhabricatorApplication',
|
'PhabricatorCelerityApplication' => 'PhabricatorApplication',
|
||||||
'PhabricatorCelerityTestCase' => 'PhabricatorTestCase',
|
'PhabricatorCelerityTestCase' => 'PhabricatorTestCase',
|
||||||
|
|
|
@ -42,11 +42,9 @@ final class PhabricatorCalendarApplication extends PhabricatorApplication {
|
||||||
return array(
|
return array(
|
||||||
'/E(?P<id>[1-9]\d*)' => 'PhabricatorCalendarEventViewController',
|
'/E(?P<id>[1-9]\d*)' => 'PhabricatorCalendarEventViewController',
|
||||||
'/calendar/' => array(
|
'/calendar/' => array(
|
||||||
'' => 'PhabricatorCalendarViewController',
|
|
||||||
'all/' => 'PhabricatorCalendarBrowseController',
|
|
||||||
'event/' => array(
|
|
||||||
'(?:query/(?P<queryKey>[^/]+)/)?'
|
'(?:query/(?P<queryKey>[^/]+)/)?'
|
||||||
=> 'PhabricatorCalendarEventListController',
|
=> 'PhabricatorCalendarEventListController',
|
||||||
|
'event/' => array(
|
||||||
'create/'
|
'create/'
|
||||||
=> 'PhabricatorCalendarEventEditController',
|
=> 'PhabricatorCalendarEventEditController',
|
||||||
'edit/(?P<id>[1-9]\d*)/'
|
'edit/(?P<id>[1-9]\d*)/'
|
||||||
|
|
|
@ -2,27 +2,6 @@
|
||||||
|
|
||||||
abstract class PhabricatorCalendarController extends PhabricatorController {
|
abstract class PhabricatorCalendarController extends PhabricatorController {
|
||||||
|
|
||||||
|
|
||||||
protected function buildSideNavView(PhabricatorCalendarEvent $status = null) {
|
|
||||||
$nav = new AphrontSideNavFilterView();
|
|
||||||
$nav->setBaseURI(new PhutilURI($this->getApplicationURI()));
|
|
||||||
|
|
||||||
$nav->addLabel(pht('Calendar'));
|
|
||||||
$nav->addFilter('/', pht('My Events'));
|
|
||||||
$nav->addFilter('all/', pht('View All'));
|
|
||||||
|
|
||||||
if ($status && $status->getID()) {
|
|
||||||
$nav->addFilter('event/edit/'.$status->getID().'/', pht('Edit Event'));
|
|
||||||
}
|
|
||||||
$nav->addFilter('event/', pht('Upcoming Events'));
|
|
||||||
|
|
||||||
return $nav;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function buildApplicationMenu() {
|
|
||||||
return $this->buildSideNavView()->getMenu();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function buildApplicationCrumbs() {
|
protected function buildApplicationCrumbs() {
|
||||||
$crumbs = parent::buildApplicationCrumbs();
|
$crumbs = parent::buildApplicationCrumbs();
|
||||||
|
|
||||||
|
|
|
@ -1,116 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
final class PhabricatorCalendarViewController
|
|
||||||
extends PhabricatorCalendarController {
|
|
||||||
|
|
||||||
public function shouldAllowPublic() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function handleRequest(AphrontRequest $request) {
|
|
||||||
$viewer = $this->getViewer();
|
|
||||||
|
|
||||||
$now = time();
|
|
||||||
$request = $this->getRequest();
|
|
||||||
$year_d = phabricator_format_local_time($now, $viewer, 'Y');
|
|
||||||
$year = $request->getInt('year', $year_d);
|
|
||||||
$month_d = phabricator_format_local_time($now, $viewer, 'm');
|
|
||||||
$month = $request->getInt('month', $month_d);
|
|
||||||
$day = phabricator_format_local_time($now, $viewer, 'j');
|
|
||||||
|
|
||||||
|
|
||||||
$holidays = id(new PhabricatorCalendarHoliday())->loadAllWhere(
|
|
||||||
'day BETWEEN %s AND %s',
|
|
||||||
"{$year}-{$month}-01",
|
|
||||||
"{$year}-{$month}-31");
|
|
||||||
|
|
||||||
$statuses = id(new PhabricatorCalendarEventQuery())
|
|
||||||
->setViewer($viewer)
|
|
||||||
->withInvitedPHIDs(array($viewer->getPHID()))
|
|
||||||
->withDateRange(
|
|
||||||
strtotime("{$year}-{$month}-01"),
|
|
||||||
strtotime("{$year}-{$month}-01 next month"))
|
|
||||||
->execute();
|
|
||||||
|
|
||||||
if ($month == $month_d && $year == $year_d) {
|
|
||||||
$month_view = new PHUICalendarMonthView($month, $year, $day);
|
|
||||||
} else {
|
|
||||||
$month_view = new PHUICalendarMonthView($month, $year);
|
|
||||||
}
|
|
||||||
|
|
||||||
$month_view->setBrowseURI($request->getRequestURI());
|
|
||||||
$month_view->setUser($viewer);
|
|
||||||
$month_view->setHolidays($holidays);
|
|
||||||
if ($this->getNoticeView()) {
|
|
||||||
$month_view->setInfoView($this->getNoticeView());
|
|
||||||
}
|
|
||||||
|
|
||||||
$phids = mpull($statuses, 'getUserPHID');
|
|
||||||
$handles = $this->loadViewerHandles($phids);
|
|
||||||
|
|
||||||
foreach ($statuses as $status) {
|
|
||||||
$event = new AphrontCalendarEventView();
|
|
||||||
$event->setEpochRange($status->getDateFrom(), $status->getDateTo());
|
|
||||||
$event->setUserPHID($status->getUserPHID());
|
|
||||||
$event->setName($status->getHumanStatus());
|
|
||||||
$event->setDescription($status->getDescription());
|
|
||||||
$event->setEventID($status->getID());
|
|
||||||
$month_view->addEvent($event);
|
|
||||||
}
|
|
||||||
|
|
||||||
$date = new DateTime("{$year}-{$month}-01");
|
|
||||||
$crumbs = $this->buildApplicationCrumbs();
|
|
||||||
$crumbs->addTextCrumb(pht('My Events'));
|
|
||||||
$crumbs->addTextCrumb($date->format('F Y'));
|
|
||||||
|
|
||||||
$nav = $this->buildSideNavView();
|
|
||||||
$nav->selectFilter('/');
|
|
||||||
$nav->appendChild(
|
|
||||||
array(
|
|
||||||
$crumbs,
|
|
||||||
$month_view,
|
|
||||||
));
|
|
||||||
|
|
||||||
return $this->buildApplicationPage(
|
|
||||||
$nav,
|
|
||||||
array(
|
|
||||||
'title' => pht('Calendar'),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
private function getNoticeView() {
|
|
||||||
$request = $this->getRequest();
|
|
||||||
$view = null;
|
|
||||||
|
|
||||||
if ($request->getExists('created')) {
|
|
||||||
$view = id(new PHUIInfoView())
|
|
||||||
->setSeverity(PHUIInfoView::SEVERITY_NOTICE)
|
|
||||||
->appendChild(pht('Successfully created your status.'));
|
|
||||||
} else if ($request->getExists('updated')) {
|
|
||||||
$view = id(new PHUIInfoView())
|
|
||||||
->setSeverity(PHUIInfoView::SEVERITY_NOTICE)
|
|
||||||
->appendChild(pht('Successfully updated your status.'));
|
|
||||||
} else if ($request->getExists('deleted')) {
|
|
||||||
$view = id(new PHUIInfoView())
|
|
||||||
->setSeverity(PHUIInfoView::SEVERITY_NOTICE)
|
|
||||||
->appendChild(pht('Successfully deleted your status.'));
|
|
||||||
} else if (!$request->getUser()->isLoggedIn()) {
|
|
||||||
$login_uri = id(new PhutilURI('/auth/start/'))
|
|
||||||
->setQueryParam('next', '/calendar/');
|
|
||||||
$view = id(new PHUIInfoView())
|
|
||||||
->setSeverity(PHUIInfoView::SEVERITY_NOTICE)
|
|
||||||
->appendChild(
|
|
||||||
pht(
|
|
||||||
'You are not logged in. %s to see your calendar events.',
|
|
||||||
phutil_tag(
|
|
||||||
'a',
|
|
||||||
array(
|
|
||||||
'href' => $login_uri,
|
|
||||||
),
|
|
||||||
pht('Log in'))));
|
|
||||||
}
|
|
||||||
|
|
||||||
return $view;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -38,6 +38,10 @@ final class PhabricatorCalendarEventSearchEngine
|
||||||
'isCancelled',
|
'isCancelled',
|
||||||
$request->getStr('isCancelled'));
|
$request->getStr('isCancelled'));
|
||||||
|
|
||||||
|
$saved->setParameter(
|
||||||
|
'display',
|
||||||
|
$request->getStr('display'));
|
||||||
|
|
||||||
return $saved;
|
return $saved;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,6 +102,7 @@ final class PhabricatorCalendarEventSearchEngine
|
||||||
$range_end = $saved->getParameter('rangeEnd');
|
$range_end = $saved->getParameter('rangeEnd');
|
||||||
$upcoming = $saved->getParameter('upcoming');
|
$upcoming = $saved->getParameter('upcoming');
|
||||||
$is_cancelled = $saved->getParameter('isCancelled', 'active');
|
$is_cancelled = $saved->getParameter('isCancelled', 'active');
|
||||||
|
$display = $saved->getParameter('display', 'month');
|
||||||
|
|
||||||
$invited_phids = $saved->getParameter('invitedPHIDs', array());
|
$invited_phids = $saved->getParameter('invitedPHIDs', array());
|
||||||
$creator_phids = $saved->getParameter('creatorPHIDs', array());
|
$creator_phids = $saved->getParameter('creatorPHIDs', array());
|
||||||
|
@ -106,6 +111,10 @@ final class PhabricatorCalendarEventSearchEngine
|
||||||
'cancelled' => pht('Cancelled Events Only'),
|
'cancelled' => pht('Cancelled Events Only'),
|
||||||
'both' => pht('Both Cancelled and Active Events'),
|
'both' => pht('Both Cancelled and Active Events'),
|
||||||
);
|
);
|
||||||
|
$display_options = array(
|
||||||
|
'month' => pht('Month View'),
|
||||||
|
'list' => pht('List View'),
|
||||||
|
);
|
||||||
|
|
||||||
$form
|
$form
|
||||||
->appendControl(
|
->appendControl(
|
||||||
|
@ -146,15 +155,22 @@ final class PhabricatorCalendarEventSearchEngine
|
||||||
->setLabel(pht('Cancelled Events'))
|
->setLabel(pht('Cancelled Events'))
|
||||||
->setName('isCancelled')
|
->setName('isCancelled')
|
||||||
->setValue($is_cancelled)
|
->setValue($is_cancelled)
|
||||||
->setOptions($resolution_types));
|
->setOptions($resolution_types))
|
||||||
|
->appendChild(
|
||||||
|
id(new AphrontFormSelectControl())
|
||||||
|
->setLabel(pht('Display Options'))
|
||||||
|
->setName('display')
|
||||||
|
->setValue($display)
|
||||||
|
->setOptions($display_options));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getURI($path) {
|
protected function getURI($path) {
|
||||||
return '/calendar/event/'.$path;
|
return '/calendar/'.$path;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getBuiltinQueryNames() {
|
protected function getBuiltinQueryNames() {
|
||||||
$names = array(
|
$names = array(
|
||||||
|
'month' => pht('Month View'),
|
||||||
'upcoming' => pht('Upcoming Events'),
|
'upcoming' => pht('Upcoming Events'),
|
||||||
'all' => pht('All Events'),
|
'all' => pht('All Events'),
|
||||||
);
|
);
|
||||||
|
@ -167,6 +183,8 @@ final class PhabricatorCalendarEventSearchEngine
|
||||||
$query->setQueryKey($query_key);
|
$query->setQueryKey($query_key);
|
||||||
|
|
||||||
switch ($query_key) {
|
switch ($query_key) {
|
||||||
|
case 'month':
|
||||||
|
return $query->setParameter('display', 'month');
|
||||||
case 'upcoming':
|
case 'upcoming':
|
||||||
return $query->setParameter('upcoming', true);
|
return $query->setParameter('upcoming', true);
|
||||||
case 'all':
|
case 'all':
|
||||||
|
@ -190,6 +208,11 @@ final class PhabricatorCalendarEventSearchEngine
|
||||||
array $events,
|
array $events,
|
||||||
PhabricatorSavedQuery $query,
|
PhabricatorSavedQuery $query,
|
||||||
array $handles) {
|
array $handles) {
|
||||||
|
|
||||||
|
if ($query->getParameter('display') == 'month') {
|
||||||
|
return $this->buildCalendarView($events, $query, $handles);
|
||||||
|
}
|
||||||
|
|
||||||
assert_instances_of($events, 'PhabricatorCalendarEvent');
|
assert_instances_of($events, 'PhabricatorCalendarEvent');
|
||||||
$viewer = $this->requireViewer();
|
$viewer = $this->requireViewer();
|
||||||
$list = new PHUIObjectItemListView();
|
$list = new PHUIObjectItemListView();
|
||||||
|
@ -222,4 +245,73 @@ final class PhabricatorCalendarEventSearchEngine
|
||||||
return $list;
|
return $list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function buildCalendarView(
|
||||||
|
array $statuses,
|
||||||
|
PhabricatorSavedQuery $query,
|
||||||
|
array $handles) {
|
||||||
|
$viewer = $this->requireViewer();
|
||||||
|
$now = time();
|
||||||
|
|
||||||
|
$epoch = $query->getParameter('rangeStart');
|
||||||
|
if (!$epoch) {
|
||||||
|
$epoch = $query->getParameter('rangeEnd');
|
||||||
|
if (!$epoch) {
|
||||||
|
$epoch = time();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$year = phabricator_format_local_time($epoch, $viewer, 'Y');
|
||||||
|
$month = phabricator_format_local_time($epoch, $viewer, 'm');
|
||||||
|
|
||||||
|
$now_year = phabricator_format_local_time($now, $viewer, 'Y');
|
||||||
|
$now_month = phabricator_format_local_time($now, $viewer, 'm');
|
||||||
|
$now_day = phabricator_format_local_time($now, $viewer, 'j');
|
||||||
|
|
||||||
|
if ($month == $now_month && $year == $now_year) {
|
||||||
|
$month_view = new PHUICalendarMonthView($month, $year, $now_day);
|
||||||
|
} else {
|
||||||
|
$month_view = new PHUICalendarMonthView($month, $year);
|
||||||
|
}
|
||||||
|
|
||||||
|
$month_view->setUser($viewer);
|
||||||
|
|
||||||
|
$phids = mpull($statuses, 'getUserPHID');
|
||||||
|
|
||||||
|
/* Assign Colors */
|
||||||
|
$unique = array_unique($phids);
|
||||||
|
$allblue = false;
|
||||||
|
$calcolors = CalendarColors::getColors();
|
||||||
|
if (count($unique) > count($calcolors)) {
|
||||||
|
$allblue = true;
|
||||||
|
}
|
||||||
|
$i = 0;
|
||||||
|
$eventcolor = array();
|
||||||
|
foreach ($unique as $phid) {
|
||||||
|
if ($allblue) {
|
||||||
|
$eventcolor[$phid] = CalendarColors::COLOR_SKY;
|
||||||
|
} else {
|
||||||
|
$eventcolor[$phid] = $calcolors[$i];
|
||||||
|
}
|
||||||
|
$i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($statuses as $status) {
|
||||||
|
$event = new AphrontCalendarEventView();
|
||||||
|
$event->setEpochRange($status->getDateFrom(), $status->getDateTo());
|
||||||
|
|
||||||
|
$name_text = $handles[$status->getUserPHID()]->getName();
|
||||||
|
$status_text = $status->getHumanStatus();
|
||||||
|
$event->setUserPHID($status->getUserPHID());
|
||||||
|
$event->setDescription(pht('%s (%s)', $name_text, $status_text));
|
||||||
|
$event->setName($status_text);
|
||||||
|
$event->setEventID($status->getID());
|
||||||
|
$event->setColor($eventcolor[$status->getUserPHID()]);
|
||||||
|
$month_view->addEvent($event);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $month_view;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue