added task count
This commit is contained in:
123
StackMonkey.ps1
123
StackMonkey.ps1
@@ -895,32 +895,54 @@ async function triggerInstall() {
|
|||||||
const runBtn = document.querySelector('.run-button');
|
const runBtn = document.querySelector('.run-button');
|
||||||
runBtn.disabled = true;
|
runBtn.disabled = true;
|
||||||
|
|
||||||
|
const statusBox = document.getElementById('status-box');
|
||||||
|
statusBox.innerHTML = '';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
// Count how many tasks are checked
|
||||||
|
const taskCount = tasks.filter(t => {
|
||||||
|
const cb = document.getElementById(t.id);
|
||||||
|
return cb && cb.checked;
|
||||||
|
}).length;
|
||||||
|
setTotalTaskCount(taskCount);
|
||||||
|
|
||||||
// 1. Run DattoRMM first
|
// 1. Run DattoRMM first
|
||||||
const dattoCB = document.getElementById('installDattoRMM');
|
const dattoCB = document.getElementById('installDattoRMM');
|
||||||
if (dattoCB && dattoCB.checked) {
|
if (dattoCB && dattoCB.checked) {
|
||||||
const sub = Array.from(
|
try {
|
||||||
document.querySelectorAll('.sub-option-installDattoRMM:checked')
|
const sub = Array.from(
|
||||||
).map(x => x.value);
|
document.querySelectorAll('.sub-option-installDattoRMM:checked')
|
||||||
const dropdown = document.getElementById('dattoDropdown');
|
).map(x => x.value);
|
||||||
const uid = dropdown.value;
|
const dropdown = document.getElementById('dattoDropdown');
|
||||||
const name = dropdown.selectedOptions[0].text;
|
const uid = dropdown.value;
|
||||||
|
const name = dropdown.selectedOptions[0].text;
|
||||||
|
|
||||||
await fetch('/installDattoRMM', {
|
await fetch('/installDattoRMM', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
checkedValues: sub,
|
checkedValues: sub,
|
||||||
UID: uid,
|
UID: uid,
|
||||||
Name: name
|
Name: name
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
logProgress('Install DattoRMM', true);
|
||||||
|
} catch (e) {
|
||||||
|
logProgress('Install DattoRMM', false);
|
||||||
|
console.error(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. Run SVSMSP module install second
|
// 2. Run SVSMSP module install second
|
||||||
const svsCB = document.getElementById('installSVSMSPModule');
|
const svsCB = document.getElementById('installSVSMSPModule');
|
||||||
if (svsCB && svsCB.checked) {
|
if (svsCB && svsCB.checked) {
|
||||||
await fetch('/installSVSMSPModule', { method: 'GET' });
|
try {
|
||||||
|
await fetch('/installSVSMSPModule', { method: 'GET' });
|
||||||
|
logProgress('Install SVSMSP Module', true);
|
||||||
|
} catch (e) {
|
||||||
|
logProgress('Install SVSMSP Module', false);
|
||||||
|
console.error(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. Run the remaining tasks
|
// 3. Run the remaining tasks
|
||||||
@@ -930,7 +952,13 @@ async function triggerInstall() {
|
|||||||
const cb = document.getElementById(t.id);
|
const cb = document.getElementById(t.id);
|
||||||
if (!cb || !cb.checked) continue;
|
if (!cb || !cb.checked) continue;
|
||||||
|
|
||||||
await fetch(t.handler, { method: 'GET' });
|
try {
|
||||||
|
await fetch(t.handler, { method: 'GET' });
|
||||||
|
logProgress(t.label || t.id, true);
|
||||||
|
} catch (e) {
|
||||||
|
logProgress(t.label || t.id, false);
|
||||||
|
console.error(`Error running ${t.id}:`, e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Error during triggerInstall:', e);
|
console.error('Error during triggerInstall:', e);
|
||||||
@@ -940,7 +968,6 @@ async function triggerInstall() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// =======================================================================
|
// =======================================================================
|
||||||
// Shutdown Handler
|
// Shutdown Handler
|
||||||
// =======================================================================
|
// =======================================================================
|
||||||
@@ -1019,6 +1046,66 @@ window.addEventListener('beforeunload', () => {
|
|||||||
fetch('/quit', { method: 'GET', keepalive: true });
|
fetch('/quit', { method: 'GET', keepalive: true });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
<script>
|
||||||
|
let completedTasks = 0;
|
||||||
|
let totalTasks = 0;
|
||||||
|
|
||||||
|
function setTotalTaskCount(count) {
|
||||||
|
totalTasks = count;
|
||||||
|
completedTasks = 0;
|
||||||
|
updateTitle();
|
||||||
|
}
|
||||||
|
|
||||||
|
function logProgress(label, isSuccess) {
|
||||||
|
const statusBox = document.getElementById('status-box');
|
||||||
|
completedTasks++;
|
||||||
|
updateTitle();
|
||||||
|
|
||||||
|
const msg = isSuccess
|
||||||
|
? `✅ ${completedTasks}/${totalTasks} done: ${label}`
|
||||||
|
: `❌ ${completedTasks}/${totalTasks} failed: ${label}`;
|
||||||
|
|
||||||
|
const div = document.createElement('div');
|
||||||
|
div.style.color = isSuccess ? 'lime' : 'red';
|
||||||
|
div.textContent = msg;
|
||||||
|
statusBox.appendChild(div);
|
||||||
|
|
||||||
|
if (completedTasks === totalTasks) {
|
||||||
|
const finalMsg = document.createElement('div');
|
||||||
|
finalMsg.style.marginTop = '10px';
|
||||||
|
finalMsg.innerHTML = `<strong>✅ All tasks complete (${completedTasks}/${totalTasks})</strong>`;
|
||||||
|
statusBox.appendChild(finalMsg);
|
||||||
|
|
||||||
|
document.title = `✅ ScriptMonkey - Complete (${completedTasks}/${totalTasks})`;
|
||||||
|
|
||||||
|
// Optional: Play sound
|
||||||
|
const sound = new Audio('data:audio/wav;base64,UklGRiQAAABXQVZFZm10IBAAAAABAAEAESsAACJWAAACABAAZGF0YQAAAAA=');
|
||||||
|
sound.play().catch(() => {});
|
||||||
|
|
||||||
|
// Optional: Flash title
|
||||||
|
flashTitle(`✅ ScriptMonkey - Complete (${completedTasks}/${totalTasks})`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateTitle() {
|
||||||
|
document.title = `ScriptMonkey - ${completedTasks}/${totalTasks} Done`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function flashTitle(finalTitle) {
|
||||||
|
let flashes = 0;
|
||||||
|
const interval = setInterval(() => {
|
||||||
|
document.title = (document.title === '') ? finalTitle : '';
|
||||||
|
flashes++;
|
||||||
|
if (flashes >= 10) {
|
||||||
|
clearInterval(interval);
|
||||||
|
document.title = finalTitle;
|
||||||
|
}
|
||||||
|
}, 800);
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
'@
|
'@
|
||||||
|
|||||||
Reference in New Issue
Block a user