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

chartingfrontend: replaced deprecated jsonlist calls with jsonlist2 to be future proof

git-svn-id: https://svn.fhem.de/fhem/trunk@6917 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
johannnes 2014-11-08 13:03:05 +00:00
parent 13b26b28fc
commit d1de37d281
8 changed files with 353 additions and 476 deletions

View File

@ -273,17 +273,17 @@ UPD 2013-03-02_01:53:05 524 www/frontend/app/resources/icons/resultset_last.png
UPD 2013-04-03_07:27:17 733 www/frontend/app/resources/icons/add.png
UPD 2013-04-03_07:27:17 389 www/frontend/app/resources/icons/resultset_previous.png
UPD 2013-06-30_11:47:12 101 www/frontend/app/resources/application.css
UPD 2014-01-12_11:31:30 3028 www/frontend/app/app.js
UPD 2014-11-08_12:33:44 2976 www/frontend/app/app.js
UPD 2013-04-28_02:00:20 1205 www/frontend/app/view/ChartGridPanel.js
UPD 2013-07-07_12:12:08 16201 www/frontend/app/view/DevicePanel.js
UPD 2013-12-26_08:39:37 10257 www/frontend/app/view/TableDataGridPanel.js
UPD 2014-11-08_12:44:55 14475 www/frontend/app/view/DevicePanel.js
UPD 2014-11-08_12:52:12 9085 www/frontend/app/view/TableDataGridPanel.js
UPD 2014-04-23_05:47:51 65039 www/frontend/app/view/LineChartPanel.js
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-11-08_12:54:06 8578 www/frontend/app/view/Viewport.js
UPD 2014-11-08_01:05:40 20348 www/frontend/app/controller/MainController.js
UPD 2014-01-12_02:49:58 16562 www/frontend/app/controller/StatusController.js
UPD 2014-04-22_07:46:36 111977 www/frontend/app/controller/ChartController.js
UPD 2013-06-30_11:46:54 5415 www/frontend/app/controller/TableDataController.js
UPD 2014-11-08_12:36:47 111652 www/frontend/app/controller/ChartController.js
UPD 2014-11-08_12:53:12 5408 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
UPD 2013-04-01_07:04:34 11535 www/frontend/app/model/ChartModel.js

View File

