refactor the script editor js

This commit is contained in:
fanfuxiaoran 2014-05-04 17:24:51 +08:00
parent 3ee9a78c6b
commit 9fc26763bd
18 changed files with 441 additions and 250 deletions

View File

@ -57,8 +57,8 @@ public class AuthorizeActionController extends BaseControllerService {
@RequestMapping("register")
@ResponseBody
public BaseResponseModel register(@RequestParam String userName,
@RequestParam String password,
@RequestParam String scope) throws CustomGenericException {
@RequestParam String password, @RequestParam String scope)
throws CustomGenericException {
UserModel user = new UserModel();
user.setUserName(userName);
user.setPassword(password);

View File

@ -8,7 +8,7 @@ import javax.servlet.http.HttpServletRequest;
import org.bench4q.share.models.master.plugin.PluginResponseModel;
import org.bench4q.web.exception.CustomGenericException;
import org.bench4q.web.masterMessager.PluginMessager;
import org.bench4q.web.validation.PluginValidation;
import org.bench4q.web.validation.PluginValidate;
import org.bench4q.web.validation.ValidateResponseModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ModelAttribute;
@ -24,7 +24,7 @@ public class PluginController extends BaseController {
private PluginMessager pluginMessager;
private PluginValidation pluginValidation;
private PluginValidate pluginValidation;
public PluginMessager getPluginMessager() {
return pluginMessager;
@ -35,12 +35,12 @@ public class PluginController extends BaseController {
this.pluginMessager = pluginMessager;
}
public PluginValidation getPluginValidation() {
public PluginValidate getPluginValidation() {
return pluginValidation;
}
@Autowired
public void setPluginValidation(PluginValidation pluginValidation) {
public void setPluginValidation(PluginValidate pluginValidation) {
this.pluginValidation = pluginValidation;
}

View File

@ -1,8 +1,119 @@
package org.bench4q.web.newapi;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Component
import org.bench4q.share.models.master.AuthorizeResponseModel;
import org.bench4q.share.models.master.RegisterResponseModel;
import org.bench4q.share.models.master.UserModel;
import org.bench4q.web.masterMessager.UserMessager;
import org.bench4q.web.model.TestPlanTaskModel;
import org.bench4q.web.validation.UserValidate;
import org.bench4q.web.validation.ValidateResponseModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.SessionAttributes;
@SessionAttributes({ "accessToken", "username", "testPlanTaskList" })
public class UserController extends BaseController {
private UserMessager userMessager;
private UserValidate userValidate;
public UserMessager getUserMessager() {
return userMessager;
}
@Autowired
public void setUserMessager(UserMessager userMessager) {
this.userMessager = userMessager;
}
public UserValidate getUserValidate() {
return userValidate;
}
@Autowired
public void setUserValidate(UserValidate userValidate) {
this.userValidate = userValidate;
}
@RequestMapping("register")
@ResponseBody
public Map<String, Object> register(@RequestParam String userName,
@RequestParam String password, @RequestParam String scope) {
Map<String, Object> map = new HashMap<String, Object>();
ValidateResponseModel validateResponseModel = this.getUserValidate()
.validateRegisterUser(userName, password, scope);
if (!validateResponseModel.isSuccess()) {
return fail(map, validateResponseModel.getMessage());
}
RegisterResponseModel registerResponseModel = this.getUserMessager()
.register(userName, password, scope);
if (!registerResponseModel.isSuccess()) {
fail(map, "please try again");
}
return success(map);
}
@RequestMapping("normalLogin")
@ResponseBody
public Map<String, Object> normalLogin(UserModel userModel,
ModelMap modelMap) {
Map<String, Object> map = new HashMap<String, Object>();
ValidateResponseModel validateResponseModel = this.getUserValidate()
.validateUserLogin(userModel.getUserName(),
userModel.getPassword());
if (!validateResponseModel.isSuccess()) {
return fail(map, "error userName or password");
}
AuthorizeResponseModel authorizeResponseModel = this.getUserMessager()
.normalLogin(userModel.getUserName(), userModel.getPassword());
if (!authorizeResponseModel.isSuccess()) {
return fail(map, "error userName or password");
} else {
updateSessionAttribute(modelMap, authorizeResponseModel,
userModel.getUserName());
return success(map);
}
}
@RequestMapping("adminLogin")
@ResponseBody
public Map<String, Object> adminLogin(UserModel userModel, ModelMap modelMap) {
Map<String, Object> map = new HashMap<String, Object>();
ValidateResponseModel validateResponseModel = this.getUserValidate()
.validateUserLogin(userModel.getUserName(),
userModel.getPassword());
if (!validateResponseModel.isSuccess()) {
return fail(map, "error userName or password");
}
AuthorizeResponseModel authorizeResponseModel = this.getUserMessager()
.adminLogin(userModel.getUserName(), userModel.getPassword());
if (!authorizeResponseModel.isSuccess()) {
return fail(map, "error userName or password");
} else {
updateSessionAttribute(modelMap, authorizeResponseModel,
userModel.getUserName());
return success(map);
}
}
private void updateSessionAttribute(ModelMap modelMap,
AuthorizeResponseModel authorizeResponseModel, String userName) {
modelMap.addAttribute("accessToken",
authorizeResponseModel.getAccessToken());
modelMap.addAttribute("username", userName);
List<TestPlanTaskModel> testPlanTaskModels = new ArrayList<TestPlanTaskModel>();
modelMap.addAttribute("testPlanTaskList", testPlanTaskModels);
}
}

View File

@ -2,7 +2,7 @@ package org.bench4q.web.validation;
import org.springframework.web.multipart.MultipartFile;
public class PluginValidation {
public class PluginValidate {
public ValidateResponseModel validatePluginName(String pluginName) {
if (ValidateHelper.validateStringInput(pluginName)) {

View File

@ -0,0 +1,31 @@
package org.bench4q.web.validation;
import org.springframework.stereotype.Component;
@Component
public class UserValidate {
public ValidateResponseModel validateRegisterUser(String userName,
String password, String scope) {
if (ValidateHelper.validateStringInput(userName)) {
return new ValidateResponseModel(false, "error user name");
}
if (ValidateHelper.validateStringInput(password)) {
return new ValidateResponseModel(false, "error password");
}
if (ValidateHelper.validateInteger(scope)) {
return new ValidateResponseModel(false, "error scope");
}
return new ValidateResponseModel(true, "");
}
public ValidateResponseModel validateUserLogin(String userName,String password){
if (ValidateHelper.validateStringInput(userName)) {
return new ValidateResponseModel(false, "error user name");
}
if (ValidateHelper.validateStringInput(password)) {
return new ValidateResponseModel(false, "error password");
}
return new ValidateResponseModel(true, "");
}
}

View File

@ -1 +1 @@
masterAddress=133.133.12.1:7979/
masterAddress=127.0.1.1:7979/

View File

@ -96,7 +96,7 @@ body {
</div>
<div class="box-content row-fluid">
<div id="pluginArea" class="listArea span8"></div>
<div id="usePlugin" class="listArea span8"></div>
<div class=" span4 button-div">
<div>
<button type="submit" class="btn btn-primary btn-width"
@ -200,7 +200,7 @@ body {
</h3>
</div>
<div class="modal-body" style="height: 260px;">
<div class="inset scroll" id="choosePlugin"></div>
<div class="inset scroll" id="pluginList"></div>
</div>
<div class="modal-footer">
@ -268,19 +268,15 @@ body {
<script src="lib/chrisma/js/jquery.cookie.js"></script>
<script src="lib/chrisma/js/theme.js"></script>
<script src="script/base.js"></script>
<script src="script/plugin.js"></script>
<script src="script/paramInfosForm.js"></script>
<script src="script/pluginModel.js"></script>
<script src="script/ScriptEditor/uiCommon.js"></script>
<script src="script/ScriptEditor/plugin.js"></script>
<script src="script/ScriptEditor/paramInfosForm.js"></script>
<script src="script/ScriptEditor/pluginModel.js"></script>
<script src="script/ScriptEditor/ContainerManager.js"></script>
<script src="script/ScriptEditor/usePluginEditor.js"></script>
<script src="script/ScriptEditor/useBehaviorEditor.js"></script>
<script src="script/ScriptEditor/scriptEditor.js"></script>
<script src="script/submitPluginMessage.js"></script>
<!-- <script src="script/pluginModel.js"></script>
<script src="script/pluginCommon.js"></script>
<script src="script/plugin-new.js"></script>
<script src="script/submitPluginMessage.js"></script>
<script src="script/behaviorsForm.js"></script> -->
<script src="script/ScriptEditor/submitPluginMessage.js"></script>
</fmt:bundle>
</body>
</html>

View File

@ -1,9 +1,9 @@
var Container = function() {
this.pluginListContainer = $("#choosePlugin");
this.usePluginContainer = $("#pluginArea");
this.pluginListContainer = $("#pluginList");
this.usePluginContainer = $("#usePlugin");
this.pluginParamConfigContainer = $("#pluginParams");
this.behaviorListForPlugin = $("#pluginMethod");
this.usePluginModal = $("#insertPluginAreaPlugins");
this.usePluginModal=$("#insertPluginAreaPlugins")
this.useBehaviorListContainer = $("#behaviorArea");
this.behaviorParamConfigContianer = $("#showPluginMethod");
@ -13,20 +13,6 @@ var ListContainer = function(container) {
};
Container.prototype.createLineWithRadio = function(lineText, nameAttr) {
var textNode = document.createTextNode(lineText);
var divNode = document.createElement("div");
var inputNode = document.createElement("input");
var brNode = document.createElement("br");
inputNode.setAttribute("type", "radio");
inputNode.setAttribute("name", nameAttr);
inputNode.setAttribute("class", "chooseOnePlugin");
inputNode.setAttribute("value", lineText);
divNode.appendChild(inputNode);
divNode.appendChild(textNode);
divNode.appendChild(brNode);
return $(divNode).html() + "<br>";
};
Container.prototype.createALine = function(name, index, list) {
var div = document.createElement("div");
var p = document.createElement("p");
@ -101,3 +87,4 @@ Container.prototype.createParamInforsContainer = function(data, name, index) {
+ "</div></div>";
return documentHtml;
};

View File

@ -1,26 +1,25 @@
var container = new Container();
var plugin = new Plugin(container);
var behavior = new Behavior(container, plugin);
var container;
var plugin;
var behavior;
var files = [];
$(document).ready(function() {
pluginEditorInit();
});
$("#addPlugin").click(function(e) {
$("#myModal_Plugin").modal('show');
});
$("#pluginFinish").click(function(e) {
$('#pluginArea').html("");
var item = $("input[type='radio']:checked").val();
container = new Container();
plugin = new Plugin(container);
behavior = new Behavior(container, plugin);
$("#pluginFinish").click(function(event) {
event.preventDefault();
var item = $("#pluginList input[type='radio']:checked").val();
plugin.addUsePlugin(item);
plugin.usePluginContainerInit(container.usePluginContainer);
plugin.usePluginParamInfosContainerInit(item);
$("#myModal_Plugin").modal('hide');
});
$("#addPlugin").click(function(e) {
$("#myModal_Plugin").modal('show');
});
});
function pluginEditorInit() {
plugin.pluginListContainerInit(container.pluginListContainer);
}
function choosePlugin(selectedNode) {

View File

@ -17,10 +17,11 @@ Behavior.prototype.usePluginListContainerInit = function(insertLocation,
var chooesedPluginHtml = "";
this.setInsertLocation(insertLocation);
for ( var i = 0; i < this.plugin.usePluginList.length; i++) {
chooesedPluginHtml += this.containerManager.createLineWithRadio(
this.plugin.usePluginList[i], "plugin");
chooesedPluginHtml += createLineWithRadio(this.plugin.usePluginList[i],
"plugin");
}
container.html(chooesedPluginHtml);// insertPluginAreaPlugins
};
Behavior.prototype.setInsertLocation = function(insertLocation) {
@ -53,8 +54,7 @@ Behavior.prototype.getBehaviorListOfOnePlugin = function(pluginName) {
for ( var i = 0; i < behaviors.length; i++) {
this.behaviorList.push(behaviors[i].name);
this.behaviorList[behaviors[i].name] = behaviors[i].paramInfoModels;
behaviorHtml += this.containerManager.createLineWithRadio(
behaviors[i].name, "method");
behaviorHtml += createLineWithRadio(behaviors[i].name, "method");
}
this.containerManager.behaviorListForPlugin.html(behaviorHtml);
};

View File

@ -1,19 +1,22 @@
$(document).ready(function() {
});
var Plugin = function(containerManager) {
this.pluginList = null;
this.pluginNameList = null;
this.pluginIndex = new HashMap();
this.usePluginList = new Array();
this.pluginParamInfoList = [];
this.clickPluginChoosedNodeIndex = 0;
this.clickPluginChoosedNodeName = "";
this.loadPluginNameList();
this.loadPluginList();
this.loadPluginUIList();
this.setPluginParamInfoList();
this.containerManager = containerManager;
};
Plugin.prototype.loadPluginNameList = function() {
var plugin = this;
$.ajax({
type : 'POST',
url : 'loadPluginName',
@ -25,14 +28,26 @@ Plugin.prototype.loadPluginNameList = function() {
alert(response.failedMessage);
return;
}
plugin.pluginNameList = response.data;
for (var i = 0; i < plugin.pluginNameList.length; i++) {
plugin.pluginIndex.put(plugin.pluginNameList[i], -1);
var pluginNameList = response.data;
for ( var i = 0; i < pluginNameList.length; i++) {
plugin.pluginIndex.put(pluginNameList[i], -1);
}
pluginListContainerInit($("#pluginList"), pluginNameList);
}
});
function pluginListContainerInit(container, pluginNameList) {
var pluginListHtmlContent = "";
for ( var i = 0; i < pluginNameList.length; i++) {
pluginListHtmlContent += createLineWithRadio(pluginNameList[i],
"plugin");
}
container.html(pluginListHtmlContent);
}
};
Plugin.prototype.loadPluginList = function() {
Plugin.prototype.loadPluginUIList = function() {
var plugin = this;
$.ajax({
type : 'POST',
@ -49,46 +64,41 @@ Plugin.prototype.loadPluginList = function() {
}
});
};
Plugin.prototype.pluginListContainerInit = function(container) {
var pluginListHtmlContent = "";
for (var j = 0; j < this.pluginNameList.length; j++) {
pluginListHtmlContent += this.containerManager.createLineWithRadio(
this.pluginNameList[j], "plugin");
}
container.html(pluginListHtmlContent);
$("input:radio").click(function() {
$(this).attr("checked", "checked");
});
};
Plugin.prototype.addUsePlugin = function(item) {
this.pluginIndex.put(item, this.pluginIndex.get(item) + 1);
this.usePluginList.push(this.createUsePluginName(item, this.pluginIndex
.get(item)));
var pluginName = createUsePluginName(item, this.pluginIndex.get(item));
this.usePluginList.push(pluginName);
$("#usePlugin").append(
createLine(pluginName, usePluginList.length, "pluginChoosedList"));
function createUsePluginName(pluginName, index) {
return pluginName + '_' + index;
}
function createLine(name, index, list) {
var div = document.createElement("div");
var p = document.createElement("p");
var i = document.createElement("i");
var textNode = document.createTextNode(name);
div.setAttribute("id", name);
i.setAttribute("class", "icon-hand-right");
p.setAttribute("id", index);
p.setAttribute("class", "");
if (list == "pluginMethodList") {
p.setAttribute("onClick", "showMethodDocument(this)");// loadMethodParams
} else if (list == "pluginChoosedList") {
p.setAttribute("onClick", "choosePlugin(this);");// 此处用于显示plugin文档
} else if (list == "editPluginChoosedList") {
p.setAttribute("onClick", "chooseEditPlugin(this);");
}
p.setAttribute("style", "cursor:pointer;width:85%");
p.appendChild(i);
p.appendChild(textNode);
div.appendChild(p);
return $(div);
};
Plugin.prototype.usePluginContainerInit = function(container) {
for (var i = 0; i < this.usePluginList.length; i++) {
var pluginName = this.usePluginList[i];
var div = this.containerManager.createALine(pluginName, i,
"pluginChoosedList");
container.append(div);
}
};
Plugin.prototype.configPluginContainerInit = function(container) {
};
// Plugin.prototype.deleteUsePlugin = function(pluginName) {
//
// for (var i = 0; i < this.usePluginList.length; i++) {
// if (this.usePluginList[i] == pluginName) {
// this.usePluginList.splice(i, 1);
// }
// }
//
// };
Plugin.prototype.createUsePluginName = function(pluginName, index) {
return pluginName + '_' + index;
};
Plugin.prototype.setClickPluginChoosedNodeIndex = function(selectedNode) {
this.clickPluginChoosedNodeIndex = $(selectedNode).attr("id");

View File

@ -1,11 +1,32 @@
package org.benc4q.test.newapi;
import org.bench4q.web.tool.test.LoginHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
public abstract class ControllerTestBase {
private final String userName = "admin";
private final String password = "admin";
protected String baseUrl = "http://127.0.0.1:8080";
private LoginHelper loginHelper;
private String login() {
return "";
private HttpRequest httpRequest;
public LoginHelper getLoginHelper() {
return loginHelper;
}
@Autowired
private void setLoginHelper(LoginHelper loginHelper) {
this.loginHelper = loginHelper;
}
public HttpRequest getHttpRequest() {
return httpRequest;
}
@Autowired
public void setHttpRequest(HttpRequest httpRequest) {
this.httpRequest = httpRequest;
}
}

View File

@ -1,6 +1,40 @@
package org.benc4q.test.newapi;
import org.junit.Before;
import org.junit.Test;
public class PluginControllerTest {
public class PluginControllerTest extends ControllerTestBase {
private String accessToken;
@Before
public void setUp() {
this.accessToken = this.getLoginHelper().login();
}
@Test
public void testAddPlugin() {
}
@Test
public void testDeletePlugin() {
}
@Test
public void loadPluginNameList() {
}
@Test
public void loadPluginUIList() {
}
@Test
public void loadBehaviorList() {
}
}

View File

@ -11,6 +11,8 @@ import org.springframework.ui.ModelMap;
@Component
public class LoginHelper {
private final String userName = "admin";
private final String password = "admin";
private AuthorizeActionController authorizeActionController;
private Logger logger = Logger.getLogger(LoginHelper.class);
@ -28,14 +30,14 @@ public class LoginHelper {
public String login() {
UserModel userModel = new UserModel();
userModel.setUserName("admin");
userModel.setPassword("admin");
userModel.setUserName(userName);
userModel.setPassword(password);
try {
if (this.authorizeActionController == null) {
System.out.println(" null");
}
ModelMap modelMap = new ModelMap();
authorizeActionController.login(userModel, modelMap);
authorizeActionController.adminLogin(userModel, modelMap);
String accessToken = (String) modelMap.get("accessToken");
return accessToken;
} catch (CustomGenericException e) {