summaryrefslogtreecommitdiffstats
path: root/src/components/AppContent/ChartContent.vue
blob: b77f61a98e42eed9bd5b75886ec3330e7b6c3138 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<template>
	<AppContent>
		<OrgChart :data="transformData" />
	</AppContent>
</template>

<script>
import AppContent from '@nextcloud/vue/dist/Components/NcAppContent'

import OrgChart from '../OrgChart.vue'
import { getChart, transformNode } from '../../utils/chartUtils'

export default {
	name: 'ChartContent',
	components: {
		AppContent,
		OrgChart,
	},
	props: {
		contactsList: {
			type: Object,
			required: true,
		},
	},
	data() {
		return {
			data: [],
			searchQuery: '',
		}
	},
	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 = contacts.filter(contact => contact.managersName).reduce((prev, contact) => {
				prev.push(transformNode(contact))

				const manager = contactsByUid[contact.addressbook.id][contact.managersName]
				if (manager && !manager.managersName && !headManagers.includes(manager.uid)) {
					prev.push(transformNode(manager))
					headManagers.push(manager.uid)
				}
				return prev
			}, [])

			return headManagers.map(uid => getChart(tempContacts, uid))
		},
	},
}
</script>