Skip to content

Commit

Permalink
[front: editLogs] format array of strings
Browse files Browse the repository at this point in the history
  • Loading branch information
t8g committed Sep 27, 2017
1 parent 0762acf commit 5d0a19d
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions client/src/app/isari-data.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,14 +195,19 @@ export class IsariDataService {
if (obj.value && obj.ref) return this.getForeignLabel(obj.ref, obj.value).map(x => x[0].value);

const format = (o, refs, level = 0) => {
if (isArray(o)) return o.map(oo => format(oo, refs, level)).join("\n---\n");
if (isArray(o) && o.length === 0) return "?";
if (isArray(o)) {
return o.some(isPlainObject)
? o.map(oo => format(oo, refs, level)).join("\n")
: o.join(', ');
}

return Object.keys(o)
.reduce((s, k) => {
s += `${' '.repeat(level)}${k} : `;
if (typeof o[k] === 'string') s += o[k];
else if (o[k].ref && o[k].value) s += o[k].value.length === 0 ? '[]' : (refs[o[k].value] || '????');
else s += "\n" + format(o[k], refs, level + 1);
else s += format(o[k], refs, level + 1);
return s + "\n";
}, "");
}
Expand Down

0 comments on commit 5d0a19d

Please sign in to comment.