Use new typescript api for user graphs

This commit is contained in:
Antoine Bartuccio 2024-10-09 17:16:48 +02:00
parent a98c924b24
commit 37f62e15cf
2 changed files with 19 additions and 11 deletions

View File

@ -1,16 +1,26 @@
import cytoscape from "cytoscape";
import cxtmenu from "cytoscape-cxtmenu";
import klay from "cytoscape-klay";
import { familyGetFamilyGraph } from "#openapi";
cytoscape.use(klay);
cytoscape.use(cxtmenu);
async function getGraphData(url, godfathersDepth, godchildrenDepth) {
const data = await (
await fetch(
`${url}?godfathers_depth=${godfathersDepth}&godchildren_depth=${godchildrenDepth}`,
)
).json();
async function getGraphData(userId, godfathersDepth, godchildrenDepth) {
const data = (
await familyGetFamilyGraph({
path: {
// biome-ignore lint/style/useNamingConvention: api is snake_case
user_id: userId,
},
query: {
// biome-ignore lint/style/useNamingConvention: api is snake_case
godfathers_depth: godfathersDepth,
// biome-ignore lint/style/useNamingConvention: api is snake_case
godchildren_depth: godchildrenDepth,
},
})
).data;
return [
...data.users.map((user) => {
return { data: user };
@ -160,8 +170,7 @@ function createGraph(container, data, activeUserId) {
/**
* @typedef FamilyGraphConfig
* @param {string} apiUrl Base url for fetching the tree as a string
* @param {string} activeUser Id of the user to fetch the tree from
* @param {number} activeUser Id of the user to fetch the tree from
* @param {number} depthMin Minimum tree depth for godfathers and godchildren
* @param {number} depthMax Maximum tree depth for godfathers and godchildren
**/
@ -248,7 +257,7 @@ window.loadFamilyGraph = (config) => {
async fetchGraphData() {
this.graphData = await getGraphData(
config.apiUrl,
config.activeUser,
this.godfathersDepth,
this.godchildrenDepth,
);

View File

@ -92,8 +92,7 @@
<script>
window.addEventListener("DOMContentLoaded", () => {
loadFamilyGraph({
apiUrl: "{{ api_url }}",
activeUser: "{{ object.id }}",
activeUser: {{ object.id }},
depthMin: {{ depth_min }},
depthMax: {{ depth_max }},
});