Set up the tabs and views in the level editor to reload so that when patches are applied, their changes are visible.

This commit is contained in:
Scott Erickson 2014-04-17 14:23:33 -07:00
parent 781a8ec913
commit cdaf2ebfaf
12 changed files with 53 additions and 15 deletions

View file

@ -16,4 +16,11 @@
bottom: 0
top: 35px
border: 2px solid black
border-top: none
border-top: none
.inner-editor
position: absolute
left: 0
right: 0
bottom: 0
top: 0px

View file

@ -10,3 +10,10 @@
top: 35px
border: 2px solid black
border-top: none
.inner-editor
position: absolute
left: 0
right: 0
bottom: 0
top: 0px

View file

@ -1,3 +1,3 @@
.patches-view
.status-buttons
margin: 10px 0
margin-bottom: 10px

View file

@ -1,11 +1,11 @@
nav.navbar.navbar-default(role='navigation')
ul.nav.navbar-nav.nav-tabs
li.active
a(href="#component-code" data-toggle="tab" data-i18n="general.code") Code
a(href="#component-code" data-toggle="tab" data-i18n="general.code")#component-code-tab Code
li
a(href="#component-config-schema" data-toggle="tab" data-i18n="editor.level_component_config_schema") Config Schema
a(href="#component-config-schema" data-toggle="tab" data-i18n="editor.level_component_config_schema")#component-config-schema-tab Config Schema
li
a(href="#component-settings" data-toggle="tab" data-i18n="editor.level_component_settings") Settings
a(href="#component-settings" data-toggle="tab" data-i18n="editor.level_component_settings")#component-settings-tab Settings
li
a(href="#component-patches" data-toggle="tab" data-i18n="resources.patches")#component-patches-tab Patches

View file

@ -2,11 +2,11 @@ nav.navbar.navbar-default(role='navigation')
ul.nav.navbar-nav.nav-tabs
li.active
a(href="#system-code" data-toggle="tab") Code
a(href="#system-code" data-toggle="tab")#system-code-tab Code
li
a(href="#system-config-schema" data-toggle="tab") Config Schema
a(href="#system-config-schema" data-toggle="tab")#system-config-schema-tab Config Schema
li
a(href="#system-settings" data-toggle="tab") Settings
a(href="#system-settings" data-toggle="tab")#system-settings-tab Settings
li
a(href="#system-patches" data-toggle="tab" data-i18n="resources.patches")#system-patches-tab Patches

View file

@ -6,6 +6,7 @@ block modal-header-content
block modal-body-content
.modal-body
p= patch.get('commitMessage')
.changes-stub

View file

@ -14,6 +14,9 @@ module.exports = class LevelComponentEditView extends View
'click #done-editing-component-button': 'endEditing'
'click .nav a': (e) -> $(e.target).tab('show')
'click #component-patches-tab': -> @patchesView.load()
'click #component-code-tab': 'buildCodeEditor'
'click #component-config-schema-tab': 'buildConfigSchemaTreema'
'click #component-settings-tab': 'buildSettingsTreema'
'click #component-history-button': 'showVersionHistory'
'click #patch-component-button': 'startPatchingComponent'
'click #component-watch-button': 'toggleWatchComponent'
@ -76,8 +79,9 @@ module.exports = class LevelComponentEditView extends View
Backbone.Mediator.publish 'level-component-edited', levelComponent: @levelComponent
buildCodeEditor: ->
editorEl = @$el.find '#component-code-editor'
editorEl.text @levelComponent.get('code')
@editor?.destroy()
editorEl = $('<div></div>').text(@levelComponent.get('code')).addClass('inner-editor')
@$el.find('#component-code-editor').empty().append(editorEl)
@editor = ace.edit(editorEl[0])
session = @editor.getSession()
session.setMode 'ace/mode/coffee'

View file

