Skip to content
This repository has been archived by the owner on Jun 27, 2019. It is now read-only.

WIP: Introduces a new design for web-inspector #2030

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions src/bin/sol-fbp-runner/Modal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
(function(window) {

'use strict'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing semicolon here...


function Modal(){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

split the { from the Modal()

function Modal() {


var instance = this;

this.el = $("<div/>").addClass("modal").appendTo("#modal-container");
this.header = $("<div/>").addClass("modal-header").appendTo(this.el);
this.title = $("<span/>").appendTo(this.header).addClass("modal-title");
this.content = $("<pre/>").appendTo(this.el);

this.el.hide();
this.shield = $("<div/>").attr("id","shield");

this.closeButton = $("<img/>").attr("src","images/ico_close.png").addClass("close").appendTo(this.header)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing semicolon here...

.click(function(){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same split here

.click(function() {

instance.hide();
});


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try not putting so much empty lines between braces

}

Modal.prototype.show = function(data, title) {

var instance = this;

this.title.empty().append(title);
this.content.empty().append(data);

//adding click to the shield div
this.shield.insertBefore(this.el)
.click(function() {
instance.hide();
});

this.el.show(400);
};

Modal.prototype.hide = function() {
this.title.empty();
this.content.empty();
this.el.hide();
this.shield.remove();
};

window.Modal = Modal;

})(window)
122 changes: 122 additions & 0 deletions src/bin/sol-fbp-runner/Port.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
(function(window) {

'use strict'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing semicolon here...


function Port (params) {

//data properties
var instance = this; //returns the __proto__ of the object

this.name = params["name"];
this.value = params["value"];
this.type = params["type"] || "in";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you receiving empty type? That shouldn't happen

this.data_type = params["data_type"];
this.widget = params["widget"];
this.port_index = params["port_index"];
this.required = params["required"] || true;
this.key = "port_" + this.type + "_" + params["key"];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All these parameters should be written in dot notation instead of using ['key']

It would be something like this:

this.required = params.required;

You can see more info about this here:
https://jslinterrors.com/a-is-better-written-in-dot-notation

this.connections = []; //the pair port which this port is connected
this.emitt = false;

//DOM properties
this.el = $("<div/>")
.attr("id",this.key)
.addClass("port "+this.getPortType())
.append(this.name);

//adding the port to the correct container
if(this.type == "in") this.widget.getLeft().append(this.el);
if(this.type == "out") this.widget.getRight().append(this.el);

//MOUSE AND CUSTOM EVENTS
this.el.click(function (event) {
$(event.target).trigger({
type:"port-select",
port:instance,
widget:instance.widget,
value:instance.value
});

});

this.el.mouseover(function (event) {
$(event.target).trigger({
type:"port-over",
port:instance,
widget:instance.widget,
connections:instance.connections
});
});

this.el.mouseout(function (event) {
$(event.target).trigger({
type:"port-out",
port:instance,
widget:instance.widget,
connections:instance.connections
});
});
}

Port.prototype.update = function (value) {

this.value = value; //retrieves only the valu

var widget = this.widget;
var instance = this.instance;

if(this.emitt) this.el.trigger(
{
type:"port-update",
widget:widget,
port:instance,
value:value,
});
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing semicolon here...


Port.prototype.getElement = function() {
return this.el;
}

Port.prototype.getParentWidget = function() {
return this.widget;
}

Port.prototype.getPortType = function() {
return (this.type === "in") ? "in" : "out";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you already ensure it's a string when you set it, no need to check it here

}

Port.prototype.select = function() {
this.emitt = true;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why the double "t"? Also, why not call it "selected"?

this.el.addClass("selected");
}

Port.prototype.unselect = function() {
this.emitt = false;
this.el.removeClass("selected");
}

Port.prototype.connect = function (port) {

//ERROR TRYING TO CONNECT PORTs!
if(this.connections.indexOf(port.key) == -1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the port.key is always the same type you should use three equals.

Also, put a space between if and (. :)

if (this.connections.indexOf(port.key) === -1)

{
this.connections.push(port.key);
this.widget.autoSelectPort(this);
}

}

Port.prototype.hidePort = function() {
this.el.addClass("hidden");
this.el.addClass("non-selectable");
this.el.unbind();
}

Port.prototype.showPort = function() {
//TODO
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All Port prototype should be ended with semicolon.


window.Port = Port;

})(window)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing semicolon here...

222 changes: 222 additions & 0 deletions src/bin/sol-fbp-runner/Widget.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
(function(window) {

'use strict'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

semicolon here :)


function Widget(payload, key) {

//caching a secure reference to the instance
var instance = this;
//var selectedPort;

Widget.prototype.portsCount = 0;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you shouldn't set a class property from an instance constructor. Maybe move this outside this function


//unique id for the widget and other unique properties
this.raw = JSON.stringify(payload, null, 4);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keeping this is not that good, is this a stop-gap until we can render this in a nice format/html?

this.key = key;
this.widgetName = payload.id; //change to 'name ?'
this.uid = payload.path[payload.path.length-1];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, but you should also save payload.path somewhere and have some parenting/container. This will happen when you have flows that use sub flows. I'm not sure how to represent that in a nice graphical way. To the parent flow, the internal is represented as a single node with input and output ports. We can either "click to enter/expand" or show inlined with some graphical delimiter.

this.type = payload.type;
this.category = payload.category;
this.description = payload.description;
this.url = payload.url;
this.portsIn = [];
this.portsOut = [];
this.autoSelected = false;
this.hidden = true;
this.selectedPort = null;
this.totalPorts = 0;

//TODO: we should change the id key to name
this.name = "widget" + payload.id;

//title and subtitle of the widget
this.title = $("<span/>").addClass("widget-title").append(this.widgetName);
this.subtitle = $("<span/>").addClass("widget-subtitle").append(this.type);

//info button
var info = $("<img/>").attr("src","images/ico_info.png").addClass("info");
info.click(function(event) {
window.modal.show(instance.raw, instance.type);
});

//creating DOM elements
this.displayValue = $("<span/>").addClass("display-value");
this.el = $("<div/>").addClass("widget").attr("id",this.uid).appendTo("#container");
$("<div/>").addClass("widget-header").appendTo(this.el).append(this.title).append(this.subtitle).append(info);
$("<div/>").addClass("widget-display").appendTo(this.el).addClass("widget-data").append(this.displayValue);
this.widgetPorts = $("<div/>").addClass("widget-ports").appendTo(this.el);

//putting the ports in the correct container
this.lports = $("<div/>").addClass("port-container").appendTo("#"+this.uid + " .widget-ports");
this.rports = $("<div/>").addClass("port-container").appendTo("#"+this.uid + " .widget-ports");

//reading all in ports
var port;
payload.ports_in.forEach(function(element, index) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will be empty as when we start, there are no connections yet. Or is this deferred? If so, until when? In theory connections and disconnections could happen all the time (dynamic), but in practice it's done once at startup (static)

port = new Port(
{
name:element["name"],
value:undefined,
type:"in",
port_index:element["base_port_idx"],
data_type:element["data_type"],
required:element["required"],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use dot notation instead of using ['key'] here too

widget:instance,
key:instance.key + "_" + Widget.prototype.portsCount

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can use the node uid + port index as the key. The node id is unique during the flow lifetime. The port is also unique within a node. So this.uid + "-" + index is enough.

});

instance.portsIn.push(port);
instance.totalPorts++;
port.el.on("port-select", instance.onPortSelect);
Widget.prototype.portsCount ++;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is affecting the class, not the instance. Did you want to mean "this"?

});

//reading all out ports
payload.ports_out.forEach(function(element, index) {
port = new Port(
{
name:element["name"],
value:undefined,
type:"out",
port_index:element["base_port_idx"],
data_type:element["data_type"],
required:element["required"],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use dot notation instead of using ['key'] here too

widget:instance,
key:instance.key + "_" + Widget.prototype.portsCount
});
instance.portsOut.push(port);
instance.totalPorts++;
port.el.on("port-select", instance.onPortSelect);
Widget.prototype.portsCount ++;
});

//Auto Adjusting the size of the Widget Container
var h = Math.max(this.portsIn.length, this.portsOut.length) * 26;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we get 26 from some existing element? Or at least make it a constant that we can remember about it later :-)

this.widgetPorts.css("height",h);

}

Widget.prototype.onPortSelect = function(event) {
event.widget.selectPort(event.port, event.value);
};

Widget.prototype.getUID = function() {
return this.uid;
};

//UPDATES THE VALUES OF ALL PORTS
Widget.prototype.update = function(type, data) {

//getting the child ports of the widget
var port = (type === "deliver") ? this.portsIn[data.port_idx] : this.portsOut[data.port_idx];

//if the ports have no pair, skip
if(port.connections.length < 0) return;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for Inspector, it may be useful to know the packet being delivered even if there are no connections. I'd not do this early return


//found paired ports, update its value
var packet = data.packet;
var packetType = packet.packet_type;

if(packetType === "empty"){
port.update("empty");
}else if(packetType === "int" || packetType === "float"){
port.update(packet.payload.value)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing semicolon here...

also in these line of codes try not letting everything together, just for organization
Such as

} else if (packetType === "int" || packetType === "float") {

}else if(packetType === "byte"){
port.update(packet.payload);
}else if(packetType === "boolean"){
port.update(packet.payload.toString());
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see my original web-inspector javascript, it's better to move this to a function that renders a packet to html, possibly with some CSS classes to allow identification of type. Things like rgb can display a color preview, etc. This may be reused in other places

};

Widget.prototype.fadeIn = function(delay) {
var instance = this;
setTimeout(function(){
instance.el.fadeIn(300);
},delay);
};

Widget.prototype.clearPorts = function() {

this.portsIn.forEach(function(p, i){
if(p.connections.length === 0){
p.hidePort();
}
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing semicolon here


this.portsOut.forEach(function(p, i){
if(p.connections === 0){
p.hidePort();
}
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing semicolon here

};

Widget.prototype.autoSelectPort = function(port) {
if(this.selectedPort == null){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you should always use three === to compare NULL.

You can also put like this:

if (!this.selectedPort) {

this.selectPort(port,port.value);
}
};

Widget.prototype.selectPort = function(port, value) {

//dealing with repeated port click
if(port === this.selectedPort) {
port.unselect();
this.unsubscribe(port);
this.selectedPort = null;
return;
}

//clearing last selected port
if(this.selectedPort != null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change != to !==

or

if (this.selectedPort) {

this.selectedPort.unselect();
this.unsubscribe(port);
}

//selecting new port
this.clearDisplay().append(value);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why take a value? just use port.value, no?

this.selectedPort = port;
this.selectedPort.select();
this.subscribe(port);
};

Widget.prototype.onPortValueChange = function(event) {
event.widget.clearDisplay().append(event.value);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this signature doesn't look right. Why not find the port and specify it here, then call the function on the Port so it could update itself.

};

Widget.prototype.subscribe = function(port) {
port.el.on('port-update', this.onPortValueChange);
};

Widget.prototype.unsubscribe = function(port) {
port.el.off('port-update', this.onPortValueChange);
this.clearDisplay(port.widget);
};

Widget.prototype.clearDisplay = function() {
var display = $("#" + this.uid + " .display-value").empty();
return display;
};

Widget.prototype.getElement = function() {
return this.el;
};

Widget.prototype.getLeft = function() {
return this.lports;
};

Widget.prototype.getRight = function() {
return this.rports;
};

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left and right come from nowhere. What if we use "in" and "out"? If they happen to be at the left, right, top, bottom... is up to the theme/graphics


Widget.prototype.getInByIndex = function(index) {
return this.portsIn[index];
};

Widget.prototype.getOutByIndex = function(index) {
return this.portsOut[index];
};

window.Widget = Widget;

})(window)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add semicolon here

Loading