Initial commit

This commit is contained in:
Niels
2025-05-30 16:03:59 +02:00
commit 73a6841c08
34 changed files with 5064 additions and 0 deletions
+218
View File
@@ -0,0 +1,218 @@
// Database should be updated to contain location and section.
var db = undefined;
function settings_db_open() {
if (db == undefined)
db = LocalStorage.openDatabaseSync("harbour-labyrinth-test1", "1.0", "StorageDatabase", 100000);
/* db.transaction(function(tx)
{
tx.executeSql("DROP TABLE IF EXISTS favorites");
}); */
// drop()
/* property string showname
property string showimage: ""
property string summary: ""
property string showid: ""
property string showstatus: ""
property string showprem: ""
property string showrating: ""
property string shownetwork: "" */
return db;
}
/*
showName.text = simple.name
showStatus.text = simple.status
showPrem.text = simple.premiered
showRating.text = simple.rating.average
showNetwork.text = simple.network.name
ssummary = simple.summary
imdb = simple.externals.imdb
*/
function initialize() { // klar
db = settings_db_open();
db.transaction(
function(tx) {
// tx.executeSql('ALTER TABLE favorites ADD seen INTEGER');
tx.executeSql('CREATE TABLE IF NOT EXISTS favorites(showid INTEGER UNIQUE, name TEXT, image TEXT, summary TEXT, status TEXT, premiered TEXT, rating TEXT, network TEXT, updated INTEGER, previous TEXT, next TEXT,nextse TEXT, imdb TEXT, official TEXT, seen INTEGER)');
tx.executeSql('CREATE TABLE IF NOT EXISTS seen(showid INTEGER UNIQUE, season INTEGER, episode INTEGER)');
// tx.executeSql('CREATE TABLE IF NOT EXISTS next(showid INTEGER UNIQUE, next TEXT)');
// tx.executeSql('CREATE TABLE IF NOT EXISTS previous(showid INTEGER UNIQUE, prev TEXT)');
});
}
/*
function getCount(){
db.transaction(function(tx)
{
var rs = tx.executeSql('SELECT * FROM favorites');
dbcount = rs.rows.length
})
}
*/
function getFavByNr(shids,nr) // klar
{
db.transaction(function(tx)
{
var rs = tx.executeSql('SELECT * FROM favorites');
// var shids = new Array();
// var shids = []
// var shid = ""
// var shupdated = ""
shids.push(rs.rows.item(nr).showid)
shids.push(rs.rows.item(nr).updated)
// shids = [rs.rows.item(nr).showid,rs.rows.item(nr).updated]
// console.log(" --- DB SHIDS; "+shids)
// return shids
});
}
function getFav(showid) {
var res = undefined
settings_db_open();
db.transaction(function(tx) {
res = tx.executeSql("SELECT * FROM favorites WHERE showid like ('"+ showid + "')");})
try {
if (typeof res.rows.item(0).showid === 'number')
return true
} catch(a) {
return false
}}
function getFav_(showid) {
settings_db_open();
db.transaction(function(tx)
{
try {
tx.executeSql("SELECT * FROM favorites WHERE showid='"+showid+"'");
console.log("SUCCESS")
} catch(a) {
console.log("ERROR")
}
// console.log("FAVDB: "+ result.item(0))
});
}
function loadWakeup(model,showid) // klar
{
model.clear()
db.transaction(function(tx)
{
var rs = tx.executeSql('SELECT '+showid+' FROM favorites');
//for(var i = 0; i < rs.rows.length; i++)
//{ model.id, model.name, showImg.source, model.summary, model.status, model.premiered, model.rating, model.network
model.append({"showid" : rs.rows.item(i).showid, "name" : rs.rows.item(i).name,"image" : rs.rows.item(i).image,"summary" : rs.rows.item(i).summary,"status" : rs.rows.item(i).status,"premiered" : rs.rows.item(i).premiered,"rating" : rs.rows.item(i).rating,"network" : rs.rows.item(i).network,"updated" : rs.rows.item(i).updated,"previous" : rs.rows.item(i).previous,"next" : rs.rows.item(i).next, "nextse" : rs.rows.item(i).nextse})
//}
});
}
function load(model) // klar
{
model.clear()
db.transaction(function(tx)
{
var rs = tx.executeSql('SELECT * FROM favorites ORDER BY name ASC, next');
for(var i = 0; i < rs.rows.length; i++)
{
model.append({"showid" : rs.rows.item(i).showid, "name" : rs.rows.item(i).name,"image" : rs.rows.item(i).image,"summary" : rs.rows.item(i).summary,"status" : rs.rows.item(i).status,"premiered" : rs.rows.item(i).premiered,"rating" : rs.rows.item(i).rating,"network" : rs.rows.item(i).network,"updated" : rs.rows.item(i).updated,"prev" : rs.rows.item(i).previous,"next" : rs.rows.item(i).next, "nextse" : rs.rows.item(i).nextse, "imdb" : rs.rows.item(i).imdb, "official" : rs.rows.item(i).official, "seen" : rs.rows.item(i).seen})
}
});
}
// ADD FAVORITE
function add(showid, name, image, summary, status, prem, rating, network, updated, previous, next, nextse, imdb, official) // klar
{
settings_db_open();
try {
db.transaction(function(tx)
{
tx.executeSql('INSERT INTO favorites VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?);', [showid, name, image, summary, status, prem, rating, network, updated, previous, next, nextse, imdb, official])
return true
});
}
catch(a)
{
console.log("insert failed, probably already exists");
return false;
}
}
// --------------------------------------------
function update(showid, name, image, summary, status, prem, rating, network, updated, imdb, official) // klar
{
settings_db_open();
try {
db.transaction(function(tx)
{
tx.executeSql('UPDATE favorites SET name=?,image=?,summary=?,status=?,premiered=?,rating=?,network=?,updated=?,imdb=?,official=? WHERE showid='+showid+';',
[name, image, summary, status, prem, rating, network, updated, imdb, official])
return true;
});
}
catch(a)
{
console.log("insert failed, probably already exists");
return false;
}
}
// SKA GÖRAS BÅDE VID ADD OCH UPPDATE
function updateNext(showid, next, nextse) // klar
{
settings_db_open();
db.transaction(function(tx)
{
tx.executeSql('UPDATE favorites SET next=?,nextse=? WHERE showid='+showid+';', [next, nextse])
console.log("*** DB UPDATE NEXT: "+showid+" / "+next)
});
}
function updatePrev(showid, prev) // klar
{
settings_db_open();
db.transaction(function(tx)
{
tx.executeSql('UPDATE favorites SET previous=? WHERE showid='+showid+';', [prev])
console.log("*** DB UPDATE PREV: "+showid+" / "+prev)
});
}
// -------------------
function del(showid) // klar
{
settings_db_open();
db.transaction(function(tx)
{
tx.executeSql('DELETE FROM favorites WHERE showid = ?', [showid])
});
}
function drop() // klar
{
settings_db_open();
db.transaction(function(tx)
{
tx.executeSql("DROP TABLE IF EXISTS favorites");
});
}
+88
View File
@@ -0,0 +1,88 @@
/* JSONPath 0.8.5 - XPath for JSON
*
* Copyright (c) 2007 Stefan Goessner (goessner.net)
* Licensed under the MIT (MIT-LICENSE.txt) licence.
*
*/
function jsonPath(obj, expr, arg) {
var P = {
resultType: arg && arg.resultType || "VALUE",
result: [],
normalize: function(expr) {
var subx = [];
return expr.replace(/[\['](\??\(.*?\))[\]']|\['(.*?)'\]/g, function($0,$1,$2){return "[#"+(subx.push($1||$2)-1)+"]";}) /* http://code.google.com/p/jsonpath/issues/detail?id=4 */
.replace(/'?\.'?|\['?/g, ";")
.replace(/;;;|;;/g, ";..;")
.replace(/;$|'?\]|'$/g, "")
.replace(/#([0-9]+)/g, function($0,$1){return subx[$1];});
},
asPath: function(path) {
var x = path.split(";"), p = "$";
for (var i=1,n=x.length; i<n; i++)
p += /^[0-9*]+$/.test(x[i]) ? ("["+x[i]+"]") : ("['"+x[i]+"']");
return p;
},
store: function(p, v) {
if (p) P.result[P.result.length] = P.resultType == "PATH" ? P.asPath(p) : v;
return !!p;
},
trace: function(expr, val, path) {
if (expr !== "") {
var x = expr.split(";"), loc = x.shift();
x = x.join(";");
if (val && val.hasOwnProperty(loc))
P.trace(x, val[loc], path + ";" + loc);
else if (loc === "*")
P.walk(loc, x, val, path, function(m,l,x,v,p) { P.trace(m+";"+x,v,p); });
else if (loc === "..") {
P.trace(x, val, path);
P.walk(loc, x, val, path, function(m,l,x,v,p) { typeof v[m] === "object" && P.trace("..;"+x,v[m],p+";"+m); });
}
else if (/^\(.*?\)$/.test(loc)) // [(expr)]
P.trace(P.eval(loc, val, path.substr(path.lastIndexOf(";")+1))+";"+x, val, path);
else if (/^\?\(.*?\)$/.test(loc)) // [?(expr)]
P.walk(loc, x, val, path, function(m,l,x,v,p) { if (P.eval(l.replace(/^\?\((.*?)\)$/,"$1"), v instanceof Array ? v[m] : v, m)) P.trace(m+";"+x,v,p); }); // issue 5 resolved
else if (/^(-?[0-9]*):(-?[0-9]*):?([0-9]*)$/.test(loc)) // [start:end:step] phyton slice syntax
P.slice(loc, x, val, path);
else if (/,/.test(loc)) { // [name1,name2,...]
for (var s=loc.split(/'?,'?/),i=0,n=s.length; i<n; i++)
P.trace(s[i]+";"+x, val, path);
}
}
else
P.store(path, val);
},
walk: function(loc, expr, val, path, f) {
if (val instanceof Array) {
for (var i=0,n=val.length; i<n; i++)
if (i in val)
f(i,loc,expr,val,path);
}
else if (typeof val === "object") {
for (var m in val)
if (val.hasOwnProperty(m))
f(m,loc,expr,val,path);
}
},
slice: function(loc, expr, val, path) {
if (val instanceof Array) {
var len=val.length, start=0, end=len, step=1;
loc.replace(/^(-?[0-9]*):(-?[0-9]*):?(-?[0-9]*)$/g, function($0,$1,$2,$3){start=parseInt($1||start);end=parseInt($2||end);step=parseInt($3||step);});
start = (start < 0) ? Math.max(0,start+len) : Math.min(len,start);
end = (end < 0) ? Math.max(0,end+len) : Math.min(len,end);
for (var i=start; i<end; i+=step)
P.trace(i+";"+expr, val, path);
}
},
eval: function(x, _v, _vname) {
try { return $ && _v && eval(x.replace(/(^|[^\\])@/g, "$1_v").replace(/\\@/g, "@")); } // issue 7 : resolved ..
catch(e) { throw new SyntaxError("jsonPath: " + e.message + ": " + x.replace(/(^|[^\\])@/g, "$1_v").replace(/\\@/g, "@")); } // issue 7 : resolved ..
}
};
var $ = obj;
if (expr && obj && (P.resultType == "VALUE" || P.resultType == "PATH")) {
P.trace(P.normalize(expr).replace(/^\$;?/,""), obj, "$"); // issue 6 resolved
return P.result.length ? P.result : false;
}
}
+1694
View File
File diff suppressed because it is too large Load Diff