Skip to content

Commit

Permalink
Validate compatible frames for all selected models prior to displayin…
Browse files Browse the repository at this point in the history
…g frame selection dialog.

PP-71 PP-82
  • Loading branch information
lo5 committed May 15, 2014
1 parent 4b4e281 commit b2be635
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion client/src/scripts/model-selection-view.coffee
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
defaultScoringSelectionMessage = 'Score selected models.'
Steam.ModelSelectionView = (_) ->
_selections = nodes$ []
_hasSelection = lift$ _selections, (selections) -> selections.length > 0
_caption = lift$ _selections, (selections) ->
"#{describeCount selections.length, 'model'} selected."

_compatibleFrames = lift$ _selections, (selections) ->
framesPerModel = map selections, (selection) -> selection.data.compatible_frames
framesByKey = indexBy (flatten framesPerModel), (frame) -> frame.key
commonFrameKeys = sortBy intersection.apply null, map framesPerModel, (frames) -> map frames, (frame) -> frame.key
map commonFrameKeys, (key) -> framesByKey[key]

_canScoreSelections = lift$ _compatibleFrames, (frames) -> frames.length > 0

_modelSelectionMessage = lift$ _compatibleFrames, (frames) ->
if frames.length
defaultScoringSelectionMessage
else
'No compatible datasets found.'

scoreSelections = ->
_.promptForFrame (action, frameKey) ->
_.promptForFrame _compatibleFrames(), (action, frameKey) ->
switch action
when 'confirm'
scorings = map _selections(), (selection) ->
Expand All @@ -21,6 +36,9 @@ Steam.ModelSelectionView = (_) ->
when 'error'
_.fail 'Error', 'An error occured while fetching the list of datasets.', error, noop

tryScoreSelections = (hover) ->
_.status if hover then _modelSelectionMessage() else null

clearSelections = ->
_.deselectAllModels()

Expand All @@ -36,6 +54,8 @@ Steam.ModelSelectionView = (_) ->
caption: _caption
hasSelection: _hasSelection
clearSelections: clearSelections
canScoreSelections: _canScoreSelections
tryScoreSelections: tryScoreSelections
scoreSelections: scoreSelections
template: 'model-selection-view'

0 comments on commit b2be635

Please sign in to comment.