mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-27 17:45:40 -05:00
Fixed up showing errors, made sure they work with the play view.
This commit is contained in:
parent
7640a6365b
commit
6cd7c723d8
9 changed files with 41 additions and 21 deletions
|
@ -686,3 +686,9 @@
|
|||
user_profile: "User Profile"
|
||||
patches: "Patches"
|
||||
model: "Model"
|
||||
system: "System"
|
||||
component: "Component"
|
||||
thang: "Thang"
|
||||
level_session: "Your Session"
|
||||
opponent_session: "Opponent Session"
|
||||
article: "Article"
|
||||
|
|
|
@ -16,6 +16,7 @@ class CocoModel extends Backbone.Model
|
|||
@markToRevert()
|
||||
@addSchemaDefaults()
|
||||
@once 'sync', @onLoaded, @
|
||||
@on 'error', @onError, @
|
||||
@saveBackup = _.debounce(@saveBackup, 500)
|
||||
|
||||
type: ->
|
||||
|
@ -27,6 +28,9 @@ class CocoModel extends Backbone.Model
|
|||
clone.set($.extend(true, {}, if withChanges then @attributes else @_revertAttributes))
|
||||
clone
|
||||
|
||||
onError: ->
|
||||
@loading = false
|
||||
|
||||
onLoaded: ->
|
||||
@loaded = true
|
||||
@loading = false
|
||||
|
|
|
@ -109,6 +109,9 @@ module.exports = class SuperModel extends Backbone.Model
|
|||
|
||||
getProgress: -> return @progress
|
||||
|
||||
getResource: (rid) ->
|
||||
return @resources[rid]
|
||||
|
||||
|
||||
|
||||
class Resource extends Backbone.Model
|
||||
|
@ -131,9 +134,10 @@ class Resource extends Backbone.Model
|
|||
return if @isLoaded
|
||||
@trigger('failed', {resource: @})
|
||||
@isLoaded = @isLoading = false
|
||||
@isFailed = true
|
||||
|
||||
markLoading: ->
|
||||
@isLoaded = false
|
||||
@isLoaded = @isFailed = false
|
||||
@isLoading = true
|
||||
|
||||
load: -> @
|
||||
|
|
|
@ -168,15 +168,18 @@ a[data-toggle="modal"]
|
|||
.icon-cog.big
|
||||
background-position: 0px 0px
|
||||
|
||||
// loading screens for everything but the play view
|
||||
.loading-screen
|
||||
text-align: center
|
||||
.progress
|
||||
width: 50%
|
||||
margin: 0 25%
|
||||
|
||||
// all loading screens
|
||||
.loading-container
|
||||
text-align: center
|
||||
.progress-bar
|
||||
width: 0%
|
||||
transition: width 0.1s ease
|
||||
|
||||
.errors .alert
|
||||
padding: 5px
|
||||
display: block
|
||||
|
@ -184,6 +187,7 @@ a[data-toggle="modal"]
|
|||
.btn
|
||||
margin-left: 10px
|
||||
|
||||
|
||||
.modal
|
||||
overflow-y: auto !important
|
||||
.wait
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
.loading-screen
|
||||
.loading-screen.loading-container
|
||||
h1(data-i18n="common.loading") Loading...
|
||||
.progress
|
||||
.progress-bar
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
strong(data-i18n="loading_error.unknown") Unknown error.
|
||||
|
||||
if resourceIndex !== undefined
|
||||
button.btn.btn-sm.retry-loading-resource(data-i18n="common.retry", data-resource-index=resourceIndex) Retry
|
||||
button.btn.btn-xs.retry-loading-resource(data-i18n="common.retry", data-resource-index=resourceIndex) Retry
|
||||
if requestIndex !== undefined
|
||||
button.btn.btn-sm.retry-loading-request(data-i18n="common.retry", data-request-index=requestIndex) Retry
|
||||
button.btn.btn-xs.retry-loading-request(data-i18n="common.retry", data-request-index=requestIndex) Retry
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
.right-wing
|
||||
|
||||
.loading-details
|
||||
.loading-details.loading-container
|
||||
|
||||
.load-progress
|
||||
.progress.progress-striped.active
|
||||
|
@ -40,3 +40,6 @@
|
|||
strong.tip.rare
|
||||
span(data-i18n='play_level.tip_harry') Yer a Wizard,
|
||||
span= me.get('name') || 'Anoner'
|
||||
|
||||
.errors
|
||||
|
|
@ -116,22 +116,24 @@ module.exports = class CocoView extends Backbone.View
|
|||
|
||||
updateProgressBar: (progress) =>
|
||||
prog = "#{parseInt(progress*100)}%"
|
||||
@$el?.find('.loading-screen .progress-bar').css('width', prog)
|
||||
@$el?.find('.loading-container .progress-bar').css('width', prog)
|
||||
|
||||
onLoaded: -> @render()
|
||||
|
||||
# Error handling for loading
|
||||
onResourceLoadFailed: (source) ->
|
||||
# console.debug 'gintau', 'onResourceLoadFailed', source
|
||||
@$el.find('.loading-screen .errors').append(loadingErrorTemplate({
|
||||
status: 'error',
|
||||
name: source.resource.name
|
||||
resourceIndex: source.resource.rid,
|
||||
responseText: source.error
|
||||
onResourceLoadFailed: (e) ->
|
||||
r = e.resource
|
||||
@$el.find('.loading-container .errors').append(loadingErrorTemplate({
|
||||
status: r.jqxhr?.status
|
||||
name: r.name
|
||||
resourceIndex: r.rid,
|
||||
responseText: r.jqxhr?.responseText
|
||||
})).i18n()
|
||||
|
||||
onRetryResource: (e) ->
|
||||
res = @supermodel.getResource($(e.target).data('resource-index'))
|
||||
# different views may respond to this call, and not all have the resource to reload
|
||||
return unless res and res.isFailed
|
||||
res.load()
|
||||
$(e.target).closest('.loading-error-alert').remove()
|
||||
|
||||
|
|
|
@ -111,7 +111,6 @@ module.exports = class PlayLevelView extends View
|
|||
load: ->
|
||||
@loadStartTime = new Date()
|
||||
@levelLoader = new LevelLoader supermodel: @supermodel, levelID: @levelID, sessionID: @sessionID, opponentSessionID: @getQueryVariable('opponent'), team: @getQueryVariable("team")
|
||||
# @listenTo(@levelLoader, 'progress', @onLevelLoaderProgressChanged) # TODO NOW: transfer to supermodel system
|
||||
@god = new God()
|
||||
|
||||
getRenderData: ->
|
||||
|
@ -154,8 +153,6 @@ module.exports = class PlayLevelView extends View
|
|||
_.defer => @onLevelLoaded()
|
||||
|
||||
onLevelLoaded: ->
|
||||
console.debug 'level_view', 'onLevelLoaderLoaded', @levelLoader.progress()
|
||||
|
||||
return unless @levelLoader.progress() is 1 # double check, since closing the guide may trigger this early
|
||||
@loadingView.showReady()
|
||||
if window.currentModal and not window.currentModal.destroyed
|
||||
|
|
Loading…
Reference in a new issue