reorganize recordScript code

This commit is contained in:
luqiong 2014-09-03 16:52:26 +08:00
parent 230a2e23ca
commit 06a1d745f2
10 changed files with 201 additions and 126 deletions

View File

@ -39,7 +39,7 @@ agentManage_jsp_addAgent=Add Agent
portManage_jsp_addPort=Add Port
configuredmessage=Here settings can be configured
startserver=Start Server
stopserver=Stop Server
stoprecording=Stop Recording
savefile=Save File
editscript=Edit Script
savechanges=Save

View File

@ -39,7 +39,7 @@ agentManage_jsp_addAgent=\u6DFB\u52A0\u4EE3\u7406
portManage_jsp_addPort=\u6DFB\u52A0\u7AEF\u53E3
configuredmessage=\u5728\u8FD9\u91CC\u53EF\u4EE5\u914D\u7F6E
startserver=\u542F\u52A8\u670D\u52A1\u5668
stopserver=\u505C\u6B62\u670D\u52A1\u5668
stoprecording=\u505C\u6B62\u5f55\u5236
savefile=\u4FDD\u5B58\u6587\u4EF6
editscript=\u7F16\u8F91\u811A\u672C
savechanges=\u4FDD\u5B58

View File

@ -47,4 +47,4 @@ saveScriptFail=Fail to save script.
plugin_jsp_addPage=Add Page
stopTestPlan_fail=Stop running test plan fail
RecordingScript=Recording Script
stopRecord=click stop server to stop recording script
stoprecord=click stop script recording to stop recording script

View File

@ -37,10 +37,10 @@ recordScript=\u5F55\u5236\u811A\u672C
startServerFail=\u542F\u52A8\u670D\u52A1\u5668\u5931\u8D25:
setProxy=\u8BF7\u8BBE\u7F6E\u4EE3\u7406:
recordScript=\u5F55\u5236\u811A\u672C
stopRecord=\u505C\u6B62\u811A\u672C\u5F55\u5236\uFF0C\u8BF7\u8F93\u5165\u811A\u672C\u540D\u79F0\uFF0C\u4FDD\u5B58\u811A\u672C
stopRecord=\u505C\u6B62\u811A\u672C\u5F55\u5236\uFF0C\u8BF7\u5148\u66f4\u6539\u6d4f\u89c8\u5668\u4ee3\u7406\u8bbe\u7f6e\uff0c\u518d\u8F93\u5165\u811A\u672C\u540D\u79F0\uFF0C\u4FDD\u5B58\u811A\u672C
saveScriptSuccess=\u4FDD\u5B58\u6210\u529F\u3002
saveScriptFail=\u4FDD\u5B58\u811A\u672C\u5931\u8D25
plugin_jsp_addPage=\u52A0\u9875
stopTestPlan_fail=\u505C\u6B62\u8FD0\u884C\u6D4B\u8BD5\u8BA1\u5212\u5931\u8D25
RecordingScript=\u6b63\u5728\u5f55\u5236\u811a\u672c
stopRecord=\u70b9\u51fb\u505c\u6b62\u670d\u52a1\u5668\u505c\u6b62\u5f55\u5236\u811a\u672c
stoprecord=\u70b9\u51fb\u505c\u6b62\u5f55\u5236\u505c\u6b62\u5f55\u5236\u811a\u672c

Binary file not shown.

After

Width:  |  Height:  |  Size: 655 B

View File

