Experimental update mechanism for a single page view

This commit is contained in:
Erki Aas 2022-10-11 02:27:31 +03:00
parent 26e79bbb20
commit 274620c994

View File

@ -9,6 +9,7 @@
:row-data="null" :row-data="null"
:supress-horisontal-scroll="true" :supress-horisontal-scroll="true"
:enable-scrolling="true" :enable-scrolling="true"
:get-row-id="(params) => params.data.index"
></ag-grid-vue> ></ag-grid-vue>
</div> </div>
</template> </template>
@ -37,6 +38,9 @@ export default {
floatingFilter: true, floatingFilter: true,
resizable: true, resizable: true,
}, },
currentRowCount: 0,
viewRowCount: 20,
comboBoxOptions: [],
columnDefs: [ columnDefs: [
{ {
field: '_id', field: '_id',
@ -71,6 +75,23 @@ export default {
created() { created() {
this.setupStream() this.setupStream()
}, },
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
}
}
},
methods: { methods: {
setupStream() { setupStream() {
let es = new EventSource('/events'); let es = new EventSource('/events');
@ -79,13 +100,31 @@ export default {
onGridReady(params) { onGridReady(params) {
this.gridApi = params.api; this.gridApi = params.api;
this.gridColumnApi = params.columnApi; this.gridColumnApi = params.columnApi;
const timer = setInterval(() => {
this.refreshRowData();
}, 1000);
}, },
handleReceiveMessage (event) { handleReceiveMessage (event) {
const eventData = this.parseEventData(event.data); const eventData = this.parseEventData(event.data);
this.rowData.unshift(eventData) eventData.index = this.currentRowCount
// this.rowData.unshift(eventData)
if (this.currentRowCount < this.viewRowCount) {
this.gridApi.setRowData(this.rowData) this.gridApi.setRowData(this.rowData)
this.currentRowCount = this.currentRowCount + 1
}
this.gridApi.sizeColumnsToFit() this.gridApi.sizeColumnsToFit()
}, },
refreshRowData () {
const itemsToUpdate = [];
this.rowData.slice(0 - this.viewRowCount).forEach((row, index) => {
row.index = index
itemsToUpdate.push(row)
});
this.gridApi.applyTransactionAsync({ update: itemsToUpdate });
this.gridApi.sizeColumnsToFit()
this.getComboBoxOptions()
},
parseEventData (eventData) { parseEventData (eventData) {
try { try {
let json = JSON.parse(eventData) let json = JSON.parse(eventData)
@ -97,20 +136,24 @@ export default {
console.error(e, eventData) console.error(e, eventData)
} }
}, },
setColumnDefs (json) { getComboBoxOptions () {
const keys = Object.keys(json) const opts = {}
const defs = [] this.columnDefs.map((def) => {
keys.map((key) => { if ((def.floatingFilterComponent || null) === 'ComboboxFilter' ) {
const definition = { const field = def.field
field: key, const unique = {};
initialPinned: true, this.rowData.map((row) => {
filter: true, const value = field.split('.').reduce((a, b) => a[b], row);
floatingFilter: true, unique[value] = 1;
minWidth: 80
}
defs.push(definition)
}) })
this.columnDefs = defs const uniqueArray = [];
for (const n in unique) uniqueArray.push(n);
opts[field] = uniqueArray
}
})
if (JSON.stringify(this.comboBoxOptions) !== JSON.stringify(opts)) {
this.comboBoxOptions = opts
}
} }
} }
} }