add edit script
This commit is contained in:
parent
9ca0d5f8f7
commit
a394d3b784
|
@ -24,9 +24,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.SessionAttributes;
|
||||
|
@ -103,6 +101,7 @@ public class ScriptController extends BaseController {
|
|||
if (operateScriptServerResponseModel.isSuccess()) {
|
||||
ScriptModel scriptModel = operateScriptServerResponseModel
|
||||
.getScriptModels().get(0);
|
||||
System.out.println(scriptModel.getScriptContent());
|
||||
RunScenarioModel runScenarioModel = (RunScenarioModel) MarshalHelper
|
||||
.tryUnmarshal(RunScenarioModel.class,
|
||||
scriptModel.getScriptContent());
|
||||
|
@ -112,6 +111,7 @@ public class ScriptController extends BaseController {
|
|||
Gson gson = new Gson();
|
||||
map = success(map);
|
||||
map.put("script", gson.toJson(runScenarioModel));
|
||||
map.put("scriptId", scriptModel.getId());
|
||||
return map;
|
||||
} else {
|
||||
map = fail(map,
|
||||
|
@ -149,8 +149,6 @@ public class ScriptController extends BaseController {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@RequestMapping("uploadScriptFile")
|
||||
@ResponseBody
|
||||
public Map<String, Object> uploadScriptFile(
|
||||
|
@ -210,21 +208,22 @@ public class ScriptController extends BaseController {
|
|||
operateScriptServerResponseModel.getFailCauseString());
|
||||
}
|
||||
}
|
||||
@RequestMapping(value="submitScriptCreated/{scriptName}")
|
||||
|
||||
@RequestMapping(value = "submitScriptCreated/{scriptName}")
|
||||
@ResponseBody
|
||||
public Map<String, Object> submitScriptCreated(
|
||||
@ModelAttribute("accessToken") String accessToken,
|
||||
@RequestParam String runScenarioModelStr,
|
||||
@PathVariable String scriptName,
|
||||
@RequestParam(required = false) MultipartFile[] paramFiles
|
||||
) {
|
||||
@RequestParam(required = false) MultipartFile[] paramFiles) {
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
Gson gson = new Gson();
|
||||
RunScenarioModel runScenarioModel = gson.fromJson(runScenarioModelStr, RunScenarioModel.class);
|
||||
|
||||
// RunScenarioModel runScenarioModel = this.getScriptService()
|
||||
// .createRunScenarioModel(scenarioModel.getUsePlugins(),
|
||||
// scenarioModel.getBehaviors());
|
||||
RunScenarioModel runScenarioModel = gson.fromJson(runScenarioModelStr,
|
||||
RunScenarioModel.class);
|
||||
|
||||
// RunScenarioModel runScenarioModel = this.getScriptService()
|
||||
// .createRunScenarioModel(scenarioModel.getUsePlugins(),
|
||||
// scenarioModel.getBehaviors());
|
||||
OperateScriptServerResponseModel operateScriptServerResponseModel = this
|
||||
.getScriptMessager().uploadScript(accessToken, scriptName,
|
||||
MarshalHelper.tryMarshal(runScenarioModel), paramFiles);
|
||||
|
@ -239,17 +238,24 @@ public class ScriptController extends BaseController {
|
|||
@ResponseBody
|
||||
public Map<String, Object> updateScript(
|
||||
@ModelAttribute("accessToken") String accessToken,
|
||||
@RequestParam String scriptId, @RequestParam String script) {
|
||||
@RequestParam String scriptId,
|
||||
@RequestParam String runScenarioModelStr,
|
||||
@RequestParam(required = false) MultipartFile[] paramFiles) {
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
try {
|
||||
System.out.println(script);
|
||||
MarshalHelper.unmarshal(RunScenarioModel.class, script);
|
||||
} catch (Exception e) {
|
||||
return fail(map, "");
|
||||
}
|
||||
return processScriptResponse(new HashMap<String, Object>(), this
|
||||
.getScriptMessager()
|
||||
.updateScript(accessToken, scriptId, script));
|
||||
// try {
|
||||
// System.out.println(script);
|
||||
// MarshalHelper.unmarshal(RunScenarioModel.class, script);
|
||||
// } catch (Exception e) {
|
||||
// return fail(map, "");
|
||||
// }
|
||||
Gson gson = new Gson();
|
||||
RunScenarioModel runScenarioModel = gson.fromJson(runScenarioModelStr,
|
||||
RunScenarioModel.class);
|
||||
System.out.println(MarshalHelper.tryMarshal(runScenarioModel));
|
||||
return processScriptResponse(
|
||||
map,
|
||||
this.getScriptMessager().updateScript(accessToken, scriptId,
|
||||
MarshalHelper.tryMarshal(runScenarioModel), paramFiles));
|
||||
|
||||
}
|
||||
|
||||
|
@ -325,8 +331,7 @@ public class ScriptController extends BaseController {
|
|||
|
||||
return map;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void updateRunScenarioModel(RunScenarioModel runScenarioModel) {
|
||||
List<BehaviorModel> behaviorModels = new LinkedList<BehaviorModel>();
|
||||
for (PageModel pageModel : runScenarioModel.getPages()) {
|
||||
|
|
|
@ -110,16 +110,40 @@ public class ScriptMessager extends MasterMessager {
|
|||
accessToken);
|
||||
}
|
||||
|
||||
// public OperateScriptServerResponseModel updateScript(String accessToken,
|
||||
// String scriptId, String scriptContent) {
|
||||
// String url = this.getBaseUrl() + "/updateScript" + "/" + scriptId;
|
||||
// Map<String, String> params = new HashMap<String, String>();
|
||||
// params.put("content", scriptContent);
|
||||
// return this.getOperateScriptServerResponseModelByPost(url, params,
|
||||
// accessToken);
|
||||
//
|
||||
// }
|
||||
|
||||
public OperateScriptServerResponseModel updateScript(String accessToken,
|
||||
String scriptId, String scriptContent) {
|
||||
String scriptId, String scenarioModel, MultipartFile[] paramFiles) {
|
||||
String url = this.getBaseUrl() + "/updateScript" + "/" + scriptId;
|
||||
Map<String, String> params = new HashMap<String, String>();
|
||||
params.put("content", scriptContent);
|
||||
return this.getOperateScriptServerResponseModelByPost(url, params,
|
||||
accessToken);
|
||||
List<String> stringPart = new LinkedList<String>();
|
||||
stringPart.add(scenarioModel);
|
||||
HttpResponse httpResponse = null;
|
||||
|
||||
try {
|
||||
httpResponse = this.getHttpRequester().postFilesMulti(
|
||||
makeAccessTockenMap(accessToken), url, "paramFiles[]",
|
||||
paramFiles, "scenarioModel", stringPart);
|
||||
if (!validateHttpResponse(httpResponse))
|
||||
return null;
|
||||
return (OperateScriptServerResponseModel) MarshalHelper.unmarshal(
|
||||
OperateScriptServerResponseModel.class,
|
||||
httpResponse.getContent());
|
||||
|
||||
} catch (Exception e) {
|
||||
this.handleException(httpResponse, e);
|
||||
return createFailOperateScriptServerResponseModel();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public OperateScriptServerResponseModel loadScripts(String accessToken) {
|
||||
String url = this.getBaseUrl() + "/loadScriptList";
|
||||
return this.getOperateScriptServerResponseModelByPost(url, null,
|
||||
|
|
|
@ -102,15 +102,17 @@
|
|||
<div class="row-fluid">
|
||||
<div class="span9" id="useBehaviorList"></div>
|
||||
<div class="span3 buttonsControl">
|
||||
<div id="insertChildDiv" class="hide">
|
||||
<button type="submit" class="btn btn-primary btn-width"
|
||||
id="insertChildNode">
|
||||
<fmt:message key="plugin_jsp_insertChild" />
|
||||
</button>
|
||||
</div>
|
||||
<div>
|
||||
<button type="submit" class="btn btn-primary btn-width"
|
||||
id="addBehavior">
|
||||
<fmt:message key="plugin_jsp_add" />
|
||||
</button>
|
||||
<div>
|
||||
<button type="submit" class="btn btn-primary btn-width"
|
||||
id="insertBehaviorAfter">
|
||||
<fmt:message key="plugin_jsp_insertAfter" />
|
||||
</button>
|
||||
</div>
|
||||
<div>
|
||||
<button type="submit" class="btn btn-primary btn-width"
|
||||
|
@ -120,7 +122,7 @@
|
|||
</div>
|
||||
<div>
|
||||
<button type="submit" class="btn btn-primary btn-width"
|
||||
id="cleaBehavior">
|
||||
id="clearBehavior">
|
||||
<fmt:message key="plugin_jsp_clear" />
|
||||
</button>
|
||||
</div>
|
||||
|
@ -234,6 +236,7 @@
|
|||
|
||||
<script src="script/Share/getUrlVars.js"></script>
|
||||
<script src="script/ScriptEditor/scriptEditor.js"></script>
|
||||
<script src="script/ScriptEditor/scriptModels.js"></script>
|
||||
</fmt:bundle>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -9,7 +9,7 @@ var collectScriptData;
|
|||
// }
|
||||
//}
|
||||
|
||||
function getScriptObject(scriptId) {
|
||||
function getScriptObject(scriptId,usePlugin) {
|
||||
$.post("getScript", {
|
||||
scriptId : scriptId
|
||||
}, function(data) {
|
||||
|
@ -18,7 +18,7 @@ function getScriptObject(scriptId) {
|
|||
return;
|
||||
} else {
|
||||
var scriptObj = eval("(" + data.script + ")");
|
||||
var usePlugin = new UsePlugin();
|
||||
|
||||
usePlugin.initPluginAndPages(scriptObj);
|
||||
}
|
||||
}, "json");
|
||||
|
@ -26,27 +26,17 @@ function getScriptObject(scriptId) {
|
|||
|
||||
$(function() {
|
||||
var scriptId = getvars()['scriptId'];
|
||||
getScriptObject(scriptId);
|
||||
var usePlugin = new UsePlugin("useBehaviorList");
|
||||
getScriptObject(scriptId,usePlugin);
|
||||
$("#scriptName").val(getvars()['name']);
|
||||
|
||||
$("#tabs").tabs();
|
||||
|
||||
|
||||
$("#submitScript").click(function() {
|
||||
|
||||
// var script = editor.getSession().getValue();
|
||||
// $.post("updateScript", {
|
||||
// scriptId : scriptId,
|
||||
// scriptName : $("#scriptName").val(),
|
||||
// script : script
|
||||
// }, function(data) {
|
||||
// if (data.success) {
|
||||
// alert($.i18n.prop("script-save"))
|
||||
// } else {
|
||||
// alert($.i18n.prop('fail'));
|
||||
// }
|
||||
//
|
||||
// });
|
||||
var plugins = usePlugin.getPlugins();
|
||||
var pages = usePlugin.getPages();
|
||||
updateScript(scriptId,pages,plugins);
|
||||
|
||||
});
|
||||
});
|
||||
|
|
|
@ -2,8 +2,8 @@ function BehaviorViewModel(pluginModel, method, id) {
|
|||
this.pluginModel = pluginModel;
|
||||
this.method = method;
|
||||
this.id = id;
|
||||
|
||||
this.getBehaviorName = function(){
|
||||
|
||||
this.getBehaviorName = function() {
|
||||
return pluginModel.nickName + "_" + method + "_" + id;
|
||||
}
|
||||
}
|
||||
|
@ -17,8 +17,8 @@ function BatchViewModel(id, parentId, childId) {
|
|||
this.parentId = parentId;
|
||||
this.childId = childId;
|
||||
}
|
||||
function Behavior(usePlugin,containerId) {
|
||||
// var containerId = "useBehaviorList";
|
||||
function Behavior(usePlugin, containerId) {
|
||||
// var containerId = "useBehaviorList";
|
||||
var usePlugin = usePlugin;
|
||||
|
||||
var behaviorMap = new HashMap();
|
||||
|
@ -28,7 +28,7 @@ function Behavior(usePlugin,containerId) {
|
|||
var index = 1;
|
||||
var paramDataCollector = new DataCollector();
|
||||
var behavior = this;
|
||||
|
||||
|
||||
// init tree node container
|
||||
jstreeCreate(containerId);
|
||||
|
||||
|
@ -115,7 +115,8 @@ function Behavior(usePlugin,containerId) {
|
|||
return;
|
||||
}
|
||||
$("#pluginMethod").html("");
|
||||
var dataBehaviors = data.behaviors.sort(function(a, b) {
|
||||
var dataBehaviors = data.behaviors.sort(function(a,
|
||||
b) {
|
||||
return a.name.localeCompare(b.name);
|
||||
});
|
||||
createRadioGroupByAttribute(dataBehaviors, "name",
|
||||
|
@ -124,114 +125,127 @@ function Behavior(usePlugin,containerId) {
|
|||
|
||||
});
|
||||
|
||||
$("#selectBehavior #ok").click(
|
||||
function() {
|
||||
var usePluginId = $(
|
||||
"#usePlugins input[name='behavior_usePlugin']:checked")
|
||||
.attr("id");
|
||||
var method = $("#pluginMethod input[name='method']:checked")
|
||||
.val();
|
||||
var pluginId = usePluginId.split("_")[2];
|
||||
// get add type, insert or add
|
||||
var pos;
|
||||
if ($("#insertChildNode").hasClass("clicked")) {
|
||||
pos = "last";
|
||||
} else {
|
||||
pos = "after";
|
||||
$("#selectBehavior #ok")
|
||||
.click(
|
||||
function() {
|
||||
var usePluginId = $(
|
||||
"#usePlugins input[name='behavior_usePlugin']:checked")
|
||||
.attr("id");
|
||||
var method = $(
|
||||
"#pluginMethod input[name='method']:checked")
|
||||
.val();
|
||||
var pluginId = usePluginId.split("_")[2];
|
||||
// get add type, insert or add
|
||||
var pos;
|
||||
if ($("#insertChildNode").hasClass("clicked")) {
|
||||
pos = "last";
|
||||
} else {
|
||||
pos = "after";
|
||||
|
||||
}
|
||||
// deal page and batch
|
||||
if (pluginId == "page") {
|
||||
// add page to web
|
||||
jstreeCreateNode(containerId, "page", "page", index, pos);
|
||||
jstreeSelectNode(containerId, index);
|
||||
} else if (pluginId == "batch") {
|
||||
var batchViewModel = new BatchViewModel(index, -1, -1);
|
||||
batchMap.put(batchViewModel.id, batchViewModel);
|
||||
// add batch to web
|
||||
jstreeCreateNode("useBehaviorList", "batch", "batch",
|
||||
batchViewModel.id, pos);
|
||||
jstreeSelectNode(containerId, index);
|
||||
} else {
|
||||
if (pluginId == undefined || method == undefined) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
// deal page and batch
|
||||
if (pluginId == "page") {
|
||||
// add page to web
|
||||
createPageViewModel(index, pos);
|
||||
jstreeSelectNode(containerId, index);
|
||||
|
||||
var pluginModel = usePlugin.getUsePluginMap().get(pluginId);
|
||||
|
||||
var behaviorViewModel = new BehaviorViewModel(pluginModel,
|
||||
method, index);
|
||||
|
||||
jstreeCreateNode("useBehaviorList",
|
||||
behaviorViewModel.method,
|
||||
behaviorViewModel.getBehaviorName(),
|
||||
behaviorViewModel.id, pos);
|
||||
createBehaviorEditor(behaviorViewModel);
|
||||
} else if (pluginId == "batch") {
|
||||
// var batchViewModel = new BatchViewModel(index,
|
||||
// -1, -1);
|
||||
// batchMap.put(batchViewModel.id, batchViewModel);
|
||||
// // add batch to web
|
||||
// jstreeCreateNode("useBehaviorList", "batch",
|
||||
// "batch",
|
||||
// batchViewModel.id, pos);
|
||||
createBatchViewModel(index, -1, -1, pos);
|
||||
jstreeSelectNode(containerId, index);
|
||||
} else {
|
||||
if (pluginId == undefined || method == undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
//add behavior id to plugin which used
|
||||
pluginModel.behaviors.push(behaviorViewModel);
|
||||
behaviorMap.put(behaviorViewModel.id, behaviorViewModel);
|
||||
// var pluginModel =
|
||||
// usePlugin.getUsePluginMap().get(
|
||||
// pluginId);
|
||||
//
|
||||
// var behaviorViewModel = new BehaviorViewModel(
|
||||
// pluginModel, method, index);
|
||||
//
|
||||
// jstreeCreateNode("useBehaviorList",
|
||||
// behaviorViewModel.method, behaviorViewModel
|
||||
// .getBehaviorName(),
|
||||
// behaviorViewModel.id, pos);
|
||||
// createBehaviorEditor(behaviorViewModel);
|
||||
//
|
||||
// // add behavior id to plugin which used
|
||||
// pluginModel.behaviors.push(behaviorViewModel);
|
||||
// behaviorMap.put(behaviorViewModel.id,
|
||||
// behaviorViewModel);
|
||||
|
||||
}
|
||||
if (pos == "last") {
|
||||
$("#insertChildNode").removeClass("clicked");
|
||||
} else {
|
||||
$("#addBehavior").removeClass("clicked");
|
||||
}
|
||||
$("#selectBehavior").modal('hide');
|
||||
$("#usePlugins").html("");
|
||||
$("#pluginMethod").html("");
|
||||
index++;
|
||||
});
|
||||
createBehaviorViewModel(index, pluginId, method,
|
||||
pos, index);
|
||||
|
||||
}
|
||||
if (pos == "last") {
|
||||
$("#insertChildNode").removeClass("clicked");
|
||||
} else {
|
||||
$("#addBehavior").removeClass("clicked");
|
||||
}
|
||||
$("#selectBehavior").modal('hide');
|
||||
$("#usePlugins").html("");
|
||||
$("#pluginMethod").html("");
|
||||
index++;
|
||||
});
|
||||
$("#selectBehavior #cancel").click(function() {
|
||||
if ($("#insertChildNode").hasClass("clicked")) {
|
||||
$("#insertChildNode").removeClass("clicked")
|
||||
} else {
|
||||
$("#addBehavior").removeClass("clicked");pos = "after";
|
||||
$("#addBehavior").removeClass("clicked");
|
||||
pos = "after";
|
||||
}
|
||||
$("#selectBehavior").modal('hide');
|
||||
$("#usePlugins").html("");
|
||||
$("#pluginMethod").html("");
|
||||
});
|
||||
$("#removeBehavior").click(function() {
|
||||
|
||||
|
||||
// selected node's type
|
||||
var selectedNodes = jstreeSelectedNodes(containerId);
|
||||
if (!selectedNodes.length) {
|
||||
return;
|
||||
}
|
||||
var currNode = selectedNodes[0];
|
||||
//delete behavior from plugin
|
||||
// delete behavior from plugin
|
||||
var pluginModel = behaviorMap.get(currNode.id).pluginModel;
|
||||
|
||||
for(var i=0;i<pluginModel.behaviors;i++){
|
||||
if (pluginModel.behaviors[i].id == currNode.id){
|
||||
pluginModel.behaviors.splice(i,1);
|
||||
|
||||
for (var i = 0; i < pluginModel.behaviors; i++) {
|
||||
if (pluginModel.behaviors[i].id == currNode.id) {
|
||||
pluginModel.behaviors.splice(i, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
behavior.deleteBehaviorNode(currNode.id);
|
||||
});
|
||||
this.deleteBehaviorNode = function(behaviorId){
|
||||
this.deleteBehaviorNode = function(behaviorId) {
|
||||
behaviorMap.remove(behaviorId);
|
||||
behaviorEditorMap.remove(behaviorId);
|
||||
// delete node from tree
|
||||
jstreeDeleteNode(containerId,behaviorId);
|
||||
jstreeDeleteNode(containerId, behaviorId);
|
||||
$("#behaviorEditor").html("");
|
||||
$("#behaviorEditor").attr("behavior", "");
|
||||
}
|
||||
$("#clearBehavior").click(function() {
|
||||
$("#insertChildDiv").addClass("hide");
|
||||
//delete from pluginModel
|
||||
// delete from pluginModel
|
||||
var keys = behaviorMap.getKeys();
|
||||
for(var i=0;i<keys.length;i++){
|
||||
for (var i = 0; i < keys.length; i++) {
|
||||
var pluginModel = behaviorMap.get(keys[i]).pluginModel;
|
||||
pluginModel.behaviors = [];
|
||||
}
|
||||
behavior.clearBehaviorNode();
|
||||
|
||||
|
||||
})
|
||||
this.clearBehaviorNode = function(){
|
||||
this.clearBehaviorNode = function() {
|
||||
behaviorMap.clear();
|
||||
behaviorEditorMap.clear();
|
||||
// clear tree
|
||||
|
@ -251,7 +265,7 @@ function Behavior(usePlugin,containerId) {
|
|||
$("#behaviorEditor").html("");
|
||||
|
||||
}
|
||||
function createBehaviorEditor(behaviorModel) {
|
||||
function createBehaviorEditor(behaviorModel, selectedId, parameters) {
|
||||
|
||||
var pluginName = behaviorModel.pluginModel.name;
|
||||
var methodName = behaviorModel.method;
|
||||
|
@ -259,13 +273,14 @@ function Behavior(usePlugin,containerId) {
|
|||
$.post("getPluginMethod" + "/" + pluginName + "/" + methodName, {},
|
||||
function(data) {
|
||||
if (data.success) {
|
||||
var methodData = dataTransfer(data.method);
|
||||
var methodData = dataTransfer(data.method, parameters);
|
||||
var generator = containerFactory.createEditorContainer(
|
||||
methodName, "generator", methodData);
|
||||
|
||||
$(generator).addClass("generator");
|
||||
behaviorEditorMap.put(behaviorModel.id, generator);
|
||||
jstreeSelectNode(containerId, behaviorModel.id);
|
||||
if (selectedId == behaviorModel.id)
|
||||
jstreeSelectNode(containerId, behaviorModel.id);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
@ -306,7 +321,7 @@ function Behavior(usePlugin,containerId) {
|
|||
"behavior_usePlugin", "batch"));
|
||||
|
||||
}
|
||||
|
||||
|
||||
this.getPages = function() {
|
||||
updateBehaviorEditors();
|
||||
var treeObj = $("#" + containerId).jstree(true);
|
||||
|
@ -338,28 +353,82 @@ function Behavior(usePlugin,containerId) {
|
|||
new Array());
|
||||
var pageModel = idModelMap.get(currNode.parents[0]);
|
||||
pageModel.batches.push(batchModel);
|
||||
idModelMap.put(batchModel.id,batchModel);
|
||||
idModelMap.put(batchModel.id, batchModel);
|
||||
} else {
|
||||
var behaviorView = behaviorMap.get(currNode.id);
|
||||
var behaviorEditor = behaviorEditorMap.get(behaviorView.id);
|
||||
var params = paramDataCollector
|
||||
.getUnitParams($(behaviorEditor).find(".editor"));
|
||||
var params = paramDataCollector.getUnitParams($(behaviorEditor)
|
||||
.find(".editor"));
|
||||
var behaviorModel = new BehaviorModel(behaviorView.id,
|
||||
behaviorView.pluginModel.id, behaviorView.method,
|
||||
getBehaviorType(behaviorView.pluginModel.name), params);
|
||||
|
||||
|
||||
var batchModel = idModelMap.get(currNode.parents[0]);
|
||||
batchModel.behaviors.push(behaviorModel);
|
||||
idModelMap.put(behaviorModel.id,behaviorModel);
|
||||
idModelMap.put(behaviorModel.id, behaviorModel);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
this.initBehaviorList = function(pages){
|
||||
//init page, batch, behavior
|
||||
for(var i=0;i<pages.length;i++){
|
||||
|
||||
this.initBehaviorList = function(pages) {
|
||||
// init page, batch, behavior
|
||||
for (var i = 0; i < pages.length; i++) {
|
||||
// create page
|
||||
var page = pages[i];
|
||||
createPageViewModel(page.id, "after");
|
||||
// update index
|
||||
updateIndex(page.id);
|
||||
// init batch
|
||||
initBatch(page.id, page.batches);
|
||||
}
|
||||
index += 1;
|
||||
}
|
||||
function initBatch(parentNode, batches) {
|
||||
for (var i = 0; i < batches.length; i++) {
|
||||
var batch = batches[i];
|
||||
createBatchViewModel(batch.id, batch.parentId, batch.childId,
|
||||
"last", parentNode);
|
||||
updateIndex(batch.id);
|
||||
// init behavior
|
||||
initBehavior(batch.id, batch.behaviors);
|
||||
}
|
||||
}
|
||||
function initBehavior(parentNode, behaviors) {
|
||||
var selectedId = behaviors[0].id;
|
||||
for (var i = 0; i < behaviors.length; i++) {
|
||||
var behavior = behaviors[i];
|
||||
updateIndex(behavior.id);
|
||||
createBehaviorViewModel(behavior.id, behavior.use, behavior.name,
|
||||
"last", selectedId, behavior.parameters, parentNode);
|
||||
}
|
||||
}
|
||||
function createPageViewModel(id, pos) {
|
||||
jstreeCreateNode(containerId, "page", "page", id, pos);
|
||||
}
|
||||
function createBatchViewModel(id, parentId, childId, pos, parentNode) {
|
||||
var batchViewModel = new BatchViewModel(id, parentId, childId);
|
||||
batchMap.put(batchViewModel.id, batchViewModel);
|
||||
// add batch to web
|
||||
jstreeCreateNode(containerId, "batch", "batch", batchViewModel.id, pos,
|
||||
parentNode);
|
||||
}
|
||||
function createBehaviorViewModel(id, pluginId, method, pos, selectedId,
|
||||
parameters, parentNode) {
|
||||
var pluginModel = usePlugin.getUsePluginMap().get(pluginId);
|
||||
|
||||
var behaviorViewModel = new BehaviorViewModel(pluginModel, method, id);
|
||||
|
||||
jstreeCreateNode("useBehaviorList", behaviorViewModel.method,
|
||||
behaviorViewModel.getBehaviorName(), behaviorViewModel.id, pos,
|
||||
parentNode);
|
||||
createBehaviorEditor(behaviorViewModel, selectedId, parameters);
|
||||
|
||||
// add behavior id to plugin which used
|
||||
pluginModel.behaviors.push(behaviorViewModel);
|
||||
behaviorMap.put(behaviorViewModel.id, behaviorViewModel);
|
||||
}
|
||||
function updateIndex(id) {
|
||||
if (index < id) {
|
||||
index = id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,17 +6,21 @@
|
|||
* @param pos the position of new node to the parent node,maybe "last" which means the childnode of the selected
|
||||
* node,"after" or "before" means the sibling node of the selected node
|
||||
*/
|
||||
function jstreeCreateNode(containerId,data,name,id,pos){
|
||||
function jstreeCreateNode(containerId,data,name,id,pos,parentNode){
|
||||
var treeObj = $("#"+containerId).jstree(true);
|
||||
var parentNode = treeObj.get_selected();
|
||||
if(parentNode == null || parentNode == undefined){
|
||||
parentNode = treeObj.get_selected();
|
||||
if(!parentNode.length){
|
||||
parentNode=null;
|
||||
}
|
||||
else{
|
||||
parentNode = parentNode[0];
|
||||
}
|
||||
}
|
||||
|
||||
var childNode = null;
|
||||
var type = data;
|
||||
if(!parentNode.length){
|
||||
parentNode=null;
|
||||
}
|
||||
else{
|
||||
parentNode = parentNode[0];
|
||||
}
|
||||
|
||||
if(type!="page" && type!="batch")
|
||||
type = "default";
|
||||
childNode = treeObj.create_node(parentNode,{text:name,id:id,data:data,type:type},pos);
|
||||
|
@ -24,7 +28,6 @@ function jstreeCreateNode(containerId,data,name,id,pos){
|
|||
treeObj.open_node(parentNode);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* delete current node
|
||||
* @param containerId the id of jstree container
|
||||
|
|
|
@ -54,3 +54,21 @@ function submitScript(pages,usePlugins) {
|
|||
});
|
||||
|
||||
}
|
||||
function updateScript(scriptId, pages, usePlugins){
|
||||
var runScenarioModel = new RunScenarioModel(0,usePlugins,new Array(),pages);
|
||||
|
||||
$.ajax({
|
||||
type : "POST",
|
||||
url : "updateScript",
|
||||
data :{scriptId:scriptId, runScenarioModelStr: JSON.stringify(runScenarioModel)},//JSON.stringify(runScenarioModel),
|
||||
// dataType : "json",
|
||||
// contentType : "application/json",
|
||||
success : function(data) {
|
||||
if (!data.success) {
|
||||
return;
|
||||
} else {
|
||||
alert("success");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ function UsePlugin(behaviorListContainerId) {
|
|||
map.put(pluginModel.id, pluginModel);
|
||||
|
||||
updateUsePlugin();
|
||||
createEditor(pluginModel);
|
||||
createEditor(pluginModel,pluginModel.id);
|
||||
index++;
|
||||
$("#selectUsePlugin").modal('hide');
|
||||
});
|
||||
|
@ -96,11 +96,11 @@ function UsePlugin(behaviorListContainerId) {
|
|||
});
|
||||
|
||||
}
|
||||
function createEditor(pluginModel) {
|
||||
function createEditor(pluginModel, selectedId, parameters) {
|
||||
|
||||
$.post("getPlugin" + "/" + pluginModel.name, {}, function(data) {
|
||||
if (data.success) {
|
||||
var pluginData = dataTransfer(data.plugin);
|
||||
var pluginData = dataTransfer(data.plugin,parameters);
|
||||
createEditorByData(pluginModel,pluginData);
|
||||
// var generator = containerFactory.createEditorContainer(
|
||||
// pluginModel.name, "generator", pluginData);
|
||||
|
@ -108,7 +108,8 @@ function UsePlugin(behaviorListContainerId) {
|
|||
// $(generator).addClass("generator");
|
||||
// usePluginEditorMap.put(pluginModel.id, generator);
|
||||
//select this new node
|
||||
jstreeSelectNode(containerId, pluginModel.id);
|
||||
if(selectedId == pluginModel.id)
|
||||
jstreeSelectNode(containerId, pluginModel.id);
|
||||
|
||||
} else {
|
||||
return;
|
||||
|
@ -117,6 +118,7 @@ function UsePlugin(behaviorListContainerId) {
|
|||
});
|
||||
|
||||
}
|
||||
|
||||
function updateUsePlugin() {
|
||||
if ($("#pluginEditor").attr("usePlugin") == undefined
|
||||
|| $("#pluginEditor").attr("usePlugin") == "") {
|
||||
|
@ -197,40 +199,27 @@ function UsePlugin(behaviorListContainerId) {
|
|||
}
|
||||
function initPluginList(usePlugins){
|
||||
//init plugin
|
||||
|
||||
var selectedId = usePlugins[0].id;
|
||||
for(var i=0;i < usePlugins.length;i++){
|
||||
var usePlugin = usePlugins[i];
|
||||
createUsePlugin(usePlugin);
|
||||
createUsePlugin(usePlugin,selectedId);
|
||||
if(index < usePlugin.id){
|
||||
index = usePlugin.id;
|
||||
}
|
||||
}
|
||||
index +=1;//this is new id
|
||||
jstreeSelectNode("usePluginList", usePlugins[0].id);
|
||||
}
|
||||
function createUsePlugin(usePlugin){
|
||||
function createUsePlugin(usePlugin,selectedId){
|
||||
//add to map
|
||||
var pluginModel = new UsePluginViewModel(usePlugin.id, usePlugin.name, usePlugin.nickName);
|
||||
map.put(pluginModel.id, pluginModel);
|
||||
|
||||
//add to editor map
|
||||
getUsePluginEditor(pluginModel,usePlugin.parameters);
|
||||
createEditor(pluginModel,selectedId, usePlugin.parameters);
|
||||
//add to tree
|
||||
jstreeCreateNode("usePluginList",usePlugin.name,usePlugin.nickName,usePlugin.id,"after");
|
||||
}
|
||||
|
||||
function getUsePluginEditor(pluginModel,parameters){
|
||||
$.post("getPlugin" + "/" + pluginModel.name, {}, function(data) {
|
||||
if (data.success) {
|
||||
var pluginData = dataTransfer(data.plugin,parameters);
|
||||
createEditorByData(pluginModel,pluginData);
|
||||
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
function createEditorByData(pluginModel,pluginData){
|
||||
|
||||
var generator = containerFactory.createEditorContainer(
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
package org.bench4q.web.test.masterMessager;
|
||||
|
||||
import static com.github.tomakehurst.wiremock.client.WireMock.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
|
||||
import static com.github.tomakehurst.wiremock.client.WireMock.containing;
|
||||
import static com.github.tomakehurst.wiremock.client.WireMock.post;
|
||||
import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -18,6 +22,7 @@ import org.junit.runner.RunWith;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = { "file:src/test/resources/bench4qweb-servlet.xml" })
|
||||
|
@ -134,8 +139,8 @@ public class ScriptMessagerTest extends MessagerTestBase {
|
|||
aResponse().withStatus(200)
|
||||
.withHeader("Content-Type", "text/xml")
|
||||
.withBody(this.createResponse())));
|
||||
assertNotNull(this.getScriptMessager().updateScript(null, scriptId, ""));
|
||||
assertTrue(this.getScriptMessager().updateScript(null, scriptId, "")
|
||||
assertNotNull(this.getScriptMessager().updateScript(null, scriptId, "",new MultipartFile[0]));
|
||||
assertTrue(this.getScriptMessager().updateScript(null, scriptId, "",new MultipartFile[0])
|
||||
.isSuccess());
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue