Skip to content

Commit

Permalink
Remove ChangeListener from classifier (#3520)
Browse files Browse the repository at this point in the history
Update annotations in component state on classification change instead.
  • Loading branch information
eatyourgreens authored Mar 2, 2017
1 parent af80b8b commit 7bf6e09
Showing 1 changed file with 43 additions and 39 deletions.
82 changes: 43 additions & 39 deletions app/classifier/index.cjsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
React = require 'react'
apiClient = require 'panoptes-client/lib/api-client'
ChangeListener = require '../components/change-listener'
SubjectViewer = require '../components/subject-viewer'
`import ClassificationSummary from './classification-summary';`
{Link} = require 'react-router'
Expand Down Expand Up @@ -59,6 +58,7 @@ Classifier = React.createClass
showingExpertClassification: false
subjectLoading: false
renderIntervention: false
annotations: []

disableIntervention: ->
@setState renderIntervention: false
Expand All @@ -85,10 +85,16 @@ Classifier = React.createClass

componentWillMount: () ->
interventionMonitor.setProjectSlug @props.project.slug
@props.classification.listen 'change', =>
{annotations} = @props.classification
@setState {annotations}

componentWillUnmount: () ->
interventionMonitor.removeListener 'interventionRequested', @enableIntervention
interventionMonitor.removeListener 'classificationTaskRequested', @disableIntervention
@props.classification.stopListening 'change', =>
{annotations} = @props.classification
@setState {annotations}
try
@context.geordi?.forget ['subjectID']

Expand Down Expand Up @@ -146,45 +152,43 @@ Classifier = React.createClass
largeFormatImage = @props.workflow.configuration.image_layout and 'no-max-height' in @props.workflow.configuration.image_layout
classifierClassNames = if largeFormatImage then "classifier large-image" else "classifier"

<ChangeListener target={@props.classification}>{=>
if @state.showingExpertClassification
currentClassification = @state.expertClassification
else
currentClassification = @props.classification
unless @props.classification.completed
currentAnnotation = currentClassification.annotations[currentClassification.annotations.length - 1]
currentTask = @props.workflow.tasks[currentAnnotation?.task]

# This is just easy access for debugging.
window.classification = currentClassification

<div className={classifierClassNames} >
<SubjectViewer
user={@props.user}
project={@props.project}
subject={@props.subject}
workflow={@props.workflow}
preferences={@props.preferences}
classification={currentClassification}
annotation={currentAnnotation}
onLoad={@handleSubjectImageLoad}
frameWrapper={FrameAnnotator}
allowFlipbook={workflowAllowsFlipbook @props.workflow}
allowSeparateFrames={workflowAllowsSeparateFrames @props.workflow}
onChange={@handleAnnotationChange.bind this, currentClassification}
playIterations={@props.workflow?.configuration.playIterations}
/>

<div className="task-area">
{if currentTask?
@renderTask currentClassification, currentAnnotation, currentTask
else if @subjectIsGravitySpyGoldStandard()
@renderGravitySpyGoldStandard currentClassification
else if not @props.workflow.configuration?.hide_classification_summaries # Classification is complete; show summary if enabled
@renderSummary currentClassification}
</div>
if @state.showingExpertClassification
currentClassification = @state.expertClassification
else
currentClassification = @props.classification
unless @props.classification.completed
currentAnnotation = @state.annotations[@state.annotations.length - 1]
currentTask = @props.workflow.tasks[currentAnnotation?.task]

# This is just easy access for debugging.
window.classification = currentClassification

<div className={classifierClassNames} >
<SubjectViewer
user={@props.user}
project={@props.project}
subject={@props.subject}
workflow={@props.workflow}
preferences={@props.preferences}
classification={currentClassification}
annotation={currentAnnotation}
onLoad={@handleSubjectImageLoad}
frameWrapper={FrameAnnotator}
allowFlipbook={workflowAllowsFlipbook @props.workflow}
allowSeparateFrames={workflowAllowsSeparateFrames @props.workflow}
onChange={@handleAnnotationChange.bind this, currentClassification}
playIterations={@props.workflow?.configuration.playIterations}
/>

<div className="task-area">
{if currentTask?
@renderTask currentClassification, currentAnnotation, currentTask
else if @subjectIsGravitySpyGoldStandard()
@renderGravitySpyGoldStandard currentClassification
else if not @props.workflow.configuration?.hide_classification_summaries # Classification is complete; show summary if enabled
@renderSummary currentClassification}
</div>
}</ChangeListener>
</div>

renderTask: (classification, annotation, task) ->
disableTalk = @props.classification.metadata.subject_flagged?
Expand Down

0 comments on commit 7bf6e09

Please sign in to comment.