Skip to content

Commit

Permalink
WIP #541 Added setter support in CreateTorchMeta
Browse files Browse the repository at this point in the history
  • Loading branch information
brollb committed Jul 26, 2016
1 parent 6ee51bf commit 500d776
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 27 deletions.
3 changes: 0 additions & 3 deletions src/common/layer-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,6 @@
}
})(fn);

console.log('getting class attrs, vals for', method.self.val, method.key.val);
console.log('class defs:', dict);
return dict;
};

Expand Down Expand Up @@ -161,7 +159,6 @@
}
})(fn);

console.log('dict:', dict);
return dict;
};

Expand Down
72 changes: 48 additions & 24 deletions src/plugins/CreateTorchMeta/CreateTorchMeta.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,18 @@
/*globals define*/
/*jshint node:true, browser:true*/

/**
* Generated by PluginGenerator 0.14.0 from webgme on Tue Mar 15 2016 21:19:45 GMT-0500 (CDT).
*/

define([
'plugin/PluginConfig',
'plugin/PluginBase',
'deepforge/js-yaml.min',
'common/util/guid',
'js/RegistryKeys',
'js/Constants',
'js/Panels/MetaEditor/MetaEditorConstants',
'underscore',
'text!deepforge/layers.json',
'text!./metadata.json'
], function (
PluginConfig,
PluginBase,
yaml,
generateGuid,
REGISTRY_KEYS,
CONSTANTS,
META_CONSTANTS,
_,
DEFAULT_LAYERS,
Expand Down Expand Up @@ -148,9 +138,9 @@ define([
categories.forEach(cat => {
content[cat]
.forEach(layer => {
var attrs = layer.params,
name = layer.name;
nodes[name] = this.createMetaNode(name, nodes[cat], cat, attrs);
var name = layer.name;

nodes[name] = this.createMetaNode(name, nodes[cat], cat, layer);
// Make the node non-abstract
this.core.setRegistry(nodes[name], 'isAbstract', false);
});
Expand Down Expand Up @@ -222,12 +212,25 @@ define([
}
};

CreateTorchMeta.prototype.createMetaNode = function (name, base, tabName, attrs) {
var isBoolean = txt => {
return typeof txt === 'boolean' || (txt === 'false' || txt === 'true');
};

CreateTorchMeta.prototype.createMetaNode = function (name, base, tabName, layer) {
var node = this.META[name],
nodeId = node && this.core.getPath(node),
tabId = this.metaSheets[tabName],
position = this.getPositionFor(name, tabName);

position = this.getPositionFor(name, tabName),
setters = {},
defaults = {},
attrs,
desc;

if (layer) {
attrs = layer.params;
setters = layer.setters;
defaults = layer.defaults;
}
if (!tabId) {
this.logger.error(`No meta sheet for ${tabName}`);
}
Expand Down Expand Up @@ -272,7 +275,8 @@ define([
rmAttrs;

rmAttrs = _.difference(currentAttrs, attrs) // old attribute names
.filter(attr => attr !== 'name');
.filter(attr => attr !== 'name')
.filter(attr => !setters[attr]);

if (rmAttrs.length) {
this.logger.debug(`Removing ${rmAttrs.join(', ')} from ${name}`);
Expand All @@ -285,9 +289,34 @@ define([
});

attrs.forEach((name, index) => {
var desc = {};
desc = {};
desc.argindex = index;
desc.default = '';
desc.default = defaults.hasOwnProperty(name) ? defaults[name] : '';
this.addAttribute(name, node, desc);
});

// Add the setters to the meta
Object.keys(setters).forEach(name => {
var values;
desc = setters[name];
desc.default = defaults.hasOwnProperty(name) ? defaults[name] : '';
if (desc.setterType === 'const') {
values = Object.keys(desc.setterFn);
desc.isEnum = true;
desc.enumValues = values;
if (values.every(isBoolean)) {
if (!defaults.hasOwnProperty(name) && values.length === 1) {
// there is only a method to toggle the flag to true/false,
// then the default must be the other one
desc.default = values[0] === 'true' ? false : true;
}

if (isBoolean(desc.default)) {
this.logger.debug(`setting ${name} to boolean`);
desc.type = 'boolean';
}
}
}
this.addAttribute(name, node, desc);
});
}
Expand Down Expand Up @@ -341,11 +370,6 @@ define([
schema.max = +def.max;
}

// Add the infer flag
if (def.infer) {
schema.infer = def.infer;
}

// Add the argindex flag
schema.argindex = def.argindex;

Expand Down

0 comments on commit 500d776

Please sign in to comment.