Add feature to restore script content to a specific version on history page
This commit is contained in:
@@ -74,10 +74,12 @@ const FunctionHistory = {
|
||||
m(".flex-1.p-4.bg-white.dark:bg-gray-900", [
|
||||
mode === "view"
|
||||
? m("div", [
|
||||
m(
|
||||
"h3.text-lg.font-semibold.mb-2",
|
||||
`Version ${selectedVersion.version_number}`
|
||||
),
|
||||
m("div.flex.justify-between.items-center.mb-2", [
|
||||
m("h3.text-lg.font-semibold", `Version ${selectedVersion.version_number}`),
|
||||
m("button.bg-blue-500.hover:bg-blue-600.text-white.px-3.py-1.rounded.text-sm", {
|
||||
onclick: () => FunctionHistory.restoreVersion(vnode)
|
||||
}, "Restore this Version")
|
||||
]),
|
||||
m("div#editor-history", { style: "height: 600px;" }),
|
||||
])
|
||||
: m("div", [
|
||||
@@ -175,6 +177,33 @@ const FunctionHistory = {
|
||||
}
|
||||
},
|
||||
|
||||
restoreVersion: async function (vnode) {
|
||||
const { selectedVersion } = vnode.state;
|
||||
const { restore_url } = vnode.attrs;
|
||||
|
||||
if (!confirm(`Are you sure you want to restore version ${selectedVersion.version_number}? This will create a new version with this content.`)) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await m.request({
|
||||
method: "POST",
|
||||
url: restore_url,
|
||||
body: { version_number: selectedVersion.version_number }
|
||||
});
|
||||
|
||||
if (response.status === "success") {
|
||||
Alert.show(response.message, "success");
|
||||
// Reload the page to show the new version
|
||||
window.location.reload();
|
||||
} else {
|
||||
Alert.show(response.message || "Error restoring version", "error");
|
||||
}
|
||||
} catch (err) {
|
||||
Alert.show(err.message || "Error restoring version", "error");
|
||||
}
|
||||
},
|
||||
|
||||
onremove: function (vnode) {
|
||||
if (vnode.state.editor) {
|
||||
vnode.state.editor.destroy();
|
||||
|
||||
Reference in New Issue
Block a user