mirror of
https://github.com/Terranom674/Piwigo_Bratonien_Tools.git
synced 2026-09-20 01:44:31 +00:00
Keep connector status polling from reloading admin page
This commit is contained in:
@@ -52,6 +52,12 @@
|
|||||||
|
|
||||||
function token(){var input=section.querySelector('input[name="pwg_token"]');return input?input.value:'';}
|
function token(){var input=section.querySelector('input[name="pwg_token"]');return input?input.value:'';}
|
||||||
function setOpen(value){try{if(value)sessionStorage.setItem(storageKey,'1');else sessionStorage.removeItem(storageKey);}catch(e){}}
|
function setOpen(value){try{if(value)sessionStorage.setItem(storageKey,'1');else sessionStorage.removeItem(storageKey);}catch(e){}}
|
||||||
|
function showWizard(){
|
||||||
|
setOpen(true);
|
||||||
|
if(!dialog)return;
|
||||||
|
if(typeof dialog.showModal==='function'&&!dialog.open)dialog.showModal();
|
||||||
|
else dialog.setAttribute('open','open');
|
||||||
|
}
|
||||||
function resetServer(){
|
function resetServer(){
|
||||||
var pwgToken=token();
|
var pwgToken=token();
|
||||||
if(!pwgToken)return Promise.reject(new Error('CSRF token missing'));
|
if(!pwgToken)return Promise.reject(new Error('CSRF token missing'));
|
||||||
@@ -65,8 +71,7 @@
|
|||||||
|
|
||||||
if(openButton){
|
if(openButton){
|
||||||
openButton.addEventListener('click',function(event){
|
openButton.addEventListener('click',function(event){
|
||||||
if(resetBusy)return;event.preventDefault();event.stopImmediatePropagation();resetBusy=true;setOpen(true);
|
event.preventDefault();event.stopImmediatePropagation();showWizard();
|
||||||
resetServer().then(function(){window.location.reload();}).catch(function(){setOpen(false);resetBusy=false;});
|
|
||||||
},true);
|
},true);
|
||||||
}
|
}
|
||||||
if(closeButton){
|
if(closeButton){
|
||||||
@@ -75,12 +80,14 @@
|
|||||||
if(dialog){
|
if(dialog){
|
||||||
dialog.addEventListener('cancel',function(event){event.preventDefault();event.stopImmediatePropagation();closeAfterReset();},true);
|
dialog.addEventListener('cancel',function(event){event.preventDefault();event.stopImmediatePropagation();closeAfterReset();},true);
|
||||||
dialog.addEventListener('click',function(event){if(event.target===dialog){event.preventDefault();event.stopImmediatePropagation();closeAfterReset();}},true);
|
dialog.addEventListener('click',function(event){if(event.target===dialog){event.preventDefault();event.stopImmediatePropagation();closeAfterReset();}},true);
|
||||||
|
try{if(sessionStorage.getItem(storageKey)==='1')showWizard();}catch(e){}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function initNCConnectorPolling(){
|
function initNCConnectorPolling(){
|
||||||
var section=document.getElementById('nc-connector');if(!section)return;
|
var section=document.getElementById('nc-connector');if(!section)return;
|
||||||
var endpoint='plugins/bratonien_tools/nc-connector-status.php';
|
var endpoint='plugins/bratonien_tools/nc-connector-status.php';
|
||||||
|
var pollTimer=null;
|
||||||
|
|
||||||
function valueNodeForLabel(labelText){
|
function valueNodeForLabel(labelText){
|
||||||
var labels=[].slice.call(section.querySelectorAll('.bratonien-label'));
|
var labels=[].slice.call(section.querySelectorAll('.bratonien-label'));
|
||||||
@@ -108,18 +115,25 @@
|
|||||||
var nextRunNode=valueNodeForLabel('Nächster Lauf');
|
var nextRunNode=valueNodeForLabel('Nächster Lauf');
|
||||||
var lastResultNode=lastResultValueNode();
|
var lastResultNode=lastResultValueNode();
|
||||||
|
|
||||||
|
function render(data){
|
||||||
|
if(lastRunNode&&typeof data.last_run_label==='string'&&data.last_run_label!=='')lastRunNode.textContent=data.last_run_label;
|
||||||
|
if(nextRunNode&&typeof data.next_run_label==='string'&&data.next_run_label!=='')nextRunNode.textContent=data.next_run_label;
|
||||||
|
if(lastResultNode&&typeof data.message==='string'&&data.message!=='')lastResultNode.textContent=data.message;
|
||||||
|
}
|
||||||
|
|
||||||
function poll(){
|
function poll(){
|
||||||
fetch(endpoint+'?_='+Date.now(),{credentials:'same-origin',cache:'no-store'})
|
fetch(endpoint+'?_='+Date.now(),{credentials:'same-origin',cache:'no-store',headers:{'Accept':'application/json'}})
|
||||||
.then(function(response){if(!response.ok)throw new Error('HTTP '+response.status);return response.json();})
|
.then(function(response){if(!response.ok)throw new Error('HTTP '+response.status);return response.json();})
|
||||||
.then(function(data){
|
.then(render)
|
||||||
if(lastRunNode&&data.last_run_label)lastRunNode.textContent=data.last_run_label;
|
|
||||||
if(nextRunNode&&data.next_run_label)nextRunNode.textContent=data.next_run_label;
|
|
||||||
if(lastResultNode&&typeof data.message==='string'&&data.message!=='')lastResultNode.textContent=data.message;
|
|
||||||
})
|
|
||||||
.catch(function(){});
|
.catch(function(){});
|
||||||
}
|
}
|
||||||
|
|
||||||
poll();window.setInterval(poll,5000);
|
function schedule(){
|
||||||
|
if(pollTimer)window.clearInterval(pollTimer);
|
||||||
|
pollTimer=window.setInterval(poll,5000);
|
||||||
|
}
|
||||||
|
|
||||||
|
poll();schedule();
|
||||||
}
|
}
|
||||||
|
|
||||||
function initAll(){initBratonienTabs();initNCWizardLifecycle();initNCConnectorPolling();}
|
function initAll(){initBratonienTabs();initNCWizardLifecycle();initNCConnectorPolling();}
|
||||||
|
|||||||
Reference in New Issue
Block a user