1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-10 08:52:39 +01:00

Swapping out foreach out of behavior

Summary: Ref T8300, swapping out foreach out of behavior

Test Plan: no user facing changes

Reviewers: #blessed_reviewers, epriestley

Reviewed By: #blessed_reviewers, epriestley

Subscribers: Korvin, epriestley

Maniphest Tasks: T8300

Differential Revision: https://secure.phabricator.com/D12980
This commit is contained in:
lkassianik 2015-05-22 14:46:48 -07:00
parent 8166f25c0d
commit 04584131f7

View file

@ -7,6 +7,7 @@ JX.behavior('day-view', function(config) {
var hourly_events = config.hourlyEvents; var hourly_events = config.hourlyEvents;
var today_events = config.todayEvents; var today_events = config.todayEvents;
function findTodayClusters() { function findTodayClusters() {
var events = today_events.sort(function(x, y){ var events = today_events.sort(function(x, y){
return (x.eventStartEpoch - y.eventStartEpoch); return (x.eventStartEpoch - y.eventStartEpoch);
@ -14,34 +15,42 @@ JX.behavior('day-view', function(config) {
var clusters = []; var clusters = [];
events.forEach(function(e){ for (var i=0; i < events.length; i++) {
var destination_cluster_index = null; var today_event = events[i];
var event_start = e.eventStartEpoch - (30*60);
var event_end = e.eventEndEpoch + (30*60);
clusters.forEach(function(cluster, index){ var destination_cluster_index = null;
for(var i=0; i < cluster.length; i++) { var event_start = today_event.eventStartEpoch - (30*60);
var clustered_event = cluster[i]; var event_end = today_event.eventEndEpoch + (30*60);
for (var j=0; j < clusters.length; j++) {
var cluster = clusters[j];
for(var k=0; k < cluster.length; k++) {
var clustered_event = cluster[k];
var compare_event_start = clustered_event.eventStartEpoch; var compare_event_start = clustered_event.eventStartEpoch;
var compare_event_end = clustered_event.eventEndEpoch; var compare_event_end = clustered_event.eventEndEpoch;
if (event_start < compare_event_end && if (event_start < compare_event_end &&
event_end > compare_event_start) { event_end > compare_event_start) {
destination_cluster_index = index; destination_cluster_index = j;
break; break;
} }
} }
});
if (destination_cluster_index !== null) { if (destination_cluster_index !== null) {
clusters[destination_cluster_index].push(e); break;
}
}
if (destination_cluster_index !== null) {
clusters[destination_cluster_index].push(today_event);
destination_cluster_index = null; destination_cluster_index = null;
} else { } else {
var next_cluster = []; var next_cluster = [];
next_cluster.push(e); next_cluster.push(today_event);
clusters.push(next_cluster); clusters.push(next_cluster);
} }
}); }
return clusters; return clusters;
} }