schit/js/Schedule.js

159 lines
3.9 KiB
JavaScript
Raw Normal View History

2019-07-31 16:11:49 +02:00
/**
* get the data from schedule
*/
2019-09-20 22:48:05 +02:00
class Schedule {
2019-07-31 16:11:49 +02:00
/**
2019-09-20 22:54:50 +02:00
* class constructor
2019-07-31 16:11:49 +02:00
*/
2019-09-20 22:54:50 +02:00
constructor(scheduleXml){
/**
* the schedule xml object parsed as jQuery object
*/
this.schedule = false;
2019-07-31 16:11:49 +02:00
2019-09-20 22:54:50 +02:00
/**
* Array of Events
*
* [{
* id: 2132,
* title: "foobar"
* date:2018-09-22T10:30:00+02:00
* }]
*/
this.events = [];
2019-07-31 16:11:49 +02:00
2019-09-20 22:54:50 +02:00
/**
* object with Information of the conference
* {'title', 'start', 'end', ..}
*/
this.conf = {
title: 'defaultConf',
start: '1984-09-23',
end: '1984-09-24'
}
2019-07-31 16:11:49 +02:00
2019-09-20 22:54:50 +02:00
/**
* indepent time
*/
this.now = new Date();
2019-07-31 16:11:49 +02:00
2019-07-31 23:49:24 +02:00
this.schedule = scheduleXml.children("schedule");
2019-09-20 17:32:36 +02:00
this.conf.version = this.schedule.children("version").text();
this.conf.title = this.schedule.children("conference").children("title").text();
this.conf.start = this.schedule.children("conference").children("start").text();
this.conf.end = this.schedule.children("conference").children("end").text();
2019-07-31 23:49:24 +02:00
}
/**
* set orientation time
*/
setTimeTo(time){
this.now = time;
2019-07-31 16:11:49 +02:00
}
2019-09-20 17:32:36 +02:00
/**
* @return String the schedule version
*/
getScheduleVersion(){
return this.conf.version ;
}
2019-07-31 16:11:49 +02:00
/**
* @return String the schedule title
*/
getScheduleTitle(){
2019-07-31 23:49:24 +02:00
return this.conf.title;
2019-07-31 16:11:49 +02:00
}
/**
2019-07-31 23:49:24 +02:00
* @return day of conf start
2019-07-31 16:11:49 +02:00
*/
2019-07-31 23:49:24 +02:00
getScheduleStart(){
return this.conf.start;
}
/**this.events
* @return day of conf end
*/
getScheduleEnd(){
return this.conf.end;
}
2019-07-31 16:11:49 +02:00
2019-07-31 23:49:24 +02:00
/**
* return array of all Events
*/
2019-09-21 00:41:20 +02:00
getEvents()
{
2019-07-31 23:49:24 +02:00
let allEvents = [];
if (this.events.length == 0 ){
//this.schedule.find('event').toArray();
2019-09-21 13:56:06 +02:00
var now = this.now
2019-07-31 23:49:24 +02:00
this.schedule.find('event').each( function(){
2019-09-21 13:56:06 +02:00
var eventStart = new Date($(this).children('date').text());
2019-09-22 11:18:37 +02:00
var tenHours = 36000000;
if ((eventStart - now) >= 0 && (eventStart - now) < tenHours){
2019-09-21 13:56:06 +02:00
allEvents.push({
title: $(this).children('title').text(),
room: $(this).children('room').text(),
date: $(this).children('date').text(),
start: $(this).children('start').text(),
duration: $(this).children('duration').text(),
abstract: $(this).children('abstract').text().slice(0, 256),
persons: $(this).children('persons').text(),
});
}
2019-07-31 23:49:24 +02:00
});
}
2019-09-21 13:56:06 +02:00
this.events = allEvents;
2019-07-31 16:11:49 +02:00
}
2019-09-21 02:14:38 +02:00
getEventsAllTracks(count)
{
let roomlist = [];
let events = this.getNextEvents(count);
events.forEach( event => {
if (0 == roomlist.filter(item => event.room == item).length){
roomlist.push(event.room);
}
});
return {
events: events,
roomlist: roomlist
}
}
2019-07-31 16:11:49 +02:00
/**
2019-07-31 23:49:24 +02:00
* get next Events by time and room
2019-07-31 16:11:49 +02:00
*
* @param {Timestamp} minimum time to start
* @param {*} room
*/
getTalk(time, room){
return talk;
}
/**
2019-07-31 23:49:24 +02:00
* get the next Events, based on time
*
2019-07-31 16:11:49 +02:00
*/
2019-09-21 00:41:20 +02:00
getNextEvents(count){
2019-07-31 23:49:24 +02:00
if (this.events.length == 0){
2019-09-21 00:41:20 +02:00
return this.events.slice(0, count);
2019-07-31 23:49:24 +02:00
}
let talks = [];
let now = this.now;
this.events.forEach( talk => {
let talkStart = new Date(talk.date).getTime();
if ( talkStart >= now ){
talks.push(talk);
}
});
2019-07-31 16:11:49 +02:00
2019-09-21 00:41:20 +02:00
return this.events.slice(0, count);
2019-07-31 16:11:49 +02:00
}
}