2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-01-31 12:49:34 +00:00

several bugfixes, parser enhancements, see forum post for details

git-svn-id: https://svn.fhem.de/fhem/trunk@5224 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
johannnes 2014-03-14 17:18:16 +00:00
parent 6c9160414e
commit 6a9bdec573
2 changed files with 285 additions and 217 deletions

View File

@ -282,7 +282,7 @@ UPD 2014-01-12_12:09:17 5144 www/frontend/app/view/StatusPanel.js
UPD 2014-01-12_12:55:22 10486 www/frontend/app/view/Viewport.js
UPD 2014-01-12_04:44:35 22438 www/frontend/app/controller/MainController.js
UPD 2014-01-12_02:49:58 16562 www/frontend/app/controller/StatusController.js
UPD 2014-01-12_03:28:35 109269 www/frontend/app/controller/ChartController.js
UPD 2014-03-14_05:50:19 111937 www/frontend/app/controller/ChartController.js
UPD 2013-06-30_11:46:54 5415 www/frontend/app/controller/TableDataController.js
UPD 2013-04-01_07:04:35 202 www/frontend/app/model/ReadingsModel.js
UPD 2013-04-01_07:04:36 338 www/frontend/app/model/SavedChartsModel.js

View File

@ -239,12 +239,21 @@ Ext.define('FHEM.controller.ChartController', {
var splitArr = row.split(" "),
i = 2; // 2 is needed as offset, because get function starts at one and our array at 0
Ext.each(splitArr, function(key) {
if (key.lastIndexOf(":") + 1 === key.length &&
// first we need to check if key is empty string, which can be caused by logfiles
// that contain multiple spaces between key / values in one row...
// in that case, we will skip the entry
if (key !== "" &&
key.lastIndexOf(":") + 1 === key.length &&
!Ext.Array.contains(keyArray, key.replace(":", ""))) {
keyArray.push(key.replace(":", ""));
keyIndexArray.push(i);
}
// only raise counter when key is not empty string (multiple whitespaces),
// as the get function will exactly work like this
if (key !== "") {
i++;
}
});
});
@ -781,10 +790,10 @@ Ext.define('FHEM.controller.ChartController', {
});
// last fallback, similar to parseint
queryString += '$fld[3]*1';
queryString += '$fld[' + (yaxisindex - 1) + ']*1';
// add closing brackets
for (bracket = 1; bracket < count; bracket++) {
for (var bracket = 1; bracket < count; bracket++) {
queryString += ")";
}
}
@ -1328,8 +1337,10 @@ Ext.define('FHEM.controller.ChartController', {
* reset the form fields e.g. when loading a new chart
*/
resetFormFields: function() {
this.getLinechartpanel().axiscounter = 0;
//remove a possibly set record of the last loaded chart
this.getLinechartpanel().record = null;
var fieldset = this.getChartformpanel().down('fieldset[name=axesfieldset]');
fieldset.removeAll();
this.getLinechartpanel().createNewYAxis();
@ -1396,14 +1407,33 @@ Ext.define('FHEM.controller.ChartController', {
/**
* save the current chart to database
* save the current chart
*/
saveChartData: function() {
saveChartData: function(btn, evt, savename, scope) {
var me = this;
var me = scope ? scope : this,
update = false,
lcp = me.getLinechartpanel();
// detect if we have a loaded chart or a new one
if (lcp && lcp.record && lcp.record !== null) {
// we have a already saved chart, need to update
savename = lcp.record.NAME;
update = true;
} else {
// we got a new chart which needs to be saved
if (!savename || Ext.isEmpty(savename)) {
Ext.Msg.prompt("Select a name", "Enter a name to save the Chart", function(action, savename) {
if (action === "ok" && !Ext.isEmpty(savename)) {
me.saveChartData(null, null, savename, me);
}
}, me);
// we need to return as the script continues without waiting for user input
return;
}
}
if (savename && !Ext.isEmpty(savename)) {
//replacing spaces in name
savename = savename.replace(/ /g, "_");
//replacing + in name
@ -1431,8 +1461,7 @@ Ext.define('FHEM.controller.ChartController', {
generalizationfactor = Ext.ComponentQuery.query('combobox[name=genfactor]')[0].getValue(),
leftaxisconfiguration = Ext.ComponentQuery.query('radiogroup[name=leftaxisconfiguration]')[0].getChecked()[0].inputValue,
rightaxisconfiguration = Ext.ComponentQuery.query('radiogroup[name=rightaxisconfiguration]')[0].getChecked()[0].inputValue,
chart = me.getChart(),
store = chart.getStore();
chart = me.getChart();
//setting the start / endtime parameter in the chartconfig to the string of the radiofield, gets parsed on load
if (this.getStarttimepicker().isDisabled()) {
@ -1450,7 +1479,7 @@ Ext.define('FHEM.controller.ChartController', {
var logtype = logtypes[i].getChecked()[0].inputValue,
device = dev.getValue(),
yaxis = yaxes[i].getValue(),
yaxis = yaxes[i].getValue() ? yaxes[i].getValue() : yaxes[i].rawValue,
linestrokewidth = rowFieldSets[i].styleConfig.linestrokewidth,
linecolorhexcode = rowFieldSets[i].styleConfig.linecolorhexcode.toString(),
fillopacity = rowFieldSets[i].styleConfig.fillopacity,
@ -1570,7 +1599,9 @@ Ext.define('FHEM.controller.ChartController', {
jsonConfig += '"starttime":"' + dbstarttime + '","endtime":"' + dbendtime + '"}';
if (chart) {
chart.setLoading(true);
}
//decide if we save to db or to file
var filelogbool = false,
@ -1586,6 +1617,23 @@ Ext.define('FHEM.controller.ChartController', {
if (filelogbool === true && dblogbool === false) {
var filelogrecfound = false;
// check for create or update
if (update === true) {
// find the current chart and relplace it
Ext.each(FHEM.filelogcharts, function(chart) {
if (chart.ID === lcp.record.ID) {
filelogrecfound = chart;
}
});
if (!filelogrecfound) {
Ext.Msg.alert("Error", "Could not find the original Chart to update..");
} else {
filelogrecfound.TIMESTAMP = Ext.Date.format(new Date(), 'Y-m-d H:i:s');
filelogrecfound.VALUE = Ext.decode(jsonConfig);
me.updateFileLogCharts(false);
}
} else {
// create the current chart object
var chartobject = {},
hash = 0,
@ -1607,19 +1655,30 @@ Ext.define('FHEM.controller.ChartController', {
// 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 + '+';
var url;
// check for create or update
if (update === true) {
url = '../../../fhem?cmd=get+' + FHEM.dblogname + '+-+webchart+' + dbstarttime + '+' + dbendtime + '+';
url +=devices[0].getValue() + '+updatechart+""+""+' + lcp.record.ID + '+' + jsonConfig + '&XHR=1';
} else {
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){
if (chart) {
chart.setLoading(false);
}
var json = Ext.decode(response.responseText);
if (json.success === "true" || json.data && json.data.length === 0) {
me.getMaintreepanel().fireEvent("treeupdated");
@ -1631,7 +1690,9 @@ Ext.define('FHEM.controller.ChartController', {
}
},
failure: function() {
if (chart) {
chart.setLoading(false);
}
if (json && json.msg) {
Ext.Msg.alert("Error", "The Chart could not be saved, error Message is:<br><br>" + json.msg);
} else {
@ -1641,8 +1702,9 @@ Ext.define('FHEM.controller.ChartController', {
});
}
} else {
Ext.Msg.alert("Error", "No name for the chart has been found!");
}
}, this);
},
@ -1729,6 +1791,9 @@ Ext.define('FHEM.controller.ChartController', {
if (chartdata && !Ext.isEmpty(chartdata)) {
// set the rec of the loading record to panel to detect if chart needs update or create on save
this.getLinechartpanel().record = record.raw.data;
//reset y-axis max
me.maxYValue = 0;
me.minYValue = 9999999;
@ -1782,6 +1847,9 @@ Ext.define('FHEM.controller.ChartController', {
} else {
yaxes[i].getStore().getProxy().url = url = '../../../fhem?cmd=get+' + FHEM.dblogname + '+-+webchart+""+""+' + chartdata.device + '+getreadings&XHR=1';
}
// disable the datasource selection, as changing this on a saved chart would be
// a lot of work...
logtypes[i].setDisabled(true);
yaxes[i].setDisabled(false);
yaxes[i].setValue(chartdata.y);
rowFieldSets[i].styleConfig.linestrokewidth = chartdata.linestrokewidth || 2;