Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Добавить улов индексирован #967

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/css/dialogs-browse-backups.css
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@
height: 90px;
}

.browse-backups .session-list-empty,
.browse-backups .snapshot-list-empty {
.browse-backups .centered-message {
position: absolute;
left: 50%;
width: 200px;
Expand All @@ -68,9 +67,18 @@
font-size: 16px;
text-align: center;
border: 1px solid;
}

.browse-backups .session-list-empty,
.browse-backups .snapshot-list-empty {
color: #bbb;
}

.browse-backups .session-list-error,
.browse-backups .snapshot-list-error {
color: white;
}

.browse-backups .session-item {
/* Transition duration should be kept in sync with SelectSession.DELETE_TRANSITION_DURATION */
transition: all 500ms;
Expand Down
47 changes: 26 additions & 21 deletions src/js/controller/dialogs/backups/steps/SelectSession.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,31 +39,36 @@

ns.SelectSession.prototype.update = function () {
pskl.app.backupService.list().then(function (sessions) {
var html = '';
if (sessions.length === 0) {
html = pskl.utils.Template.get('session-list-empty');
} else {
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);
});
}
var html = this.getMarkupForSessions_(sessions);
this.container.querySelector('.session-list').innerHTML = html;
}.bind(this)).catch(function () {
var html = pskl.utils.Template.get('session-list-error');
this.container.querySelector('.session-list').innerHTML = html;
}.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 () {
pskl.utils.Event.removeAllEventListeners(this);
};
Expand Down
55 changes: 32 additions & 23 deletions src/js/controller/dialogs/backups/steps/SessionDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,33 +27,42 @@
ns.SessionDetails.prototype.onShow = function () {
var sessionId = this.backupsController.backupsData.selectedSession;
pskl.app.backupService.getSnapshotsBySessionId(sessionId).then(function (snapshots) {
var html = '';
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');
html = pskl.utils.Template.get('snapshot-list-empty');
} else {
var sessionItemTemplate = pskl.utils.Template.get('snapshot-list-item');
var html = '';
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));
}
var html = this.getMarkupForSnapshots_(snapshots);
this.container.querySelector('.snapshot-list').innerHTML = html;

// Load the image of the first frame for each sprite and update the list.
snapshots.forEach(function (snapshot) {
this.updateSnapshotPreview_(snapshot);
}.bind(this));
}.bind(this)).catch(function () {
var html = pskl.utils.Template.get('snapshot-list-error');
this.container.querySelector('.snapshot-list').innerHTML = html;
}.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) {
pskl.utils.serialization.Deserializer.deserialize(
JSON.parse(snapshot.serialized),
Expand Down
4 changes: 1 addition & 3 deletions src/js/database/PiskelDatabase.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@
return _requestPromise(request).then(function (event) {
this.db = event.target.result;
return this.db;
}.bind(this)).catch(function (e) {
console.log('Failed to initialize IndexedDB, local browser saves will be unavailable.');
});
}.bind(this));
};

ns.PiskelDatabase.prototype.onUpgradeNeeded_ = function (event) {
Expand Down
8 changes: 5 additions & 3 deletions src/js/service/storage/IndexedDbStorageService.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
};

ns.IndexedDbStorageService.prototype.init = function () {
this.piskelDatabase.init();
this.piskelDatabase.init().catch(function (e) {
console.log('Failed to initialize PiskelDatabase, local browser saves will be unavailable.');
});
};

ns.IndexedDbStorageService.prototype.save = function (piskel) {
Expand All @@ -30,7 +32,7 @@
};

ns.IndexedDbStorageService.prototype.load = function (name) {
this.piskelDatabase.get(name).then(function (piskelData) {
return this.piskelDatabase.get(name).then(function (piskelData) {
if (typeof piskelData !== 'undefined') {
var serialized = piskelData.serialized;
pskl.utils.serialization.Deserializer.deserialize(
Expand All @@ -46,7 +48,7 @@
};

ns.IndexedDbStorageService.prototype.remove = function (name) {
this.piskelDatabase.delete(name);
return this.piskelDatabase.delete(name);
};

ns.IndexedDbStorageService.prototype.getKeys = function () {
Expand Down
12 changes: 10 additions & 2 deletions src/templates/dialogs/browse-backups.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ <h3 class="dialog-head">
</script>

<script type="text/template" id="session-list-empty">
<div class="session-list-empty">No session found ...</div>
<div class="centered-message session-list-empty">No session found ...</div>
</script>

<script type="text/template" id="session-list-error">
<div class="centered-message session-list-error">Could not load backup sessions, something went wrong.</div>
</script>

<script type="text/template" id="session-list-item">
Expand Down Expand Up @@ -57,7 +61,11 @@ <h3 class="dialog-head">
</script>

<script type="text/template" id="snapshot-list-empty">
<div class="snapshot-list-empty">No snapshot found ...</div>
<div class="centered-message snapshot-list-empty">No snapshot found ...</div>
</script>

<script type="text/template" id="snapshot-list-error">
<div class="centered-message snapshot-list-error">Could not load snapshots, something went wrong.</div>
</script>

<script type="text/template" id="snapshot-list-item">
Expand Down