stat grouping is now everywhere
This lead to a complete refactor of the stats page Some things might break
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
import { union, difference, sortBy, findLast } from 'lodash';
|
||||
|
||||
export function nodeArrayToTree(nodes){
|
||||
export function nodeArrayToTree(nodes) {
|
||||
// Store a dict and list of all the nodes
|
||||
let nodeIndex = {};
|
||||
let nodeList = [];
|
||||
nodes.forEach( node => {
|
||||
nodes.forEach(node => {
|
||||
let treeNode = {
|
||||
node: node,
|
||||
children: [],
|
||||
@@ -20,7 +20,7 @@ export function nodeArrayToTree(nodes){
|
||||
treeNode.node.ancestors,
|
||||
ancestor => !!nodeIndex[ancestor.id]
|
||||
);
|
||||
if (ancestorInForest){
|
||||
if (ancestorInForest) {
|
||||
nodeIndex[ancestorInForest.id].children.push(treeNode);
|
||||
} else {
|
||||
forest.push(treeNode);
|
||||
@@ -33,13 +33,13 @@ export function nodeArrayToTree(nodes){
|
||||
export default function nodesToTree({
|
||||
collection, ancestorId, filter, options = {},
|
||||
includeFilteredDocAncestors = false, includeFilteredDocDescendants = false
|
||||
}){
|
||||
}) {
|
||||
// Setup the filter
|
||||
let collectionFilter = {
|
||||
'ancestors.id': ancestorId,
|
||||
'removed': {$ne: true},
|
||||
'removed': { $ne: true },
|
||||
};
|
||||
if (filter){
|
||||
if (filter) {
|
||||
collectionFilter = {
|
||||
...collectionFilter,
|
||||
...filter,
|
||||
@@ -49,7 +49,7 @@ export default function nodesToTree({
|
||||
let collectionSort = {
|
||||
order: 1
|
||||
};
|
||||
if (options && options.sort){
|
||||
if (options && options.sort) {
|
||||
collectionSort = {
|
||||
...collectionSort,
|
||||
...options.sort,
|
||||
@@ -58,7 +58,7 @@ export default function nodesToTree({
|
||||
let collectionOptions = {
|
||||
sort: collectionSort,
|
||||
}
|
||||
if (options){
|
||||
if (options) {
|
||||
collectionOptions = {
|
||||
...collectionOptions,
|
||||
...options,
|
||||
@@ -74,10 +74,10 @@ export default function nodesToTree({
|
||||
let ancestors = [];
|
||||
let ancestorIds = [];
|
||||
let docIds = [];
|
||||
if (filter && (includeFilteredDocAncestors || includeFilteredDocDescendants)){
|
||||
if (filter && (includeFilteredDocAncestors || includeFilteredDocDescendants)) {
|
||||
docIds = docs.map(doc => doc._id)
|
||||
}
|
||||
if (filter && includeFilteredDocAncestors){
|
||||
if (filter && includeFilteredDocAncestors) {
|
||||
// Add all ancestor ids to an array
|
||||
docs.forEach(doc => {
|
||||
ancestorIds = union(ancestorIds, doc.ancestors.map(ref => ref.id));
|
||||
@@ -86,19 +86,19 @@ export default function nodesToTree({
|
||||
ancestorIds = difference(ancestorIds, docIds);
|
||||
// Get the docs from the collection, don't worry about `removed` docs,
|
||||
// if their descendant was not removed, neither are they
|
||||
ancestors = collection.find({_id: {$in: ancestorIds}}).map(doc => {
|
||||
ancestors = collection.find({ _id: { $in: ancestorIds } }).map(doc => {
|
||||
// Mark that the nodes are ancestors of the found nodes
|
||||
doc._ancestorOfMatchedDocument = true;
|
||||
return doc;
|
||||
});
|
||||
}
|
||||
let descendants = [];
|
||||
if (filter && includeFilteredDocDescendants){
|
||||
if (filter && includeFilteredDocDescendants) {
|
||||
let exludeIds = union(ancestorIds, docIds);
|
||||
descendants = collection.find({
|
||||
'_id': {$nin: exludeIds},
|
||||
'ancestors.id': {$in: docIds},
|
||||
'removed': {$ne: true},
|
||||
'_id': { $nin: exludeIds },
|
||||
'ancestors.id': { $in: docIds },
|
||||
'removed': { $ne: true },
|
||||
}).map(doc => {
|
||||
// Mark that the nodes are descendants of the found nodes
|
||||
doc._descendantOfMatchedDocument = true;
|
||||
|
||||
Reference in New Issue
Block a user