Initial query mechanism

This commit is contained in:
Erki Aas 2022-11-08 20:17:45 +02:00
parent 63b2fb2c20
commit 258571a064
2 changed files with 18 additions and 7 deletions

View File

@ -71,7 +71,9 @@ export default {
}, },
created() { created() {
// TODO: monitor actual URL. // TODO: monitor actual URL.
this.setFilterQuery({}) this.setFilterQuery({
'initial': 'true'
})
}, },
methods: { methods: {
...mapActions({ ...mapActions({
@ -85,11 +87,13 @@ export default {
for (const key in this.filterQuery) { for (const key in this.filterQuery) {
url.searchParams.append(key, this.filterQuery[key]); url.searchParams.append(key, this.filterQuery[key]);
} }
let es = new EventSource(url.toString()); if (url.searchParams.keys().next()) {
es.onmessage = (e) => this.handleReceiveMessage(e) let es = new EventSource(url.toString());
es.addEventListener("filters", (e) => this.handleReceiveFilters(e)) es.onmessage = (e) => this.handleReceiveMessage(e)
es.addEventListener("timeout", (e) => this.handleReceiveTimeout(e)) es.addEventListener("filters", (e) => this.handleReceiveFilters(e))
this.es = es es.addEventListener("timeout", (e) => this.handleReceiveTimeout(e))
this.es = es
}
}, },
onGridReady(params) { onGridReady(params) {
this.gridApi = params.api; this.gridApi = params.api;
@ -125,6 +129,8 @@ export default {
}, },
handleReceiveMessage (event) { handleReceiveMessage (event) {
const eventData = parseEventData(event.data); const eventData = parseEventData(event.data);
// TODO: Duplicate rows might be added. I don't want to seek for every row to be included, but use other ways that would never pull duplicate rows.
// Maybe it's still necessary to filter here, don't know yet.
this.gridApi.applyTransactionAsync({ this.gridApi.applyTransactionAsync({
add: [eventData] add: [eventData]
}, (res) => { }, (res) => {

View File

@ -29,12 +29,17 @@ const store = createStore({
state.filterOptions = payload state.filterOptions = payload
}, },
SET_FILTER_QUERY(state, payload) { SET_FILTER_QUERY(state, payload) {
state.filterQuery = payload let query = payload
if (Object.keys(state.filterOptions).length) {
query['initial'] = false
}
state.filterQuery = query
}, },
TOGGLE_FILTER_QUERY_STREAMING(state) { TOGGLE_FILTER_QUERY_STREAMING(state) {
let query = state.filterQuery let query = state.filterQuery
query['streaming'] = (query['streaming'] === undefined) ? false : query['streaming'] query['streaming'] = (query['streaming'] === undefined) ? false : query['streaming']
query['streaming'] = !(query['streaming']) query['streaming'] = !(query['streaming'])
query['initial'] = false
state.filterQuery = query state.filterQuery = query
}, },
}, },