44 lines
1.3 KiB
JavaScript
44 lines
1.3 KiB
JavaScript
import { fetchData } from "./js/api.js";
|
|
import { createAccordion } from "./js/accordion.js";
|
|
|
|
|
|
function start() {
|
|
fetchData("accounts").then((data) => {
|
|
const container = document.getElementById("accordion-container");
|
|
container.innerHTML = "";
|
|
|
|
data = data.sort((a, b) => (a.number > b.number) ? 1 : ((b.number > a.number) ? -1 : 0));
|
|
|
|
data.forEach(element => {
|
|
const linkName = element.name;
|
|
|
|
const childrenContainer = createChildrens(element.subaccounts, linkName);
|
|
createAccordion(container, element, childrenContainer, linkName);
|
|
});
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Funktion mit rekusiven Aufruf um verschachtelte Accordions zu erzeugen
|
|
* @param {array} subaccounts
|
|
* @param {string} linkName
|
|
* @returns
|
|
*/
|
|
function createChildrens(subaccounts, linkName) {
|
|
const childrenContainer = document.createElement("div");
|
|
childrenContainer.setAttribute("class", "children-container");
|
|
|
|
if (subaccounts.length > 0) {
|
|
subaccounts.forEach(account => {
|
|
const linkHref = `${linkName}:${account.name}`;
|
|
const container = createChildrens(account.subaccounts, linkHref);
|
|
createAccordion(childrenContainer, account, container, linkHref);
|
|
})
|
|
|
|
|
|
return childrenContainer;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
start(); |