-
Notifications
You must be signed in to change notification settings - Fork 3
Annotator Data Incongruity Fix #477
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2892f63
I think this gets the sync
thehabes b126346
Changes while reviewing
thehabes ee8f745
changes while reviewing
thehabes 459a845
changes while reviewing
thehabes dbc3f34
Stop 'delete all annotations' button mashing
thehabes 9c5d403
revert change
thehabes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1084,41 +1084,54 @@ class AnnotoriousAnnotator extends HTMLElement { | |
| let page = JSON.parse(JSON.stringify(this.#resolvedAnnotationPage)) | ||
| page.items = allAnnotations | ||
| const pageID = page["@id"] ?? page.id | ||
| const mod = await fetch(`${TPEN.servicesURL}/project/${TPEN.activeProject._id}/page/${pageID.split("/").pop()}`, { | ||
| let mod | ||
| try { | ||
| const res = await fetch(`${TPEN.servicesURL}/project/${TPEN.activeProject._id}/page/${pageID.split("/").pop()}`, { | ||
| method: "PUT", | ||
| headers: { | ||
| "Content-Type": "application/json", | ||
| "Authorization": `Bearer ${TPEN.getAuthorization()}`, | ||
| }, | ||
| body: JSON.stringify({ "items": page.items }) | ||
| }) | ||
| .then(res => { | ||
| if(!res.ok) { | ||
| TPEN.eventDispatcher.dispatch("tpen-toast", { | ||
| message: "ERROR Annotations Not Saved", | ||
| status: "error" | ||
| }) | ||
| throw new Error("Could not save annotations", { "cause": `\n${res.status} Error from TPEN Services. Check the Network response.` }) | ||
| } | ||
| return res.json() | ||
| }) | ||
| .catch(err => { | ||
| saveButton.textContent = "ERROR" | ||
| throw err | ||
| }) | ||
| page.items = page.items.map(i => ({ | ||
| ...i, | ||
| ...(mod.items?.find(a => a.target === i.target) ?? {}) | ||
| })) | ||
| if (!res.ok) { | ||
| TPEN.eventDispatcher.dispatch("tpen-toast", { | ||
| message: "ERROR Annotations Not Saved", | ||
| status: "error" | ||
| }) | ||
| throw new Error("Could not save annotations", { "cause": `\n${res.status} Error from TPEN Services. Check the Network response.` }) | ||
| } | ||
| mod = await res.json() | ||
| } catch (err) { | ||
| saveButton.textContent = "ERROR" | ||
| throw err | ||
| } | ||
| 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 | ||
| } | ||
|
|
||
|
|
@@ -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 { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this makes sense. |
||
| deleteAllBtn.removeAttribute("disabled") | ||
| deleteAllBtn.textContent = "Delete All Annotations" | ||
| } | ||
| } | ||
|
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is weird. The fetch.then.catch is replaced with a try{fetch.then}catch{} and it looks like nothing is really changed until after this block around line 1109.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It believed that the try/catch was more explicit and I also think it thought that was the most reliable way to stop code execution. In practice the old way works the same, so I reverted this change.