Functional host filter.

This commit is contained in:
Ryan Breen
2023-02-14 21:14:17 -05:00
parent ccc17fbaa8
commit 14a20dd13d
3 changed files with 28 additions and 1 deletions

View File

@@ -35,3 +35,14 @@ export async function sortByIndex(index, query, asc, max) {
}
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];
}

View File

@@ -71,6 +71,16 @@
<label for="toKind">To</label>
<input type="number" id="toKind" x-model.number="toKind" class="input" @change="reload">
</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>

View File

@@ -1,5 +1,5 @@
import Alpine from 'alpinejs';
import { sortByIndex } from './db';
import { getHosts, sortByIndex } from './db';
import { KINDS } from './utils';
Alpine.data('eventLog', () => ({
@@ -8,6 +8,8 @@ Alpine.data('eventLog', () => ({
view: 'created_at',
max: 100,
sort: 'asc',
allHosts: [],
host: '',
// date view
fromCreatedAt: '2008-10-31',
@@ -30,6 +32,7 @@ Alpine.data('eventLog', () => ({
this.max
);
this.events = events;
getHosts().then(hosts => (this.allHosts = hosts));
},
quickKindSelect() {
@@ -60,6 +63,9 @@ Alpine.data('eventLog', () => ({
case 'kind':
return IDBKeyRange.bound(this.fromKind, this.toKind);
case 'host':
if (this.host.length === 0) return null;
return IDBKeyRange.only(this.host);
default:
return null;
}