phaethon-order commited on
Commit
a6c47c4
·
1 Parent(s): a815f7c

Remove debug document deletion in add_doc function and enhance cell editing with focusEditingCell functionality in manifest.html

Browse files
Files changed (2) hide show
  1. routes/api.py +1 -3
  2. static/manifest.html +25 -4
routes/api.py CHANGED
@@ -51,9 +51,7 @@ def allowed_file(filename: str) -> bool:
51
  @api_bp.route("/upload", methods=["POST"])
52
  def add_doc():
53
  """Upload one document, extract text, persist metadata, and schedule chunking."""
54
- delete_document(7)
55
- logger.error("DEBUG: Deleted document with doc_id=7 for testing purposes")
56
-
57
  if "file" not in request.files:
58
  return jsonify({"error": "No file part"}), 400
59
  file = request.files["file"]
 
51
  @api_bp.route("/upload", methods=["POST"])
52
  def add_doc():
53
  """Upload one document, extract text, persist metadata, and schedule chunking."""
54
+
 
 
55
  if "file" not in request.files:
56
  return jsonify({"error": "No file part"}), 400
57
  file = request.files["file"]
static/manifest.html CHANGED
@@ -291,6 +291,7 @@
291
  });
292
  });
293
  attachEditing();
 
294
  }
295
 
296
  function fetchManifestAll(){
@@ -317,10 +318,13 @@
317
  lastPageBtn.addEventListener('click', () => { const rows = filteredRows(); currentPage = Math.max(1, Math.ceil(rows.length / PAGE_SIZE)); renderTable(); });
318
 
319
  function attachEditing(){
320
- // cell editing
321
- manifestTableWrapper.querySelectorAll('td.editable').forEach(td => {
322
- td.addEventListener('click', () => beginCellEdit(td));
323
- });
 
 
 
324
  // delete handlers
325
  manifestTableWrapper.querySelectorAll('button.delete').forEach(btn => {
326
  btn.addEventListener('click', () => doDelete(btn.getAttribute('data-doc')));
@@ -336,6 +340,23 @@
336
  });
337
  }
338
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
339
  function beginCellEdit(td){
340
  const tr = td.closest('tr');
341
  const docId = tr.getAttribute('data-doc');
 
291
  });
292
  });
293
  attachEditing();
294
+ focusEditingCell();
295
  }
296
 
297
  function fetchManifestAll(){
 
318
  lastPageBtn.addEventListener('click', () => { const rows = filteredRows(); currentPage = Math.max(1, Math.ceil(rows.length / PAGE_SIZE)); renderTable(); });
319
 
320
  function attachEditing(){
321
+ // Robust click-to-edit via delegation; overwrite each render to avoid duplicates
322
+ manifestTableWrapper.onclick = (ev) => {
323
+ const td = ev.target.closest('td.editable');
324
+ if (td && manifestTableWrapper.contains(td)) {
325
+ beginCellEdit(td);
326
+ }
327
+ };
328
  // delete handlers
329
  manifestTableWrapper.querySelectorAll('button.delete').forEach(btn => {
330
  btn.addEventListener('click', () => doDelete(btn.getAttribute('data-doc')));
 
340
  });
341
  }
342
 
343
+ function focusEditingCell(){
344
+ if (!editing.rowDocId || !editing.col) return;
345
+ const row = manifestTableWrapper.querySelector(`tr[data-doc="${CSS.escape(editing.rowDocId)}"]`);
346
+ if (!row) return;
347
+ const field = row.querySelector(`td[data-col="${CSS.escape(editing.col)}"] input`);
348
+ if (!field) return;
349
+ field.focus();
350
+ if (field.setSelectionRange && typeof field.value === 'string') {
351
+ const len = field.value.length;
352
+ try { field.setSelectionRange(len, len); } catch {}
353
+ }
354
+ field.addEventListener('keydown', (ev) => {
355
+ if (ev.key === 'Escape') { ev.preventDefault(); cancelCellEdit(); }
356
+ else if (ev.key === 'Enter') { ev.preventDefault(); confirmCellEdit(editing.rowDocId); }
357
+ }, { once: true });
358
+ }
359
+
360
  function beginCellEdit(td){
361
  const tr = td.closest('tr');
362
  const docId = tr.getAttribute('data-doc');