From ed85df4b90236d97d5df6c25bb4d0f46f7e9e3f1 Mon Sep 17 00:00:00 2001 From: Kilian Saffran Date: Mon, 25 Feb 2019 21:27:41 +0100 Subject: [PATCH] adminview settings and printtemplates --- admin.html | 2 +- cashbox.html | 69 ++++++++ css/app.css | 8 + index.html | 50 ++---- js/app.js | 44 ----- js/mainapp.js | 58 +++++++ main.js | 2 +- modules/clients/index.js | 4 +- modules/products/index.js | 2 +- modules/settings/db/cashbox.sql | 119 ++++++++++++++ modules/settings/form_datastore.html | 194 +++++++++++++++++++++++ modules/settings/form_datastore.js | 14 ++ modules/settings/form_printtemplate.html | 65 ++++++++ modules/settings/form_printtemplate.js | 4 + modules/settings/index.html | 56 +++++++ modules/settings/index.js | 71 +++++++++ modules/settings/lib/datastore.js | 46 ++++++ modules/settings/lib/printtemplate.js | 14 ++ modules/stations/index.html | 2 +- modules/stations/index.js | 4 +- modules/tables/index.html | 2 +- modules/tables/index.js | 4 +- modules/transactions/index.html | 2 +- modules/transactions/index.js | 4 +- renderer.js | 49 +++--- 25 files changed, 773 insertions(+), 116 deletions(-) delete mode 100644 js/app.js create mode 100644 js/mainapp.js create mode 100644 modules/settings/db/cashbox.sql create mode 100644 modules/settings/form_datastore.html create mode 100644 modules/settings/form_datastore.js create mode 100644 modules/settings/form_printtemplate.html create mode 100644 modules/settings/form_printtemplate.js create mode 100644 modules/settings/index.html create mode 100644 modules/settings/index.js create mode 100644 modules/settings/lib/datastore.js create mode 100644 modules/settings/lib/printtemplate.js diff --git a/admin.html b/admin.html index be926a1..ebf724e 100644 --- a/admin.html +++ b/admin.html @@ -45,7 +45,7 @@ - + diff --git a/cashbox.html b/cashbox.html index e69de29..c0f4c19 100644 --- a/cashbox.html +++ b/cashbox.html @@ -0,0 +1,69 @@ + + + + + + + + + + +CASHBOX + + + +
+
+
+
+

CashBox

