-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathui_table.js
227 lines (197 loc) · 11.4 KB
/
ui_table.js
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
module.exports = function(RED) {
function checkConfig(node, conf) {
if (!conf || !conf.hasOwnProperty("group")) {
node.error(RED._("ui_table.error.no-group"));
return false;
}
return true;
}
function HTML(config) {
var html = "<p align='center' style='font-size:16px;'>" + config.label + "</p>"
+"<table id='table' border='1' cellspacing='0'>"
+ "<tr>"
+ "<th ng-repeat = 'item in msg.series' style='font-size:14px; padding:3px'>{{item}}</th>"
+ "</tr>" + "<tbody>"
+ "<tr ng-repeat = 'row in msg.payload'>"
+ "<td ng-repeat = 'item in row' style='font-size:14px; padding:3px'>{{item}}</td>"
+ "</tr> </tbody> </table>";
return html;
};
var ui = undefined;
function TableNode(config) {
try {
var node = this;
if(ui === undefined) {
// load Dashboard API
ui = RED.require("node-red-dashboard")(RED);
}
RED.nodes.createNode(this, config);
var done = null;
this.confsel = config.confsel;
this.contype1 = config.contype1;
this.contype2 = config.contype2;
var item = config.item;
var label = config.label;
if (label == undefined) {
label = "";
}
try {
var statusList = config.statuslist.split(",");
} catch (e) {
var statusList = [];
}
var data; // 出力データ
var dataAry = [];
var group = RED.nodes.getNode(config.group);
if (!group && config.templateScope !== 'global') { return; }
var tab = null;
if (config.templateScope !== 'global') {
tab = RED.nodes.getNode(group.config.tab);
if (!tab) { return; }
}
// サイズ調整
if (config.width === "0") { delete config.width; }
if (config.height === "0") { delete config.height; }
var previousTemplate = null;
if (checkConfig(node, config)) {
var html = HTML(config);
done = ui.addWidget({
node: node,
format: html,
group: config.group,
width: parseInt(config.width || group.config.width || 6),
height: parseInt(config.height || group.config.width/3+1 || 2),
order: config.order,
templateScope: "local",
emitOnlyNewValues: false,
forwardInputMessages: config.fwdInMessages,
storeFrontEndInputAsState: config.storeOutMessages,
beforeEmit: function(msg, value) {
node.status({fill:"blue", shape:"dot", text:"runtime.connect"});
// 入力値によって分岐
switch (node.confsel) {
case "dynamodbSet":
// contentTypeを基にデータ作成
switch(node.contype1) {
case "Alarm&Event":
msg.series = ["timestamp", "No", "エラー詳細", "ステータス"];
itemList = msg.payload.Items;
dataAry = []; // 出力用データ一時保存用
var temp = []; // 出力用データ保存用
var contentList; // 取得データ一時保存
if (itemList != undefined) {
for(i=0;i < itemList.length; i++) { //データ件数でループ
try {
if (itemList[i].dataObject.objectContent != undefined) {
contentList = itemList[i].dataObject.objectContent.contentData;
} else if (itemList[i].dataObject.ObjectContent != undefined) {
contentList = itemList[i].dataObject.ObjectContent.contentData;
} else {
node.status({fill:"yellow", shape:"ring", text:"runtime.noObjCnt"});
continue;
}
} catch (e) {
node.status({fill:"yellow", shape:"ring", text:"runtime.noObjCnt"});
continue;
}
if (contentList.length > 0){
var conIdx;
for (conIdx=0; conIdx<contentList.length; conIdx++) {
if (contentList[conIdx].commonName === "Alarm&Event" && contentList[conIdx].dataValue != undefined) {
if (statusList.indexOf(contentList[conIdx].dataValue.AnEStatus) != -1) {
// 情報をdataAryに格納
if (itemList[i].timestamp != undefined) {
temp.push(itemList[i].timestamp);
} else {
temp.push(itemList[i].timeStamp);
}
temp.push(contentList[conIdx].dataValue.AnECode);
temp.push(contentList[conIdx].dataValue.AnEDescription);
temp.push(contentList[conIdx].dataValue.AnEStatus);
dataAry.push(temp);
temp = [];
}
} else {
node.status({fill:"yellow", shape:"ring", text:"runtime.noConType"});
}
}
}
}
}
node.status({fill:"green", shape:"dot", text:"runtime.complete"});
break;
default:
node.error("contentType:対象外の集計データです");
node.status({fill:"yellow", shape:"ring", text:"runtime.noConType"});
dataAry = [];
}
msg.payload = dataAry;
break;
case "inchartSet":
switch(node.contype2) {
case "iaCloudData":
default:
try {
dataAry = []; // 出力用データ一時保存用
var temp = []; // 出力用データ保存用
msg.series = msg.payload[0].series;
data = msg.payload[0].data;
msg.series.unshift("timestamp");
for (var i=0;i<data[0].length;i++) {
temp.push(data[0][i].x, data[0][i].y);
for (var j=1;j<data.length;j++){
temp.push(data[j][i].y);
}
dataAry.push(temp);
temp = [];
}
} catch (e) {
node.status({fill:"yellow", shape:"ring", text:"runtime.formatError"});
}
}
msg.payload = dataAry;
break;
case "formatSet":
// 項目取得、配列に変換
msg.series = item.split(",");
break;
default:
}
var properties = Object.getOwnPropertyNames(msg).filter(function (p) { return p[0] != '_'; });
var clonedMsg = {
templateScope: config.templateScope
};
for (var i=0; i<properties.length; i++) {
var property = properties[i];
clonedMsg[property] = msg[property];
}
// transform to string if msg.template is buffer
if (clonedMsg.template !== undefined && Buffer.isBuffer(clonedMsg.template)) {
clonedMsg.template = clonedMsg.template.toString();
}
if (clonedMsg.template === undefined && previousTemplate !== null) {
clonedMsg.template = previousTemplate;
}
if (clonedMsg.template) {
previousTemplate = clonedMsg.template
}
if (msg.payload.length > 0) {
node.status({fill:"green", shape:"dot", text:"runtime.complete"});
} else {
node.status({fill:"yellow", shape:"ring", text:"runtime.noData"});
}
return { msg:clonedMsg };
},
beforeSend: function (msg, original) {
if (original) { return original.msg; }
},
});
}
}
catch (e) {
console.log(e);
}
node.on("close", done);
}
RED.nodes.registerType('ui_table', TableNode);
};