Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

noflo

Package Overview
Dependencies
Maintainers
1
Versions
91
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

noflo - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3

components/Callback.js

17

components/FilterPropertyValue.js

@@ -50,3 +50,11 @@ (function() {

mapParts = map.split("=");
return this.accepts[mapParts[0]] = mapParts[1];
try {
return this.accepts[mapParts[0]] = eval(mapParts[1]);
} catch (e) {
if (e instanceof ReferenceError) {
return this.accepts[mapParts[0]] = mapParts[1];
} else {
throw e;
}
}
};

@@ -66,9 +74,12 @@

value = object[property];
if (this.accepts[property] && this.accepts[property] !== value) continue;
if (this.accepts[property]) {
if (this.accepts[property] !== value) continue;
match = true;
}
if (this.regexps[property]) {
regexp = new RegExp(this.regexps[property]);
if (!regexp.exec(value)) continue;
match = true;
}
newData[property] = value;
match = true;
continue;

@@ -75,0 +86,0 @@ }

(function() {
var Output, noflo;
var Output, noflo, util;
var __hasProp = Object.prototype.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; };

@@ -7,2 +7,4 @@

util = require("util");
Output = (function() {

@@ -15,11 +17,37 @@

function Output() {
var _this = this;
this.options = {
showHidden: false,
depth: 2,
colors: false
};
this.inPorts = {
"in": new noflo.ArrayPort()
"in": new noflo.ArrayPort(),
options: new noflo.Port()
};
this.outPorts = {};
this.inPorts["in"].on("data", function(data) {
return console.log(data);
return _this.log(data);
});
this.inPorts.options.on("data", function(data) {
return _this.setOptions(data);
});
}
Output.prototype.setOptions = function(options) {
var key, value, _results;
if (typeof options !== "object") throw "Options is not an object";
_results = [];
for (key in options) {
if (!__hasProp.call(options, key)) continue;
value = options[key];
_results.push(this.options[key] = value);
}
return _results;
};
Output.prototype.log = function(data) {
return console.log(util.inspect(data, this.options.showHidden, this.options.depth, this.options.colors));
};
return Output;

@@ -26,0 +54,0 @@

@@ -16,4 +16,10 @@ (function() {

var _this = this;
this.options = {
normalize: false,
trim: false,
explicitRoot: true
};
this.inPorts = {
"in": new noflo.Port()
"in": new noflo.Port(),
options: new noflo.Port()
};

@@ -31,8 +37,23 @@ this.outPorts = {

});
this.inPorts.options.on("data", function(data) {
return _this.setOptions(data);
});
}
ParseXml.prototype.setOptions = function(options) {
var key, value, _results;
if (typeof options !== "object") throw "Options is not an object";
_results = [];
for (key in options) {
if (!__hasProp.call(options, key)) continue;
value = options[key];
_results.push(this.options[key] = value);
}
return _results;
};
ParseXml.prototype.parseXml = function(xml) {
var parser, target;
target = this.outPorts.out;
parser = new xml2js.Parser;
parser = new xml2js.Parser(this.options);
parser.on("end", function(parsed) {

@@ -39,0 +60,0 @@ target.send(parsed);

12

components/ReadFile.js

@@ -15,5 +15,9 @@ (function() {

var _this = this;
this.inPorts.source = new noflo.Port();
this.outPorts.out = new noflo.Port();
this.outPorts.error = new noflo.Port();
this.inPorts = {
source: new noflo.Port()
};
this.outPorts = {
out: new noflo.Port(),
error: new noflo.Port()
};
this.inPorts.source.on("data", function(data) {

@@ -31,3 +35,5 @@ return _this.readFile(data);

}
_this.outPorts.out.beginGroup(fileName);
_this.outPorts.out.send(data);
_this.outPorts.out.endGroup();
return _this.outPorts.out.disconnect();

@@ -34,0 +40,0 @@ });

@@ -7,12 +7,28 @@ {

"ReadFile": {
"component": "ReadFile"
"component": "ReadFile",
"display": {
"x": 91,
"y": 154
}
},
"SplitbyLines": {
"component": "SplitStr"
"component": "SplitStr",
"display": {
"x": 209,
"y": 414
}
},
"CountLines": {
"component": "Counter"
"component": "Counter",
"display": {
"x": 206,
"y": 750
}
},
"Display": {
"component": "Output"
"component": "Output",
"display": {
"x": 71,
"y": 1003
}
}

@@ -22,9 +38,2 @@ },

{
"data": "package.json",
"tgt": {
"process": "ReadFile",
"port": "source"
}
},
{
"src": {

@@ -68,4 +77,11 @@ "process": "ReadFile",

}
},
{
"data": "package.json",
"tgt": {
"process": "ReadFile",
"port": "source"
}
}
]
}
}

@@ -15,6 +15,2 @@ (function() {

Component.prototype.inPorts = {};
Component.prototype.outPorts = {};
Component.prototype.description = "";

@@ -21,0 +17,0 @@

@@ -5,7 +5,7 @@ (function() {

fs = require("fs");
fs = require('fs');
events = require("events");
events = require('events');
fbp = require("./Fbp");
fbp = require('./Fbp');

@@ -16,3 +16,3 @@ Graph = (function() {

Graph.prototype.name = "";
Graph.prototype.name = '';

@@ -26,16 +26,17 @@ Graph.prototype.nodes = [];

function Graph(name) {
this.name = name;
this.nodes = [];
this.edges = [];
this.initializers = [];
this.name = name;
}
Graph.prototype.addNode = function(id, component) {
Graph.prototype.addNode = function(id, component, display) {
var node;
node = {
id: id,
component: component
component: component,
display: display
};
this.nodes.push(node);
return this.emit("addNode", node);
return this.emit('addNode', node);
};

@@ -61,3 +62,3 @@

}
this.emit("removeNode", node);
this.emit('removeNode', node);
if (this.nodes.indexOf(node !== -1)) {

@@ -90,3 +91,3 @@ return this.nodes.splice(this.nodes.indexOf(node), 1);

this.edges.push(edge);
return this.emit("addEdge", edge);
return this.emit('addEdge', edge);
};

@@ -100,7 +101,7 @@

if (edge.from.node === node && edge.from.port === port) {
this.emit("removeEdge", edge);
this.emit('removeEdge', edge);
this.edges.splice(index, 1);
}
if (edge.to.node === node && edge.to.port === port) {
this.emit("removeEdge", edge);
this.emit('removeEdge', edge);
this.edges.splice(index, 1);

@@ -114,3 +115,3 @@ }

if (edge.to.node === node && edge.to.port === port) {
this.emit("removeEdge", edge);
this.emit('removeEdge', edge);
_results.push(this.initializers.splice(index, 1));

@@ -136,3 +137,3 @@ } else {

this.initializers.push(initializer);
return this.emit("addEdge", initializer);
return this.emit('addEdge', initializer);
};

@@ -199,2 +200,3 @@

};
if (node.display) json.processes[node.id].display = node.display;
}

@@ -254,3 +256,3 @@ _ref2 = this.edges;

def = _ref[id];
graph.addNode(id, def.component);
graph.addNode(id, def.component, def.display);
}

@@ -257,0 +259,0 @@ _ref2 = definition.connections;

@@ -16,35 +16,35 @@ (function() {

InternalSocket.prototype.getId = function() {
if (this.from && !this.to) {
return "" + this.from.process.id + ":" + this.from.port + " -> ANON";
}
if (!this.from) return "DATA -> " + this.to.process.id + ":" + this.to.port;
return "" + this.from.process.id + ":" + this.from.port + " -> " + this.to.process.id + ":" + this.to.port;
};
InternalSocket.prototype.connect = function() {
this.connected = true;
return this.emit("connect", this);
return this.emit('connect', this);
};
InternalSocket.prototype.beginGroup = function(group) {
this.groups.push(group);
return this.emit("begingroup", group);
InternalSocket.prototype.disconnect = function() {
this.connected = false;
return this.emit('disconnect', this);
};
InternalSocket.prototype.isConnected = function() {
return this.connected;
};
InternalSocket.prototype.send = function(data) {
return this.emit("data", data);
return this.emit('data', data);
};
InternalSocket.prototype.endGroup = function() {
return this.emit("endgroup", this.groups.pop());
InternalSocket.prototype.beginGroup = function(group) {
this.groups.push(group);
return this.emit('begingroup', group);
};
InternalSocket.prototype.disconnect = function() {
this.connected = false;
return this.emit("disconnect", this);
InternalSocket.prototype.endGroup = function() {
return this.emit('endgroup', this.groups.pop());
};
InternalSocket.prototype.isConnected = function() {
return this.connected;
InternalSocket.prototype.getId = function() {
if (this.from && !this.to) {
return "" + this.from.process.id + ":" + this.from.port + " -> ANON";
}
if (!this.from) return "DATA -> " + this.to.process.id + ":" + this.to.port;
return "" + this.from.process.id + ":" + this.from.port + " -> " + this.to.process.id + ":" + this.to.port;
};

@@ -59,5 +59,5 @@

exports.createSocket = function() {
return new InternalSocket();
return new InternalSocket;
};
}).call(this);

@@ -30,12 +30,12 @@ (function() {

this.startupDate = new Date();
this.graph.on("addNode", function(node) {
this.graph.on('addNode', function(node) {
return _this.addNode(node);
});
this.graph.on("removeNode", function(node) {
this.graph.on('removeNode', function(node) {
return _this.removeNode(node);
});
this.graph.on("addEdge", function(edge) {
this.graph.on('addEdge', function(edge) {
return _this.addEdge(edge);
});
this.graph.on("removeEdge", function(edge) {
this.graph.on('removeEdge', function(edge) {
return _this.removeEdge(edge);

@@ -51,3 +51,3 @@ });

var implementation;
if (typeof component === "object") return component;
if (typeof component === 'object') return component;
try {

@@ -72,8 +72,6 @@ if (component.substr(0, 1) === ".") {

if (this.processes[node.id]) return;
process = {};
process = {
id: node.id
};
if (node.component) process.component = this.load(node.component);
process.id = node.id;
if (node.config && process.component.initialize) {
process.component.initialize(node.config);
}
return this.processes[process.id] = process;

@@ -174,3 +172,3 @@ };

NoFlo.prototype.removeEdge = function(edge) {
var connection, index, _len, _ref, _results;
var connection, index, _len, _ref, _ref2, _results;
_ref = this.connections;

@@ -181,3 +179,5 @@ _results = [];

if (edge.to.node === connection.to.process.id && edge.to.port === connection.to.port) {
connection.to.process.component.inPorts[connection.to.port].detach(connection);
if ((_ref2 = connection.to.process.component.inPorts[connection.to.port]) != null) {
_ref2.detach(connection);
}
this.connections.splice(index, 1);

@@ -184,0 +184,0 @@ }

(function() {
var express, noflo, nofloRoot, path;
var express, noflo, nofloRoot, path, prepareEdge, prepareNetwork, prepareNode, preparePort;

@@ -12,2 +12,71 @@ express = require("express");

prepareNetwork = function(network, id) {
var cleanNetwork, combined, edge, index, name, node, _len, _ref;
cleanNetwork = {
id: id,
name: network.graph.name,
started: network.startupDate,
nodes: [],
edges: []
};
_ref = network.graph.nodes;
for (name in _ref) {
node = _ref[name];
cleanNetwork.nodes.push(prepareNode(node, network));
}
combined = network.graph.edges.concat(network.graph.initializers);
for (index = 0, _len = combined.length; index < _len; index++) {
edge = combined[index];
cleanNetwork.edges.push(prepareEdge(edge, index));
}
return cleanNetwork;
};
prepareNode = function(node, network) {
var cleanNode, name, port, process, _ref, _ref2;
process = network.getNode(node.id);
cleanNode = {
id: node.id,
cleanId: node.id.replace(" ", "_"),
display: node.display,
inPorts: [],
outPorts: []
};
_ref = process.component.inPorts;
for (name in _ref) {
port = _ref[name];
cleanNode.inPorts.push(preparePort(port, name));
}
_ref2 = process.component.outPorts;
for (name in _ref2) {
port = _ref2[name];
cleanNode.outPorts.push(preparePort(port, name));
}
return cleanNode;
};
prepareEdge = function(edge, index) {
var cleanEdge;
cleanEdge = {
id: index + 1,
to: edge.to,
from: edge.from
};
cleanEdge.to.cleanNode = edge.to.node.replace(" ", "_");
if (edge.from.node) {
cleanEdge.from.cleanNode = edge.from.node.replace(" ", "_");
}
return cleanEdge;
};
preparePort = function(port, name) {
var cleanPort;
cleanPort = {
name: name,
type: "single"
};
if (port instanceof noflo.ArrayPort) cleanPort.type = "array";
return cleanPort;
};
exports.createServer = function(port, success) {

@@ -32,55 +101,22 @@ var app, sourceDir, staticDir;

app.get("/", function(req, res) {
return res.render("index", {
networks: app.networks
});
return res.render("application", {});
});
app.get("/network", function(req, res) {
var id, network, results, _len, _ref;
results = [];
_ref = app.networks;
for (id = 0, _len = _ref.length; id < _len; id++) {
network = _ref[id];
results.push(prepareNetwork(network, id));
}
return res.send(results);
});
app.param("network_id", function(req, res, next, id) {
var edge, name, node, port, process, type, _i, _j, _len, _len2, _ref, _ref2, _ref3, _ref4;
if (!app.networks[id]) return res.send("No network '" + id + "' found", 404);
req.network = app.networks[id];
_ref = req.network.graph.nodes;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
node = _ref[_i];
process = req.network.getNode(node.id);
node.cleanId = node.id.replace(" ", "_");
node.inPorts = [];
node.outPorts = [];
_ref2 = process.component.inPorts;
for (name in _ref2) {
port = _ref2[name];
type = "single";
if (port instanceof noflo.ArrayPort) type = "array";
node.inPorts.push({
name: name,
type: type
});
}
_ref3 = process.component.outPorts;
for (name in _ref3) {
port = _ref3[name];
type = "single";
if (port instanceof noflo.ArrayPort) type = "array";
node.outPorts.push({
name: name,
type: type
});
}
}
_ref4 = req.network.graph.edges;
for (_j = 0, _len2 = _ref4.length; _j < _len2; _j++) {
edge = _ref4[_j];
edge.to.cleanNode = edge.to.node.replace(" ", "_");
if (edge.from.node) edge.from.cleanNode = edge.from.node.replace(" ", "_");
}
req.network.id = id;
req.network = prepareNetwork(app.networks[id], id);
return next();
});
app.get("/:network_id", function(req, res) {
return res.render("network", {
network: req.network
});
});
app.param("node_id", function(req, res, next, id) {
var node, _i, _len, _ref;
_ref = req.network.graph.nodes;
_ref = req.network.nodes;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {

@@ -95,20 +131,15 @@ node = _ref[_i];

app.param("edge_id", function(req, res, next, id) {
var combined;
combined = req.network.graph.edges.concat(req.network.graph.initializers);
if (!combined[id]) return res.send("No edge '" + id + "' found", 404);
req.edge = combined[id];
var index;
index = id - 1;
if (!req.network.edges[index]) {
return res.send("No edge '" + id + "' found", 404);
}
req.edge = req.network.edges[index];
return next();
});
app.get("/network/:network_id", function(req, res) {
var network;
network = {
name: req.network.graph.name,
started: req.network.startupDate,
nodes: req.network.graph.nodes,
edges: req.network.graph.edges.concat(req.network.graph.initializers)
};
return res.send(network);
return res.send(req.network);
});
app.get("/network/:network_id/node", function(req, res) {
return res.send(req.network.graph.nodes);
return res.send(req.network.nodes);
});

@@ -119,3 +150,3 @@ app.post("/network/:network_id/node", function(req, res) {

}
req.network.graph.addNode(req.body.id, req.body.component);
app.networks[req.network.id].graph.addNode(req.body.id, req.body.component);
res.header("Location", "/network/" + req.params.network_id + "/node/" + req.body.id);

@@ -127,8 +158,21 @@ return res.send(null, 201);

});
app.put("/network/:network_id/node/:node_id", function(req, res) {
var index, node, _len, _ref;
if (req.body.display) {
_ref = app.networks[req.network.id].graph.nodes;
for (index = 0, _len = _ref.length; index < _len; index++) {
node = _ref[index];
if (node.id !== req.node.id) continue;
node.display = req.body.display;
req.node = prepareNode(node, app.networks[req.network.id]);
}
}
return res.send(req.node);
});
app["delete"]("/network/:network_id/node/:node_id", function(req, res) {
req.network.graph.removeNode(req.node.id);
app.networks[req.network.id].graph.removeNode(req.node.id);
return res.send(req.node);
});
app.get("/network/:network_id/edge", function(req, res) {
return res.send(req.network.graph.edges.concat(req.network.graph.initializers));
return res.send(req.network.edges);
});

@@ -140,3 +184,3 @@ app.post("/network/:network_id/edge", function(req, res) {

if (req.body.data) {
req.network.graph.addInitial(req.body.data, req.body.to.node, req.body.to.process);
app.networks[req.network.id].graph.addInitial(req.body.data, req.body.to.node, req.body.to.process);
return res.send(null, 201);

@@ -147,3 +191,3 @@ }

if (!req.body.from.port) return res.send("Missing source port", 422);
req.network.addEdge(req.body.from.node, req.body.from.port, req.body.to.node, req.body.to.port);
app.networks[req.network.id].addEdge(req.body.from.node, req.body.from.port, req.body.to.node, req.body.to.port);
return res.send(null, 201);

@@ -156,6 +200,6 @@ });

if (req.edge.from) {
req.network.graph.removeEdge(req.edge.from.node, req.edge.from.port);
app.networks[req.network.id].graph.removeEdge(req.edge.from.node, req.edge.from.port);
return res.send(req.edge);
}
req.network.graph.removeEdge(req.edge.to.node, req.edge.to.port);
app.networks[req.network.id].graph.removeEdge(req.edge.to.node, req.edge.to.port);
return res.send(req.edge);

@@ -162,0 +206,0 @@ });

@@ -5,7 +5,8 @@ {

"keywords": ["fbp", "workflow", "flow"],
"author": "Henri Bergius",
"author": "Henri Bergius <henri.bergius@iki.fi>",
"contributors": [
"Jerry Jalava"
"Jerry Jalava",
"Ryan Shaw"
],
"version": "0.0.2",
"version": "0.0.3",
"licenses": [{

@@ -16,3 +17,3 @@ "type": "MIT",

"engines": {
"node": ">=0.4.0"
"node": ">=0.6.0"
},

@@ -27,3 +28,6 @@ "dependencies": {

"nodeunit" : ">=0.6.0",
"coffee-script": ">=1.1.0"
"async" : ">=0.1.18",
"coffee-script": ">=1.1.0",
"docco-husky": ">=0.3.2",
"kckupmq": "0.3.x"
},

@@ -34,2 +38,3 @@ "main": "./lib/NoFlo",

},
"homepage": "http://noflojs.org/",
"repository": {

@@ -41,3 +46,7 @@ "type": "git",

"test": "./node_modules/nodeunit/bin/nodeunit test"
},
"docco_husky": {
"output_dir": "docs",
"project_name": "NoFlo"
}
}

@@ -1,2 +0,2 @@

NoFlo: Flow-based programming for Node.js
NoFlo: Flow-based programming for Node.js [![Build Status](https://secure.travis-ci.org/bergie/noflo.png?branch=master)](http://travis-ci.org/bergie/noflo)
=========================================

@@ -100,3 +100,4 @@

class Forwarder extends noflo.Component
description: "This component receives data on a single input port and sends the same data out to the output port"
description: "This component receives data on a single input
port and sends the same data out to the output port"

@@ -103,0 +104,0 @@ constructor: ->

@@ -0,120 +1,414 @@

(function() {
var model, nofloClient, view;
jsPlumb.bind("ready", function() {
var endPoints, getNodePosition, plumbNodes, previousPosition;
plumbNodes = {};
document.onselectstart = function() {
return false;
};
previousPosition = {
x: 0,
y: 0
};
endPoints = {
obj: {
endpoint: [
"Dot", {
radius: 6
}
],
paintStyle: {
fillStyle: "#75507b"
}
},
model = {};
view = {};
model.Network = Backbone.Model.extend({
defaults: {
nodes: null
},
url: function() {
return "/network/" + this.id;
},
initialize: function(attributes) {
var _ref, _ref2;
if (attributes == null) attributes = {};
if ((_ref = attributes.nodes) == null) attributes.nodes = [];
return (_ref2 = attributes.edges) != null ? _ref2 : attributes.edges = [];
},
set: function(attributes) {
if (attributes.nodes) {
attributes.nodes = new model.Nodes(attributes.nodes, {
network: this
});
}
if (attributes.edges) {
attributes.edges = new model.Edges(attributes.edges, {
network: this
});
}
return Backbone.Model.prototype.set.call(this, attributes);
}
});
model.Networks = Backbone.Collection.extend({
model: model.Network,
url: "/network"
});
model.Node = Backbone.Model.extend({
defaults: {
component: "",
inPorts: null,
outPorts: null,
display: {
x: null,
y: null
}
},
initialize: function(attributes) {
var _ref, _ref2;
if (attributes == null) attributes = {};
if ((_ref = attributes.inPorts) == null) attributes.inPorts = [];
return (_ref2 = attributes.outPorts) != null ? _ref2 : attributes.outPorts = [];
},
set: function(attributes) {
if (attributes.inPorts) {
attributes.inPorts = new model.NodePorts(attributes.inPorts, {
node: this
});
}
if (attributes.outPorts) {
attributes.outPorts = new model.NodePorts(attributes.outPorts, {
node: this
});
}
return Backbone.Model.prototype.set.call(this, attributes);
},
url: function() {
return "" + (this.collection.url()) + "/" + this.id;
}
});
model.Nodes = Backbone.Collection.extend({
model: model.Node,
network: null,
initialize: function(models, options) {
return this.network = options != null ? options.network : void 0;
},
url: function() {
return "/network/" + this.network.id + "/node";
}
});
model.Port = Backbone.Model.extend({
node: null,
defaults: {
type: "",
name: "",
data: null
}
});
model.NodePorts = Backbone.Collection.extend({
model: model.Port,
node: null,
initialize: function(models, options) {
return this.node = options != null ? options.node : void 0;
}
});
model.Edge = Backbone.Model.extend({
defaults: {
data: null,
rdf: null
};
jsPlumb.Defaults.Connector = "Bezier";
jsPlumb.Defaults.PaintStyle = {
strokeStyle: "#5c3566",
lineWidth: 6
};
jsPlumb.setMouseEventsEnabled(true);
jsPlumb.Defaults.DragOptions = {
cursor: "pointer",
zIndex: 2000
};
getNodePosition = function(node) {
if (node.display && node.display.x && node.display.y) {
previousPosition = node.display;
return node.display;
}
return previousPosition = {
x: previousPosition.x + 200,
y: previousPosition.y + 50
from: null,
to: null
},
url: function() {
return "" + (this.collection.url()) + "/" + this.id;
}
});
model.Edges = Backbone.Collection.extend({
model: model.Edge,
network: null,
initialize: function(models, options) {
return this.network = options != null ? options.network : void 0;
},
url: function() {
return "/network/" + this.network.id + "/edge";
}
});
view.Networks = Backbone.View.extend({
app: null,
initialize: function(options) {
return this.app = options != null ? options.app : void 0;
},
render: function() {
var app, element;
element = jQuery(this.el);
element.empty();
app = this.app;
this.collection.each(function(network) {
var networkElement;
networkElement = jQuery('<div></div>').html(network.get('name'));
networkElement.click(function() {
return app.navigate("#/" + network.id, {
trigger: true
});
});
return element.append(networkElement);
});
return this;
}
});
view.Network = Backbone.View.extend({
nodeViews: null,
initialize: function() {
var _this = this;
this.nodeViews = {};
this.model.get('nodes').each(function(node) {
return _this.nodeViews[node.id] = new view.Node({
model: node,
tagName: 'div'
});
});
this.edgeViews = [];
return this.model.get('edges').each(function(edge) {
return _this.edgeViews.push(new view.Edge({
model: edge,
networkView: _this
}));
});
},
render: function() {
var element;
var _this = this;
document.onselectstart = function() {
return false;
};
};
jsPlumb.setRenderMode(jsPlumb.CANVAS);
return jQuery.get("/network/" + jQuery('#network').attr('about'), function(data) {
var domNode, edge, inAnchors, index, maxConnections, node, outAnchors, port, position, _i, _j, _len, _len2, _len3, _len4, _ref, _ref2, _ref3, _ref4, _results;
jsPlumb.Defaults.Connector = "Bezier";
jsPlumb.Defaults.PaintStyle = {
strokeStyle: "#5c3566",
lineWidth: 6
};
jsPlumb.Defaults.DragOptions = {
cursor: "pointer",
zIndex: 2000
};
jsPlumb.setRenderMode(jsPlumb.CANVAS);
element = jQuery(this.el);
element.empty();
element.append(jQuery("<header><h1>" + (this.model.get('name')) + "</h1><div id='uptime'></div>"));
jQuery('#uptime').countdown({
since: new Date(data.started),
format: "YOWDHM",
since: new Date(this.model.get('started')),
format: 'YOWDHM',
significant: 2
});
_ref = data.nodes;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
node = _ref[_i];
domNode = jQuery("#" + node.cleanId);
domNode.addClass("component");
position = getNodePosition(node);
domNode.css("top", position.y);
domNode.css("left", position.x);
node.inEndpoints = {};
node.outEndpoints = {};
inAnchors = ["LeftMiddle", "TopLeft", "BottomLeft"];
outAnchors = ["RightMiddle", "TopRight", "BottonRight"];
_ref2 = node.inPorts;
for (index = 0, _len2 = _ref2.length; index < _len2; index++) {
port = _ref2[index];
maxConnections = 1;
if (port.type === "array") maxConnections = -1;
node.inEndpoints[port.name] = jsPlumb.addEndpoint(domNode, {
isSource: false,
isTarget: true,
maxConnections: maxConnections,
anchor: inAnchors[index]
}, endPoints.obj);
_(this.nodeViews).each(function(nodeView) {
element.append(nodeView.render().el);
return nodeView.renderPorts();
});
_(this.edgeViews).each(function(edgeView) {
return edgeView.renderConnection();
});
jsPlumb.bind('jsPlumbConnection', function(info) {
return console.log("ATTACH", info);
});
jsPlumb.bind('jsPlumbConnectionDetached', function(info) {
var edgeView, _i, _len, _ref, _results;
_ref = _this.edgeViews;
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
edgeView = _ref[_i];
if (edgeView.connection !== info.connection) continue;
console.log("DETACH", edgeView.model);
_results.push(edgeView.model.destroy({
success: function() {
return console.log("CONNECTION DELETED");
},
error: function() {
return console.log("FAILED TO DELETE CONNECTION");
}
}));
}
_ref3 = node.outPorts;
for (index = 0, _len3 = _ref3.length; index < _len3; index++) {
port = _ref3[index];
maxConnections = 1;
if (port.type === "array") maxConnections = -1;
node.outEndpoints[port.name] = jsPlumb.addEndpoint(domNode, {
isSource: true,
isTarget: false,
maxConnections: maxConnections,
anchor: outAnchors[index]
}, endPoints.obj);
return _results;
});
return this;
}
});
view.Node = Backbone.View.extend({
inAnchors: ["LeftMiddle", "TopLeft", "BottomLeft"],
outAnchors: ["RightMiddle", "TopRight", "BottonRight"],
inEndpoints: null,
outEndpoints: null,
initialize: function(options) {
this.inEndpoints = {};
return this.outEndpoints = {};
},
render: function() {
var element;
var _this = this;
element = jQuery(this.el);
element.empty();
element.addClass('component');
element.css('top', this.model.get('display').x);
element.css('left', this.model.get('display').y);
element.html(this.model.id);
jsPlumb.draggable(this.el, {
stop: function(event, data) {
_this.model.set({
display: {
x: data.offset.top,
y: data.offset.left
}
});
return _this.model.save({
success: function() {
return console.log("SUCCESS");
},
error: function() {
return console.log("ERROR");
}
});
}
plumbNodes[node.cleanId] = node;
jsPlumb.draggable(domNode);
});
return this;
},
renderPorts: function() {
var nodeView;
nodeView = this;
this.model.get('inPorts').each(function(port, index) {
var inPortView;
inPortView = new view.Port({
model: port,
inPort: true,
nodeView: nodeView,
anchor: nodeView.inAnchors[index]
});
inPortView.render();
return nodeView.inEndpoints[port.get('name')] = inPortView.endPoint;
});
this.model.get('outPorts').each(function(port, index) {
var outPortView;
outPortView = new view.Port({
model: port,
inPort: false,
nodeView: nodeView,
anchor: nodeView.outAnchors[index]
});
outPortView.render();
return nodeView.outEndpoints[port.get('name')] = outPortView.endPoint;
});
return this;
}
});
view.Port = Backbone.View.extend({
endPoint: null,
inPort: false,
anchor: "LeftMiddle",
portDefaults: {
endpoint: [
'Dot', {
radius: 6
}
],
paintStyle: {
fillStyle: '#75507b'
}
_ref4 = data.edges;
_results = [];
for (_j = 0, _len4 = _ref4.length; _j < _len4; _j++) {
edge = _ref4[_j];
if (!edge.from.node) continue;
_results.push(jsPlumb.connect({
source: plumbNodes[edge.from.cleanNode].outEndpoints[edge.from.port],
target: plumbNodes[edge.to.cleanNode].inEndpoints[edge.to.port],
overlays: [
[
"Label", {
label: edge.from.port,
location: 0.2,
cssClass: "outPort"
}
], [
"Label", {
label: edge.to.port,
location: 0.8,
cssClass: "inPort"
}
]
},
initialize: function(options) {
this.endPoint = null;
this.nodeView = options != null ? options.nodeView : void 0;
this.inPort = options != null ? options.inPort : void 0;
return this.anchor = options != null ? options.anchor : void 0;
},
render: function() {
var portOptions;
if (this.endPoint) return this;
portOptions = {
isSource: true,
isTarget: false,
maxConnections: 1,
anchor: this.anchor,
overlays: [
[
"Label", {
location: [2.5, -0.5],
label: this.model.get('name')
}
]
}));
]
};
if (this.inPort) {
portOptions.isSource = false;
portOptions.isTarget = true;
portOptions.overlays[0][1].location = [-1.5, -0.5];
}
return _results;
if (this.model.get('type') === 'array') portOptions.maxConnections = -1;
this.endPoint = jsPlumb.addEndpoint(this.nodeView.el, portOptions, this.portDefaults);
return this;
}
});
view.Edge = Backbone.View.extend({
networkView: null,
connection: null,
initialize: function(options) {
return this.networkView = options != null ? options.networkView : void 0;
},
render: function() {
return this;
},
renderConnection: function() {
var source, target;
if (!this.model.get('from').node) return;
source = this.model.get('from');
target = this.model.get('to');
return this.connection = jsPlumb.connect({
source: this.networkView.nodeViews[source.node].outEndpoints[source.port],
target: this.networkView.nodeViews[target.node].inEndpoints[target.port]
});
}
});
nofloClient = Backbone.Router.extend({
networks: null,
routes: {
'': 'index',
'/:network': 'network'
},
initialize: function(options) {
this.networks = new model.Networks([]);
return this.networks.fetch(options);
},
index: function() {
var _this = this;
this.networks = new model.Networks([]);
return this.networks.fetch({
success: function(networks) {
var networksView;
networksView = new view.Networks({
app: _this,
collection: networks,
el: jQuery('#noflo')
});
return networksView.render();
}
});
},
network: function(id) {
var network;
network = this.networks.get(id);
return network.fetch({
success: function() {
var networkView;
networkView = new view.Network({
model: network,
el: jQuery('#noflo')
});
return networkView.render();
}
});
}
});
jsPlumb.bind("ready", function() {
var app;
return app = new nofloClient({
success: function() {
return Backbone.history.start();
},
error: function() {
return jQuery('#noflo').empty().append(jQuery('<div>Failed to fetch networks</div>'));
}
});
});
}).call(this);

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc