Skip to content

Commit

Permalink
Added default names for pipelines, data, ops. Fixes #172 (#182)
Browse files Browse the repository at this point in the history
  • Loading branch information
brollb committed Jun 1, 2016
1 parent e5acb09 commit 716b4aa
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/visualizers/panels/ForgeActionButton/Actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,23 @@ define([
],
create = {};

var getUniqueName = function(parentId, basename) {
var pNode = this.client.getNode(parentId),
children = pNode.getChildrenIds().map(id => this.client.getNode(id)),
name = basename,
exists = {},
i = 2;

children.forEach(child => exists[child.getAttribute('name')] = true);

while (exists[name]) {
name = basename + '_' + i;
i++;
}

return name;
};

var createNew = function(type, metasheetName) {
// Create CNN node in the current dir
// Get CNN node type
Expand All @@ -33,6 +50,17 @@ define([

this.client.startTransaction('Created new operation prototype');
newId = this.client.createChild({parentId, baseId});

// Name the new node
var basename = 'New' + this.client.getNode(baseId).getAttribute('name'),
newName = getUniqueName.call(this, parentId, basename);

// If instance, make the first char lowercase
if (!metasheetName) {
newName = newName.substring(0, 1).toLowerCase() + newName.substring(1);
}

this.client.setAttributes(newId, 'name', newName);
if (metasheetName) { // Add to metasheet
var root = this.client.getNode(CONSTANTS.PROJECT_ROOT_ID),
metatabs = root.getRegistry(REGISTRY_KEYS.META_SHEETS),
Expand Down

0 comments on commit 716b4aa

Please sign in to comment.