codecombat/app/views/play/level/tome/problem.coffee

49 lines
1.5 KiB
CoffeeScript
Raw Normal View History

2014-01-03 13:32:13 -05:00
ProblemAlertView = require './problem_alert_view'
Range = ace.require("ace/range").Range
module.exports = class Problem
annotation: null
alertView: null
markerRange: null
constructor: (@aether, @aetherProblem, @ace, withAlert=false, withRange=false) ->
@buildAnnotation()
@buildAlertView() if withAlert
@buildMarkerRange() if withRange
destroy: ->
unless @alertView?.destroyed
@alertView?.$el?.remove()
@alertView?.destroy()
2014-01-03 13:32:13 -05:00
@removeMarkerRange()
buildAnnotation: ->
2014-05-08 14:43:00 -04:00
return unless @aetherProblem.range
2014-01-03 13:32:13 -05:00
text = @aetherProblem.message.replace /^Line \d+: /, ''
2014-05-08 14:43:00 -04:00
start = @aetherProblem.range[0]
2014-01-03 13:32:13 -05:00
@annotation =
row: start.row,
column: start.col,
2014-01-03 13:32:13 -05:00
raw: text,
text: text,
type: @aetherProblem.level ? "error"
buildAlertView: ->
@alertView = new ProblemAlertView problem: @
@alertView.render()
$(@ace.container).append @alertView.el
buildMarkerRange: ->
2014-05-08 14:43:00 -04:00
return unless @aetherProblem.range
[start, end] = @aetherProblem.range
2014-01-03 13:32:13 -05:00
clazz = "problem-marker-#{@aetherProblem.level}"
@markerRange = new Range start.row, start.col, end.row, end.col
2014-01-03 13:32:13 -05:00
@markerRange.start = @ace.getSession().getDocument().createAnchor @markerRange.start
@markerRange.end = @ace.getSession().getDocument().createAnchor @markerRange.end
@markerRange.id = @ace.getSession().addMarker @markerRange, clazz, "text"
removeMarkerRange: ->
return unless @markerRange
@ace.getSession().removeMarker @markerRange.id
@markerRange.start.detach()
@markerRange.end.detach()