summaryrefslogtreecommitdiffstats
path: root/test-scheduler/ui/src/components/workflow_graph/wfresult.vue
blob: a252870c1c6b95a9b6c80b2cbcabd15c835b0aaa (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
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
<template>
<div style="min-height: 600px; overflow-x: auto; overflow-y: auto;">
    <div id="file-section1" class="col-md-4">
      <div id="workflow-content-div">
        <div class="dark-gray-bg" style="font-size: 17px; max-width: 500px; margin: 0 auto 10px;"> WORKFLOW.JSON CONTENT</div>
        <pre class="white-pink" id="workflow-content" style="height: 600px; background-color:#f5f5f5;"></pre>
      </div>
    </div>
    <div class="col-md-8" id="graph-show-section" style="">
      <div v-show="!wfloading" style="margin-top: 10px;">
          <div style="min-height: 30px; text-align: right;">
              <button v-show="workflowId != '' && !wfCompletedFlag" class="btn" v-on:click="completeWF(1)" title="mark the status 'complete' by hand.">mark it <strong>complete</strong></button>
          </div>
          <div id="workflow-graph">
          </div>
      </div>
      <div v-show="wfloading" class="spiner-example" id="loading">
        <div class="sk-spinner sk-spinner-three-bounce">
          <div class="sk-bounce1"></div>
          <div class="sk-bounce2"></div>
          <div class="sk-bounce3"></div>
        </div>
      </div>
          <div class="row">
          <div id="iframeContainer"></div>
          <div id="workflowId" style="display:none">
              <input name="workflowId" type="hidden" v-bind:value="workflowId" />
              <input name="function" type="hidden" value="graphLoad" />
              <button id="graphloadbtn" type="button" onclick="graphLoad()"></button>
          </div>
        </div>
    </div>
</div>
</template>
<script>
export default {
    props: ['workflowId', 'wfloading', 'wfJson'],
    name: 'wfresult',
    data: function() {
        return {
            frameLoadedFlag : false,
            initalPaintFlag : false,
            RESPONSE_TIME_LIMIT : 6000,
            responseTimeCounter : 0,
            wfCompletedFlag : false,
            intervalTime : 1000,
            timer: null
        }
    },
    computed: {
        wfget: function(){
            return !this.wfloading;
        }
    },
    watch: {
        workflowId: function(val){
            console.log("############## workflowId changed! " + val);
            this.graphLoad();
        },
        wfJson: function(val){
            this.fillWfContent(val);
        }
    },
    mounted: function(){
        window.clearInterval(this.timer);
    },
    destroyed: function(){
        window.clearInterval(this.timer);
    },
    methods: {
        graphLoad: function(){
            console.log("load function activate");
            this.reset();
            this.initialPaintWFGraph();
            var self = this;
              self.timer = window.setInterval(function() {
                if(!self.initalPaintFlag) {
                  if(self.responseTimeCounter > self.RESPONSE_TIME_LIMIT) {
                    self.initialPaintWFGraph();
                    self.responseTimeCounter = 0;
                  }
                } else {
                  if(self.frameLoadedFlag || self.responseTimeCounter > self.RESPONSE_TIME_LIMIT) {
                    self.repaintWFGraph();
                    self.responseTimeCounter = 0;
                  }
                }
                self.responseTimeCounter += self.intervalTime;
            }, self.intervalTime);
        },
        reset: function(){
            this.frameLoadedFlag = false;
              this.initalPaintFlag = false;
              this.RESPONSE_TIME_LIMIT = 6000;
              this.responseTimeCounter = 0;
              this.wfCompletedFlag = false;
              var graphDiv = document.getElementById("workflow-graph");
              graphDiv.innerHTML = '';
        },
        initialPaintWFGraph: function() {
            console.log("start to initial paint");
            this.setIframeSrc();
            var iframe = document.getElementById("testFrame");
            var self = this;
             if (iframe.attachEvent) {
               iframe.attachEvent("onload", function(){
                 window.setTimeout(function(){
                    self.frameLoadedFlag = true;
                    self.initialPaint();
                    console.log("finish to initial paint");
                 }, 1000);
               });
             } else {
               iframe.onload = function(){
                window.setTimeout(function(){
                    self.frameLoadedFlag = true;
                    self.initialPaint();
                    console.log("finish to initial paint");
                 }, 1000);
               }
             }
        },
        setIframeSrc: function(){
         var iframeContainer = document.getElementById("iframeContainer");
         var iframeDiv = document.getElementById("testFrame");
         if(iframeDiv != undefined ) {
             iframeContainer.removeChild(iframeDiv);
         }
         var apiPrefix = this.global.WF_GRAPH_ADDR + "#/workflow/id/";
         var apiUrl = apiPrefix + this.workflowId;
         console.log("workflowId prop:" + this.workflowId);
         var iframeDiv = "<iframe id=\"testFrame\" width=\"0\" height=\"0\" style=\"border: none;\" src=\"" + apiUrl + "\"></iframe>";
         iframeContainer.innerHTML = iframeDiv;
         this.frameLoadedFlag = false;
        },
        initialPaint: function() {
          var iframe = document.getElementById("testFrame");
          var frameContent = iframe.contentWindow.document.getElementById("graph-ui-content");
          if(frameContent == null) return;
          this.frameLoadedFlag = true;
          var content = frameContent.cloneNode(true);
          content.id = "graph-ui-content-1";
          var graphDiv = document.getElementById("workflow-graph");
          graphDiv.appendChild(content);
          this.initalPaintFlag = true;
          this.wfloading = false;
          console.log("####################wfloading   false######################");
        },
        repaint: function() {
             var iframe = document.getElementById("testFrame");
             var frameContent = iframe.contentWindow.document.getElementById("graph-ui-content");
             if(frameContent == null) return;
             this.frameLoadedFlag = true;
             var newContent = frameContent.cloneNode(true);
             var newNodes = newContent.getElementsByClassName("node");
             var oldContent = document.getElementById("graph-ui-content-1");
             var oldNodes = oldContent.getElementsByClassName("node");
             var completeText = iframe.contentWindow.document.getElementsByClassName("ui-content")[0].getElementsByTagName("h4")[0].getElementsByTagName("span")[3].innerHTML;
             if(newNodes.length > oldNodes.length) {
              console.log("execute in new > old");
                newContent.id = "graph-ui-content-1";
                var graphDiv = document.getElementById("workflow-graph");
                graphDiv.innerHTML = '';
                graphDiv.appendChild(newContent);
             }
             else if(newNodes.length == oldNodes.length) {
                console.log("execute in new = old");
                for(var i = 0; i < newNodes.length; i++)
                {
                  var newGraph = newNodes[i].children[0];
                  var newGraphStyle = newGraph.getAttribute("style");
                  var oldGraph = oldNodes[i].children[0];
                  var oldGraphStyle = oldGraph.getAttribute("style");
                  if(newGraphStyle != oldGraphStyle) {
                    oldGraph.setAttribute("style", newGraphStyle);
                  }
                  var newText = newNodes[i].getElementsByTagName("text")[0];
                  var newTextStyle = newText.getAttribute("style");
                  var oldText = oldNodes[i].getElementsByTagName("text")[0];
                  var oldTextStyle = oldText.getAttribute("style");
                  if(oldTextStyle != newTextStyle) {
                    oldText.setAttribute("style", newTextStyle);
                  }
                }
                if(completeText == "COMPLETED") {
                    this.completeWF(5);
                }
             }
             else {
                  console.log("execute in new < old");
             }
        },
        repaintWFGraph: function() {
         this.setIframeSrc();
         var iframe = document.getElementById("testFrame");
         var self = this;
         if (iframe.attachEvent) {
           iframe.attachEvent("onload", function(){
             window.setTimeout(function(){
                self.frameLoadedFlag = true;
                self.repaint();
             }, 1000);
           });
         } else {
          iframe.onload = function(){
            window.setTimeout(function(){
                self.frameLoadedFlag = true;
                self.repaint();
             }, 1000);
          }
         }
        },
        completeWF: function(delay) {
            this.wfCompletedFlag = true;
            console.log("#####################################completed: clean the interval  " + this.timer);
            window.clearInterval(this.timer);
            var self = this;
            window.setTimeout(function() {
              self.$emit("wfComplete", true);
            }, delay*1000);
        },
        fillWfContent: function(wfContent) {
            var contentDiv = document.getElementById("workflow-content");
            contentDiv.innerHTML = wfContent;
        }
    }
}
</script>
<style scoped>
#workflow-graph {
    text-align: center;
}
#workflow-graph > div{
    display: inline-block;
}
</style>