$( 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){
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){
//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('<option value="'+ds[i]+'">'+prop.name+'</option>');
}
- 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('<option value="'+key+'">'+gdataset.name+'</option>');
},
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
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 {