1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-09-20 09:18:48 +02:00

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
This commit is contained in:
epriestley 2016-10-26 12:49:59 -07:00
parent 7cb44bcee6
commit 4c3f09a6a6
3 changed files with 78 additions and 6 deletions

View file

@ -3,6 +3,10 @@
final class PhabricatorCalendarEventListController
extends PhabricatorCalendarController {
private $viewYear;
private $viewMonth;
private $viewDay;
public function shouldAllowPublic() {
return true;
}
@ -16,6 +20,10 @@ final class PhabricatorCalendarEventListController
$month = $request->getURIData('month');
$day = $request->getURIData('day');
$this->viewYear = $year;
$this->viewMonth = $month;
$this->viewDay = $day;
$engine = new PhabricatorCalendarEventSearchEngine();
if ($month && $year) {
@ -33,9 +41,36 @@ final class PhabricatorCalendarEventListController
protected function buildApplicationCrumbs() {
$crumbs = parent::buildApplicationCrumbs();
$viewer = $this->getViewer();
$year = $this->viewYear;
$month = $this->viewMonth;
$day = $this->viewDay;
$parameters = array();
// If the viewer clicks "Create Event" while on a particular day view,
// default the times to that day.
if ($year && $month && $day) {
$datetimes = PhabricatorCalendarEvent::newDefaultEventDateTimes(
$viewer,
PhabricatorTime::getNow());
foreach ($datetimes as $datetime) {
$datetime
->setYear($year)
->setMonth($month)
->setDay($day);
}
list($start, $end) = $datetimes;
$parameters['start'] = $start->getEpoch();
$parameters['end'] = $end->getEpoch();
}
id(new PhabricatorCalendarEventEditEngine())
->setViewer($this->getViewer())
->addActionToCrumbs($crumbs);
->addActionToCrumbs($crumbs, $parameters);
return $crumbs;
}

View file

@ -75,10 +75,10 @@ final class PhabricatorCalendarEvent extends PhabricatorCalendarDAO
$default_icon = 'fa-calendar';
$datetime_start = PhutilCalendarAbsoluteDateTime::newFromEpoch(
$now,
$actor->getTimezoneIdentifier());
$datetime_end = $datetime_start->newRelativeDateTime('PT1H');
$datetime_defaults = self::newDefaultEventDateTimes(
$actor,
$now);
list($datetime_start, $datetime_end) = $datetime_defaults;
return id(new PhabricatorCalendarEvent())
->setDescription('')
@ -102,6 +102,31 @@ final class PhabricatorCalendarEvent extends PhabricatorCalendarDAO
->applyViewerTimezone($actor);
}
public static function newDefaultEventDateTimes(
PhabricatorUser $viewer,
$now) {
$datetime_start = PhutilCalendarAbsoluteDateTime::newFromEpoch(
$now,
$viewer->getTimezoneIdentifier());
// Advance the time by an hour, then round downwards to the nearest hour.
// For example, if it is currently 3:25 PM, we suggest a default start time
// of 4 PM.
$datetime_start = $datetime_start
->newRelativeDateTime('PT1H')
->newAbsoluteDateTime();
$datetime_start->setMinute(0);
$datetime_start->setSecond(0);
// Default the end time to an hour after the start time.
$datetime_end = $datetime_start
->newRelativeDateTime('PT1H')
->newAbsoluteDateTime();
return array($datetime_start, $datetime_end);
}
private function newChild(
PhabricatorUser $actor,
$sequence,

View file

@ -1349,7 +1349,9 @@ abstract class PhabricatorEditEngine
}
final public function addActionToCrumbs(PHUICrumbsView $crumbs) {
final public function addActionToCrumbs(
PHUICrumbsView $crumbs,
array $parameters = array()) {
$viewer = $this->getViewer();
$can_create = $this->hasCreateCapability();
@ -1385,6 +1387,11 @@ abstract class PhabricatorEditEngine
$form_key = $config->getIdentifier();
$create_uri = $this->getEditURI(null, "form/{$form_key}/");
if ($parameters) {
$create_uri = (string)id(new PhutilURI($create_uri))
->setQueryParams($parameters);
}
if (count($configs) > 1) {
$menu_icon = 'fa-caret-square-o-down';
@ -1395,6 +1402,11 @@ abstract class PhabricatorEditEngine
$form_key = $config->getIdentifier();
$config_uri = $this->getEditURI(null, "form/{$form_key}/");
if ($parameters) {
$config_uri = (string)id(new PhutilURI($config_uri))
->setQueryParams($parameters);
}
$item_icon = 'fa-plus';
$dropdown->addAction(