+ datafilter(json) {
+ // find viable rows from json data
+ let ids = new Set(Object.keys(json));
+ const selection = {...json}; // clone
+
+ if (this.preset.cat !== undefined) {
+ ids.clear();
+ let children = [this.preset.cat];
+ for (let loop = 0; children.length && loop < 20; loop++) {
+ for (let child of children) ids.add(child.toString());
+ children = children.map(cat => json[cat][3]).filter(is => is).flat()
+ }
+ }
+ if (this.preset.image) {
+ ids = ids.filter(id => json[id][2]);
+ }
+ if (this.preset.level !== undefined) {
+ ids = ids.filter(id => json[id][1] <= this.preset.level);
+ }
+
+ // keep only wanted ids
+ for (let id in selection) {
+ if (id && !ids.has(id)) {
+ delete selection[id];
+ }
+ }
+
+ // retain orphaned references in grandparent categories
+ for (let id in selection) {
+ selection[id][3] = function subresolve(subs) {
+ //console.log(subs);
+ return (subs || []).flatMap(sub =>
+ sub in selection ? [sub] : subresolve(json[sub][3])
+ );
+ }(selection[id][3]);
+ }
+ return selection;
+ }
+