Filters for created_at and kind.

This commit is contained in:
Ryan Breen
2023-02-12 22:46:34 -05:00
parent 0847a55afa
commit e0349bdf00
3 changed files with 85 additions and 15 deletions

View File

@@ -5,16 +5,52 @@ Alpine.data('eventLog', () => ({
events: [],
view: 'created_at',
max: 100,
ascending: false,
sort: 'asc',
// date view
fromCreatedAt: '2008-10-31',
toCreatedAt: new Date().toISOString().split('T')[0],
// kind view
fromKind: 0,
toKind: 50000,
async init() {
await this.reload();
},
async reload() {
let events = await sortByIndex(this.view, this.ascending, this.max);
let events = await sortByIndex(
this.view,
this.keyRange,
this.sort === 'asc',
this.max
);
this.events = events;
},
get fromTime() {
let dt = new Date(this.fromCreatedAt);
return Math.floor(dt.getTime() / 1000);
},
get toTime() {
let dt = new Date(this.toCreatedAt);
return Math.floor(dt.getTime() / 1000);
},
get keyRange() {
switch (this.view) {
case 'created_at':
return IDBKeyRange.bound(this.fromTime, this.toTime);
case 'kind':
return IDBKeyRange.bound(this.fromKind, this.toKind);
default:
return null;
}
},
}));
Alpine.start();