Исправлено повторное появление подсказок модуля на главной странице
This commit is contained in:
+30
-7
@@ -10,6 +10,8 @@ const moduleField = document.getElementById('moduleField');
|
|||||||
const moduleNames = new Map();
|
const moduleNames = new Map();
|
||||||
const moduleAttachments = new Map();
|
const moduleAttachments = new Map();
|
||||||
let moduleSearchTimer = null;
|
let moduleSearchTimer = null;
|
||||||
|
let moduleSearchSeq = 0;
|
||||||
|
let moduleOptionsKey = '';
|
||||||
const toast = document.getElementById('toast');
|
const toast = document.getElementById('toast');
|
||||||
const camVideo = document.getElementById('camVideo');
|
const camVideo = document.getElementById('camVideo');
|
||||||
const camCanvas = document.getElementById('camCanvas');
|
const camCanvas = document.getElementById('camCanvas');
|
||||||
@@ -248,8 +250,20 @@ if (params.get('nameInput')) {
|
|||||||
field.innerHTML = `<label>Фамилия и имя</label><div class="fixed-name" id="fixedName">${escName(studentName)}</div>`;
|
field.innerHTML = `<label>Фамилия и имя</label><div class="fixed-name" id="fixedName">${escName(studentName)}</div>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function rememberModules(list) {
|
||||||
|
list.forEach(m => {
|
||||||
|
moduleNames.set(m.name, m.id);
|
||||||
|
moduleAttachments.set(m.name.toLowerCase(), m.has_attachments === true);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function renderModuleOptions(list) {
|
function renderModuleOptions(list) {
|
||||||
list.forEach(m => { moduleNames.set(m.name, m.id); moduleAttachments.set(m.name.toLowerCase(), m.has_attachments === true); });
|
rememberModules(list);
|
||||||
|
const value = (moduleInput.value || '').trim().toLowerCase();
|
||||||
|
if (value && list.some(m => String(m.name).trim().toLowerCase() === value)) return;
|
||||||
|
const key = list.map(m => m.name).join('\n');
|
||||||
|
if (key === moduleOptionsKey) return;
|
||||||
|
moduleOptionsKey = key;
|
||||||
moduleInputList.innerHTML = '';
|
moduleInputList.innerHTML = '';
|
||||||
list.forEach(m => {
|
list.forEach(m => {
|
||||||
const opt = document.createElement('option');
|
const opt = document.createElement('option');
|
||||||
@@ -298,7 +312,7 @@ async function resolveModuleId(name) {
|
|||||||
const cached = findModuleId(n);
|
const cached = findModuleId(n);
|
||||||
if (cached) return cached;
|
if (cached) return cached;
|
||||||
const list = await fetchModules(n, 5);
|
const list = await fetchModules(n, 5);
|
||||||
if (list) renderModuleOptions(list);
|
if (list) rememberModules(list);
|
||||||
const lower = n.toLowerCase();
|
const lower = n.toLowerCase();
|
||||||
const exact = (list || []).find(m => m.name.toLowerCase() === lower);
|
const exact = (list || []).find(m => m.name.toLowerCase() === lower);
|
||||||
return exact ? exact.id : null;
|
return exact ? exact.id : null;
|
||||||
@@ -307,9 +321,10 @@ async function resolveModuleId(name) {
|
|||||||
(async () => {
|
(async () => {
|
||||||
await initDateTime();
|
await initDateTime();
|
||||||
try {
|
try {
|
||||||
|
const seq = moduleSearchSeq;
|
||||||
const list = await fetchModules('', MODULE_LIST_LIMIT);
|
const list = await fetchModules('', MODULE_LIST_LIMIT);
|
||||||
if (list) {
|
if (list) {
|
||||||
renderModuleOptions(list);
|
if (seq === moduleSearchSeq) renderModuleOptions(list);
|
||||||
if (list.length) {
|
if (list.length) {
|
||||||
moduleInput.required = true;
|
moduleInput.required = true;
|
||||||
moduleField.style.display = '';
|
moduleField.style.display = '';
|
||||||
@@ -547,17 +562,25 @@ moduleInput.addEventListener('input', () => {
|
|||||||
updateAttachHint();
|
updateAttachHint();
|
||||||
clearTimeout(moduleSearchTimer);
|
clearTimeout(moduleSearchTimer);
|
||||||
const q = moduleInput.value.trim();
|
const q = moduleInput.value.trim();
|
||||||
|
const seq = ++moduleSearchSeq;
|
||||||
moduleSearchTimer = setTimeout(async () => {
|
moduleSearchTimer = setTimeout(async () => {
|
||||||
const list = await fetchModules(q, q ? 20 : MODULE_LIST_LIMIT);
|
const list = await fetchModules(q, q ? 20 : MODULE_LIST_LIMIT);
|
||||||
|
if (seq !== moduleSearchSeq) return;
|
||||||
if (list) renderModuleOptions(list);
|
if (list) renderModuleOptions(list);
|
||||||
updateAttachHint();
|
updateAttachHint();
|
||||||
}, 250);
|
}, 250);
|
||||||
});
|
});
|
||||||
|
moduleInput.addEventListener('change', () => {
|
||||||
|
clearTimeout(moduleSearchTimer);
|
||||||
|
moduleSearchSeq++;
|
||||||
|
updateAttachHint();
|
||||||
|
});
|
||||||
moduleInput.addEventListener('focus', async () => {
|
moduleInput.addEventListener('focus', async () => {
|
||||||
if (!moduleInput.value.trim()) {
|
if (moduleInput.value.trim()) return;
|
||||||
const list = await fetchModules('', MODULE_LIST_LIMIT);
|
const seq = ++moduleSearchSeq;
|
||||||
if (list) renderModuleOptions(list);
|
const list = await fetchModules('', MODULE_LIST_LIMIT);
|
||||||
}
|
if (seq !== moduleSearchSeq) return;
|
||||||
|
if (list) renderModuleOptions(list);
|
||||||
});
|
});
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user