mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-23 22:10:55 +01:00
Calendar day view and corresponding sidebar should correctly display all all-day events returned from query
Summary: Closes T8085, Calendar day view and corresponding sidebar should correctly display all all-day events returned from query Test Plan: Open day view with all-day and multi-day events, all events should correctly be drawn in day view in correct order, and sidebar preview should correctly mark future day boxes with all day events. Reviewers: epriestley, #blessed_reviewers Reviewed By: epriestley, #blessed_reviewers Subscribers: Korvin, epriestley Maniphest Tasks: T8085 Differential Revision: https://secure.phabricator.com/D12776
This commit is contained in:
parent
dd88a0e9e9
commit
22ac7d7c76
4 changed files with 82 additions and 33 deletions
|
@ -392,9 +392,14 @@ final class PhabricatorCalendarEventSearchEngine
|
||||||
$phids = mpull($statuses, 'getUserPHID');
|
$phids = mpull($statuses, 'getUserPHID');
|
||||||
|
|
||||||
foreach ($statuses as $status) {
|
foreach ($statuses as $status) {
|
||||||
|
if ($status->getIsCancelled()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
$event = new AphrontCalendarEventView();
|
$event = new AphrontCalendarEventView();
|
||||||
$event->setEventID($status->getID());
|
$event->setEventID($status->getID());
|
||||||
$event->setEpochRange($status->getDateFrom(), $status->getDateTo());
|
$event->setEpochRange($status->getDateFrom(), $status->getDateTo());
|
||||||
|
$event->setIsAllDay($status->getIsAllDay());
|
||||||
|
|
||||||
$event->setName($status->getName());
|
$event->setName($status->getName());
|
||||||
$event->setURI('/'.$status->getMonogram());
|
$event->setURI('/'.$status->getMonogram());
|
||||||
|
|
|
@ -10,6 +10,7 @@ final class AphrontCalendarEventView extends AphrontView {
|
||||||
private $eventID;
|
private $eventID;
|
||||||
private $color;
|
private $color;
|
||||||
private $uri;
|
private $uri;
|
||||||
|
private $isAllDay;
|
||||||
|
|
||||||
public function setURI($uri) {
|
public function setURI($uri) {
|
||||||
$this->uri = $uri;
|
$this->uri = $uri;
|
||||||
|
@ -81,14 +82,16 @@ final class AphrontCalendarEventView extends AphrontView {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAllDay() {
|
public function setIsAllDay($is_all_day) {
|
||||||
$time = (60 * 60 * 22);
|
$this->isAllDay = $is_all_day;
|
||||||
if (($this->getEpochEnd() - $this->getEpochStart()) >= $time) {
|
return $this;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
|
public function getIsAllDay() {
|
||||||
|
return $this->isAllDay;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function getMultiDay() {
|
public function getMultiDay() {
|
||||||
$nextday = strtotime('12:00 AM Tomorrow', $this->getEpochStart());
|
$nextday = strtotime('12:00 AM Tomorrow', $this->getEpochStart());
|
||||||
if ($this->getEpochEnd() > $nextday) {
|
if ($this->getEpochEnd() > $nextday) {
|
||||||
|
|
|
@ -7,6 +7,9 @@ final class PHUICalendarDayView extends AphrontView {
|
||||||
private $year;
|
private $year;
|
||||||
private $browseURI;
|
private $browseURI;
|
||||||
private $events = array();
|
private $events = array();
|
||||||
|
private $todayEvents = array();
|
||||||
|
|
||||||
|
private $allDayEvents = array();
|
||||||
|
|
||||||
public function addEvent(AphrontCalendarEventView $event) {
|
public function addEvent(AphrontCalendarEventView $event) {
|
||||||
$this->events[] = $event;
|
$this->events[] = $event;
|
||||||
|
@ -34,43 +37,62 @@ final class PHUICalendarDayView extends AphrontView {
|
||||||
$hourly_events = array();
|
$hourly_events = array();
|
||||||
$rows = array();
|
$rows = array();
|
||||||
|
|
||||||
|
$all_day_events = $this->getAllDayEvents();
|
||||||
|
|
||||||
// sort events into buckets by their start time
|
// sort events into buckets by their start time
|
||||||
// pretend no events overlap
|
// pretend no events overlap
|
||||||
foreach ($hours as $hour) {
|
foreach ($hours as $hour) {
|
||||||
$events = array();
|
$current_hour_events = array();
|
||||||
$hour_start = $hour->format('U');
|
$hour_start = $hour->format('U');
|
||||||
$hour_end = id(clone $hour)->modify('+1 hour')->format('U');
|
$hour_end = id(clone $hour)->modify('+1 hour')->format('U');
|
||||||
|
|
||||||
|
if ($hour == $this->getDateTime()) {
|
||||||
|
foreach ($all_day_events as $all_day_event) {
|
||||||
|
$all_day_start = $all_day_event->getEpochStart();
|
||||||
|
$all_day_end = $all_day_event->getEpochEnd();
|
||||||
|
$day_end = id(clone $hour)->modify('+1 day')->format('U') - 1;
|
||||||
|
|
||||||
|
if ($all_day_start < $day_end && $all_day_end > $hour_start) {
|
||||||
|
|
||||||
|
$current_hour_events[] = $all_day_event;
|
||||||
|
$this->todayEvents[] = $all_day_event;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
foreach ($this->events as $event) {
|
foreach ($this->events as $event) {
|
||||||
|
if ($event->getIsAllDay()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if ($event->getEpochStart() >= $hour_start
|
if ($event->getEpochStart() >= $hour_start
|
||||||
&& $event->getEpochStart() < $hour_end) {
|
&& $event->getEpochStart() < $hour_end) {
|
||||||
$events[] = $event;
|
$current_hour_events[] = $event;
|
||||||
|
$this->todayEvents[] = $event;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$count_events = count($events);
|
foreach ($current_hour_events as $event) {
|
||||||
$n = 0;
|
|
||||||
foreach ($events as $event) {
|
|
||||||
$event_start = $event->getEpochStart();
|
$event_start = $event->getEpochStart();
|
||||||
$event_end = $event->getEpochEnd();
|
$event_end = $event->getEpochEnd();
|
||||||
|
|
||||||
$top = ((($event_start - $hour_start) / ($hour_end - $hour_start))
|
$top = (($event_start - $hour_start) / ($hour_end - $hour_start))
|
||||||
* 100).'%';
|
* 100;
|
||||||
$height = ((($event_end - $event_start) / ($hour_end - $hour_start))
|
$top = max(0, $top);
|
||||||
* 100).'%';
|
|
||||||
|
$height = (($event_end - $event_start) / ($hour_end - $hour_start))
|
||||||
|
* 100;
|
||||||
|
$height = min(2400, $height);
|
||||||
|
|
||||||
$hourly_events[$event->getEventID()] = array(
|
$hourly_events[$event->getEventID()] = array(
|
||||||
'hour' => $hour,
|
'hour' => $hour,
|
||||||
'event' => $event,
|
'event' => $event,
|
||||||
'offset' => '0',
|
'offset' => '0',
|
||||||
'width' => '100%',
|
'width' => '100%',
|
||||||
'top' => $top,
|
'top' => $top.'%',
|
||||||
'height' => $height,
|
'height' => $height.'%',
|
||||||
);
|
);
|
||||||
|
|
||||||
$n++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$clusters = $this->findClusters();
|
$clusters = $this->findTodayClusters();
|
||||||
foreach ($clusters as $cluster) {
|
foreach ($clusters as $cluster) {
|
||||||
$hourly_events = $this->updateEventsFromCluster(
|
$hourly_events = $this->updateEventsFromCluster(
|
||||||
$cluster,
|
$cluster,
|
||||||
|
@ -138,26 +160,46 @@ final class PHUICalendarDayView extends AphrontView {
|
||||||
$layout);
|
$layout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function getAllDayEvents() {
|
||||||
|
$all_day_events = array();
|
||||||
|
|
||||||
|
foreach ($this->events as $event) {
|
||||||
|
if ($event->getIsAllDay()) {
|
||||||
|
$all_day_events[] = $event;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$all_day_events = array_values(msort($all_day_events, 'getEpochStart'));
|
||||||
|
|
||||||
|
return $all_day_events;
|
||||||
|
}
|
||||||
|
|
||||||
private function renderSidebar() {
|
private function renderSidebar() {
|
||||||
$this->events = msort($this->events, 'getEpochStart');
|
$this->events = msort($this->events, 'getEpochStart');
|
||||||
$week_of_boxes = $this->getWeekOfBoxes();
|
$week_of_boxes = $this->getWeekOfBoxes();
|
||||||
$filled_boxes = array();
|
$filled_boxes = array();
|
||||||
|
|
||||||
foreach ($week_of_boxes as $weekly_box) {
|
foreach ($week_of_boxes as $day_box) {
|
||||||
$start = $weekly_box['start'];
|
$box_start = $day_box['start'];
|
||||||
$end = id(clone $start)->modify('+1 day');
|
$box_end = id(clone $box_start)->modify('+1 day');
|
||||||
|
|
||||||
|
$box_start = $box_start->format('U');
|
||||||
|
$box_end = $box_end->format('U');
|
||||||
|
|
||||||
$box_events = array();
|
$box_events = array();
|
||||||
|
|
||||||
foreach ($this->events as $event) {
|
foreach ($this->events as $event) {
|
||||||
if ($event->getEpochStart() >= $start->format('U') &&
|
$event_start = $event->getEpochStart();
|
||||||
$event->getEpochStart() < $end->format('U')) {
|
$event_end = $event->getEpochEnd();
|
||||||
|
|
||||||
|
if ($event_start < $box_end && $event_end > $box_start) {
|
||||||
$box_events[] = $event;
|
$box_events[] = $event;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$filled_boxes[] = $this->renderSidebarBox(
|
$filled_boxes[] = $this->renderSidebarBox(
|
||||||
$box_events,
|
$box_events,
|
||||||
$weekly_box['title']);
|
$day_box['title']);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $filled_boxes;
|
return $filled_boxes;
|
||||||
|
@ -267,7 +309,6 @@ final class PHUICalendarDayView extends AphrontView {
|
||||||
|
|
||||||
private function updateEventsFromCluster($cluster, $hourly_events) {
|
private function updateEventsFromCluster($cluster, $hourly_events) {
|
||||||
$cluster_size = count($cluster);
|
$cluster_size = count($cluster);
|
||||||
|
|
||||||
$n = 0;
|
$n = 0;
|
||||||
foreach ($cluster as $cluster_member) {
|
foreach ($cluster as $cluster_member) {
|
||||||
$event_id = $cluster_member->getEventID();
|
$event_id = $cluster_member->getEventID();
|
||||||
|
@ -375,8 +416,8 @@ final class PHUICalendarDayView extends AphrontView {
|
||||||
return $date;
|
return $date;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function findClusters() {
|
private function findTodayClusters() {
|
||||||
$events = msort($this->events, 'getEpochStart');
|
$events = msort($this->todayEvents, 'getEpochStart');
|
||||||
$clusters = array();
|
$clusters = array();
|
||||||
|
|
||||||
foreach ($events as $event) {
|
foreach ($events as $event) {
|
||||||
|
|
|
@ -37,7 +37,7 @@ final class PHUICalendarListView extends AphrontTagView {
|
||||||
foreach ($events as $event) {
|
foreach ($events as $event) {
|
||||||
$color = $event->getColor();
|
$color = $event->getColor();
|
||||||
|
|
||||||
if ($event->getAllDay()) {
|
if ($event->getIsAllDay()) {
|
||||||
$timelabel = pht('All Day');
|
$timelabel = pht('All Day');
|
||||||
} else {
|
} else {
|
||||||
$timelabel = phabricator_time(
|
$timelabel = phabricator_time(
|
||||||
|
|
Loading…
Reference in a new issue