Skip to content

Commit

Permalink
* (pascal-hari) The group attributes will be replaced recursively
Browse files Browse the repository at this point in the history
  • Loading branch information
GermanBluefox committed Mar 22, 2022
1 parent 40e379d commit 5052e96
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 45 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,12 @@ Notice that these settings are valid only for reconnection and not for the first

<!--
Placeholder for the next version (at the beginning of the line):
### __WORK IN PROGRESS__
### **WORK IN PROGRESS**
-->
## Changelog
### **WORK IN PROGRESS**
* (pascal-hari) The group attributes will be replaced recursively

### 1.4.12 (2022-02-12)
* (bluefox) Fixed bug with the export of specific widgets

Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@
"dependencies": {
"jsonwebtoken": "^8.5.1",
"@iobroker/adapter-core": "^2.6.0",
"axios": "^0.26.0"
"axios": "^0.26.1"
},
"devDependencies": {
"@alcalzone/release-script": "^3.5.2",
"@alcalzone/release-script-plugin-iobroker": "^3.5.1",
"@alcalzone/release-script-plugin-license": "^3.5.0",
"@alcalzone/release-script": "^3.5.6",
"@alcalzone/release-script-plugin-iobroker": "^3.5.7",
"@alcalzone/release-script-plugin-license": "^3.5.3",
"gulp": "^4.0.2",
"gulp-replace": "^1.1.3",
"iobroker.web": "*",
"mocha": "^9.2.1",
"mocha": "^9.2.2",
"chai": "^4.3.6"
},
"bugs": {
Expand Down
22 changes: 4 additions & 18 deletions www/js/vis.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,6 @@
/* jshint -W097 */// jshint strict:false
'use strict';

function replaceGroupAttr(inputStr, groupAttrList) {
let newString = inputStr
let match = false
let ms = inputStr.match(/(groupAttr\d+)+?/g)
if (ms) {
match = true
ms.forEach(function (m){
newString = newString.replace(/groupAttr(\d+)/, groupAttrList[m]);
});
console.log("Replaced " + inputStr + " with " + newString + " (based on " + ms + ")")
}
return [match, newString]
}

if (typeof systemDictionary !== 'undefined') {
$.extend(systemDictionary, {
'No connection to Server': {'en': 'No connection to Server', 'de': 'Keine Verbindung zum Server', 'ru': 'Нет соединения с сервером',
Expand Down Expand Up @@ -1631,11 +1617,11 @@ var vis = {
widget = JSON.parse(JSON.stringify(widget));
var aCount = parseInt(this.views[view].widgets[groupId].data.attrCount, 10);
if (aCount) {
$.map(widget.data, function(val, key) {
$.map(widget.data, function (val, key) {
if (typeof val === 'string') {
const [doesMatch, newString] = replaceGroupAttr(val, that.views[view].widgets[groupId].data)
if(doesMatch) {
widget.data[key] = newString || '';
var result = replaceGroupAttr(val, that.views[view].widgets[groupId].data);
if (result.doesMatch) {
widget.data[key] = result.newString || '';
}
}
});
Expand Down
60 changes: 39 additions & 21 deletions www/js/visUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@
*/

function replaceGroupAttr(inputStr, groupAttrList) {
let newString = inputStr
let match = false
let ms = inputStr.match(/(groupAttr\d+)+?/g)
var newString = inputStr;
var match = false;
var ms = inputStr.match(/(groupAttr\d+)+?/g);
if (ms) {
match = true
ms.forEach(function (m){
match = true;
ms.forEach(function (m) {
newString = newString.replace(/groupAttr(\d+)/, groupAttrList[m]);
});
console.log("Replaced " + inputStr + " with " + newString + " (based on " + ms + ")")
console.log('Replaced ' + inputStr + ' with ' + newString + ' (based on ' + ms + ')');
}
return [match, newString]
return {doesMatch: match, newString: newString};
}

function getWidgetGroup(views, view, widget) {
Expand Down Expand Up @@ -432,17 +432,23 @@ function getUsedObjectIDs(views, isByViews) {
} else
if (attr !== 'oidTrueValue' && attr !== 'oidFalseValue' && ((attr.match(/oid\d{0,2}$/) || attr.match(/^oid/) || attr.match(/^signals-oid-/) || attr === 'lc-oid') && data[attr])) {
if (data[attr] && data[attr] !== 'nothing_selected') {
if (IDs.indexOf(data[attr]) === -1) IDs.push(data[attr]);
if (_views && _views[view].indexOf(data[attr]) === -1) _views[view].push(data[attr]);
if (IDs.indexOf(data[attr]) === -1) {
IDs.push(data[attr]);
}
if (_views && _views[view].indexOf(data[attr]) === -1) {
_views[view].push(data[attr]);
}
}

// Visibility binding
if (attr === 'visibility-oid' && data['visibility-oid']) {
var vid = data['visibility-oid'];
var vgroup = getWidgetGroup(views, view, id);
if (vgroup) {
const [doesMatch, newString] = replaceGroupAttr(vid, views[view].widgets[vgroup].data)
if (doesMatch) vid = newString;
var result1 = replaceGroupAttr(vid, views[view].widgets[vgroup].data);
if (result1.doesMatch) {
vid = result1.newString;
}
}

if (!visibility[vid]) visibility[vid] = [];
Expand All @@ -453,12 +459,16 @@ function getUsedObjectIDs(views, isByViews) {
if (attr.match(/^signals-oid-/) && data[attr]) {
var sid = data[attr];
var group = getWidgetGroup(views, view, id);
if(group) {
const [doesMatch, newString] = replaceGroupAttr(sid, views[view].widgets[group].data)
if (doesMatch) sid = newString;
if (group) {
var result2 = replaceGroupAttr(sid, views[view].widgets[group].data);
if (result2.doesMatch) {
sid = result2.newString;
}
}

if (!signals[sid]) signals[sid] = [];
if (!signals[sid]) {
signals[sid] = [];
}
signals[sid].push({
view: view,
widget: id,
Expand All @@ -468,12 +478,16 @@ function getUsedObjectIDs(views, isByViews) {
if (attr === 'lc-oid') {
var lcsid = data[attr];
var ggroup = getWidgetGroup(views, view, id);
if(ggroup) {
const [doesMatch, newString] = replaceGroupAttr(lcsid, views[view].widgets[ggroup].data)
if (doesMatch) lcsid = newString;
if (ggroup) {
var result3 = replaceGroupAttr(lcsid, views[view].widgets[ggroup].data);
if (result3.doesMatch) {
lcsid = result3.newString;
}
}

if (!lastChanges[lcsid]) lastChanges[lcsid] = [];
if (!lastChanges[lcsid]) {
lastChanges[lcsid] = [];
}
lastChanges[lcsid].push({
view: view,
widget: id
Expand All @@ -483,8 +497,12 @@ function getUsedObjectIDs(views, isByViews) {
if ((m = attr.match(/^attrType(\d+)$/)) && data[attr] === 'id') {
var _id = 'groupAttr' + m[1];
if (data[_id]) {
if (IDs.indexOf(data[_id]) === -1) IDs.push(data[_id]);
if (_views && _views[view].indexOf(data[_id]) === -1) _views[view].push(data[_id]);
if (IDs.indexOf(data[_id]) === -1) {
IDs.push(data[_id]);
}
if (_views && _views[view].indexOf(data[_id]) === -1) {
_views[view].push(data[_id]);
}
}
}
}
Expand Down

0 comments on commit 5052e96

Please sign in to comment.