-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathEditTestPlan.cshtml
482 lines (431 loc) · 17.6 KB
/
EditTestPlan.cshtml
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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
@inherits ViewPage<EditTestPlanResponse>
@{
RedirectIfNotAuthenticated();
var hrefVewPlan = new ViewTestPlan { Slug = Model.Slug, Id = Model.TestRunId }.ToGetUrl();
var hrefSearchResults = new SearchTestResults { TestPlanId = Model.Id, TestRunId = Model.TestRunId }.ToGetUrl();
var hrefUploadFiles = new UploadTestResults { TestPlanId = Model.Id, TestRunId = Model.TestRunId }.ToPostUrl();
}
<link href="/Scripts/fineuploader-3.2.css" rel="stylesheet" />
<script src="/Scripts/jquery.fineuploader-3.2.min.js"></script>
<style>
#Contents {
width: 450px;
height: 100px;
}
.intro {
width: 980px;
margin: 60px 0 0 0;
}
#testruns .list-group-item {
padding: 12px 15px;
}
#testruns td {
vertical-align: top;
padding: 0 10px 0 0;
}
#testruns td:first-child {
width: 500px;
}
</style>
<div class="modal fade" id="modalCreateTestRun">
<div class="modal-dialog">
<form id="formCreateTestRun" action="/testplans/@Model.Id/testruns">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Create New Test Run</h4>
</div>
<div class="modal-body">
<p class="error-summary alert alert-danger"></p>
<div class="form-group">
<label>Series Id:</label>
<input class="form-control" type="text" name="SeriesId" value="Created on @(DateTime.UtcNow.ToString("yyyy-MM-dd"))" placeholder="optional"/>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Create</button>
</div>
</div>
</form>
</div>
</div>
<div class="modal fade" id="modalDeleteTestPlan">
<div class="modal-dialog">
<form id="formDeleteTestPlan" action="/testplans/@Model.Id/delete">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Are you really sure you want to delete this Test Plan?
</h4>
</div>
<div class="modal-body">
<p>
This action <b>CANNOT</b> be undone and will delete this entire
<b>@Model.Name</b> and all its results.
</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-danger">Delete Test Plan</button>
</div>
</div>
</form>
</div>
</div>
<div class="modal fade" id="modalDeleteTestRun">
<div class="modal-dialog modal-sm">
<form id="formDeleteTestRun" action="/testruns/@Model.TestRunId/delete">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Confirm Delete</h4>
</div>
<div class="modal-body">
Did you really want to delete this Run?
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-danger">Delete Test Run</button>
</div>
</div>
</form>
</div>
</div>
<div style="width: 980px">
<button id="btnDeletePlan" data-click="deleteTestPlan:@Model.Id" class="btn btn-danger" style="float: right">Delete Test Plan</button>
</div>
<h2>@Model.Name</h2>
<p>
Add new test results to analyze the results of your Apache benchmarks below:
</p>
<div id="testruns" style="display: none;">
<table>
<tr>
<td>
<div class="list-group">
</div>
</td>
<td>
<div class="btn-group">
<button type="button" class="btn btn-lg btn-default dropdown-toggle" data-toggle="dropdown">
<span class="glyphicon glyphicon-share-alt"></span>
Go to another test run
<span class="caret"></span>
</button>
<ul id="existing-testruns" class="dropdown-menu" role="menu">
</ul>
</div>
</td>
</tr>
</table>
</div>
<div style="width: 490px;">
<button id="btnDeleteRun" data-click="deleteTestRun" class="btn btn-sm btn-danger" style="float: right">Delete Test Run</button>
<h4 id="lnkViewResults" style="margin: 0 0 20px 0"></h4>
</div>
<div class="clearfix"></div>
<h4 style="margin: 40px 0 10px 0">Add more results to this test run</h4>
<div style="float: left; padding: 0 20px 0 0">
<p>
Upload multiple apache benchmark output files directly or as batches in .zip's
</p>
<div style="position: absolute; z-index: 1; margin: 10px 0 0 220px; user-select: none">
<input id="chkCreateTestRuns" type="checkbox"/>
<label for="chkCreateTestRuns" style="font-weight: normal">
Create new test run for each .zip
</label>
</div>
<div id="uploadtestresults">
<span class="help-block"></span>
<noscript>
<input type="file" id="upload" name="upload" />
</noscript>
</div>
</div>
<form id="formAddTestResult" action="@(new AddTestResults { TestPlanId = Model.Id }.ToPostUrl())" method="POST"
style="float: left; border-left: 1px solid #ccc; padding: 0 0 0 20px">
<div>
<div class="form-group">
<p>
Manually add Apache Benchmark outputs:
</p>
<textarea class="form-control" id="Contents" name="Contents" placeholder="paste apache benchmark output"></textarea>
<span class="help-block"></span>
<button class="btn btn-sm btn-default" type="submit">add test result</button>
</div>
</div>
<div class="clearfix"></div>
</form>
<div class="clearfix"></div>
<div id="testresults" style="display: none;">
<hr />
<h3>Test Results</h3>
<table class="table table-striped" style="width: 100%;">
<thead>
<th>Id</th>
<th>Software</th>
<th>Host</th>
<th>Request Path</th>
<th>Request Length</th>
<th>Concurrency</th>
<th>Time Taken</th>
<th>Total Requests</th>
<th>Failed Requests</th>
<th>Total Transferred</th>
<th>Html Transferred</th>
<th>Requests /s</th>
<th>Time per Request</th>
<th>Transfer Rate</th>
</thead>
<tbody></tbody>
</table>
</div>
<div class="clearfix"></div>
<div id="labels" style="width: 980px; display: none; margin: 60px 0">
<hr/>
<h4>Markup Graphs with Custom Labels</h4>
<form id="formUpdateLabels" action="@(new UpdateTestPlanLabels { Id = Model.Id }.ToPostUrl())" method="POST">
<div style="float: right;">
<div class="input-group" style="width: 200px;">
<span class="input-group-addon" style="padding: 2px 0 0 0">
<input id="chkEditLabels" type="checkbox" data-click="editLabels">
<label for="chkEditLabels" style="padding: 0 0 0 5px;">edit labels</label>
</span>
<span class="input-group-btn">
<button id="btnSaveLabels" class="btn btn-success disabled" type="submit" data-click="saveLabels">save</button>
</span>
</div>
</div>
<p>
Make your charts more readable by assigning user-defined labels to your results
</p>
<table class="table table-striped" style="margin:0">
<thead>
<tr>
<th>Server Labels</th>
<th>Test Labels</th>
</tr>
</thead>
<tbody>
<tr>
<td class="server-labels" style="width:50%">
<div class="preview-labels"></div>
<textarea name="ServerLabels" style="width: 100%; height: 200px;"></textarea>
</td>
<td class="test-labels" style="width:50%">
<div class="preview-labels"></div>
<textarea name="TestLabels" style="width: 100%; height: 200px;"></textarea>
</td>
</tr>
</tbody>
</table>
</form>
</div>
<script>
var Model = {
TestPlan: @Model.AsRawJson(),
ActiveTestRun: null,
OtherTestRuns: [],
ResultsUploaded: [],
addNewUploads: function(r) {
this.ResultsUploaded = this.ResultsUploaded.concat(r || []);
refreshTestRuns();
},
clearUploads: function() {
this.ResultsUploaded = [];
},
setTestRuns: function(runs) {
var isActive = function(r) { return r.Id == this.TestPlan.TestRunId; }.bind(this);
this.ActiveTestRun = runs.filter(isActive)[0];
this.OtherTestRuns = runs.filter(function (r) { return !isActive(r); });
},
setLabels: function(r) {
this.TestPlan.ServerLabels = r.ServerLabels || {};
this.TestPlan.TestLabels = r.TestLabels || {};
},
apply: function(){}
};
function Views(model) {
this.model = model;
var render = function() {
for (var name in this) {
if (typeof this[name] != 'function') continue;
this[name](model);
}
}.bind(this);
for (var k in model) {
if (typeof model[k] != 'function') continue;
model[k] = (function(fn) {
return function() {
fn.apply(model, arguments);
render();
};
})(model[k]);
}
}
Views.prototype = {
activeTestRun: function() {
var r = this.model.ActiveTestRun;
if (!r) return;
$("#testruns").show().find(".list-group").html(
"<a " + (r.TestResultsCount > 0 ? ' href="@hrefVewPlan"' : '')
+ " class='list-group-item' data-click='showRun:" + r.Id + "'>"
+ '<span class="badge">' + r.TestResultsCount + '</span>'
+ r.SeriesId
+ "</a>");
$("#lnkViewResults").html(r.TestResultsCount == 0
? '<span class="disabled">view results</span> <span style="color:#ccc">|</span> <span class="disabled">search results</span>'
: '<a href="@hrefVewPlan">view results</a> ' +
'<span style="color:#ccc">|</span> ' +
'<a href="@hrefSearchResults">search results</a>');
},
otherTestRuns: function() {
var runs = this.model.OtherTestRuns;
var html = runs.map(function(r) {
return '<li><a href="/testplans/@Model.Id/testruns/' + r.Id + '/edit">'
+ r.SeriesId
+ '</a></li>';
});
if (runs.length > 0)
html.push('<li class="divider"></li>');
html.push('<li><a href="#" data-click="createTestRun">'
+ '<span class="glyphicon glyphicon-plus"></span> '
+ ' Create new test run</a></li>');
$("#existing-testruns").html(html.join(''));
},
hasOtherRuns: function() {
var hasRuns = this.model.OtherTestRuns.length > 0;
$("#btnDeleteRun").toggle(hasRuns);
},
newTestResults: function() {
var results = this.model.ResultsUploaded;
if (results.length > 0) {
$("#testresults").show().find("TABLE tbody").html(
results.map(function(r) {
return "<tr>" +
"<td>" + r.Id + "</td>" +
"<td>" + r.Software + "</td>" +
"<td>" + r.Hostname + ":" + r.Port + "</td>" +
"<td>" + r.RequestPath + "</td>" +
"<td>" + r.RequestLength + "</td>" +
"<td>" + r.Concurrency + "</td>" +
"<td>" + r.TimeTaken + "</td>" +
"<td>" + r.TotalRequests + "</td>" +
"<td>" + r.FailedRequests + "</td>" +
"<td>" + r.TotalTransferred + "</td>" +
"<td>" + r.HtmlTransferred + "</td>" +
"<td>" + r.RequestsPerSec + "</td>" +
"<td>" + r.TimePerRequest + "</td>" +
"<td>" + r.TransferRate + "</td>" +
"</tr>";
}));
var total = $("#testresults tbody tr").length;
$("#testresults h3").html(total == 1
? "1 test result was added"
: total + " test results were added");
} else {
$(".qq-upload-list li")
.remove();
$("#testresults")
.hide()
.find("TABLE tbody")
.html("");
}
},
testPlanLabels: function() {
var serverLabels = this.model.TestPlan.ServerLabels || {},
testLabels = this.model.TestPlan.TestLabels || {},
htmlTable = function(map) {
var html = Object.keys(map).map(function(k) {
return "<tr><th>" + k + "</th><td>" + map[k] + "</td></tr>";
}).join('');
return "<table class='table table-bordered' style='margin:0'>" + html + "</table>";
},
textareaText = function(map) {
return Object.keys(map).map(function(key) {
return key + " " + map[key] + "\n";
}).join('');
},
editMode = $("#chkEditLabels")[0].checked;
$("#labels").toggle(Object.keys(serverLabels).length > 0);
$("#labels textarea").toggle(editMode);
$("#labels .preview-labels").toggle(!editMode);
$("#btnSaveLabels").toggleClass("disabled", !editMode);
$(".server-labels textarea").val(textareaText(serverLabels));
$(".server-labels .preview-labels").html(htmlTable(serverLabels));
$(".test-labels textarea").val(textareaText(testLabels));
$(".test-labels .preview-labels").html(htmlTable(testLabels));
}
};
Model.Views = new Views(Model);
//bind global event handlers
$(document).bindHandlers({
createTestRun: function() {
$("#modalCreateTestRun")
.on('shown.bs.modal', function() {
$(this).find("INPUT").first().focus();
})
.modal('show');
$("#modalCreateTestRun INPUT").first().focus(function() {
var $this = $(this); //fix for Chrome
$this.select().mouseup(function() { $this.unbind("mouseup"); return false; });
});
},
deleteTestPlan: function(planId) {
$("#modalDeleteTestPlan").modal('show');
},
deleteTestRun: function(runId) {
$("#modalDeleteTestRun").modal('show');
},
editLabels: Model.apply,
saveLabels: function() {}
});
//bind forms
$("#formCreateTestRun").bindForm();
$("#formDeleteTestPlan").bindForm();
$("#formDeleteTestRun").bindForm();
$("#formUpdateLabels").bindForm({
success: function(r) {
$("#chkEditLabels")[0].checked = false;
Model.setLabels(r);
}
});
$("#formAddTestResult").bindForm({
validate: function() {
Model.clearUploads();
},
success: function (r) {
Model.addNewUploads(r.Results);
}
});
var uploader = new qq.FineUploader({
element: document.getElementById("uploadtestresults"),
allowedExtensions: ['zip', 'txt'],
minSizeLimit: 1,
text: {
uploadButton: 'upload test results'
},
request: {
endpoint: "@hrefUploadFiles",
customHeaders : {
accept: 'application/json'
}
},
callbacks: {
onValidateBatch: function() {
Model.clearUploads();
this.setParams({ CreateNewTestRuns: $("#chkCreateTestRuns")[0].checked });
},
onComplete: function (id, fileName, response) {
Model.addNewUploads(response.Results);
}
}
});
function refreshTestRuns() {
$.getJSON("/testplans/@Model.Id/testruns", Model.setTestRuns);
$.getJSON("/testplans/@Model.Id/testruns/@Model.TestRunId/edit", Model.setLabels);
}
//main
refreshTestRuns();
</script>