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

Chore: Toggling annotation mode handlers using emitted messages #307

Merged
merged 2 commits into from Aug 15, 2017
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/lib/annotations/Annotator.js
Expand Up @@ -327,6 +327,10 @@ class Annotator extends EventEmitter {
* @return {void}
*/
toggleAnnotationHandler(mode, event = {}) {
if (!this.isModeAnnotatable(mode)) {
return;
}

this.destroyPendingThreads();

// No specific mode available for annotation type
Expand Down
11 changes: 9 additions & 2 deletions src/lib/annotations/__tests__/Annotator-test.js
Expand Up @@ -293,6 +293,7 @@ describe('lib/annotations/Annotator', () => {
stubs.disable = sandbox.stub(annotator, 'disableAnnotationMode');
stubs.enable = sandbox.stub(annotator, 'enableAnnotationMode');
sandbox.stub(annotator.previewUI, 'getAnnotateButton');
stubs.isAnnotatable = sandbox.stub(annotator, 'isModeAnnotatable').returns(true);

annotator.modeButtons = {
point: { selector: 'point_btn' },
Expand All @@ -304,11 +305,17 @@ describe('lib/annotations/Annotator', () => {
annotator.modeButtons = {};
});

it('should do nothing if specified annotation type is not annotatable', () => {
stubs.isAnnotatable.returns(false);
annotator.toggleAnnotationHandler('bleh');
expect(stubs.destroyStub).to.not.be.called;
});

it('should do nothing if specified annotation type does not have a mode button', () => {
annotator.toggleAnnotationHandler(TYPES.highlight);
expect(stubs.destroyStub).to.be.called;
expect(stubs.exitAnnotationModes)
})
expect(stubs.exitModes).to.not.be.called;
});

it('should turn annotation mode on if it is off', () => {
stubs.annotationMode.returns(false);
Expand Down
5 changes: 5 additions & 0 deletions src/lib/viewers/BaseViewer.js
Expand Up @@ -677,6 +677,11 @@ class BaseViewer extends EventEmitter {
});
this.annotator.init(this.scale);

// Add a custom listener for entering/exit annotations mode using the app's custom annotations buttons
this.addListener('toggleannotationmode', (data) => {
this.annotator.toggleAnnotationHandler(data);
});

// Add a custom listener for events related to scaling/orientation changes
this.addListener('scale', (data) => {
this.annotator.emit('scaleAnnotations', data);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/viewers/__tests__/BaseViewer-test.js
Expand Up @@ -769,7 +769,6 @@ describe('lib/viewers/BaseViewer', () => {
base.annotator = {
init: sandbox.stub(),
addListener: sandbox.stub(),
setScale: sandbox.stub()
};
base.annotatorConf = {
CONSTRUCTOR: sandbox.stub().returns(base.annotator)
Expand All @@ -779,6 +778,7 @@ describe('lib/viewers/BaseViewer', () => {

it('should initialize the annotator', () => {
expect(base.annotator.init).to.be.calledWith(1.5);
expect(base.addListener).to.be.calledWith('toggleannotationmode', sinon.match.func);
expect(base.addListener).to.be.calledWith('scale', sinon.match.func);
expect(base.annotator.addListener).to.be.calledWith('annotatorevent', sinon.match.func);
});
Expand Down