Improve CampaignEditor saving, particularly level order

* Do not cache campaign
* Instead have an on leave message if there are unsaved changes
* Propagate campaignIndex values to campaign and levels so that they signal a change in order

 The save modal seems to have a lot of issues with identifying what models have
 changed. I tried using different methods, but none were consistent. Moving on
 to other bugs.
This commit is contained in:
Scott Erickson 2016-05-31 15:08:09 -07:00
parent d36908f8c1
commit d4c5d418ff
4 changed files with 23 additions and 3 deletions

View file

@ -8,7 +8,6 @@ module.exports = class Campaign extends CocoModel
@className: 'Campaign'
@schema: schema
urlRoot: '/db/campaign'
saveBackups: true
@denormalizedLevelProperties: _.keys(_.omit(schema.properties.levels.additionalProperties.properties, ['unlocks', 'position', 'rewards']))
@denormalizedCampaignProperties: ['name', 'i18n', 'slug']

View file

@ -60,6 +60,14 @@ module.exports = class CampaignEditorView extends RootView
@listenToOnce @levels, 'sync', @onFundamentalLoaded
@listenToOnce @achievements, 'sync', @onFundamentalLoaded
onLeaveMessage: ->
@propagateCampaignIndexes()
for model in @toSave.models
diff = model.getDelta()
if _.size(diff)
console.log 'model, diff', model, diff
return 'You have changes!'
loadThangTypeNames: ->
# Load the names of the ThangTypes that this level's Treema nodes might want to display.
originals = []
@ -143,6 +151,19 @@ module.exports = class CampaignEditorView extends RootView
@updateRewardsForLevel model, level.rewards
super()
propagateCampaignIndexes: ->
campaignLevels = $.extend({}, @campaign.get('levels'))
index = 0
for levelOriginal, campaignLevel of campaignLevels
level = @levels.findWhere({original: levelOriginal})
if level.get('campaignIndex') isnt index
level.set('campaignIndex', index)
campaignLevel.campaignIndex = index
index += 1
@campaign.set('levels', campaignLevels)
onClickPatches: (e) ->
@patchesView = @insertSubView(new PatchesView(@campaign), @$el.find('.patches-view'))
@ -160,6 +181,7 @@ module.exports = class CampaignEditorView extends RootView
break
onClickSaveButton: ->
@propagateCampaignIndexes()
@toSave.set @toSave.filter (m) -> m.hasLocalChanges()
@openModalView new SaveCampaignModal({}, @toSave)

View file

@ -80,7 +80,6 @@ module.exports = class CampaignView extends RootView
return
@campaign = new Campaign({_id:@terrain})
@campaign.saveBackups = @editorMode
@campaign = @supermodel.loadModel(@campaign).model
# Temporary attempt to make sure all earned rewards are accounted for. Figure out a better solution...

View file

@ -79,4 +79,4 @@ module.exports =
for original, level of campaign.levels
campaign.levels[original] = _.pick level, ['locked', 'disabled', 'original', 'rewards', 'slug']
return campaign
res.status(200).send((formatCampaign(campaign) for campaign in campaigns))
res.status(200).send((formatCampaign(campaign) for campaign in campaigns))