From 5c422e892a65432a9dc1ab6da491f514992b8cd4 Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Wed, 5 Apr 2017 12:31:19 -0300 Subject: [PATCH] Add children fo traverse callback --- kfet/static/kfet/js/kfet.api.js | 7 +++++-- kfet/static/kfet/js/kpsul.js | 27 ++++++++++++--------------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/kfet/static/kfet/js/kfet.api.js b/kfet/static/kfet/js/kfet.api.js index 730fab12..4f73e20b 100644 --- a/kfet/static/kfet/js/kfet.api.js +++ b/kfet/static/kfet/js/kfet.api.js @@ -733,8 +733,11 @@ class ModelForest { */ traverse(modelname, callback) { function recurse(node) { - if (node.modelname === modelname) - callback(node.content, node.parent && node.parent.content || null) ; + if (node.modelname === modelname) { + var parent = node.parent && node.parent.content || null; + var children = node.children.map( (child) => child.content); + callback(node.content, children, parent); + } for (let child of node.children) recurse(child); diff --git a/kfet/static/kfet/js/kpsul.js b/kfet/static/kfet/js/kpsul.js index af2e4f5f..e1bb2b55 100644 --- a/kfet/static/kfet/js/kpsul.js +++ b/kfet/static/kfet/js/kpsul.js @@ -575,12 +575,9 @@ class ArticleAutocomplete { var lower = prefix.toLowerCase() ; var that = this ; - article_list.traverse('article', function(article, category) { - if (article.name.toLowerCase().startsWith(lower)) { + article_list.traverse('article', function(article) { + if (article.name.toLowerCase().startsWith(lower)) that.matching.push(article); - if (that.active_categories.indexOf(category) == -1) - that.active_categories.push(category); - } }); if (this.matching.length == 1) { @@ -602,14 +599,18 @@ class ArticleAutocomplete { updateDisplay() { var that = this; - this.manager.list.traverse('article', function(article, category) { - if (that.matching.indexOf(article) != -1) { - that._$container.find('#article-'+article.id).show(); - } else { - that._$container.find('#article-'+article.id).hide(); + this.manager.list.traverse('category', function(category, articles) { + var is_active = false; + for (let article of articles) { + if (that.matching.indexOf(article) != -1) { + is_active = true; + that._$container.find('#article-'+article.id).show(); + } else { + that._$container.find('#article-'+article.id).hide(); + } } - if (that.active_categories.indexOf(category) != -1) { + if (is_active) { that._$container.find('#category-'+category.id).show(); } else { that._$container.find('#category-'+category.id).hide(); @@ -636,14 +637,10 @@ class ArticleAutocomplete { this.manager.list.traverse('article', function(article) { that.matching.push(article); }); - this.manager.list.traverse('category', function(category) { - that.active_categories.push(category); - }); this.updateDisplay(); } resetMatch() { this.matching = []; - this.active_categories = []; } }