mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-18 11:30:55 +01: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:
parent
7cb44bcee6
commit
4c3f09a6a6
3 changed files with 78 additions and 6 deletions
|
@ -3,6 +3,10 @@
|
||||||
final class PhabricatorCalendarEventListController
|
final class PhabricatorCalendarEventListController
|
||||||
extends PhabricatorCalendarController {
|
extends PhabricatorCalendarController {
|
||||||
|
|
||||||
|
private $viewYear;
|
||||||
|
private $viewMonth;
|
||||||
|
private $viewDay;
|
||||||
|
|
||||||
public function shouldAllowPublic() {
|
public function shouldAllowPublic() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -16,6 +20,10 @@ final class PhabricatorCalendarEventListController
|
||||||
$month = $request->getURIData('month');
|
$month = $request->getURIData('month');
|
||||||
$day = $request->getURIData('day');
|
$day = $request->getURIData('day');
|
||||||
|
|
||||||
|
$this->viewYear = $year;
|
||||||
|
$this->viewMonth = $month;
|
||||||
|
$this->viewDay = $day;
|
||||||
|
|
||||||
$engine = new PhabricatorCalendarEventSearchEngine();
|
$engine = new PhabricatorCalendarEventSearchEngine();
|
||||||
|
|
||||||
if ($month && $year) {
|
if ($month && $year) {
|
||||||
|
@ -33,9 +41,36 @@ final class PhabricatorCalendarEventListController
|
||||||
protected function buildApplicationCrumbs() {
|
protected function buildApplicationCrumbs() {
|
||||||
$crumbs = parent::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())
|
id(new PhabricatorCalendarEventEditEngine())
|
||||||
->setViewer($this->getViewer())
|
->setViewer($this->getViewer())
|
||||||
->addActionToCrumbs($crumbs);
|
->addActionToCrumbs($crumbs, $parameters);
|
||||||
|
|
||||||
return $crumbs;
|
return $crumbs;
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,10 +75,10 @@ final class PhabricatorCalendarEvent extends PhabricatorCalendarDAO
|
||||||
|
|
||||||
$default_icon = 'fa-calendar';
|
$default_icon = 'fa-calendar';
|
||||||
|
|
||||||
$datetime_start = PhutilCalendarAbsoluteDateTime::newFromEpoch(
|
$datetime_defaults = self::newDefaultEventDateTimes(
|
||||||
$now,
|
$actor,
|
||||||
$actor->getTimezoneIdentifier());
|
$now);
|
||||||
$datetime_end = $datetime_start->newRelativeDateTime('PT1H');
|
list($datetime_start, $datetime_end) = $datetime_defaults;
|
||||||
|
|
||||||
return id(new PhabricatorCalendarEvent())
|
return id(new PhabricatorCalendarEvent())
|
||||||
->setDescription('')
|
->setDescription('')
|
||||||
|
@ -102,6 +102,31 @@ final class PhabricatorCalendarEvent extends PhabricatorCalendarDAO
|
||||||
->applyViewerTimezone($actor);
|
->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(
|
private function newChild(
|
||||||
PhabricatorUser $actor,
|
PhabricatorUser $actor,
|
||||||
$sequence,
|
$sequence,
|
||||||
|
|
|
@ -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();
|
$viewer = $this->getViewer();
|
||||||
|
|
||||||
$can_create = $this->hasCreateCapability();
|
$can_create = $this->hasCreateCapability();
|
||||||
|
@ -1385,6 +1387,11 @@ abstract class PhabricatorEditEngine
|
||||||
$form_key = $config->getIdentifier();
|
$form_key = $config->getIdentifier();
|
||||||
$create_uri = $this->getEditURI(null, "form/{$form_key}/");
|
$create_uri = $this->getEditURI(null, "form/{$form_key}/");
|
||||||
|
|
||||||
|
if ($parameters) {
|
||||||
|
$create_uri = (string)id(new PhutilURI($create_uri))
|
||||||
|
->setQueryParams($parameters);
|
||||||
|
}
|
||||||
|
|
||||||
if (count($configs) > 1) {
|
if (count($configs) > 1) {
|
||||||
$menu_icon = 'fa-caret-square-o-down';
|
$menu_icon = 'fa-caret-square-o-down';
|
||||||
|
|
||||||
|
@ -1395,6 +1402,11 @@ abstract class PhabricatorEditEngine
|
||||||
$form_key = $config->getIdentifier();
|
$form_key = $config->getIdentifier();
|
||||||
$config_uri = $this->getEditURI(null, "form/{$form_key}/");
|
$config_uri = $this->getEditURI(null, "form/{$form_key}/");
|
||||||
|
|
||||||
|
if ($parameters) {
|
||||||
|
$config_uri = (string)id(new PhutilURI($config_uri))
|
||||||
|
->setQueryParams($parameters);
|
||||||
|
}
|
||||||
|
|
||||||
$item_icon = 'fa-plus';
|
$item_icon = 'fa-plus';
|
||||||
|
|
||||||
$dropdown->addAction(
|
$dropdown->addAction(
|
||||||
|
|
Loading…
Reference in a new issue