@ -4,7 +4,7 @@
Ext.Loader.setConfig({
enabled: true,
disableCaching: false,
disableCaching: true,
paths: {
'FHEM': 'app'
}
@ -27,7 +27,7 @@ Ext.application({
// Gather information from FHEM to display status, devices, etc.
var me = this,
url = '../../../fhem?cmd=jsonlist&XHR=1';
url = '../../../fhem?cmd=jsonlist2&XHR=1';
Ext.Ajax.request({
method: 'GET',
@ -38,22 +38,22 @@ Ext.application({
Ext.getBody().unmask();
try {
FHEM.info = Ext.decode(response.responseText);
FHEM.version = FHEM.info.Results[0].devices[0].ATTR.version;
if (window.location.href.indexOf("frontenddev") > 0) {
FHEM.appPath = 'www/frontenddev/app/';
} else {
FHEM.appPath = 'www/frontend/app/';
}
FHEM.filelogs = [];
Ext.each(FHEM.info.Results, function(result) {
if (result.list === "DbLog" && result.devices[0].NAME) {
FHEM.dblogname = result.devices[0].NAME;
if (result.Internals.TYPE === "DbLog" && result.Internals.NAME) {
FHEM.dblogname = result.Internals.NAME;
}
if (result.list === "FileLog" && result.devices.length > 0) {
FHEM.filelogs = result.devices;
if (result.Internals.TYPE === "FileLog") {
FHEM.filelogs.push(result);
}
});
if ((!FHEM.dblogname || Ext.isEmpty(FHEM.dblogname)) && !FHEM.filelogs) {
if ((!FHEM.dblogname || Ext.isEmpty(FHEM.dblogname)) && Ext.isEmpty(FHEM.filelogs)) {
Ext.Msg.alert("Error", "Could not find a DbLog or FileLog Configuration. Do you have them already defined?");
} else {
Ext.create("FHEM.view.Viewport", {

View File

@ -156,8 +156,8 @@ Ext.define('FHEM.controller.ChartController', {
var fileLogNames = [];
Ext.each(FHEM.filelogs, function(log) {
if (log.REGEXP && log.REGEXP !== "fakelog" && log.NAME !== "") {
var devObj = { "DEVICE": log.NAME};
if (log.Internals.REGEXP && log.Internals.REGEXP !== "fakelog" && log.Internals.NAME !== "") {
var devObj = { "DEVICE": log.Internals.NAME};
fileLogNames.push(devObj);
}
});
@ -200,9 +200,9 @@ Ext.define('FHEM.controller.ChartController', {
logname = selectionArray[0];
}
Ext.each(FHEM.filelogs, function(log) {
if (log.NAME === logname) {
if (log.Internals.NAME === logname) {
// found the filelog entry, getting the logfile to load values
currentlogfile = log.currentlogfile;
currentlogfile = log.Internals.currentlogfile;
return false;
}
});
@ -759,9 +759,9 @@ Ext.define('FHEM.controller.ChartController', {
cmd;
if (logtype && logtype === "filelog") {
Ext.each(FHEM.filelogs, function(log) {
if (log.NAME === device) {
if (log.Internals.NAME === device) {
// found the filelog entry, getting the logfile to load values
currentlogfile = log.currentlogfile;
currentlogfile = log.Internals.currentlogfile;
return false;
}
});
@ -2292,11 +2292,9 @@ 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 me = this,
unsorted = Ext.ComponentQuery.query('treepanel button[name=unsortedtree]')[0].pressed;
var me = this;
//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;
@ -2366,7 +2364,6 @@ Ext.define('FHEM.controller.ChartController', {
}
});
}
}
Ext.ComponentQuery.query('treepanel')[0].setLoading(false);
}
});

View File

@ -66,12 +66,6 @@ Ext.define('FHEM.controller.MainController', {
'button[name=restartfhem]': {
click: this.restartFhem
},
'button[name=unsortedtree]': {
click: this.setupTree
},
'button[name=sortedtree]': {
click: this.setupTree
},
'panel[name=statuspanel]': {
saveconfig: this.saveObjectToUserConfig
}
@ -88,9 +82,6 @@ Ext.define('FHEM.controller.MainController', {
me.createFHEMPanel();
me.createDevicePanel();
me.createLineChartPanel();
me.createDatabaseTablePanel();
me.showFHEMStatusPanel();
me.getMainviewport().show();
me.getMainviewport().getEl().setOpacity(0);
@ -101,18 +92,16 @@ Ext.define('FHEM.controller.MainController', {
remove: false
});
if (Ext.isDefined(FHEM.version)) {
var sp = this.getStatustextfield();
sp.setText(FHEM.version + "; Frontend Version: 1.0.8 - 2014-01-12");
}
sp.setText("Frontend Version: 1.1.0 - 2014-11-08");
this.setupTree(false);
this.setupTree();
},
/**
* setup west accordion / treepanel
*/
setupTree: function(unsorted) {
setupTree: function() {
var me = this,
rootNode = { text:"root", expanded: true, children: []},
oldRootNode = me.getMaintreepanel().getRootNode();
@ -121,71 +110,43 @@ Ext.define('FHEM.controller.MainController', {
if (oldRootNode) {
oldRootNode.removeAll();
}
if (unsorted && unsorted.name === 'unsortedtree') {
//setup the tree "unsorted"
Ext.each(FHEM.info.Results, function(result) {
if (result.list && !Ext.isEmpty(result.list)) {
if (result.devices && result.devices.length > 0) {
var blacklist = ['dummy', 'notify', 'Global', 'telnet', 'DbLog', 'FileLog', 'FHEMWEB', 'weblink'];
if (Ext.Array.contains(blacklist, result.list)) {
node = {text: result.list, expanded: false, children: []};
} else {
node = {text: result.list, expanded: true, children: []};
}
Ext.each(result.devices, function(device) {
var subnode = {text: device.NAME, leaf: true, data: device};
node.children.push(subnode);
}, this);
} else {
node = {text: result.list, leaf: true};
}
rootNode.children.push(node);
}
});
this.getMaintreepanel().setRootNode(rootNode);
this.addChartsToTree();
} else {
//sort / create items by room
me.getMaintreepanel().setRootNode(rootNode);
var root = me.getMaintreepanel().getRootNode();
var rooms = [];
Ext.each(FHEM.info.Results, function(result) {
if (result.list && !Ext.isEmpty(result.list)) {
if (result.devices && result.devices.length > 0) {
Ext.each(result.devices, function(device) {
if (device.ATTR && device.ATTR.room) {
//first we check if we have comma separated multiple rooms
var roomArray = device.ATTR.room.split(",");
// get all rooms
if (result.Attributes && result.Attributes.room) {
var roomArray = result.Attributes.room.split(",");
Ext.each(roomArray, function(room) {
//check if room exists
var resultnode = root.findChild("text", room, true),
subnode = {text: device.NAME, leaf: true, data: device};
if (!resultnode) {
//create roomfolder
if (!Ext.Array.contains(rooms, room)) {
var roomfolder;
if (room !== "hidden") {
if (room === "Unsorted") {
roomfolder = {text: room, leaf: false, expanded: false, children: []};
} else {
rootNode.children.push(roomfolder);
} else if (room !== "hidden") {
roomfolder = {text: room, leaf: false, expanded: true, children: []};
rootNode.children.push(roomfolder);
}
roomfolder.children.push(subnode);
root.appendChild(roomfolder);
}
} else {
resultnode.appendChild(subnode);
root.appendChild(resultnode);
rooms.push(room);
}
});
}
}, this);
} else {
node = {text: result.list, leaf: true};
root.appendChild(node);
}
});
Ext.each(FHEM.info.Results, function(result) {
if (result.Attributes && result.Attributes.room && result.Attributes.room !== "hidden") {
//get room
Ext.each(rootNode.children, function(room) {
if (room.text === result.Attributes.room) {
var subnode = {text: result.Internals.NAME, leaf: true, data: result};
room.children.push(subnode);
return false;
}
});
}
});
me.getMaintreepanel().setRootNode(rootNode);
this.addChartsToTree();
}
},
/**
@ -212,10 +173,9 @@ Ext.define('FHEM.controller.MainController', {
}
store.each(function(rec) {
var chartchild,
unsortedMode = Ext.ComponentQuery.query('button[name=unsortedtree]')[0].pressed;
var chartchild;
if (!unsortedMode && rec.raw && rec.raw.VALUE && rec.raw.VALUE.parentFolder) {
if (rec.raw && rec.raw.VALUE && rec.raw.VALUE.parentFolder) {
var ownerFolder = rec.raw.VALUE.parentFolder,
index = rec.raw.VALUE.treeIndex,
parentNode = rootNode.findChild("text", ownerFolder, true);
@ -432,10 +392,10 @@ Ext.define('FHEM.controller.MainController', {
Ext.Ajax.request({
method: 'GET',
disableCaching: false,
url: '../../../fhem?cmd=jsonlist&XHR=1',
url: '../../../fhem?cmd=jsonlist2&XHR=1',
success: function(response){
if (response.responseText !== "Unknown command JsonList, try help↵") {
if (response.responseText !== "Unknown command JsonList2, try help↵") {
//restarting the frontend
window.location.reload();
} else {
@ -528,12 +488,12 @@ Ext.define('FHEM.controller.MainController', {
if (record.raw.leaf === true) {
var panel = Ext.ComponentQuery.query('devicepanel')[0];
var title;
if (record.raw.ATTR &&
record.raw.ATTR.alias &&
!Ext.isEmpty(record.raw.ATTR.alias)) {
title = record.raw.data.ATTR.alias;
if (record.raw.data.Attributes &&
record.raw.data.Attributes.alias &&
!Ext.isEmpty(record.raw.data.Attributes.alias)) {
title = record.raw.data.Attributes.alias;
} else {
title = record.raw.data.NAME;
title = record.raw.data.Internals.NAME;
}
panel.setTitle(title);
panel.record = record;
@ -564,6 +524,10 @@ Ext.define('FHEM.controller.MainController', {
*/
showLineChartPanel: function() {
var panel = Ext.ComponentQuery.query('linechartpanel')[0];
if (!panel) {
this.createLineChartPanel();
panel = Ext.ComponentQuery.query('linechartpanel')[0];
}
this.hideCenterPanels();
panel.show();
},
@ -602,6 +566,10 @@ Ext.define('FHEM.controller.MainController', {
*/
showDatabaseTablePanel: function() {
var panel = Ext.ComponentQuery.query('tabledatagridpanel')[0];
if (!panel) {
this.createDatabaseTablePanel();
panel = Ext.ComponentQuery.query('tabledatagridpanel')[0];
}
this.hideCenterPanels();
panel.show();
},

View File

@ -36,7 +36,7 @@ Ext.define('FHEM.controller.TableDataController', {
checkedradio = Ext.ComponentQuery.query('radiogroup[name=tddynamictime]')[0],
starttimepicker = Ext.ComponentQuery.query('datefield[name=tdstarttimepicker]')[0],
endtimepicker = Ext.ComponentQuery.query('datefield[name=tdendtimepicker]')[0],
gridpanel = Ext.ComponentQuery.query('gridpanel[name=tabledatagridpanel]')[0];
gridpanel = Ext.ComponentQuery.query('gridpanel[name=tdgridpanel]')[0];
//check if timerange or dynamic time should be used
checkedradio.eachBox(function(box, idx){

View File

@ -132,7 +132,7 @@ Ext.define('FHEM.view.DevicePanel', {
// Starting a task to update the device readings
var task = {
run: function(){
me.getDeviceData(me.record.raw.data.NAME);
me.getDeviceData(me.title);
},
interval: 5000 //5 seconds
};
@ -150,7 +150,7 @@ Ext.define('FHEM.view.DevicePanel', {
*/
sendCommand: function(command, value) {
var me = this,
url = '../../../fhem?cmd=set ' + me.record.raw.data.NAME + ' '+ command;
url = '../../../fhem?cmd=set ' + me.record.raw.data.Internals.NAME + ' '+ command;
if (value && !Ext.isEmpty(value)) {
url += ' ' + value;
@ -189,7 +189,7 @@ Ext.define('FHEM.view.DevicePanel', {
// trigger an update nearly immediately to set new values
var task = new Ext.util.DelayedTask(function(){
me.getDeviceData(me.record.raw.data.NAME);
me.getDeviceData(me.record.raw.data.Internals.NAME);
});
task.delay(1000);
@ -209,20 +209,12 @@ Ext.define('FHEM.view.DevicePanel', {
updateControls: function(results) {
var me = this,
allSets = results.sets,
allSets = [],
controlfieldset = me.down('panel[name=container] fieldset[name=controlfieldset]');
if (controlfieldset.items.length <= 0) {
if (results.ATTR.webCmd) {
Ext.each(results.sets, function(set) {
var split = set.split(":");
if (split[0] === results.ATTR.webCmd) {
// overriding all sets as we only need the user defined webcmd now
allSets = set;
}
});
}
allSets = results.PossibleSets.split(" ");
Ext.each(allSets, function(set) {
//check for button / slider
@ -256,13 +248,11 @@ Ext.define('FHEM.view.DevicePanel', {
});
var current;
Ext.each(results.READINGS, function(reading) {
Ext.iterate(reading, function(k,v) {
Ext.iterate(results.Readings, function(k,v) {
if (k === text) {
current = v;
current = v.Value;
}
});
});
var combo = Ext.create('Ext.form.ComboBox', {
store: comboStore,
@ -285,13 +275,11 @@ Ext.define('FHEM.view.DevicePanel', {
Ext.each(splitvals, function(val) {
var pressed = false;
Ext.each(results.READINGS, function(reading) {
Ext.iterate(reading, function(k,v) {
if (k === text && v === val || k === text && val === "0" && v === "null") {
Ext.iterate(results.Readings, function(k,v) {
if (k === text && v.Value === val || k === text && val === "0" && v.Value === "null") {
pressed = true;
}
});
});
var control = Ext.create('Ext.button.Button', {
text: val,
@ -323,13 +311,11 @@ Ext.define('FHEM.view.DevicePanel', {
var xtype = item.getXType(),
current;
Ext.each(results.READINGS, function(reading) {
Ext.iterate(reading, function(k,v) {
Ext.iterate(results.Readings, function(k,v) {
if (k === subfieldset.title) {
current = v;
current = v.Value;
}
});
});
if (xtype === "combobox") {
item.setValue(current);
@ -358,18 +344,13 @@ Ext.define('FHEM.view.DevicePanel', {
var me = this,
devicedata = [],
readingsdata = [],
devicegrid = me.down('panel[name=container] grid[name=devicedata]'),
devicestore = devicegrid.getStore(),
readingsgrid = me.down('panel[name=container] grid[name=readingsgrid]'),
readingsstore = readingsgrid.getStore();
Ext.iterate(readings, function(key, value) {
if (key !== 'ATTR' && key !== 'attrs' &&
key !== 'ATTRIBUTES' && key !== 'sets' &&
key !== 'READINGS' && key !== 'CHANGETIME') {
if (typeof value === "object") {
Ext.iterate(value, function(k, v) {
Ext.iterate(readings.Internals, function(k, v) {
var obj = {
key: k,
value: v
@ -377,31 +358,16 @@ Ext.define('FHEM.view.DevicePanel', {
devicedata.push(obj);
});
} else {
var obj = {
key: key,
value: value
};
devicedata.push(obj);
}
}
});
devicestore.loadData(devicedata);
var readingcollection = readings.READINGS,
readingsdata = [];
Ext.each(readingcollection, function(readings) {
Ext.each(readings, function(reading) {
Ext.iterate(reading, function(key, value) {
Ext.iterate(readings.Readings, function(key, value) {
var obj;
if (typeof value === "object") {
obj = {
key: key,
value: value.VAL,
measured: value.TIME
value: value.Value,
measured: value.Time
};
readingsdata.push(obj);
@ -418,8 +384,6 @@ Ext.define('FHEM.view.DevicePanel', {
}
});
});
});
readingsstore.loadData(readingsdata);
},
@ -432,7 +396,7 @@ Ext.define('FHEM.view.DevicePanel', {
Ext.Ajax.request({
method: 'GET',
disableCaching: false,
url: '../../../fhem?cmd=jsonlist&XHR=1',
url: '../../../fhem?cmd=jsonlist2&XHR=1',
scope: me,
success: function(response){
me.setLoading(false);
@ -441,12 +405,11 @@ Ext.define('FHEM.view.DevicePanel', {
var devicejson;
Ext.each(json.Results, function(result) {
Ext.each(result.devices, function(device) {
if (device.NAME === name) {
devicejson = device;
if (result.Internals.NAME === name) {
devicejson = result;
return false;
}
});
});
if (devicejson && devicejson !== "") {
me.updateControls(devicejson);
me.processReadings(devicejson);

View File

@ -10,6 +10,10 @@ Ext.define('FHEM.view.TableDataGridPanel', {
title: 'Table Data',
layout: 'fit',
height: '100%',
/**
*
*/
@ -17,7 +21,9 @@ Ext.define('FHEM.view.TableDataGridPanel', {
var me = this;
me.callParent(arguments);
if (!FHEM.dblogname) {
Ext.Msg.alert("Error", "This function is currently only available to users of DbLog!");
}
me.tablestore = Ext.create('FHEM.store.TableDataStore');
@ -36,15 +42,9 @@ Ext.define('FHEM.view.TableDataGridPanel', {
autoLoad: false
});
me.on("afterlayout", function() {
if (!FHEM.dblogname) {
Ext.Msg.alert("Error", "This function is currently only available to users of DbLog!");
}
me.devicestore.load();
me.add(
me.items = [
{
xtype: 'fieldset',
title: 'Configure Database Query',
@ -180,22 +180,12 @@ Ext.define('FHEM.view.TableDataGridPanel', {
},
{
xtype: 'gridpanel',
maxHeight: me.up().getHeight() - 290,
name: 'tabledatagridpanel',
name: 'tdgridpanel',
title: 'Data',
collapsible: true,
titleCoolapse: true,
store: me.tablestore,
width: '100%',
loadMask: true,
selModel: {
pruneRemoved: false
},
multiSelect: true,
viewConfig: {
trackOver: false
},
verticalScroller:{
//trailingBufferZone: 20, // Keep 200 records buffered in memory behind scroll
//leadingBufferZone: 50 // Keep 5000 records buffered in memory ahead of scroll
},
columns: [
{ text: 'TIMESTAMP', dataIndex: 'TIMESTAMP', width: 240, sortable: false },
{ text: 'DEVICE', dataIndex: 'DEVICE', width: '10%', sortable: false },
@ -206,9 +196,8 @@ Ext.define('FHEM.view.TableDataGridPanel', {
{ text: 'UNIT', dataIndex: 'UNIT', width: '5%', sortable: false }
]
}
);
}, me, {single: true});
];
me.callParent(arguments);
}
});

View File

@ -138,23 +138,6 @@ Ext.define('FHEM.view.Viewport', {
"true",
"children": []
},
tbar: [
{
xtype: 'button',
name: 'unsortedtree',
toggleGroup: 'treeorder',
allowDepress: false,
text: 'Unsorted'
},
{
xtype: 'button',
name: 'sortedtree',
toggleGroup: 'treeorder',
allowDepress: false,
text: 'Order by Room',
pressed: true
}
],
listeners: {
'itemcontextmenu': function(scope, rec, item, index, e, eOpts) {
e.preventDefault();
@ -208,29 +191,6 @@ Ext.define('FHEM.view.Viewport', {
{
xtype: 'statuspanel'
}
// {
// region: 'center',
// title: 'Welcome',
// layout: 'hbox',
// bodyStyle: 'padding:5px 5px 0',
// items: [
// {
// xtype: 'image',
// src: '../../fhem/images/default/fhemicon.png',
// height: 132,
// width: 120
// },
// {
// xtype: 'text',
// name: 'statustextfield',
// padding: '50 0 0 20',
// width: 400,
// height: 130,
// html: '<br>Welcome to the new FHEM Frontend.<br>For Informations, Problems and discussion, visit the <a href="http://forum.fhem.de/index.php?t=msg&th=10439&start=0&rid=0">FHEM Forums</a>'
// }
// ],
// height: '100%'
// }
]
});