Skip to content

Commit

Permalink
feat: [save] support start & stop
Browse files Browse the repository at this point in the history
  • Loading branch information
LynnL4 committed Oct 17, 2024
1 parent 6936037 commit 491a3da
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 53 deletions.
56 changes: 7 additions & 49 deletions nodes/save.html
Original file line number Diff line number Diff line change
@@ -1,52 +1,3 @@
<style>
#node-input-conditions-table {
width: 100%;
}

#node-input-conditions-table td {
padding: 4px;
text-align: left;
}

/*
#node-input-conditions-table th:nth-child(1),
#node-input-conditions-table td:nth-child(1) {
width: 20%;
}
#node-input-conditions-table th:nth-child(2),
#node-input-conditions-table td:nth-child(2) {
width: 20%;
}
#node-input-conditions-table th:nth-child(3),
#node-input-conditions-table td:nth-child(3) {
width: 20%;
}
#node-input-conditions-table th:nth-child(4),
#node-input-conditions-table td:nth-child(4) {
width: 20%;
}
#node-input-conditions-table th:nth-child(5),
#node-input-conditions-table td:nth-child(5) {
width: 15%;
}
#node-input-conditions-table th:nth-child(6),
#node-input-conditions-table td:nth-child(6) {
width: 5%;
} */

#node-input-conditions-table select {
width: 80px;
}

#node-input-conditions-table input {
width: 60px;
}
</style>
<script type="text/html" data-template-name="save">
<!-- Existing configurations -->
<div class="form-row">
Expand All @@ -64,12 +15,18 @@
<option value="external">External</option>
</select>
</div>
<div class="form-row">
<label for="node-input-start"><i class="fa fa-toggle-on"></i> Start</label>
<input type="checkbox" id="node-input-start">
</div>
<div class="form-row">
<label for="node-input-slice"><i class="fa fa-clock-o"></i> Slice</label>
<select id="node-input-slice">
<option value="120">2</option>
<option value="300" selected>5</option>
<option value="600">10</option>
<option value="1800">30</option>
<option value="3600">60</option>
</select>
<span> Minutes</span>
</div>
Expand All @@ -90,6 +47,7 @@
slice: { value: "300" },
storage: { value: "local" },
duration: { value: 0 }, // Default duration (0 means indefinite)
start: { value: true },
client: { type: "sscma", required: true, label: RED._("sscma") },
},
inputs: 1,
Expand Down
22 changes: 18 additions & 4 deletions nodes/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,29 @@ module.exports = function (RED) {
node.client = RED.nodes.getNode(config.client);
node.config = {
storage: config.storage,
slice: +config.slice
slice: +config.slice,
duration: +config.duration * 60,
enabled: config.start
}

node.receive = function (msg) {
node.send(msg);
if (msg.hasOwnProperty('enabled')) {
if (msg.enabled) {
node.client.request(node.id, "enable", "");
} else {
node.client.request(node.id, "disable", "");
}
}
if (msg.type === "sscma") {
if (msg.payload.name === "start") {
node.status({ fill: "blue", shape: "dot", text: "running" });
}
if (msg.payload.name === "stop") {
node.status({ fill: "gray", shape: "dot", text: "idle" });
}
}
}



if (node.client) {
node.client.register(node);
}
Expand Down

0 comments on commit 491a3da

Please sign in to comment.