@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+97 -146
-2
src/__phutil_library_map__.php
··· 1519 1519 'PhabricatorCalendarRemarkupRule' => 'applications/calendar/remarkup/PhabricatorCalendarRemarkupRule.php', 1520 1520 'PhabricatorCalendarReplyHandler' => 'applications/calendar/mail/PhabricatorCalendarReplyHandler.php', 1521 1521 'PhabricatorCalendarSchemaSpec' => 'applications/calendar/storage/PhabricatorCalendarSchemaSpec.php', 1522 - 'PhabricatorCalendarViewController' => 'applications/calendar/controller/PhabricatorCalendarViewController.php', 1523 1522 'PhabricatorCampfireProtocolAdapter' => 'infrastructure/daemon/bot/adapter/PhabricatorCampfireProtocolAdapter.php', 1524 1523 'PhabricatorCelerityApplication' => 'applications/celerity/application/PhabricatorCelerityApplication.php', 1525 1524 'PhabricatorCelerityTestCase' => '__tests__/PhabricatorCelerityTestCase.php', ··· 4874 4873 'PhabricatorCalendarRemarkupRule' => 'PhabricatorObjectRemarkupRule', 4875 4874 'PhabricatorCalendarReplyHandler' => 'PhabricatorApplicationTransactionReplyHandler', 4876 4875 'PhabricatorCalendarSchemaSpec' => 'PhabricatorConfigSchemaSpec', 4877 - 'PhabricatorCalendarViewController' => 'PhabricatorCalendarController', 4878 4876 'PhabricatorCampfireProtocolAdapter' => 'PhabricatorBotBaseStreamingProtocolAdapter', 4879 4877 'PhabricatorCelerityApplication' => 'PhabricatorApplication', 4880 4878 'PhabricatorCelerityTestCase' => 'PhabricatorTestCase',
+2 -4
src/applications/calendar/application/PhabricatorCalendarApplication.php
··· 42 42 return array( 43 43 '/E(?P<id>[1-9]\d*)' => 'PhabricatorCalendarEventViewController', 44 44 '/calendar/' => array( 45 - '' => 'PhabricatorCalendarViewController', 46 - 'all/' => 'PhabricatorCalendarBrowseController', 45 + '(?:query/(?P<queryKey>[^/]+)/)?' 46 + => 'PhabricatorCalendarEventListController', 47 47 'event/' => array( 48 - '(?:query/(?P<queryKey>[^/]+)/)?' 49 - => 'PhabricatorCalendarEventListController', 50 48 'create/' 51 49 => 'PhabricatorCalendarEventEditController', 52 50 'edit/(?P<id>[1-9]\d*)/'
-21
src/applications/calendar/controller/PhabricatorCalendarController.php
··· 2 2 3 3 abstract class PhabricatorCalendarController extends PhabricatorController { 4 4 5 - 6 - protected function buildSideNavView(PhabricatorCalendarEvent $status = null) { 7 - $nav = new AphrontSideNavFilterView(); 8 - $nav->setBaseURI(new PhutilURI($this->getApplicationURI())); 9 - 10 - $nav->addLabel(pht('Calendar')); 11 - $nav->addFilter('/', pht('My Events')); 12 - $nav->addFilter('all/', pht('View All')); 13 - 14 - if ($status && $status->getID()) { 15 - $nav->addFilter('event/edit/'.$status->getID().'/', pht('Edit Event')); 16 - } 17 - $nav->addFilter('event/', pht('Upcoming Events')); 18 - 19 - return $nav; 20 - } 21 - 22 - public function buildApplicationMenu() { 23 - return $this->buildSideNavView()->getMenu(); 24 - } 25 - 26 5 protected function buildApplicationCrumbs() { 27 6 $crumbs = parent::buildApplicationCrumbs(); 28 7
-116
src/applications/calendar/controller/PhabricatorCalendarViewController.php
··· 1 - <?php 2 - 3 - final class PhabricatorCalendarViewController 4 - extends PhabricatorCalendarController { 5 - 6 - public function shouldAllowPublic() { 7 - return true; 8 - } 9 - 10 - public function handleRequest(AphrontRequest $request) { 11 - $viewer = $this->getViewer(); 12 - 13 - $now = time(); 14 - $request = $this->getRequest(); 15 - $year_d = phabricator_format_local_time($now, $viewer, 'Y'); 16 - $year = $request->getInt('year', $year_d); 17 - $month_d = phabricator_format_local_time($now, $viewer, 'm'); 18 - $month = $request->getInt('month', $month_d); 19 - $day = phabricator_format_local_time($now, $viewer, 'j'); 20 - 21 - 22 - $holidays = id(new PhabricatorCalendarHoliday())->loadAllWhere( 23 - 'day BETWEEN %s AND %s', 24 - "{$year}-{$month}-01", 25 - "{$year}-{$month}-31"); 26 - 27 - $statuses = id(new PhabricatorCalendarEventQuery()) 28 - ->setViewer($viewer) 29 - ->withInvitedPHIDs(array($viewer->getPHID())) 30 - ->withDateRange( 31 - strtotime("{$year}-{$month}-01"), 32 - strtotime("{$year}-{$month}-01 next month")) 33 - ->execute(); 34 - 35 - if ($month == $month_d && $year == $year_d) { 36 - $month_view = new PHUICalendarMonthView($month, $year, $day); 37 - } else { 38 - $month_view = new PHUICalendarMonthView($month, $year); 39 - } 40 - 41 - $month_view->setBrowseURI($request->getRequestURI()); 42 - $month_view->setUser($viewer); 43 - $month_view->setHolidays($holidays); 44 - if ($this->getNoticeView()) { 45 - $month_view->setInfoView($this->getNoticeView()); 46 - } 47 - 48 - $phids = mpull($statuses, 'getUserPHID'); 49 - $handles = $this->loadViewerHandles($phids); 50 - 51 - foreach ($statuses as $status) { 52 - $event = new AphrontCalendarEventView(); 53 - $event->setEpochRange($status->getDateFrom(), $status->getDateTo()); 54 - $event->setUserPHID($status->getUserPHID()); 55 - $event->setName($status->getHumanStatus()); 56 - $event->setDescription($status->getDescription()); 57 - $event->setEventID($status->getID()); 58 - $month_view->addEvent($event); 59 - } 60 - 61 - $date = new DateTime("{$year}-{$month}-01"); 62 - $crumbs = $this->buildApplicationCrumbs(); 63 - $crumbs->addTextCrumb(pht('My Events')); 64 - $crumbs->addTextCrumb($date->format('F Y')); 65 - 66 - $nav = $this->buildSideNavView(); 67 - $nav->selectFilter('/'); 68 - $nav->appendChild( 69 - array( 70 - $crumbs, 71 - $month_view, 72 - )); 73 - 74 - return $this->buildApplicationPage( 75 - $nav, 76 - array( 77 - 'title' => pht('Calendar'), 78 - )); 79 - } 80 - 81 - private function getNoticeView() { 82 - $request = $this->getRequest(); 83 - $view = null; 84 - 85 - if ($request->getExists('created')) { 86 - $view = id(new PHUIInfoView()) 87 - ->setSeverity(PHUIInfoView::SEVERITY_NOTICE) 88 - ->appendChild(pht('Successfully created your status.')); 89 - } else if ($request->getExists('updated')) { 90 - $view = id(new PHUIInfoView()) 91 - ->setSeverity(PHUIInfoView::SEVERITY_NOTICE) 92 - ->appendChild(pht('Successfully updated your status.')); 93 - } else if ($request->getExists('deleted')) { 94 - $view = id(new PHUIInfoView()) 95 - ->setSeverity(PHUIInfoView::SEVERITY_NOTICE) 96 - ->appendChild(pht('Successfully deleted your status.')); 97 - } else if (!$request->getUser()->isLoggedIn()) { 98 - $login_uri = id(new PhutilURI('/auth/start/')) 99 - ->setQueryParam('next', '/calendar/'); 100 - $view = id(new PHUIInfoView()) 101 - ->setSeverity(PHUIInfoView::SEVERITY_NOTICE) 102 - ->appendChild( 103 - pht( 104 - 'You are not logged in. %s to see your calendar events.', 105 - phutil_tag( 106 - 'a', 107 - array( 108 - 'href' => $login_uri, 109 - ), 110 - pht('Log in')))); 111 - } 112 - 113 - return $view; 114 - } 115 - 116 - }
+95 -3
src/applications/calendar/query/PhabricatorCalendarEventSearchEngine.php
··· 38 38 'isCancelled', 39 39 $request->getStr('isCancelled')); 40 40 41 + $saved->setParameter( 42 + 'display', 43 + $request->getStr('display')); 44 + 41 45 return $saved; 42 46 } 43 47 ··· 98 102 $range_end = $saved->getParameter('rangeEnd'); 99 103 $upcoming = $saved->getParameter('upcoming'); 100 104 $is_cancelled = $saved->getParameter('isCancelled', 'active'); 105 + $display = $saved->getParameter('display', 'month'); 101 106 102 107 $invited_phids = $saved->getParameter('invitedPHIDs', array()); 103 108 $creator_phids = $saved->getParameter('creatorPHIDs', array()); ··· 106 111 'cancelled' => pht('Cancelled Events Only'), 107 112 'both' => pht('Both Cancelled and Active Events'), 108 113 ); 114 + $display_options = array( 115 + 'month' => pht('Month View'), 116 + 'list' => pht('List View'), 117 + ); 109 118 110 119 $form 111 120 ->appendControl( ··· 146 155 ->setLabel(pht('Cancelled Events')) 147 156 ->setName('isCancelled') 148 157 ->setValue($is_cancelled) 149 - ->setOptions($resolution_types)); 158 + ->setOptions($resolution_types)) 159 + ->appendChild( 160 + id(new AphrontFormSelectControl()) 161 + ->setLabel(pht('Display Options')) 162 + ->setName('display') 163 + ->setValue($display) 164 + ->setOptions($display_options)); 150 165 } 151 166 152 167 protected function getURI($path) { 153 - return '/calendar/event/'.$path; 168 + return '/calendar/'.$path; 154 169 } 155 170 156 171 protected function getBuiltinQueryNames() { 157 172 $names = array( 173 + 'month' => pht('Month View'), 158 174 'upcoming' => pht('Upcoming Events'), 159 - 'all' => pht('All Events'), 175 + 'all' => pht('All Events'), 160 176 ); 161 177 162 178 return $names; ··· 167 183 $query->setQueryKey($query_key); 168 184 169 185 switch ($query_key) { 186 + case 'month': 187 + return $query->setParameter('display', 'month'); 170 188 case 'upcoming': 171 189 return $query->setParameter('upcoming', true); 172 190 case 'all': ··· 190 208 array $events, 191 209 PhabricatorSavedQuery $query, 192 210 array $handles) { 211 + 212 + if ($query->getParameter('display') == 'month') { 213 + return $this->buildCalendarView($events, $query, $handles); 214 + } 215 + 193 216 assert_instances_of($events, 'PhabricatorCalendarEvent'); 194 217 $viewer = $this->requireViewer(); 195 218 $list = new PHUIObjectItemListView(); ··· 220 243 } 221 244 222 245 return $list; 246 + } 247 + 248 + private function buildCalendarView( 249 + array $statuses, 250 + PhabricatorSavedQuery $query, 251 + array $handles) { 252 + $viewer = $this->requireViewer(); 253 + $now = time(); 254 + 255 + $epoch = $query->getParameter('rangeStart'); 256 + if (!$epoch) { 257 + $epoch = $query->getParameter('rangeEnd'); 258 + if (!$epoch) { 259 + $epoch = time(); 260 + } 261 + } 262 + 263 + $year = phabricator_format_local_time($epoch, $viewer, 'Y'); 264 + $month = phabricator_format_local_time($epoch, $viewer, 'm'); 265 + 266 + $now_year = phabricator_format_local_time($now, $viewer, 'Y'); 267 + $now_month = phabricator_format_local_time($now, $viewer, 'm'); 268 + $now_day = phabricator_format_local_time($now, $viewer, 'j'); 269 + 270 + if ($month == $now_month && $year == $now_year) { 271 + $month_view = new PHUICalendarMonthView($month, $year, $now_day); 272 + } else { 273 + $month_view = new PHUICalendarMonthView($month, $year); 274 + } 275 + 276 + $month_view->setUser($viewer); 277 + 278 + $phids = mpull($statuses, 'getUserPHID'); 279 + 280 + /* Assign Colors */ 281 + $unique = array_unique($phids); 282 + $allblue = false; 283 + $calcolors = CalendarColors::getColors(); 284 + if (count($unique) > count($calcolors)) { 285 + $allblue = true; 286 + } 287 + $i = 0; 288 + $eventcolor = array(); 289 + foreach ($unique as $phid) { 290 + if ($allblue) { 291 + $eventcolor[$phid] = CalendarColors::COLOR_SKY; 292 + } else { 293 + $eventcolor[$phid] = $calcolors[$i]; 294 + } 295 + $i++; 296 + } 297 + 298 + foreach ($statuses as $status) { 299 + $event = new AphrontCalendarEventView(); 300 + $event->setEpochRange($status->getDateFrom(), $status->getDateTo()); 301 + 302 + $name_text = $handles[$status->getUserPHID()]->getName(); 303 + $status_text = $status->getHumanStatus(); 304 + $event->setUserPHID($status->getUserPHID()); 305 + $event->setDescription(pht('%s (%s)', $name_text, $status_text)); 306 + $event->setName($status_text); 307 + $event->setEventID($status->getID()); 308 + $event->setColor($eventcolor[$status->getUserPHID()]); 309 + $month_view->addEvent($event); 310 + } 311 + 312 + return $month_view; 313 + 314 + 223 315 } 224 316 225 317 }