Skip to content

Commit

Permalink
* (agav99) Checked the initialization of the local_ variables
Browse files Browse the repository at this point in the history
  • Loading branch information
GermanBluefox committed Nov 6, 2023
1 parent 683c371 commit 035f080
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 51 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ Notice that these settings are valid only for reconnection and not for the first
## Changelog
### **WORK IN PROGRESS**
* (agav99) added the new binding operation for getting property of JSON or object
* (agav99) Checked the initialization of the `local_` variables

### 1.5.1 (2023-11-06)
* (bluefox) Changed License: it is now MIT, and the license check was removed
Expand Down
91 changes: 40 additions & 51 deletions www/js/vis.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,58 +324,47 @@ var vis = {
},
_setValue: function (id, state, isJustCreated) {
var that = this;
var oldValue = this.states.attr(id + '.val');

// Inform other widgets, that does not support canJS
function sub_UpdateWidgetsNotCanJS(){
for (var i = 0, len = that.onChangeCallbacks.length; i < len; i++) {
try {
that.onChangeCallbacks[i].callback(that.onChangeCallbacks[i].arg, id, state);
} catch (e) {
that.conn.logError('Error: can\'t update states object for ' + id + '(' + e + '): ' + JSON.stringify(e.stack));
}
}
}
var oldValue = this.states.attr(`${id}.val`);

// If ID starts from 'local_', do not send changes to the server, we assume that it is a local variable of the client
if (id.indexOf('local_') === 0) {
if (id.startsWith('local_')) {
that.states.attr(state);

// Inform other widgets, that does not support canJS
sub_UpdateWidgetsNotCanJS();
that._informWidgetsAboutChanges(id, state);

//need update string to number
state.ts=Date.now();
state.lc=state.ts;
state.ts = Date.now();
state.lc = state.ts;

// update local variable state -> needed for binding, etc.
vis.updateState(id, state);

return;
}

this.conn.setState(id, state[id + '.val'], function (err) {
this.conn.setState(id, state[`${id}.val`], function (err) {
if (err) {
//state[id + '.val'] = oldValue;
that.showMessage(_('Cannot execute %s for %s, because of insufficient permissions', 'setState', id), _('Insufficient permissions'), 'alert', 600);
}

var val = that.states.attr(id + '.val');
var val = that.states.attr(`${id}.val`);

if (that.states.attr(id) || val !== undefined || val !== null) {
that.states.attr(state);

// If error set value back, but we need generate the edge
if (err) {
if (isJustCreated) {
that.states.removeAttr(id + '.val');
that.states.removeAttr(id + '.q');
that.states.removeAttr(id + '.from');
that.states.removeAttr(id + '.ts');
that.states.removeAttr(id + '.lc');
that.states.removeAttr(id + '.ack');
that.states.removeAttr(`${id}.val`);
that.states.removeAttr(`${id}.q`);
that.states.removeAttr(`${id}.from`);
that.states.removeAttr(`${id}.ts`);
that.states.removeAttr(`${id}.lc`);
that.states.removeAttr(`${id}.ack`);
} else {
state[id + '.val'] = oldValue;
state[`${id}.val`] = oldValue;
that.states.attr(state);
}
}
Expand Down Expand Up @@ -2960,51 +2949,51 @@ var vis = {
this.subscribing.byViews[view] = this.subscribing.byViews[view] || [];

// subscribe
var oids_get = []; //array for getting Values
var oids_subscribe = []; //array for subscribe Values (exclude "local_")

for (var i = 0; i < this.subscribing.byViews[view].length; i++) {
let oid=this.subscribing.byViews[view][i];
var oidsGet = []; // array for getting Values
var oidsSubscribe = []; // array for subscribe Values (exclude "local_")

//if (oid.indexOf('groupAttr') === 0) //now not possible here, groupAttr changed to real VarName in getUsedObjectIDs() (after #492)
for (let i = 0; i < this.subscribing.byViews[view].length; i++) {
const oid = this.subscribing.byViews[view][i];

// if (oid.indexOf('groupAttr') === 0) // now not possible here, groupAttr changed to real VarName in getUsedObjectIDs() (after #492)
// continue;

if (oid.indexOf('local_') === 0){
if (((this.states[oid+'.val'] == 'null') || (this.states[oid+'.val'] == null)) //Value can be already set in view user script
&& !oids_get.includes(oid))
oids_get.push(oid); //add only to "oids_get" array. will try to find it in URL params
if (oid.startsWith('local_')) {
if ((this.states[`${oid}.val`] === 'null' || (this.states[`${oid}.val`] === null)) // Value can be already set in view user script
&& !oidsGet.includes(oid)
) {
oidsGet.push(oid); // add only to "oids_get" array. will try to find it in URL params
}

continue;
}

let pos = this.subscribing.active.indexOf(oid);
if (pos === -1) {
if (!this.subscribing.active.includes(oid)) {
this.subscribing.active.push(oid);
oids_subscribe.push(oid);
oids_get.push(oid);

oidsSubscribe.push(oid);
oidsGet.push(oid);
}
}

if (oids_get.length) {
var that = this;
console.debug('[' + Date.now() + '] Request ' + oids_get.length + ' Subscribe ' + oids_subscribe.length+' states.');

this.conn.getStates(oids_get, function (error, data) {
error && that.showError(error);
if (oidsGet.length) {
console.debug(`[${Date.now()}] Request ${oidsGet.length} Subscribe ${oidsSubscribe.length} states.`);

that.updateStates(data);
this.conn.getStates(oidsGet, (error, data) => {
error && this.showError(error);

this.updateStates(data);

if (oidsSubscribe.length) {
this.conn.subscribe(oidsSubscribe);
}

if (oids_subscribe.length)
that.conn.subscribe(oids_subscribe);

callback && callback();
});
} else {
callback && callback();
}
},
//******************************************************************************************* */
unsubscribeStates: function (view) {
if (!view || this.editMode) return;

Expand Down

0 comments on commit 035f080

Please sign in to comment.