mirror of
https://github.com/getgrav/grav-plugin-admin.git
synced 2025-10-26 00:36:31 +02:00
fix labels in snapshots
This commit is contained in:
@@ -121,7 +121,7 @@ class SafeUpgradeManager
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, array{id: string, source_version:?string, target_version:?string, created_at:int, created_at_iso:?string, backup_path:?string, package_path:?string}>
|
||||
* @return array<int, array{id: string, label:?string, source_version:?string, target_version:?string, created_at:int, created_at_iso:?string, backup_path:?string, package_path:?string}>
|
||||
*/
|
||||
public function listSnapshots(): array
|
||||
{
|
||||
@@ -144,6 +144,7 @@ class SafeUpgradeManager
|
||||
|
||||
$snapshots[] = [
|
||||
'id' => (string)$decoded['id'],
|
||||
'label' => isset($decoded['label']) && $decoded['label'] !== '' ? (string)$decoded['label'] : null,
|
||||
'source_version' => $decoded['source_version'] ?? null,
|
||||
'target_version' => $decoded['target_version'] ?? null,
|
||||
'created_at' => $createdAt,
|
||||
|
||||
@@ -186,6 +186,12 @@ class RestoreManager {
|
||||
this.job.snapshot = job.result.snapshot;
|
||||
}
|
||||
|
||||
if (!this.job.label && progress.label) {
|
||||
this.job.label = progress.label;
|
||||
} else if (!this.job.label && job.result && job.result.label) {
|
||||
this.job.label = job.result.label;
|
||||
}
|
||||
|
||||
if (stage === 'error' || status === 'error') {
|
||||
const message = job.error || progress.message || (operation === 'snapshot'
|
||||
? translations.PLUGIN_ADMIN?.RESTORE_GRAV_SNAPSHOT_FAILED || 'Snapshot creation failed.'
|
||||
@@ -199,10 +205,14 @@ class RestoreManager {
|
||||
if (stage === 'complete' || status === 'success') {
|
||||
if (operation === 'snapshot') {
|
||||
const snapshotId = progress.snapshot || (job.result && job.result.snapshot) || this.job.snapshot || '';
|
||||
const snapshotLabel = snapshotId || (translations.PLUGIN_ADMIN?.RESTORE_GRAV_TABLE_SNAPSHOT || 'snapshot');
|
||||
const labelValue = progress.label || (job.result && job.result.label) || this.job.label || '';
|
||||
let displayName = labelValue || snapshotId || (translations.PLUGIN_ADMIN?.RESTORE_GRAV_TABLE_SNAPSHOT || 'snapshot');
|
||||
if (labelValue && snapshotId && labelValue !== snapshotId) {
|
||||
displayName = `${labelValue} (${snapshotId})`;
|
||||
}
|
||||
const successMessage = translations.PLUGIN_ADMIN?.RESTORE_GRAV_SNAPSHOT_SUCCESS
|
||||
? translations.PLUGIN_ADMIN.RESTORE_GRAV_SNAPSHOT_SUCCESS.replace('%s', snapshotLabel)
|
||||
: (snapshotId ? `Snapshot ${snapshotId} created.` : 'Snapshot created.');
|
||||
? translations.PLUGIN_ADMIN.RESTORE_GRAV_SNAPSHOT_SUCCESS.replace('%s', displayName)
|
||||
: (snapshotId ? `Snapshot ${displayName} created.` : 'Snapshot created.');
|
||||
toastr.success(successMessage);
|
||||
this.job = null;
|
||||
this.clearPoll();
|
||||
@@ -210,15 +220,22 @@ class RestoreManager {
|
||||
return;
|
||||
}
|
||||
|
||||
const snapshot = progress.snapshot || this.job.snapshot;
|
||||
const snapshotId = progress.snapshot || this.job.snapshot || '';
|
||||
const labelValue = progress.label || (job.result && job.result.label) || this.job.label || '';
|
||||
let snapshotDisplay = snapshotId || labelValue;
|
||||
if (labelValue && snapshotId && labelValue !== snapshotId) {
|
||||
snapshotDisplay = `${labelValue} (${snapshotId})`;
|
||||
} else if (!snapshotDisplay) {
|
||||
snapshotDisplay = translations.PLUGIN_ADMIN?.RESTORE_GRAV_TABLE_SNAPSHOT || 'snapshot';
|
||||
}
|
||||
const version = (job.result && job.result.version) || progress.version || '';
|
||||
let successMessage;
|
||||
if (translations.PLUGIN_ADMIN?.RESTORE_GRAV_SUCCESS_MESSAGE && version) {
|
||||
successMessage = translations.PLUGIN_ADMIN.RESTORE_GRAV_SUCCESS_MESSAGE.replace('%1$s', snapshot).replace('%2$s', version);
|
||||
successMessage = translations.PLUGIN_ADMIN.RESTORE_GRAV_SUCCESS_MESSAGE.replace('%1$s', snapshotDisplay).replace('%2$s', version);
|
||||
} else if (translations.PLUGIN_ADMIN?.RESTORE_GRAV_SUCCESS_SIMPLE) {
|
||||
successMessage = translations.PLUGIN_ADMIN.RESTORE_GRAV_SUCCESS_SIMPLE.replace('%s', snapshot);
|
||||
successMessage = translations.PLUGIN_ADMIN.RESTORE_GRAV_SUCCESS_SIMPLE.replace('%s', snapshotDisplay);
|
||||
} else {
|
||||
successMessage = version ? `Snapshot ${snapshot} restored (Grav ${version}).` : `Snapshot ${snapshot} restored.`;
|
||||
successMessage = version ? `Snapshot ${snapshotDisplay} restored (Grav ${version}).` : `Snapshot ${snapshotDisplay} restored.`;
|
||||
}
|
||||
toastr.success(successMessage);
|
||||
this.job = null;
|
||||
|
||||
41
themes/grav/js/admin.min.js
vendored
41
themes/grav/js/admin.min.js
vendored
@@ -11160,6 +11160,11 @@ var RestoreManager = /*#__PURE__*/function () {
|
||||
} else if (!_this5.job.snapshot && job.result && job.result.snapshot) {
|
||||
_this5.job.snapshot = job.result.snapshot;
|
||||
}
|
||||
if (!_this5.job.label && progress.label) {
|
||||
_this5.job.label = progress.label;
|
||||
} else if (!_this5.job.label && job.result && job.result.label) {
|
||||
_this5.job.label = job.result.label;
|
||||
}
|
||||
if (stage === 'error' || status === 'error') {
|
||||
var _translations$PLUGIN_0, _translations$PLUGIN_1;
|
||||
var message = job.error || progress.message || (operation === 'snapshot' ? ((_translations$PLUGIN_0 = external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN) === null || _translations$PLUGIN_0 === void 0 ? void 0 : _translations$PLUGIN_0.RESTORE_GRAV_SNAPSHOT_FAILED) || 'Snapshot creation failed.' : ((_translations$PLUGIN_1 = external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN) === null || _translations$PLUGIN_1 === void 0 ? void 0 : _translations$PLUGIN_1.RESTORE_GRAV_FAILED) || 'Snapshot restore failed.');
|
||||
@@ -11169,12 +11174,16 @@ var RestoreManager = /*#__PURE__*/function () {
|
||||
return;
|
||||
}
|
||||
if (stage === 'complete' || status === 'success') {
|
||||
var _translations$PLUGIN_12, _translations$PLUGIN_13;
|
||||
var _translations$PLUGIN_13, _translations$PLUGIN_14;
|
||||
if (operation === 'snapshot') {
|
||||
var _translations$PLUGIN_10, _translations$PLUGIN_11;
|
||||
var snapshotId = progress.snapshot || job.result && job.result.snapshot || _this5.job.snapshot || '';
|
||||
var snapshotLabel = snapshotId || ((_translations$PLUGIN_10 = external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN) === null || _translations$PLUGIN_10 === void 0 ? void 0 : _translations$PLUGIN_10.RESTORE_GRAV_TABLE_SNAPSHOT) || 'snapshot';
|
||||
var _successMessage = (_translations$PLUGIN_11 = external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN) !== null && _translations$PLUGIN_11 !== void 0 && _translations$PLUGIN_11.RESTORE_GRAV_SNAPSHOT_SUCCESS ? external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN.RESTORE_GRAV_SNAPSHOT_SUCCESS.replace('%s', snapshotLabel) : snapshotId ? "Snapshot ".concat(snapshotId, " created.") : 'Snapshot created.';
|
||||
var _snapshotId = progress.snapshot || job.result && job.result.snapshot || _this5.job.snapshot || '';
|
||||
var _labelValue = progress.label || job.result && job.result.label || _this5.job.label || '';
|
||||
var displayName = _labelValue || _snapshotId || ((_translations$PLUGIN_10 = external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN) === null || _translations$PLUGIN_10 === void 0 ? void 0 : _translations$PLUGIN_10.RESTORE_GRAV_TABLE_SNAPSHOT) || 'snapshot';
|
||||
if (_labelValue && _snapshotId && _labelValue !== _snapshotId) {
|
||||
displayName = "".concat(_labelValue, " (").concat(_snapshotId, ")");
|
||||
}
|
||||
var _successMessage = (_translations$PLUGIN_11 = external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN) !== null && _translations$PLUGIN_11 !== void 0 && _translations$PLUGIN_11.RESTORE_GRAV_SNAPSHOT_SUCCESS ? external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN.RESTORE_GRAV_SNAPSHOT_SUCCESS.replace('%s', displayName) : _snapshotId ? "Snapshot ".concat(displayName, " created.") : 'Snapshot created.';
|
||||
utils_toastr.success(_successMessage);
|
||||
_this5.job = null;
|
||||
_this5.clearPoll();
|
||||
@@ -11183,15 +11192,23 @@ var RestoreManager = /*#__PURE__*/function () {
|
||||
}, 1500);
|
||||
return;
|
||||
}
|
||||
var snapshot = progress.snapshot || _this5.job.snapshot;
|
||||
var snapshotId = progress.snapshot || _this5.job.snapshot || '';
|
||||
var labelValue = progress.label || job.result && job.result.label || _this5.job.label || '';
|
||||
var snapshotDisplay = snapshotId || labelValue;
|
||||
if (labelValue && snapshotId && labelValue !== snapshotId) {
|
||||
snapshotDisplay = "".concat(labelValue, " (").concat(snapshotId, ")");
|
||||
} else if (!snapshotDisplay) {
|
||||
var _translations$PLUGIN_12;
|
||||
snapshotDisplay = ((_translations$PLUGIN_12 = external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN) === null || _translations$PLUGIN_12 === void 0 ? void 0 : _translations$PLUGIN_12.RESTORE_GRAV_TABLE_SNAPSHOT) || 'snapshot';
|
||||
}
|
||||
var version = job.result && job.result.version || progress.version || '';
|
||||
var successMessage;
|
||||
if ((_translations$PLUGIN_12 = external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN) !== null && _translations$PLUGIN_12 !== void 0 && _translations$PLUGIN_12.RESTORE_GRAV_SUCCESS_MESSAGE && version) {
|
||||
successMessage = external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN.RESTORE_GRAV_SUCCESS_MESSAGE.replace('%1$s', snapshot).replace('%2$s', version);
|
||||
} else if ((_translations$PLUGIN_13 = external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN) !== null && _translations$PLUGIN_13 !== void 0 && _translations$PLUGIN_13.RESTORE_GRAV_SUCCESS_SIMPLE) {
|
||||
successMessage = external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN.RESTORE_GRAV_SUCCESS_SIMPLE.replace('%s', snapshot);
|
||||
if ((_translations$PLUGIN_13 = external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN) !== null && _translations$PLUGIN_13 !== void 0 && _translations$PLUGIN_13.RESTORE_GRAV_SUCCESS_MESSAGE && version) {
|
||||
successMessage = external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN.RESTORE_GRAV_SUCCESS_MESSAGE.replace('%1$s', snapshotDisplay).replace('%2$s', version);
|
||||
} else if ((_translations$PLUGIN_14 = external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN) !== null && _translations$PLUGIN_14 !== void 0 && _translations$PLUGIN_14.RESTORE_GRAV_SUCCESS_SIMPLE) {
|
||||
successMessage = external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN.RESTORE_GRAV_SUCCESS_SIMPLE.replace('%s', snapshotDisplay);
|
||||
} else {
|
||||
successMessage = version ? "Snapshot ".concat(snapshot, " restored (Grav ").concat(version, ").") : "Snapshot ".concat(snapshot, " restored.");
|
||||
successMessage = version ? "Snapshot ".concat(snapshotDisplay, " restored (Grav ").concat(version, ").") : "Snapshot ".concat(snapshotDisplay, " restored.");
|
||||
}
|
||||
utils_toastr.success(successMessage);
|
||||
_this5.job = null;
|
||||
@@ -11220,8 +11237,8 @@ var RestoreManager = /*#__PURE__*/function () {
|
||||
if (this.pollFailures >= 3) {
|
||||
var message;
|
||||
if (operation === 'snapshot') {
|
||||
var _translations$PLUGIN_14;
|
||||
message = ((_translations$PLUGIN_14 = external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN) === null || _translations$PLUGIN_14 === void 0 ? void 0 : _translations$PLUGIN_14.RESTORE_GRAV_SNAPSHOT_FALLBACK) || 'Snapshot creation may have completed. Reloading...';
|
||||
var _translations$PLUGIN_15;
|
||||
message = ((_translations$PLUGIN_15 = external_GravAdmin_namespaceObject.translations.PLUGIN_ADMIN) === null || _translations$PLUGIN_15 === void 0 ? void 0 : _translations$PLUGIN_15.RESTORE_GRAV_SNAPSHOT_FALLBACK) || 'Snapshot creation may have completed. Reloading...';
|
||||
} else {
|
||||
message = snapshot ? "Snapshot ".concat(snapshot, " restore is completing. Reloading...") : 'Snapshot restore is completing. Reloading...';
|
||||
}
|
||||
|
||||
@@ -36,7 +36,14 @@
|
||||
<td class="checkbox-cell">
|
||||
<input type="checkbox" name="snapshots[]" value="{{ snapshot.id }}" form="snapshot-delete-form" />
|
||||
</td>
|
||||
<td><code>{{ snapshot.id }}</code></td>
|
||||
<td>
|
||||
{% if snapshot.label %}
|
||||
<strong>{{ snapshot.label }}</strong><br>
|
||||
<code>{{ snapshot.id }}</code>
|
||||
{% else %}
|
||||
<code>{{ snapshot.id }}</code>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>{{ version ?: "PLUGIN_ADMIN.UNKNOWN"|t }}</td>
|
||||
<td>
|
||||
{% if snapshot.created_at %}
|
||||
|
||||
Reference in New Issue
Block a user