|
154 | 154 | document.getElementById('filter_error').innerText = error.message;
|
155 | 155 | }
|
156 | 156 | }
|
| 157 | +function tab_option(type_str, regex_prefix, regex_postfix, nodes, logs) |
| 158 | +{ |
| 159 | + str = type_str + " log with multiple nodes detected.\n\n"; |
| 160 | + str += "Would you like to open them all with new tabs?\n\n"; |
| 161 | + str += "Nodes detected:\n" + nodes.join("\n"); |
| 162 | + |
| 163 | + function make_regex(key) { |
| 164 | + return new RegExp(regex_prefix + key + regex_postfix, "g"); |
| 165 | + } |
| 166 | + |
| 167 | + if(!confirm(str)) |
| 168 | + return null; |
| 169 | + |
| 170 | + function load_next_tab() { |
| 171 | + if (!nodes.length) |
| 172 | + return; |
| 173 | + window.addEventListener('message', on_recv_msg); |
| 174 | + w = window.open(window.location.href, '_blank'); |
| 175 | + w.blur(); |
| 176 | + window.focus(); |
| 177 | + } |
| 178 | + function on_recv_msg(msg) { |
| 179 | + if(msg.data == "v0.1-ready") { |
| 180 | + msg.source.postMessage({"version": "v0.1-data", "logs": logs, "prefix": make_regex(nodes.shift())}, "*"); |
| 181 | + window.removeEventListener('message', on_recv_msg); |
| 182 | + load_next_tab(); |
| 183 | + } |
| 184 | + } |
| 185 | + var result = make_regex(nodes.shift()); |
| 186 | + load_next_tab(); |
| 187 | + return result; |
| 188 | +} |
| 189 | +function single_option(type_str, regex_prefix, regex_postfix, nodes) |
| 190 | +{ |
| 191 | + str = type_str + " log with multiple nodes detected.\n\n"; |
| 192 | + str += "Which would you like rendered?\n\n"; |
| 193 | + str += "Nodes detected:\n" + nodes.join("\n"); |
| 194 | + |
| 195 | + function make_regex(key) { |
| 196 | + return new RegExp(regex_prefix + key + regex_postfix, "g"); |
| 197 | + } |
| 198 | + |
| 199 | + var result = prompt(str, nodes[0]); |
| 200 | + |
| 201 | + return result ? make_regex(result.trim()) : null; |
| 202 | +} |
157 | 203 | function detect_ci_logs(logs)
|
158 | 204 | {
|
159 | 205 | nodes = new Set()
|
160 | 206 | Array.from(logs.matchAll(/[0-9\-T:.Z]+ (lightningd-[0-9]+) /g)).forEach(match => {
|
161 | 207 | nodes.add(match[1]);
|
162 | 208 | });
|
163 | 209 | var keys = [...nodes];
|
164 |
| - var node = keys.at(0); |
165 | 210 |
|
166 |
| - if (nodes.size > 1) { |
167 |
| - str = "Continous Integration log with multiple nodes detected.\n\nWhich would you like rendered?\n\nNodes detected:\n" + keys.join("\n"); |
168 |
| - node = prompt(str, keys[0]).trim(); |
169 |
| - } |
| 211 | + if (keys.length > 1) |
| 212 | + return tab_option("Continous Integration", "[0-9\-T:.Z]+ ", " ", keys, logs) |
| 213 | + || single_option("Continous Integration", "[0-9\-T:.Z]+ ", " ", keys); |
170 | 214 |
|
171 |
| - return node ? new RegExp(`[0-9\-T:.Z]+ ${node} `, "g") : null; |
| 215 | + return keys.at(0); |
172 | 216 | }
|
173 | 217 | function detect_pytest_logs(logs)
|
174 | 218 | {
|
|
177 | 221 | nodes.add(match[1]);
|
178 | 222 | });
|
179 | 223 | var keys = [...nodes];
|
180 |
| - var node = keys.at(0); |
181 | 224 |
|
182 |
| - if (nodes.size > 1) { |
183 |
| - str = "Python Test log with multiple nodes detected.\n\nWhich would you like rendered?\n\nNodes detected:\n" + keys.join("\n"); |
184 |
| - node = prompt(str, keys[0]).trim(); |
185 |
| - } |
| 225 | + if (keys.length > 1) |
| 226 | + return tab_option("Python Test", "", " ", keys, logs) |
| 227 | + || single_option("Python Test", "", " ", keys); |
186 | 228 |
|
187 |
| - return node ? new RegExp(`^${node} `, "g") : null; |
| 229 | + return keys.at(0); |
| 230 | +} |
| 231 | +window.onload = function() { |
| 232 | + if (window.opener) { |
| 233 | + function receive_data_message(msg) { |
| 234 | + if (!msg.data || msg.data.version != "v0.1-data") { |
| 235 | + console.log("Unrecognized data message"); |
| 236 | + console.log(msg); |
| 237 | + } |
| 238 | + else { |
| 239 | + do_render(msg.data.logs, document.getElementById('area'), msg.data.prefix); |
| 240 | + window.removeEventListener('message', receive_data_message); |
| 241 | + } |
| 242 | + } |
| 243 | + window.addEventListener('message', receive_data_message); |
| 244 | + console.log(window.opener); |
| 245 | + window.opener.postMessage("v0.1-ready", "*"); |
| 246 | + } |
188 | 247 | }
|
189 | 248 | function detect_log_prefix(logs)
|
190 | 249 | {
|
|
196 | 255 | return pytest;
|
197 | 256 | return null;
|
198 | 257 | }
|
199 |
| -function do_render(logs, area) |
| 258 | +function do_render(logs, area, prefix) |
200 | 259 | {
|
201 | 260 | var d = document;
|
202 | 261 | var sheet = d.getElementById('logStyleSheet').sheet;
|
|
210 | 269 | while(sheet.cssRules.length)
|
211 | 270 | sheet.deleteRule(0);
|
212 | 271 |
|
213 |
| - prefix = detect_log_prefix(logs); |
| 272 | + if(!prefix) |
| 273 | + prefix = detect_log_prefix(logs); |
214 | 274 |
|
215 | 275 | for(line of logs.split("\n")) {
|
216 | 276 | line = line.trim()
|
|
0 commit comments