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