Merge pull request #1192 from codecombat/master

Master into production
This commit is contained in:
Michael Schmatz 2014-06-19 08:36:59 -07:00
commit 1535f36d87
9 changed files with 68 additions and 15 deletions

View file

@ -37,6 +37,19 @@
<script src="/javascripts/aether.js"></script> <script src="/javascripts/aether.js"></script>
<script src="/javascripts/app.js"></script> <!-- it's all Backbone! --> <script src="/javascripts/app.js"></script> <!-- it's all Backbone! -->
<script>
window.linkedInAsyncInit = function() {
console.log("Linkedin Async Init!");
Backbone.Mediator.publish('linkedin-loaded');
};
</script>
<script type="text/javascript" async src="http://platform.linkedin.com/in.js">
api_key: 75v8mv4ictvmx6
onLoad: linkedInAsyncInit
authorize: true
</script>
<script> <script>
window.userObject = "userObjectTag"; window.userObject = "userObjectTag";
</script> </script>

View file

@ -124,6 +124,8 @@ module.exports = class God extends CocoClass
console.log "|#{@nick}'s debugger|", event.data.args... console.log "|#{@nick}'s debugger|", event.data.args...
when 'debug-value-return' when 'debug-value-return'
Backbone.Mediator.publish 'god:debug-value-return', event.data.serialized Backbone.Mediator.publish 'god:debug-value-return', event.data.serialized
when 'debug-world-load-progress-changed'
Backbone.Mediator.publish 'god:debug-world-load-progress-changed', event.data
onNewWorldCreated: (e) -> onNewWorldCreated: (e) ->
@currentUserCodeMap = @filterUserCodeMapWhenFromWorld e.world.userCodeMap @currentUserCodeMap = @filterUserCodeMapWhenFromWorld e.world.userCodeMap

View file

@ -1,12 +1,9 @@
module.exports = initializeLinkedIn = -> module.exports = initializeLinkedIn = ->
window.linkedInAsyncInit = -> window.linkedInAsyncInit = ->
console.log "Linkedin async init success!"
Backbone.Mediator.publish 'linkedin-loaded' Backbone.Mediator.publish 'linkedin-loaded'
linkedInSnippet = linkedInSnippet =
'<script type="text/javascript" async src="http://platform.linkedin.com/in.js"> ''
api_key: 75v8mv4ictvmx6
onLoad: linkedInAsyncInit
authorize: true
</script>'
$('head').append(linkedInSnippet) $('head').append(linkedInSnippet)

View file

@ -8,4 +8,11 @@
padding: 10px padding: 10px
background: transparent url(/images/level/popover_background.png) background: transparent url(/images/level/popover_background.png)
background-size: 100% 100% background-size: 100% 100%
.progress
position: relative
span
position: absolute
display: block
color: black
width: 100%

View file

@ -1,2 +1,6 @@
div.progress
.progress-bar(role="progressbar", aria-valuenow="50", aria-valuemin="0", aria-valuemax="100")
span Inspecting variable...
pre pre
code code

View file

