From c17c5a8e97b730f60244f40d525ced1c83d569e4 Mon Sep 17 00:00:00 2001 From: rob Date: Wed, 31 Jul 2019 16:11:49 +0200 Subject: [PATCH] version 0.01 --- index.html | 30 +++++++++++++--- js/Schedule.js | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++ js/import.js | 6 ---- js/xml2json.js | 34 ++++++++++++++++++ 4 files changed, 155 insertions(+), 10 deletions(-) create mode 100644 js/Schedule.js delete mode 100644 js/import.js create mode 100644 js/xml2json.js diff --git a/index.html b/index.html index e660d20..5c6cdd6 100644 --- a/index.html +++ b/index.html @@ -6,19 +6,41 @@ - + + Datenspuren Wegweiser - +

Datenspuren Wegweiser

+
+
nächste talk
+

Plan:

diff --git a/js/Schedule.js b/js/Schedule.js new file mode 100644 index 0000000..0a62652 --- /dev/null +++ b/js/Schedule.js @@ -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); + } + +} diff --git a/js/import.js b/js/import.js deleted file mode 100644 index 775466a..0000000 --- a/js/import.js +++ /dev/null @@ -1,6 +0,0 @@ -var schedule = class { - - getSchedule = function(){ - return "fahrplan"; - } -} diff --git a/js/xml2json.js b/js/xml2json.js new file mode 100644 index 0000000..4800174 --- /dev/null +++ b/js/xml2json.js @@ -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; + }