" + json.msg);
- } else {
- Ext.Msg.alert("Error", "The Chart could not be saved!");
- }
- },
- failure: function() {
- chart.setLoading(false);
- if (json && json.msg) {
- Ext.Msg.alert("Error", "The Chart could not be saved, error Message is:
" + json.msg);
- } else {
- Ext.Msg.alert("Error", "The Chart could not be saved!");
- }
+ //decide if we save to db or to file
+ var filelogbool = false,
+ dblogbool = false;
+
+ Ext.each(logtypes, function(typeradio) {
+ if (typeradio.getChecked()[0].inputValue === "filelog") {
+ filelogbool = true;
+ } else {
+ dblogbool = true;
}
});
+
+ if (filelogbool === true && dblogbool === false) {
+
+ // create the current chart object
+ var chartobject = {},
+ hash = 0,
+ k,
+ char;
+
+ // generate hash from savename
+ for (k = 0, l = savename.length; k < l; k++) {
+ char = savename.charCodeAt(k);
+ hash = ((hash<<5)-hash)+char;
+ hash |= 0; // Convert to 32bit integer
+ }
+
+ chartobject.ID = hash;
+ chartobject.NAME = savename;
+ chartobject.TIMESTAMP = Ext.Date.format(new Date(), 'Y-m-d H:i:s');
+ chartobject.TYPE = "savedfilelogchart";
+ chartobject.VALUE = Ext.decode(jsonConfig);
+
+ // append the chartobject to the global FHEM.filelogcharts
+ FHEM.filelogcharts.push(chartobject);
+
+ me.updateFileLogCharts(true);
+
+ } else {
+
+ var url = '../../../fhem?cmd=get+' + FHEM.dblogname + '+-+webchart+' + dbstarttime + '+' + dbendtime + '+';
+ url +=devices[0].getValue() + '+savechart+""+""+' + savename + '+' + jsonConfig + '&XHR=1';
+ Ext.Ajax.request({
+ method: 'POST',
+ disableCaching: false,
+ url: url,
+ success: function(response){
+ chart.setLoading(false);
+ var json = Ext.decode(response.responseText);
+ if (json.success === "true" || json.data && json.data.length === 0) {
+ me.getMaintreepanel().fireEvent("treeupdated");
+ Ext.Msg.alert("Success", "Chart successfully saved!");
+ } else if (json.msg) {
+ Ext.Msg.alert("Error", "The Chart could not be saved, error Message is:
" + json.msg);
+ } else {
+ Ext.Msg.alert("Error", "The Chart could not be saved!");
+ }
+ },
+ failure: function() {
+ chart.setLoading(false);
+ if (json && json.msg) {
+ Ext.Msg.alert("Error", "The Chart could not be saved, error Message is:
" + json.msg);
+ } else {
+ Ext.Msg.alert("Error", "The Chart could not be saved!");
+ }
+ }
+ });
+ }
+
}
}, this);
},
+ /**
+ * function used to update the filelogcharts by given cmd
+ */
+ updateFileLogCharts: function(treeupdate) {
+ var me = this,
+ chart = me.getChart();
+
+ // preapre the string for the file
+ var finalstring = "FHEM.filelogcharts = " + Ext.encode(FHEM.filelogcharts) + ";;";
+
+ var cmd = "{ `echo '" + finalstring + "' > www/frontend/www/frontend/app/filelogcharts.js`}";
+// var cmd = "{ `echo '" + finalstring + "' > www/frontenddev/app/filelogcharts.js`}";
+
+ Ext.Ajax.request({
+ method: 'POST',
+ disableCaching: false,
+ url: '../../../fhem?',
+ params: {
+ cmd: cmd,
+ XHR: 1
+ },
+ success: function(response){
+ if (chart) {
+ chart.setLoading(false);
+ }
+ if (treeupdate) {
+ me.getMaintreepanel().fireEvent("treeupdated");
+ }
+
+ if (response.status === 200) {
+ Ext.Msg.alert("Success", "Changes successfully saved!");
+ } else if (response.statusText) {
+ Ext.Msg.alert("Error", "The Changes could not be saved, error Message is:
" + response.statusText);
+ } else {
+ Ext.Msg.alert("Error", "The Changes could not be saved!");
+ }
+ },
+ failure: function(response) {
+ if (chart) {
+ chart.setLoading(false);
+ }
+ me.getMaintreepanel().setLoading(false);
+ if (response.statusText) {
+ Ext.Msg.alert("Error", "The Changes could not be saved, error Message is:
" + response.statusText);
+ } else {
+ Ext.Msg.alert("Error", "The Changes could not be saved!");
+ }
+ }
+ });
+ },
+
/**
* loading saved chart data and trigger the load of the chart
*/
@@ -1558,7 +1719,8 @@ Ext.define('FHEM.controller.ChartController', {
record.raw.data = record.raw;
}
var me = this;
- if (record.raw.data && record.raw.data.TYPE && record.raw.data.TYPE === "savedchart") {
+ if (record.raw.data && record.raw.data.TYPE &&
+ (record.raw.data.TYPE === "savedchart" || record.raw.data.TYPE === "savedfilelogchart" )) {
var name = record.raw.data.NAME,
chartdata = record.raw.data.VALUE;
@@ -1598,6 +1760,7 @@ Ext.define('FHEM.controller.ChartController', {
yaxeslength++;
}
+ var logtypes = Ext.ComponentQuery.query('radiogroup[name=datasourceradio]');
var devices = Ext.ComponentQuery.query('combobox[name=devicecombo]');
var yaxes = Ext.ComponentQuery.query('combobox[name=yaxiscombo]');
var yaxescolorcombos = Ext.ComponentQuery.query('combobox[name=yaxiscolorcombo]');
@@ -1605,10 +1768,14 @@ Ext.define('FHEM.controller.ChartController', {
var yaxesstepchecks = Ext.ComponentQuery.query('checkbox[name=yaxisstepcheck]');
var axissideradio = Ext.ComponentQuery.query('radiogroup[name=axisside]');
var yaxesstatistics = Ext.ComponentQuery.query('combobox[name=yaxisstatisticscombo]');
+ var logtypename;
var i = 0;
Ext.each(yaxes, function(yaxis) {
+
if (i === 0) {
+ logtypename = logtypes[i].getChecked()[0].name;
+ eval('logtypes[i].setValue({' + logtypename + ': "' + chartdata.logtype + '"})');
devices[i].setValue(chartdata.device);
yaxes[i].getStore().getProxy().url = url = '../../../fhem?cmd=get+' + FHEM.dblogname + '+-+webchart+""+""+' + chartdata.device + '+getreadings&XHR=1';
yaxes[i].setDisabled(false);
@@ -1625,14 +1792,16 @@ Ext.define('FHEM.controller.ChartController', {
}
i++;
} else {
- var axisdevice = "y" + (i + 1) + "device",
+ logtypename = logtypes[i].getChecked()[0].name,
+ logtype = "y" + (i + 1) + "logtype",
+ axisdevice = "y" + (i + 1) + "device",
axisname = "y" + (i + 1) + "axis",
axiscolorcombo = axisname + "colorcombo",
axisfillcheck = axisname + "fillcheck",
axisstepcheck = axisname + "stepcheck",
axisside = axisname + "side",
axisstatistics = axisname + "statistics";
-
+ eval('logtypes[i].setValue({' + logtypename + ' : chartdata.' + logtype + '})');
eval('devices[i].setValue(chartdata.' + axisdevice + ')');
yaxes[i].getStore().getProxy().url = '../../../fhem?cmd=get+' + FHEM.dblogname + '+-+webchart+""+""+' + eval('chartdata.' + axisdevice) + '+getreadings&XHR=1';
yaxes[i].setDisabled(false);
@@ -1689,12 +1858,13 @@ Ext.define('FHEM.controller.ChartController', {
//convert time
var dynamicradio = Ext.ComponentQuery.query('radiogroup[name=dynamictime]')[0],
st = chartdata.starttime;
- if (st === "year" || st === "month" || st === "week" || st === "day" || st === "hour") {
- dynamicradio.eachBox(function(box, idx) {
- if (box.inputValue === st) {
- box.setValue(true);
- }
- });
+ if (st === "year" || st === "month" || st === "week" || st === "day" || st === "hour" ||
+ st === "lasthour" || st === "last24h" || st === "last7days" || st === "lastmonth") {
+ dynamicradio.eachBox(function(box, idx) {
+ if (box.inputValue === st) {
+ box.setValue(true);
+ }
+ });
} else {
var start = chartdata.starttime.replace("_", " "),
end = chartdata.endtime.replace("_", " ");
@@ -1771,30 +1941,41 @@ Ext.define('FHEM.controller.ChartController', {
var url = '../../../fhem?cmd=get+' + FHEM.dblogname + '+-+webchart+""+""+""+renamechart+""+""+' + savename + '+' + chartid + '&XHR=1';
- Ext.Ajax.request({
- method: 'GET',
- disableCaching: false,
- url: url,
- success: function(response){
- var json = Ext.decode(response.responseText);
- if (json && json.success === "true" || json.data && json.data.length === 0) {
- me.getMaintreepanel().fireEvent("treeupdated");
- Ext.Msg.alert("Success", "Chart successfully renamed!");
- } else if (json && json.msg) {
- Ext.Msg.alert("Error", "The Chart could not be renamed, error Message is:
" + json.msg);
- } else {
- Ext.Msg.alert("Error", "The Chart could not be renamed!");
- }
- },
- failure: function() {
- if (json && json.msg) {
- Ext.Msg.alert("Error", "The Chart could not be renamed, error Message is:
" + json.msg);
- } else {
- Ext.Msg.alert("Error", "The Chart could not be renamed!");
- }
+ if (menu.record.raw.data.TYPE === "savedfilelogchart") {
+ if (Ext.Array.contains(FHEM.filelogcharts, menu.record.raw.data) === true) {
+ Ext.Array.remove(FHEM.filelogcharts, menu.record.raw.data);
+
+ var newRec = menu.record.raw.data;
+ newRec.NAME = savename;
+ FHEM.filelogcharts.push(newRec);
+
+ me.updateFileLogCharts(true);
}
- });
-
+ } else {
+ Ext.Ajax.request({
+ method: 'GET',
+ disableCaching: false,
+ url: url,
+ success: function(response){
+ var json = Ext.decode(response.responseText);
+ if (json && json.success === "true" || json.data && json.data.length === 0) {
+ me.getMaintreepanel().fireEvent("treeupdated");
+ Ext.Msg.alert("Success", "Chart successfully renamed!");
+ } else if (json && json.msg) {
+ Ext.Msg.alert("Error", "The Chart could not be renamed, error Message is:
" + json.msg);
+ } else {
+ Ext.Msg.alert("Error", "The Chart could not be renamed!");
+ }
+ },
+ failure: function() {
+ if (json && json.msg) {
+ Ext.Msg.alert("Error", "The Chart could not be renamed, error Message is:
" + json.msg);
+ } else {
+ Ext.Msg.alert("Error", "The Chart could not be renamed!");
+ }
+ }
+ });
+ }
}
});
},
@@ -1825,40 +2006,50 @@ Ext.define('FHEM.controller.ChartController', {
var url = '../../../fhem?cmd=get+' + FHEM.dblogname + '+-+webchart+""+""+""+deletechart+""+""+' + chartid + '&XHR=1';
- Ext.Ajax.request({
- method: 'GET',
- disableCaching: false,
- url: url,
- success: function(response){
- var json = Ext.decode(response.responseText);
- if (json && json.success === "true" || json.data && json.data.length === 0) {
- var rootNode = me.getMaintreepanel().getRootNode();
- var deletedNode = rootNode.findChildBy(function(rec) {
- if (rec.raw.data && rec.raw.data.ID === chartid) {
- return true;
- }
- }, this, true);
- if (deletedNode) {
- deletedNode.destroy();
- }
- Ext.Msg.alert("Success", "Chart successfully deleted!");
-
- } else if (json && json.msg) {
- Ext.Msg.alert("Error", "The Chart could not be deleted, error Message is:
" + json.msg);
- } else {
- Ext.Msg.alert("Error", "The Chart could not be deleted!");
- }
- btn.up().up().destroy();
- },
- failure: function() {
- if (json && json.msg) {
- Ext.Msg.alert("Error", "The Chart could not be deleted, error Message is:
" + json.msg);
- } else {
- Ext.Msg.alert("Error", "The Chart could not be deleted!");
- }
+ if (menu.record.raw.data.TYPE === "savedfilelogchart") {
+ if (Ext.Array.contains(FHEM.filelogcharts, menu.record.raw.data) === true) {
+ Ext.Array.remove(FHEM.filelogcharts, menu.record.raw.data);
+
+ me.updateFileLogCharts(true);
btn.up().up().destroy();
}
- });
+ } else {
+ Ext.Ajax.request({
+ method: 'GET',
+ disableCaching: false,
+ url: url,
+ success: function(response){
+ var json = Ext.decode(response.responseText);
+ if (json && json.success === "true" || json.data && json.data.length === 0) {
+ var rootNode = me.getMaintreepanel().getRootNode();
+ var deletedNode = rootNode.findChildBy(function(rec) {
+ if (rec.raw.data && rec.raw.data.ID === chartid) {
+ return true;
+ }
+ }, this, true);
+ if (deletedNode) {
+ deletedNode.destroy();
+ }
+ Ext.Msg.alert("Success", "Chart successfully deleted!");
+
+ } else if (json && json.msg) {
+ Ext.Msg.alert("Error", "The Chart could not be deleted, error Message is:
" + json.msg);
+ } else {
+ Ext.Msg.alert("Error", "The Chart could not be deleted!");
+ }
+ btn.up().up().destroy();
+ },
+ failure: function() {
+ if (json && json.msg) {
+ Ext.Msg.alert("Error", "The Chart could not be deleted, error Message is:
" + json.msg);
+ } else {
+ Ext.Msg.alert("Error", "The Chart could not be deleted!");
+ }
+ btn.up().up().destroy();
+ }
+ });
+ }
+
}
},
{
@@ -1999,14 +2190,19 @@ Ext.define('FHEM.controller.ChartController', {
* handling the moving of nodes in tree, saving new position of saved charts in db
*/
movenodeintree: function(treeview, action, collidatingrecord) {
- var unsorted = Ext.ComponentQuery.query('treepanel button[name=unsortedtree]')[0].pressed;
+ var me = this,
+ unsorted = Ext.ComponentQuery.query('treepanel button[name=unsortedtree]')[0].pressed;
//only save orders when in sorted mode
if (!unsorted) {
+ Ext.ComponentQuery.query('treepanel')[0].setLoading(true);
var rec = action.records[0],
id = rec.raw.data.ID;
- if (rec.raw.data && rec.raw.data.ID && rec.raw.data.TYPE === "savedchart" && !rec.raw.data.template) {
+ if (rec.raw.data && rec.raw.data.ID &&
+ (rec.raw.data.TYPE === "savedchart" || rec.raw.data.TYPE === "savedfilelogchart") &&
+ !rec.raw.data.template) {
+
var rootNode = this.getMaintreepanel().getRootNode();
rootNode.cascadeBy(function(node) {
if (node.raw && node.raw.data && node.raw.data.ID && node.raw.data.ID === id) {
@@ -2024,35 +2220,51 @@ Ext.define('FHEM.controller.ChartController', {
var encodedchartconfig = Ext.encode(chartconfig),
url = '../../../fhem?cmd=get+' + FHEM.dblogname + '+-+webchart+""+""+""+updatechart+""+""+' + chartid + '+' + encodedchartconfig + '&XHR=1';
- Ext.Ajax.request({
- method: 'GET',
- disableCaching: false,
- url: url,
- success: function(response){
- var json = Ext.decode(response.responseText);
- if (json && json.success === "true" || json.data && json.data.length === 0) {
- //be quiet
- } else if (json && json.msg) {
- Ext.Msg.alert("Error", "The new position could not be saved, error Message is:
" + json.msg);
- } else {
- Ext.Msg.alert("Error", "The new position could not be saved!");
- }
- },
- failure: function() {
- if (json && json.msg) {
- Ext.Msg.alert("Error", "The new position could not be saved, error Message is:
" + json.msg);
- } else {
- Ext.Msg.alert("Error", "The new position could not be saved!");
- }
+ // check for filelog or dblog
+ if (node.raw.data.TYPE === "savedfilelogchart") {
+
+ if (Ext.Array.contains(FHEM.filelogcharts, rec.raw.data) === true) {
+ Ext.Array.remove(FHEM.filelogcharts, rec.raw.data);
+ var newRec = rec.raw.data;
+ newRec.parentFolder = ownerfolder;
+ newRec.treeIndex = index;
+ FHEM.filelogcharts.push(newRec);
+//
+ me.updateFileLogCharts();
}
- });
+
+ } else {
+ Ext.Ajax.request({
+ method: 'GET',
+ disableCaching: false,
+ url: url,
+ success: function(response){
+ Ext.ComponentQuery.query('treepanel')[0].setLoading(false);
+ var json = Ext.decode(response.responseText);
+ if (json && json.success === "true" || json.data && json.data.length === 0) {
+ //be quiet
+ } else if (json && json.msg) {
+ Ext.Msg.alert("Error", "The new position could not be saved, error Message is:
" + json.msg);
+ } else {
+ Ext.Msg.alert("Error", "The new position could not be saved!");
+ }
+ },
+ failure: function() {
+ Ext.ComponentQuery.query('treepanel')[0].setLoading(false);
+ if (json && json.msg) {
+ Ext.Msg.alert("Error", "The new position could not be saved, error Message is: