Skip to content

Commit

Permalink
#280 Added FilterArray block to Filter menu
Browse files Browse the repository at this point in the history
  • Loading branch information
peetkes committed Jul 22, 2020
1 parent ea543c2 commit dae8373
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
25 changes: 25 additions & 0 deletions ml-backend/src/main/ml-modules/root/custom-modules/pipes/core.sjs
Original file line number Diff line number Diff line change
Expand Up @@ -1674,6 +1674,31 @@ function init (LiteGraph) {
}
LiteGraph.registerNodeType("Filter/DistinctValues", DistinctValues);

function FilterArray() {
this.addInput("unfiltered"); //Add Inputs, same as the one in the json definition
this.addInput("patterns"); //Add Inputs, same as the one in the json definition
this.addOutput("filtered");//Add Outputs, same as the one in the json definition
this.include = this.addWidget("toggle","include", true, function(v){} );
}
FilterArray.title = "FilterArray";
FilterArray.desc = "Returns the filtered Array based on the given pattern(can be an arrray), either inclusive or exclusive";

FilterArray.prototype.onExecute = function() {
xdmp.trace(TRACE_ID, "++++++++++++++++++FilterArray++++++++++++++++++++++++++++++");
let unfiltered = this.getInputData(0);
let patterns = this.getInputData(1);
let include = this.include.value;
let filtered = include ? unfiltered.filter(function(item) { return patterns.includes(item); } ) : unfiltered.filter(function(item) { return !(patterns.includes(item)); } );
xdmp.trace(TRACE_ID, unfiltered);
xdmp.trace(TRACE_ID, patterns);
xdmp.trace(TRACE_ID, "include=" + include);
xdmp.trace(TRACE_ID, filtered);
xdmp.trace(TRACE_ID, "++++++++++++++++++FilterArray++++++++++++++++++++++++++++++");
this.setOutputData(0, filtered); //Set output(s) value(s)
};

LiteGraph.registerNodeType("Filter/FilterArray", FilterArray );

function Highlight () {
this.addInput("string", null);
this.addInput("query", null);
Expand Down
33 changes: 33 additions & 0 deletions src/statics/library/core.json
Original file line number Diff line number Diff line change
Expand Up @@ -1469,6 +1469,39 @@
"code": ""
}
},
{
"functionName": "FilterArray",
"blockName": "FilterArray",
"library": "Filter",
"description": "Returns the filtered Array based on the given pattern (can be an arrray), either inclusive or exclusive",
"inputs": [
{
"name": "unfiltered",
"type": "string*"
},
{
"name": "patterns",
"type": "string*"
}
],
"widgets": [
{
"type": "toggle",
"name": "include",
"default": "enabled"
}
],
"outputs": [
{
"name": "filtered",
"type": "string*"
}
],
"function": {
"ref": null,
"code": ""
}
},
{
"functionName": "selectCase",
"blockName": "selectCase",
Expand Down

0 comments on commit dae8373

Please sign in to comment.