fix testsuite name bugs and improve some ui details
[bottlenecks.git] / test-scheduler / ui / src / components / testcase_content.vue
1 <template>
2   <div class="wrapper wrapper-content animated fadeIn">
3     <div class="row" style="margin-bottom: 20px;">
4       <div class="col-md-12">
5         <ol class="breadcrumb" style="padding-left: 20px; font-size: 17px;">
6           <li>
7             <router-link to="/" >root</router-link>
8           </li>
9           <li>
10             <router-link :to="{ path: '/testcase', query: { name: suitename }}" >{{this.$route.query.suiteName}}</router-link>
11           </li>
12           <li>
13             <router-link :to="{ path: '/content', query: { suiteName: suitename, caseName: casename } }"><b>{{this.$route.query.caseName}}</b></router-link>
14           </li>
15         </ol>
16       </div>
17     </div>
18     <div id="page-content" class="row">
19       <div class="col-lg-12">
20         <div class="ibox">
21             <div class="ibox-title">
22                 <h5 style="font-size:26px;margin-top: -3px;">Test Case Content</h5>
23                 <div v-show="contentLoading || contentSaving" class="sk-spinner sk-spinner-circle" style="float: left;margin-left: 10px;">
24                     <div class="sk-circle1 sk-circle"></div>
25                     <div class="sk-circle2 sk-circle"></div>
26                     <div class="sk-circle3 sk-circle"></div>
27                     <div class="sk-circle4 sk-circle"></div>
28                     <div class="sk-circle5 sk-circle"></div>
29                     <div class="sk-circle6 sk-circle"></div>
30                     <div class="sk-circle7 sk-circle"></div>
31                     <div class="sk-circle8 sk-circle"></div>
32                     <div class="sk-circle9 sk-circle"></div>
33                     <div class="sk-circle10 sk-circle"></div>
34                     <div class="sk-circle11 sk-circle"></div>
35                     <div class="sk-circle12 sk-circle"></div>
36                 </div>
37                 <div class="ibox-tools">
38                     <button class="btn btn-info btn-sm my-button-sm" type="button" v-on:click="runTestcase()">Run</button>
39                     <button class="btn btn-success btn-sm my-button-sm" type="button" v-on:click="setEditable()">Edit</button>
40                     <button v-show="isEditable" class="btn btn-warning btn-sm my-button-sm" v-on:click="saveTestcase()" type="button">Save</button>
41                     <button v-show="isEditable" class="btn btn-danger btn-sm my-button-sm" v-on:click="cancelEdit()" type="button">Cancel</button>
42                     <a class="collapse-link">
43                         <i class="fa fa-chevron-up"></i>
44                     </a>
45                     <a class="fullscreen-link">
46                         <i class="fa fa-expand"></i>
47                     </a>
48                 </div>
49             </div>
50             <div class="ibox-content" style="max-height: 600px; overflow-y: auto; padding: 0; border: 1px solid #e7e7e7;">
51                 <div style='text-align:center;'>
52                   <textarea v-show='!isEditable' v-model="content" id="tc_content" style="white-space:nowrap; overflow:scroll;max-width:2400px; width: 100%;height: 100%;min-height: 500px;font-size:16px;border:none; vertical-align: middle; padding: 30px 0 20px 40px;">
53                   </textarea>
54                 </div><editor v-show='isEditable' v-bind:saveSignal='saveSignal' v-bind = 'editorContent' v-on:saveResponse='processSaveResponse'></editor>
55             </div>
56         </div>
57       </div>
58     </div>
59     <hr />
60     <div class="row" v-show="runYet">
61       <div class="col-lg-12">
62           <div class="ibox">
63               <div class="ibox-title">
64                   <h5 style="font-size:26px;margin-top: -3px;">Workflow</h5>
65                   <div class="ibox-tools">
66                       <a class="collapse-link">
67                           <i class="fa fa-chevron-up"></i>
68                       </a>
69                       <a class="fullscreen-link">
70                           <i class="fa fa-expand"></i>
71                       </a>
72                   </div>
73               </div>
74               <div class="ibox-content" style="padding-top: 60px;">
75                   <wfresult v-bind:workflowId="workflowId" v-bind:wfloading='wfloading' v-bind:wfJson='wfJson'></wfresult>
76               </div>
77           </div>
78       </div>
79     </div>
80   </div>
81 </template>
82 <script>
83 import editor from './editor/editor.vue'
84 import wfresult from './workflow_graph/wfresult.vue'
85 import showMessage from './message/showMessage.js'
86 export default {
87     name: 'testcase_content',
88     data () {
89       return {
90           content: '',
91           editorContent: {'stepList': [], 'mainOrdersList': [], 'subflowList': []},
92           bakContent: '',
93           isEditable: false,
94           contentLoading: false,
95           contentSaving: false,
96           suitename:this.$route.query.suiteName,
97           casename:this.$route.query.caseName,
98           workflowId: '',
99           wfloading: false,
100           wfJson: '',
101           wfComplete: false,
102           saveSignal: false,
103           runYet: false,
104       }
105     },
106     created: function() {
107         this.getTestcase();
108     },
109     methods: {
110       setEditable: function(){
111           this.isEditable = true;
112           this.bakContent = this.content;
113       },
114       cancelEdit: function(){
115           this.content = this.bakContent;
116           this.isEditable = false;
117       },
118       saveTestcase: function(){
119           console.log("save");
120           this.saveSignal = true;
121           this.contentSaving = true;
122       },
123       runTestcase: function(){
124         var self = this;
125         var msgTitle = "RUN -- TESTCASE";
126         if(!self.runYet) {
127           self.runYet = true;
128         }
129         $.ajax({
130             url: this.global.SERVER_ADDR + "execute/testcase",
131             method: "POST",
132             data: {
133                 "suiteName": this.$route.query.suiteName,
134                 "caseName": this.$route.query.caseName
135             },
136             beforeSend: function(XHR) {
137                 self.wfloading = true;
138                 showMessage("info", msgTitle, "start to run <strong>" + self.$route.query.caseName + "</strong>");
139             },
140             success: function(data) {
141                 if(data['code'] == 200) {
142                     self.workflowId = data['result']['workflowId'];
143                     showMessage(data['code'], msgTitle, "<strong>" + self.$route.query.caseName + "</strong> finished!");
144                     $.ajax({
145                         url: self.global.SERVER_ADDR + "story-content",
146                         method: "GET",
147                         data: {
148                             "service":  self.$route.query.suiteName,
149                             "story": self.$route.query.caseName
150                         },
151                         success: function(data) {
152                             if(data['code'] == 200) {
153                                 self.wfJson = data['result']['content'];
154                             } else {
155                               showMessage(data['code'], msgTitle, "workflow.json get failed!");
156                             }
157                         },
158                         error: function(obj, status, msg) {
159                           showMessage(status, msgTitle, msg);
160                         }
161                     });
162                 } else {
163                   self.wfloading = false;
164                   showMessage(data['code'], msgTitle, "Failed to run <strong>" + self.$route.query.caseName + "</strong>", data['error']);
165                 }
166             },
167             error: function(obj, status, msg) {
168                 self.wfloading = false;
169                 showMessage(status, msgTitle, "Failed to run <strong>" + self.$route.query.caseName + "</strong>", msg);
170             }
171         });
172       },
173       getTestcase: function(){
174           var self = this;
175           var msgTitle = "GET -- TESTCASE";
176           $.ajax({
177             url: this.global.SERVER_ADDR + "testcase/content",
178             method:"GET",
179             data:{
180               suiteName:  this.$route.query.suiteName,
181               caseName: this.$route.query.caseName
182             },
183             beforeSend: function(XHR) {
184                 self.contentLoading = true;
185             },
186             success:function (data) {
187               if(data['code'] == 200) {
188                 self.content = data['result']['content'];
189                 self.contentLoading = false;
190                 self.editorContent = data['result']['editorContent'];
191               }
192               else {
193                 showMessage("error", msgTitle, "fail to load testcase content!", data['error']);
194                 self.contentLoading = false;
195               }
196             },
197             error: function (obj, status, msg) {
198               showMessage(status, msgTitle, "fail to load testcase content!", msg);
199               self.contentLoading = false;
200             }
201           });
202       },
203       async processSaveResponse(result) {
204           if(result == true) {
205             this.saveSignal = false;
206             this.isEditable = false;
207             this.contentSaving = false;
208             this.getTestcase();
209           } else {
210             this.saveSignal = false;
211             this.contentSaving = false;
212           }
213       }
214     },
215     components: {
216       editor,
217       wfresult
218     }
219 }
220 </script>