Skip to content
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

feat(annotation): handle create event #1199

Merged
merged 3 commits into from
Apr 17, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 8 additions & 0 deletions src/lib/AnnotationControls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ export default class AnnotationControls {
*/
private handleFullscreenExit = (): void => this.handleFullscreenChange(false);

/**
* Returns the current active annotation mode
* @return {string} Current active annotation mode
ConradJChan marked this conversation as resolved.
Show resolved Hide resolved
*/
public getActiveMode = (): AnnotationMode => {
return this.currentActiveControl;
};

/**
* Deactivate current control button
*/
Expand Down
15 changes: 14 additions & 1 deletion src/lib/viewers/BaseViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ class BaseViewer extends EventEmitter {
this.mobileZoomChangeHandler = this.mobileZoomChangeHandler.bind(this);
this.mobileZoomEndHandler = this.mobileZoomEndHandler.bind(this);
this.handleAnnotatorEvents = this.handleAnnotatorEvents.bind(this);
this.handleAnnotationCreateEvent = this.handleAnnotationCreateEvent.bind(this);
this.handleFullscreenEnter = this.handleFullscreenEnter.bind(this);
this.handleFullscreenExit = this.handleFullscreenExit.bind(this);
this.createAnnotator = this.createAnnotator.bind(this);
Expand Down Expand Up @@ -976,7 +977,7 @@ class BaseViewer extends EventEmitter {
this.annotator.addListener('annotatorevent', this.handleAnnotatorEvents);

if (this.options.showAnnotationsControls && this.annotationControls) {
this.annotator.addListener('annotationcreate', this.annotationControls.resetControls);
this.annotator.addListener('annotations_create', this.handleAnnotationCreateEvent);
}
}

Expand Down Expand Up @@ -1100,6 +1101,18 @@ class BaseViewer extends EventEmitter {
this.emit('annotatorevent', data);
}

handleAnnotationCreateEvent({ annotation, meta: { status } = {} }) {
if (status !== 'pending') {
ConradJChan marked this conversation as resolved.
Show resolved Hide resolved
const activeMode = this.annotationControls.getActiveMode();
this.annotator.toggleAnnotationMode(activeMode);
ConradJChan marked this conversation as resolved.
Show resolved Hide resolved
this.annotationControls.resetControls();
}

if (status === 'success') {
this.annotator.emit('annotations_active_set', annotation.id);
ConradJChan marked this conversation as resolved.
Show resolved Hide resolved
ConradJChan marked this conversation as resolved.
Show resolved Hide resolved
}
}

/**
* Creates combined options to give to the annotator
*
Expand Down