fix(revisions): connect safe restore UI and readable change history
This commit is contained in:
1 parent
2cbaa9342d
commit
96065d1e89
11 files changed
+166
-96
No files matched your search
+6
-1
@@ -252,6 +252,10 @@ window.PagesEditor = {
|
||||
if (this.saving) return false
|
||||
if (!this.dirty) return !this.paused
|
||||
if (!manual && this.paused) return false
|
||||
const messageField=document.getElementById('revision-message')
|
||||
const changeMessage=messageField?.value.trim()||''
|
||||
// A supplied message belongs to the next explicit save, not autosave.
|
||||
if (!manual && changeMessage) return false
|
||||
if (manual) this.mergeAttempts=0
|
||||
this.persist()
|
||||
this.saving = true
|
||||
@@ -261,11 +265,12 @@ window.PagesEditor = {
|
||||
try {
|
||||
body = await this.canonical(text,format)
|
||||
const data = await this.post('/_/api/v1/revisions/save',{
|
||||
object_uuid:this.value('object-uuid'),body,message:manual?'manual-save':'autosave',
|
||||
object_uuid:this.value('object-uuid'),body,message:manual?(changeMessage||'manual-save'):'autosave',
|
||||
lang:this.value('page-language')||'und',content_type:this.value('page-content-type'),filename:this.value('page-filename'),
|
||||
base_revision_uuid:this.baseRevision,editor_principal_uuid:this.owner,
|
||||
})
|
||||
if (!data.revision_uuid) throw {kind:'failed'}
|
||||
if (manual && messageField?.value.trim()===changeMessage) messageField.value=''
|
||||
this.baseRevision = data.revision_uuid
|
||||
this.baseBody = typeof data.body==='string' ? data.body : body
|
||||
this.initialText = text; this.initialFormat = format
|
||||
|
||||
+20
-44
@@ -1,44 +1,20 @@
|
||||
console.log("revisions.js loaded")
|
||||
|
||||
async function restoreRevision(
|
||||
revisionUUID,
|
||||
) {
|
||||
|
||||
if (
|
||||
!confirm(
|
||||
"restore revision?"
|
||||
)
|
||||
) {
|
||||
return
|
||||
}
|
||||
|
||||
const res = await fetch(
|
||||
"/_/api/v1/revisions/restore",
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type":
|
||||
"application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
revision_uuid:
|
||||
revisionUUID,
|
||||
}),
|
||||
},
|
||||
)
|
||||
|
||||
if (!res.ok) {
|
||||
|
||||
alert(
|
||||
"restore failed",
|
||||
)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
alert(
|
||||
"revision restored",
|
||||
)
|
||||
|
||||
location.reload()
|
||||
}
|
||||
(() => {
|
||||
'use strict';
|
||||
const ja=document.documentElement.lang.startsWith('ja'),t=(en,jp)=>ja?jp:en;
|
||||
for(const node of document.querySelectorAll('[data-revision-time]')){
|
||||
const date=new Date(Number(node.dataset.revisionTime)*1000);
|
||||
if(!Number.isNaN(date.valueOf())){node.dateTime=date.toISOString();node.textContent=date.toLocaleString(undefined,{year:'numeric',month:'2-digit',day:'2-digit',hour:'2-digit',minute:'2-digit',second:'2-digit',timeZoneName:'short'});node.title=date.toISOString();}
|
||||
}
|
||||
let busy=false;
|
||||
document.addEventListener('click',async event=>{
|
||||
const button=event.target.closest('[data-restore-revision]');if(!button||busy)return;
|
||||
const message=prompt(t('Restore as a new revision. Enter a change message:','新しいリビジョンとして復元します。更新メッセージを入力してください。'),t('Restore revision ','リビジョンを復元: ')+button.dataset.restoreRevision);
|
||||
if(message===null)return;
|
||||
busy=true;button.disabled=true;
|
||||
try{
|
||||
const response=await fetch('/_/api/v1/revisions/restore',{method:'POST',credentials:'same-origin',headers:{'Content-Type':'application/json'},body:JSON.stringify({revision_uuid:button.dataset.restoreRevision,base_revision_uuid:button.dataset.baseRevision,message}),signal:AbortSignal.timeout(30000)});
|
||||
if(response.redirected||!response.ok)throw Error(response.status===412?t('Changed elsewhere. Reload history before restoring.','別の画面で更新されました。履歴を再読み込みしてから復元してください。'):t('Restore failed. Check your login and permissions.','復元できませんでした。ログイン状態と権限を確認してください。'));
|
||||
location.reload();
|
||||
}catch(error){alert(error.message);}finally{busy=false;button.disabled=false;}
|
||||
});
|
||||
})();
|
||||
Reference in new issue
Block a user