version 0.01
parent
949c45adb5
commit
c17c5a8e97
30
index.html
30
index.html
|
@ -6,19 +6,41 @@
|
|||
|
||||
<link rel="stylesheet" href="css/bootstrap.min.css">
|
||||
<script type="text/javascript" src="js/jquery-3.4.1.min.js"></script>
|
||||
<script type="text/javascript" src="js/import.js"></script>
|
||||
<script type="text/javascript" src="js/xml2json.js"></script>
|
||||
<script type="text/javascript" src="js/Schedule.js"></script>
|
||||
|
||||
<title>Datenspuren Wegweiser</title>
|
||||
</head>
|
||||
<body>
|
||||
<body class="bg-dark text-info">
|
||||
<h1>Datenspuren Wegweiser</h1>
|
||||
<div class="talks">
|
||||
<div class="talk">nächste talk</div>
|
||||
</div>
|
||||
|
||||
<h2>Plan: <span id="scheduleName"></span></h2>
|
||||
|
||||
<script>
|
||||
$.when( $.ready ).then(function() {
|
||||
var s = new schedule();
|
||||
$('#scheduleName').html( s.getSchedule() );
|
||||
let path = "./src/schedule.xml";
|
||||
$.get( path, function( data ) {
|
||||
this.xml = new XMLSerializer().serializeToString(data);
|
||||
|
||||
//console.log(xml2json(this.xml));
|
||||
|
||||
var scheduleXml = $( $.parseXML( this.xml ) );
|
||||
var s = new Schedule(scheduleXml);
|
||||
|
||||
$('#scheduleName').html( s.getScheduleTitle() );
|
||||
|
||||
var talks = s.getTalks(s);
|
||||
//console.log(talks[0].childNodes[0].nodeValue.text());
|
||||
for ( var i = 0; i < talks.length; i++) {
|
||||
item = "<li>" + talks[i] + "<li>";
|
||||
$('.talk').append(item);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
})
|
||||
</script>
|
||||
</body>
|
||||
|
|
|
@ -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