summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristoph Wurst <ChristophWurst@users.noreply.github.com>2022-09-27 19:36:07 +0200
committerGitHub <noreply@github.com>2022-09-27 19:36:07 +0200
commite058254f588c3ade89c111ab2246e9f93ebc9ce8 (patch)
tree4f002cc392b929cae8a9545bc3d03c6908a58612
parent307840462a8d99c48c4c40a79481fb734cddeb30 (diff)
parent240ee34f0515580c13537ea1e8c480dbc41bf7eb (diff)
Merge pull request #2962 from nextcloud/fix/org-chart-save-uid-and-display-name
Save UID and display name for managers of the org chart
-rw-r--r--src/components/AppContent/ChartContent.vue9
-rw-r--r--src/components/ContactDetails/ContactDetailsProperty.vue20
-rw-r--r--src/models/contact.js19
-rw-r--r--src/utils/chartUtils.js20
4 files changed, 36 insertions, 32 deletions
diff --git a/src/components/AppContent/ChartContent.vue b/src/components/AppContent/ChartContent.vue
index b77f61a9..e9c3b82f 100644
--- a/src/components/AppContent/ChartContent.vue
+++ b/src/components/AppContent/ChartContent.vue
@@ -44,14 +44,17 @@ export default {
prev.push(transformNode(contact))
const manager = contactsByUid[contact.addressbook.id][contact.managersName]
- if (manager && !manager.managersName && !headManagers.includes(manager.uid)) {
+ if (manager && !manager.managersName && !headManagers.some(m => m.nodeId === manager.uid)) {
prev.push(transformNode(manager))
- headManagers.push(manager.uid)
+ headManagers.push(transformNode(manager))
}
return prev
}, [])
- return headManagers.map(uid => getChart(tempContacts, uid))
+ const charts = headManagers.map(managerNode => getChart(tempContacts, managerNode))
+ // Debugging logs to figure out why a graph might not show. Leave this in place until the logic is bulletproof
+ console.debug('Org charts', charts.map((nodes, index) => nodes.map(n => `list ${index} ${n.nodeId} (${n.fullName}) -> ${n.parentNodeId}`)))
+ return charts
},
},
}
diff --git a/src/components/ContactDetails/ContactDetailsProperty.vue b/src/components/ContactDetails/ContactDetailsProperty.vue
index 2882853e..feb8c06c 100644
--- a/src/components/ContactDetails/ContactDetailsProperty.vue
+++ b/src/components/ContactDetails/ContactDetailsProperty.vue
@@ -230,7 +230,7 @@ export default {
return {
...prev,
[contact.uid]: {
- id: contact.uid,
+ id: contact.key,
name: contact.displayName,
},
}
@@ -333,6 +333,16 @@ export default {
? this.property.getValues()[0]
: this.property.getValues()
}
+ if (this.propName === 'x-managersname') {
+ if (this.property.getParameter('uid')) {
+ return this.property.getParameter('uid') + '~' + this.contact.addressbook.id
+ }
+ // Try to find the matching contact by display name
+ // TODO: this only *shows* the display name but doesn't assign the missing UID
+ const displayName = this.property.getFirstValue()
+ const other = this.otherContacts(this.contact).find(contact => contact.displayName === displayName)
+ return other?.key
+ }
return this.property.getFirstValue()
},
set(data) {
@@ -342,7 +352,13 @@ export default {
? this.property.setValues([data])
: this.property.setValues(data)
} else {
- this.property.setValue(data)
+ if (this.propName === 'x-managersname') {
+ const manager = this.$store.getters.getContact(data)
+ this.property.setValue(manager.displayName)
+ this.property.setParameter('uid', manager.uid)
+ } else {
+ this.property.setValue(data)
+ }
}
this.updateContact()
},
diff --git a/src/models/contact.js b/src/models/contact.js
index f97c6b71..8c8bbdab 100644
--- a/src/models/contact.js
+++ b/src/models/contact.js
@@ -371,22 +371,11 @@ export default class Contact {
* @memberof Contact
*/
get managersName() {
- return this.firstIfArray(this.vCard.getFirstPropertyValue('x-managersname'))
- }
-
- /**
- * Set the x-managersname
- *
- * @param {string} managersName the x-managersname data
- * @memberof Contact
- */
- set managersName(managersName) {
- // delete the org if empty
- if (isEmpty(managersName)) {
- this.vCard.removeProperty('x-managersname')
- return
+ const prop = this.vCard.getFirstProperty('x-managersname')
+ if (!prop) {
+ return null
}
- this.vCard.updatePropertyWithValue('x-managersname', managersName)
+ return prop.getFirstParameter('uid') ?? null
}
/**
diff --git a/src/utils/chartUtils.js b/src/utils/chartUtils.js
index 66bc75a5..7d48a38a 100644
--- a/src/utils/chartUtils.js
+++ b/src/utils/chartUtils.js
@@ -1,20 +1,16 @@
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))
- }
- const children = list.filter(node => {
- return node.parentNodeId === parent
- })
-
- children.forEach(node => {
- nodes.push(node)
- getChart(list, node.nodeId, nodes)
+export const getChart = (allNodes, currentNode) => {
+ const result = [currentNode]
+ const children = allNodes.filter(node => {
+ return node.nodeId !== currentNode.nodeId && node.parentNodeId === currentNode.nodeId
})
- return nodes
+ return [
+ ...result,
+ ...children.flatMap(child => getChart(allNodes, child)),
+ ]
}
export const transformNode = (contact) => {