@ -14,6 +14,7 @@ module.exports = class DebugView extends View
subscriptions: subscriptions:
'god:new-world-created': 'onNewWorld' 'god:new-world-created': 'onNewWorld'
'god:debug-value-return': 'handleDebugValue' 'god:debug-value-return': 'handleDebugValue'
'god:debug-world-load-progress-changed': 'handleWorldLoadProgressChanged'
'tome:spell-shown': 'changeCurrentThangAndSpell' 'tome:spell-shown': 'changeCurrentThangAndSpell'
'tome:cast-spells': 'onTomeCast' 'tome:cast-spells': 'onTomeCast'
'surface:frame-changed': 'onFrameChanged' 'surface:frame-changed': 'onFrameChanged'
@ -26,6 +27,7 @@ module.exports = class DebugView extends View
@ace = options.ace @ace = options.ace
@thang = options.thang @thang = options.thang
@spell = options.spell @spell = options.spell
@progress = 0
@variableStates = {} @variableStates = {}
@globals = {Math: Math, _: _, String: String, Number: Number, Array: Array, Object: Object} # ... add more as documented @globals = {Math: Math, _: _, String: String, Number: Number, Array: Array, Object: Object} # ... add more as documented
for className, serializedClass of serializedClasses for className, serializedClass of serializedClasses
@ -36,6 +38,7 @@ module.exports = class DebugView extends View
@lastFrameRequested = -1 @lastFrameRequested = -1
@workerIsSimulating = false @workerIsSimulating = false
@spellHasChanged = false @spellHasChanged = false
@debouncedTooltipUpdate = _.debounce @updateTooltipProgress, 100
@ -50,15 +53,30 @@ module.exports = class DebugView extends View
setTooltipKeyAndValue: (key, value) => setTooltipKeyAndValue: (key, value) =>
@hideProgressBarAndShowText()
message = "Time: #{@calculateCurrentTimeString()}\n#{key}: #{value}" message = "Time: #{@calculateCurrentTimeString()}\n#{key}: #{value}"
@$el.find("code").text message @$el.find("code").text message
@$el.show().css(@pos) @$el.show().css(@pos)
setTooltipText: (text) => setTooltipText: (text) =>
#perhaps changing styling here in the future #perhaps changing styling here in the future
@hideProgressBarAndShowText()
@$el.find("code").text text @$el.find("code").text text
@$el.show().css(@pos) @$el.show().css(@pos)
setTooltipProgress: (progress) =>
@showProgressBarAndHideText()
@$el.find(".progress-bar").css('width',progress + '%').attr 'aria-valuenow', progress
@$el.show().css(@pos)
showProgressBarAndHideText: ->
@$el.find("pre").css("display","none")
@$el.find(".progress").css("display","block")
hideProgressBarAndShowText: ->
@$el.find("pre").css("display","block")
@$el.find(".progress").css("display","none")
onTomeCast: -> onTomeCast: ->
@invalidateCache() @invalidateCache()
@ -91,6 +109,8 @@ module.exports = class DebugView extends View
if @variableChain and not key is @variableChain.join(".") then return if @variableChain and not key is @variableChain.join(".") then return
@setTooltipKeyAndValue(key,value) @setTooltipKeyAndValue(key,value)
handleWorldLoadProgressChanged: (data) ->
@progress = data.progress
afterRender: -> afterRender: ->
super() super()
@ -141,6 +161,11 @@ module.exports = class DebugView extends View
@variableChain = @markerRange = null @variableChain = @markerRange = null
@update() @update()
updateTooltipProgress: =>
if @variableChain and @progress < 1
@setTooltipProgress(@progress * 100)
_.delay @updateTooltipProgress, 100
onNewWorld: (e) -> onNewWorld: (e) ->
@thang = @options.thang = e.world.thangMap[@thang.id] if @thang @thang = @options.thang = e.world.thangMap[@thang.id] if @thang
@frameRate = e.world.frameRate @frameRate = e.world.frameRate
@ -148,6 +173,7 @@ module.exports = class DebugView extends View
onFrameChanged: (data) -> onFrameChanged: (data) ->
@currentFrame = data.frame @currentFrame = data.frame
@frameRate = data.world.frameRate @frameRate = data.world.frameRate
onSpellChangedCalculation: (data) -> onSpellChangedCalculation: (data) ->
@spellHasChanged = data.hasChangedSignificantly @spellHasChanged = data.hasChangedSignificantly
@ -159,8 +185,8 @@ module.exports = class DebugView extends View
@setTooltipKeyAndValue(@variableChain.join("."),@stringifyValue(@thang[@variableChain[1]],0)) @setTooltipKeyAndValue(@variableChain.join("."),@stringifyValue(@thang[@variableChain[1]],0))
else if @variableChain.length is 1 and Aether.globals[@variableChain[0]] else if @variableChain.length is 1 and Aether.globals[@variableChain[0]]
@setTooltipKeyAndValue(@variableChain.join("."),@stringifyValue(Aether.globals[@variableChain[0]],0)) @setTooltipKeyAndValue(@variableChain.join("."),@stringifyValue(Aether.globals[@variableChain[0]],0))
else if @workerIsSimulating else if @workerIsSimulating and @progress < 1
@setTooltipText("World is simulating, please wait...") @debouncedTooltipUpdate()
else if @currentFrame is @lastFrameRequested and (cacheValue = @retrieveValueFromCache(@thang.id, @spell.name, @variableChain, @currentFrame)) else if @currentFrame is @lastFrameRequested and (cacheValue = @retrieveValueFromCache(@thang.id, @spell.name, @variableChain, @currentFrame))
@setTooltipKeyAndValue(@variableChain.join("."),cacheValue) @setTooltipKeyAndValue(@variableChain.join("."),cacheValue)
else else
@ -171,7 +197,8 @@ module.exports = class DebugView extends View
frame: @currentFrame frame: @currentFrame
if @currentFrame isnt @lastFrameRequested then @workerIsSimulating = true if @currentFrame isnt @lastFrameRequested then @workerIsSimulating = true
@lastFrameRequested = @currentFrame @lastFrameRequested = @currentFrame
@setTooltipText("Finding value...") @progress = 0
@debouncedTooltipUpdate()
else else
@$el.hide() @$el.hide()
if @variableChain?.length is 2 if @variableChain?.length is 2

