diff --git a/js/ui.js b/js/ui.js
index 656c5c52..43270144 100644
--- a/js/ui.js
+++ b/js/ui.js
@@ -1605,7 +1605,7 @@ function generateBirdOptionList({ store, rows, selected }) {
-const getActiveRowID = () => activeRow?.id;
+const getActiveRowID = () => activeRow?.rowIndex - 1;
const isSpeciesViewFiltered = (sendSpecies) => {
const filtered = document.querySelector('#speciesFilter tr.text-warning');
@@ -2658,7 +2658,7 @@ async function onPredictionDone({
const resultTable = document.getElementById('resultTableBody');
if (active) {
// Refresh node and scroll to active row:
- activeRow = document.getElementById(active);
+ activeRow = resultTable.rows[active];
if (activeRow === null) { // because: after an edit the active row may not exist
const rows = resultTable.querySelectorAll('tr.daytime, tr.nighttime')
if (rows.length) {
@@ -3730,7 +3730,7 @@ async function createContextMenu(e) {
}
}
if (region === undefined && ! inSummary) return;
- //const createOrEdit = (['archive', 'explore'].includes(STATE.mode)) && (region?.attributes.label || target.closest('#summary')) ? 'Edit' : 'Create';
+ const createOrEdit = (['archive', 'explore'].includes(STATE.mode)) && (region?.attributes.label || target.closest('#summary')) ? 'Edit' : 'Create';
menu.html(`
play_circle Play
@@ -3739,7 +3739,7 @@ async function createContextMenu(e) {
- edit_document Edit Record${plural}
+ edit_document ${createOrEdit} Record${plural}
music_note Export Audio Clip${plural}
@@ -3752,6 +3752,8 @@ async function createContextMenu(e) {
delete_forever Delete Record${plural}
`);
+ const modalTitle = document.getElementById('record-entry-modal-label');
+ modalTitle.innerText = `${createOrEdit} Record`;
if (!hideInSelection) {
const contextAnalyseSelectionLink = document.getElementById('context-analyse-selection');
contextAnalyseSelectionLink.addEventListener('click', getSelectionResults);
diff --git a/js/worker.js b/js/worker.js
index baea422b..e2a14288 100644
--- a/js/worker.js
+++ b/js/worker.js
@@ -1683,45 +1683,37 @@ const onInsertManualRecord = async ({ cname, start, end, comment, count, file, l
const { speciesID } = await db.getAsync(`SELECT id as speciesID FROM species
WHERE cname = ?`, cname);
let res = await db.getAsync(`SELECT id,filestart FROM files WHERE name = ?`, file);
- // Manual records can be added off the bat, so there may be no record of the file in either db
+
- if (!res) { // No file: check the memory db
- if (toDisk) res = await memoryDB.getAsync('SELECT id, filestart FROM files WHERE name = ?', file);
- if (!res) { // Still no file, add it.
- fileStart = metadata[file].fileStart;
- res = await db.runAsync('INSERT OR IGNORE INTO files VALUES ( ?,?,?,?,? )',
- fileID, file, metadata[file].duration, fileStart, null);
- fileID = res.lastID;
- changes = 1;
- } else { // memory db has file
- fileID = res.id;
- fileStart = res.filestart;
- await diskDB.runAsync('INSERT OR IGNORE INTO files VALUES ( ?,?,?,?,? )',
- fileID, file, metadata[file].duration, fileStart, null);
- }
+ if (!res) {
+ // Manual records can be added off the bat, so there may be no record of the file in either db
+ fileStart = metadata[file].fileStart;
+ res = await db.runAsync('INSERT OR IGNORE INTO files VALUES ( ?,?,?,?,? )',
+ fileID, file, metadata[file].duration, fileStart, null);
+ fileID = res.lastID;
+ changes = 1;
+ let durationSQL = Object.entries(metadata[file].dateDuration)
+ .map(entry => `(${entry.toString()},${fileID})`).join(',');
+ await db.runAsync(`INSERT OR IGNORE INTO duration VALUES ${durationSQL}`);
} else {
fileID = res.id;
fileStart = res.filestart;
}
- let durationSQL;
- if (metadata[file]) { // If we don't have file metadata, the file must be saved already
- durationSQL = Object.entries(metadata[file].dateDuration)
- .map(entry => `(${entry.toString()},${fileID})`).join(',');
- await db.runAsync(`INSERT OR IGNORE INTO duration VALUES ${durationSQL}`);
- }
- let response;
const dateTime = fileStart + startMilliseconds;
const isDaylight = isDuringDaylight(dateTime, STATE.lat, STATE.lon);
confidence = confidence || 2000;
- response = await db.runAsync('INSERT OR REPLACE INTO records VALUES ( ?,?,?,?,?,?,?,?,?,?)',
+ // Delete an existing record if it exists
+ const result = await db.getAsync(`SELECT id as originalSpeciesID FROM species WHERE cname = ?`, originalCname);
+ if (result?.originalSpeciesID) await db.runAsync('DELETE FROM records WHERE datetime = ? AND speciesID = ? AND fileID = ?', dateTime, result.originalSpeciesID, fileID)
+ const response = await db.runAsync('INSERT OR REPLACE INTO records VALUES ( ?,?,?,?,?,?,?,?,?,?)',
dateTime, start, fileID, speciesID, confidence, label, comment, end, parseInt(count), isDaylight);
- if (response.changes && STATE.db === diskDB) {
- UI.postMessage({ event: 'diskDB-has-records' });
- } else {
- UI.postMessage({event: 'unsaved-records'});
+ if (response.changes){
+ STATE.db === diskDB ? UI.postMessage({ event: 'diskDB-has-records' }) : UI.postMessage({event: 'unsaved-records'});
}
+ let test = await db.allAsync('SELECT * from records where datetime = ?', dateTime)
+ console.log('After insert: ',JSON.stringify(test));
return response.changes
}