interlude/schedule.js

117 lines
3.4 KiB
JavaScript
Raw Permalink Normal View History

function Schedule(hallId, date, setPageTitle) {
2014-05-13 07:27:47 +03:00
var events = [];
2021-08-08 14:13:07 +03:00
var apiEndpointPrefix = 'https://cfp.openfest.org/api/conferences/8';
var pageTitle = 'OpenFest';
var room = '';
var nextLectureDelayMinutes = 4; // show the current lecture as next for the first N minutes
$.getJSON(apiEndpointPrefix + '/halls.json', function(data) {
room = data[hallId]['name']['bg'];
if (room === undefined) {
room = '';
}
});
2015-08-12 21:03:56 +03:00
this.update = function() {
$.getJSON(apiEndpointPrefix + '/events.json', function(eventsData) {
$.getJSON(apiEndpointPrefix + '/slots.json', function(slotsData) {
$.each(slotsData, function(slotId, slot) {
$.extend(eventsData[slot['event_id'].toString()], slot);
$.extend(eventsData[slot['event_id'].toString()], {"slotId": slotId});
});
var scheduleEvents = $.map(eventsData, function(event, eventId) {
event['id'] = eventId;
event['startTime'] = moment(event['starts_at']);
event['endTime'] = moment(event['ends_at']);
event['hallId'] = event['hall_id'];
if (event['startTime'].date() !== date) {
return null;
}
if (event['hallId'] !== hallId) {
return null;
}
return event;
});
events = scheduleEvents.sort(function (a,b) {return a['startTime'].isBefore(b['startTime']) ? -1 : 1});
});
2014-05-13 07:27:47 +03:00
});
this.setPageTitle();
2014-05-13 07:27:47 +03:00
}
this.upcomingEvents = function() {
var now = this.referenceTime();
2014-05-13 07:27:47 +03:00
return _.select(events, function(event) {
return event.startTime.isAfter(now);
2014-05-13 07:27:47 +03:00
});
}
this.nextEvent = function() {
return _.first(this.upcomingEvents());
}
2014-06-21 05:08:15 +03:00
this.currentEvent = function() {
2014-06-21 10:55:38 +03:00
var latestEvent = _.last(this.pastEvents());
if (typeof(latestEvent) != 'undefined' && latestEvent.endTime.isAfter(this.now())) {
2014-06-21 10:55:38 +03:00
return latestEvent;
} else {
return undefined;
}
2014-06-21 05:08:15 +03:00
}
2014-05-13 15:43:58 +03:00
this.futureEvents = function() {
return this.upcomingEvents().splice(1);
}
this.pastEvents = function() {
var now = this.referenceTime();
2014-05-13 15:43:58 +03:00
return _.select(events, function(event) {
return event.startTime.isBefore(now);
2014-05-13 15:43:58 +03:00
});
}
this.allEvents = function() {
2014-05-13 07:27:47 +03:00
return events;
}
this.now = function() {
now = $.urlParam("now");
if (now) {
return moment(now);
} else {
return moment();
}
}
this.referenceTime = function() {
return this.now().subtract(nextLectureDelayMinutes, 'minutes');
}
this.room = function() {
return room;
}
this.setPageTitle = function() {
if (setPageTitle) {
$('title').text(pageTitle + " room=" + room + " date=" + date);
}
}
2015-08-12 21:03:56 +03:00
}
2014-05-13 07:27:47 +03:00
2015-08-12 21:03:56 +03:00
$.urlParam = function(name){
var results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.href);
if (results==null){
return null;
}
else{
return results[1] || 0;
2014-05-13 07:27:47 +03:00
}
}
var schedule = new Schedule(parseInt($.urlParam('roomId')), parseInt($.urlParam('date')), true);