diff --git a/resources/celerity/map.php b/resources/celerity/map.php index ad88264ee5..422fee0b9d 100644 --- a/resources/celerity/map.php +++ b/resources/celerity/map.php @@ -331,7 +331,8 @@ return array( 'rsrc/js/application/aphlict/behavior-aphlict-listen.js' => 'b1a59974', 'rsrc/js/application/aphlict/behavior-aphlict-status.js' => 'ea681761', 'rsrc/js/application/auth/behavior-persona-login.js' => '9414ff18', - 'rsrc/js/application/calendar/event-all-day.js' => 'ca5fa62a', + 'rsrc/js/application/calendar/behavior-day-view.js' => 'f4f4ad80', + 'rsrc/js/application/calendar/behavior-event-all-day.js' => '38dcf3c8', 'rsrc/js/application/config/behavior-reorder-fields.js' => '14a827de', 'rsrc/js/application/conpherence/ConpherenceThreadManager.js' => '10246726', 'rsrc/js/application/conpherence/behavior-drag-and-drop-photo.js' => 'cf86d16a', @@ -553,6 +554,7 @@ return array( 'javelin-behavior-dashboard-move-panels' => '82439934', 'javelin-behavior-dashboard-query-panel-select' => '453c5375', 'javelin-behavior-dashboard-tab-panel' => 'd4eecc63', + 'javelin-behavior-day-view' => 'f4f4ad80', 'javelin-behavior-device' => 'a205cf28', 'javelin-behavior-differential-add-reviewers-and-ccs' => 'e10f8e18', 'javelin-behavior-differential-comment-jump' => '4fdb476d', @@ -573,7 +575,7 @@ return array( 'javelin-behavior-doorkeeper-tag' => 'e5822781', 'javelin-behavior-durable-column' => '16c695bf', 'javelin-behavior-error-log' => '6882e80a', - 'javelin-behavior-event-all-day' => 'ca5fa62a', + 'javelin-behavior-event-all-day' => '38dcf3c8', 'javelin-behavior-fancy-datepicker' => '5c0f680f', 'javelin-behavior-global-drag-and-drop' => 'c8e57404', 'javelin-behavior-herald-rule-editor' => '7ebaeed3', diff --git a/src/view/phui/calendar/PHUICalendarDayView.php b/src/view/phui/calendar/PHUICalendarDayView.php index 337ef50738..7a96100b2a 100644 --- a/src/view/phui/calendar/PHUICalendarDayView.php +++ b/src/view/phui/calendar/PHUICalendarDayView.php @@ -10,6 +10,7 @@ final class PHUICalendarDayView extends AphrontView { private $browseURI; private $events = array(); private $todayEvents = array(); + private $jsTodayEvents = array(); private $allDayEvents = array(); @@ -45,6 +46,7 @@ final class PHUICalendarDayView extends AphrontView { require_celerity_resource('phui-calendar-day-css'); $hours = $this->getHoursOfDay(); + $js_hourly_events = array(); $hourly_events = array(); $first_event_hour = null; @@ -83,6 +85,11 @@ final class PHUICalendarDayView extends AphrontView { && $event->getEpochStart() < $hour_end)) { $current_hour_events[] = $event; $this->todayEvents[] = $event; + $this->jsTodayEvents[] = array( + 'eventStartEpoch' => $event->getEpochStart(), + 'eventEndEpoch' => $event->getEpochEnd(), + 'eventName' => $event->getName(), + ); } } foreach ($current_hour_events as $event) { @@ -102,6 +109,17 @@ final class PHUICalendarDayView extends AphrontView { $first_event_hour = $hour; } + $js_hourly_events[$event->getEventID()] = array( + 'eventStartEpoch' => $event->getEpochStart(), + 'eventEndEpoch' => $event->getEpochEnd(), + 'eventName' => $event->getName(), + 'hour' => $hour, + 'offset' => '0', + 'width' => '100%', + 'top' => $top.'%', + 'height' => $height.'%', + ); + $hourly_events[$event->getEventID()] = array( 'hour' => $hour, 'event' => $event, @@ -176,6 +194,13 @@ final class PHUICalendarDayView extends AphrontView { $sidebar = $this->renderSidebar(); $warnings = $this->getQueryRangeWarning(); + Javelin::initBehavior( + 'day-view', + array( + 'todayEvents' => $this->jsTodayEvents, + 'hourlyEvents' => $js_hourly_events, + )); + $table_box = id(new PHUIObjectBoxView()) ->setHeader($header) ->appendChild($all_day_event_box) diff --git a/webroot/rsrc/js/application/calendar/behavior-day-view.js b/webroot/rsrc/js/application/calendar/behavior-day-view.js new file mode 100644 index 0000000000..9cd90e01bc --- /dev/null +++ b/webroot/rsrc/js/application/calendar/behavior-day-view.js @@ -0,0 +1,50 @@ +/** + * @provides javelin-behavior-day-view + */ + + +JX.behavior('day-view', function(config) { + var hourly_events = config.hourlyEvents; + var today_events = config.todayEvents; + + function findTodayClusters() { + var events = today_events.sort(function(x, y){ + return (x.eventStartEpoch - y.eventStartEpoch); + }); + + var clusters = []; + + events.forEach(function(e){ + var destination_cluster_index = null; + var event_start = e.eventStartEpoch - (30*60); + var event_end = e.eventEndEpoch + (30*60); + + clusters.forEach(function(cluster, index){ + for(var i=0; i < cluster.length; i++) { + var clustered_event = cluster[i]; + var compare_event_start = clustered_event.eventStartEpoch; + var compare_event_end = clustered_event.eventEndEpoch; + + if (event_start < compare_event_end && + event_end > compare_event_start) { + destination_cluster_index = index; + break; + } + } + }); + + if (destination_cluster_index !== null) { + clusters[destination_cluster_index].push(e); + destination_cluster_index = null; + } else { + var next_cluster = []; + next_cluster.push(e); + clusters.push(next_cluster); + } + }); + + return clusters; + } + + var today_clusters = findTodayClusters(); +}); diff --git a/webroot/rsrc/js/application/calendar/event-all-day.js b/webroot/rsrc/js/application/calendar/behavior-event-all-day.js similarity index 100% rename from webroot/rsrc/js/application/calendar/event-all-day.js rename to webroot/rsrc/js/application/calendar/behavior-event-all-day.js