View file

@ -9,6 +9,7 @@ class LevelSessionHandler extends Handler
editableProperties: ['multiplayer', 'players', 'code', 'codeLanguage', 'completed', 'state', editableProperties: ['multiplayer', 'players', 'code', 'codeLanguage', 'completed', 'state',
'levelName', 'creatorName', 'levelID', 'screenshot', 'levelName', 'creatorName', 'levelID', 'screenshot',
'chat', 'teamSpells', 'submitted', 'unsubscribed','playtime'] 'chat', 'teamSpells', 'submitted', 'unsubscribed','playtime']
privateProperties: ['code', 'submittedCode', 'unsubscribed']
jsonSchema: require '../../../app/schemas/models/level_session' jsonSchema: require '../../../app/schemas/models/level_session'
getByRelationship: (req, res, args...) -> getByRelationship: (req, res, args...) ->
@ -20,7 +21,7 @@ class LevelSessionHandler extends Handler
if req.user.isAdmin() or req.user.id is document.creator or ('employer' in req.user.get('permissions')) if req.user.isAdmin() or req.user.id is document.creator or ('employer' in req.user.get('permissions'))
return documentObject return documentObject
else else
return _.omit documentObject, ['submittedCode','code'] return _.omit documentObject, @privateProperties
getActiveSessions: (req, res) -> getActiveSessions: (req, res) ->
return @sendUnauthorizedError(res) unless req.user.isAdmin() return @sendUnauthorizedError(res) unless req.user.isAdmin()

View file

@ -236,12 +236,14 @@ UserHandler = class UserHandler extends Handler
@sendSuccess(res, documents) @sendSuccess(res, documents)
getLevelSessions: (req, res, userID) -> getLevelSessions: (req, res, userID) ->
return @sendUnauthorizedError(res) unless req.user._id+'' is userID or req.user.isAdmin()
query = creator: userID query = creator: userID
isAuthorized = req.user._id+'' is userID or req.user.isAdmin()
projection = null projection = null
if req.query.project if req.query.project
projection = {} projection = {}
projection[field] = 1 for field in req.query.project.split(',') projection[field] = 1 for field in req.query.project.split(',') when isAuthorized or not (field in LevelSessionHandler.privateProperties)
# If no req.query.project, then LevelSessionHandler.formatEntity will remove private properties if needed.
LevelSession.find(query).select(projection).exec (err, documents) => LevelSession.find(query).select(projection).exec (err, documents) =>
return @sendDatabaseError(res, err) if err return @sendDatabaseError(res, err) if err
documents = (LevelSessionHandler.formatEntity(req, doc) for doc in documents) documents = (LevelSessionHandler.formatEntity(req, doc) for doc in documents)