2022-04-13 15:32:59 +02:00
|
|
|
const bootstrap = require('bootstrap');
|
|
|
|
const image = require('../../images/ajax-loader.gif');
|
2021-05-26 16:26:01 +02:00
|
|
|
|
2021-07-30 14:04:42 +02:00
|
|
|
document.addEventListener("readystatechange", event => {
|
|
|
|
if(event.target.readyState === 'complete') {
|
|
|
|
initDeleteButtons();
|
|
|
|
initRunNowButtons();
|
2022-02-01 14:29:19 +01:00
|
|
|
initTags();
|
2021-07-30 14:04:42 +02:00
|
|
|
}
|
|
|
|
});
|
2021-05-24 14:08:30 +02:00
|
|
|
|
2022-02-01 14:29:19 +01:00
|
|
|
function initTags() {
|
|
|
|
document.querySelectorAll('.tag').forEach(elem => {
|
|
|
|
let backcolor = elem.dataset.backgroundColor;
|
|
|
|
let frontcolor = elem.dataset.color;
|
|
|
|
elem.style.backgroundColor = backcolor;
|
|
|
|
elem.style.color = frontcolor;
|
|
|
|
})
|
|
|
|
}
|
2021-05-24 14:08:30 +02:00
|
|
|
function initDeleteButtons() {
|
2021-07-30 14:04:42 +02:00
|
|
|
document.querySelectorAll('.delete-btn').forEach(elem => elem.addEventListener("click", event => {
|
|
|
|
let me = event.currentTarget;
|
|
|
|
let href = me.dataset.href;
|
|
|
|
let confirmation = me.dataset.confirmation;
|
2021-05-24 14:08:30 +02:00
|
|
|
|
|
|
|
if(confirm(confirmation)) {
|
2021-07-30 14:04:42 +02:00
|
|
|
fetch(href, { method: 'DELETE' })
|
|
|
|
.then(response => response.json())
|
|
|
|
.then(data => {
|
|
|
|
window.location.href = data.return_path
|
2021-05-24 14:08:30 +02:00
|
|
|
})
|
|
|
|
}
|
2021-07-30 14:04:42 +02:00
|
|
|
}));
|
2021-06-01 20:21:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function initRunNowButtons() {
|
2021-07-30 14:04:42 +02:00
|
|
|
document.querySelectorAll('.runnow').forEach(elem => elem.addEventListener("click", event => {
|
|
|
|
let me = event.currentTarget;
|
|
|
|
let href = me.dataset.href;
|
2021-07-30 14:35:47 +02:00
|
|
|
|
2021-08-02 13:57:36 +02:00
|
|
|
let runnowCnt = document.querySelector('.runnow-content');
|
|
|
|
if(runnowCnt.querySelector('img') === null) {
|
|
|
|
let loaderImg = document.createElement('img');
|
2022-04-13 15:32:59 +02:00
|
|
|
loaderImg.src = image;
|
2021-08-02 13:57:36 +02:00
|
|
|
runnowCnt.appendChild(loaderImg);
|
|
|
|
}
|
2021-07-30 14:35:47 +02:00
|
|
|
document.querySelector('.container-fluid').classList.add('blur');
|
|
|
|
document.querySelector('.runnow-overlay').classList.add('d-block');
|
|
|
|
document.querySelector('.runnow-overlay').classList.remove('d-none');
|
|
|
|
|
2021-07-30 14:04:42 +02:00
|
|
|
fetch(href, { method: 'GET' })
|
|
|
|
.then(response => response.json())
|
|
|
|
.then(data => {
|
|
|
|
let modal = document.querySelector('#runnow_result');
|
|
|
|
modal.querySelector('.modal-title').innerHTML = data.title;
|
2021-06-01 20:21:47 +02:00
|
|
|
if (data.status == 'deferred') {
|
2021-07-30 14:04:42 +02:00
|
|
|
modal.querySelector('.modal-body').innerHTML = data.message;
|
|
|
|
me.classList.add('disabled');
|
|
|
|
let td = me.closest('td');
|
|
|
|
td.querySelectorAll('.btn').forEach(btn => {
|
|
|
|
btn.classList.add('btn-outline-success');
|
|
|
|
btn.classList.remove('btn-outline-primary');
|
|
|
|
btn.classList.remove('btn-outline-danger');
|
2021-07-14 13:46:56 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
|
2021-07-30 14:04:42 +02:00
|
|
|
let tr = me.closest('tr');
|
|
|
|
tr.classList.add('running');
|
|
|
|
tr.classList.add('text-success');
|
|
|
|
tr.classList.remove('norun');
|
|
|
|
tr.classList.remove('text-danger');
|
2021-06-01 20:21:47 +02:00
|
|
|
} else if (data.status == 'ran') {
|
2021-07-02 21:03:21 +02:00
|
|
|
let content = '<p>Cronjob ran in ' + data.runtime.toFixed(3) + ' seconds with exit code ' + data.exitcode +'</p>'
|
2021-06-01 20:21:47 +02:00
|
|
|
content += '<pre>' + data.output + '</pre>'
|
|
|
|
|
2021-07-30 14:04:42 +02:00
|
|
|
modal.querySelector('.modal-body').innerHTML = content;
|
2021-06-01 20:21:47 +02:00
|
|
|
}
|
|
|
|
|
2022-04-13 15:32:59 +02:00
|
|
|
var bsModal = new bootstrap.Modal('#runnow_result').show();
|
2021-07-30 14:35:47 +02:00
|
|
|
|
|
|
|
document.querySelector('.container-fluid').classList.remove('blur');
|
|
|
|
document.querySelector('.runnow-overlay').classList.remove('d-block');
|
|
|
|
document.querySelector('.runnow-overlay').classList.add('d-none');
|
2021-07-30 14:04:42 +02:00
|
|
|
})
|
2021-06-01 20:21:47 +02:00
|
|
|
})
|
2021-07-30 14:04:42 +02:00
|
|
|
)
|
2021-05-24 14:08:30 +02:00
|
|
|
}
|