-
Notifications
You must be signed in to change notification settings - Fork 6
/
throttle.html
102 lines (98 loc) · 4.94 KB
/
throttle.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<script type="text/x-red" data-template-name="throttle">
<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=""><i class="fa fa-filter"></i> Throttle</label>
<select id="node-input-throttleType" style="width: 70%">
<option value="time">by time</option>
<option value="count">by count</option>
<option value="block">by block size</option>
<option value="reset">by reset</option>
</select>
</div>
<div class="form-row throttle-limit-row" id="throttle-limit-row-time">
<label for="node-input-timeLimit"><i class="fa fa-clock-o"></i> Time Limit</label>
<input type="text" id="node-input-timeLimit" placeholder="0" style="padding-left: 5px; width: 70%">
<input type="hidden" id="node-input-timeLimitType">
</div>
<div class="form-row throttle-limit-row hidden" id="throttle-limit-row-count">
<label for="node-input-countLimit"><i class="fa fa-hashtag"></i> Count Limit</label>
<input type="text" id="node-input-countLimit" placeholder="0">
</div>
<div class="form-row throttle-limit-row hidden" id="throttle-limit-row-block">
<label for="node-input-blockSize"><i class="fa fa-hashtag"></i> Block Size</label>
<input type="text" id="node-input-blockSize" placeholder="0">
</div>
<div class="form-row">
<label> </label>
<input type="checkbox" id="node-input-locked" style="display: inline-block; width: auto; vertical-align: top;">
<label for="node-input-locked" style="width: 70%;">Locked by default?</label>
</div>
</script>
<script type="text/x-red" data-help-name="throttle">
<p>A simple node to throttle down passed through message amount.</p>
<p>Just insert the throttle node in between two others, and the passed through message amount can be limited by different parameters.</p>
<p><strong>By Time:</strong><br/>
Limits the passed through messages by a given amount of time.
For example: setting the node to <code>10 seconds</code> means, that only one message in ten seconds will be forwarded.</p>
<p><strong>By Count:</strong><br/>
Limits the passed through messages by a given count.
For example: setting the node to a count of <code>5</code> means, that only every fifth message will be forwarded.</p>
<p><strong>By Block Size:</strong><br/>
Limits the passed through messages by a given block size.
The counter will be reset when a message with <code>msg.reset</code> was received.
For example: setting the node to a block size of <code>5</code> means, that only the first five messages will be forwarded.</p>
<p><strong>By Reset:</strong><br/>
Will only pass through a single message, when a message with <code>msg.reset</code> was received before.</p>
<p>Every other messages will be dropped!</p>
</script>
<script type="text/javascript">
RED.nodes.registerType("throttle", {
category: "function",
defaults: {
name: {value:""},
throttleType: {value:"time"},
timeLimit: {value:0,validate:RED.validators.number()},
timeLimitType: {value:"seconds"},
countLimit: {value:0,validate:RED.validators.number()},
blockSize: {value:0,validate:RED.validators.number()},
locked: {value:false}
},
color:"#e6e0f8",
inputs: 1,
outputs: 1,
icon: "throttle.png",
label: function() {
return this.name || "throttle";
},
labelStyle: function() {
return this.name ? "node_label_italic" : "";
},
oneditprepare: function() {
// defaults
this.throttleType = !this.throttleType ? "time" : this.throttleType;
this.countLimit = !this.countLimit ? 0 : this.countLimit;
this.blockSize = !this.blockSize ? 0 : this.blockSize;
this.timeLimit = !this.timeLimit ? 0 : this.timeLimit;
this.timeLimitType = !this.timeLimitType ? "seconds" : this.timeLimitType;
// change listener for type select
$("#node-input-throttleType").change(function() {
$(".throttle-limit-row").hide();
$("#throttle-limit-row-" + $(this).val()).show();
});
// typed input for time throttle
$("#node-input-timeLimit").typedInput({
default: "seconds",
typeField: $("#node-input-timeLimitType"),
types: [
{value: "milliseconds", label: "milliseconds", hasValue: true},
{value: "seconds", label: "seconds", hasValue: true},
{value: "minutes", label: "minutes", hasValue: true},
{value: "hours", label: "hours", hasValue: true}
]
});
}
});
</script>