2022-09-06 12:03:37 +00:00
|
|
|
<template>
|
|
|
|
<table class="p-organizationchart-table">
|
|
|
|
<tbody>
|
|
|
|
<tr v-if="node">
|
|
|
|
<td :colspan="colspan">
|
|
|
|
<div :class="nodeContentClass" @click="onNodeClick">
|
2022-09-14 11:26:01 +00:00
|
|
|
<component :is="templates[node.type] || templates['default']" :node="node" />
|
2022-12-08 11:04:25 +00:00
|
|
|
<a v-if="toggleable" tabindex="0" class="p-node-toggler" @click="toggleNode" @keydown="onKeydown">
|
2023-04-07 06:49:35 +00:00
|
|
|
<component :is="templates.togglericon || (expanded ? 'ChevronDownIcon' : 'ChevronUpIcon')" :expanded="expanded" class="p-node-toggler-icon" />
|
2022-09-06 12:03:37 +00:00
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
<tr :style="childStyle" class="p-organizationchart-lines">
|
|
|
|
<td :colspan="colspan">
|
|
|
|
<div class="p-organizationchart-line-down"></div>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
<tr :style="childStyle" class="p-organizationchart-lines">
|
|
|
|
<template v-if="node.children && node.children.length === 1">
|
|
|
|
<td :colspan="colspan">
|
|
|
|
<div class="p-organizationchart-line-down"></div>
|
|
|
|
</td>
|
|
|
|
</template>
|
|
|
|
<template v-if="node.children && node.children.length > 1">
|
2022-09-14 11:26:01 +00:00
|
|
|
<template v-for="(child, i) of node.children" :key="child.key">
|
|
|
|
<td class="p-organizationchart-line-left" :class="{ 'p-organizationchart-line-top': !(i === 0) }"> </td>
|
|
|
|
<td class="p-organizationchart-line-right" :class="{ 'p-organizationchart-line-top': !(i === node.children.length - 1) }"> </td>
|
2022-09-06 12:03:37 +00:00
|
|
|
</template>
|
|
|
|
</template>
|
|
|
|
</tr>
|
|
|
|
<tr :style="childStyle" class="p-organizationchart-nodes">
|
|
|
|
<td v-for="child of node.children" :key="child.key" colspan="2">
|
2022-09-14 11:26:01 +00:00
|
|
|
<OrganizationChartNode
|
|
|
|
:node="child"
|
|
|
|
:templates="templates"
|
|
|
|
:collapsedKeys="collapsedKeys"
|
|
|
|
@node-toggle="onChildNodeToggle"
|
|
|
|
:collapsible="collapsible"
|
|
|
|
:selectionMode="selectionMode"
|
|
|
|
:selectionKeys="selectionKeys"
|
|
|
|
@node-click="onChildNodeClick"
|
|
|
|
/>
|
2022-09-06 12:03:37 +00:00
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2023-04-07 06:49:35 +00:00
|
|
|
import ChevronDownIcon from 'primevue/icon/chevrondown';
|
|
|
|
import ChevronUpIcon from 'primevue/icon/chevronup';
|
2022-09-14 11:26:01 +00:00
|
|
|
import { DomHandler } from 'primevue/utils';
|
2022-09-06 12:03:37 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'OrganizationChartNode',
|
|
|
|
emits: ['node-click', 'node-toggle'],
|
|
|
|
props: {
|
|
|
|
node: {
|
|
|
|
type: null,
|
|
|
|
default: null
|
|
|
|
},
|
|
|
|
templates: {
|
|
|
|
type: null,
|
|
|
|
default: null
|
|
|
|
},
|
|
|
|
collapsible: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
|
|
|
},
|
|
|
|
collapsedKeys: {
|
|
|
|
type: null,
|
|
|
|
default: null
|
|
|
|
},
|
|
|
|
selectionKeys: {
|
|
|
|
type: null,
|
|
|
|
default: null
|
|
|
|
},
|
|
|
|
selectionMode: {
|
|
|
|
type: String,
|
|
|
|
default: null
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
onNodeClick(event) {
|
|
|
|
if (DomHandler.hasClass(event.target, 'p-node-toggler') || DomHandler.hasClass(event.target, 'p-node-toggler-icon')) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.selectionMode) {
|
|
|
|
this.$emit('node-click', this.node);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onChildNodeClick(node) {
|
|
|
|
this.$emit('node-click', node);
|
|
|
|
},
|
|
|
|
toggleNode() {
|
|
|
|
this.$emit('node-toggle', this.node);
|
|
|
|
},
|
|
|
|
onChildNodeToggle(node) {
|
|
|
|
this.$emit('node-toggle', node);
|
2022-12-08 11:04:25 +00:00
|
|
|
},
|
|
|
|
onKeydown(event) {
|
|
|
|
if (event.code === 'Enter' || event.code === 'Space') {
|
|
|
|
this.toggleNode();
|
|
|
|
event.preventDefault();
|
|
|
|
}
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
nodeContentClass() {
|
2022-09-14 11:26:01 +00:00
|
|
|
return ['p-organizationchart-node-content', this.node.styleClass, { 'p-organizationchart-selectable-node': this.selectable, 'p-highlight': this.selected }];
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
leaf() {
|
|
|
|
return this.node.leaf === false ? false : !(this.node.children && this.node.children.length);
|
|
|
|
},
|
|
|
|
colspan() {
|
2022-09-14 11:26:01 +00:00
|
|
|
return this.node.children && this.node.children.length ? this.node.children.length * 2 : null;
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
childStyle() {
|
|
|
|
return {
|
|
|
|
visibility: !this.leaf && this.expanded ? 'inherit' : 'hidden'
|
2022-09-14 11:26:01 +00:00
|
|
|
};
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
expanded() {
|
|
|
|
return this.collapsedKeys[this.node.key] === undefined;
|
|
|
|
},
|
|
|
|
selectable() {
|
|
|
|
return this.selectionMode && this.node.selectable !== false;
|
|
|
|
},
|
|
|
|
selected() {
|
|
|
|
return this.selectable && this.selectionKeys && this.selectionKeys[this.node.key] === true;
|
|
|
|
},
|
|
|
|
toggleable() {
|
|
|
|
return this.collapsible && this.node.collapsible !== false && !this.leaf;
|
|
|
|
}
|
2023-04-07 06:49:35 +00:00
|
|
|
},
|
|
|
|
components: {
|
|
|
|
ChevronDownIcon: ChevronDownIcon,
|
|
|
|
ChevronUpIcon: ChevronUpIcon
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
};
|
2022-09-06 12:03:37 +00:00
|
|
|
</script>
|