Skip to content

Commit

Permalink
Fix output properties
Browse files Browse the repository at this point in the history
  • Loading branch information
HexyWitch committed May 20, 2015
1 parent 2ffe90d commit e02b6c5
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 26 deletions.
10 changes: 5 additions & 5 deletions src/app/node/modal-addnode.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,24 @@ <h1 class="modal-title">Add Custom Node</h1>
</table>
</div>

<div class="row" id="addnode-outputs" style="display: none;">
<div class="row" id="addnode-output" style="display: none;">
<label class="clearfix">
<span class="left">Outputs</span>
<span class="left">Output</span>
<a href="#" ng-click="addOutput()" class="button success right">+</a>
</label>

<table id="addnode-outputs-table">
<table id="addnode-output-table">
<tbody>
</tbody>
</table>
</div>

<div class="row">
<div class="row" id="addnode-category" style="display: none;">
<label>Category</label>
<input id="category" type="text" placeholder="category"/>
</div>

<div class="row">
<div class="row" id="addnode-script" style="display: none;">
<label>Script</label>
<input id="script" type="text" placeholder="script"/>
</div>
Expand Down
11 changes: 8 additions & 3 deletions src/app/node/modal-editnode.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,19 @@ <h1 class="modal-title">Edit Custom Node</h1>
</table>
</div>

<div class="row" id="editnode-outputs" ng-show="node.prototype.type == 'action'">
<div class="row" id="editnode-output" ng-show="node.prototype.type == 'action'">
<label class="clearfix">
<span class="left">Outputs</span>
<span class="left">Output</span>
<a href="#" ng-click="addOutput()" class="button success right">+</a>
</label>

<table id="editnode-outputs-table">
<table id="editnode-output-table">
<tbody>
<tr ng-repeat="(key, value) in output">
<td><input id="key" type="text" value="{{key}}" placeholder="key" /></td>
<td><input id="value" type="text" value="{{value}}" placeholder="value" /></td>
<td><a href="#" propertyremovable class="button alert right">-</a></td>
</tr>
</tbody>
</table>
</div>
Expand Down
54 changes: 39 additions & 15 deletions src/app/node/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,16 +114,30 @@ angular.module('app.node', ['app.modal'])
propertiesTable.append($compile(template)($scope));
}

$scope.changeType = function() {
var outputsTable = angular.element(
document.querySelectorAll('#addnode-outputs')
$scope.addOutput = function(key, value) {
if (typeof key == 'undefined') key = '';
if (typeof value == 'undefined') value = '';
var template = this_.propertyTemplate.format(key, value);
var outputTable = angular.element(
document.querySelectorAll('#addnode-output-table>tbody')
);
outputTable.append($compile(template)($scope));
}

$scope.changeType = function() {
var outputTable = angular.element(document.querySelector('#addnode-output'));
var categoryRow = angular.element(document.querySelector('#addnode-script'));
var scriptRow = angular.element(document.querySelector('#addnode-category'));
var domType = document.querySelector('#addnode-modal #type');

if (domType.value == 'action') {
outputsTable.css('display', 'block');
outputTable.css('display', 'block');
categoryRow.css('display', 'block');
scriptRow.css('display', 'block');
} else {
outputsTable.css('display', 'none');
outputTable.css('display', 'none');
categoryRow.css('display', 'none');
scriptRow.css('display', 'none');
}
}

Expand All @@ -142,20 +156,20 @@ angular.module('app.node', ['app.modal'])
}

if (newNode.type == 'action'){
var domOutputKeys = document.querySelectorAll('#addnode-outputs #key');
var domOutputValues = document.querySelectorAll('#addnode-outputs #value');
var domOutputKeys = document.querySelectorAll('#addnode-output #key');
var domOutputValues = document.querySelectorAll('#addnode-output #value');
var domCategory = document.querySelector('#addnode-modal #category');
var domScript = document.querySelector('#addnode-modal #script');

newNode.script = domScript.value;
newNode.category = domCategory.value;
newNode.outputs = {};
newNode.output = {};

for (var i=0; i<domOutputKeys.length; i++) {
var key = domOutputKeys[i].value;
var value = domOutputValues[i].value;
if (key)
newNode.outputs[key] = value;
newNode.output[key] = value;
}
}

Expand All @@ -181,7 +195,7 @@ angular.module('app.node', ['app.modal'])
var key = domOutputKeys[i].value;
var value = domOutputValues[i].value;
if (key)
newNode.outputs[key] = value;
newNode.output[key] = value;
}

if (newNode.name) {
Expand Down Expand Up @@ -219,6 +233,7 @@ angular.module('app.node', ['app.modal'])
}

$scope.properties = this.jsonProperties($scope.node.prototype.properties);
$scope.output = $scope.node.prototype.output;

this.propertyTemplate = '\
<tr>\
Expand All @@ -241,6 +256,16 @@ angular.module('app.node', ['app.modal'])
propertiesTable.append($compile(template)($scope));
}

$scope.addOutput = function(key, value) {
if (typeof key == 'undefined') key = '';
if (typeof value == 'undefined') value = '';
var template = this_.propertyTemplate.format(key, value);
var outputTable = angular.element(
document.querySelectorAll('#editnode-output-table>tbody')
);
outputTable.append($compile(template)($scope));
}

$scope.saveNode = function() {
var domName = document.querySelector('#editnode-form #name');
var domTitle = document.querySelector('#editnode-form #title');
Expand All @@ -254,9 +279,8 @@ angular.module('app.node', ['app.modal'])
}

if ($scope.node.prototype.type == 'action'){
console.log("ARawd")
var domOutputKeys = document.querySelectorAll('#editnode-outputs #key');
var domOutputValues = document.querySelectorAll('#editnode-outputs #value');
var domOutputKeys = document.querySelectorAll('#editnode-output #key');
var domOutputValues = document.querySelectorAll('#editnode-output #value');
var domCategory = document.querySelector('#editnode-modal #category');
var domScript = document.querySelector('#editnode-modal #script');

Expand All @@ -265,13 +289,13 @@ angular.module('app.node', ['app.modal'])
if (domCategory.value != '')
newNode.category = domCategory.value;
if (domOutputKeys.length > 0)
newNode.outputs = {};
newNode.output = {};

for (var i=0; i<domOutputKeys.length; i++) {
var key = domOutputKeys[i].value;
var value = domOutputValues[i].value;
if (key)
newNode.outputs[key] = value;
newNode.output[key] = value;
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/editor/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,8 @@ this.b3editor = this.b3editor || {};
data[name].category = node.prototype.category;
if (node.prototype.script)
data[name].script = node.prototype.script;
if (node.prototype.outputs)
data[name].outputs = JSON.parse(JSON.stringify(node.prototype.outputs));
if (node.prototype.output)
data[name].output = JSON.parse(JSON.stringify(node.prototype.output));
}
}
}
Expand Down Expand Up @@ -398,7 +398,7 @@ this.b3editor = this.b3editor || {};
node.prototype.properties = JSON.parse(JSON.stringify(newNode.properties));
if (node.prototype.type == "action") {
if (newNode.output)
node.prototype.output = JSON.parse(JSON.stringify(node.output));
node.prototype.output = JSON.parse(JSON.stringify(newNode.output));
if (newNode.script)
node.prototype.script = newNode.script;
if (newNode.category)
Expand Down

0 comments on commit e02b6c5

Please sign in to comment.