+
+
+ +
+
+
+
+ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/css/app.css b/css/app.css index d4d9112..7da579b 100644 --- a/css/app.css +++ b/css/app.css @@ -55,6 +55,10 @@ select.form-control { background-repeat: no-repeat; } +select.bg-primary, select.bg-primary:hover, select.bg-primary:active { + background-image: url("data:image/svg+xml;utf8,"); + color: #fff; + } input.right { text-align: right; } @@ -63,4 +67,8 @@ input.right { color: #fff; +} + +.card { +margin: 10px; } \ No newline at end of file diff --git a/index.html b/index.html index 3f28e45..f017df1 100644 --- a/index.html +++ b/index.html @@ -8,52 +8,36 @@ -CASHBOX +Invoice Journal
-
-
-
-

CashBox

-
-
- -
-
-
-
+ - + - + @@ -63,7 +47,7 @@ var browserapp = { - + diff --git a/js/app.js b/js/app.js deleted file mode 100644 index 70c9a10..0000000 --- a/js/app.js +++ /dev/null @@ -1,44 +0,0 @@ - -// $("#menu-toggle").click(function(e) { -// e.preventDefault(); -// $("#wrapper").toggleClass("toggled"); -// }); - -$( document ).ready(function() { - console.log( "Main ready!" ); - browserapp.loadmodule("overview"); - console.log("After module load!"); -}); -console.log(navigator.platform); -console.log(location.protocol); -var browserapp = { -loadview: function(viewname){ - location.href= viewname + '.html'; -}, -loadmodule: function(modulename){ - var appdata = browserapp.getconfig(); - var params = "?"; - for (var i in appdata){ - params += "&" + i +"=" + encodeURIComponent(appdata[i]); - } - 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 params = "?"; - for (var i in appdata){ - params += "&" + i +"=" + encodeURIComponent(appdata[i]); - } - if (pageparams){ - for (var i in pageparams){ - params += "&" + i +"=" + encodeURIComponent(pageparams[i]); - } - } - //console.log("modules/"+modulename+"/index.html"+params); - $("#moduleframe").attr("src","modules/"+modulename+"/"+ page +".html"+ params); -}, -getconfig:function (){ - return {dbfile:"invoicejournal",serviceurl:"http://localhost:6060/"}; -} -} \ No newline at end of file diff --git a/js/mainapp.js b/js/mainapp.js new file mode 100644 index 0000000..cb6645e --- /dev/null +++ b/js/mainapp.js @@ -0,0 +1,58 @@ +$( document ).ready(function() { + console.log( "Main ready!" ); + browserapp.setdatasets(); + browserapp.loaddataset(); + browserapp.loadmodule("overview"); + console.log("After module load!"); +}); + +//console.log(navigator.platform); +//console.log(location.protocol); +var browserapp = { + config: null, + datasets: null, + loadmodule: function(modulename){ + //var appdata = browserapp.getconfig(); + var params = "?"; + for (var i in this.config){ + params += "&" + i +"=" + encodeURIComponent(this.config[i]); + } + //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 params = "?"; + for (var i in this.config){ + params += "&" + i +"=" + encodeURIComponent(this.config[i]); + } + if (pageparams){ + for (var i in pageparams){ + params += "&" + i +"=" + encodeURIComponent(pageparams[i]); + } + } + //console.log("modules/"+modulename+"/index.html"+params); + $("#moduleframe").attr("src","modules/"+modulename+"/"+ page +".html"+ params); + }, + setdatasets: function(myds){ + $("#globaldatasets").html(""); + var ds = usersystem.getLocalDataSets(); + for (var i in ds){ + var prop = usersystem.getPreference(ds[i]); + $("#globaldatasets").append(''); + } + }, + currentdataset: function(){ + return $("#globaldatasets :selected").val(); + }, + loaddataset: function(){ + var gdset = $("#globaldatasets :selected").val(); + if (gdset == ""){ + this.config = null; + }else { + var ldata = usersystem.getPreference(gdset); + this.config={dbfile:ldata.dbfile,serviceurl:"http://"+ldata.server+":6060/"}; + } + } + +} \ No newline at end of file diff --git a/main.js b/main.js index fb5f37a..f49e854 100644 --- a/main.js +++ b/main.js @@ -23,7 +23,7 @@ function createWindow () { mainWindow = new BrowserWindow({ show: false, - frame: false, + // frame: false, webPreferences: { nodeIntegration: true } diff --git a/modules/clients/index.js b/modules/clients/index.js index 4172c12..9f39e0d 100644 --- a/modules/clients/index.js +++ b/modules/clients/index.js @@ -15,7 +15,7 @@ function loadtable(){ // 'printf("%.2f",CAST(sum(pos.quantity * pos.unitamount) + case when pos.taxpercent > 0 then sum(pos.taxpercent * pos.quantity * pos.unitamount) else 0.0 end AS real)) as totalamount, ' + // 'printf("%.2f",COALESCE(ij.payedamount,0.0)) as payedamount, ' + // 'ij.status ' + - // 'from invoicejournal ij ' + + // 'from cashbox ij ' + // 'left join invoicepositions pos on (ij.id=pos.id_invoice) ' + // 'left join accounts rec on (ij.id_receipient = rec.id) ' + // 'left join accounts sen on (ij.id_sender = sen.id) where ij.byear=' + cfg.byear +' group by pos.id_invoice order by date desc;'; @@ -51,7 +51,7 @@ function loadtable(){ } function loadyears(){ - sql = "select byear from invoicejournal group by byear order by byear asc;"; + sql = "select byear from cashbox group by byear order by byear asc;"; var data = appdb.dbquery(sql); //onsole.log(data.sqldata); for (var i in data.sqldata){ diff --git a/modules/products/index.js b/modules/products/index.js index 2dabae4..026bc24 100644 --- a/modules/products/index.js +++ b/modules/products/index.js @@ -15,7 +15,7 @@ function loadtable(){ // 'printf("%.2f",CAST(sum(pos.quantity * pos.unitamount) + case when pos.taxpercent > 0 then sum(pos.taxpercent * pos.quantity * pos.unitamount) else 0.0 end AS real)) as totalamount, ' + // 'printf("%.2f",COALESCE(ij.payedamount,0.0)) as payedamount, ' + // 'ij.status ' + - // 'from invoicejournal ij ' + + // 'from cashbox ij ' + // 'left join invoicepositions pos on (ij.id=pos.id_invoice) ' + // 'left join accounts rec on (ij.id_receipient = rec.id) ' + // 'left join accounts sen on (ij.id_sender = sen.id) where ij.byear=' + cfg.byear +' group by pos.id_invoice order by date desc;'; diff --git a/modules/settings/db/cashbox.sql b/modules/settings/db/cashbox.sql new file mode 100644 index 0000000..18e3267 --- /dev/null +++ b/modules/settings/db/cashbox.sql @@ -0,0 +1,119 @@ +CREATE Table payementtypes ( + id TEXT, + name TEXT, + modified DATETIME defaults CURRENT_TIMESTAMP, + created DATETIME defaults CURRENT_TIMESTAMP, + primary key (id) +); + +CREATE TRIGGER trg_payementtypes_upd UPDATE ON payementtypes + BEGIN + UPDATE payementtypes SET modified=CURRENT_TIMESTAMP WHERE id = NEW.id; + END; + + +CREATE Table groups ( + id TEXT, + name TEXT, + modified DATETIME defaults CURRENT_TIMESTAMP, + created DATETIME defaults CURRENT_TIMESTAMP, + primary key (id) +); + +CREATE TRIGGER trg_groups_upd UPDATE ON groups + BEGIN + UPDATE groups SET modified=CURRENT_TIMESTAMP WHERE id = NEW.id; + END; + +CREATE Table tables ( + id TEXT, + name TEXT, + seats integer, + modified DATETIME defaults CURRENT_TIMESTAMP, + created DATETIME defaults CURRENT_TIMESTAMP, + primary key (id) +); + +CREATE TRIGGER trg_tables_upd UPDATE ON tables + BEGIN + UPDATE tables SET modified=CURRENT_TIMESTAMP WHERE id = NEW.id; + END; + +CREATE TABLE products ( + id TEXT, + id_group TEXT, + name TEXT, + specification TEXT, + netamount REAL, + grossamount REAL, + vatpercent REAL, + visible BOOLEAN, + modified DATETIME defaults CURRENT_TIMESTAMP, + created DATETIME defaults CURRENT_TIMESTAMP, + primary key (id) +); + +CREATE TRIGGER trg_products_upd UPDATE ON products + BEGIN + UPDATE products SET modified=CURRENT_TIMESTAMP WHERE id = NEW.id; + END; + +CREATE TABLE transactions ( + id TEXT, + id_payementtype TEXT, + id_client TEXT, + id_table TEXT, + id_product TEXT, + netamount REAL, + vatamount REAL, + grossamount REAL, + payedamount REAL, + cashbackamount REAL, + status TEXT, + statusdate DATE, + modified DATETIME defaults CURRENT_TIMESTAMP, + created DATETIME defaults CURRENT_TIMESTAMP, + primary key (id) +); + +CREATE TRIGGER trg_transactions_upd UPDATE ON transactions + BEGIN + UPDATE transactions SET modified=CURRENT_TIMESTAMP WHERE id = NEW.id; + END; + +CREATE TABLE transactiondata ( + id TEXT, + id_transaction TEXT, + id_product TEXT, + id_client TEXT, + id_table TEXT, + netamount REAL, + vatamount REAL, + grossamount REAL, + quantity integer, + modified DATETIME defaults CURRENT_TIMESTAMP, + created DATETIME defaults CURRENT_TIMESTAMP, + primary key (id) +); + +CREATE TRIGGER trg_transactiondata_upd UPDATE ON transactiondata + BEGIN + UPDATE transactiondata SET modified=CURRENT_TIMESTAMP WHERE id = NEW.id; + END; + +CREATE TABLE printtemplates ( + id TEXT, + name TEXT, + templatedesign TEXT, + templatesql TEXT, + templatetype TEXT, + modified DATETIME defaults CURRENT_TIMESTAMP, + created DATETIME defaults CURRENT_TIMESTAMP, + primary key (id) +); + +CREATE TRIGGER trg_printtemplates_upd UPDATE ON printtemplates + BEGIN + UPDATE printtemplates SET modified=CURRENT_TIMESTAMP WHERE id = NEW.id; + END; + \ No newline at end of file diff --git a/modules/settings/form_datastore.html b/modules/settings/form_datastore.html new file mode 100644 index 0000000..a6c3f39 --- /dev/null +++ b/modules/settings/form_datastore.html @@ -0,0 +1,194 @@ + + + + + + + + + + +Datenbank-Einstellungen + + + +
+ +
+
+
+
+
+
+
+ + +
+
+
+
+
+
+
+
+
Verbindung
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+
+
+
+
+
+ Standard Werte +
+
+
+ + +
+
+ + +
+
+
+
+
+
+
+ E-Mail Server +
+
+
+ + +
+
+ +
+ + +
+
+
+ + +
+
+ + +
+
+
+
+
+
+
+
+
+ + + + + + + + + + + +
NameTypStandard
+
+
+
+
Drucker
+
+
+ + + +
+
+ + + +
+
+
+ + +
+
+
+
+
+ + + + + + + + + + + + + + \ No newline at end of file diff --git a/modules/settings/form_datastore.js b/modules/settings/form_datastore.js new file mode 100644 index 0000000..8aaa4ea --- /dev/null +++ b/modules/settings/form_datastore.js @@ -0,0 +1,14 @@ +function initpage(){ + console.log("ID:" + mpref.cfg.id); + if (mpref.cfg.id){ + loadform(); + } +} + +function loadform(){ + var pref = parent.usersystem.getPreference(mpref.cfg.id); + console.log(pref); + for (var i in pref){ + $("#" + i).val(pref[i]); + } +} diff --git a/modules/settings/form_printtemplate.html b/modules/settings/form_printtemplate.html new file mode 100644 index 0000000..04ab82f --- /dev/null +++ b/modules/settings/form_printtemplate.html @@ -0,0 +1,65 @@ + + + + + + + + + + +Druck Template + + + +
+
+ +
+
+ + +
+
+
+
+ + +
+
+
+
+
+ + +
+
+
+ + + + + + + + + + + + + + \ No newline at end of file diff --git a/modules/settings/form_printtemplate.js b/modules/settings/form_printtemplate.js new file mode 100644 index 0000000..ea81536 --- /dev/null +++ b/modules/settings/form_printtemplate.js @@ -0,0 +1,4 @@ +function initpage(){ + console.log(parent.usersystem.getsysinfo()); + //parent.usersystem.setProperty("testproperty",{id:"TEST"}); +} \ No newline at end of file diff --git a/modules/settings/index.html b/modules/settings/index.html new file mode 100644 index 0000000..631f384 --- /dev/null +++ b/modules/settings/index.html @@ -0,0 +1,56 @@ + + + + + + + + + + +Einstellungen + + + +
+ + + + + + + + + + + + + + + +
NameDatabaseServerTypeVPNVerbunden
+
+ + + + + + + + + + + + \ No newline at end of file diff --git a/modules/settings/index.js b/modules/settings/index.js new file mode 100644 index 0000000..3bc9e74 --- /dev/null +++ b/modules/settings/index.js @@ -0,0 +1,71 @@ +var winh = Math.max(document.documentElement.clientHeight, window.innerHeight || 0); +var tblh = winh-54; + +function initpage(){ + console.log(parent.usersystem.getsysinfo()); + loadtable(); + //parent.usersystem.setProperty("testproperty",{id:"TEST"}); +} + +function loadtable(){ + + var connected=parent.browserapp.currentdataset(); + + var localds = parent.usersystem.getLocalDataSets(); + console.log(localds); + for (var i in localds){ + var prop = parent.usersystem.getPreference(localds[i]); + console.log("PROP"); + console.log(connected +"<=>"+ localds[i]); + + console.log(prop); + var row = '' + + '' + + ''+prop.name+'' + + ''+prop.dbfile+'' + + ''+prop.server+'' + + ''+prop.type+'' + + ''+prop.vpn+'' + + ''+ + ''; + $("#tbl_datasets").append(row); + + //$("#globaldatasets").append(''); + } + $('#tbl_datasets').bootstrapTable({ + pagination: false, + search: false, + height: tblh, + clickToSelect: true + }); +} + +// function settings_edit(){ +// var settings_id= getTableSelectionID(); +// if (settings_id){ +// parent.browserapp.loadmodulepage('settings','form_datastore',{"id":settings_id}); +// } + +// } + +function getTableSelectionID(){ + var sel = $('#tbl_datasets').bootstrapTable('getSelections'); + var id = null; + + if (sel){ id=sel[0]._id; } + console.log("Selected ID:" + id); + return id; + } + + function getTableSelectionIDs(){ + var sel = $('#tbl_datasets').bootstrapTable('getSelections'); + var ids = []; + if (sel){ + for (var s in sel){ + ids.push(s._id); + } + } + return ids; + } + + \ No newline at end of file diff --git a/modules/settings/lib/datastore.js b/modules/settings/lib/datastore.js new file mode 100644 index 0000000..834821a --- /dev/null +++ b/modules/settings/lib/datastore.js @@ -0,0 +1,46 @@ +var datastore = { + new: function(){ + parent.browserapp.loadmodulepage('settings','form_datastore',{"id":""}); + }, + edit: function(){ + var settings_id= getTableSelectionID(); + console.log(settings_id); + if (settings_id){ + parent.browserapp.loadmodulepage('settings','form_datastore',{"id":settings_id}); + } + }, + delete: function(){ + + }, + import: function(){ + + }, + export: function(){ + + }, + test: function(){ + + }, + save: function(){ + var dts ={}; + $("input,select").each(function(){ + var inp = $(this); + //console.log(inp); + dts[inp.attr("id")] = inp.val(); + }); + console.log(dts); + console.log(mpref); + if (mpref.cfg.id == ""){ + var keyname = dts['name'].toLowerCase(); + console.log(keyname); + keyname = keyname.replace(/[^a-z0-9-_]/g,""); + console.log(keyname); + mpref.cfg.id = "db."+ keyname; + } + if (dts.name){ + console.log("Before save:" + mpref.cfg.id); + parent.usersystem.setPreference(mpref.cfg.id,dts); + } + + } +} \ No newline at end of file diff --git a/modules/settings/lib/printtemplate.js b/modules/settings/lib/printtemplate.js new file mode 100644 index 0000000..6ca67db --- /dev/null +++ b/modules/settings/lib/printtemplate.js @@ -0,0 +1,14 @@ +var printtemplate = { + new: function(){ + + }, + edit: function(){ + + }, + duplicate: function(){ + + }, + delete: function(){ + + } +} diff --git a/modules/stations/index.html b/modules/stations/index.html index 2a40eb3..2a66de8 100644 --- a/modules/stations/index.html +++ b/modules/stations/index.html @@ -6,7 +6,7 @@ - + Rechnungen diff --git a/modules/stations/index.js b/modules/stations/index.js index b48d6a6..7c61e85 100644 --- a/modules/stations/index.js +++ b/modules/stations/index.js @@ -18,7 +18,7 @@ function loadtable(){ 'printf("%.2f",CAST(sum(pos.quantity * pos.unitamount) + case when pos.taxpercent > 0 then sum(pos.taxpercent * pos.quantity * pos.unitamount) else 0.0 end AS real)) as totalamount, ' + 'printf("%.2f",COALESCE(ij.payedamount,0.0)) as payedamount, ' + 'ij.status ' + - 'from invoicejournal ij ' + + 'from cashbox ij ' + 'left join invoicepositions pos on (ij.id=pos.id_invoice) ' + 'left join accounts rec on (ij.id_receipient = rec.id) ' + 'left join accounts sen on (ij.id_sender = sen.id) where ij.byear=' + cfg.byear +' group by pos.id_invoice order by date desc;'; @@ -54,7 +54,7 @@ function loadtable(){ } function loadyears(){ - sql = "select byear from invoicejournal group by byear order by byear asc;"; + sql = "select byear from cashbox group by byear order by byear asc;"; var data = appdb.dbquery(sql); //onsole.log(data.sqldata); for (var i in data.sqldata){ diff --git a/modules/tables/index.html b/modules/tables/index.html index 2a40eb3..2a66de8 100644 --- a/modules/tables/index.html +++ b/modules/tables/index.html @@ -6,7 +6,7 @@ - + Rechnungen diff --git a/modules/tables/index.js b/modules/tables/index.js index b48d6a6..7c61e85 100644 --- a/modules/tables/index.js +++ b/modules/tables/index.js @@ -18,7 +18,7 @@ function loadtable(){ 'printf("%.2f",CAST(sum(pos.quantity * pos.unitamount) + case when pos.taxpercent > 0 then sum(pos.taxpercent * pos.quantity * pos.unitamount) else 0.0 end AS real)) as totalamount, ' + 'printf("%.2f",COALESCE(ij.payedamount,0.0)) as payedamount, ' + 'ij.status ' + - 'from invoicejournal ij ' + + 'from cashbox ij ' + 'left join invoicepositions pos on (ij.id=pos.id_invoice) ' + 'left join accounts rec on (ij.id_receipient = rec.id) ' + 'left join accounts sen on (ij.id_sender = sen.id) where ij.byear=' + cfg.byear +' group by pos.id_invoice order by date desc;'; @@ -54,7 +54,7 @@ function loadtable(){ } function loadyears(){ - sql = "select byear from invoicejournal group by byear order by byear asc;"; + sql = "select byear from cashbox group by byear order by byear asc;"; var data = appdb.dbquery(sql); //onsole.log(data.sqldata); for (var i in data.sqldata){ diff --git a/modules/transactions/index.html b/modules/transactions/index.html index 2a40eb3..2a66de8 100644 --- a/modules/transactions/index.html +++ b/modules/transactions/index.html @@ -6,7 +6,7 @@ - + Rechnungen diff --git a/modules/transactions/index.js b/modules/transactions/index.js index b48d6a6..7c61e85 100644 --- a/modules/transactions/index.js +++ b/modules/transactions/index.js @@ -18,7 +18,7 @@ function loadtable(){ 'printf("%.2f",CAST(sum(pos.quantity * pos.unitamount) + case when pos.taxpercent > 0 then sum(pos.taxpercent * pos.quantity * pos.unitamount) else 0.0 end AS real)) as totalamount, ' + 'printf("%.2f",COALESCE(ij.payedamount,0.0)) as payedamount, ' + 'ij.status ' + - 'from invoicejournal ij ' + + 'from cashbox ij ' + 'left join invoicepositions pos on (ij.id=pos.id_invoice) ' + 'left join accounts rec on (ij.id_receipient = rec.id) ' + 'left join accounts sen on (ij.id_sender = sen.id) where ij.byear=' + cfg.byear +' group by pos.id_invoice order by date desc;'; @@ -54,7 +54,7 @@ function loadtable(){ } function loadyears(){ - sql = "select byear from invoicejournal group by byear order by byear asc;"; + sql = "select byear from cashbox group by byear order by byear asc;"; var data = appdb.dbquery(sql); //onsole.log(data.sqldata); for (var i in data.sqldata){ diff --git a/renderer.js b/renderer.js index 6076f0f..5459137 100644 --- a/renderer.js +++ b/renderer.js @@ -5,7 +5,9 @@ var usersystem = { profilepath: function(){ var ppath=""; if (os.platform() == "darwin"){ - ppath = os.homedir() + '/Library/Application Support/invoicejournal/'; + ppath = os.homedir() + '/Library/Application Support/cashbox/'; + } else if (os.platform() == "Win32") { + ppath = os.homedir() + '/AppData/Roaming/cashbox/'; } return ppath; }, @@ -27,40 +29,37 @@ var usersystem = { showError: function(errtitle,errmsg){ dialog.showErrorBox(errtitle, errmsg); }, - setProperty(key,data){ - - + setPreference: function(key,data){ + //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; - } - return true; - - }); - return false; + var result = fs.writeFileSync(this.profilepath() + key + ".json", data); + return result; }, - getProperty(key){ + getPreference: function(key){ var data = null; - fs.readFile(this.profilepath() + key + ".json", 'utf-8', (err, data) => { - if(err){ - this.showError("Error reading Preference!",err.message); - return data; - } + if (fs.existsSync(this.profilepath() + key + ".json")){ + console.log("Read Key:" + key); + var data = fs.readFileSync(this.profilepath() + key + ".json", 'utf-8'); if (data.startsWith("{") || data.startsWith("[")){ data = JSON.parse(data); } - // Change how to handle the file content - console.log("The file content is : " + data); - return JSON.stringify(data); - }); + return data; + } return data; }, - getsysinfo(){ + getLocalDataSets: function(){ + var 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 { "hostname": os.hostname(), "userdir": os.homedir(), -- 2.39.5