Skip to content

Commit

Permalink
fix: issue #46, Cannot read property 'options' of undefined"
Browse files Browse the repository at this point in the history
  • Loading branch information
naimo84 committed Jan 8, 2023
1 parent 6797288 commit f77f6fc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
16 changes: 14 additions & 2 deletions src/docker-service-actions.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
name: { value: "" },
config: { value: "", type: "docker-configuration", required: true },
service: { value: "" },
action: { value: "inspect" }
action: { value: "inspect" },
options: { value: "" },
optionstype: { value: "" },
},
inputs: 1,
outputs: 1,
Expand Down Expand Up @@ -37,6 +39,10 @@
$('#node-input-action').change(function () {
var value = $('#node-input-action').val()
})
$("#node-input-options").typedInput({
types: ["str", "json", "msg"],
typeField: "#node-input-optionstype"
});


$("#node-input-service").click(function () {
Expand All @@ -60,7 +66,7 @@
})
</script>

<script type="text/x-red" data-template-name="docker-service-actions">
<script type="text/html" data-template-name="docker-service-actions">
<div class="form-row">
<label for="node-input-config"><i class="icon-server"></i> Config</label>
<input type="text" id="node-input-config">
Expand All @@ -76,6 +82,12 @@
<i id="node-config-lookup-uuid-icon" class="fa fa-plus-square"></i>
</a>
</div>
<div class="form-row" id="options">
<label for="node-input-options"><i class="icon-tag"></i> Options</label>
<input type="text" id="node-input-options">
<input type="hidden" id="node-input-optionstype">

</div>
<div class="form-row">
<label for="node-input-action"><i class="fa fa-wrench"></i> Action</label>
<select type="text" id="node-input-action" style="display: inline-block; vertical-align: top;">
Expand Down
9 changes: 4 additions & 5 deletions src/docker-service-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,16 @@ module.exports = function (RED: Red) {
let client = config.getClient();
this.on('input', (msg) => {

let serviceId: string = n.service || msg.payload.serviceId || msg.serviceId || undefined;
let serviceId: string = n.service || msg.payload?.serviceId || msg.serviceId || undefined;
if(serviceId === undefined){
serviceId = n.serviceName || msg.payload.serviceName || msg.serviceName || undefined;
serviceId = n.serviceName || msg.payload?.serviceName || msg.serviceName || undefined;
}
let action = n.action || msg.action || msg.payload.action || undefined;
let action = n.action || msg.action || msg.payload?.action || undefined;
if (serviceId === undefined && !['list', 'prune', 'create'].includes(action)) {
this.error("Service id/name must be provided via configuration or via `msg.service`");
return;
}

let options = n.options || msg.options || msg.payload.options || undefined;
let options = RED.util.evaluateNodeProperty(n.options, n.optionstype, n, msg) || msg.options || msg.options || msg.payload?.options || undefined;

this.status({});
executeAction(serviceId, options, client, action, this,msg);
Expand Down

0 comments on commit f77f6fc

Please sign in to comment.