Don't save duplicate user code problems
This commit is contained in:
parent
a65dabad04
commit
f75ff8a236
2 changed files with 26 additions and 20 deletions
app/views/play/level/tome
|
@ -1,6 +1,5 @@
|
||||||
ProblemAlertView = require './ProblemAlertView'
|
ProblemAlertView = require './ProblemAlertView'
|
||||||
Range = ace.require('ace/range').Range
|
Range = ace.require('ace/range').Range
|
||||||
UserCodeProblem = require 'models/UserCodeProblem'
|
|
||||||
|
|
||||||
module.exports = class Problem
|
module.exports = class Problem
|
||||||
annotation: null
|
annotation: null
|
||||||
|
@ -11,7 +10,6 @@ module.exports = class Problem
|
||||||
@buildAlertView() if withAlert
|
@buildAlertView() if withAlert
|
||||||
@buildMarkerRange() if isCast
|
@buildMarkerRange() if isCast
|
||||||
Backbone.Mediator.publish("problem:problem-created", line:@annotation.row, text: @annotation.text) if application.isIPadApp
|
Backbone.Mediator.publish("problem:problem-created", line:@annotation.row, text: @annotation.text) if application.isIPadApp
|
||||||
@saveUserCodeProblem() if isCast
|
|
||||||
|
|
||||||
destroy: ->
|
destroy: ->
|
||||||
unless @alertView?.destroyed
|
unless @alertView?.destroyed
|
||||||
|
@ -50,21 +48,3 @@ module.exports = class Problem
|
||||||
@ace.getSession().removeMarker @markerRange.id
|
@ace.getSession().removeMarker @markerRange.id
|
||||||
@markerRange.start.detach()
|
@markerRange.start.detach()
|
||||||
@markerRange.end.detach()
|
@markerRange.end.detach()
|
||||||
|
|
||||||
saveUserCodeProblem: () ->
|
|
||||||
@userCodeProblem = new UserCodeProblem()
|
|
||||||
@userCodeProblem.set 'code', @aether.raw
|
|
||||||
if @aetherProblem.range
|
|
||||||
rawLines = @aether.raw.split '\n'
|
|
||||||
errorLines = rawLines.slice @aetherProblem.range[0].row, @aetherProblem.range[1].row + 1
|
|
||||||
@userCodeProblem.set 'codeSnippet', errorLines.join '\n'
|
|
||||||
@userCodeProblem.set 'errHint', @aetherProblem.hint if @aetherProblem.hint
|
|
||||||
@userCodeProblem.set 'errId', @aetherProblem.id if @aetherProblem.id
|
|
||||||
@userCodeProblem.set 'errLevel', @aetherProblem.level if @aetherProblem.level
|
|
||||||
@userCodeProblem.set 'errMessage', @aetherProblem.message if @aetherProblem.message
|
|
||||||
@userCodeProblem.set 'errRange', @aetherProblem.range if @aetherProblem.range
|
|
||||||
@userCodeProblem.set 'errType', @aetherProblem.type if @aetherProblem.type
|
|
||||||
@userCodeProblem.set 'language', @aether.language.id if @aether.language?.id
|
|
||||||
@userCodeProblem.set 'levelID', @levelID if @levelID
|
|
||||||
@userCodeProblem.save()
|
|
||||||
null
|
|
|
@ -8,6 +8,7 @@ Problem = require './Problem'
|
||||||
SpellDebugView = require './SpellDebugView'
|
SpellDebugView = require './SpellDebugView'
|
||||||
SpellToolbarView = require './SpellToolbarView'
|
SpellToolbarView = require './SpellToolbarView'
|
||||||
LevelComponent = require 'models/LevelComponent'
|
LevelComponent = require 'models/LevelComponent'
|
||||||
|
UserCodeProblem = require 'models/UserCodeProblem'
|
||||||
|
|
||||||
module.exports = class SpellView extends CocoView
|
module.exports = class SpellView extends CocoView
|
||||||
id: 'spell-view'
|
id: 'spell-view'
|
||||||
|
@ -63,6 +64,7 @@ module.exports = class SpellView extends CocoView
|
||||||
@listenTo(@session, 'change:multiplayer', @onMultiplayerChanged)
|
@listenTo(@session, 'change:multiplayer', @onMultiplayerChanged)
|
||||||
@spell = options.spell
|
@spell = options.spell
|
||||||
@problems = []
|
@problems = []
|
||||||
|
@savedProblems = {} # Cache saved user code problems to prevent duplicates
|
||||||
@writable = false unless me.team in @spell.permissions.readwrite # TODO: make this do anything
|
@writable = false unless me.team in @spell.permissions.readwrite # TODO: make this do anything
|
||||||
@highlightCurrentLine = _.throttle @highlightCurrentLine, 100
|
@highlightCurrentLine = _.throttle @highlightCurrentLine, 100
|
||||||
$(window).on 'resize', @onWindowResize
|
$(window).on 'resize', @onWindowResize
|
||||||
|
@ -486,6 +488,7 @@ module.exports = class SpellView extends CocoView
|
||||||
continue if key = aetherProblem.userInfo?.key and key of seenProblemKeys
|
continue if key = aetherProblem.userInfo?.key and key of seenProblemKeys
|
||||||
seenProblemKeys[key] = true if key
|
seenProblemKeys[key] = true if key
|
||||||
@problems.push problem = new Problem aether, aetherProblem, @ace, isCast and problemIndex is 0, isCast, @spell.levelID
|
@problems.push problem = new Problem aether, aetherProblem, @ace, isCast and problemIndex is 0, isCast, @spell.levelID
|
||||||
|
@saveUserCodeProblem(aether, aetherProblem) if isCast
|
||||||
annotations.push problem.annotation if problem.annotation
|
annotations.push problem.annotation if problem.annotation
|
||||||
@aceSession.setAnnotations annotations
|
@aceSession.setAnnotations annotations
|
||||||
@highlightCurrentLine aether.flow unless _.isEmpty aether.flow
|
@highlightCurrentLine aether.flow unless _.isEmpty aether.flow
|
||||||
|
@ -498,6 +501,29 @@ module.exports = class SpellView extends CocoView
|
||||||
Backbone.Mediator.publish 'tome:problems-updated', spell: @spell, problems: @problems, isCast: isCast
|
Backbone.Mediator.publish 'tome:problems-updated', spell: @spell, problems: @problems, isCast: isCast
|
||||||
@ace.resize()
|
@ace.resize()
|
||||||
|
|
||||||
|
saveUserCodeProblem: (aether, aetherProblem) ->
|
||||||
|
# Skip duplicate problems
|
||||||
|
hashValue = aether.raw + aetherProblem.message
|
||||||
|
return if hashValue of @savedProblems
|
||||||
|
@savedProblems[hashValue] = true
|
||||||
|
# Save new problem
|
||||||
|
@userCodeProblem = new UserCodeProblem()
|
||||||
|
@userCodeProblem.set 'code', aether.raw
|
||||||
|
if aetherProblem.range
|
||||||
|
rawLines = aether.raw.split '\n'
|
||||||
|
errorLines = rawLines.slice aetherProblem.range[0].row, aetherProblem.range[1].row + 1
|
||||||
|
@userCodeProblem.set 'codeSnippet', errorLines.join '\n'
|
||||||
|
@userCodeProblem.set 'errHint', aetherProblem.hint if aetherProblem.hint
|
||||||
|
@userCodeProblem.set 'errId', aetherProblem.id if aetherProblem.id
|
||||||
|
@userCodeProblem.set 'errLevel', aetherProblem.level if aetherProblem.level
|
||||||
|
@userCodeProblem.set 'errMessage', aetherProblem.message if aetherProblem.message
|
||||||
|
@userCodeProblem.set 'errRange', aetherProblem.range if aetherProblem.range
|
||||||
|
@userCodeProblem.set 'errType', aetherProblem.type if aetherProblem.type
|
||||||
|
@userCodeProblem.set 'language', aether.language.id if aether.language?.id
|
||||||
|
@userCodeProblem.set 'levelID', @spell.levelID if @spell.levelID
|
||||||
|
@userCodeProblem.save()
|
||||||
|
null
|
||||||
|
|
||||||
# Autocast:
|
# Autocast:
|
||||||
# Goes immediately if the code is a) changed and b) complete/valid and c) the cursor is at beginning or end of a line
|
# Goes immediately if the code is a) changed and b) complete/valid and c) the cursor is at beginning or end of a line
|
||||||
# We originally thought it would:
|
# We originally thought it would:
|
||||||
|
|
Reference in a new issue