Change naming and veriy test-scheduler function
[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-8">
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">
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           saveSignal: false
102       }
103     },
104     created: function() {
105         this.getTestcase();
106     },
107     methods: {
108       setEditable: function(){
109           this.isEditable = true;
110           this.bakContent = this.content;
111       },
112       cancelEdit: function(){
113           this.content = this.bakContent;
114           this.isEditable = false;
115       },
116       saveTestcase: function(){
117           console.log("save");
118           this.saveSignal = true;
119           this.contentSaving = true;
120       },
121       runTestcase: function(){
122         var self = this;
123         var msgTitle = "RUN -- TESTCASE";
124         $.ajax({
125             url: this.global.SERVER_ADDR + "execute/testcase",
126             method: "POST",
127             data: {
128                 "suiteName": this.$route.query.suiteName,
129                 "caseName": this.$route.query.caseName
130             },
131             beforeSend: function(XHR) {
132                 self.wfloading = true;
133                 showMessage("info", msgTitle, "start to run <strong>" + self.$route.query.caseName + "</strong>");
134             },
135             success: function(data) {
136                 if(data['code'] == 200) {
137                     self.workflowId = data['result']['workflowId'];
138                     showMessage(data['code'], msgTitle, "<strong>" + self.$route.query.caseName + "</strong> finished!");
139                     $.ajax({
140                         url: self.global.SERVER_ADDR + "story-content",
141                         method: "GET",
142                         data: {
143                             "service":  self.$route.query.suiteName,
144                             "story": self.$route.query.caseName
145                         },
146                         success: function(data) {
147                             if(data['code'] == 200) {
148                                 self.wfJson = data['result']['content'];
149                             } else {
150                               showMessage(data['code'], msgTitle, "workflow.json get failed!");
151                             }
152                         },
153                         error: function(obj, status, msg) {
154                           showMessage(status, msgTitle, msg);
155                         }
156                     });
157                 } else {
158                   self.wfloading = false;
159                   showMessage(data['code'], msgTitle, "Failed to run <strong>" + self.$route.query.caseName + "</strong>", data['error']);
160                 }
161             },
162             error: function(obj, status, msg) {
163                 self.wfloading = false;
164                 showMessage(status, msgTitle, "Failed to run <strong>" + self.$route.query.caseName + "</strong>", msg);
165             }
166         });
167       },
168       getTestcase: function(){
169           var self = this;
170           var msgTitle = "GET -- TESTCASE";
171           $.ajax({
172             url: this.global.SERVER_ADDR + "testcase/content",
173             method:"GET",
174             data:{
175               suiteName:  this.$route.query.suiteName,
176               caseName: this.$route.query.caseName
177             },
178             beforeSend: function(XHR) {
179                 self.contentLoading = true;
180             },
181             success:function (data) {
182               if(data['code'] == 200) {
183                 self.content = data['result']['content'];
184                 self.contentLoading = false;
185                 self.editorContent = data['result']['editorContent'];
186               }
187               else {
188                 showMessage("error", msgTitle, "fail to load testcase content!", data['error']);
189                 self.contentLoading = false;
190               }
191             },
192             error: function (obj, status, msg) {
193               showMessage(status, msgTitle, "fail to load testcase content!", msg);
194               self.contentLoading = false;
195             }
196           });
197       },
198       async processSaveResponse(result) {
199           if(result == true) {
200             this.saveSignal = false;
201             this.isEditable = false;
202             this.contentSaving = false;
203             this.getTestcase();
204           } else {
205             this.saveSignal = false;
206             this.contentSaving = false;
207           }
208       }
209     },
210     components: {
211       editor,
212       wfresult
213     }
214 }
215 </script>