Skip to content
This repository was archived by the owner on May 21, 2018. It is now read-only.

Commit

Permalink
Merge pull request #717 from hansonrobotics/settings_fix
Browse files Browse the repository at this point in the history
Settings fix
  • Loading branch information
vytasrgl authored May 9, 2017
2 parents fb64532 + 3e596d3 commit ee7b540
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 25 deletions.
31 changes: 21 additions & 10 deletions src/webui/client/modules/performances/views/node_select.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ define(['application', 'marionette', './templates/node_select.tpl', '../entities
if (this.model.hasProperty('rosnode')) {
this.changeRosNode()
this.listenTo(this.model, 'change:rosnode', function() {
self.model.unset('schema')
self.model.unset('values')
self.changeRosNode(true)
})
}
Expand Down Expand Up @@ -294,18 +296,25 @@ define(['application', 'marionette', './templates/node_select.tpl', '../entities
changeRosNode: function(reset) {
let self = this,
rosnode = this.model.get('rosnode'),
schema = new NodeConfigSchema(rosnode)
schemaModel = new NodeConfigSchema({}, {node_name: rosnode}),
schema = this.model.get('schema')

if (reset) this.model.set('values', {})

schema.fetch({
success: function(model) {
self.showNodeSettings(model)
},
error: function() {
self.model.set('schema', {})
}
})
if (schema) {
schemaModel.set(schema)
self.showNodeSettings(schemaModel)
} else
schemaModel.fetch({
success: function() {
let json = schemaModel.toJSON()
self.model.set('schema', json)
self.showNodeSettings(schemaModel)
},
error: function() {
self.model.set('schema', {})
}
})
},
showNodeSettings: function(schemaModel) {
let self = this,
Expand All @@ -323,8 +332,10 @@ define(['application', 'marionette', './templates/node_select.tpl', '../entities

let updateValues = function() {
let currentView = self.getRegion('settingsEditor').currentView
if (currentView && currentView.model === nodeConfig)
if (currentView && currentView.model === nodeConfig) {
self.model.set('values', nodeConfig.toJSON())
self.model.set('node_schema', nodeConfig.toJSON())
}
else
nodeConfig.off('change', updateValues)
}
Expand Down
2 changes: 1 addition & 1 deletion src/webui/client/modules/settings/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ define(['application', './views/layout', './views/settings', './entities/robot_c

node = decodeURIComponent(node)
let nodeConfig = new NodeConfig({}, {node_name: node}),
nodeConfigSchema = new NodeConfigSchema(node)
nodeConfigSchema = new NodeConfigSchema({}, {node_name: node})

nodeConfig.fetch()
nodeConfigSchema.fetch({
Expand Down
37 changes: 25 additions & 12 deletions src/webui/client/modules/settings/entities/node_config_schema.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
define(['backbone', 'lib/api', './node_config'], function(Backbone, api, NodeConfig) {
return Backbone.Model.extend({
initialize: function(node_name) {
this.node_name = node_name
initialize: function(attributes, options) {
options = options || {}
this.node_name = options['node_name'] || null
this.on('change', this.updateGroupNames)
},
sync: function(method, self, options) {
if (method === 'read') {
Expand Down Expand Up @@ -47,25 +49,22 @@ define(['backbone', 'lib/api', './node_config'], function(Backbone, api, NodeCon
}
}
},
getSchemaFromDescription: function(description, prefix) {
prefix = prefix || 'root.'

getSchemaFromDescription: function(description) {
let self = this,
properties = this.getSchemaFromParams(description.parameters, prefix)
properties = this.getSchemaFromParams(description.parameters)

_.each(description.groups, function(group, name) {
properties[name] = {
type: 'object',
title: group.name,
properties: self.getSchemaFromDescription(group, prefix + name + '.')
properties: self.getSchemaFromDescription(group)
}
})

return properties
},
getSchemaFromParams(params, prefix) {
let self = this,
schema = {}
getSchemaFromParams(params) {
let schema = {}

$.each(params, function(i, param) {
// hide node schema field
Expand Down Expand Up @@ -112,17 +111,31 @@ define(['backbone', 'lib/api', './node_config'], function(Backbone, api, NodeCon
if ($.isNumeric(param.max)) property.maximum = param.max

schema[param.name] = property
self.groupNames[param.name] = prefix + param.name
})

return schema
},
groupNames: {},
getGroupName: function(name) {
return name in this.groupNames ? this.groupNames[name] : name
},
getAllKeys: function() {
return _.keys(this.groupNames)
},
updateGroupNames: function() {
this.groupNames = {}
this.crawlProperties('', 'root', this.attributes)
// remove root
delete this.groupNames['root']
},
crawlProperties: function(prefix, name, value) {
this.groupNames[name] = prefix + name

if (value['type'] === 'object') {
let properties = value['properties']
for (let key in properties)
if (properties.hasOwnProperty(key))
this.crawlProperties(prefix + name + '.', key, properties[key])
}
}
})
})
9 changes: 7 additions & 2 deletions src/webui/client/modules/settings/views/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,13 @@ define(['application', 'marionette', './templates/settings.tpl', 'json-editor',
})

this.setConfig()
this.editor.on('change', function() {
self.update()
let init = true
self.editor.on('change', function() {
// skip the first update since it is tiggered before values are properly set
if (init)
init = false
else
self.update()
})

if (this.options.refresh)
Expand Down

0 comments on commit ee7b540

Please sign in to comment.