-
Notifications
You must be signed in to change notification settings - Fork 47
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: Removing DrawingModeController dependency on DocDrawingThread #161
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,10 @@ | ||
import AnnotationModeController from './AnnotationModeController'; | ||
import shell from './drawingShell.html'; | ||
import DocDrawingThread from '../doc/DocDrawingThread'; | ||
import { | ||
replaceHeader, | ||
enableElement, | ||
disableElement, | ||
eventToLocationHandler, | ||
clearCanvas, | ||
hasValidBoundaryCoordinates | ||
} from '../util'; | ||
import { replaceHeader, enableElement, disableElement, clearCanvas, hasValidBoundaryCoordinates } from '../util'; | ||
import { | ||
TYPES, | ||
STATES, | ||
THREAD_EVENT, | ||
SELECTOR_ANNOTATION_BUTTON_DRAW_CANCEL, | ||
SELECTOR_ANNOTATION_BUTTON_DRAW_POST, | ||
SELECTOR_ANNOTATION_BUTTON_DRAW_UNDO, | ||
|
@@ -107,40 +100,18 @@ class DrawingModeController extends AnnotationModeController { | |
/** @inheritdoc */ | ||
setupHandlers() { | ||
/* eslint-disable require-jsdoc */ | ||
const locationFunction = (event) => this.annotator.getLocationFromEvent(event, TYPES.point); | ||
this.locationFunction = (event) => this.annotator.getLocationFromEvent(event, TYPES.point); | ||
/* eslint-enable require-jsdoc */ | ||
|
||
// Setup | ||
const threadParams = this.annotator.getThreadParams([], {}, TYPES.draw); | ||
this.currentThread = new DocDrawingThread(threadParams); | ||
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. Now you will be able to DrawingThreads for other viewers |
||
this.currentThread.addListener('threadevent', (data) => { | ||
const thread = this.currentThread || this.selectedThread; | ||
this.handleThreadEvents(thread, data); | ||
}); | ||
|
||
// Get handlers | ||
this.pushElementHandler( | ||
this.annotatedElement, | ||
['mousemove', 'touchmove'], | ||
eventToLocationHandler(locationFunction, this.currentThread.handleMove) | ||
); | ||
|
||
this.pushElementHandler( | ||
this.annotatedElement, | ||
['mousedown', 'touchstart'], | ||
eventToLocationHandler(locationFunction, this.currentThread.handleStart) | ||
); | ||
|
||
this.pushElementHandler( | ||
this.annotatedElement, | ||
['mouseup', 'touchcancel', 'touchend'], | ||
eventToLocationHandler(locationFunction, this.currentThread.handleStop) | ||
); | ||
this.drawingStartHandler = this.drawingStartHandler.bind(this); | ||
this.pushElementHandler(this.annotatedElement, ['mousedown', 'touchstart'], this.drawingStartHandler); | ||
|
||
this.pushElementHandler(this.cancelButtonEl, 'click', () => { | ||
if (this.currentThread) { | ||
this.currentThread.cancelUnsavedAnnotation(); | ||
} | ||
|
||
this.currentThread = undefined; | ||
this.toggleMode(); | ||
}); | ||
|
||
|
@@ -149,11 +120,61 @@ class DrawingModeController extends AnnotationModeController { | |
this.saveThread(this.currentThread); | ||
} | ||
|
||
this.currentThread = undefined; | ||
this.toggleMode(); | ||
}); | ||
|
||
this.pushElementHandler(this.undoButtonEl, 'click', this.currentThread.undo); | ||
this.pushElementHandler(this.redoButtonEl, 'click', this.currentThread.redo); | ||
this.pushElementHandler(this.undoButtonEl, 'click', () => { | ||
if (this.currentThread) { | ||
this.currentThread.undo(); | ||
} | ||
}); | ||
|
||
this.pushElementHandler(this.redoButtonEl, 'click', () => { | ||
if (this.currentThread) { | ||
this.currentThread.redo(); | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
* Start a drawing stroke | ||
* | ||
* @param {Event} event - DOM event | ||
* @return {void} | ||
*/ | ||
drawingStartHandler(event) { | ||
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. Starting a new drawing should trigger the creation of a blank drawing annotation and kick off the drawing path tracking in the thread |
||
event.stopPropagation(); | ||
event.preventDefault(); | ||
|
||
// Get annotation location from click event, ignore click if location is invalid | ||
const location = this.annotator.getLocationFromEvent(event, TYPES.point); | ||
if (!location) { | ||
return; | ||
} | ||
|
||
if (this.currentThread) { | ||
this.currentThread.handleStart(location); | ||
return; | ||
} | ||
|
||
// Add initial drawing boundary based on starting location | ||
location.minX = location.x; | ||
location.maxX = location.x; | ||
location.minY = location.y; | ||
location.maxY = location.y; | ||
|
||
// Create new thread with no annotations, show indicator, and show dialog | ||
const thread = this.annotator.createAnnotationThread([], location, TYPES.draw); | ||
if (!thread) { | ||
return; | ||
} | ||
|
||
this.currentThread = thread; | ||
this.emit(THREAD_EVENT.pending, thread.getThreadEventData()); | ||
thread.bindDrawingListeners(this.locationFunction); | ||
thread.addListener('threadevent', (data) => this.handleThreadEvents(thread, data)); | ||
thread.handleStart(location); | ||
} | ||
|
||
/** | ||
|
@@ -171,6 +192,9 @@ class DrawingModeController extends AnnotationModeController { | |
const { eventData } = data; | ||
switch (data.event) { | ||
case 'softcommit': | ||
thread.removeListener('threadevent', this.handleThreadEvents); | ||
thread.unbindDrawingListeners(); | ||
|
||
this.currentThread = undefined; | ||
this.saveThread(thread); | ||
this.unbindListeners(); | ||
|
@@ -187,6 +211,10 @@ class DrawingModeController extends AnnotationModeController { | |
return; | ||
} | ||
|
||
this.currentThread = undefined; | ||
thread.removeListener('threadevent', this.handleThreadEvents); | ||
thread.unbindDrawingListeners(); | ||
|
||
if (thread.state === STATES.pending) { | ||
// Soft delete, in-progress thread doesn't require a redraw or a delete on the server | ||
// Clear in-progress thread and restart drawing | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,12 +16,6 @@ class PointModeController extends AnnotationModeController { | |
/** @property {HTMLElement} - The button to exit point annotation mode */ | ||
exitButtonEl; | ||
|
||
/** @property {HTMLElement} - The button to cancel the pending thread */ | ||
cancelButtonEl; | ||
|
||
/** @property {HTMLElement} - The button to commit the pending thread */ | ||
postButtonEl; | ||
|
||
/** @inheritdoc */ | ||
init(data) { | ||
super.init(data); | ||
|
@@ -123,23 +117,7 @@ class PointModeController extends AnnotationModeController { | |
// Get handlers | ||
this.pushElementHandler(this.annotatedElement, ['mousedown', 'touchstart'], this.pointClickHandler); | ||
|
||
this.pushElementHandler(this.exitButtonEl, 'click', () => { | ||
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. These buttons don't actually exist in point annotation mode |
||
if (this.currentThread) { | ||
this.currentThread.cancelUnsavedAnnotation(); | ||
} | ||
|
||
this.toggleMode(); | ||
}); | ||
|
||
this.pushElementHandler(this.cancelButtonEl, 'click', () => { | ||
this.currentThread.cancelUnsavedAnnotation(); | ||
this.emit(CONTROLLER_EVENT.toggleMode); | ||
}); | ||
|
||
this.pushElementHandler(this.postButtonEl, 'click', () => { | ||
this.currentThread.saveAnnotation(TYPES.point); | ||
this.emit(CONTROLLER_EVENT.toggleMode); | ||
}); | ||
this.pushElementHandler(this.exitButtonEl, 'click', this.toggleMode); | ||
} | ||
|
||
/** @inheritdoc */ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,8 +78,8 @@ class DocDrawingThread extends DrawingThread { | |
page: location.page, | ||
dimensions: location.dimensions | ||
}; | ||
this.checkAndHandleScaleUpdate(); | ||
} | ||
this.checkAndHandleScaleUpdate(); | ||
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 should happen regardless of whether or not the thread page has been set already |
||
|
||
this.drawingFlag = DRAW_STATES.drawing; | ||
if (!this.pendingPath) { | ||
|
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.
Moving this into the {TYPE}DrawingThread logic