/
ganttSideTableTree.vue
124 lines (115 loc) · 2.79 KB
/
ganttSideTableTree.vue
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<template>
<div class="gantt-side-table-tree">
<gantt-side-table-tree-item
class="item"
v-for="model in treeData"
track-by="$index"
:model.sync="model">
</gantt-side-table-tree-item>
</div>
</template>
<script>
import moment from 'moment'
import ganttSideTableTreeItem from './ganttSideTableTreeItem'
import { setTableTree } from '../vuex/actions'
import { getGanttData } from '../vuex/getters'
export default {
name: 'ganttSideTableTree',
vuex: {
getters: {
data: getGanttData
},
actions: {
setTableTree
}
},
created () {
let treeData = { children: [] }
let childrenCollection = []
let rowDatetimeRange = {
from: '',
to: ''
}
let getRowDateRange = (tasks) => {
let rowStartFrom = moment().add(9999, 'year')
let rowEndTo = moment().subtract(9999, 'year')
tasks.forEach((task) => {
rowStartFrom = moment.min(rowStartFrom, task.from.clone())
rowEndTo = moment.max(rowEndTo, task.to.clone())
})
return {
from: rowStartFrom,
to: rowEndTo
}
}
this.data.forEach((data) => {
if (data.children
&& data.children.length > 0)
{
childrenCollection = childrenCollection.concat(data.children)
data.children.forEach((child) => {
let __index = this.data.findIndex((d) => {
return d.id === child
})
if (__index > -1) {
if (treeData.id === this.data[__index].id) {
treeData = Object.assign({}, {
id: data.id,
name: data.name,
children: [treeData]
})
} else {
treeData = Object.assign({}, treeData, {
id: data.id,
name: data.name
})
treeData.children.push({
id: this.data[__index].id,
name: this.data[__index].name,
children: []
})
}
}
})
}
});
if (treeData.length > 0) {
treeData = [treeData];
} else {
treeData = [];
}
this.data.forEach((data) => {
if (childrenCollection.indexOf(data.id) === -1
&& data.children.length === 0) {
treeData.push({
id: data.id,
name: data.name,
children: []
})
}
})
this.setTableTree(treeData)
this.$nextTick(() => {
this.treeData = treeData
})
},
components: {
ganttSideTableTreeItem
},
data () {
return {
treeData: []
}
}
}
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="scss" scoped>
.gantt-side-table-tree {
overflow: hidden;
margin: 0;
padding: 0;
display: flex;
flex-direction: column;
}
</style>