@ -31,7 +31,14 @@ module.exports = class EditorLevelView extends View
'click #patches-tab': -> @patchesView.load()
'click #level-patch-button': 'startPatchingLevel'
'click #level-watch-button': 'toggleWatchLevel'
subscriptions:
'refresh-level-editor': 'rerenderAllViews'
rerenderAllViews: ->
for view in [@thangsTab, @settingsTab, @scriptsTab, @componentsTab, @systemsTab, @patchesView]
view.render()
constructor: (options, @levelID) ->
super options
@listenToOnce(@supermodel, 'loaded-all', @onAllLoaded)
@ -94,6 +101,7 @@ module.exports = class EditorLevelView extends View
Backbone.Mediator.publish 'level-loaded', level: @level
@showReadOnly() if me.get('anonymous')
@patchesView = @insertSubView(new PatchesView(@level), @$el.find('.patches-view'))
@listenTo @patchesView, 'accepted-patch', -> location.reload()
@$el.find('#level-watch-button').find('> span').toggleClass('secret') if @level.watching()
onPlayLevel: (e) ->

View file

@ -14,6 +14,9 @@ module.exports = class LevelSystemEditView extends View
'click #done-editing-system-button': 'endEditing'
'click .nav a': (e) -> $(e.target).tab('show')
'click #system-patches-tab': -> @patchesView.load()
'click #system-code-tab': 'buildCodeEditor'
'click #system-config-schema-tab': 'buildConfigSchemaTreema'
'click #system-settings-tab': 'buildSettingsTreema'
'click #system-history-button': 'showVersionHistory'
'click #patch-system-button': 'startPatchingSystem'
'click #system-watch-button': 'toggleWatchSystem'
@ -76,8 +79,9 @@ module.exports = class LevelSystemEditView extends View
Backbone.Mediator.publish 'level-system-edited', levelSystem: @levelSystem
buildCodeEditor: ->
editorEl = @$el.find '#system-code-editor'
editorEl.text @levelSystem.get('code')
@editor?.destroy()
editorEl = $('<div></div>').text(@levelSystem.get('code')).addClass('inner-editor')
@$el.find('#system-code-editor').empty().append(editorEl)
@editor = ace.edit(editorEl[0])
@editor.setReadOnly(not me.isAdmin())
session = @editor.getSession()

View file

@ -7,6 +7,7 @@ module.exports = class PatchModal extends ModalView
id: "patch-modal"
template: template
plain: true
modalWidthPercent: 60
events:
'click #withdraw-button': 'withdrawPatch'
@ -30,12 +31,15 @@ module.exports = class PatchModal extends ModalView
c.isPatchCreator = @patch.get('creator') is auth.me.id
c.isPatchRecipient = @targetModel.hasWriteAccess()
c.status = @patch.get 'status'
c.patch = @patch
c
afterRender: ->
return if @originalSource.loading
headModel = @originalSource.clone(false)
headModel.set(@targetModel.attributes)
headModel = null
if @targetModel.hasWriteAccess()
headModel = @originalSource.clone(false)
headModel.set(@targetModel.attributes)
pendingModel = @originalSource.clone(false)
pendingModel.applyDelta(@patch.get('delta'))
@ -49,6 +53,7 @@ module.exports = class PatchModal extends ModalView
delta = @deltaView.getApplicableDelta()
@targetModel.applyDelta(delta)
@targetModel.addPatchToAcceptOnSave(@patch)
@trigger 'accepted-patch'
@hide()
rejectPatch: ->

View file

@ -53,4 +53,5 @@ module.exports = class PatchesView extends CocoView
openPatchModal: (e) ->
patch = _.find @patches.models, {id:$(e.target).data('patch-id')}
modal = new PatchModal(patch, @model)
@openModalView(modal)
@openModalView(modal)
@listenTo modal, 'accepted-patch', -> @trigger 'accepted-patch'

View file

@ -8,6 +8,7 @@ module.exports = class SaveVersionModal extends ModalView
id: 'save-version-modal'
template: template
plain: true
modalWidthPercent: 60
events:
'click #save-version-button': 'onClickSaveButton'