Filters for created_at and kind.
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user