Bunch of fixes to the thang component edit view.

This commit is contained in:
Scott Erickson 2014-08-26 09:48:33 -07:00
parent 1406a970ea
commit 6091eaea6f
5 changed files with 25 additions and 18 deletions

View file

@ -10,9 +10,6 @@ module.exports = class ThangComponentConfigView extends CocoView
template: template
changed: false
events:
'click .treema-shortened': -> console.log 'clicked treema root'
constructor: (options) ->
super options
@component = options.component
@ -35,6 +32,7 @@ module.exports = class ThangComponentConfigView extends CocoView
setIsDefaultComponent: (isDefaultComponent) ->
changed = @isDefaultComponent isnt isDefaultComponent
if isDefaultComponent then @config = undefined
@isDefaultComponent = isDefaultComponent
@render() if changed
@ -44,7 +42,6 @@ module.exports = class ThangComponentConfigView extends CocoView
teams = _.filter(_.pluck(thangs, 'team'))
superteams = _.filter(_.pluck(thangs, 'superteam'))
superteams = _.union(teams, superteams)
config = $.extend true, {}, @config
schema = $.extend true, {}, @component.get('configSchema')
schema.default ?= {}
_.merge schema.default, @additionalDefaults if @additionalDefaults
@ -54,7 +51,7 @@ module.exports = class ThangComponentConfigView extends CocoView
treemaOptions =
supermodel: @supermodel
schema: schema
data: config
data: @config
callbacks: {change: @onConfigEdited}
world: @world
view: @
@ -83,6 +80,7 @@ module.exports = class ThangComponentConfigView extends CocoView
@$el.find('.panel-body').hide()
onConfigEdited: =>
@config = @editThangTreema.data
@changed = true
@trigger 'changed', { component: @component, config: @data() }

View file

@ -114,6 +114,11 @@ module.exports = class ThangComponentsEditView extends CocoView
for component in @components
componentMap[component.original] = component
thangComponentMap = {}
if thangTypeComponents = @thangType?.get('components')
for thangTypeComponent in thangTypeComponents
thangComponentMap[thangTypeComponent.original] = thangTypeComponent
# Deleting components missing dependencies.
while true
removedSomething = false
@ -121,7 +126,7 @@ module.exports = class ThangComponentsEditView extends CocoView
componentModel = @supermodel.getModelByOriginalAndMajorVersion(
LevelComponent, componentRef.original, componentRef.majorVersion)
for dependency in componentModel.get('dependencies') or []
if not componentMap[dependency.original]
unless (componentMap[dependency.original] or thangComponentMap[dependency.original])
delete componentMap[componentRef.original]
component = @supermodel.getModelByOriginal(
LevelComponent, componentRef.original)
@ -140,7 +145,7 @@ module.exports = class ThangComponentsEditView extends CocoView
# Delete individual component config views that are no longer included.
for subview in _.values(@subviews)
continue unless subview instanceof ThangComponentConfigView
if not componentMap[subview.component.get('original')]
unless (componentMap[subview.component.get('original')] or thangComponentMap[subview.component.get('original')])
@removeSubView(subview)
@updateComponentsList()
@ -157,6 +162,10 @@ module.exports = class ThangComponentsEditView extends CocoView
for component in @components
componentMap[component.original] = component
if thangTypeComponents = @thangType?.get('components')
for thangTypeComponent in thangTypeComponents
componentMap[thangTypeComponent.original] = thangTypeComponent
# Go through the map, adding missing dependencies.
while true
addedSomething = false
@ -213,7 +222,7 @@ module.exports = class ThangComponentsEditView extends CocoView
else
modifiedRef = _.merge {}, thangTypeComponent
modifiedRef.additionalDefaults = modifiedRef.config
delete modifiedRef.additionalDefaults
delete modifiedRef.config
componentRefs[thangTypeComponent.original] = modifiedRef
for componentRef in _.values(componentRefs)
@ -255,7 +264,12 @@ module.exports = class ThangComponentsEditView extends CocoView
majorVersion: e.component.get('version').major
config: e.config
})
@onComponentsChanged()
for subview in _.values(@subviews)
continue unless subview instanceof ThangComponentConfigView
if subview.component.get('original') is e.component.get('original')
_.defer -> subview.setIsDefaultComponent(false)
break
@updateComponentsList()
@reportChanges()
@ -291,11 +305,6 @@ module.exports = class ThangComponentsEditView extends CocoView
subview.$el[0].scrollIntoView()
break
onComponentConfigChanged: (data) =>
@updatingFromConfig = true
@selectedRow.set '/config', data if data and @configView.changed and @configView.editing
@updatingFromConfig = false
onChangeExtantComponents: =>
@buildAddComponentTreema()
@reportChanges()

View file

@ -36,11 +36,13 @@ module.exports = class LevelThangEditView extends CocoView
onLoaded: -> @render()
afterRender: ->
super()
thangType = @supermodel.getModelByOriginal(ThangType, @thangData.thangType)
options =
components: @thangData.components
supermodel: @supermodel
level: @level
world: @world
thangType: thangType
@thangComponentEditView = new ThangComponentsEditView options
@listenTo @thangComponentEditView, 'components-changed', @onComponentsChanged

View file

@ -52,14 +52,12 @@ describe 'ThangComponentsEditView', ->
# TODO: Figure out why this is breaking karma but not always
it 'adds dependencies to its components list', ->
# jasmine.Ajax.requests.sendResponses(responses)
componentOriginals = (c.original for c in view.components)
expect('A' in componentOriginals).toBeTruthy()
expect('B' in componentOriginals).toBeTruthy()
expect('C' in componentOriginals).toBeTruthy()
it 'removes components that are dependent on a removed component', ->
# jasmine.Ajax.requests.sendResponses(responses)
view.components = (c for c in view.components when c.original isnt 'A')
view.onComponentsChanged()
expect(view.components.length).toBe(0)

View file

@ -50,8 +50,8 @@ module.exports = ->
]
thangType: new ThangType({
components: [
{ original: 'C', majorVersion: 0, config: {propD: 'Default property from thang type component.'} }
{ original: 'D', majorVersion: 0 }
{ original: 'A', majorVersion: 0, config: {propD: 'Default property from thang type component.'} }
{ original: 'D', majorVersion: 0, config: {prop1: 'one', prop2: 'two'} }
]
})
})