web: save events on timer
This commit is contained in:
parent
a5415906e9
commit
add261dd01
3 changed files with 64 additions and 55 deletions
|
@ -121,51 +121,4 @@ function event_parse_reaction(ev) {
|
|||
}
|
||||
}
|
||||
|
||||
async function model_save_events(model) {
|
||||
function _events_save(ev, resolve, reject) {
|
||||
const db = ev.target.result;
|
||||
let tx = db.transaction("events", "readwrite");
|
||||
let store = tx.objectStore("events");
|
||||
for (const evid in model.all_events) {
|
||||
store.put(model.all_events[evid]);
|
||||
}
|
||||
tx.oncomplete = (ev) => {
|
||||
db.close();
|
||||
resolve();
|
||||
log_debug("saved events!");
|
||||
};
|
||||
tx.onerror = (ev) => {
|
||||
db.close();
|
||||
log_error("failed to save events");
|
||||
reject(ev);
|
||||
};
|
||||
}
|
||||
return dbcall(_events_save);
|
||||
}
|
||||
|
||||
async function model_load_events(model, fn) {
|
||||
function _events_load(ev, resolve, reject) {
|
||||
const db = ev.target.result;
|
||||
const tx = db.transaction("events", "readonly");
|
||||
const store = tx.objectStore("events");
|
||||
const cursor = store.openCursor();
|
||||
cursor.onsuccess = (ev) => {
|
||||
var cursor = ev.target.result;
|
||||
if (cursor) {
|
||||
fn(cursor.value);
|
||||
cursor.continue();
|
||||
} else {
|
||||
db.close();
|
||||
resolve();
|
||||
log_debug("Successfully loaded events");
|
||||
}
|
||||
}
|
||||
cursor.onerror = (ev) => {
|
||||
db.close();
|
||||
reject(ev);
|
||||
log_error("Could not load events.");
|
||||
};
|
||||
}
|
||||
return dbcall(_events_load);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue