bmc_hub/patch_bb_chat2.py
Christian ceb560e2f2 feat: Add bottom bar functionality with real-time updates and manual endpoint tests
- Implemented a new bottom bar feature in `bottom-bar.js` that fetches and displays various notifications and statuses in real-time.
- Added functions for handling visibility, state updates, and user interactions within the bottom bar.
- Introduced WebSocket connection for real-time updates and fallback polling mechanism.
- Created a manual testing script `test_manual.py` to validate API endpoints for the manual module.
- Included tests for various paths to ensure expected responses from the server.
2026-04-12 02:27:01 +02:00

60 lines
2.9 KiB
Python

import re
with open("static/js/bottom-bar.js", "r") as f:
text = f.read()
events_html = """
if (btn.id === 'btnNextTask') {
console.log("-> Beder backend om næste opgave...");
btn.innerHTML = '<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span> Omsætter kalender og SLA...';
btn.disabled = true;
fetch('/api/v1/bottom-bar/next_task', { method: 'POST' })
.then(r => r.json())
.then(data => {
const task = data.task;
btn.innerHTML = '<i class="bi bi-magic me-2"></i>Du fik tildelt: ' + task.title + ' (Sag #' + task.case_id + ') <span class="badge bg-light text-dark ms-2">' + data.free_time_calculated + 'm fri</span>';
btn.classList.add('btn-success');
btn.classList.remove('btn-primary');
})
.catch(err => {
console.error("Fejl:", err);
btn.innerHTML = "Fejl - prøv igen";
btn.disabled = false;
});
}
if (btn.id === 'btnSendMsg') {
const input = document.getElementById('chatInputQuick');
const recipientObj = document.getElementById('chatRecipient');
if (input && input.value.trim() !== '') {
const recipient = recipientObj ? recipientObj.options[recipientObj.selectedIndex].text : 'Alle';
console.log("-> Sender besked til", recipient, ":", input.value);
const msgVal = input.value;
input.value = '';
const msgContainer = document.createElement('div');
msgContainer.className = 'mb-2 text-end';
msgContainer.innerHTML = '<div class="small text-muted mb-1 me-1" style="font-size:0.7rem;">Til: ' + recipient + '</div><div class="d-inline-block bg-primary text-white p-2 rounded-3 text-start shadow-sm" style="max-width: 85%;"><strong>Mig:</strong> ' + msgVal + '</div>';
const listUl = listContainer.querySelector('ul') || listContainer;
listUl.appendChild(msgContainer);
// Simple hacky scroll down
const tabInner = document.getElementById('bbTabInnerContent');
if(tabInner) {
tabInner.scrollTop = tabInner.scrollHeight + 500;
}
}
}
"""
pattern = r" if \(btn\.id === 'btnNextTask'\) \{.*?\n \}"
text = re.sub(pattern, events_html.strip(), text, flags=re.DOTALL)
with open("static/js/bottom-bar.js", "w") as f:
f.write(text)