1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-08-06 13:56:45 +00:00

Include separate entries for each evaluation of a run

This commit is contained in:
Jeremy Ruston 2025-04-07 16:13:18 +01:00
parent 3a2c81192e
commit 3c6ec3f9bb
7 changed files with 344 additions and 130 deletions

View File

@ -235,7 +235,7 @@ exports.compileFilter = function(filterString,options) {
this.filterCache = Object.create(null);
this.filterCacheCount = 0;
}
if(this.filterCache[filterString] !== undefined && !wrappers.prefix && !wrappers.operator) {
if(this.filterCache[filterString] !== undefined && !wrappers.prefix && !wrappers.operation && !wrappers.operator) {
return this.filterCache[filterString];
}
var filterParseTree;
@ -258,7 +258,8 @@ exports.compileFilter = function(filterString,options) {
var operationSubFunction = function(source,widget) {
var accumulator = source,
results = [],
currTiddlerTitle = widget && widget.getVariable("currentTiddler");
currTiddlerTitle = widget && widget.getVariable("currentTiddler"),
handleOperation = function() {
$tw.utils.each(operation.operators,function(operator) {
var operands = [],
operatorName,operatorFunction;
@ -309,6 +310,11 @@ exports.compileFilter = function(filterString,options) {
accumulator = results;
}
});
};
if(wrappers.operation) {
handleOperation = wrappers.operation.bind(self,handleOperation,operation);
}
handleOperation();
if($tw.utils.isArray(results)) {
return results;
} else {

View File

@ -15,8 +15,12 @@ Export our filter function
exports.inspect = function(source,operator,options) {
var self = this,
inputFilter = operator.operands[0] || "",
output = {input: [],runs: [], inputFilter: inputFilter},
currentRun;
output = {
input: [],
runs: [],
inputFilter: inputFilter
},
currentRun,currentOperation;
// Save the input
source(function(tiddler,title) {
output.input.push(title);
@ -30,15 +34,23 @@ exports.inspect = function(source,operator,options) {
input: results.toArray(),
prefixName: innerOptions.prefixName,
suffixes: innerOptions.suffixes,
operators: []
operations: []
};
currentRun = details.operators;
currentRun = details.operations;
var innerResults = filterRunPrefixFunction.call(null,operationFunction,innerOptions);
innerResults(results,innerSource,innerWidget);
details.output = results.toArray();
output.runs.push(details);
};
},
operation: function(operationFunction,operation) {
var details = {
operators: []
}
currentOperation = details.operators;
currentRun.push(details);
operationFunction();
},
operator: function(operatorFunction,innerSource,innerOperator,innerOptions) {
var details = {
operatorName: innerOperator.operatorName,
@ -53,7 +65,7 @@ exports.inspect = function(source,operator,options) {
innerSource(function(tiddler,title) {
details.input.push(title);
});
currentRun.push(details);
currentOperation.push(details);
var innerResults = operatorFunction.apply(null,Array.prototype.slice.call(arguments,1));
if(!$tw.utils.isArray(innerResults)) {
var resultArray = [];

View File

@ -93,6 +93,22 @@ tags: $:/tags/Macro
</div>
\end inspect-operator
\procedure inspect-operation(jsonOperation,indexOperation)
<div class="tc-box tc-inspect-operation-box">
<div class="tc-box-header">
<span class="">Evaluation</span>
<span class="tc-pill"><$text text=<<indexOperation>> /></span>
</div>
<div class="tc-box-content">
<$list filter="[<jsonOperation>jsonindexes[operators]nsort[]]" variable="indexOperator">
<$let transclusion={{{ [[operator-]addsuffix<indexOperator>] }}}>
<$transclude $variable="inspect-operator" jsonOperator={{{ [<jsonOperation>jsonextract[operators],<indexOperator>] }}}/>
</$let>
</$list>
</div>
</div>
\end inspect-operation
\procedure inspect-run(jsonRun)
<div class="tc-box tc-inspect-run-box">
<div class="tc-box-header">
@ -107,11 +123,13 @@ tags: $:/tags/Macro
</div>
<div class="tc-box-content">
<$transclude $variable="inspect-list" jsonList={{{ [<jsonRun>jsonextract[input]] }}} class="tc-box tc-inspect-input-box"/>
<$list filter="[<jsonRun>jsonindexes[operators]nsort[]]" variable="indexOperator">
<$let transclusion={{{ [[operator-]addsuffix<indexOperator>] }}}>
<$transclude $variable="inspect-operator" jsonOperator={{{ [<jsonRun>jsonextract[operators],<indexOperator>] }}}/>
<div class="tc-inspect-operations-wrapper">
<$list filter="[<jsonRun>jsonindexes[operations]nsort[]]" variable="indexOperation">
<$let transclusion={{{ [[operation-]addsuffix<indexOperation>] }}}>
<$transclude $variable="inspect-operation" jsonOperation={{{ [<jsonRun>jsonextract[operations],<indexOperation>] }}} indexOperation=<<indexOperation>>/>
</$let>
</$list>
</div>
<$transclude $variable="inspect-list" jsonList={{{ [<jsonRun>jsonextract[output]] }}} class="tc-box tc-inspect-output-box">
</div>
</div>

View File

@ -8,7 +8,7 @@ title: Output
\whitespace trim
\procedure test-filter()
1 2 3
1 2 3 :sort[length[]add[1]]
\end
\function test-filter-wrapper()
@ -21,7 +21,7 @@ title: Output
+
title: ExpectedResult
<p>1 2 3-{
<p>1 2 3 :sort[length[]add[1]]-{
"input": [
"$:/core",
"ExpectedResult",
@ -32,6 +32,8 @@ title: ExpectedResult
"input": [],
"prefixName": "or",
"suffixes": [],
"operations": [
{
"operators": [
{
"operatorName": "title",
@ -56,6 +58,8 @@ title: ExpectedResult
"1"
]
}
]
}
],
"output": [
"1"
@ -67,6 +71,8 @@ title: ExpectedResult
],
"prefixName": "or",
"suffixes": [],
"operations": [
{
"operators": [
{
"operatorName": "title",
@ -91,6 +97,8 @@ title: ExpectedResult
"2"
]
}
]
}
],
"output": [
"1",
@ -104,6 +112,8 @@ title: ExpectedResult
],
"prefixName": "or",
"suffixes": [],
"operations": [
{
"operators": [
{
"operatorName": "title",
@ -128,6 +138,162 @@ title: ExpectedResult
"3"
]
}
]
}
],
"output": [
"1",
"2",
"3"
]
},
{
"input": [
"1",
"2",
"3"
],
"prefixName": "sort",
"suffixes": [],
"operations": [
{
"operators": [
{
"operatorName": "length",
"operands": [
""
],
"parseTree": {
"operator": "length",
"operands": [
{
"text": "",
"value": ""
}
]
},
"input": [
"1"
],
"output": [
"1"
]
},
{
"operatorName": "add",
"operands": [
"1"
],
"parseTree": {
"operator": "add",
"operands": [
{
"text": "1",
"value": "1"
}
]
},
"input": [
"1"
],
"output": [
"2"
]
}
]
},
{
"operators": [
{
"operatorName": "length",
"operands": [
""
],
"parseTree": {
"operator": "length",
"operands": [
{
"text": "",
"value": ""
}
]
},
"input": [
"2"
],
"output": [
"1"
]
},
{
"operatorName": "add",
"operands": [
"1"
],
"parseTree": {
"operator": "add",
"operands": [
{
"text": "1",
"value": "1"
}
]
},
"input": [
"1"
],
"output": [
"2"
]
}
]
},
{
"operators": [
{
"operatorName": "length",
"operands": [
""
],
"parseTree": {
"operator": "length",
"operands": [
{
"text": "",
"value": ""
}
]
},
"input": [
"3"
],
"output": [
"1"
]
},
{
"operatorName": "add",
"operands": [
"1"
],
"parseTree": {
"operator": "add",
"operands": [
{
"text": "1",
"value": "1"
}
]
},
"input": [
"1"
],
"output": [
"2"
]
}
]
}
],
"output": [
"1",
@ -136,7 +302,7 @@ title: ExpectedResult
]
}
],
"inputFilter": "1 2 3",
"inputFilter": "1 2 3 :sort[length[]add[1]]",
"output": [
"1",
"2",

View File

@ -25,4 +25,3 @@ The JSON object contains the following properties:
*** `operands`: an array of string operands passed to the operator
*** `input`: the input titles passed to the operator
*** `output`: the output titles resulting from evaluating the operator

View File

@ -6,7 +6,7 @@ type: text/vnd.tiddlywiki
<$macrocall $name=".example" n="1" eg="""
<$transclude $variable="inspect-filter" filter="[tags[]prefix[$:/]] :sort[length[]] +[first[2]tagging[]]" inputFilter="[all[tiddlers]]"/>
<$transclude $variable="inspect-filter" filter="[tags[]prefix[$:/]] :sort[length[]add[1]] +[first[2]tagging[]]" inputFilter="[all[tiddlers]]"/>
"""/>
<$macrocall $name=".example" n="2" eg="""

View File

@ -3591,6 +3591,7 @@ span.tc-translink > a:first-child {
.tc-inspect-filter-box.tc-inspect-filter-box-horizontal > .tc-box > .tc-box-content,
.tc-inspect-filter-box.tc-inspect-filter-box-horizontal .tc-inspect-run-box > .tc-box-content,
.tc-inspect-filter-box.tc-inspect-filter-box-horizontal .tc-inspect-operation-box > .tc-box-content,
.tc-inspect-filter-box.tc-inspect-filter-box-horizontal .tc-inspect-operator-box > .tc-box-content {
display: flex;
flex-direction: row;
@ -3598,11 +3599,23 @@ span.tc-translink > a:first-child {
align-items: flex-start;
}
.tc-inspect-operations-wrapper {
display: flex;
flex-direction: column;
justify-content: flex-start;
align-items: stretch;
}
.tc-inspect-run-box {
--box-background-color: #ffc;
--box-foreground-color: #440;
}
.tc-inspect-operation-box {
--box-background-color: #cfc;
--box-foreground-color: #040;
}
.tc-inspect-operator-box {
--box-background-color: #fcc;
--box-foreground-color: #400;