@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.

Suggest better start/end datetimes for Calendar events

Summary:
Fixes T11638.

- Fix a regression: I broke this "round to the nearest hour" code a while ago while fiddling with datetimes.
- Improve a beahvior: from the day view, make the menu-bar "Create Event" button default to creating an event on the day you were viewing.

Test Plan: Created events from month and day views, got nice round numbers and proper day suggestions.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T11638

Differential Revision: https://secure.phabricator.com/D16754

+78 -6
+36 -1
src/applications/calendar/controller/PhabricatorCalendarEventListController.php
··· 3 3 final class PhabricatorCalendarEventListController 4 4 extends PhabricatorCalendarController { 5 5 6 + private $viewYear; 7 + private $viewMonth; 8 + private $viewDay; 9 + 6 10 public function shouldAllowPublic() { 7 11 return true; 8 12 } ··· 16 20 $month = $request->getURIData('month'); 17 21 $day = $request->getURIData('day'); 18 22 23 + $this->viewYear = $year; 24 + $this->viewMonth = $month; 25 + $this->viewDay = $day; 26 + 19 27 $engine = new PhabricatorCalendarEventSearchEngine(); 20 28 21 29 if ($month && $year) { ··· 33 41 protected function buildApplicationCrumbs() { 34 42 $crumbs = parent::buildApplicationCrumbs(); 35 43 44 + $viewer = $this->getViewer(); 45 + 46 + $year = $this->viewYear; 47 + $month = $this->viewMonth; 48 + $day = $this->viewDay; 49 + 50 + $parameters = array(); 51 + 52 + // If the viewer clicks "Create Event" while on a particular day view, 53 + // default the times to that day. 54 + if ($year && $month && $day) { 55 + $datetimes = PhabricatorCalendarEvent::newDefaultEventDateTimes( 56 + $viewer, 57 + PhabricatorTime::getNow()); 58 + 59 + foreach ($datetimes as $datetime) { 60 + $datetime 61 + ->setYear($year) 62 + ->setMonth($month) 63 + ->setDay($day); 64 + } 65 + 66 + list($start, $end) = $datetimes; 67 + $parameters['start'] = $start->getEpoch(); 68 + $parameters['end'] = $end->getEpoch(); 69 + } 70 + 36 71 id(new PhabricatorCalendarEventEditEngine()) 37 72 ->setViewer($this->getViewer()) 38 - ->addActionToCrumbs($crumbs); 73 + ->addActionToCrumbs($crumbs, $parameters); 39 74 40 75 return $crumbs; 41 76 }
+29 -4
src/applications/calendar/storage/PhabricatorCalendarEvent.php
··· 75 75 76 76 $default_icon = 'fa-calendar'; 77 77 78 - $datetime_start = PhutilCalendarAbsoluteDateTime::newFromEpoch( 79 - $now, 80 - $actor->getTimezoneIdentifier()); 81 - $datetime_end = $datetime_start->newRelativeDateTime('PT1H'); 78 + $datetime_defaults = self::newDefaultEventDateTimes( 79 + $actor, 80 + $now); 81 + list($datetime_start, $datetime_end) = $datetime_defaults; 82 82 83 83 return id(new PhabricatorCalendarEvent()) 84 84 ->setDescription('') ··· 100 100 ->setEndDateTime($datetime_end) 101 101 ->attachImportSource(null) 102 102 ->applyViewerTimezone($actor); 103 + } 104 + 105 + public static function newDefaultEventDateTimes( 106 + PhabricatorUser $viewer, 107 + $now) { 108 + 109 + $datetime_start = PhutilCalendarAbsoluteDateTime::newFromEpoch( 110 + $now, 111 + $viewer->getTimezoneIdentifier()); 112 + 113 + // Advance the time by an hour, then round downwards to the nearest hour. 114 + // For example, if it is currently 3:25 PM, we suggest a default start time 115 + // of 4 PM. 116 + $datetime_start = $datetime_start 117 + ->newRelativeDateTime('PT1H') 118 + ->newAbsoluteDateTime(); 119 + $datetime_start->setMinute(0); 120 + $datetime_start->setSecond(0); 121 + 122 + // Default the end time to an hour after the start time. 123 + $datetime_end = $datetime_start 124 + ->newRelativeDateTime('PT1H') 125 + ->newAbsoluteDateTime(); 126 + 127 + return array($datetime_start, $datetime_end); 103 128 } 104 129 105 130 private function newChild(
+13 -1
src/applications/transactions/editengine/PhabricatorEditEngine.php
··· 1349 1349 } 1350 1350 1351 1351 1352 - final public function addActionToCrumbs(PHUICrumbsView $crumbs) { 1352 + final public function addActionToCrumbs( 1353 + PHUICrumbsView $crumbs, 1354 + array $parameters = array()) { 1353 1355 $viewer = $this->getViewer(); 1354 1356 1355 1357 $can_create = $this->hasCreateCapability(); ··· 1385 1387 $form_key = $config->getIdentifier(); 1386 1388 $create_uri = $this->getEditURI(null, "form/{$form_key}/"); 1387 1389 1390 + if ($parameters) { 1391 + $create_uri = (string)id(new PhutilURI($create_uri)) 1392 + ->setQueryParams($parameters); 1393 + } 1394 + 1388 1395 if (count($configs) > 1) { 1389 1396 $menu_icon = 'fa-caret-square-o-down'; 1390 1397 ··· 1394 1401 foreach ($configs as $config) { 1395 1402 $form_key = $config->getIdentifier(); 1396 1403 $config_uri = $this->getEditURI(null, "form/{$form_key}/"); 1404 + 1405 + if ($parameters) { 1406 + $config_uri = (string)id(new PhutilURI($config_uri)) 1407 + ->setQueryParams($parameters); 1408 + } 1397 1409 1398 1410 $item_icon = 'fa-plus'; 1399 1411