mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-30 19:06:59 -05:00
Patch modal handles invalid patches.
This commit is contained in:
parent
2cdd7c4115
commit
9b873cfab4
4 changed files with 25 additions and 17 deletions
|
@ -18,6 +18,6 @@ class NameLoader extends CocoClass
|
||||||
loadedNames: (newNames) =>
|
loadedNames: (newNames) =>
|
||||||
_.extend namesCache, newNames
|
_.extend namesCache, newNames
|
||||||
|
|
||||||
getName: (id) -> namesCache[id].name
|
getName: (id) -> namesCache[id]?.name or id
|
||||||
|
|
||||||
module.exports = new NameLoader()
|
module.exports = new NameLoader()
|
||||||
|
|
|
@ -211,7 +211,9 @@ class CocoModel extends Backbone.Model
|
||||||
jsondiffpatch.patch newAttributes, delta
|
jsondiffpatch.patch newAttributes, delta
|
||||||
catch error
|
catch error
|
||||||
console.error "Error applying delta", delta, "to attributes", newAttributes, error
|
console.error "Error applying delta", delta, "to attributes", newAttributes, error
|
||||||
|
return false
|
||||||
@set newAttributes
|
@set newAttributes
|
||||||
|
return true
|
||||||
|
|
||||||
getExpandedDelta: ->
|
getExpandedDelta: ->
|
||||||
delta = @getDelta()
|
delta = @getDelta()
|
||||||
|
|
|
@ -7,7 +7,10 @@ block modal-header-content
|
||||||
block modal-body-content
|
block modal-body-content
|
||||||
.modal-body
|
.modal-body
|
||||||
p= patch.get('commitMessage')
|
p= patch.get('commitMessage')
|
||||||
.changes-stub
|
if deltaWorked
|
||||||
|
.changes-stub
|
||||||
|
else
|
||||||
|
.alert.alert-danger Could not apply this delta to the current version.
|
||||||
|
|
||||||
|
|
||||||
block modal-footer
|
block modal-footer
|
||||||
|
|
|
@ -8,7 +8,7 @@ module.exports = class PatchModal extends ModalView
|
||||||
template: template
|
template: template
|
||||||
plain: true
|
plain: true
|
||||||
modalWidthPercent: 60
|
modalWidthPercent: 60
|
||||||
@DOC_SKIP_PATHS = ['_id','version', 'commitMessage', 'parent', 'created', 'slug', 'index', '__v', 'patches']
|
@DOC_SKIP_PATHS = ['_id','version', 'commitMessage', 'parent', 'created', 'slug', 'index', '__v', 'patches', 'creator']
|
||||||
|
|
||||||
events:
|
events:
|
||||||
'click #withdraw-button': 'withdrawPatch'
|
'click #withdraw-button': 'withdrawPatch'
|
||||||
|
@ -23,6 +23,20 @@ module.exports = class PatchModal extends ModalView
|
||||||
else
|
else
|
||||||
@originalSource = new @targetModel.constructor({_id:targetID})
|
@originalSource = new @targetModel.constructor({_id:targetID})
|
||||||
@supermodel.loadModel @originalSource, 'source_document'
|
@supermodel.loadModel @originalSource, 'source_document'
|
||||||
|
|
||||||
|
onLoaded: ->
|
||||||
|
@headModel = null
|
||||||
|
if @targetModel.hasWriteAccess()
|
||||||
|
@headModel = @originalSource.clone(false)
|
||||||
|
@headModel.markToRevert true
|
||||||
|
@headModel.set(@targetModel.attributes)
|
||||||
|
@headModel.loaded = true
|
||||||
|
|
||||||
|
@pendingModel = @originalSource.clone(false)
|
||||||
|
@pendingModel.markToRevert true
|
||||||
|
@deltaWorked = @pendingModel.applyDelta(@patch.get('delta'))
|
||||||
|
@pendingModel.loaded = true
|
||||||
|
super()
|
||||||
|
|
||||||
getRenderData: ->
|
getRenderData: ->
|
||||||
c = super()
|
c = super()
|
||||||
|
@ -30,23 +44,12 @@ module.exports = class PatchModal extends ModalView
|
||||||
c.isPatchRecipient = @targetModel.hasWriteAccess()
|
c.isPatchRecipient = @targetModel.hasWriteAccess()
|
||||||
c.status = @patch.get 'status'
|
c.status = @patch.get 'status'
|
||||||
c.patch = @patch
|
c.patch = @patch
|
||||||
|
c.deltaWorked = @deltaWorked
|
||||||
c
|
c
|
||||||
|
|
||||||
afterRender: ->
|
afterRender: ->
|
||||||
return unless @supermodel.finished()
|
return super() unless @supermodel.finished() and @deltaWorked
|
||||||
headModel = null
|
@deltaView = new DeltaView({model:@pendingModel, headModel:@headModel, skipPaths: PatchModal.DOC_SKIP_PATHS})
|
||||||
if @targetModel.hasWriteAccess()
|
|
||||||
headModel = @originalSource.clone(false)
|
|
||||||
headModel.markToRevert true
|
|
||||||
headModel.set(@targetModel.attributes)
|
|
||||||
headModel.loaded = true
|
|
||||||
|
|
||||||
pendingModel = @originalSource.clone(false)
|
|
||||||
pendingModel.markToRevert true
|
|
||||||
pendingModel.applyDelta(@patch.get('delta'))
|
|
||||||
pendingModel.loaded = true
|
|
||||||
|
|
||||||
@deltaView = new DeltaView({model:pendingModel, headModel:headModel, skipPaths: PatchModal.DOC_SKIP_PATHS})
|
|
||||||
changeEl = @$el.find('.changes-stub')
|
changeEl = @$el.find('.changes-stub')
|
||||||
@insertSubView(@deltaView, changeEl)
|
@insertSubView(@deltaView, changeEl)
|
||||||
super()
|
super()
|
||||||
|
|
Loading…
Reference in a new issue