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
|
||||
if data['type'] == "variable":
|
||||
condition.method = condition._hasVariable
|
||||
|
||||
if data['type'] == "diversion":
|
||||
condition.method = condition._hasDiverged
|
||||
|
||||
if 'vars' in data:
|
||||
condition.vars = data['vars']
|
||||
|
||||
|
@ -316,6 +318,24 @@ class Condition(object):
|
|||
r = not 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:
|
||||
"""
|
||||
|
|
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) {
|
||||
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': { 'value': '','placeholder': "Variable name (without $)" },
|
||||
'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];
|
||||
for ( let v in vars ) {
|
||||
let attr = vars[v];
|
||||
let inputType = attr.hasOwnProperty('tag') ? attr['tag'] : 'input';
|
||||
|
||||
attr['name'] = typeof conditionId == 'undefined' ? v : `${conditionId}-vars.${v}`;
|
||||
if(typeof values != 'undefined') {
|
||||
let value = this._getValueForPath(v, values);
|
||||
|
@ -1138,7 +1144,7 @@ class Graph {
|
|||
crel( 'span', {
|
||||
'title': attr.hasOwnProperty('title') ? attr['title'] : ""
|
||||
}, attr.hasOwnProperty('label') ? attr['label'] : v ),
|
||||
crel( 'input', attr )
|
||||
crel( inputType, attr )
|
||||
// crel('span', {'class': 'label-unit'}, attr.hasOwnProperty('unit') ? attr['unit'] : "" )
|
||||
)
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue