Update teacher profiles and record summaries
This commit is contained in:
+44
-7
@@ -37,6 +37,7 @@ let currentRecords = [];
|
||||
let recordSort = { date: "asc", time: "asc" };
|
||||
let currentRecordOrder = [];
|
||||
let correctedRecords = new Map();
|
||||
let expandedSummaryRecords = new Set();
|
||||
let activeCorrectionKey = "";
|
||||
let activeDeleteKey = "";
|
||||
|
||||
@@ -63,7 +64,7 @@ function metric(label, value) {
|
||||
}
|
||||
|
||||
function makeRecordKey(row, index) {
|
||||
return JSON.stringify([index, row.date, row.time, row.student, row.duration, row.teacher, row.subject]);
|
||||
return row.record_id || JSON.stringify([index, row.date, row.time, row.student, row.duration, row.teacher, row.subject]);
|
||||
}
|
||||
|
||||
function buildRecordLine(row) {
|
||||
@@ -182,6 +183,8 @@ function renderRecordRow(row) {
|
||||
const correctedClass = corrected ? " corrected-row" : "";
|
||||
const actionLabel = corrected ? "编辑" : "纠错";
|
||||
const badge = corrected ? '<span class="correction-badge">已修改</span>' : "";
|
||||
const summaryCount = Number(displayRow.summary_count || 0);
|
||||
const summaryExpanded = expandedSummaryRecords.has(key);
|
||||
return `<tr class="record-row${correctedClass}">
|
||||
<td>${escapeHtml(displayRow.date)} ${escapeHtml(displayRow.weekday)}</td>
|
||||
<td>${escapeHtml(displayRow.time)}</td>
|
||||
@@ -191,6 +194,7 @@ function renderRecordRow(row) {
|
||||
<td class="num">${escapeHtml(displayRow.duration)}</td>
|
||||
<td class="record-action-cell">
|
||||
<div class="record-actions">
|
||||
<button class="small-button summary-toggle" type="button" data-record-key="${escapeHtml(key)}" ${summaryCount > 0 ? "" : "disabled"}>${summaryExpanded ? "收起小结" : "课程小结"}</button>
|
||||
<button class="small-button correction-edit" type="button" data-record-key="${escapeHtml(key)}">${actionLabel}</button>
|
||||
<button class="small-button record-delete" type="button" data-record-key="${escapeHtml(key)}">删除</button>
|
||||
${badge}
|
||||
@@ -199,6 +203,15 @@ function renderRecordRow(row) {
|
||||
</tr>`;
|
||||
}
|
||||
|
||||
function renderSummaryEntry(summary) {
|
||||
const title = summary.title || "课程小结";
|
||||
const time = summary.time_range ? ` · ${summary.time_range}` : "";
|
||||
return `<div class="record-summary-item">
|
||||
<div class="record-summary-title">${escapeHtml(title)}${escapeHtml(time)}</div>
|
||||
<div class="summary-body">${escapeHtml(summary.body || "暂无正文")}</div>
|
||||
</div>`;
|
||||
}
|
||||
|
||||
function renderGroupedRecords(records) {
|
||||
currentRecordOrder = [];
|
||||
return groupRecordsByTeacher(records)
|
||||
@@ -213,13 +226,28 @@ function renderGroupedRecords(records) {
|
||||
</tr>${sortRecordsForDisplay(group.records)
|
||||
.map((row) => {
|
||||
currentRecordOrder.push(row._recordKey);
|
||||
return renderRecordRow(row);
|
||||
const summaryCount = Number(row.summary_count || 0);
|
||||
const summaryRow = summaryCount
|
||||
? `<tr class="summary-collapse-row" data-summary-row="${escapeHtml(row._recordKey)}" ${expandedSummaryRecords.has(row._recordKey) ? "" : "hidden"}>
|
||||
<td colspan="7">${(row.summaries || []).map(renderSummaryEntry).join("")}</td>
|
||||
</tr>`
|
||||
: "";
|
||||
return `${renderRecordRow(row)}${summaryRow}`;
|
||||
})
|
||||
.join("")}`,
|
||||
)
|
||||
.join("");
|
||||
}
|
||||
|
||||
function toggleSummaryRow(key) {
|
||||
if (expandedSummaryRecords.has(key)) {
|
||||
expandedSummaryRecords.delete(key);
|
||||
} else {
|
||||
expandedSummaryRecords.add(key);
|
||||
}
|
||||
renderCurrentRecords();
|
||||
}
|
||||
|
||||
function statusClass(status) {
|
||||
if (status === "欠费") return "debt";
|
||||
if (status === "预警") return "warning";
|
||||
@@ -279,6 +307,7 @@ function updateCorrectionToolbar(message = "", isError = false) {
|
||||
function resetCorrections() {
|
||||
correctedRecords = new Map();
|
||||
currentRecordOrder = [];
|
||||
expandedSummaryRecords = new Set();
|
||||
activeCorrectionKey = "";
|
||||
updateCorrectionToolbar();
|
||||
}
|
||||
@@ -421,7 +450,7 @@ async function submitDeleteRecord() {
|
||||
const data = await fetchJson("/api/deletions", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ items: [{ original_line: buildRecordLine(original) }] }),
|
||||
body: JSON.stringify({ items: [{ record_id: original.record_id }] }),
|
||||
});
|
||||
closeDeleteDialog();
|
||||
updateCorrectionToolbar(`已提交 ${data.submitted} 条删除审核`);
|
||||
@@ -488,12 +517,15 @@ async function copyCorrectedRecords() {
|
||||
async function submitCorrectedRecords() {
|
||||
const items = currentRecordOrder
|
||||
.map((key) => {
|
||||
const original = findCurrentRecord(key);
|
||||
const corrected = correctedRecords.get(key);
|
||||
if (!original || !corrected) return null;
|
||||
if (!corrected) return null;
|
||||
return {
|
||||
original_line: buildRecordLine(original),
|
||||
corrected_line: buildRecordLine(corrected),
|
||||
record_id: corrected.record_id,
|
||||
date: corrected.date,
|
||||
time: corrected.time,
|
||||
student: corrected.student,
|
||||
teacher: corrected.teacher,
|
||||
subject: corrected.subject,
|
||||
};
|
||||
})
|
||||
.filter(Boolean);
|
||||
@@ -597,8 +629,13 @@ document.querySelectorAll("[data-query]").forEach((button) => {
|
||||
});
|
||||
|
||||
recordRows.addEventListener("click", (event) => {
|
||||
const summaryButton = event.target.closest(".summary-toggle");
|
||||
const editButton = event.target.closest(".correction-edit");
|
||||
const deleteButton = event.target.closest(".record-delete");
|
||||
if (summaryButton) {
|
||||
toggleSummaryRow(summaryButton.dataset.recordKey);
|
||||
return;
|
||||
}
|
||||
if (editButton) {
|
||||
openCorrectionDialog(editButton.dataset.recordKey);
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user