Show error message if BackupDatabase promise rejected

This commit is contained in:
Julian Descottes 2017-10-17 02:09:28 +02:00
parent ab9bbce1ed
commit 3e779a651f
2 changed files with 58 additions and 44 deletions

View File

@ -39,31 +39,36 @@
ns.SelectSession.prototype.update = function () { ns.SelectSession.prototype.update = function () {
pskl.app.backupService.list().then(function (sessions) { pskl.app.backupService.list().then(function (sessions) {
var html = ''; var html = this.getMarkupForSessions_(sessions);
if (sessions.length === 0) { this.container.querySelector('.session-list').innerHTML = html;
html = pskl.utils.Template.get('session-list-empty'); }.bind(this)).catch(function () {
} else { var html = pskl.utils.Template.get('session-list-error');
var sessionItemTemplate = pskl.utils.Template.get('session-list-item');
var html = '';
sessions.forEach(function (session) {
if (session.id === pskl.app.sessionId) {
// Do not show backups for the current session.
return;
}
var view = {
id: session.id,
name: session.name,
description: session.description ? '- ' + session.description : '',
date: pskl.utils.DateUtils.format(session.endDate, 'the {{Y}}/{{M}}/{{D}} at {{H}}:{{m}}'),
count: session.count === 1 ? '1 snapshot' : session.count + ' snapshots'
};
html += pskl.utils.Template.replace(sessionItemTemplate, view);
});
}
this.container.querySelector('.session-list').innerHTML = html; this.container.querySelector('.session-list').innerHTML = html;
}.bind(this)); }.bind(this));
}; };
ns.SelectSession.prototype.getMarkupForSessions_ = function (sessions) {
if (sessions.length === 0) {
return pskl.utils.Template.get('session-list-empty');
}
var sessionItemTemplate = pskl.utils.Template.get('session-list-item');
return sessions.reduce(function (previous, session) {
if (session.id === pskl.app.sessionId) {
// Do not show backups for the current session.
return previous;
}
var view = {
id: session.id,
name: session.name,
description: session.description ? '- ' + session.description : '',
date: pskl.utils.DateUtils.format(session.endDate, 'the {{Y}}/{{M}}/{{D}} at {{H}}:{{m}}'),
count: session.count === 1 ? '1 snapshot' : session.count + ' snapshots'
};
return previous + pskl.utils.Template.replace(sessionItemTemplate, view);
}, '');
};
ns.SelectSession.prototype.destroy = function () { ns.SelectSession.prototype.destroy = function () {
pskl.utils.Event.removeAllEventListeners(this); pskl.utils.Event.removeAllEventListeners(this);
}; };

View File

@ -27,33 +27,42 @@
ns.SessionDetails.prototype.onShow = function () { ns.SessionDetails.prototype.onShow = function () {
var sessionId = this.backupsController.backupsData.selectedSession; var sessionId = this.backupsController.backupsData.selectedSession;
pskl.app.backupService.getSnapshotsBySessionId(sessionId).then(function (snapshots) { pskl.app.backupService.getSnapshotsBySessionId(sessionId).then(function (snapshots) {
var html = ''; var html = this.getMarkupForSnapshots_(snapshots);
if (snapshots.length === 0) { this.container.querySelector('.snapshot-list').innerHTML = html;
// This should normally never happen, all sessions have at least one snapshot and snapshots
// can not be individually deleted. // Load the image of the first frame for each sprite and update the list.
console.warn('Could not retrieve snapshots for a session'); snapshots.forEach(function (snapshot) {
html = pskl.utils.Template.get('snapshot-list-empty'); this.updateSnapshotPreview_(snapshot);
} else { }.bind(this));
var sessionItemTemplate = pskl.utils.Template.get('snapshot-list-item'); }.bind(this)).catch(function () {
var html = ''; var html = pskl.utils.Template.get('snapshot-list-error');
snapshots.forEach(function (snapshot) {
var view = {
id: snapshot.id,
name: snapshot.name,
description: snapshot.description ? '- ' + snapshot.description : '',
date: pskl.utils.DateUtils.format(snapshot.date, 'the {{Y}}/{{M}}/{{D}} at {{H}}:{{m}}'),
frames: snapshot.frames === 1 ? '1 frame' : snapshot.frames + ' frames',
resolution: pskl.utils.StringUtils.formatSize(snapshot.width, snapshot.height),
fps: snapshot.fps
};
html += pskl.utils.Template.replace(sessionItemTemplate, view);
this.updateSnapshotPreview_(snapshot);
}.bind(this));
}
this.container.querySelector('.snapshot-list').innerHTML = html; this.container.querySelector('.snapshot-list').innerHTML = html;
}.bind(this)); }.bind(this));
}; };
ns.SessionDetails.prototype.getMarkupForSnapshots_ = function (snapshots) {
if (snapshots.length === 0) {
// This should normally never happen, all sessions have at least one snapshot and snapshots
// can not be individually deleted.
console.warn('Could not retrieve snapshots for a session');
return pskl.utils.Template.get('snapshot-list-empty');
}
var sessionItemTemplate = pskl.utils.Template.get('snapshot-list-item');
return snapshots.reduce(function (previous, snapshot) {
var view = {
id: snapshot.id,
name: snapshot.name,
description: snapshot.description ? '- ' + snapshot.description : '',
date: pskl.utils.DateUtils.format(snapshot.date, 'the {{Y}}/{{M}}/{{D}} at {{H}}:{{m}}'),
frames: snapshot.frames === 1 ? '1 frame' : snapshot.frames + ' frames',
resolution: pskl.utils.StringUtils.formatSize(snapshot.width, snapshot.height),
fps: snapshot.fps
};
return previous + pskl.utils.Template.replace(sessionItemTemplate, view);
}, '');
};
ns.SessionDetails.prototype.updateSnapshotPreview_ = function (snapshot) { ns.SessionDetails.prototype.updateSnapshotPreview_ = function (snapshot) {
pskl.utils.serialization.Deserializer.deserialize( pskl.utils.serialization.Deserializer.deserialize(
JSON.parse(snapshot.serialized), JSON.parse(snapshot.serialized),