Change child sort + bugfix grom prev commit

This commit is contained in:
Ludovic Stephan 2017-04-09 12:30:15 -03:00
parent 73fb3c419e
commit 9ad208a171

View file

@ -669,7 +669,11 @@ class ModelForest {
var children = this.get_children(node);
if (children) {
children.sort(struct_data.child_sort);
if (struct_data.child_sort)
children.sort(struct_data.child_sort);
else
children.sort(children[0].constructor.compare);
for (let child of children) {
var $child = this.render_element(child, templates, options);
$container.append($child);
@ -702,7 +706,11 @@ class ModelForest {
* @param {Object} [options] Options for element render method
*/
display($container, templates, options) {
this.roots.sort(this.constructor.root_sort);
if (this.constructor.root_sort)
this.roots.sort(this.constructor.root_sort);
else
this.roots.sort(this.roots[0].constructor.compare);
for (let root of this.roots) {
$container.append(this.render_element(root, templates, options));
}
@ -720,8 +728,9 @@ class ModelForest {
var that = this;
function recurse(node) {
if (node.constructor.verbose_name === modelname) {
if callback(node);
if (callback(node)) {
return true;
}
}
var children = that.get_children(node);
@ -730,6 +739,8 @@ class ModelForest {
if (recurse(child))
return true;
}
return false;
}
for (let root of this.roots)
@ -809,20 +820,11 @@ class ArticleList extends APIModelForest {
'category': {
'model': ArticleCategory,
'children': 'articles',
'child_sort': Article.compare,
},
};
}
/**
* Comparison function to sort roots
* @default <tt>{@link Models.ArticleCategory.compare|ArticleCategory.compare}</tt>
*/
static get root_sort() {
return ArticleCategory.compare;
}
/**
* Default url to get ArticlList data
* @abstract