Skip to content

Commit

Permalink
UI for editing and creating groups
Browse files Browse the repository at this point in the history
  • Loading branch information
bergie committed Mar 2, 2014
1 parent b9f5602 commit b4b6508
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 8 deletions.
5 changes: 4 additions & 1 deletion elements/noflo-context.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
search: '',
editor: null,
graphs: [],
edges: [],
nodes: [],
edges: [],
runtimes: [],
component: '',
enteredView: function () {
Expand Down Expand Up @@ -133,10 +133,13 @@
this.nodeMenu.type = 'node-menu';
this.nodeMenu.appendChild(menu);
this.nodeMenu.addTo(this.contextBar);
this.nodeMenu.dialog = menu;
this.nodeMenu.addEventListener('newgraph', function (event) {
this.project.graphs.push(event.detail);
this.fire('newgraph', event.detail);
}.bind(this));
} else {
this.nodeMenu.dialog.nodes = this.nodes;
}

this.nodes.forEach(function (node) {
Expand Down
3 changes: 1 addition & 2 deletions elements/noflo-edge-menu.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,9 @@
</style>
<template>
<header>
<h1>{{ edges.length}} <template if="{{ edges.length > 1 }}">Edges</template><template if="{{ edges.length == 1 }}">Edge</template></h1>
<h1 on-click="{{ clear }}">{{ edges.length}} <template if="{{ edges.length > 1 }}">Edges</template><template if="{{ edges.length == 1 }}">Edge</template></h1>
</header>
<ul class="toolbar toolbar2right">
<li><button class="blue-button" on-click="{{ clear }}"><!--i class="fa fa-check" --></i>Deselect</button></li>
</ul>
<ul class="routes">
<template repeat="{{ route in routes }}">
Expand Down
81 changes: 81 additions & 0 deletions elements/noflo-group-inspector.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<polymer-element name="noflo-group-inspector" attributes="graph group groupdescription nodes" class="modal-content">
<template>
<h1>
<template if="{{ group }}">
{{ group }}
</template>
<template if="{{ !group }}">
New
</template>
group containing {{ nodes.length }} nodes
</h1>
<form>
<label>
Group name
<input type="text" value="{{ name }}" placeholder="processing" required>
</label>
<label>
Group description
<input type="text" value="{{ description }}" placeholder="The nodes that process things" required>
</label>
<div class="toolbar">
<button on-click="{{ send }}">
<template if="{{ group }}">
Rename
</template>
<template if="{{ !group }}">
Create
</template>
</button>
<a on-click="{{ close }}">Cancel</a>
</div>
</form>
</template>
<script>
Polymer('noflo-group-inspector', {
name: '',
description: '',
graph: null,
nodes: [],
group: '',
groupdescription: '',
enteredView: function () {
document.getElementById('container').classList.add('blur');
this.name = this.group;
this.description = this.groupdescription;
},
leftView: function () {
document.getElementById('container').classList.remove('blur');
},
send: function (event) {
if (event) {
event.preventDefault();
}
if (!this.name) {
return;
}
if (this.group) {
if (this.name !== this.group) {
this.graph.renameGroup(this.group, this.name);
}
if (this.description !== this.groupdescription) {
this.graph.setGroupMetadata(this.group, {
description: this.description
});
}
} else {
this.graph.addGroup(this.name, this.nodes, {
description: this.description
});
}
this.close();
},
close: function () {
if (!this.parentNode) {
return;
}
this.parentNode.removeChild(this);
}
});
</script>
</polymer-element>
32 changes: 27 additions & 5 deletions elements/noflo-node-menu.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<link rel="import" href="noflo-new-graph.html">
<link rel="import" href="noflo-group-inspector.html">
<polymer-element name="noflo-node-menu" attributes="graph nodes" class="sticky-head the-card-content">
<template>
<header>
<h1>{{ nodes.length}} <template if="{{ nodes.length > 1 }}">Nodes</template><template if="{{ nodes.length == 1 }}">Node</template></h1>
<h1 on-click="{{ clear }}">{{ nodes.length}} <template if="{{ nodes.length > 1 }}">Nodes</template><template if="{{ nodes.length == 1 }}">Node</template></h1>
</header>
<ul class="toolbar toolbar2right">
<li><button class="blue-button" on-click="{{ clear }}"><!--i class="fa fa-check"></i-->Deselect</button></li>
<li><button class="blue-button" on-click="{{ group }}">Group</button></li>
<li><button class="blue-button" on-click="{{ subgraph }}">Subgraph</button></li>
</ul>
</template>
Expand Down Expand Up @@ -34,12 +35,33 @@ <h1>{{ nodes.length}} <template if="{{ nodes.length > 1 }}">Nodes</template><tem
}
currentGraph.checkTransactionEnd();
},
/*
group: function (event) {
event.preventDefault();
this.nodes.forEach(function (node) {

// See if the nodes are already part of a group
var group = '';
var description = '';
var selectedNodes = this.nodes.map(function (node) {
return node.id;
});
selectedNodes.sort();

this.graph.groups.forEach(function (grp) {
var grpNodes = JSON.parse(JSON.stringify(grp.nodes));
grpNodes.sort();
if (grpNodes.join(',') == selectedNodes.join(',')) {
group = grp.name;
description = grp.metadata.description;
}
});
}*/

var dialog = document.createElement('noflo-group-inspector');
dialog.group = group;
dialog.groupdescription = description;
dialog.nodes = selectedNodes;
dialog.graph = this.graph;
document.body.appendChild(dialog);
},
subgraph: function (event) {
event.preventDefault();
var currentGraph = this.graph;
Expand Down
3 changes: 3 additions & 0 deletions elements/noflo-packets.html
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,11 @@
menu.graph = this.currentgraph;
this.edgeMenu = document.createElement('the-card');
this.edgeMenu.type = 'edge-menu';
this.edgeMenu.dialog = menu;
this.edgeMenu.appendChild(menu);
this.edgeMenu.addTo(this.panel);
} else {
this.edgeMenu.dialog.edges = this.edges;
}

this.edges.forEach(function (edge) {
Expand Down

0 comments on commit b4b6508

Please sign in to comment.