Skip to content

Commit

Permalink
Merge pull request #150 from alan-wu/main
Browse files Browse the repository at this point in the history
Handle json parsing error and add on error callback.
  • Loading branch information
alan-wu authored Nov 29, 2024
2 parents 7a33274 + 861f881 commit 80c88fb
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 30 deletions.
30 changes: 29 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,35 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

## [v1.6.0-beta.1](https://github.com/alan-wu/scaffoldvuer/compare/v1.5.1...v1.6.0-beta.1)
## [v1.6.2](https://github.com/alan-wu/scaffoldvuer/compare/v1.6.1...v1.6.2)

### Commits

- Fix a logical error. [`d769203`](https://github.com/alan-wu/scaffoldvuer/commit/d7692039b56da40d4310196a5bf007c8aee5acb3)

## [v1.6.1](https://github.com/alan-wu/scaffoldvuer/compare/v1.6.0...v1.6.1) - 2024-11-14

### Commits

- Fix few issues with annotator. [`9672dd9`](https://github.com/alan-wu/scaffoldvuer/commit/9672dd96a23a78207843c4e5ccb53eed348cd780)

## [v1.6.0](https://github.com/alan-wu/scaffoldvuer/compare/v1.6.0-beta.1...v1.6.0) - 2024-11-14

### Merged

- Support external annotation display [`#146`](https://github.com/alan-wu/scaffoldvuer/pull/146)
- Fix some annotation related issue [`#2`](https://github.com/alan-wu/scaffoldvuer/pull/2)
- Annotation [`#5`](https://github.com/alan-wu/scaffoldvuer/pull/5)
- State saving [`#148`](https://github.com/alan-wu/scaffoldvuer/pull/148)
- Improve searching, making it consistent with flatmapvuer. [`#147`](https://github.com/alan-wu/scaffoldvuer/pull/147)

### Commits

- Update src/components.d.ts [`be9431d`](https://github.com/alan-wu/scaffoldvuer/commit/be9431dd8c543b4c2028128bc10b6dcbba317574)
- Merge in changes. [`aa853de`](https://github.com/alan-wu/scaffoldvuer/commit/aa853de47c582dd83915abf25aa5c1e2bf8768b0)
- Improve searching, making it consistence with flatmapvuer. [`f4f793d`](https://github.com/alan-wu/scaffoldvuer/commit/f4f793d33027ba73ed2a1a631d3d2a0559485844)

## [v1.6.0-beta.1](https://github.com/alan-wu/scaffoldvuer/compare/v1.5.1...v1.6.0-beta.1) - 2024-10-31

### Commits

Expand Down
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@abi-software/scaffoldvuer",
"version": "1.6.0-beta.1",
"version": "1.6.2",
"license": "Apache-2.0",
"repository": {
"type": "git",
Expand Down Expand Up @@ -54,7 +54,7 @@
"vue": "^3.4.21",
"vue-router": "^4.2.5",
"vue3-component-svg-sprite": "^0.0.1",
"zincjs": "^1.11.4"
"zincjs": "^1.11.5"
},
"devDependencies": {
"@vitejs/plugin-vue": "^4.6.2",
Expand Down
12 changes: 12 additions & 0 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
:marker-labels="markerLabels"
:enableLocalAnnotations="false"
@open-map="openMap"
@on-error="onError"
@on-ready="onReady"
@scaffold-selected="onSelected"
@scaffold-navigated="onNavigated"
Expand Down Expand Up @@ -640,6 +641,17 @@ export default {
}
});
},
onError: function(payload) {
if (payload?.type === "download-error") {
const dropZone = this.$refs.dropzone;
if (dropZone) {
const realFilename = dropZone.findRealFilename(payload.xhr.responseURL);
if (realFilename) {
console.error(`External Resource ${realFilename}`);
}
}
}
},
onReady: function () {
if (this.consoleOn) console.log(this.$refs.scaffold)
if (this.readyCallback) {
Expand Down
12 changes: 10 additions & 2 deletions src/app/DropZone.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

<script>
/* eslint-disable no-alert, no-console */
import { markRaw } from 'vue';
import { SimpleDropzone } from "simple-dropzone";
import path from "path";
Expand All @@ -26,7 +27,8 @@ export default {
name: "DropZone",
data: function () {
return {
objectURLs: [],
objectURLs: markRaw([]),
filesMapping: markRaw({}),
};
},
mounted: function () {
Expand All @@ -39,6 +41,9 @@ export default {
});
},
methods: {
findRealFilename: function(objectURL) {
return this.filesMapping[objectURL]
},
processTextureFile: function(textureData, flatarray) {
if (textureData && textureData.images && textureData.images.source) {
const images = textureData.images.source;
Expand All @@ -50,6 +55,7 @@ export default {
const objectURL = URL.createObjectURL(flatarray[index][1]);
this.objectURLs.push(objectURL);
textureData.images.source[i] = objectURL;
this.filesMapping[objectURL] = images[i];
}
}
const content = JSON.stringify(textureData);
Expand All @@ -65,6 +71,7 @@ export default {
const re = new RegExp(key, "g");
content = content.replace(re, objectURL);
this.objectURLs.push(objectURL);
this.filesMapping[objectURL] = key;
}
}
const data = JSON.parse(content);
Expand Down Expand Up @@ -93,7 +100,8 @@ export default {
},
revokeURLs: function () {
this.objectURLs.forEach(objectURL => URL.revokeObjectURL(objectURL));
this.objectURLs = [];
this.objectURLs.length = 0;
this.filesMapping = markRaw({});
},
localDrop: function (fileMap) {
this.revokeURLs();
Expand Down
36 changes: 24 additions & 12 deletions src/components/ScaffoldVuer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -1338,7 +1338,7 @@ export default {
this.$module.selectObjectOnPick = true;
} else if (type === 'tool') {
this.activeDrawTool = icon;
this.createData.shape = this.activeDrawTool;
this.createData.shape = this.activeDrawTool ? this.activeDrawTool : '';
this.$module.selectObjectOnPick = false;
}
},
Expand Down Expand Up @@ -1544,13 +1544,25 @@ export default {
});
zincObjects = event.zincObjects;
}
let id = undefined;
let regionPath = undefined;
if (event.identifiers.length > 0 && event.identifiers[0]) {
id = event.identifiers[0].data.id
? event.identifiers[0].data.id
: event.identifiers[0].data.group;
if (event.identifiers[0].data.region) {
regionPath = event.identifiers[0].data.region;
}
}
/*
* Event Type 1: Selected
* Event Type 2: Highlighted
* Event Type 3: Move
*/
if (event.eventType == 1) {
if (this.viewingMode === 'Annotation') {
this.tData.label = id;
this.tData.region = regionPath;
this.activateAnnotationMode(names, event);
} else {
if (this.$refs.scaffoldTreeControls) {
Expand All @@ -1566,7 +1578,7 @@ export default {
//identifiers.
if (event.identifiers.length === 1) {
this.lastSelected.isSearch = false;
this.lastSelected.region = event.identifiers[0].data.region;
this.lastSelected.region = regionPath;
this.lastSelected.group = event.identifiers[0].data.group;
} else if (event.identifiers.length === 0) {
this.lastSelected.isSearch = false;
Expand All @@ -1590,21 +1602,13 @@ export default {
}
}
if (event.identifiers.length > 0 && event.identifiers[0]) {
let id = event.identifiers[0].data.id
? event.identifiers[0].data.id
: event.identifiers[0].data.group;
if (event.identifiers[0].coords) {
this.tData.active = false;
if (!this.annotationSidebar) {
if (this.viewingMode !== "Annotation" || !this.annotationSidebar) {
this.tData.visible = true;
}
this.tData.label = id;
if (event.identifiers[0].data.region) {
this.tData.region = event.identifiers[0].data.region;
}
else {
this.tData.region = undefined;
}
this.tData.region = regionPath;
this.tData.x = event.identifiers[0].coords.x;
this.tData.y = event.identifiers[0].coords.y;
this.createEditTemporaryLines(event.identifiers);
Expand Down Expand Up @@ -2205,6 +2209,11 @@ export default {
}
}
},
downloadErrorCallback: function() {
return (error) => {
this.$emit('on-error', error);
}
},
setURLFinishCallback: function (options) {
return () => {
this.localAnnotationsList.length = 0;
Expand Down Expand Up @@ -2364,6 +2373,9 @@ export default {
this.isReady = false;
this.$_searchIndex.removeAll();
this.hideRegionTooltip();
this.$module.setDownloadErrorCallback(
this.downloadErrorCallback()
);
this.$module.setFinishDownloadCallback(
this.setURLFinishCallback({
background: state?.background,
Expand Down
34 changes: 28 additions & 6 deletions src/scripts/OrgansRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const OrgansSceneData = function() {
const organPartAddedCallbacks = new Array();
const organPartRemovedCallbacks = new Array();
let finishDownloadCallback = undefined;
let downloadErrorCallback = undefined;
const modelsLoader = ModelsLoaderIn;
this.NDCCameraControl = undefined;
_this.typeName = "Organ Viewer";
Expand Down Expand Up @@ -187,6 +188,16 @@ const OrgansSceneData = function() {
finishDownloadCallback = undefined;
}


this.setDownloadErrorCallback = function(callback) {
if (typeof(callback === "function"))
downloadErrorCallback = callback;
}

this.unsetDownloadErrorCallback = function() {
downloadErrorCallback = undefined;
}

this.getNamedObjectsToScreenCoordinates = function(name, camera) {
const vector = new THREE.Vector3();
vector.setFromMatrixPosition( obj.matrixWorld );
Expand Down Expand Up @@ -435,11 +446,22 @@ const OrgansSceneData = function() {
finishDownloadCallback();
}
}

const singleItemDownloadCompletedCallback = function(systemName, partName, useDefautColour) {
return function(geometry) {
addOrganPart(systemName, partName, useDefautColour, geometry);
_this.settingsChanged();

//The payload can either be a zinc object when the loading is successful or
//an object containg the details of error message on failure.
//We only use it to handle an error
const singleItemFinishCallback = function() {
return function(payload) {

if (payload?.type === "Error") {
if (downloadErrorCallback) {
const error = {
xhr: payload.xhr,
type: "download-error",
};
downloadErrorCallback(error);
}
}
}
}

Expand Down Expand Up @@ -549,7 +571,7 @@ const OrgansSceneData = function() {
_this.sceneData.metaURL = url;
organScene.addZincObjectAddedCallbacks(_addOrganPartCallback(systemName, partName, false));
organScene.addZincObjectRemovedCallbacks(_removeOrganPartCallback(undefined, partName, false));
organScene.loadMetadataURL(url, undefined, downloadCompletedCallback());
organScene.loadMetadataURL(url, singleItemFinishCallback(), downloadCompletedCallback());
_this.scene = organScene;
_this.zincRenderer.setCurrentScene(organScene);
_this.graphicsHighlight.reset();
Expand Down
1 change: 0 additions & 1 deletion src/scripts/Search.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ export class SearchIndex
let results = undefined;
if (text.length > 2 && ["'", '"'].includes(text.slice(0, 1))) {
text = text.replaceAll(text.slice(0, 1), '')
console.log(text)
results = this._searchEngine.search(text, {prefix: true, combineWith: 'AND'})
} else if (text.length > 1) {
results = this._searchEngine.search(text, {prefix: true})
Expand Down

0 comments on commit 80c88fb

Please sign in to comment.