2022-10-05 14:44:28 +00:00
|
|
|
<template>
|
|
|
|
<div style="height: 100%; width: 100%">
|
|
|
|
<ag-grid-vue
|
|
|
|
style="width: 100%; height: 100%;"
|
|
|
|
class="ag-theme-alpine"
|
|
|
|
@grid-ready="onGridReady"
|
|
|
|
:defaultColDef="defaultColDef"
|
|
|
|
:columnDefs="columnDefs"
|
2022-10-10 23:50:03 +00:00
|
|
|
:pagination="true"
|
|
|
|
:paginationAutoPageSize=true
|
2022-10-05 14:44:28 +00:00
|
|
|
:row-data="null"
|
|
|
|
:supress-horisontal-scroll="true"
|
|
|
|
:enable-scrolling="true"
|
2022-10-10 23:27:31 +00:00
|
|
|
></ag-grid-vue>
|
2022-10-05 14:44:28 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import { AgGridVue } from "ag-grid-vue3";
|
|
|
|
import "ag-grid-community/styles//ag-grid.css";
|
|
|
|
import "ag-grid-community/styles//ag-theme-alpine.css";
|
|
|
|
import ScreenshotCell from "./ScreenshotCell.js";
|
2022-10-10 23:50:03 +00:00
|
|
|
import ComboboxFilter from './ComboboxFilter.js';
|
|
|
|
|
|
|
|
const comboBoxDefinition = () => {
|
|
|
|
return {
|
|
|
|
filter: true,
|
|
|
|
floatingFilter: true,
|
|
|
|
suppressMenu: true,
|
|
|
|
floatingFilterComponent: 'ComboboxFilter',
|
|
|
|
floatingFilterComponentParams: {
|
|
|
|
suppressFilterButton: true,
|
|
|
|
options: []
|
|
|
|
},
|
|
|
|
}
|
|
|
|
};
|
2022-10-05 14:44:28 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
components: {
|
|
|
|
AgGridVue,
|
|
|
|
ScreenshotCell: ScreenshotCell,
|
2022-10-10 23:50:03 +00:00
|
|
|
ComboboxFilter
|
2022-10-05 14:44:28 +00:00
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
gridApi: null,
|
|
|
|
gridColumnApi: null,
|
|
|
|
rowData: [],
|
|
|
|
defaultColDef: {
|
|
|
|
width: 50,
|
|
|
|
initialPinned: true,
|
|
|
|
resizable: true,
|
2022-10-10 23:50:03 +00:00
|
|
|
editable: true
|
2022-10-05 14:44:28 +00:00
|
|
|
},
|
2022-10-10 23:27:31 +00:00
|
|
|
currentRowCount: 0,
|
|
|
|
viewRowCount: 20,
|
|
|
|
comboBoxOptions: [],
|
2022-10-05 14:44:28 +00:00
|
|
|
columnDefs: [
|
|
|
|
{
|
|
|
|
field: '_id',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
field: 'kubernetes.namespace',
|
|
|
|
headerName: 'namespace',
|
2022-10-10 23:50:03 +00:00
|
|
|
...comboBoxDefinition(),
|
2022-10-05 14:44:28 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
field: 'kubernetes.pod.name',
|
|
|
|
headerName: 'pod',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
field: 'kubernetes.container.name',
|
|
|
|
headerName: 'container',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
field: 'message',
|
|
|
|
tooltipValueGetter: (params) => 'Address: ' + params.value,
|
|
|
|
width: 500,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
field: 'stream',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
field: '@timestamp',
|
|
|
|
width: 70
|
|
|
|
}
|
|
|
|
],
|
|
|
|
}
|
|
|
|
},
|
|
|
|
created() {
|
|
|
|
this.setupStream()
|
|
|
|
},
|
2022-10-10 23:27:31 +00:00
|
|
|
watch: {
|
|
|
|
comboBoxOptions: {
|
|
|
|
handler(newValue, oldValue) {
|
|
|
|
const clonedDefs = [ ...this.columnDefs ];
|
|
|
|
clonedDefs.map((def) => {
|
|
|
|
if ((def.floatingFilterComponent || null) === 'ComboboxFilter' ) {
|
|
|
|
def.floatingFilterComponentParams = {
|
|
|
|
suppressFilterButton: true,
|
|
|
|
options: Object.values(newValue[def.field])
|
|
|
|
}
|
|
|
|
return def
|
|
|
|
}
|
|
|
|
})
|
|
|
|
this.columnDefs = clonedDefs
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2022-10-05 14:44:28 +00:00
|
|
|
methods: {
|
|
|
|
setupStream() {
|
|
|
|
let es = new EventSource('/events');
|
|
|
|
es.onmessage = (e) => this.handleReceiveMessage(e)
|
|
|
|
},
|
|
|
|
onGridReady(params) {
|
|
|
|
this.gridApi = params.api;
|
|
|
|
this.gridColumnApi = params.columnApi;
|
2022-10-10 23:27:31 +00:00
|
|
|
const timer = setInterval(() => {
|
2022-10-10 23:50:03 +00:00
|
|
|
this.getComboBoxOptions();
|
|
|
|
}, 3000);
|
2022-10-05 14:44:28 +00:00
|
|
|
},
|
|
|
|
handleReceiveMessage (event) {
|
|
|
|
const eventData = this.parseEventData(event.data);
|
2022-10-10 23:50:03 +00:00
|
|
|
this.rowData.push(eventData)
|
|
|
|
this.gridApi.setRowData(this.rowData)
|
2022-10-10 23:27:31 +00:00
|
|
|
this.gridApi.sizeColumnsToFit()
|
2022-10-10 23:50:03 +00:00
|
|
|
this.getComboBoxOptions()
|
2022-10-10 23:27:31 +00:00
|
|
|
},
|
|
|
|
refreshRowData () {
|
|
|
|
const itemsToUpdate = [];
|
|
|
|
this.rowData.slice(0 - this.viewRowCount).forEach((row, index) => {
|
|
|
|
row.index = index
|
|
|
|
itemsToUpdate.push(row)
|
|
|
|
});
|
|
|
|
this.gridApi.applyTransactionAsync({ update: itemsToUpdate });
|
2022-10-05 14:44:28 +00:00
|
|
|
this.gridApi.sizeColumnsToFit()
|
2022-10-10 23:27:31 +00:00
|
|
|
this.getComboBoxOptions()
|
2022-10-05 14:44:28 +00:00
|
|
|
},
|
|
|
|
parseEventData (eventData) {
|
|
|
|
try {
|
|
|
|
let json = JSON.parse(eventData)
|
|
|
|
if (!json.message) {
|
|
|
|
json.message = JSON.stringify(json.json)
|
|
|
|
}
|
|
|
|
return json
|
|
|
|
} catch (e) {
|
|
|
|
console.error(e, eventData)
|
|
|
|
}
|
|
|
|
},
|
2022-10-10 23:27:31 +00:00
|
|
|
getComboBoxOptions () {
|
|
|
|
const opts = {}
|
|
|
|
this.columnDefs.map((def) => {
|
|
|
|
if ((def.floatingFilterComponent || null) === 'ComboboxFilter' ) {
|
|
|
|
const field = def.field
|
|
|
|
const unique = {};
|
|
|
|
this.rowData.map((row) => {
|
|
|
|
const value = field.split('.').reduce((a, b) => a[b], row);
|
|
|
|
unique[value] = 1;
|
|
|
|
})
|
|
|
|
const uniqueArray = [];
|
|
|
|
for (const n in unique) uniqueArray.push(n);
|
|
|
|
opts[field] = uniqueArray
|
2022-10-05 14:44:28 +00:00
|
|
|
}
|
|
|
|
})
|
2022-10-10 23:27:31 +00:00
|
|
|
if (JSON.stringify(this.comboBoxOptions) !== JSON.stringify(opts)) {
|
|
|
|
this.comboBoxOptions = opts
|
|
|
|
}
|
2022-10-05 14:44:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
</script>
|