Skip to content

Commit

Permalink
Merge pull request #5 from hidetak/simplify-typedinput-process
Browse files Browse the repository at this point in the history
Simplify typedinput process
  • Loading branch information
hidetak authored Mar 22, 2024
2 parents ca2a511 + e9f6f0a commit 8c51b69
Show file tree
Hide file tree
Showing 21 changed files with 128 additions and 588 deletions.
2 changes: 1 addition & 1 deletion node-red-node-wot/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions node-red-node-wot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"node-red"
],
"engines": {
"node": ">=8.0.0"
"node": ">=14.0.0"
},
"repository": {
"type": "git",
Expand All @@ -34,7 +34,7 @@
"wot-server-event": "dist/wot-server-event.js",
"wot-server-td": "dist/wot-server-td.js"
},
"version": ">=2.0.0"
"version": ">=1.3.7"
},
"scripts": {
"build": "npm run copy:src2dist && tsc",
Expand Down
6 changes: 3 additions & 3 deletions node-red-node-wot/src/locales/en-US/wot-thing-config.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ <h3>Details</h3>
</li>
<li>Description: Specify the description of the Thing.</li>
<li>
Thing ID: Specify the Thing ID. The specified Thing ID is used as the ID for Thing Description.
If omitted, the ID for Thing Description is automatically generated.<br/>
Thing ID: Specify the Thing ID. The specified Thing ID is used as the ID for Thing Description. If omitted,
the ID for Thing Description is automatically generated.<br />
Example of Thing ID: "urn:dev:ops:32473-WoTLamp-1234"
</li>
<li>
Use basic authentication: Specifies whether Basic authentication is applied to the Thing.<br/>
Use basic authentication: Specifies whether Basic authentication is applied to the Thing.<br />
If you use Basic Authentication, please set your user name and password.
</li>
</ul>
Expand Down
4 changes: 2 additions & 2 deletions node-red-node-wot/src/locales/ja/wot-thing-config.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ <h3>Details</h3>
<li>説明: Thingの説明を指定します。</li>
<li>
Thing ID: Thing IDを指定します。指定したThing IDは、Thing
DescriptionのIDとして利用します。省略した場合は、Thing DescriptionのIDは自動的に生成されます。<br/>
DescriptionのIDとして利用します。省略した場合は、Thing DescriptionのIDは自動的に生成されます。<br />
Thing IDの例: "urn:dev:ops:32473-WoTLamp-1234"
</li>
<li>
Basic認証利用: ThingにBasic認証をかけるかどうかを指定します。<br/>
Basic認証利用: ThingにBasic認証をかけるかどうかを指定します。<br />
Basic認証を利用する場合は、ユーザー名とパスワードを設定してください。
</li>
</ul>
Expand Down
2 changes: 1 addition & 1 deletion node-red-node-wot/src/wot-event.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module.exports = function (RED) {
subscription = undefined
consumedThing = _consumedThing
// Repeat until event subscription succeeds.
await new Promise((resolve, reject) => {
await new Promise((resolve) => {
repeatId = setInterval(() => {
consumedThing
.subscribeEvent(
Expand Down
2 changes: 1 addition & 1 deletion node-red-node-wot/src/wot-property.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ module.exports = function (RED) {
return
}
// Repeat until observeProperty succeeds.
await new Promise((resolve, reject) => {
await new Promise((resolve) => {
repeatId = setInterval(() => {
consumedThing
.observeProperty(
Expand Down
75 changes: 10 additions & 65 deletions node-red-node-wot/src/wot-server-action.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@
color: "#a2dea0",
defaults: {
name: { value: "" },

actionName: { value: "", required: true },
actionDescription: { value: "" },
actionInputDataType: { value: "string", required: true },
actionOutputDataType: { value: "string", required: true },
outParams1_actionArgsType: {
value: "msg",
required: true,
},
outParams1_actionArgsConstValue: {
value: "payload",
required: true,
},
woTServerConfig: {
type: "wot-server-config",
Expand All @@ -27,9 +28,6 @@
required: true,
},
},
credentials: {
outParams1_actionArgs: { type: "text" },
},
inputs: 0,
outputs: 1,
outputLabels: function (index) {
Expand Down Expand Up @@ -61,66 +59,14 @@
id: "tab-outParams1-settings",
label: this._("editor.outParams1.tabLabel"),
})
prepareInOutParamSetting(
"outParams1",
{
name: "actionArgs",
types: ["msg"],
defaultType: "msg",
defaultValue: "payload",
required: true,
},
this
)
},
oneditsave: function () {
saveInOutParamSetting(
"outParams1",
{
name: "actionArgs",
types: ["msg"],
defaultType: "msg",
defaultValue: "payload",
required: true,
},
this
)
$("#node-input-outParams1_actionArgsConstValue").typedInput({
defaultType: "msg",
defaultValue: "payload",
types: ["msg"],
typeField: "#node-input-outParams1_actionArgsType",
})
},
})
const prepareInOutParamSetting = (inOrOutParams, params, _this) => {
const { name, types, defaultType, defaultValue, required } = params
const varName = `${inOrOutParams}_${name}`
if (!_this[`${varName}Type`]) {
_this[`${varName}Type`] = defaultType
}
if (this[`${varName}Type`] == "str") {
$(`#node-input-${varName}ConstValue`).val("")
} else {
if (_this[`${varName}ConstValue`] == "") {
$(`#node-input-${varName}ConstValue`).val(_this.credentials[varName])
} else {
_this.credentials[varName] = _this[`${varName}ConstValue`]
$(`#node-input-${varName}`).val(_this.credentials[`${varName}`])
}
}
$(`#node-input-${varName}Type`).val(_this[`${varName}Type`])
$(`#node-input-${varName}`).typedInput({
default: defaultType,
typeField: $(`#node-input-${varName}Type`),
types: types,
})
$(`#node-input-${varName}`).typedInput("type", _this[`${varName}Type`])
}
const saveInOutParamSetting = (inOrOutParams, params, _this) => {
const varName = `${inOrOutParams}_${params.name}`
if ($(`#node-input-${varName}Type`).val() != "str") {
_this[`${varName}ConstValue`] = $(`#node-input-${varName}`).val()
$(`#node-input-${varName}ConstValue`).val(_this[`${varName}ConstValue`])
} else {
$(`#node-input-${varName}ConstValue`).val("")
_this[`${varName}ConstValue`] = ""
}
}
})()
</script>

Expand Down Expand Up @@ -181,10 +127,9 @@
<div id="tabs-content" style="min-height:250px;">
<div id="tab-outParams1-settings">
<div class='form-row'>
<label for='node-input-outParams1_writingValue'><span data-i18n="editor.outParams1.actionArgs.label"></span></label>
<input required type='text' id='node-input-outParams1_actionArgs' data-i18n="[placeholder]editor.outParams1.actionArgs.placeholder">
<label for='node-input-outParams1_actionArgsConstValue'><span data-i18n="editor.outParams1.actionArgs.label"></span></label>
<input type='text' id='node-input-outParams1_actionArgsConstValue' data-i18n="[placeholder]editor.outParams1.actionArgs.placeholder">
<input type='hidden' id='node-input-outParams1_actionArgsType'>
<input type='hidden' id='node-input-outParams1_actionArgsConstValue'>
</div>
</div>
</div>
Expand Down
6 changes: 1 addition & 5 deletions node-red-node-wot/src/wot-server-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,5 @@ module.exports = function (RED) {
const woTServerConfig = RED.nodes.getNode(config.woTServerConfig)
woTServerConfig.addUserNode(node)
}
RED.nodes.registerType("wot-server-action", WoTServerAction, {
credentials: {
outParams1_actionArgs: { type: "text" },
},
})
RED.nodes.registerType("wot-server-action", WoTServerAction)
}
86 changes: 18 additions & 68 deletions node-red-node-wot/src/wot-server-config.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,9 @@
category: "config",
defaults: {
name: { value: "", required: true },
bindingType: { value: "http" },
bindingConfigType: { value: "json" },
bindingConfigConstValue: { value: "{}" },
},
credentials: {
bindingConfig: { type: "object" },
bindingType: { value: "http", required: true },
bindingConfigType: { value: "json", required: true },
bindingConfigConstValue: { value: "{}", required: true },
},
label: function () {
return this.name || this._("editor.configLabel")
Expand All @@ -37,16 +34,12 @@
},
oneditprepare: function () {
// 入力パラメータの指定項目作成
createInOutParamSetting(
{
name: "bindingConfig",
types: ["json"],
defaultType: "json",
defaultValue: "{}",
required: true,
},
this
)
$("#node-config-input-bindingConfigConstValue").typedInput({
defaultType: "json",
defaultValue: "{}",
types: ["json"],
typeField: "#node-config-input-bindingConfigType",
})

BINDING_TYPE_LIST.forEach((type) => {
$("#node-config-input-bindingType").append(`<option value="${type}">${type}</option>`)
Expand All @@ -57,62 +50,19 @@
$("#node-config-input-bindingType").on("change", () => {
const selectedBindingType = $("#node-config-input-bindingType").val()
if (selectedBindingType === this.bindingType && this.bindingConfigConstValue !== "{}") {
$("#node-config-input-bindingConfig").typedInput("value", this.bindingConfigConstValue)
$("#node-config-input-bindingConfigConstValue").typedInput(
"value",
this.bindingConfigConstValue
)
} else {
$("#node-config-input-bindingConfig").typedInput(
$("#node-config-input-bindingConfigConstValue").typedInput(
"value",
JSON.stringify(BINDING_CONFIG_DEFAULT[selectedBindingType])
)
}
})
},
oneditsave: function () {
saveInOutParamSetting(
{
name: "bindingConfig",
types: ["json"],
defaultType: "json",
defaultValue: "{}",
required: true,
},
this
)
},
})

const createInOutParamSetting = (params, _this) => {
const { name, types, defaultType, defaultValue, required } = params
if (!_this[name + "Type"]) {
_this[name + "Type"] = defaultType
}
if (_this[name + "Type"] == "str") {
$(`#node-config-input-${name}ConstValue`).val("")
} else {
if (_this[name + "ConstValue"] == "") {
$(`#node-config-input-${name}ConstValue`).val(_this.credentials[name])
} else {
_this.credentials[name] = _this[name + "ConstValue"]
$(`#node-config-input-${name}`).val(_this.credentials[name])
}
}
$(`#node-config-input-${name}Type`).val(_this[name + "Type"])
$(`#node-config-input-${name}`).typedInput({
default: defaultType,
typeField: $(`#node-config-input-${name}Type`),
types: types,
})
$(`#node-config-input-${name}`).typedInput("type", _this[name + "Type"])
}
const saveInOutParamSetting = (params, _this) => {
const { name } = params
if ($(`#node-config-input-${name}Type`).val() != "str") {
_this[`${name}ConstValue`] = $(`#node-config-input-${name}`).val()
$(`#node-config-input-${name}ConstValue`).val(_this[`${name}ConstValue`])
} else {
$(`#node-config-input-${name}ConstValue`).val("")
_this[`${name}ConstValue`] = ""
}
}
})()
</script>

Expand All @@ -126,14 +76,14 @@
<select id="node-config-input-bindingType"></select>
</div>
<div class="form-row">
<label for="node-config-input-bindingConfig"><span data-i18n="editor.bindingConfigLabel"></span></label>
<label for="node-config-input-bindingConfigConstValue"
><span data-i18n="editor.bindingConfigLabel"></span
></label>
<input
required
type="text"
id="node-config-input-bindingConfig"
id="node-config-input-bindingConfigConstValue"
data-i18n="[placeholder]editor.bindingConfigPlaceholder"
/>
<input type="hidden" id="node-config-input-bindingConfigType" />
<input type="hidden" id="node-config-input-bindingConfigConstValue" />
</div>
</script>
Loading

0 comments on commit 8c51b69

Please sign in to comment.