From: Kilian Saffran Date: Fri, 22 Feb 2019 06:46:48 +0000 (+0100) Subject: load dataset corrections (syncronous) X-Git-Tag: 0.7beta~35 X-Git-Url: http://cloud.dks.lu/git/?a=commitdiff_plain;h=4e6b003fe6ab129b5e4671cc90199d11d37309f5;p=invoicejournal.git load dataset corrections (syncronous) --- diff --git a/index.html b/index.html index 1b5b8bd..d89e28b 100644 --- a/index.html +++ b/index.html @@ -47,7 +47,7 @@ - + diff --git a/js/app.js b/js/mainapp.js similarity index 51% rename from js/app.js rename to js/mainapp.js index 3ef4326..79a0066 100644 --- a/js/app.js +++ b/js/mainapp.js @@ -1,14 +1,13 @@ $( document ).ready(function() { console.log( "Main ready!" ); - usersystem.getLocalDataSets(browserapp.getdatasets); + browserapp.setdatasets(); + browserapp.loaddataset(); browserapp.loadmodule("overview"); - console.log("After module load!"); }); - -console.log(navigator.platform); -console.log(location.protocol); +//console.log(navigator.platform); +//console.log(location.protocol); var browserapp = { config: null, loadmodule: function(modulename){ @@ -17,13 +16,13 @@ var browserapp = { for (var i in this.config){ params += "&" + i +"=" + encodeURIComponent(appdata[i]); } - console.log("modules/"+modulename+"/index.html"+params); + //console.log("modules/"+modulename+"/index.html"+params); $("#moduleframe").attr("src","modules/"+modulename+"/index.html"+ params); }, loadmodulepage: function(modulename,page,pageparams = null){ - var appdata = browserapp.getconfig(); + //var appdata = browserapp.getconfig(); var params = "?"; - for (var i in appdata){ + for (var i in this.config){ params += "&" + i +"=" + encodeURIComponent(appdata[i]); } if (pageparams){ @@ -34,43 +33,20 @@ var browserapp = { //console.log("modules/"+modulename+"/index.html"+params); $("#moduleframe").attr("src","modules/"+modulename+"/"+ page +".html"+ params); }, - getconfig: async function (){ - console.log("GetConfig"); - var cdata = await usersystem.getPreference($("#globaldatasets").val()); - console.log("Current Dataset"); - console.log(cdata); - var ret = {}; - if ((cdata) && (cdata.name)){ - ret= {dbfile:cdata.dbfile,serviceurl:"http://"+cdata.server+":6060/"}; + setdatasets: function(myds){ + var ds = usersystem.getLocalDataSets(); + for (var i in ds){ + var prop = usersystem.getPreference(ds[i]); + $("#globaldatasets").append(''); } - return ret; - }, - getdatasets: function(gdata){ - //var ds = usersystem.getLocalDataSets(); - //console.log("Datasets"); - //console.log(gdata.length); - - for (var i in gdata){ - console.log("TEST:" + i); - var prop = usersystem.getPreference(gdata[i],browserapp.addglobaldataset); - - } - - }, - addglobaldataset: function(key,gdataset){ - $("#globaldatasets").append(''); }, loaddataset: function(){ if ($("globaldatasets").val() == ""){ this.config = null; }else { var ldata = usersystem.getPreference($("globaldatasets").val()); - console.log("New Loaded DataSet:"); - console.log(ldata); this.config={dbfile:ldata.dbfile,serviceurl:"http://"+ldata.server+":6060/"}; } - - } } \ No newline at end of file diff --git a/renderer.js b/renderer.js index a6d612c..8ad4921 100644 --- a/renderer.js +++ b/renderer.js @@ -30,65 +30,34 @@ var usersystem = { dialog.showErrorBox(errtitle, errmsg); }, setPreference: function(key,data){ - - console.log("save preferences to: " + this.profilepath() + key + ".json"); + //console.log("save preferences to: " + this.profilepath() + key + ".json"); if ((typeof data == 'object') || (typeof data == 'array')){ data = JSON.stringify(data); } - fs.writeFile(this.profilepath() + key + ".json", data, (err) => { - if (err) { - this.showError("Error writing Preference!",err.message); - console.log(err); - return false; - } - console.log("save preferences saved!"); - return true; - - }); - return false; + var result = fs.writeFileSync(this.profilepath() + key + ".json", data); + return result; }, - getPreference: function(key,callback=null){ + getPreference: function(key){ var data = null; if (fs.existsSync(this.profilepath() + key + ".json")){ console.log("Read Key:" + key); - fs.readFile(this.profilepath() + key + ".json", 'utf-8', (err, data) => { - if(err){ - //this.showError("Error reading Preference!",err.message); - console.log("Error reading Preference!" + err.message); - return data; - } - //console.log(data); - if (data.startsWith("{") || data.startsWith("[")){ - data = JSON.parse(data); - } - if (callback){ - callback(key,data); - } - - // Change how to handle the file content - //console.log("The preference content is : " ); - //console.log(data); - return data; - }); + var data = fs.readFile(this.profilepath() + key + ".json", 'utf-8') + if (data.startsWith("{") || data.startsWith("[")){ + data = JSON.parse(data); + } + return data; } return data; }, - getLocalDataSets: function(callback=null){ + getLocalDataSets: function(){ var datasets =[]; - fs.readdir(this.profilepath(), function (err, files) { - //handling error - if (err) { - return console.log('Unable to scan directory: ' + err); - } - //listing all files using forEach - files.forEach(function (file) { - if (file.match('db\..*\.json')){ - console.log(file); - datasets.push(file.replace('.json','')); - } - }); - callback(datasets); + var files = fs.readdirSync(this.profilepath()); + files.forEach(function(file) { + if (file.match('db\..*\.json')){ + datasets.push(file.replace('.json','')); + } }); + return datasets; }, getsysinfo: function(){ return {