Skip to content

Commit

Permalink
fixup! Reference managers by UID
Browse files Browse the repository at this point in the history
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
  • Loading branch information
ChristophWurst committed Sep 22, 2022
1 parent 31ec9cc commit e12e89a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
21 changes: 15 additions & 6 deletions src/components/AppContent/ChartContent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,28 @@ export default {
},
computed: {
transformData() {
const contactsByUid = {}
const contacts = Object.keys(this.contactsList).map(key => {
const [uid, addressbook] = key.split('~')
if (!contactsByUid[addressbook]) {
contactsByUid[addressbook] = {}
}
return (contactsByUid[addressbook][uid] = this.contactsList[key])
})
const headManagers = []
const tempContacts = Object.keys(this.contactsList || {}).filter(key => this.contactsList[key].managersName).reduce((prev, cur) => {
const contact = this.contactsList[cur]
const manager = this.contactsList[contact.managersName]
const tempContacts = contacts.filter(contact => contact.managersName).reduce((prev, contact) => {
prev.push(transformNode(contact))
if (manager && !manager.managersName && !headManagers.includes(manager?.uid)) {
const manager = contactsByUid[contact.addressbook.id][contact.managersName]
if (manager && !manager.managersName && !headManagers.includes(manager.uid)) {
prev.push(transformNode(manager))
headManagers.push(manager?.uid)
headManagers.push(manager.uid)
}
return prev
}, [])
return headManagers.map(id => getChart(tempContacts, id))
return headManagers.map(uid => getChart(tempContacts, uid))
},
},
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/ChartTemplate.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<div class="org-chart-node">
<div class="inner-box">
<a href="" @click.prevent.stop="onAvatarClick(data.nodeId)">
<a href="" @click.prevent.stop="onAvatarClick(data.key)">
<Avatar
:disable-tooltip="true"
:display-name="data.fullName"
Expand Down
7 changes: 5 additions & 2 deletions src/utils/chartUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import { generateUrl } from '@nextcloud/router'
import { GROUP_ALL_CONTACTS } from '../models/constants.ts'

export const getChart = (list, parent, nodes = []) => {
if (!nodes.length) nodes.push(list.find(node => node.nodeId === parent))
if (!nodes.length) {
nodes.push(list.find(node => node.nodeId === parent))
}
const children = list.filter(node => {
return node.parentNodeId === parent
})
Expand All @@ -18,7 +20,8 @@ export const getChart = (list, parent, nodes = []) => {
export const transformNode = (contact) => {
return {
nodeId: contact.uid,
parentNodeId: contact.managersName ? contact.managersName.split('~')[0] : null,
key: contact.key,
parentNodeId: contact.managersName,
fullName: contact.displayName,
org: contact.org,
photoUrl: `${contact.url}?photo`,
Expand Down

0 comments on commit e12e89a

Please sign in to comment.