version 0.01
parent
949c45adb5
commit
c17c5a8e97
@ -0,0 +1,95 @@
|
||||
/**
|
||||
* get the data from schedule
|
||||
*/
|
||||
var Schedule = class {
|
||||
|
||||
/**
|
||||
* the schedule xml object parsed as jQuery object
|
||||
*/
|
||||
schedule = false;
|
||||
|
||||
/**
|
||||
* Array of talks
|
||||
*
|
||||
* [{
|
||||
* id: 2132,
|
||||
* title: "foobar"
|
||||
* date:2018-09-22T10:30:00+02:00
|
||||
* }]
|
||||
*/
|
||||
talks = [];
|
||||
|
||||
|
||||
query = {
|
||||
time : { 'from' : new Date, 'to' : new Date }
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
talkPrototype = {
|
||||
'date' : '1970-01-01T00:00:00+02:00',
|
||||
'start' : '1970-01-01T00:00:00+02:00',
|
||||
'duration' : '00:15',
|
||||
'room' : 'Großer Saal',
|
||||
'slug' : 'DS2018-9336-eroffnung',
|
||||
'url' : '/2018/fahrplan/events/9336.html',
|
||||
'title' : 'Eröffnung',
|
||||
'subtitle' : 'Datenspuren 2018',
|
||||
'track' : '',
|
||||
'type' : '',
|
||||
'language' : 'de',
|
||||
'abstract' : 'Eröffnung der Datenspuren 2018',
|
||||
'description' : 'Opening Datenspuren 2018',
|
||||
'logo' : false,
|
||||
'persons' : { 'id' : '7339', 'name' : 'Nerd Norbert' }
|
||||
}
|
||||
|
||||
/**
|
||||
* class constructor
|
||||
*/
|
||||
constructor(scheduleXml){
|
||||
this.schedule = scheduleXml;
|
||||
this.talks = this.getTalks();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return String the schedule title
|
||||
*/
|
||||
getScheduleTitle(){
|
||||
return this.schedule.find("title")[0]
|
||||
}
|
||||
|
||||
/**
|
||||
* return array of all talks
|
||||
*/
|
||||
getTalks(){
|
||||
this.schedule.find('event');
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* get next talks by time and room
|
||||
*
|
||||
* @param {Timestamp} minimum time to start
|
||||
* @param {*} room
|
||||
*/
|
||||
getTalk(time, room){
|
||||
|
||||
return talk;
|
||||
}
|
||||
|
||||
/**
|
||||
* get the next talks, based on time
|
||||
* @param {Date} time
|
||||
*/
|
||||
getNextTalks(time){
|
||||
let startTime = new Date(Date.now())
|
||||
|
||||
this.query.time.from = time.toISOString();
|
||||
console.log(this.query);
|
||||
}
|
||||
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
var schedule = class {
|
||||
|
||||
getSchedule = function(){
|
||||
return "fahrplan";
|
||||
}
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
/**
|
||||
* This function coverts a DOM Tree into JavaScript Object.
|
||||
* @param srcDOM: DOM Tree to be converted.
|
||||
*/
|
||||
function xml2json(srcDOM) {
|
||||
let children = [...srcDOM.children];
|
||||
|
||||
// base case for recursion.
|
||||
if (!children.length) {
|
||||
return srcDOM.innerHTML
|
||||
}
|
||||
|
||||
// initializing object to be returned.
|
||||
let jsonResult = {};
|
||||
|
||||
for (let child of children) {
|
||||
|
||||
// checking is child has siblings of same name.
|
||||
let childIsArray = children.filter(eachChild => eachChild.nodeName === child.nodeName).length > 1;
|
||||
|
||||
// if child is array, save the values as array, else as strings.
|
||||
if (childIsArray) {
|
||||
if (jsonResult[child.nodeName] === undefined) {
|
||||
jsonResult[child.nodeName] = [xml2json(child)];
|
||||
} else {
|
||||
jsonResult[child.nodeName].push(xml2json(child));
|
||||
}
|
||||
} else {
|
||||
jsonResult[child.nodeName] = xml2json(child);
|
||||
}
|
||||
}
|
||||
|
||||
return jsonResult;
|
||||
}
|
Loading…
Reference in New Issue