diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -1519,7 +1519,6 @@ 'PhabricatorCalendarRemarkupRule' => 'applications/calendar/remarkup/PhabricatorCalendarRemarkupRule.php', 'PhabricatorCalendarReplyHandler' => 'applications/calendar/mail/PhabricatorCalendarReplyHandler.php', 'PhabricatorCalendarSchemaSpec' => 'applications/calendar/storage/PhabricatorCalendarSchemaSpec.php', - 'PhabricatorCalendarViewController' => 'applications/calendar/controller/PhabricatorCalendarViewController.php', 'PhabricatorCampfireProtocolAdapter' => 'infrastructure/daemon/bot/adapter/PhabricatorCampfireProtocolAdapter.php', 'PhabricatorCelerityApplication' => 'applications/celerity/application/PhabricatorCelerityApplication.php', 'PhabricatorCelerityTestCase' => '__tests__/PhabricatorCelerityTestCase.php', @@ -4874,7 +4873,6 @@ 'PhabricatorCalendarRemarkupRule' => 'PhabricatorObjectRemarkupRule', 'PhabricatorCalendarReplyHandler' => 'PhabricatorApplicationTransactionReplyHandler', 'PhabricatorCalendarSchemaSpec' => 'PhabricatorConfigSchemaSpec', - 'PhabricatorCalendarViewController' => 'PhabricatorCalendarController', 'PhabricatorCampfireProtocolAdapter' => 'PhabricatorBotBaseStreamingProtocolAdapter', 'PhabricatorCelerityApplication' => 'PhabricatorApplication', 'PhabricatorCelerityTestCase' => 'PhabricatorTestCase', diff --git a/src/applications/calendar/application/PhabricatorCalendarApplication.php b/src/applications/calendar/application/PhabricatorCalendarApplication.php --- a/src/applications/calendar/application/PhabricatorCalendarApplication.php +++ b/src/applications/calendar/application/PhabricatorCalendarApplication.php @@ -42,11 +42,9 @@ return array( '/E(?P[1-9]\d*)' => 'PhabricatorCalendarEventViewController', '/calendar/' => array( - '' => 'PhabricatorCalendarViewController', - 'all/' => 'PhabricatorCalendarBrowseController', + '(?:query/(?P[^/]+)/)?' + => 'PhabricatorCalendarEventListController', 'event/' => array( - '(?:query/(?P[^/]+)/)?' - => 'PhabricatorCalendarEventListController', 'create/' => 'PhabricatorCalendarEventEditController', 'edit/(?P[1-9]\d*)/' diff --git a/src/applications/calendar/controller/PhabricatorCalendarController.php b/src/applications/calendar/controller/PhabricatorCalendarController.php --- a/src/applications/calendar/controller/PhabricatorCalendarController.php +++ b/src/applications/calendar/controller/PhabricatorCalendarController.php @@ -2,27 +2,6 @@ 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() { $crumbs = parent::buildApplicationCrumbs(); diff --git a/src/applications/calendar/controller/PhabricatorCalendarViewController.php b/src/applications/calendar/controller/PhabricatorCalendarViewController.php deleted file mode 100644 --- a/src/applications/calendar/controller/PhabricatorCalendarViewController.php +++ /dev/null @@ -1,116 +0,0 @@ -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; - } - -} diff --git a/src/applications/calendar/query/PhabricatorCalendarEventSearchEngine.php b/src/applications/calendar/query/PhabricatorCalendarEventSearchEngine.php --- a/src/applications/calendar/query/PhabricatorCalendarEventSearchEngine.php +++ b/src/applications/calendar/query/PhabricatorCalendarEventSearchEngine.php @@ -38,6 +38,10 @@ 'isCancelled', $request->getStr('isCancelled')); + $saved->setParameter( + 'display', + $request->getStr('display')); + return $saved; } @@ -98,6 +102,7 @@ $range_end = $saved->getParameter('rangeEnd'); $upcoming = $saved->getParameter('upcoming'); $is_cancelled = $saved->getParameter('isCancelled', 'active'); + $display = $saved->getParameter('display', 'month'); $invited_phids = $saved->getParameter('invitedPHIDs', array()); $creator_phids = $saved->getParameter('creatorPHIDs', array()); @@ -106,6 +111,10 @@ 'cancelled' => pht('Cancelled Events Only'), 'both' => pht('Both Cancelled and Active Events'), ); + $display_options = array( + 'month' => pht('Month View'), + 'list' => pht('List View'), + ); $form ->appendControl( @@ -146,17 +155,24 @@ ->setLabel(pht('Cancelled Events')) ->setName('isCancelled') ->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) { - return '/calendar/event/'.$path; + return '/calendar/'.$path; } protected function getBuiltinQueryNames() { $names = array( + 'month' => pht('Month View'), 'upcoming' => pht('Upcoming Events'), - 'all' => pht('All Events'), + 'all' => pht('All Events'), ); return $names; @@ -167,6 +183,8 @@ $query->setQueryKey($query_key); switch ($query_key) { + case 'month': + return $query->setParameter('display', 'month'); case 'upcoming': return $query->setParameter('upcoming', true); case 'all': @@ -190,6 +208,11 @@ array $events, PhabricatorSavedQuery $query, array $handles) { + + if ($query->getParameter('display') == 'month') { + return $this->buildCalendarView($events, $query, $handles); + } + assert_instances_of($events, 'PhabricatorCalendarEvent'); $viewer = $this->requireViewer(); $list = new PHUIObjectItemListView(); @@ -222,4 +245,73 @@ 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; + + + } + }