diff --git a/core/modules/filters/x-listops.js b/core/modules/filters/x-listops.js new file mode 100644 index 000000000..63edcd142 --- /dev/null +++ b/core/modules/filters/x-listops.js @@ -0,0 +1,192 @@ +/*\ +title: $:/core/modules/filters/x-listops.js +type: application/javascript +module-type: filteroperator + +Extended filter operators to manipulate the current list. + +\*/ +(function () { + + /*jslint node: true, browser: true */ + /*global $tw: false */ + "use strict"; + + var prepare_results = function (source) { + var results = []; + source(function (tiddler, title) { + results.push(title); + }); + return results; + }; + + /* + Moves a number of items from the tail of the current list before the item named in the operand + */ + exports.putbefore = function (source, operator, options) { + var results = prepare_results(source), + index = results.indexOf(operator.operand), + count = parseInt(operator.suffix) || 1; + if (index === -1) { + return results.slice(0, -1); + } + return results.slice(0, index).concat(results.slice(-count)).concat(results.slice(index, -count)); + }; + + /* + Moves a number of items from the tail of the current list after the item named in the operand + */ + exports.putafter = function (source, operator, options) { + var results = prepare_results(source), + index = results.indexOf(operator.operand), + count = parseInt(operator.suffix) || 1; + if (index === -1) { + return results.slice(0, -1); + } + return results.slice(0, index + 1).concat(results.slice(-count)).concat(results.slice(index + 1, -count)); + }; + + /* + Replaces the item named in the operand with a number of items from the tail of the current list + */ + exports.replace = function (source, operator, options) { + var results = prepare_results(source), + index = results.indexOf(operator.operand), + count = parseInt(operator.suffix) || 1; + if (index === -1) { + return results.slice(0, -count); + } + return results.slice(0, index).concat(results.slice(-count)).concat(results.slice(index + 1, -count)); + }; + + /* + Moves a number of items from the tail of the current list to the head of the list + */ + exports.putfirst = function (source, operator, options) { + var results = prepare_results(source), + count = parseInt(operator.suffix) || 1; + return results.slice(-count).concat(results.slice(0, -count)); + }; + + /* + Moves a number of items from the head of the current list to the tail of the list + */ + exports.putlast = function (source, operator, options) { + var results = prepare_results(source), + count = parseInt(operator.suffix) || 1; + return results.slice(count).concat(results.slice(0, count)); + }; + +/* + Moves the item named in the operand a number of places forward or backward in the list + */ + exports.move = function (source, operator, options) { + var results = prepare_results(source), + index = results.indexOf(operator.operand), + count = parseInt(operator.suffix) || 1, + marker = results.splice(index, 1); + return results.slice(0, index + count).concat(marker).concat(results.slice(index + count)); + }; + + /* + Returns the items from the current list that are after the item named in the operand + */ + exports.allafter = function (source, operator, options) { + var results = prepare_results(source), + index = results.indexOf(operator.operand); + if (index === -1 || index > (results.length - 2)) { + return []; + } + if (operator.suffix) { + return results.slice(index); + } + return results.slice(index + 1); + }; + + /* + Returns the items from the current list that are before the item named in the operand + */ + exports.allbefore = function (source, operator, options) { + var results = prepare_results(source), + index = results.indexOf(operator.operand); + if (index <= 0) { + return []; + } + if (operator.suffix) { + return results.slice(0, index + 1); + } + return results.slice(0, index); + }; + + /* + Appends the items listed in the operand array to the tail of the current list + */ + exports.append = function (source, operator, options) { + var append = $tw.utils.parseStringArray(operator.operand), + results = prepare_results(source), + count = parseInt(operator.suffix) || append.length; + if (append.length === 0) { + return results; + } + if (operator.prefix) { + return results.concat(append.slice(-count)); + } else { + return results.concat(append.slice(0, count)); + } + }; + + /* + Prepends the items listed in the operand array to the head of the current list + */ + exports.prepend = function (source, operator, options) { + var prepend = $tw.utils.parseStringArray(operator.operand), + results = prepare_results(source), + count = parseInt(operator.suffix) || prepend.length; + if (prepend.length === 0) { + return results; + } + if (operator.prefix) { + return prepend.slice(-count).concat(results); + } else { + return prepend.slice(0, count).concat(results); + } + }; + + /* + Returns all items from the current list except the items listed in the operand array + */ + exports.remove = function (source, operator, options) { + var array = $tw.utils.parseStringArray(operator.operand), + results = prepare_results(source), + count = parseInt(operator.suffix) || array.length, + p, len, index; + len = array.length - 1; + for (p = 0; p < count; ++p) { + if (operator.prefix) { + index = results.indexOf(array[len - p]); + } else { + index = results.indexOf(array[p]); + } + if (index !== -1) { + results.splice(index, 1); + } + } + return results; + }; + + /* + Returns all items from the current list sorted in the order of the items in the operand array + */ + exports.sortby = function (source, operator, options) { + var results = prepare_results(source); + if (!results || results.length < 2) { + return results; + } + var lookup = $tw.utils.parseStringArray(operator.operand); + results.sort(function (a, b) { + return lookup.indexOf(a) - lookup.indexOf(b); + }); + return results; + }; + +})(); diff --git a/core/modules/widgets/action-listops.js b/core/modules/widgets/action-listops.js new file mode 100644 index 000000000..c88130b39 --- /dev/null +++ b/core/modules/widgets/action-listops.js @@ -0,0 +1,89 @@ +/*\ +title: $:/core/modules/widgets/action-listops.js +type: application/javascript +module-type: widget + +Action widget to apply list operations to any tiddler field (defaults to the 'tags' field of the current tiddler) + +\*/ +(function () { + + /*jslint node: true, browser: true */ + /*global $tw: false */ + "use strict"; + + var Widget = require("$:/core/modules/widgets/widget.js").widget; + + var ActionListopsWidget = function (parseTreeNode, options) { + this.initialise(parseTreeNode, options); + }; + + /* + Inherit from the base widget class + */ + ActionListopsWidget.prototype = new Widget(); + + /* + Render this widget into the DOM + */ + ActionListopsWidget.prototype.render = function (parent, nextSibling) { + this.computeAttributes(); + this.execute(); + }; + + /* + Compute the internal state of the widget + */ + ActionListopsWidget.prototype.execute = function () { + // Get our parameters + this.target = this.getAttribute("$tiddler", this.getVariable("currentTiddler")); + this.filter = this.getAttribute("$filter"); + this.subfilter = this.getAttribute("$subfilter"); + this.listField = this.getAttribute("$list", "list"); + this.listIndex = this.getAttribute("$index"); + this.filtertags = this.getAttribute("$tags"); + }; + + /* + Refresh the widget by ensuring our attributes are up to date + */ + ActionListopsWidget.prototype.refresh = function (changedTiddlers) { + var changedAttributes = this.computeAttributes(); + if (changedAttributes.$tiddler || changedAttributes.$filter || changedAttributes.$subfilter || changedAttributes.$list || changedAttributes.$index || changedAttributes.$tags) { + this.refreshSelf(); + return true; + } + return this.refreshChildren(changedTiddlers); + }; + + /* + Invoke the action associated with this widget + */ + ActionListopsWidget.prototype.invokeAction = function (triggeringWidget, event) { + //try this + var field = this.listField, + index = undefined, + type = "!!", + list = this.listField; + if (this.listIndex) { + field = undefined; + index = this.listIndex; type = "##"; + list = this.listIndex; + } + if (this.filter) { + this.wiki.setText(this.target, field, index, $tw.utils.stringifyList(this.wiki.filterTiddlers(this.filter, this))); + } + if (this.subfilter) { + var subfilter = "[list[" + this.target + type + list + "]] " + this.subfilter; + this.wiki.setText(this.target, field, index, $tw.utils.stringifyList(this.wiki.filterTiddlers(subfilter, this))); + } + if (this.filtertags) { + var tagfilter = "[list[" + this.target + "!!tags]] " + this.filtertags; + this.wiki.setText(this.target, "tags", undefined, $tw.utils.stringifyList(this.wiki.filterTiddlers(tagfilter, this))); + } + return true; // Action was invoked + }; + + exports["action-listops"] = ActionListopsWidget; + +})(); diff --git a/editions/tw5.com/tiddlers/filters/FilterOperators.tid b/editions/tw5.com/tiddlers/filters/FilterOperators.tid index 60fdb35cd..5390dbf55 100644 --- a/editions/tw5.com/tiddlers/filters/FilterOperators.tid +++ b/editions/tw5.com/tiddlers/filters/FilterOperators.tid @@ -1,9 +1,3 @@ -created: 20140410103123179 -modified: 20150917193612610 -tags: Filters -title: Filter Operators -type: text/vnd.tiddlywiki - \define .operator-rows(filter) <$list filter="$filter$"> <$link to={{!!title}}>{{!!caption}} @@ -28,7 +22,9 @@ The following table lists all the core operators. The commonest ones are checkma <<.operator-rows "[tag[Filter Operators]!tag[Order Operators]!tag[String Operators]!tag[Tag Operators]!tag[Special Operators]sort[]]">> <<.group-heading "Order Operators">> -<<.operator-rows "[tag[Filter Operators]tag[Order Operators]!tag[String Operators]!tag[Tag Operators]!tag[Special Operators]sort[]]">> +<<.operator-rows "[tag[Filter Operators]tag[Order Operators]!tag[Listops Operators]!tag[String Operators]!tag[Tag Operators]!tag[Special Operators]sort[]]">> +<<.group-heading "Listops Operators">> +<<.operator-rows "[tag[Filter Operators]tag[Listops Operators]tag[Order Operators]!tag[String Operators]!tag[Tag Operators]!tag[Special Operators]sort[]]">> <<.group-heading "String Operators">> <<.operator-rows "[tag[Filter Operators]!tag[Order Operators]tag[String Operators]!tag[Tag Operators]!tag[Special Operators]sort[]]">> <<.group-heading "Tag Operators">> diff --git a/editions/tw5.com/tiddlers/filters/allafter.tid b/editions/tw5.com/tiddlers/filters/allafter.tid new file mode 100644 index 000000000..bdb21a919 --- /dev/null +++ b/editions/tw5.com/tiddlers/filters/allafter.tid @@ -0,0 +1,17 @@ +caption: allafter +created: 20151017145021839 +creator: matabele +modified: 20151108051523860 +modifier: matabele +op-input: a list of items +op-output: all items after the marker +op-parameter: the list item to be used as a marker +op-parameter-name: marker +op-purpose: discard all items except those after the marker +op-suffix: specifying a suffix ('include') will include the marker in the output +revision: 0 +tags: [[Filter Operators]] [[Order Operators]] [[Listops Operators]] +title: allafter Operator +type: text/vnd.tiddlywiki + +<<.operator-examples "allafter">> diff --git a/editions/tw5.com/tiddlers/filters/allbefore.tid b/editions/tw5.com/tiddlers/filters/allbefore.tid new file mode 100644 index 000000000..51c176747 --- /dev/null +++ b/editions/tw5.com/tiddlers/filters/allbefore.tid @@ -0,0 +1,17 @@ +caption: allbefore +created: 20151017145131857 +creator: matabele +modified: 20151108051507578 +modifier: matabele +op-input: a list of items +op-output: all items before the marker +op-parameter: the list item to be used as a marker +op-parameter-name: marker +op-purpose: discard all items except those before the marker +op-suffix: specifying a suffix ('include') will include the marker in the output +revision: 0 +tags: [[Filter Operators]] [[Order Operators]] [[Listops Operators]] +title: allbefore Operator +type: text/vnd.tiddlywiki + +<<.operator-examples "allbefore">> diff --git a/editions/tw5.com/tiddlers/filters/append.tid b/editions/tw5.com/tiddlers/filters/append.tid new file mode 100644 index 000000000..c481a790e --- /dev/null +++ b/editions/tw5.com/tiddlers/filters/append.tid @@ -0,0 +1,18 @@ +caption: append +created: 20151017145358368 +creator: matabele +modified: 20151108051540981 +modifier: matabele +op-input: a list of items +op-neg-output: a list with items appended from the tail of the operand array +op-output: a list with items appended from the head of the operand array +op-parameter: the array of items to be appended to the tail of the list +op-parameter-name: list +op-purpose: append a range of items from an array to the list +op-suffix: an integer N, defaulting to all +revision: 0 +tags: [[Filter Operators]] [[Order Operators]] [[Listops Operators]] +title: append Operator +type: text/vnd.tiddlywiki + +<<.operator-examples "append">> diff --git a/editions/tw5.com/tiddlers/filters/examples/allafter.tid b/editions/tw5.com/tiddlers/filters/examples/allafter.tid new file mode 100644 index 000000000..62f29dbc2 --- /dev/null +++ b/editions/tw5.com/tiddlers/filters/examples/allafter.tid @@ -0,0 +1,13 @@ +created: 20151022123929297 +creator: matabele +modified: 20151108080543606 +modifier: matabele +revision: 0 +tags: [[Operator Examples]] [[allafter Operator]] +title: allafter Operator (Examples) +type: text/vnd.tiddlywiki + +<<.using-days-of-week>> + +<<.operator-example 1 "[list[Days of the Week]] +[allafter[Wednesday]]">> +<<.operator-example 2 "[list[Days of the Week]] +[allafter:include[Wednesday]]">> diff --git a/editions/tw5.com/tiddlers/filters/examples/allbefore.tid b/editions/tw5.com/tiddlers/filters/examples/allbefore.tid new file mode 100644 index 000000000..4a125df86 --- /dev/null +++ b/editions/tw5.com/tiddlers/filters/examples/allbefore.tid @@ -0,0 +1,13 @@ +created: 20151017150902487 +creator: matabele +modified: 20151108051438263 +modifier: matabele +revision: 0 +tags: [[Operator Examples]] [[allbefore Operator]] +title: allbefore Operator (Examples) +type: text/vnd.tiddlywiki + +<<.using-days-of-week>> + +<<.operator-example 1 "[list[Days of the Week]allbefore[Wednesday]]">> +<<.operator-example 2 "[list[Days of the Week]allbefore:include[Wednesday]]">> diff --git a/editions/tw5.com/tiddlers/filters/examples/append.tid b/editions/tw5.com/tiddlers/filters/examples/append.tid new file mode 100644 index 000000000..3eddb92de --- /dev/null +++ b/editions/tw5.com/tiddlers/filters/examples/append.tid @@ -0,0 +1,17 @@ +created: 20151017150942725 +creator: matabele +modified: 20151108051557748 +modifier: matabele +revision: 0 +tags: [[Operator Examples]] [[append Operator]] +title: append Operator (Examples) +type: text/vnd.tiddlywiki + +<<.using-days-of-week>> + +<<.operator-example 1 "[list[Days of the Week]append[Tomorrow]]">> +<<.operator-example 2 "[list[Days of the Week]append[Yesterday Today Tomorrow]]">> + +;Append the first 4 short days of the week to our list + +<<.operator-example 3 "[list[Days of the Week]append:4{Days of the Week!!short}]">> diff --git a/editions/tw5.com/tiddlers/filters/examples/move.tid b/editions/tw5.com/tiddlers/filters/examples/move.tid new file mode 100644 index 000000000..a7c90e9ef --- /dev/null +++ b/editions/tw5.com/tiddlers/filters/examples/move.tid @@ -0,0 +1,13 @@ +created: 20151022123633433 +creator: matabele +modified: 20151108051643871 +modifier: matabele +revision: 0 +tags: [[Operator Examples]] [[move Operator]] +title: move Operator (Examples) +type: text/vnd.tiddlywiki + +<<.using-days-of-week>> + +<<.operator-example 1 "[list[Days of the Week]] +[move[Wednesday]]">> +<<.operator-example 2 "[list[Days of the Week]] +[move:-2[Wednesday]]">> diff --git a/editions/tw5.com/tiddlers/filters/examples/prepend.tid b/editions/tw5.com/tiddlers/filters/examples/prepend.tid new file mode 100644 index 000000000..d2dceced5 --- /dev/null +++ b/editions/tw5.com/tiddlers/filters/examples/prepend.tid @@ -0,0 +1,18 @@ +created: 20151017151508135 +creator: matabele +modified: 20151108051743531 +modifier: matabele +revision: 0 +tags: [[Operator Examples]] [[prepend Operator]] +title: prepend Operator (Examples) +type: text/vnd.tiddlywiki + +<<.using-days-of-week>> + +The operator may be used to prepend a number of items to the list. + +<<.operator-example 1 "[list[Days of the Week]prepend[Yesterday Today Tomorrow]]">> + +The operand may list only items without spaces -- to include items with spaces, use a reference to an array e.g. prepend the last three short days of the week to the list + +<<.operator-example 2 "[list[Days of the Week]!prepend:3{Days of the Week!!short}]">> diff --git a/editions/tw5.com/tiddlers/filters/examples/putafter.tid b/editions/tw5.com/tiddlers/filters/examples/putafter.tid new file mode 100644 index 000000000..0241e0a32 --- /dev/null +++ b/editions/tw5.com/tiddlers/filters/examples/putafter.tid @@ -0,0 +1,14 @@ +created: 20151017151905558 +creator: matabele +modified: 20151108051825288 +modifier: matabele +revision: 0 +tags: [[Operator Examples]] [[putafter Operator]] +title: putafter Operator (Examples) +type: text/vnd.tiddlywiki + +<<.using-days-of-week>> + +<<.operator-example 1 "[list[Days of the Week]] +[putafter[Wednesday]]">> +<<.operator-example 2 "[list[Days of the Week]] +[putafter:2[Tuesday]]">> +<<.operator-example 3 "[list[Days of the Week]] [[Yesterday]] [[Today]] [[Tomorrow]] +[putafter:3[Tuesday]]">> diff --git a/editions/tw5.com/tiddlers/filters/examples/putbefore.tid b/editions/tw5.com/tiddlers/filters/examples/putbefore.tid new file mode 100644 index 000000000..467cc09e6 --- /dev/null +++ b/editions/tw5.com/tiddlers/filters/examples/putbefore.tid @@ -0,0 +1,14 @@ +created: 20151022142602628 +creator: matabele +modified: 20151108051906935 +modifier: matabele +revision: 0 +tags: [[Operator Examples]] [[putbefore Operator]] +title: putbefore Operator (Examples) +type: text/vnd.tiddlywiki + +<<.using-days-of-week>> + +<<.operator-example 1 "[list[Days of the Week]] +[putbefore[Wednesday]]">> +<<.operator-example 2 "[list[Days of the Week]] +[putbefore:2[Tuesday]]">> +<<.operator-example 3 "[list[Days of the Week]] [[Yesterday]] [[Today]] [[Tomorrow]] +[putbefore:3[Tuesday]]">> diff --git a/editions/tw5.com/tiddlers/filters/examples/putfirst.tid b/editions/tw5.com/tiddlers/filters/examples/putfirst.tid new file mode 100644 index 000000000..7cbc0aece --- /dev/null +++ b/editions/tw5.com/tiddlers/filters/examples/putfirst.tid @@ -0,0 +1,14 @@ +created: 20151017152847899 +creator: matabele +modified: 20151108051943204 +modifier: matabele +revision: 0 +tags: [[Operator Examples]] [[putfirst Operator]] +title: putfirst Operator (Examples) +type: text/vnd.tiddlywiki + +<<.using-days-of-week>> + +<<.operator-example 1 "[list[Days of the Week]] +[putfirst[]]">> +<<.operator-example 2 "[list[Days of the Week]] +[putfirst:2[]]">> +<<.operator-example 3 "[list[Days of the Week]] [[Yesterday]] [[Today]] [[Tomorrow]] +[putfirst:-2[]]">> diff --git a/editions/tw5.com/tiddlers/filters/examples/putlast.tid b/editions/tw5.com/tiddlers/filters/examples/putlast.tid new file mode 100644 index 000000000..c31e28ced --- /dev/null +++ b/editions/tw5.com/tiddlers/filters/examples/putlast.tid @@ -0,0 +1,14 @@ +created: 20151017153037776 +creator: matabele +modified: 20151108052020761 +modifier: matabele +revision: 0 +tags: [[Operator Examples]] [[putlast Operator]] +title: putlast Operator (Examples) +type: text/vnd.tiddlywiki + +<<.using-days-of-week>> + +<<.operator-example 1 "[list[Days of the Week]] +[putlast[]]">> +<<.operator-example 2 "[list[Days of the Week]] +[putlast:2[]]">> +<<.operator-example 3 "one two three [list[Days of the Week]] +[putlast:-3[]]">> diff --git a/editions/tw5.com/tiddlers/filters/examples/remove.tid b/editions/tw5.com/tiddlers/filters/examples/remove.tid new file mode 100644 index 000000000..aa5755d10 --- /dev/null +++ b/editions/tw5.com/tiddlers/filters/examples/remove.tid @@ -0,0 +1,14 @@ +created: 20151018054129966 +creator: matabele +modified: 20151108052052606 +modifier: matabele +revision: 0 +tags: [[Operator Examples]] [[remove Operator]] +title: remove Operator (Examples) +type: text/vnd.tiddlywiki + +<<.using-days-of-week>> + +<<.operator-example 1 "[list[Days of the Week]] +[remove[Tuesday Wednesday Thursday]]">> +<<.operator-example 2 "[list[Days of the Week]] +[remove:3[Monday Wednesday Friday Saturday]]">> +<<.operator-example 3 "[list[Days of the Week]] +[!remove:2{Days of the Week!!list}]">> diff --git a/editions/tw5.com/tiddlers/filters/examples/replace.tid b/editions/tw5.com/tiddlers/filters/examples/replace.tid new file mode 100644 index 000000000..0e660be3b --- /dev/null +++ b/editions/tw5.com/tiddlers/filters/examples/replace.tid @@ -0,0 +1,14 @@ +created: 20151017153634099 +creator: matabele +modified: 20151108052127454 +modifier: matabele +revision: 0 +tags: [[Operator Examples]] [[replace Operator]] +title: replace Operator (Examples) +type: text/vnd.tiddlywiki + +<<.using-days-of-week>> + +<<.operator-example 1 "[list[Days of the Week]] Last +[replace[Wednesday]]">> +<<.operator-example 2 "[list[Days of the Week]] Last +[replace:2[Tuesday]]">> +<<.operator-example 3 "[list[Days of the Week]] [[Yesterday]] [[Today]] [[Tomorrow]] +[replace:3[Tuesday]]">> diff --git a/editions/tw5.com/tiddlers/filters/examples/sortby.tid b/editions/tw5.com/tiddlers/filters/examples/sortby.tid new file mode 100644 index 000000000..d69147ef7 --- /dev/null +++ b/editions/tw5.com/tiddlers/filters/examples/sortby.tid @@ -0,0 +1,14 @@ +created: 20151018123433917 +creator: matabele +modified: 20151108052158811 +modifier: matabele +revision: 0 +tags: [[Operator Examples]] [[sortby Operator]] +title: sortby Operator (Examples) +type: text/vnd.tiddlywiki + +<<.using-days-of-week>> + +<<.operator-example 1 "10 6 4 9 3 2 8 +[sortby[1 2 3 4 5 6 7 8 9 10]]">> +<<.operator-example 2 "Friday Tuesday Monday Thursday Sunday +[sortby{Days of the Week!!list}]">> +<<.operator-example 3 "1 Mon 5 Fri 4 Tue Sun 2 +[sortby{Days of the Week!!short}]">> diff --git a/editions/tw5.com/tiddlers/filters/move.tid b/editions/tw5.com/tiddlers/filters/move.tid new file mode 100644 index 000000000..6007c6da3 --- /dev/null +++ b/editions/tw5.com/tiddlers/filters/move.tid @@ -0,0 +1,17 @@ +caption: move +created: 20151022123413501 +creator: matabele +modified: 20151108082424017 +modifier: matabele +op-input: a list of items +op-output: re-ordered list of items +op-parameter: the list item to be used as a marker +op-parameter-name: marker +op-purpose: move marker N places in the list +op-suffix: an integer N, defaulting to 1 +revision: 0 +tags: [[Filter Operators]] [[Order Operators]] [[Listops Operators]] +title: move Operator +type: text/vnd.tiddlywiki + +<<.operator-examples "move">> diff --git a/editions/tw5.com/tiddlers/filters/prepend.tid b/editions/tw5.com/tiddlers/filters/prepend.tid new file mode 100644 index 000000000..e45c1b0b1 --- /dev/null +++ b/editions/tw5.com/tiddlers/filters/prepend.tid @@ -0,0 +1,18 @@ +caption: prepend +created: 20151017145439292 +creator: matabele +modified: 20151108051701587 +modifier: matabele +op-input: a list of items +op-neg-output: a list with items prepended from the tail of the operand array +op-output: a list with items prepended from the head of the operand array +op-parameter: the array of items to be prepended to the head of the list +op-parameter-name: list +op-purpose: prepend a range of items from an array to the list +op-suffix: an integer N, defaulting to all +revision: 0 +tags: [[Filter Operators]] [[Order Operators]] [[Listops Operators]] +title: prepend Operator +type: text/vnd.tiddlywiki + +<<.operator-examples "prepend">> diff --git a/editions/tw5.com/tiddlers/filters/putafter.tid b/editions/tw5.com/tiddlers/filters/putafter.tid new file mode 100644 index 000000000..dd41a4c61 --- /dev/null +++ b/editions/tw5.com/tiddlers/filters/putafter.tid @@ -0,0 +1,17 @@ +caption: putafter +created: 20151017144307862 +creator: matabele +modified: 20151108051805137 +modifier: matabele +op-input: a list of items +op-output: re-ordered list of items +op-parameter: the list item to be used as a marker +op-parameter-name: marker +op-purpose: move N trailing items after the marker +op-suffix: an integer N, defaulting to 1 +revision: 0 +tags: [[Filter Operators]] [[Order Operators]] [[Listops Operators]] +title: putafter Operator +type: text/vnd.tiddlywiki + +<<.operator-examples "putafter">> diff --git a/editions/tw5.com/tiddlers/filters/putbefore.tid b/editions/tw5.com/tiddlers/filters/putbefore.tid new file mode 100644 index 000000000..bf14b29eb --- /dev/null +++ b/editions/tw5.com/tiddlers/filters/putbefore.tid @@ -0,0 +1,17 @@ +caption: putbefore +created: 20140410103123179 +creator: matabele +modified: 20151108051842788 +modifier: matabele +op-input: a [[selection of titles|Title Selection]] +op-output: the first <<.place N>> input titles +op-parameter: an integer, defaulting to 1 +op-parameter-name: marker +op-purpose: move N trailing items before the marker +op-suffix: an integer N, defaulting to 1 +revision: 0 +tags: [[Filter Operators]] [[Order Operators]] [[Listops Operators]] +title: putbefore Operator +type: text/vnd.tiddlywiki + +<<.operator-examples "putbefore">> diff --git a/editions/tw5.com/tiddlers/filters/putfirst.tid b/editions/tw5.com/tiddlers/filters/putfirst.tid new file mode 100644 index 000000000..ed07a6ce2 --- /dev/null +++ b/editions/tw5.com/tiddlers/filters/putfirst.tid @@ -0,0 +1,16 @@ +caption: putfirst +created: 20151017144802884 +creator: matabele +modified: 20151108051922934 +modifier: matabele +op-input: a list of items +op-output: re-ordered list of items +op-parameter: ignored +op-purpose: move N trailing items to the head of the list +op-suffix: an integer N, defaulting to 1 +revision: 0 +tags: [[Filter Operators]] [[Order Operators]] [[Listops Operators]] +title: putfirst Operator +type: text/vnd.tiddlywiki + +<<.operator-examples "putfirst">> diff --git a/editions/tw5.com/tiddlers/filters/putlast.tid b/editions/tw5.com/tiddlers/filters/putlast.tid new file mode 100644 index 000000000..828315ec8 --- /dev/null +++ b/editions/tw5.com/tiddlers/filters/putlast.tid @@ -0,0 +1,16 @@ +caption: putlast +created: 20151017144822139 +creator: matabele +modified: 20151108052000425 +modifier: matabele +op-input: a list of items +op-output: re-ordered list of items +op-parameter: ignored +op-purpose: move N leading items to the tail of the list +op-suffix: an integer N, defaulting to 1 +revision: 0 +tags: [[Filter Operators]] [[Order Operators]] [[Listops Operators]] +title: putlast Operator +type: text/vnd.tiddlywiki + +<<.operator-examples "putlast">> diff --git a/editions/tw5.com/tiddlers/filters/remove.tid b/editions/tw5.com/tiddlers/filters/remove.tid new file mode 100644 index 000000000..bc656fae2 --- /dev/null +++ b/editions/tw5.com/tiddlers/filters/remove.tid @@ -0,0 +1,19 @@ +caption: remove +created: 20151017144531676 +creator: matabele +modified: 20151108052035773 +modifier: matabele +op-input: a list of items +op-neg-output: items removed from current list that appear at the tail of the operand array +op-output: items removed from current list that appear at the head of the operand array +op-parameter: an array of items to remove +op-parameter-name: array +op-prefix: causes N items from the end of the array to be removed +op-purpose: remove a range of items in an array from the current list +op-suffix: an integer N, defaulting to all +revision: 0 +tags: [[Filter Operators]] [[Order Operators]] [[Listops Operators]] +title: remove Operator +type: text/vnd.tiddlywiki + +<<.operator-examples "remove">> diff --git a/editions/tw5.com/tiddlers/filters/replace.tid b/editions/tw5.com/tiddlers/filters/replace.tid new file mode 100644 index 000000000..48cc4d45c --- /dev/null +++ b/editions/tw5.com/tiddlers/filters/replace.tid @@ -0,0 +1,17 @@ +caption: replace +created: 20151017144531676 +creator: matabele +modified: 20151108052110493 +modifier: matabele +op-input: a list of items +op-output: re-ordered list of items +op-parameter: the item to be used as a marker +op-parameter-name: marker +op-purpose: replace marker with N trailing items +op-suffix: an integer N, defaulting to 1 +revision: 0 +tags: [[Filter Operators]] [[Order Operators]] [[Listops Operators]] +title: replace Operator +type: text/vnd.tiddlywiki + +<<.operator-examples "replace">> diff --git a/editions/tw5.com/tiddlers/filters/sortby.tid b/editions/tw5.com/tiddlers/filters/sortby.tid new file mode 100644 index 000000000..087bd6cef --- /dev/null +++ b/editions/tw5.com/tiddlers/filters/sortby.tid @@ -0,0 +1,16 @@ +caption: sortby +created: 20151017145021839 +creator: matabele +modified: 20151108052142057 +modifier: matabele +op-input: a list of items +op-output: all items sorted by lookup list +op-parameter: a list specifying the order in which to sort the current list +op-parameter-name: order +op-purpose: sort the current list in the order of the list referenced in the operand +revision: 0 +tags: [[Filter Operators]] [[Order Operators]] [[Listops Operators]] +title: sortby Operator +type: text/vnd.tiddlywiki + +<<.operator-examples "sortby">> diff --git a/editions/tw5.com/tiddlers/widgets/ActionListopsWidget.tid b/editions/tw5.com/tiddlers/widgets/ActionListopsWidget.tid new file mode 100644 index 000000000..926a21f15 --- /dev/null +++ b/editions/tw5.com/tiddlers/widgets/ActionListopsWidget.tid @@ -0,0 +1,128 @@ +caption: action-listops +created: 20141025120850184 +creator: matabele +modified: 20151108075247352 +modifier: matabele +myfield: +revision: 0 +tags: ActionWidgets Widgets +title: ActionListopsWidget +type: text/vnd.tiddlywiki + +\define .operator-rows(filter) +<$list filter="$filter$"> +<$link to={{!!title}}>{{!!caption}} +{{!!op-purpose}} <$list filter="[all[current]tag[Common Operators]]">{{$:/core/images/done-button}} +<$list filter="[all[current]tag[Negatable Operators]]">`!` + +\end + +\define .group-heading(_) +$_$ +\end + +! Introduction + +The ''action-listops'' widget is an [[action widget|ActionWidgets]] that manipulates user lists in any field or data index. ActionWidgets are used within triggering widgets such as the ButtonWidget. + +! Content and Attributes + +The ''action-listops'' widget is invisible. Any content within it is ignored. + +|!Attribute |!Description | +|$tiddler |The title of the tiddler whose lists are to be modified (if not provided defaults to the [[current tiddler|Current Tiddler]] | +|$list |The name of a field to be manipulated as a list (defaults to 'list') | +|$index |Optional index of a property in a [[data tiddler|DataTiddlers]] index to be manipulated as a list | +|$filter |An optional filter expression, the output of which will be saved to the field/index being manipulated | +|$subfilter |An optional subfilter expression, which takes the list being manipulated as input, and saves the modified list back to the field/index being manipulated | +|$tags |An optional subfilter expression, which takes the 'tags' field of the target tiddler as input, and saves the modified list of tags back to the 'tags' field | + +! Extended Filter Operators + +A number of [[extended filter operators|The Extended Listops Filters]] are necessary for the manipulation of lists. These operators have been designed primarily for use in subfilter expressions whereby the modified current list is returned in place of the current list. + + +<<.group-heading "Listops Operators">> + + + + + +<<.operator-rows "[tag[Filter Operators]tag[Listops Operators]tag[Order Operators]!tag[String Operators]!tag[Tag Operators]!tag[Special Operators]sort[]]">> +
OperatorPurpose
+ +! Examples + +In this example we shall populate and then clear a list in an ordinary field (myfield) of this tiddler (the default.) + +<$macrocall $name='wikitext-example-without-html' +src="""<$button> +<$action-listops $list="myfield" $subfilter="efg hlm pqr"/> +Populate 'myfield' + +<$button> +<$action-listops $list="myfield" $subfilter="abc xyz"/> +Append More Items + +<$button> +<$action-listops $list="myfield" $subfilter="-abc -hlm"/> +Remove Items + +<$button> +<$action-listops $list="myfield" $filter="[[]]"/> +Clear 'myfield' + + +<$list filter="[list[!!myfield]]"> + +"""/> + +--- +In this example we shall append and remove items from a list in an ordinary field (myfield) of this tiddler (the default) and sort the resultant list. We shall then remove some of the appended items and sort the resulting list in reverse order. + +<$macrocall $name='wikitext-example-without-html' +src="""<$button> +<$action-listops $list="myfield" $subfilter="-efg ijk xyz [[this is a title]] +[sort[]]"/> +Mangle List + +<$button> +<$action-listops $list="myfield" $subfilter="-xyz -[[this is a title]] +[!sort[]]"/> +Unmangle List + + +<$list filter="[list[!!myfield]]"> + +"""/> + +--- +In this example we shall append a few tags to the 'tags' field of this tiddler (the default.) We shall then remove some of the appended tags. + +<$macrocall $name='wikitext-example-without-html' +src="""<$button> +<$action-listops $tags="+[append{Days of the Week!!short}] $:/tag1 $:/tag2 $:/tag3"/> +Populate 'tags' + +<$button> +<$action-listops $tags="+[!remove:2{!!tags}]"/> +Remove Last Two Tags + +<$button> +<$action-listops $tags="+[!prefix[$:/]]"/> +Remove System Tags + +<$button> +<$action-listops $tags="-Mon -Tue"/> +Remove Mon and Tue + +<$button> +<$action-listops $tags="+[prefix[$:/]] ActionWidgets Widgets"/> +Remove User Tags + +<$button> +<$action-listops $tags="+[[]] ActionWidgets Widgets"/> +Clear Tags + + +<$list filter="[list[!!tags]]"> + +"""/> diff --git a/editions/tw5.com/tiddlers/widgets/ListopsData.tid b/editions/tw5.com/tiddlers/widgets/ListopsData.tid new file mode 100644 index 000000000..2c64aebad --- /dev/null +++ b/editions/tw5.com/tiddlers/widgets/ListopsData.tid @@ -0,0 +1,9 @@ +created: 20151017094630847 +creator: matabele +daysoftheweek: four three Fri Thu Wed Tue Mon +modified: 20151108041839747 +modifier: matabele +title: ListopsData +type: application/x-tiddler-dictionary + +DataIndex: diff --git a/editions/tw5.com/tiddlers/widgets/The Extended Listops Filters.tid b/editions/tw5.com/tiddlers/widgets/The Extended Listops Filters.tid new file mode 100644 index 000000000..7c4a57152 --- /dev/null +++ b/editions/tw5.com/tiddlers/widgets/The Extended Listops Filters.tid @@ -0,0 +1,113 @@ +created: 20151014170727812 +creator: matabele +days: Fri Wed Mon Tue +dofwks: Mon Tue Wed Thu Fri Sat Sun +item1: six +item2: seven +item3: eight +list: Yesterday Today Tomorrow +marker: Thursday +modified: 20151108054957921 +modifier: matabele +myfield: Monday Tuesday [[Middle of the Week]] Thursday Friday Saturday Sunday +numbers: 1 2 3 4 five 6 7 8 9 +title: The Extended Listops Filters + +! Introduction + +A number of extended filters are necessary to manipulate lists. The first set of filters are designed to move items from the tail of the list and insert them at specified locations in the list. Items are often appended to the list before using these filters. In general, these filters accept a suffix specifying the number of items to move (defaults to 1.) + +A second set of filters are designed to either add or remove from the list, a selected range of items from an array. These filters are best used with a reference to an array, stored in a field or data indexe elsewhere in the wiki (they may be used with a simple list of items, provided the items do not include white space.) In general, these filters accept a suffix specifying the number of items to move (defaults to All.) + +! Examples + +In this example we shall populate the '~DataIndex' index of the tiddler '~MyData' with the names of the days of the week, then clear this list. + +<$macrocall $name='wikitext-example-without-html' +src="""<$button> +<$action-listops $tiddler="ListopsData" $index="DataIndex" $filter="[list[Days of the Week]]"/> +Get days-of-the-week + +<$button> +<$action-listops $tiddler="ListopsData" $index="DataIndex" $filter="[[]]"/> +Clear + + +{{ListopsData}}"""/> + +--- +In this example we shall slice the populated list from the 'DaysOfTheWeek' index of the tiddler '~MyData' in order to insert items before and after a marker item (Wednesday) that are first appended to the list. + +<$macrocall $name='wikitext-example-without-html' +src="""<$button> +<$action-listops $tiddler="ListopsData" $index="DataIndex" $subfilter="one two +[putbefore:2[Wednesday]]"/> +Put 2 Items Before Wednesday + +<$button> +<$action-listops $tiddler="ListopsData" $index="DataIndex" $subfilter="four five +[putafter:2[Wednesday]] three +[putbefore[Wednesday]]"/> +Put One Item Before & Two Items After Wednesday + + +{{ListopsData}}"""/> + +--- +In this example we shall slice the populated list from the 'DaysOfTheWeek' index of the tiddler '~MyData' in order to replace the marker item (Wednesday) with items which are first appended to the list. We shall then move 3 items to the head of the list which have first been appended to the list from referenced fields. + +<$macrocall $name='wikitext-example-without-html' +src="""<$button> +<$action-listops $tiddler="ListopsData" $index="DataIndex" $subfilter="[[---o]] [[o---]] +[replace:2{!!marker}]"/> +Replace '!!marker' with 2 Items + +<$button> +<$action-listops $tiddler="ListopsData" $index="DataIndex" $subfilter="[{!!item1}] [{!!item2}] [{!!item3}] +[putfirst:3[]]"/> +Put 3 Items First + + +{{ListopsData}}"""/> + +--- +In this example we shall slice the populated list from the 'DaysOfTheWeek' index of the tiddler '~MyData' in order to append to the truncated list, items from a referenced field. We shall then remove the first two of the items added. + +<$macrocall $name='wikitext-example-without-html' +src="""|list: |<$view field="list"/> | + +<$button> +<$action-listops $tiddler="ListopsData" $index="DataIndex" $subfilter="+[allbefore:include[Wednesday]] +[prepend{!!list}]"/> +Prepend '!!list' to items before 'Wednesday' + +<$button> +<$action-listops $tiddler="ListopsData" $index="DataIndex" $subfilter="+[remove:2{!!list}]"/> +Remove first two items in '!!list' from current list + +<$button> +<$action-listops $tiddler="ListopsData" $index="DataIndex" $subfilter="+[!remove:1{!!list}]"/> +Remove last item in '!!list' from current list + + +{{ListopsData}}"""/> + +--- +In this example we shall populate the list with numbers, then move items one by one from the head to the tail and from the tail to the head (best seen by clicking the lower buttons several times.) + +This example illustrates that the append[] and prepend[] operators do not enforce unique instances of an item and that, with the next run, any duplicates are removed. + +<$macrocall $name='wikitext-example-without-html' +src="""<$button> +<$action-listops $tiddler="ListopsData" $index="DataIndex" $filter="[[]]" $subfilter="+[append:3{!!numbers}]"/> +Setup some numbers + +<$button> +<$action-listops $tiddler="ListopsData" $index="DataIndex" $subfilter="+[!append:6{!!numbers}]"/> +Append more numbers + + +<$button> +<$action-listops $tiddler="ListopsData" $index="DataIndex" $subfilter="+[putfirst:2[]]"/> +Move last 2 items to the head + +<$button> +<$action-listops $tiddler="ListopsData" $index="DataIndex" $subfilter="+[putlast[]]"/> +Move the head to the last item + + +{{ListopsData}}"""/>