Skip to content

Commit

Permalink
test : name-dul-error (#15)
Browse files Browse the repository at this point in the history
모듈 이름 중복 체크 여러가지 테스트

Co-authored-by: 김성현 <[email protected]>
  • Loading branch information
Sunghyun1320 and 김성현 authored Sep 21, 2023
1 parent 32a59f8 commit 41b49f4
Showing 1 changed file with 71 additions and 2 deletions.
73 changes: 71 additions & 2 deletions GBL_SASM_Alert/101-module.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ module.exports = function (RED) {
const workspaces = {};
const subflows = {};

var count = 0;
// Iterate through all nodes in the flow.
RED.nodes.eachNode(node => {
count++;
allNode[node.id] = Object.assign({}, node);
if (node.type === "tab") {
workspaces[node.id] = node;
Expand All @@ -72,20 +74,67 @@ module.exports = function (RED) {
}
});

// 정석 체크
for (const nodename in namekeyNode) {
if (namekeyNode[nodename].length != 1) {
namekeyNode[nodename].forEach(nodeID => {
RED.events.emit("GBLtext:" + nodeID, {
fill: "red",
shape: "dot",
text: `name "${nodename}" is duplication`
text: "error"
});
});
} else {
RED.events.emit("GBLtext:" + namekeyNode[nodename][0], {});
RED.events.emit("GBLtext:" + namekeyNode[nodename][0], {
// fill: "green",
// shape: "dot",
// text: "pass"
});
}
}

// 비동기로 시간 간격 늘려서 입력하기
// var delay_time = 65;
// for (const nodename in namekeyNode) {
// if (namekeyNode[nodename].length != 1) {
// namekeyNode[nodename].forEach(nodeID => {
// setTimeout(function () {
// RED.events.emit("GBLtext:" + nodeID, {
// fill: "red",
// shape: "dot",
// text: "error"
// });
// }, delay_time);
// delay_time += 65;
// });
// } else {
// setTimeout(function () {
// RED.events.emit("GBLtext:" + namekeyNode[nodename][0], {});
// }, delay_time);
// delay_time += 65;
// }
// }

// 시간 복잡도 고의로 늘리기
// RED.nodes.eachNode(node => {
// if (node.type === "module_in") {
// console.log("module in");
// var count = 0;
// RED.nodes.eachNode(compare_node => {
// if (node.name == compare_node.name) count++;
// });
// console.log(count);
// if (count != 1) {
// console.log("중복");
// RED.events.emit("GBLtext:" + node.id, {
// fill: "red",
// shape: "dot",
// text: "error"
// });
// } else RED.events.emit("GBLtext:" + node.id, {});
// }
// });

Object.assign(myNodeinFlow, {
...moduleflowNode,
...moduleinNode,
Expand Down Expand Up @@ -173,6 +222,18 @@ module.exports = function (RED) {

initMapping(node.context().global);

// if (config.duplicatedError) {
// console.log("중복이네");
// node.status({
// fill: "red",
// shape: "dot",
// text: `name "${config.name}" is duplication`
// });
// } else {
// console.log("중복아님");
// node.status({});
// }

var event = "GBLmodule:" + node.id;
var event_fun = function (msg) {
node.receive(msg);
Expand All @@ -181,6 +242,7 @@ module.exports = function (RED) {

var node_text_event = "GBLtext:" + node.id;
var node_text_event_fun = function (status) {
// node.receive({ GBL__: status });
node.status(status);
};
RED.events.on(node_text_event, node_text_event_fun);
Expand All @@ -192,6 +254,13 @@ module.exports = function (RED) {
});

this.on("input", function (msg) {
if (typeof msg["GBL__"] != "undefined") {
console.log(node.id);
console.log(msg["GBL__"]);
node.status(msg["GBL__"]);
return;
}

node.send(msg);
});
}
Expand Down

0 comments on commit 41b49f4

Please sign in to comment.