@@ -31,6 +31,7 @@ export default {
3131 },
3232 data () {
3333 return {
34+ steps: {},
3435 buses: {},
3536 emptyStep: EmptyStepWrapper
3637 }
@@ -63,14 +64,6 @@ export default {
6364 }
6465 },
6566
66- steps () {
67- let steps = {}
68- forEachStep (this .root , (step ) => {
69- steps[step .path ] = step
70- })
71- return steps
72- },
73-
7467 pathIdMapping () {
7568 let mapping = {}
7669 forEachStep (this .root , (step ) => {
@@ -80,8 +73,11 @@ export default {
8073 }
8174 },
8275 watch: {
83- root (root ) {
84- forEachStep (root, (step ) => {
76+ root () {
77+ this .steps = {}
78+ forEachStep (this .root , (step ) => {
79+ this .steps [step .path ] = step
80+
8581 if (step .isParallel || step .isStage || step .isFlow ) {
8682 return
8783 }
@@ -91,6 +87,11 @@ export default {
9187 this .buses [step .path ] = new Vue ()
9288 }
9389 })
90+
91+ let children = this .$refs .tree .$el .children
92+ if (children .length > 0 ) {
93+ this .refreshStatus (children)
94+ }
9495 },
9596
9697 // action from pushed log
@@ -121,6 +122,17 @@ export default {
121122 }
122123 },
123124
125+ refreshStatus (treeNodes ) {
126+ for (let tn of treeNodes) {
127+ this .fillInStatusColor (tn)
128+
129+ let children = this .getChildrenNodes (tn)
130+ if (children .length > 0 ) {
131+ this .refreshStatus (children)
132+ }
133+ }
134+ },
135+
124136 onTreeExpanded () {
125137 if (this .nodes .length === 0 ) {
126138 return
@@ -140,6 +152,7 @@ export default {
140152 cleanTreeviewElement (treeNodes ) {
141153 for (let tn of treeNodes) {
142154 this .removeNodeLevelOrButtonFromTreeNode (tn)
155+ this .fillInStatusColor (tn)
143156
144157 let children = this .getChildrenNodes (tn)
145158 if (children .length > 0 ) {
@@ -167,13 +180,31 @@ export default {
167180 }
168181 },
169182
183+ fillInStatusColor (treeNode ) {
184+ const nodeRoot = treeNode .children [0 ];
185+ if (! nodeRoot) {
186+ return
187+ }
188+
189+ const stepId = this .findIdFromLoggingItem (nodeRoot)
190+ const nodePath = this .pathIdMapping [stepId]
191+ const wrapper = this .steps [nodePath]
192+
193+ if (! wrapper || ! wrapper .status ) {
194+ return
195+ }
196+
197+ this .addStatusDiv (nodeRoot, wrapper)
198+ this .addDotIndicator (nodeRoot, wrapper)
199+ },
200+
170201 getChildrenNodes (treeNode ) {
171202 if (treeNode .children .length !== 2 ) {
172203 return []
173204 }
174205
175206 const el = treeNode .children [1 ]
176- if (el .classList .contains (' v-treeview-node__children' )) {
207+ if (el .classList .contains (' v-treeview-node__children' )) {
177208 return el .children
178209 }
179210
@@ -186,6 +217,60 @@ export default {
186217
187218 isToggleBtn (el ) {
188219 return el .classList .contains (' v-treeview-node__toggle' )
220+ },
221+
222+ findIdFromLoggingItem (node ) {
223+ let el = node .getElementsByClassName (' step-logging-item' )
224+ return el[0 ].id ;
225+ },
226+
227+ addStatusDiv (nodeRoot , wrapper ) {
228+ const div = document .createElement (' div' )
229+ div .classList .add (" status" )
230+ div .style .backgroundColor = wrapper .status .config .style .fill
231+
232+ const levels = nodeRoot .getElementsByClassName (' v-treeview-node__level' )
233+ if (levels && levels .length > 0 ) {
234+ this .removeElementsByClass (nodeRoot, ' status' )
235+ nodeRoot .prepend (div)
236+ return
237+ }
238+
239+ wrapper .showStatus = true
240+ },
241+
242+ addDotIndicator (nodeRoot , wrapper ) {
243+ const levels = nodeRoot .getElementsByClassName (' v-treeview-node__level' )
244+ if (! levels) {
245+ return
246+ }
247+
248+ for (const level of levels) {
249+ this .removeElementsByClass (level, ' dot-ind' )
250+ level .appendChild (this .getDotIndicator (wrapper))
251+ }
252+ },
253+
254+ getDotIndicator (wrapper ) {
255+ const div = document .createElement (' div' )
256+ div .style .border = ' 2px'
257+ div .style .borderStyle = ' dotted'
258+ div .style .color = wrapper .status .config .style .fill
259+ div .style .width = ' 100%'
260+ div .style .marginLeft = ' 2px'
261+ div .classList .add (' dot-ind' )
262+ return div
263+ },
264+
265+ removeElementsByClass (el , className ) {
266+ let all = el .getElementsByClassName (className)
267+ if (! all) {
268+ return
269+ }
270+
271+ for (let item of all) {
272+ item .remove ()
273+ }
189274 }
190275 }
191276}
@@ -201,6 +286,23 @@ export default {
201286 .v-treeview-node__content {
202287 margin-left : 0 ;
203288 }
289+
290+ .v-treeview-node__level {
291+ max-height : 40px ;
292+ min-height : 40px ;
293+ display : flex ;
294+ justify-content : center ;
295+ align-items : center ;
296+ }
297+
298+ .status {
299+ position : absolute ;
300+ min-width : 4px ;
301+ max-width : 4px ;
302+ top : 0 ;
303+ bottom : 0 ;
304+ left : 0 ;
305+ }
204306 }
205307}
206308 </style >
0 commit comments