Skip to content
This repository has been archived by the owner on Oct 6, 2021. It is now read-only.

Commit

Permalink
towards a more flexible editor
Browse files Browse the repository at this point in the history
Syncs annotations on change in the editor.
Makes the annotation summary available from both steps of the marking task.
Allows the editor to be updated without remounting.
  • Loading branch information
eatyourgreens committed Aug 24, 2016
1 parent 0d5ffa4 commit 3c7034a
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 31 deletions.
2 changes: 1 addition & 1 deletion app/classify/annotation.cjsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ TextRange = React.createClass
displayName: 'TextRange'

render: ->
annotation = @props.range.annotation
annotation = @props.range?.annotation ? ''
<p className="text-selection">
{annotation.text}
</p>
Expand Down
73 changes: 50 additions & 23 deletions app/classify/classification-task.cjsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,34 @@ module.exports = React.createClass
when 'choose'
<div>
<ChooseTask onChooseTask={@create} onBack={@reset} onFinish={@finish} />
<AnnotationsSummary annotations={@state.annotations} deleteTool={@deleteAnnotation} onEdit={@edit} />
</div>
when 'edit'
<EditTask annotation={@state.annotations[0]} onChange={@props.onChange} onComplete={@choose}/>
<EditTask annotation={@state.annotations[0]} onChange={@onChange} onComplete={@choose}/>
}
</div>
</div>
{children}
<div className="readymade-decision-tree-container">
<div className="decision-tree">
{switch @state.step
when 'choose', 'edit'
<div>
<AnnotationsSummary annotations={@state.annotations} deleteTool={@deleteAnnotation} onEdit={@edit} />
</div>
}
</div>
</div>
</div>
</div>

onChange: (annotation) ->
@props.onChange annotation

annotations = @state.annotations
annotations.shift()
annotations.unshift annotation
@setState {annotations}

filter: (choice) ->
switch choice
when 'yes'
Expand All @@ -90,33 +107,20 @@ module.exports = React.createClass
instructions: tasks[type]

edit: (annotation) ->
annotation.issue?.el.classList.remove 'complete'
for type, ranges of annotation.subtasks
ranges.map (range) -> range.el.classList.remove 'complete'
@editAnnotation annotation
@setState
step: 'edit'
type: annotation.type
instructions: tasks[annotation.type]

if @state.step is 'edit'
@completeAnnotation @state.annotations[0], => @editAnnotation annotation
else
@editAnnotation annotation
@props.onChange annotation

choose: (annotation) ->
annotations = @state.annotations
annotations.shift()

if annotation.empty()
annotation.destroy()
else
annotation.issue?.el.classList.add 'complete'
for type, ranges of annotation.subtasks
ranges.map (range) -> range.el.classList.add 'complete'
annotations.unshift annotation
@completeAnnotation annotation

@setState
step: 'choose'
type: null
instructions: @defaultInstructions
annotations: annotations

@props.onChange new AnnotationTool

Expand Down Expand Up @@ -149,16 +153,39 @@ module.exports = React.createClass
@props.onChange annotation

editAnnotation: (annotation) ->
annotation.issue?.el.classList.remove 'complete'
for type, ranges of annotation.subtasks
ranges.map (range) -> range.el.classList.remove 'complete'

annotations = @state.annotations
index = annotations.indexOf annotation
annotations.splice index, 1
annotations.unshift annotation
@setState {annotations}

@setState
step: 'edit'
type: annotation.type
instructions: tasks[annotation.type]
annotations: annotations

deleteAnnotation: (annotation) ->
annotations = @state.annotations
index = annotations.indexOf annotation
annotations.splice index, 1
annotation.destroy()
@setState {annotations}

completeAnnotation: (annotation, callback = () -> ) ->
annotations = @state.annotations
annotations.shift()

if annotation.empty()
annotation.destroy()
else
annotation.issue?.el.classList.add 'complete'
for type, ranges of annotation.subtasks
ranges.map (range) -> range.el.classList.add 'complete'
annotations.unshift annotation

@setState {annotations}, callback


13 changes: 10 additions & 3 deletions app/classify/tasks/edit.cjsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ TextSelection = React.createClass
getDefaultProps: ->
range: {}

render: ->
<p className="text-selection"><button className="secret-button" aria-label='Delete' onClick={@delete}>X</button> {@props.range.annotation.text}</p>

delete: (e) ->
@props.onDelete @props.range

render: ->
<p className="text-selection">
<button className="secret-button" aria-label='Delete' onClick={@delete}>X</button>
{@props.range.annotation.text}
</p>

ToolList = React.createClass
displayName: 'ToolList'
Expand Down Expand Up @@ -71,6 +74,10 @@ module.exports = React.createClass
annotation = @props.annotation
@setState {annotation}

componentWillReceiveProps: (newProps) ->
annotation = newProps.annotation
@setState {annotation}

render: ->
{tools} = tasks[@props.annotation.type]
<div className="decision-tree-task">
Expand Down
6 changes: 2 additions & 4 deletions css/custom.styl
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@
background: #43bcfd

.readymade-subject-viewer-container
padding: 0 .5em

.readymade-subject-viewer
width: 55vw
max-width: 700px
background: #eee
background: rgba(256,256,230,0.75)

Expand Down Expand Up @@ -72,8 +71,7 @@


.readymade-decision-tree-container
padding-left: 0
padding-right: .5vw
padding: 0

.readymade-marking-surface-container
display: none
Expand Down

0 comments on commit 3c7034a

Please sign in to comment.