@ -27,6 +27,15 @@ body {
.sidebar-nav {
padding: 9px 0;
}
.show{
display:block;
color:red;
}
.none-div{
display:none;
}
</style>
@ -109,7 +118,7 @@ body {
<tr>
<td>
<button id="createNewScript"
class="btn btn-primary btn-setting" onclick="" type="submit">
class="btn btn-primary" onclick="startServer()" type="submit">
<fmt:message key="script_jsp_recordScript" />
</button> <a href="createScript.jsp"><button id="createScript"
class="btn btn-primary" onclick="#" type="submit">
@ -160,33 +169,31 @@ body {
<div class="modal hide fade" id="mySecondModal">
<div class="modal-header">
<button type="button" id="myModal-close" class="close"
data-dismiss="modal">×</button>
onclick="dismiss(mySecondModal)">×</button>
<h3>
<fmt:message key="settings" />
</h3>
</div>
<div class="modal-body">
<p id="scriptInfo2"></p>
<input class="input" id="target-url2" name="target-url" type="url" value="http://">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary"
onClick="testRecordProxy()" id="testRecordProxy">
<fmt:message key="testProxySettings" />
</button>
<button type="button" id="cancel" class="btn btn-primary">
<button type="button" id="cancel" class="btn btn-primary" onclick="dismiss(mySecondModal)">
<fmt:message key="plugin_jsp_cancel" />
</button>
<span id="ProxySettingMessage" class="hide"><img src="/images/cross.png" alt="Invalid">Invalid browser settings!</span>
</div>
</div>
<div class="modal hide fade" id="myThirdModal">
<div class="modal-header">
<button type="button" id="myModal-close" class="close"
data-dismiss="modal">×</button>
<h3>
<fmt:message key="settings" />
</h3>
<button type="button" id="myModal-close" class="close" onclick="dismiss(myThirdModal)">×</button>
<h3><fmt:message key="settings" /></h3>
</div>
<div class="modal-body">
<p id="scriptInfo3"></p>
@ -201,7 +208,7 @@ body {
<fmt:message key="stopserver" />
</button>
</div>
<div id="fileName" style="display: none" class="modal-footer">
<div id="fileName" class="modal-footer none-div">
<input class="input-mini" name="scriptname"></input>
<button type="button" class="btn btn-primary"
onClick="saveScript()">
@ -228,8 +235,9 @@ body {
<script src="lib/dataTable/js/jquery.dataTables.js"></script>
<script src="lib/chrisma/js/theme.js"></script>
<script src="script/base.js"></script>
<script src="script/scriptListManage.js"></script>
<script src="script/script.js"></script>
<script src="script/RecordScript/ScriptListManage.js"></script>
<script src="script/RecordScript/RecordScriptUI.js"></script>
<script src="script/RecordScript/RecordScriptServer.js"></script>
<script src="lib/other/jquery.noty.packaged.min.js"></script>
<script src="script/scriptManager/uiFactory.js"></script>
</fmt:bundle>

View File

@ -1,61 +1,76 @@
var server = null;
var table = $("#scriptTab").DataTable();
$('.btn-setting').click(function(e) {
e.preventDefault();
$('#myModal').modal('show');
});
$("#mySecondModal #cancel").click(function() {
$('#mySecondModal').modal('hide');
});
function startServer() {
$.post("startRecordServer", {}, function(data) {
if (data.success) {
server = data.server;
$('#myModal').modal('hide');
$('#mySecondModal').modal('show');
$("#ProxySettingMessage").attr("class","hide");
$("#target-url2").val($("#target-url").val());
$('#scriptInfo2').text(
$.i18n.prop("setProxy")+
" IP:133.133.2.100"
+ " ,port: " + server.port
+ $.i18n.prop("recordScript"));
//$('#startServer').attr('disabled', true);
//$('#stopServer').attr('disabled', false);
} else {
$('#scriptInfo').html(
$.i18n.prop("startServerFail") + data.failedMessage);
}
}, "json");
}
$('#uploadScript')
.click(
function() {
var myModalContent = $('#myModal').html();
$(".modal-footer").html("");
var uploadForm = '<form method="post" enctype="multipart/form-data" action="uploadScriptFile">'
+ '<p>script name:<input class="input-mini" type="text" name="scriptName" ></p>'
+ '<p>script to upload: <input type="file" name="scriptFile"/></p>'
+ '<p><input type="submit"/></p></form>';
var status = "<div id='status'><h3></h3><div>";
$('#scriptInfo').html("");
$('#scriptInfo').html(uploadForm + status);
$('form').ajaxForm({
success : function(data) {
if (data.success) {
$("#status").text(data.message);
loadScript(table, 2);
function startRecording() {
if (server != null) {
$.post("startRecording", {
port : server.port,
scriptRecordUUID : server.fileName
}, function(data) {
if (!data.success) {
$('#scriptInfo3').text(
"start recording error:" + data.failedMessage);
$('#stopServer').attr('disabled', false);
$('#startRecording').attr('disabled', true);
}
else {
$('#scriptInfo3').text($.i18n.prop("stopRecord"));
var url = $('#target-url2').val();
window.open(url);
$('#stopServer').attr('disabled', false);
$('#startRecording').attr('disabled', true);
}
}, "json");
} else {
$('#scriptInfo3').text("record script server has not started");
}
}
else
$("#status").text(data.failedMessage);
function stopRecording() {
if (server != null) {
$.post("stopScriptRecording", {
port : server.port,
scriptRecordUUID : server.fileName
}, function(data) {
if (!data.success) {
$('#scriptInfo3').text(
"stop record server error:" + data.failedMessage);
$('#stopServer').attr('disabled', true);
$('#startServer').attr('disabled', false);
}
});
$('#myModal-close').click(function() {
$('#myModal').html(myModalContent);
$('#myModal').modal('hide');
});
});
else {
$('#stopServer').attr('disabled', true);
$('#scriptInfo3').text(
$.i18n.prop("stoprecord")
);
}
}, "json");
} else {
$('#scriptInfo3').text("record script server has not started");
}
stopServer();
}
function stopServer() {
if (server != null) {
$.post("stopRecordServer", {
@ -68,19 +83,26 @@ function stopServer() {
$('#stopServer').attr('disabled', true);
$('#startServer').attr('disabled', false);
}
else {
$('#stopServer').attr('disabled', false);
$('#fileName').show();
$('#scriptInfo3').text(
$.i18n.prop("stopRecord")
);
}
}, "json");
} else {
$('#scriptInfo3').text("record script server has not started");
}
}
function testRecordProxy() {
$.post("testRecordProxy", {}, function(data) {
if (data.success) {
$('#mySecondModal').modal('hide');
$('#myThirdModal').modal('show');
$('#scriptInfo3').text(
$.i18n.prop("RecordingScript"));
} else {
$("#ProxySettingMessage").attr("class","show");
}
}, "json");
}
function saveScript() {
@ -101,71 +123,3 @@ function saveScript() {
loadScript(table, 2);
});
}
$(document).ready(function() {
addEvent(table);
loadScript(table);
$('#stopServer').attr('disabled', true);
});
function refresh() {
location.replace(location);
}
//add by hemeimei
function getScriptPlugins(scriptId) {
$.post("getScriptPlugins", {
scriptId : scriptId
}, function(data) {
if (!data.success) {
information("failed to get script:" + data.failedMessage);
return;
} else {
data.scriptPlugins;
}
}, "json")
}
function testRecordProxy() {
$.post("testRecordProxy", {}, function(data) {
if (data.success) {
$('#mySecondModal').modal('hide');
$('#myThirdModal').modal('show');
//server = data.server;
$('#scriptInfo3').text(
$.i18n.prop("RecordingScript"));
//$('#startServer').attr('disabled', true);
//$('#stopServer').attr('disabled', true);
} else {
$('#scriptInfo2').html(
$.i18n.prop("ProxySettingError") + data.failedMessage);
}
}, "json");
}
function startRecording() {
if (server != null) {
$.post("startRecording", {
port : server.port,
scriptRecordUUID : server.fileName
}, function(data) {
if (!data.success) {
$('#scriptInfo3').text(
"start recording error:" + data.failedMessage);
$('#stopServer').attr('disabled', false);
$('#startRecording').attr('disabled', true);
}
else {
$('#scriptInfo3').text($.i18n.prop("stopRecord"));
var url = $('#target-url').val();
window.open(url);
$('#stopServer').attr('disabled', false);
$('#startRecording').attr('disabled', true);
}
}, "json");
} else {
$('#scriptInfo3').text("record script server has not started");
}
}

View File

@ -0,0 +1,49 @@
$('.btn-setting').click(function(e) {
e.preventDefault();
$('#myModal').modal('show');
});
function dismiss(container){
$(container).modal('hide');
stopServer();
}
$('#uploadScript')
.click(
function() {
var myModalContent = $('#myModal').html();
$(".modal-footer").html("");
var uploadForm = '<form method="post" enctype="multipart/form-data" action="uploadScriptFile">'
+ '<p>script name:<input class="input-mini" type="text" name="scriptName" ></p>'
+ '<p>script to upload: <input type="file" name="scriptFile"/></p>'
+ '<p><input type="submit"/></p></form>';
var status = "<div id='status'><h3></h3><div>";
$('#scriptInfo').html("");
$('#scriptInfo').html(uploadForm + status);
$('form').ajaxForm({
success : function(data) {
if (data.success) {
$("#status").text(data.message);
loadScript(table, 2);
}
else
$("#status").text(data.failedMessage);
}
});
$('#myModal-close').click(function() {
$('#myModal').html(myModalContent);
$('#myModal').modal('hide');
});
});
$(document).ready(function() {
addEvent(table);
loadScript(table);
$('#stopServer').attr('disabled', true);
});
function refresh() {
location.replace(location);
}

View File

@ -0,0 +1,64 @@
function loadScript(table) {
var editButton = "<a class='btn btn-success edit' ><i class='icon-edit icon-white'></i>"
+ $.i18n.prop('script-edit') + "</a>";
var deleteButton = "<a class='btn btn-info delete'><i class='icon-trash icon-white'></i>"
+ $.i18n.prop('delete') + "</a>";
table.clear();
$.post("loadScripts", {}, function(data) {
if (data.success) {
var scripts = data.scripts;
if (scripts == null) {
return;
}
for ( var i = 0; i < scripts.length; i++) {
var tr = table.row.add(
[ i + 1, scripts[i].name,
new Date(scripts[i].createDateTime),
editButton + deleteButton ]).draw().node();
$(tr).attr("id", scripts[i].id);
}
} else {
information(data.failedMessage);
}
}, "json");
}
function addEvent(table) {
var tbody = table.table().body();
$(tbody).on("click", "td a.delete", function(e) {
e.preventDefault();
var row = $(this).closest("tr");
var scriptId = $(row).attr("id");
deleteScript(scriptId, table.row(row));
});
$(tbody).on("click", "td a.edit", function(e) {
e.preventDefault();
var row = $(this).closest("tr");
var scriptId = $(row).attr("id");
var scriptId = $(row).attr("id");
var scriptName = table.row(row).data()[1];
editScript(scriptId, scriptName);
});
}
function deleteScript(scriptId, row) {
$.post("deleteScript", {
scriptId : scriptId
}, function(data) {
if (data.success) {
information($.i18n.prop("script-deleteSuc"));
row.remove().draw();
} else {
information(data.failedMessage);
// error message
}
}, "json");
}
function editScript(scriptId, scriptName) {
window.open("editScript.jsp?name=" + scriptName + "&scriptId=" + scriptId);// need
}