mirror of
https://gitlab.aachen.ccc.de/inventory/in.git
synced 2024-11-29 10:13:59 +01:00
detect indirect loops in tree
This commit is contained in:
parent
0961d0e47d
commit
daf41ab17e
1 changed files with 13 additions and 4 deletions
|
@ -39,18 +39,27 @@ function renderItems() {
|
|||
}
|
||||
|
||||
function getLocString(items, item) {
|
||||
if (item.is_in == item.id) {
|
||||
return ['in ↻', `${item.id} is in itself`];
|
||||
}
|
||||
let ancestors = [];
|
||||
let next = item;
|
||||
let loop = false;
|
||||
while (next) {
|
||||
if (ancestors.includes(next)) {
|
||||
loop = true;
|
||||
if (ancestors.length == 1) {
|
||||
ancestors.push(null);
|
||||
}
|
||||
break;
|
||||
}
|
||||
ancestors.unshift(next);
|
||||
next = items[next.is_in];
|
||||
}
|
||||
ancestors.pop();
|
||||
const loc = ancestors.map(i => i.id).join(' ➜ ') || '⬚';
|
||||
let loc = ancestors.map(i => i.id).join(' ➜ ') || '⬚';
|
||||
let longloc = ancestors.map(i => `${i.type || ''} ${i.id} ${i.name && `(${i.name})` || ''}`).join(' ➜ ') || 'universe';
|
||||
if (loop) {
|
||||
loc += ' ↻';
|
||||
longloc += ' ↻';
|
||||
}
|
||||
return [loc, `${item.id} is in ${longloc}`];
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue