05/24 Fix bugs
This commit is contained in:
@@ -220,5 +220,29 @@ function buildShiftForm(s) {
|
||||
<textarea class="form-control" name="note" rows="2">${esc(s.note)}</textarea></div>`;
|
||||
}
|
||||
function esc(s) { return (s||'').replace(/&/g,'&').replace(/"/g,'"').replace(/</g,'<'); }
|
||||
|
||||
// Highlight today's column in the calendar
|
||||
(function() {
|
||||
var jsDay = new Date().getDay(); // 0=Sun … 6=Sat
|
||||
var mysqlDay = String(jsDay === 0 ? 1 : jsDay + 1); // MySQL DAYOFWEEK: 1=Sun, 2=Mon…
|
||||
var colIdx = DAY_MAP.findIndex(function(d) { return d[1] === mysqlDay; });
|
||||
if (colIdx === -1) return;
|
||||
var calTable = document.querySelector('#tab-calendar table');
|
||||
if (!calTable) return;
|
||||
calTable.querySelectorAll('tr').forEach(function(tr) {
|
||||
var cells = tr.querySelectorAll('th, td');
|
||||
var cell = cells[colIdx + 1]; // +1 for the leading Shift name column
|
||||
if (cell) cell.classList.add('cal-today');
|
||||
});
|
||||
})();
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.cal-today { background: #eff6ff !important; }
|
||||
.cal-today th, thead .cal-today {
|
||||
background: #dbeafe !important;
|
||||
font-weight: 700;
|
||||
color: #1d4ed8;
|
||||
}
|
||||
</style>
|
||||
{% endblock %}
|
||||
|
||||
@@ -233,9 +233,11 @@
|
||||
<div id="hist-verdict-banner" style="display:none"></div>
|
||||
<div class="modal-body" style="padding:0">
|
||||
<div class="ai-meta-bar" id="hist-meta"></div>
|
||||
<div id="hist-body" class="ai-rendered-output" style="max-height:65vh;overflow-y:auto;padding:1.25rem 1.5rem"></div>
|
||||
<div id="hist-criteria" style="display:none;padding:.6rem 1.5rem;font-size:.78rem;background:var(--bg-subtle);border-bottom:1px solid var(--border)"></div>
|
||||
<div id="hist-body" class="ai-rendered-output" style="max-height:60vh;overflow-y:auto;padding:1.25rem 1.5rem"></div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button class="btn btn-danger btn-sm" id="btn-delete-analysis" style="margin-right:auto;display:none" onclick="deleteAnalysis()">🗑 Delete</button>
|
||||
<button class="btn btn-secondary" onclick="closeModal('modal-history')">Close</button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -407,13 +409,18 @@ document.querySelectorAll('.js-edit-criterion').forEach(function(btn) {
|
||||
});
|
||||
|
||||
/* ─── History rows ──────────────────────────────────────────── */
|
||||
var _currentAnalysisId = null;
|
||||
|
||||
document.querySelectorAll('.history-row').forEach(function(row) {
|
||||
row.addEventListener('click', function() {
|
||||
var id = row.dataset.id;
|
||||
_currentAnalysisId = id;
|
||||
document.getElementById('hist-title').textContent = 'Loading…';
|
||||
document.getElementById('hist-meta').textContent = '';
|
||||
document.getElementById('hist-body').innerHTML = '';
|
||||
document.getElementById('hist-criteria').style.display = 'none';
|
||||
document.getElementById('hist-verdict-banner').style.display = 'none';
|
||||
document.getElementById('btn-delete-analysis').style.display = 'none';
|
||||
openModal('modal-history');
|
||||
|
||||
fetch('/ai-summary/history/' + id)
|
||||
@@ -435,8 +442,23 @@ document.querySelectorAll('.history-row').forEach(function(row) {
|
||||
vb.innerHTML = verdictBannerHTML(d.verdict);
|
||||
vb.style.display = '';
|
||||
}
|
||||
|
||||
// Criteria snapshot
|
||||
var criteriaEl = document.getElementById('hist-criteria');
|
||||
if (d.criteria_snapshot) {
|
||||
try {
|
||||
var snap = JSON.parse(d.criteria_snapshot);
|
||||
if (snap && snap.length) {
|
||||
var labels = snap.map(function(c) { return c.title; }).join(' · ');
|
||||
criteriaEl.innerHTML = '<strong style="color:var(--text)">Criteria used:</strong> ' + escHtml(labels);
|
||||
criteriaEl.style.display = '';
|
||||
}
|
||||
} catch(e) { /* ignore malformed snapshot */ }
|
||||
}
|
||||
|
||||
document.getElementById('hist-body').innerHTML =
|
||||
renderAI(d.summary_text || '');
|
||||
document.getElementById('btn-delete-analysis').style.display = '';
|
||||
})
|
||||
.catch(function() {
|
||||
document.getElementById('hist-body').textContent = 'Failed to load analysis.';
|
||||
@@ -444,6 +466,24 @@ document.querySelectorAll('.history-row').forEach(function(row) {
|
||||
});
|
||||
});
|
||||
|
||||
function deleteAnalysis() {
|
||||
if (!_currentAnalysisId) return;
|
||||
if (!confirm('Delete this analysis? This cannot be undone.')) return;
|
||||
fetch('/ai-summary/history/' + _currentAnalysisId + '/delete', {
|
||||
method: 'POST',
|
||||
headers: { 'X-CSRFToken': getCsrfToken() },
|
||||
}).then(function(r) { return r.json(); })
|
||||
.then(function(d) {
|
||||
if (d.error) { alert(d.error); return; }
|
||||
closeModal('modal-history');
|
||||
// Remove the row from the table
|
||||
var row = document.querySelector('.history-row[data-id="' + _currentAnalysisId + '"]');
|
||||
if (row) row.remove();
|
||||
_currentAnalysisId = null;
|
||||
})
|
||||
.catch(function() { alert('Delete failed. Please try again.'); });
|
||||
}
|
||||
|
||||
/* ─── Utility ───────────────────────────────────────────────── */
|
||||
function escHtml(str) {
|
||||
return String(str || '').replace(/[&<>"']/g, function(c) {
|
||||
|
||||
Reference in New Issue
Block a user