node-red-contrib-prib-functions
Version:
Node-RED added node functions.
178 lines (168 loc) • 7.23 kB
HTML
<script type="text/javascript">
const pribDataTypes={
genid:{value:"genid",label:"Generated ID",icon:"fa fa-key",hasValue:false},
genData:{value:"genData",label:"Generate Data",icon:"fa fa-pencil-square",hasValue:true,
validate: function(v){return true;},
expand: function() {
const node=this;
RED.editor.editText({
mode: "handlebars",
width: "Infinity",
focus: true,
value: this.value(),
complete: function(v) {
node.value(v);
}
})
}
},
genDataJSON:{value:"genDataJSON",label:"Generate JSON",icon:"fa fa-pencil-square-o",hasValue:true,
validate: function(v){return true;},
expand: function() {
const node=this;
RED.editor.editText({
mode: "handlebars",
width: "Infinity",
focus: true,
value: this.value(),
complete: function(v) {
node.value(v);
}
})
}
}
};
/*globals RED */
RED.nodes.registerType('Load Injector', {
category: 'testing',
color: '#fdeea2',
defaults: {
name: {value: "",required:false},
thinktimemin: {value:1000, required:true}, // 1seconds
thinktimemax: {value:10000, required:true}, // 10 seconds
runtime: {value:60, required:true}, // 60 seconds
payload: {value:"", validate: RED.validators.typedInput("payloadType")},
payloadType: {value:"date"},
topic: {value:"", validate: RED.validators.typedInput("topicType")},
topicType: {value:"date"}
},
inputs:1,
inputLabels: "",
outputs:2,
outputLabels: ["Messages","Finished"],
icon: "inject.png",
label: function() {
return this.name||this._("Load Injector");
},
labelStyle: function() {
return "node_label_italic";
},
oneditprepare: function() {
this.editors={};
$("#node-input-payloadType").val(this.payloadType||"str");
$("#node-input-payload").typedInput({
default: 'str',
typeField: $("#node-input-payloadType"),
types:['date',
pribDataTypes.genid,
'str','num','bool','json','jsonata',
pribDataTypes.genData,
pribDataTypes.genDataJSON,
'bin','flow','global','env']
});
$("#node-input-topicType").val(this.topicType||"str");
$("#node-input-topic").typedInput({
default: 'str',
typeField: $("#node-input-topicType"),
types:['date',
pribDataTypes.genid,
'str','num','bool','json','jsonata',
pribDataTypes.genData,
pribDataTypes.genDataJSON,
'bin','flow','global','env']
});
},
oneditsave: function() {
const node=this;
Object.keys(node.editors).forEach(property=>{
const editor=node.editors[property];
node[property]=editor.getValue();
editor.destroy();
delete editor;
})
},
oneditcancel: function() {
const node=this;
Object.keys(node.editors).forEach(property=>{
const editor=node.editors[property];
editor.destroy();
delete editor;
});
},
oneditresize: function() {
},
button: {
enabled: function() {
return !this.changed;
},
onclick: function() {
if (this.changed) {
return RED.notify(RED._("load injector undeployed changes"),"warning");
}
var label = this._def.label.call(this);
if (label.length > 30) {
label = label.substring(0,50)+"...";
}
label = label.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">");
var node = this;
$.get( "/loadinjector/"+this.id )
.done(function( json ) {
RED.notify(node._("load injector signal success",{label:label}),{type:"success",id:"Load Injector"});
}).fail(function( jqXHR, textStatus, error ) {
if (jqXHR.status === 404) {
RED.notify(node._("load injector signal not deployed"),"error");
} else if (jqXHR.status === 500) {
RED.notify(node._("load injector signal inject failed with error "+textStatus||""),"error");
} else if (jqXHR.status === 0) {
RED.notify(node._("load injector signal no response"),"error");
} else {
RED.notify(node._("load injector signal unexpected status:"+jqXHR.status+" message:"+textStatus+" "+error),"error");
}
});
}
}
});
</script>
<script type="text/x-red" data-template-name="Load Injector">
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
<div class="form-row">
<label for="node-input-thinktimemin"><i class="fa fa-tag"></i>Minimum Think Time (millisecs)</label>
<input type="number" id="node-input-thinktimemin" placeholder="Name" min=1 max=1000000 step=100>
</div>
<div class="form-row">
<label for="node-input-thinktimemax"><i class="fa fa-tag"></i>Maximum Think Time (millisecs)</label>
<input type="number" id="node-input-thinktimemax" placeholder="Name" min=1 max=1000000 step=100>
</div>
<div class="form-row">
<label for="node-input-runtime"><i class="fa fa-tag"></i>Runtime (secs)</label>
<input type="number" id="node-input-runtime" placeholder="Name" min=1 max=1000000 step=10>
</div>
<div class="form-row">
<label for="node-input-payload"><i class="fa fa-envelope"></i> Payload</label>
<input type="text" id="node-input-payload">
<input type="hidden" id="node-input-payloadType">
</div>
<div class="form-row">
<label for="node-input-topic"><i class="fa fa-tasks"></i> Topic</span></label>
<input type="text" id="node-input-topic">
<input type="hidden" id="node-input-topicType">
</div>
</script>
<script type="text/x-red" data-help-name="Load Injector">
<p>Injects messages for a period of time based on varied time time.
Simulate random arrival of messages and can be set to reflect think time of a user by setting min and maximum boundaries.
</p>
</script>