|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright ownership. |
| 5 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | + * (the "License"); you may not use this file except in compliance with |
| 7 | + * the License. You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +const sysViewSearchNodesSelect = $('#sysViewSearchNodes'); |
| 19 | +const searchViewsSelect = $('#searchViews'); |
| 20 | + |
| 21 | +function generateColumns(viewName, nodeId) { |
| 22 | + const keys = []; |
| 23 | + |
| 24 | + if (nodeId === "total") |
| 25 | + keys.push("viewNodeId"); |
| 26 | + |
| 27 | + const hasSchema = Object.values(REPORT_DATA['systemView']).some(nodeData => { |
| 28 | + if (nodeData[viewName]) { |
| 29 | + keys.push(...nodeData[viewName]['schema']); |
| 30 | + return true; |
| 31 | + } |
| 32 | + return false; |
| 33 | + }); |
| 34 | + |
| 35 | + if (!hasSchema) |
| 36 | + return null; |
| 37 | + |
| 38 | + return keys.map((key, index) => ({ |
| 39 | + field: index, |
| 40 | + title: key, |
| 41 | + sortable: true |
| 42 | + })); |
| 43 | +} |
| 44 | + |
| 45 | +function generateRows(viewName, nodeId) { |
| 46 | + if (nodeId !== "total") { |
| 47 | + const view = REPORT_DATA['systemView'][nodeId][viewName]; |
| 48 | + if (view) |
| 49 | + return view['data']; |
| 50 | + |
| 51 | + return []; |
| 52 | + } |
| 53 | + |
| 54 | + return Object.entries(REPORT_DATA['systemView']).flatMap(([nodeId, nodeData]) => { |
| 55 | + if (!nodeData[viewName]) |
| 56 | + return []; |
| 57 | + |
| 58 | + return nodeData[viewName]['data'].map(row => [nodeId, ...row]); |
| 59 | + }); |
| 60 | +} |
| 61 | + |
| 62 | +function drawSystemViewsTable() { |
| 63 | + const div = document.getElementById('systemViewTableDiv'); |
| 64 | + div.innerHTML = ""; |
| 65 | + |
| 66 | + const nodeId = sysViewSearchNodesSelect.val(); |
| 67 | + const viewName = searchViewsSelect.val(); |
| 68 | + |
| 69 | + const columns = generateColumns(viewName, nodeId); |
| 70 | + const rows = generateRows(viewName, nodeId); |
| 71 | + |
| 72 | + const table = document.createElement('table'); |
| 73 | + |
| 74 | + table.id = 'systemViewTable'; |
| 75 | + div.appendChild(table); |
| 76 | + |
| 77 | + $(table).bootstrapTable({ |
| 78 | + formatNoMatches: () => `The "${viewName}" system view is empty on node "${nodeId}".`, |
| 79 | + pagination: true, |
| 80 | + search: true, |
| 81 | + columns: columns, |
| 82 | + data: rows, |
| 83 | + sortOrder: 'desc' |
| 84 | + }); |
| 85 | +} |
| 86 | + |
| 87 | +buildSelectNodesSystemView(sysViewSearchNodesSelect, drawSystemViewsTable); |
| 88 | +buildSelectSystemViews(searchViewsSelect, drawSystemViewsTable); |
| 89 | + |
| 90 | +drawSystemViewsTable(); |
0 commit comments