Skip to content

Commit

Permalink
fix multiuser annoations
Browse files Browse the repository at this point in the history
  • Loading branch information
Yusup-Badiev committed Sep 20, 2023
1 parent 1beec54 commit 484e896
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 12 deletions.
10 changes: 10 additions & 0 deletions neuroglancer/src/neuroglancer/ui/annotations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2147,6 +2147,11 @@ export function updateVolumeRef(ref_id: string) {
volume_ref_id = ref_id;
}

export function getVolumeRef() {
return volume_ref_id;
}


let volume_tool_mode: ToolMode = ToolMode.NOOP;

export function updateGlobalVolumeMode(mode: ToolMode) {
Expand Down Expand Up @@ -2181,6 +2186,7 @@ export class PlaceVolumeTool extends PlaceCollectionAnnotationTool {

if(restore_from_firebase && urlParams.multiUserMode) {
this.mode = volume_tool_mode;
has_volume_tool = true;
}

this.childTool = this.mode == ToolMode.NOOP ? undefined : new PlacePolygonTool(layer, {...options, parent: this}, this.mode);
Expand All @@ -2200,6 +2206,10 @@ export class PlaceVolumeTool extends PlaceCollectionAnnotationTool {
return
}

if(restore_from_firebase) {
volume_ref_id = getVolumeRef();
}

//@ts-ignore
let volume_annotation = this.annotationLayer.source.annotationMap.get(volume_ref_id);

Expand Down
9 changes: 8 additions & 1 deletion neuroglancer/src/neuroglancer/ui/url_hash_binding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { State } from 'neuroglancer/services/state';
import { database, dbRef } from 'neuroglancer/services/firebase';
import { child, get, onValue, ref, update } from "firebase/database";
import { User, getUser } from 'neuroglancer/services/user_loader';
import { updateGlobalCellSession, updateGlobalCellMode, updateGlobalComSession, updateGlobalComMode, updateGlobalVolumeMode, getInProgressAnnotation, getVolumeToolUsed, clearVolumeToolUsed } from 'neuroglancer/ui/annotations';
import { updateGlobalCellSession, updateGlobalCellMode, updateGlobalComSession, updateGlobalComMode, updateGlobalVolumeMode, getInProgressAnnotation, getVolumeToolUsed, clearVolumeToolUsed, updateVolumeRef } from 'neuroglancer/ui/annotations';

/**
* @file Implements a binding between a Trackable value and the URL hash state.
Expand Down Expand Up @@ -217,6 +217,13 @@ export class UrlHashBinding extends RefCounted {
updateGlobalVolumeMode(snapshot.val());
});

const stateRefVolumeRef = ref(database, `/test_annotations_tool/volume_ref/${this.stateID}`);
onValue(stateRefVolumeRef, (snapshot) => {
if (getInProgressAnnotation()) {
return;
}
updateVolumeRef(snapshot.val());
});

/*
const stateRefComSession = ref(database, `/test_annotations_tool/volume_session/${this.stateID}`);
Expand Down
32 changes: 21 additions & 11 deletions neuroglancer/src/neuroglancer/ui/volume_session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,18 +126,28 @@ import { displayWidgets } from '../services/display_widgets';
return
}
updateVolumeRef(reference.id);
}

if(urlParams.multiUserMode) {
const updates: any = {};
updates[`/test_annotations_tool/volume_mode/${urlParams.stateID}`] = ToolMode.DRAW;
update(ref(database), updates)
.then(() => {
console.log('Successfully Published Volume Mode State to Firebase');
})
.catch((error) => {
console.error(error);
});
if(urlParams.multiUserMode) {
const updates: any = {};
updates[`/test_annotations_tool/volume_mode/${urlParams.stateID}`] = ToolMode.DRAW;
update(ref(database), updates)
.then(() => {
console.log('Successfully Published Volume Mode State to Firebase');
})
.catch((error) => {
console.error(error);
});

updates[`/test_annotations_tool/volume_ref/${urlParams.stateID}`] = reference.id;
update(ref(database), updates)
.then(() => {
console.log('Successfully Published Volume Session State to Firebase');
})
.catch((error) => {
console.error(error);
});
}

}

this.dispose();
Expand Down

0 comments on commit 484e896

Please sign in to comment.