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) =>
|
||||
_.extend namesCache, newNames
|
||||
|
||||
getName: (id) -> namesCache[id].name
|
||||
getName: (id) -> namesCache[id]?.name or id
|
||||
|
||||
module.exports = new NameLoader()
|
||||
|
|
|
@ -211,7 +211,9 @@ class CocoModel extends Backbone.Model
|
|||
jsondiffpatch.patch newAttributes, delta
|
||||
catch error
|
||||
console.error "Error applying delta", delta, "to attributes", newAttributes, error
|
||||
return false
|
||||
@set newAttributes
|
||||
return true
|
||||
|
||||
getExpandedDelta: ->
|
||||
delta = @getDelta()
|
||||
|
|
|
@ -7,7 +7,10 @@ block modal-header-content
|
|||
block modal-body-content
|
||||
.modal-body
|
||||
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
|
||||
|
|
|
@ -8,7 +8,7 @@ module.exports = class PatchModal extends ModalView
|
|||
template: template
|
||||
plain: true
|
||||
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:
|
||||
'click #withdraw-button': 'withdrawPatch'
|
||||
|
@ -24,29 +24,32 @@ module.exports = class PatchModal extends ModalView
|
|||
@originalSource = new @targetModel.constructor({_id:targetID})
|
||||
@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: ->
|
||||
c = super()
|
||||
c.isPatchCreator = @patch.get('creator') is auth.me.id
|
||||
c.isPatchRecipient = @targetModel.hasWriteAccess()
|
||||
c.status = @patch.get 'status'
|
||||
c.patch = @patch
|
||||
c.deltaWorked = @deltaWorked
|
||||
c
|
||||
|
||||
afterRender: ->
|
||||
return unless @supermodel.finished()
|
||||
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
|
||||
pendingModel.applyDelta(@patch.get('delta'))
|
||||
pendingModel.loaded = true
|
||||
|
||||
@deltaView = new DeltaView({model:pendingModel, headModel:headModel, skipPaths: PatchModal.DOC_SKIP_PATHS})
|
||||
return super() unless @supermodel.finished() and @deltaWorked
|
||||
@deltaView = new DeltaView({model:@pendingModel, headModel:@headModel, skipPaths: PatchModal.DOC_SKIP_PATHS})
|
||||
changeEl = @$el.find('.changes-stub')
|
||||
@insertSubView(@deltaView, changeEl)
|
||||
super()
|
||||
|
|
Loading…
Reference in a new issue