second attempt at adding the task count let set
This commit is contained in:
122
StackMonkey.ps1
122
StackMonkey.ps1
@@ -747,6 +747,62 @@ $style = @'
|
||||
# no spaces before $script
|
||||
$script = @'
|
||||
<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})`;
|
||||
|
||||
const sound = new Audio('data:audio/wav;base64,UklGRiQAAABXQVZFZm10IBAAAAABAAEAESsAACJWAAACABAAZGF0YQAAAAA=');
|
||||
sound.play().catch(() => {});
|
||||
flashTitle(document.title);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// =======================================================================
|
||||
// Tab Navigation
|
||||
// =======================================================================
|
||||
@@ -895,45 +951,69 @@ async function triggerInstall() {
|
||||
const runBtn = document.querySelector('.run-button');
|
||||
runBtn.disabled = true;
|
||||
|
||||
const statusBox = document.getElementById('status-box');
|
||||
if (statusBox) statusBox.innerHTML = '';
|
||||
|
||||
try {
|
||||
// Figure out how many total tasks are selected
|
||||
const checkedTasks = tasks.filter(t => {
|
||||
const cb = document.getElementById(t.id);
|
||||
return cb && cb.checked;
|
||||
});
|
||||
setTotalTaskCount(checkedTasks.length);
|
||||
|
||||
// 1. Run DattoRMM first
|
||||
const dattoCB = document.getElementById('installDattoRMM');
|
||||
if (dattoCB && dattoCB.checked) {
|
||||
const sub = Array.from(
|
||||
document.querySelectorAll('.sub-option-installDattoRMM:checked')
|
||||
).map(x => x.value);
|
||||
const dropdown = document.getElementById('dattoDropdown');
|
||||
const uid = dropdown.value;
|
||||
const name = dropdown.selectedOptions[0].text;
|
||||
try {
|
||||
const sub = Array.from(
|
||||
document.querySelectorAll('.sub-option-installDattoRMM:checked')
|
||||
).map(x => x.value);
|
||||
const dropdown = document.getElementById('dattoDropdown');
|
||||
const uid = dropdown?.value;
|
||||
const name = dropdown?.selectedOptions?.[0]?.text || 'Datto';
|
||||
|
||||
await fetch('/installDattoRMM', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
checkedValues: sub,
|
||||
UID: uid,
|
||||
Name: name
|
||||
})
|
||||
});
|
||||
await fetch('/installDattoRMM', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ checkedValues: sub, UID: uid, Name: name })
|
||||
});
|
||||
logProgress('Install DattoRMM', true);
|
||||
} catch (e) {
|
||||
logProgress('Install DattoRMM', false);
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
// 2. Run SVSMSP module install second
|
||||
// 2. Run SVSMSP second
|
||||
const svsCB = document.getElementById('installSVSMSPModule');
|
||||
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. Remaining tasks
|
||||
for (const t of tasks) {
|
||||
if (['installDattoRMM', 'installSVSMSPModule'].includes(t.id)) continue;
|
||||
|
||||
const cb = document.getElementById(t.id);
|
||||
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) {
|
||||
console.error('Error during triggerInstall:', e);
|
||||
console.error('triggerInstall fatal error:', e);
|
||||
} finally {
|
||||
runBtn.disabled = false;
|
||||
}
|
||||
@@ -1127,6 +1207,8 @@ $script
|
||||
<button class="exit-button" onclick="endSession()">Exit</button>
|
||||
<button class="run-button" onclick="triggerInstall()">Run Selected</button>
|
||||
</div>
|
||||
<div id="status-box" style="margin-top: 1em; font-family: monospace;"></div>
|
||||
|
||||
|
||||
|
||||
</body>
|
||||
|
||||
Reference in New Issue
Block a user