Database exception handling
This commit is contained in:
@@ -112,6 +112,14 @@ class ApplicationViewCtrl extends PureCtrl {
|
||||
}
|
||||
} else if (eventName === ApplicationEvents.InvalidSyncSession) {
|
||||
this.showInvalidSessionAlert();
|
||||
} else if(eventName === ApplicationEvents.LocalDatabaseReadError) {
|
||||
this.application.alertService.alert({
|
||||
text: 'Unable to load local database. Please restart the app and try again.'
|
||||
});
|
||||
} else if (eventName === ApplicationEvents.LocalDatabaseWriteError) {
|
||||
this.application.alertService.alert({
|
||||
text: 'Unable to write to local database. Please restart the app and try again.'
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -218,7 +226,7 @@ class ApplicationViewCtrl extends PureCtrl {
|
||||
if (!this.lastShownDate || lastShownSeconds > SHOW_INTERVAL) {
|
||||
this.lastShownDate = new Date();
|
||||
setTimeout(() => {
|
||||
this.alertService.alert({
|
||||
this.application.alertService.alert({
|
||||
text: STRING_SESSION_EXPIRED
|
||||
});
|
||||
}, 500);
|
||||
|
||||
@@ -74,7 +74,6 @@ class EditorCtrl extends PureCtrl {
|
||||
|
||||
$onInit() {
|
||||
super.$onInit();
|
||||
this.addSyncStatusObserver();
|
||||
this.registerKeyboardShortcuts();
|
||||
}
|
||||
|
||||
@@ -136,6 +135,11 @@ class EditorCtrl extends PureCtrl {
|
||||
if (this.state.note.dirty) {
|
||||
this.showErrorStatus();
|
||||
}
|
||||
} else if (eventName === ApplicationEvents.LocalDatabaseWriteError) {
|
||||
this.showErrorStatus({
|
||||
message: "Offline Saving Issue",
|
||||
desc: "Changes not saved"
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -256,21 +260,6 @@ class EditorCtrl extends PureCtrl {
|
||||
this.reloadComponentContext();
|
||||
}
|
||||
|
||||
addSyncStatusObserver() {
|
||||
/** @todo */
|
||||
// this.syncStatusObserver = syncManager.
|
||||
// registerSyncStatusObserver((status) => {
|
||||
// if (status.localError) {
|
||||
// this.$timeout(() => {
|
||||
// this.showErrorStatus({
|
||||
// message: "Offline Saving Issue",
|
||||
// desc: "Changes not saved"
|
||||
// });
|
||||
// }, 500);
|
||||
// }
|
||||
// });
|
||||
}
|
||||
|
||||
editorForNote(note) {
|
||||
return this.application.componentManager.editorForNote(note);
|
||||
}
|
||||
@@ -421,13 +410,9 @@ class EditorCtrl extends PureCtrl {
|
||||
saveError: false,
|
||||
syncTakingTooLong: false
|
||||
});
|
||||
let status = "All changes saved";
|
||||
if (this.application.noAccount()) {
|
||||
status += " (offline)";
|
||||
}
|
||||
this.setStatus(
|
||||
{ message: status }
|
||||
);
|
||||
this.setStatus({
|
||||
message: 'All changes saved',
|
||||
});
|
||||
}
|
||||
|
||||
showErrorStatus(error) {
|
||||
|
||||
@@ -104,7 +104,7 @@ export class Database {
|
||||
/** @access public */
|
||||
async getAllPayloads() {
|
||||
const db = await this.openDatabase();
|
||||
return new Promise((resolve) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const objectStore =
|
||||
db.transaction(STORE_NAME).
|
||||
objectStore(STORE_NAME);
|
||||
@@ -170,11 +170,11 @@ export class Database {
|
||||
/** @access public */
|
||||
async deletePayload(uuid) {
|
||||
const db = await this.openDatabase();
|
||||
const request =
|
||||
db.transaction(STORE_NAME, READ_WRITE)
|
||||
.objectStore(STORE_NAME)
|
||||
.delete(uuid);
|
||||
return new Promise((resolve, reject) => {
|
||||
const request =
|
||||
db.transaction(STORE_NAME, READ_WRITE)
|
||||
.objectStore(STORE_NAME)
|
||||
.delete(uuid);
|
||||
request.onsuccess = resolve;
|
||||
request.onerror = reject;
|
||||
});
|
||||
|
||||
@@ -64,12 +64,14 @@ export class WebDeviceInterface extends DeviceInterface {
|
||||
|
||||
async openDatabase() {
|
||||
this.database.unlock();
|
||||
return new Promise((resolve) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.database.openDatabase(() => {
|
||||
resolve({ isNewDatabase: true });
|
||||
}).then(() => {
|
||||
resolve({ isNewDatabase: false });
|
||||
});
|
||||
}).catch((error => {
|
||||
reject(error);
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
135
dist/javascripts/app.js
vendored
135
dist/javascripts/app.js
vendored
File diff suppressed because one or more lines are too long
2
dist/javascripts/app.js.map
vendored
2
dist/javascripts/app.js.map
vendored
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user