refactor pluginActionController.java , rewrite functions in

plugin-new.js  , write function to upload pluginFile
This commit is contained in:
ZhengYingYing 2014-04-17 18:28:48 +08:00
parent 5a9d0d2f4b
commit c2d2ba1488
8 changed files with 183 additions and 146 deletions

View File

@ -27,7 +27,7 @@ import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.multipart.commons.CommonsMultipartFile;
@Controller
@SessionAttributes({ "accessToken"})
@SessionAttributes({ "accessToken" })
public class PluginActionController {
private final String baseUrl = "plugin";
@ -54,7 +54,7 @@ public class PluginActionController {
@RequestMapping("loadPluginName")
public @ResponseBody
BaseResponseModel loadPlugin(HttpServletRequest request,
BaseResponseModel loadPluginName(HttpServletRequest request,
@ModelAttribute("accessToken") String accessToken)
throws CustomGenericException {
System.out.println("loadPluginList!!");
@ -91,7 +91,7 @@ public class PluginActionController {
@ModelAttribute("accessToken") String accessToken)
throws CustomGenericException {
String caller = new String("PluginActionController:loadPluginUIInfo");
String url = this.getBaseUrl() + "/loadPluginUI";
String url = this.getBaseUrl() + "/loadPluginList";
PluginResponseModel pluginResponseModel = (PluginResponseModel) this
.getCommunicateWithMaster().getResponseModel(accessToken, url,
PluginResponseModel.class, null, caller);
@ -158,7 +158,7 @@ public class PluginActionController {
try {
String pluginUIModel = new String(pluginFile.getBytes());
MarshalHelper.unmarshal(PluginUIModel.class, pluginUIModel);
PluginResponseModel pluginResponseModel = (PluginResponseModel) this
.getCommunicateWithMaster().getResponseModelByPut(
@ -166,14 +166,13 @@ public class PluginActionController {
PluginResponseModel.class, caller);
if (pluginResponseModel.isSuccess()) {
return new BaseResponseModel(true,
"upload plugin file success!");
return new BaseResponseModel(true);
} else {
return new BaseResponseModel(false,
pluginResponseModel.getFailMessage());
}
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
return null;
}
@ -191,10 +190,11 @@ public class PluginActionController {
PluginResponseModel pluginResponseModel = (PluginResponseModel) this
.getCommunicateWithMaster().getResponseModel(accessToken, url,
PluginResponseModel.class, params, caller);
if(pluginResponseModel.isSuccess()){
return new BaseResponseModel(true,"delete success");
}else{
return new BaseResponseModel(false,pluginResponseModel.getFailMessage());
if (pluginResponseModel.isSuccess()) {
return new BaseResponseModel(true, "delete success");
} else {
return new BaseResponseModel(false,
pluginResponseModel.getFailMessage());
}
}
}

View File

@ -76,10 +76,10 @@
<div class="modal-body">
<form method="post" enctype="multipart/form-data"
action="uploadPluginFile">
<p>
<!-- <p>
file name:<input class="input-mini" type="text"
name="pluginFileName" id="fileName">
</p>
</p> -->
<p>
file to upload:<input type="file" name="pluginFile" />
</p>
@ -106,6 +106,7 @@
<script src="lib/chrisma/js/jquery.cookie.js"></script>
<script src="lib/chrisma/js/theme.js"></script>
<script src="lib/jqueryi18n/jquery.i18n.properties-1.0.9.js"></script>
<script src="http://malsup.github.com/jquery.form.js"></script>
<script src="script/base.js"></script>
<script src="script/bench4q.table.js"></script>
<script src="script/admin/agentManage.js"></script>

View File

@ -1,20 +1,37 @@
$(document).ready(function() {
loadPluginInfo();
});
var table = $('#addPluginTable');
var deleteButton = "<a class='btn btn-info' onClick='deleteScript(this)'><i class='icon-trash icon-white'></i>Delete</a>";
function loadPluginInfo() {
alert("loadPluginInfo");
$.post("loadPluginUIInfo", {}, function(data) {
if (!data.success) {
alert(data.failedMessage);
return;
}
data = data.data;// List<PluginUIModel>
table.dataTable().fnClearTable();
for (var i = 0; i < data.length; i++) {
table.dataTable().fnAddData(
[ data[i].pluginInfoModel.name, data[i].createTimeDate,
deleteButton ]);
}
});
}
function showModel() {
$('#myModal_plugin').modal('show');
$('form').ajaxForm({
success : function(data) {
$('#myModal_plugin').modal('hide');
if (data.success)
addPluginDataRow();
else
if (data.success) {
loadPluginInfo();
} else {
alert(data.failedMessage);
}
}
});
}
function addPluginDataRow() {
var fileName=$('#fileName').val();
table.dataTable().fnAddData([ fileName, Date(), deleteButton ]);
}

View File

@ -6,52 +6,43 @@ function loadProperties() {
});
}
// data 为List<ParamInfoModel>
function createBehaviorsForm(data, behaviorData, behaviorIndex) {
var methodParams = new Array();
var paramInfoList = new Array();
var fieldHTML = "";
for (var i = 0; i < data.length; i++) {
methodParams.push(data[i]);
paramInfoList.push(data[i]);
}
for (var j = 0; j < methodParams.length; j++) {
var methodParamModel = new MethodParamModel(methodParams[j].name,
methodParams[j].lable, methodParams[j].valueSeperator,
methodParams[j].fieldSeperator, methodParams[j].paramType,
methodParams[j].methodParamProperties);
var methodParamProperties = new Array();
for (var q = 0; q < methodParamModel.methodParamProperties.length; q++) {
var methodParamPropertyModel = new MethodParamPropertyModel(
methodParamModel.methodParamProperties[q].key,
methodParamModel.methodParamProperties[q].value);
methodParamProperties.push(methodParamPropertyModel);
}
var type = methodParamModel.paramType;
var size = 0, cols = "", rows = "";
for (var p = 0; p < methodParamProperties.length; p++) {
var methodParamProertyModel = methodParamProperties[p];
if (methodParamProertyModel.key == "size") {
size = methodParamProertyModel.value;
} else if (methodParamProertyModel.key == "cols") {
cols = methodParamProertyModel.value;
} else if (methodParamProertyModel.key == "rows") {
rows = methodParamProertyModel.value;
}
}
for (var j = 0; j < paramInfoList.length; j++) {
var paramTypeModel = paramInfoList[j].paramTypeModel;
var methodParamModel = new ParamInfoModel(paramInfoList[j].name,
paramInfoList[j].lable, paramTypeModel);
var type = paramTypeModel.type;
if (type == "Field") {
var size = paramTypeModel.size;
fieldHTML += createField(methodParamModel.lable,
methodParamModel.name, size, behaviorIndex);
} else if (type == "MultiField") {
} else if (type == "NField") {
var size = paramTypeModel.size;
fieldHTML += createMultiField(methodParamModel.lable,
methodParamModel.name, size, behaviorIndex);
} else if (type == "Table") {
fieldHTML += createTable(methodParamModel, cols, behaviorIndex);
var cols = paramTypeModel.cols;
fieldHTML += createTable(methodParamModel.lable,
methodParamModel.name, cols, behaviorIndex);
} else if (type == "CheckBox") {
fieldHTML += createCheckBox(methodParamModel, rows, behaviorIndex);
var rows = paramTypeModel.choiceModels;
fieldHTML += createCheckBox(methodParamModel.lable,
methodParamModel.name, rows, behaviorIndex);
} else if (type == "RadioButton") {
var rows = paramTypeModel.choiceModels;
fieldHTML += createRadioButton(methodParamModel.lable,
methodParamModel.name, rows, behaviorIndex);
}
}
return fieldHTML;
}
function createField(label, name, size, behaviorIndex) {
if (size == 0) {
size = 20;
@ -87,15 +78,13 @@ function createMultiField(label, name, size, behaviorIndex) {
var labelNode = document.createTextNode(name + ":" + label);
var div = document.createElement("div");
var addFieldButton = document.createElement("button");
var addFieldNode = document.createTextNode($.i18n
.prop("addField"));
var addFieldNode = document.createTextNode($.i18n.prop("addField"));
var removeFieldButton = document.createElement("button");
var removeFieldNode = document.createTextNode($.i18n
.prop("removeField"));
var removeFieldNode = document.createTextNode($.i18n.prop("removeField"));
var br = document.createElement("br");
var table = document.createElement("table");
$(divNode).attr("class", "MultiField sample_frame");
$(divNode).attr("class", "NField sample_frame");
$(divNode).attr("id", behaviorIndex + "_" + name);
$(div).attr("class", "sample_sub_frame");
$(addFieldButton).attr("type", "submit");
@ -147,11 +136,8 @@ function removeField(selectedNode) {
table.removeChild(deletedNode);
}
function createTable(methodParamModel, cols, behaviorIndex) {
var name = methodParamModel.name;
var label = methodParamModel.lable;
var valueSeperator = methodParamModel.valueSeperator;
var table_content = cols.split(valueSeperator);
function createTable(label, name, cols, behaviorIndex) {
var table_content = cols.split("|");// table分隔符
var tr = document.createElement("tr");
for (var i = 0; i < table_content.length; i++) {
var th = document.createElement("th");
@ -177,8 +163,7 @@ function createTable(methodParamModel, cols, behaviorIndex) {
var addColButton = document.createElement("button");
var addColNode = document.createTextNode($.i18n.prop("addCol"));
var removeColButton = document.createElement("button");
var removeColNode = document.createTextNode($.i18n
.prop("removeCol"));
var removeColNode = document.createTextNode($.i18n.prop("removeCol"));
var table = document.createElement("table");
var thead = document.createElement("thead");
var tbody = document.createElement("tbody");
@ -234,13 +219,12 @@ function removeCol(selectedNode) {
tbody.removeChild(removeNode);
}
function createCheckBox(methodParamModel, rows, behaviorIndex) {
var name = methodParamModel.name;
var label = methodParamModel.lable;
var valueSeperator = methodParamModel.valueSeperator;
var cb_content = rows.split(valueSeperator);
function createCheckBox(label,name, rows, behaviorIndex) {
var valueList = new Array();
for (var i = 0; i < rows.length; i++) {
valueList.push(rows[i].value);
}
var result = document.createElement("div");
var divNode = document.createElement("div");
var p = document.createElement("p");
var div = document.createElement("div");
@ -253,14 +237,13 @@ function createCheckBox(methodParamModel, rows, behaviorIndex) {
$(div).attr("class", "sample_sub_frame");
$(divInput).attr("class", "sample_sub_frame");
p.appendChild(labelNode);
for (var i = 0; i < cb_content.length; i++) {
for (var i = 0; i < valueList.length; i++) {
var checkBoxNode = document.createElement("input");
var brInput = document.createElement("br");
checkBoxNode.setAttribute("type", "checkbox");
checkBoxNode.setAttribute("name", "checkbox_" + name + "_"
+ behaviorIndex);
checkBoxNode.setAttribute("value", cb_content[i]);
var checkBoxValue = document.createTextNode(cb_content[i]);
checkBoxNode.setAttribute("name", "checkbox");
checkBoxNode.setAttribute("value", valueList[i]);
var checkBoxValue = document.createTextNode(valueList[i]);
divInput.appendChild(checkBoxNode);
divInput.appendChild(checkBoxValue);
divInput.appendChild(brInput);
@ -270,7 +253,42 @@ function createCheckBox(methodParamModel, rows, behaviorIndex) {
div.appendChild(divInput);
divNode.appendChild(p);
divNode.appendChild(div);
result.appendChild(divNode);
return $(result).html();
return divNode.outerHTML;
}
function createRadioButton(label,name,rows,behaviorIndex){
var valueList = new Array();
for (var i = 0; i < rows.length; i++) {
valueList.push(rows[i].value);
}
var divNode = document.createElement("div");
var p = document.createElement("p");
var div = document.createElement("div");
var br = document.createElement("br");
var divInput = document.createElement("div");
var labelNode = document.createTextNode(label);
var nameNode = document.createTextNode(name);
$(divNode).attr("class", "RadioButton sample_frame");
$(divNode).attr("id", "radio_" + name + "_" + behaviorIndex);
$(div).attr("class", "sample_sub_frame");
$(divInput).attr("class", "sample_sub_frame");
p.appendChild(labelNode);
for (var i = 0; i < valueList.length; i++) {
var checkBoxNode = document.createElement("input");
var brInput = document.createElement("br");
checkBoxNode.setAttribute("type", "radio");
checkBoxNode.setAttribute("name", "radio");
checkBoxNode.setAttribute("value", valueList[i]);
var checkBoxValue = document.createTextNode(valueList[i]);
divInput.appendChild(checkBoxNode);
divInput.appendChild(checkBoxValue);
divInput.appendChild(brInput);
}
div.appendChild(nameNode);
div.appendChild(br);
div.appendChild(divInput);
divNode.appendChild(p);
divNode.appendChild(div);
return divNode.outerHTML;
}

View File

@ -167,7 +167,7 @@ function createForm(behaviorIndex) {
if (value != "" && value != null) {
$(contents[j].lastChild.lastChild).val(value);
}
} else if (type == "MultiField sample_frame") {
} else if (type == "NField sample_frame") {
var key = contents[j].firstChild.firstChild.nodeValue.split(":")[0];
var value = parameters[key];
if (value == null) {

View File

@ -5,6 +5,8 @@ var pluginMethodList = new Array();
var usePluginList = new Array();
var pageList = new Array();
var behaviors = new Array();
var behaviorList = [];// 存放所有方法及其parameter
var pluginParamList = [];// 一个plug-in名一个paramInfoModels list
var clickPluginMethodNode = -1;
var clickPluginChoosedNode = 0;
var place = "";
@ -20,6 +22,7 @@ function setTab(name, m, n) {
$(document).ready(function() {
loadPluginList();
loadPluginParams();
});
@ -38,21 +41,25 @@ function loadPluginList() {
}
function getMethod(pluglin) {
var aMethodList = "";
$.post("loadMethod", {
pluginName : plugin
}, function(data) {
if (!data.success) {
alert(data.failedMessage);
return;
}
data = data.data;// List<String> methodList
for (var i = 0; i < data.length; i++) {
aMethodList.push(data[i]);
}
});
return aMethodList;
// 实现plug-in参数传递
function loadPluginParams() {
$
.post(
"loadPluginUIInfo",
{},
function(data) {
if (!data.success) {
alert(data.failedMessage);
return;
}
data = data.data;// List<PluginUIModel>
// pluginUIModels
for (var i = 0; i < data.length; i++) {
var pluginInfoModel = data[i].pluginInfoModel;
pluginParamList.push(pluginInfoModel.name);
pluginParamList[pluginInfoModel.name] = pluginInfoModel.paramInfoModels;
}
});
}
function addPlugin() {
@ -105,23 +112,9 @@ function createALine(pluginName, index, list) {
return div;
}
//实现plug-in参数传递
function loadPluginParams(plugin){
$.post("loadPluginParams", {
pluginName : plugin
}, function(data) {
if (!data.success) {
alert(data.failedMessage);
return;
}
data = data.data;
document.getElementById("pluginParams").innerHTML += createAPage(
data, plugin, clickPluginChoosedNode);
});
}
function choosePlugin(selectedNode) {
clickPluginChoosedNode = $(selectedNode).attr("id");
alert("clickPluginChoosedNode="+clickPluginChoosedNode);
var pluginChoosedNode = $('#pluginArea').children();
var length = pluginChoosedNode.length;
for (var i = 0; i < length; i++) {
@ -131,9 +124,14 @@ function choosePlugin(selectedNode) {
$(pluginChoosedNode[i]).find("p").attr("class", "");
}
}
var plugin=selectedNode.lastChild.nodeValue;
alert("pluginName="+plugin);
loadPluginParams(plugin);
var plugin = selectedNode.lastChild.nodeValue;
var data = getParamInfoModelList(plugin);
document.getElementById("pluginParams").innerHTML += createAPage(data,
plugin, clickPluginChoosedNode);
}
function getParamInfoModelList(plugin) {
return pluginParamList[plugin];
}
function pluginFinish() {
@ -206,21 +204,23 @@ function showInsertPlugin(pluginName) {
function getMethodList(methodData) {
var methodHtml = "";
var methodList = new Array();
var plugin_method_List = new Array();
// var paramList=new Array();//List<ParamInfoModel>
var type = methodData.split("_");
var plugin = type[0];
$.post("loadMethod", {
$.post("loadBehaviorList", {
pluginName : plugin
}, function(data) {
if (!data.success) {
alert(data.failedMessage);
return;
}
data = data.data;// List<String> methodList
data = data.data;// List<BehaviorInfoModel> behaviorInfoModels
for (var i = 0; i < data.length; i++) {
plugin_method_List.push(methodData + "." + data[i]);// httpPlugin_0.post
methodList.push(data[i]);
behaviorList.push(data[i].name);
behaviorList[data[i].name] = data[i].paramInfoModels;
/* paramList=data[i].paramInfoModels; */
methodList.push(data[i].name);
methodHtml += createLineWithRadio(methodList[i], "method");
}
document.getElementById("pluginMethod").innerHTML = methodHtml;
@ -329,33 +329,22 @@ function clearPluginMethodList() {
function loadMethodParams(behaviorData, behaviorIndex) {
var temp = behaviorData.split('.');
plugin = temp[0].split('_')[0];
var method = temp[1];
$.post("loadMethodParameters", {
pluginName : plugin,
methodName : method
}, function(data) {
if (!data.success) {
alert(data.failedMessage);
return;
}
data = data.data;
document.getElementById("showPluginMethod").innerHTML += createAPage(
data, behaviorData, behaviorIndex);
});
var data = behaviorList[method];// data 为List<ParamInfoModel>
document.getElementById("showPluginMethod").innerHTML += createAPage(data,
behaviorData, behaviorIndex);
}
// 生成页面显示
function createAPage(data, behaviorData, behaviorIndex) {
function createAPage(data, name, index) {
var documentHtml = "";
var boxHeader = "";
boxHeader = "<div class='box-header well' data-original-title> "
+ "<i class='icon-pencil left'></i>" + "<h2>sample:<i>"
+ behaviorData + "</i></h2></div>";
var fieldHTML = createBehaviorsForm(data, behaviorData, behaviorIndex);
documentHtml = "<div id='" + behaviorIndex
+ "' class='hide'><p class='hide'>" + behaviorData
+ name + "</i></h2></div>";
var fieldHTML = createBehaviorsForm(data, name, index);
documentHtml = "<div id='" + index
+ "' class='hide'><p class='hide'>" + name
+ "</p><div class='span12 box' style='margin-left:-2px;'>"
+ boxHeader + "<div class='box-content'>" + fieldHTML + "</div>"
+ "</div></div>";
@ -412,7 +401,7 @@ function saveABehavior(div) {
if (temp != "") {
value = temp;
}
} else if ($(node).attr("class") == "MultiField sample_frame") {
} else if ($(node).attr("class") == "NField sample_frame") {
key = node.firstChild.firstChild.nodeValue.split(":")[0];
var fieldNode = $(node).find("table").children();
var fieldLength = $(fieldNode).length;
@ -446,13 +435,19 @@ function saveABehavior(div) {
}
} else if ($(node).attr("class") == "CheckBox sample_frame") {
key = node.lastChild.firstChild.nodeValue;
var id = $(node).attr("id");
$('input[name=' + id + ']:checked').each(function() {
/*var id = $(node).attr("id");*/
$('input[name= "checkbox"]:checked').each(function() {
temp = $(this).val();
if (temp != "") {
value += temp + ";";
}
});
} else if ($(node).attr("class") == "RadioButton sample_frame"){
key = node.lastChild.firstChild.nodeValue;
temp=$('input[name="radio"]:checked').val();
if (temp != "") {
value += temp + ";";
}
}
if (value != "") {
parameterModel = new ParameterModel(key, value);

View File

@ -1,3 +1,15 @@
function BehaviorInfoModel(paramInfoModels,name){
this.paramInfoModels=paramInfoModels;
this.name=name;
}
function ParamInfoModel(name,lable,paramTypeModel){
this.name=name;
this.lable=lable;
this.paramTypeModel=paramTypeModel;
}
function ScenarioModel(scriptName,runScenarioModel){
this.scriptName=scriptName;
this.runScenarioModel=runScenarioModel;
@ -62,10 +74,6 @@ function MethodParamPropertyModel(key, value) {
this.value = value;
}
/*function BatchModel(behaviors) {
this.behaviors = behaviors;
}
*/
function pluignChoosedModel(pluginName, index) {
this.pluginName = pluginName;
this.index = index;

View File

@ -24,15 +24,13 @@ function startServer() {
+ " and the port: "
+ server.port
+ " to record the script.");
$('#startServer').attr('disabled', true);
$('#stopServer').attr('disabled', false);
$('#uploadScript').attr('disabled',true);
}
else{
$('#scriptInfo').html("Fail to start record server:"+data.failedMessage);
}
$('#startServer').attr('disabled', true);
$('#stopServer').attr('disabled', false);
$('#uploadScript').attr('disabled',false);
}, "json");