From 39ace9529514706019367fd11ca5c767dc890319 Mon Sep 17 00:00:00 2001 From: thlo Date: Sun, 17 Mar 2013 09:41:35 +0100 Subject: First step of repo restructuring --- web/Data.js | 296 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ web/Server.js | 180 ++++++++++++++++++++++++++++++++++ web/favicon.ico | Bin 0 -> 1502 bytes web/index.html | 104 ++++++++++++++++++++ 4 files changed, 580 insertions(+) create mode 100755 web/Data.js create mode 100755 web/Server.js create mode 100755 web/favicon.ico create mode 100755 web/index.html (limited to 'web') diff --git a/web/Data.js b/web/Data.js new file mode 100755 index 0000000..49e9026 --- /dev/null +++ b/web/Data.js @@ -0,0 +1,296 @@ +//Diff: +// getNumString +// createJQMDomTree + +var Data = +{ + assets : new Item, + folderList : [], +}; + +Array.prototype.remove = function(from, to) { + var rest = this.slice((to || from) + 1 || this.length); + this.length = from < 0 ? this.length + from : from; + return this.push.apply(this, rest); +}; + +Data.reset = function() { + this.assets = null; + this.assets = new Item; + + this.folderList = []; + +// this.folderList.push({item : this.assets, id: 0}); +// Main.log("Data.reset: folderList.push. this.folderList.length= " + this.folderList.length); +}; + +Data.completed= function(sort) { + if (sort == true) + this.assets.sortPayload(); + + this.folderList.push({item : this.assets, id: 0}); +// Main.log("Data.completed: folderList.push. this.folderList.length= " + this.folderList.length); +// Main.log ("Data.completed()= " +this.folderList.length); + +}; + +Data.selectFolder = function (idx, first_idx) { + this.folderList.push({item : this.getCurrentItem().childs[idx], id: idx, first:first_idx}); +// Main.log("Data.selectFolder: folderList.push. this.folderList.length= " + this.folderList.length); +}; + +Data.folderUp = function () { + itm = this.folderList.pop(); +// Main.log("Data.folderUp: folderList.pop. this.folderList.length= " + this.folderList.length); + return itm; +// return itm.id; +}; + +Data.isRootFolder = function() { +// Main.log("Data.isRootFolder: this.folderList.length= " + this.folderList.length); + if (this.folderList.length == 1) + return true; + else + return false; +}; + +Data.addItem = function(t_list, pyld) { + this.assets.addChild(t_list, pyld, 0); +}; + +Data.dumpFolderStruct = function(){ + Main.log("---------- dumpFolderStruct ------------"); + this.assets.print(0); + Main.log("---------- dumpFolderStruct Done -------"); +}; + +Data.createJQMDomTree = function () { + return this.assets.createJQMDomTree(0); +}; + +Data.findEpgUpdateTime = function() { + return this.assets.findEpgUpdateTime(Display.GetEpochTime() + 10000, "", 0); + // min, guid, level +}; + +Data.updateEpg = function (guid, entry) { + this.assets.updateEpgEntry(guid, entry, 0); +}; + +Data.getCurrentItem = function () { + return this.folderList[this.folderList.length-1].item; +}; + +Data.getVideoCount = function() { + return this.folderList[this.folderList.length-1].item.childs.length; +}; + +Data.getNumString =function(num, fmt) { + var res = ""; + + if (num < 10) { + for (var i = 1; i < fmt; i ++) { + res += "0"; + }; + } else if (num < 100) { + for (var i = 2; i < fmt; i ++) { + res += "0"; + }; + } + + res = res + num; + + return res; +}; + +Data.deleteElm = function (pos) { + Data.getCurrentItem().childs.remove(pos); +}; +//----------------------------------------- +function Item() { + this.title = "root"; + this.isFolder = true; + this.childs = []; + this.payload = ""; // only set, if (isFolder == false) +} + +Item.prototype.isFolder = function() { + return this.isFolder; +}; + +Item.prototype.getTitle = function () { + return this.title; +}; + +Item.prototype.getPayload = function () { + if (this.isFolder == true) { + Main.log("WARNING: getting payload on a folder title=" +this.title); + } + return this.payload; +}; + +Item.prototype.getItem = function (title) { + for (var i = 0; i < this.childs.length; i++) { + if (this.childs[i].title == title) { + return this.childs[i]; + } + } + return 0; +}; + +Item.prototype.addChild = function (key, pyld, level) { + if (key.length == 1) { + var folder = new Item; +// folder.title = pyld.startstr + " - " + key; + folder.title = key[0]; + folder.payload = pyld; + folder.isFolder = false; + this.childs.push(folder); +// this.titles.push({title: pyld.startstr + " - " + key , pyld : pyld}); + } + else { + if (level > 10) { + Main.log(" too many levels"); + return; + } + var t = key.shift(); + var found = false; + for (var i = 0; i < this.childs.length; i++) { + if (this.childs[i].title == t) { + this.childs[i].addChild(key, pyld, level +1); + found = true; + break; + } + } + if (found == false) { + var folder = new Item; + folder.title = t; + folder.addChild(key, pyld, level+1); + this.childs.push(folder); + } + } +}; + +Item.prototype.findEpgUpdateTime = function (min, guid, level) { + var prefix= ""; + for (var i = 0; i < level; i++) + prefix += "-"; + + for (var i = 0; i < this.childs.length; i++) { + if (this.childs[i].isFolder == true) { + var res = this.childs[i].findEpgUpdateTime(min, guid, level+1); + min = res.min; + guid = res.guid; + } + else { + var digi =new Date(this.childs[i].payload['start'] * 1000); + var str = digi.getHours() + ":" + digi.getMinutes(); + +// Main.log(prefix + "min= " + min+ " start= " + this.childs[i].payload['start'] + " (" + str+ ") title= " + this.childs[i].title); + + if ((this.childs[i].payload['start'] != 0) && ((this.childs[i].payload['start'] + this.childs[i].payload['dur']) < min)) { + min = this.childs[i].payload['start'] + this.childs[i].payload['dur']; + guid = this.childs[i].payload['guid'] ; +// Main.log(prefix + "New Min= " + min + " new id= " + guid + " title= " + this.childs[i].title); +// Main.logToServer(prefix + "New Min= " + min + " new id= " + guid + " title= " + this.childs[i].title); + } + } + } + + return { "min": min, "guid" : guid}; +}; + +Item.prototype.updateEpgEntry = function (guid, entry, level) { + var prefix= ""; + for (var i = 0; i < level; i++) + prefix += "-"; + for (var i = 0; i < this.childs.length; i++) { + if (this.childs[i].isFolder == true) { + var res = this.childs[i].updateEpgEntry(guid, entry, level+1); + if (res == true) + return true; + } + else { + if (this.childs[i].payload['guid'] == guid) { + Main.log("updateEpgEntry: Found " + this.childs[i].title); + this.childs[i].payload.prog = entry.prog; + this.childs[i].payload.desc = entry.desc; + this.childs[i].payload.start = entry.start; + this.childs[i].payload.dur = entry.dur; + return true; + } + } + } + return false; +}; + +Item.prototype.print = function(level) { + var prefix= ""; + for (var i = 0; i < level; i++) + prefix += " "; + + for (var i = 0; i < this.childs.length; i++) { + Main.log(prefix + this.childs[i].title); + if (this.childs[i].isFolder == true) { + Main.log(prefix+"Childs:"); + this.childs[i].print(level +1); + } + } +}; + +Item.prototype.createJQMDomTree = function(level) { + var mydiv = $('