Diversion condition
This commit is contained in:
parent
2f598ad7f7
commit
bf12323f41
3 changed files with 44 additions and 2 deletions
|
@ -264,7 +264,9 @@ class Condition(object):
|
||||||
condition.method = condition._hasMetTimeout
|
condition.method = condition._hasMetTimeout
|
||||||
if data['type'] == "variable":
|
if data['type'] == "variable":
|
||||||
condition.method = condition._hasVariable
|
condition.method = condition._hasVariable
|
||||||
|
if data['type'] == "diversion":
|
||||||
|
condition.method = condition._hasDiverged
|
||||||
|
|
||||||
if 'vars' in data:
|
if 'vars' in data:
|
||||||
condition.vars = data['vars']
|
condition.vars = data['vars']
|
||||||
|
|
||||||
|
@ -316,6 +318,24 @@ class Condition(object):
|
||||||
r = not r
|
r = not r
|
||||||
|
|
||||||
return r
|
return r
|
||||||
|
|
||||||
|
def _hasDiverged(self, story) -> bool:
|
||||||
|
if not story.lastMsgFinishTime:
|
||||||
|
return False
|
||||||
|
|
||||||
|
d = story.get(self.vars['diversionId'])
|
||||||
|
if not d:
|
||||||
|
story.logger.critical(f"Condition on non-existing diversion: {self.vars['diversionId']}")
|
||||||
|
|
||||||
|
r = d.hasHit
|
||||||
|
if r:
|
||||||
|
story.logger.debug(f"Diversion {self.vars['diversionId']} has been hit.")
|
||||||
|
|
||||||
|
if 'inverseMatch' in self.vars and self.vars['inverseMatch']:
|
||||||
|
# inverse:
|
||||||
|
r = not r
|
||||||
|
|
||||||
|
return r
|
||||||
|
|
||||||
def _hasMetReplyContains(self, story) -> bool:
|
def _hasMetReplyContains(self, story) -> bool:
|
||||||
"""
|
"""
|
||||||
|
|
16
www/js/crel.min.js
vendored
16
www/js/crel.min.js
vendored
|
@ -4,4 +4,20 @@ crel.attrMap['on'] = function(element, value) {
|
||||||
for (var eventName in value) {
|
for (var eventName in value) {
|
||||||
element.addEventListener(eventName, value[eventName]);
|
element.addEventListener(eventName, value[eventName]);
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
crel.attrMap['options'] = function(element, values) {
|
||||||
|
if(element.tagName != "SELECT") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
console.log(values);
|
||||||
|
if(Array.isArray(values)) {
|
||||||
|
for (let option of values) {
|
||||||
|
element.appendChild(crel('option', option));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (let option in values) {
|
||||||
|
element.appendChild(crel('option', {'value': option}, values[option]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
|
@ -1109,6 +1109,10 @@ class Graph {
|
||||||
'variable': {
|
'variable': {
|
||||||
'variable': { 'value': '','placeholder': "Variable name (without $)" },
|
'variable': { 'value': '','placeholder': "Variable name (without $)" },
|
||||||
'notSet': { "label": "Not set", 'value': '', 'title': "Match if the variable is _not_ set.", 'type':'checkbox' },
|
'notSet': { "label": "Not set", 'value': '', 'title': "Match if the variable is _not_ set.", 'type':'checkbox' },
|
||||||
|
},
|
||||||
|
'diversion': {
|
||||||
|
'diversionId': { 'tag': 'select', 'value': '','placeholder': "Variable name (without $)", 'options': this.diversions.map((d) => d['@id']) },
|
||||||
|
'inverseMatch': { "label": "Match if not done", 'value': '', 'title': "Match if the diversion has _not_ been done.", 'type':'checkbox' },
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -1118,6 +1122,8 @@ class Graph {
|
||||||
let vars = this.getConditionTypes()[type];
|
let vars = this.getConditionTypes()[type];
|
||||||
for ( let v in vars ) {
|
for ( let v in vars ) {
|
||||||
let attr = vars[v];
|
let attr = vars[v];
|
||||||
|
let inputType = attr.hasOwnProperty('tag') ? attr['tag'] : 'input';
|
||||||
|
|
||||||
attr['name'] = typeof conditionId == 'undefined' ? v : `${conditionId}-vars.${v}`;
|
attr['name'] = typeof conditionId == 'undefined' ? v : `${conditionId}-vars.${v}`;
|
||||||
if(typeof values != 'undefined') {
|
if(typeof values != 'undefined') {
|
||||||
let value = this._getValueForPath(v, values);
|
let value = this._getValueForPath(v, values);
|
||||||
|
@ -1138,7 +1144,7 @@ class Graph {
|
||||||
crel( 'span', {
|
crel( 'span', {
|
||||||
'title': attr.hasOwnProperty('title') ? attr['title'] : ""
|
'title': attr.hasOwnProperty('title') ? attr['title'] : ""
|
||||||
}, attr.hasOwnProperty('label') ? attr['label'] : v ),
|
}, attr.hasOwnProperty('label') ? attr['label'] : v ),
|
||||||
crel( 'input', attr )
|
crel( inputType, attr )
|
||||||
// crel('span', {'class': 'label-unit'}, attr.hasOwnProperty('unit') ? attr['unit'] : "" )
|
// crel('span', {'class': 'label-unit'}, attr.hasOwnProperty('unit') ? attr['unit'] : "" )
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue