Functional host filter.
This commit is contained in:
@@ -35,3 +35,14 @@ export async function sortByIndex(index, query, asc, max) {
|
|||||||
}
|
}
|
||||||
return events;
|
return events;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function getHosts() {
|
||||||
|
let db = await openEventsDb();
|
||||||
|
let hosts = new Set();
|
||||||
|
let cursor = await db.transaction('events').store.openCursor();
|
||||||
|
while (cursor) {
|
||||||
|
hosts.add(cursor.value.metadata.host);
|
||||||
|
cursor = await cursor.continue();
|
||||||
|
}
|
||||||
|
return [...hosts];
|
||||||
|
}
|
||||||
|
|||||||
@@ -71,6 +71,16 @@
|
|||||||
<label for="toKind">To</label>
|
<label for="toKind">To</label>
|
||||||
<input type="number" id="toKind" x-model.number="toKind" class="input" @change="reload">
|
<input type="number" id="toKind" x-model.number="toKind" class="input" @change="reload">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div x-show="view === 'host'">
|
||||||
|
<label for="host">Host</label>
|
||||||
|
<select id="host" class="input" x-model="host" @change="reload">
|
||||||
|
<option value=""></option>
|
||||||
|
<template x-for="h in allHosts">
|
||||||
|
<option :value="h" x-text="h"></option>
|
||||||
|
</template>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import Alpine from 'alpinejs';
|
import Alpine from 'alpinejs';
|
||||||
import { sortByIndex } from './db';
|
import { getHosts, sortByIndex } from './db';
|
||||||
import { KINDS } from './utils';
|
import { KINDS } from './utils';
|
||||||
|
|
||||||
Alpine.data('eventLog', () => ({
|
Alpine.data('eventLog', () => ({
|
||||||
@@ -8,6 +8,8 @@ Alpine.data('eventLog', () => ({
|
|||||||
view: 'created_at',
|
view: 'created_at',
|
||||||
max: 100,
|
max: 100,
|
||||||
sort: 'asc',
|
sort: 'asc',
|
||||||
|
allHosts: [],
|
||||||
|
host: '',
|
||||||
|
|
||||||
// date view
|
// date view
|
||||||
fromCreatedAt: '2008-10-31',
|
fromCreatedAt: '2008-10-31',
|
||||||
@@ -30,6 +32,7 @@ Alpine.data('eventLog', () => ({
|
|||||||
this.max
|
this.max
|
||||||
);
|
);
|
||||||
this.events = events;
|
this.events = events;
|
||||||
|
getHosts().then(hosts => (this.allHosts = hosts));
|
||||||
},
|
},
|
||||||
|
|
||||||
quickKindSelect() {
|
quickKindSelect() {
|
||||||
@@ -60,6 +63,9 @@ Alpine.data('eventLog', () => ({
|
|||||||
case 'kind':
|
case 'kind':
|
||||||
return IDBKeyRange.bound(this.fromKind, this.toKind);
|
return IDBKeyRange.bound(this.fromKind, this.toKind);
|
||||||
|
|
||||||
|
case 'host':
|
||||||
|
if (this.host.length === 0) return null;
|
||||||
|
return IDBKeyRange.only(this.host);
|
||||||
default:
|
default:
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user