Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 27 additions & 8 deletions components/annotorious-annotator/line-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -1106,19 +1106,32 @@ class AnnotoriousAnnotator extends HTMLElement {
saveButton.textContent = "ERROR"
throw err
})
page.items = page.items.map(i => ({
...i,
...(mod.items?.find(a => a.target === i.target) ?? {})
}))
page.items = page.items.map(i => {
const selectorValue = i.target?.selector?.value ?? i.target
// Prefer matching by ID for previously-saved annotations, fall back to selector for new ones
const match = mod.items?.find(a => a.id === i.id)
?? mod.items?.find(a => {
const aSelector = a.target?.selector?.value ?? a.target
return aSelector === selectorValue
})
return match ? { ...i, ...match } : i
})
this.#modifiedAnnotationPage = page
this.#resolvedAnnotationPage = JSON.parse(JSON.stringify(page))
// Sync server-assigned IDs back to Annotorious so subsequent saves use the correct IDs
let syncAnnotations = JSON.parse(JSON.stringify(page.items))
syncAnnotations = this.formatAnnotations(syncAnnotations)
syncAnnotations = this.convertSelectors(syncAnnotations, true)
this.#annotoriousInstance.clearAnnotations()
this.#annotoriousInstance.setAnnotations(syncAnnotations, false)
this.#resolvedAnnotationPage.$isDirty = false
TPEN.eventDispatcher.dispatch("tpen-page-committed", this.#modifiedAnnotationPage)
TPEN.eventDispatcher.dispatch("tpen-toast", {
message: "Annotations Saved",
status: "success"
})
saveButton.removeAttribute("disabled")
saveButton.textContent = "Save Annotations"
this.#resolvedAnnotationPage.$isDirty = false
return this.#modifiedAnnotationPage
}

Expand All @@ -1127,17 +1140,23 @@ class AnnotoriousAnnotator extends HTMLElement {
* https://annotorious.dev/api-reference/openseadragon-annotator/#clearannotations
*/
async deleteAllAnnotations() {
const deleteAllBtn = this.shadowRoot.getElementById("deleteAllBtn")
deleteAllBtn.setAttribute("disabled", "true")
deleteAllBtn.textContent = "deleting. please wait..."
this.#annotoriousInstance.clearAnnotations()
this.#resolvedAnnotationPage.$isDirty = true
await this.saveAnnotations()
try {
await this.saveAnnotations()
await this.clearColumnsServerSide()
} catch (err) {
console.error("Could not clear columns server side.", err)
console.error("Could not delete all annotations.", err)
TPEN.eventDispatcher.dispatch("tpen-toast", {
message: "Could not clear columns. Some column data may remain.",
message: "Could not delete all annotations.",
status: "error"
})
} finally {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this makes sense.

deleteAllBtn.removeAttribute("disabled")
deleteAllBtn.textContent = "Delete All Annotations"
}
}

Expand Down