add device jsp

This commit is contained in:
fanfuxiaoran 2014-05-08 17:54:55 +08:00
parent 389b4f3936
commit e64e1a9bca
8 changed files with 273 additions and 305 deletions

View File

@ -27,7 +27,7 @@ import org.springframework.web.bind.annotation.SessionAttributes;
@Controller
@SessionAttributes("accessToken")
public class AgentActionController extends BaseControllerService {
private final String baseUrl =this.masterIp+ "agentManage";
private final String baseUrl = this.masterIp + "agentManage";
public static int IN_IDLE = 1;
private String getBaseUrl() {

View File

@ -23,6 +23,7 @@ import org.bench4q.web.service.CommunicateWithMaster;
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.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
@ -157,6 +158,23 @@ public class PluginActionController extends BaseController {
}
}
@RequestMapping("getPlugin/{pluginName}")
@ResponseBody
Map<String, Object> getPlugin(
@ModelAttribute("accessToken") String accessToken,
@PathVariable String pluginName) {
Map<String, Object> map = new HashMap<String, Object>();
PluginResponseModel pluginResponseModel = this.getPluginMessager()
.getPluginInfoModel(accessToken, pluginName);
if (!pluginResponseModel.isSuccess()) {
return fail(map, "fail:" + pluginResponseModel.getFailMessage());
} else {
map = success(map);
map.put("pluginInfo", pluginResponseModel.getPluginInfoModel());
return map;
}
}
@RequestMapping("loadBehaviorList")
public @ResponseBody
BaseResponseModel loadBehaviorList(HttpServletRequest request,

View File

@ -41,6 +41,13 @@ public class PluginMessager extends MasterMessager {
return pluginResponseModel;
}
public PluginResponseModel getPluginInfoModel(String accessToken,
String pluginName) {
String url = this.getBaseUrl() + "/getPlugin" + "/" + pluginName;
return getPluginResponseModelByGet(url, null, accessToken);
}
public PluginResponseModel loadBehaviors(String accessToken,
String pluginName) {
String url = this.getBaseUrl() + "/loadBehaviors" + "/" + pluginName;
@ -83,10 +90,12 @@ public class PluginMessager extends MasterMessager {
try {
httpResponse = this.getHttpRequester().sendGet(url, null,
makeAccessTockenMap(accessToken));
System.out.println(httpResponse.getContent());
if (!validateHttpResponse(httpResponse))
return null;
if (!validateHttpResponse(httpResponse)) {
logger.info("response is null");
return createFailPluginResponseModel();
}
return extractPluginResponseModel(httpResponse);
} catch (JAXBException | IOException e) {
@ -106,8 +115,12 @@ public class PluginMessager extends MasterMessager {
private PluginResponseModel extractPluginResponseModel(
HttpResponse httpResponse) throws JAXBException {
return (PluginResponseModel) MarshalHelper.unmarshal(
PluginResponseModel.class, httpResponse.getContent());
PluginResponseModel pluginResponseModel = (PluginResponseModel) MarshalHelper
.unmarshal(PluginResponseModel.class, httpResponse.getContent());
if (!pluginResponseModel.isSuccess()) {
logger.info(pluginResponseModel.getFailMessage());
}
return pluginResponseModel;
}

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:component-scan base-package="org.bench4q" />
<mvc:annotation-driven />
</beans>

View File

@ -3,34 +3,47 @@ label {
margin-right: 30px;
}
input,textarea {
}
button {
margin-right: 5px;
width: 70px;
}
.editor {
background-color: #f5f5f5;
border-top-color: #dcdcdc;
width: 400px;
.containerBox {
width: 80%;
border: 1px solid #d5d5d5;
margin-left: 10px;
margin-top: 10px;
padding-left: 30px;
color: #212121;
margin-top: 20px;
margin-left: 20px;
margin-right: 20px;
box-shadow:3px 3px 3px #888888;
}
.containerBox .header {
border-bottom: 1px solid #c5d5dd;
padding-left: 10px;
padding-top: 3px;
font-weight: bold;
text-shadow: 0 1px white;
background: #e5eecc;
border-top-right-radius: 4px;
border-top-left-radius: 4px;
color: #3a505b;
}
.editor {
background: #f7f7f7;;
padding-left: 10px;
padding-right: 30px;
padding-top: 10px;
padding-bottom: 10px;
margin-bottom: 10px;
}
.editor div {
}
table tr td input {
td input {
text-align: center;
width: 100%;
}
@ -39,226 +52,8 @@ table tr td input {
font-weight: bold;
margin-bottom: 10px;
margin-top: 10px;
background: #e6f1f6;
}
.editor button {
margin-top: 10px;
}
.inset {
width: 85%;
height: 80%;
align: center;
margin: 5px;
}
.scroll {
overflow-x: hidden;
overflow-y: auto;
}
.button-div {
margin-top: 50px;
padding-left: 20px;
}
.button-div div {
margin-top: 10px;
}
.behavior_box {
border: 1px inset;
width: 200px;
height: 300px;
margin-right: 0px;
margin-left: 0px;
}
.table-margin {
margin-top: 10px;
padding-top: 5px;
padding-left: 20px;
padding-bottom: 10px;
}
.sample_frame {
padding: 10px;
margin: 5px 5px 5px 5px;
border: #E8F2FE solid thin;
}
.sample_sub_frame {
border: #F0ECE0 solid thin;
margin-top: 5px;
margin-bottom: 5px;
margin-left: 10px;
margin-right: 10px;
}
.btn-width {
width: 85px;
}
.btn-large {
width: 25%;
}
.listArea {
height: 340px;
margin-bottom: 15px;
outline-style: outset;
outline-color: #A0D0EC;
/* color: black; */
}
.behavior-box {
height: 400px;
border: 1px solid #3689BB;
margin-left: 5px;
}
#myModal_Behavior {
width: 800px;
left: 40%;
}
.listArea,#insertPluginAreaPlugins,#pluginMethod p,a {
padding-top: 10px;
padding-left: 20px;
}
#pluginMethod {
padding-top: 10px;
padding-left: 20px;
}
a {
color: #4E9BCB;
/* border-bottom: 1px solid #F0ECE0; */
}
#submitBehaviors p {
margin-top: 10px;
margin-left: 10px;
}
.visited {
background-color: #E8F2FE;
}
.tab .nav li a:hover,.nav>li>a:focus {
text-decoration: none;
background-color: #E5E3E9;
}
.tab .nav-tabs {
border-bottom: 1px solid #F7F5FA;
margin-bottom: 15px;
}
.tab .nav {
list-style: none;
}
.tab {
background-color: #F7F5FA;
margin-bottom: 15px;
padding-bottom: 5px;
padding-top: -10px;
}
.tab ul {
/* zoom: 1; */
clear: both;
}
.tab ul:after {
display: block;
height: 0px;
visibility: hidden;
clear: both;
content: "";
}
.tab ul li {
margin-bottom: -10px;
text-align: center;
line-height: 100%;
width: 20%;
display: inline;
float: left;
height: 26px;
color: #fff;
text-align: center;
}
.tab ul li.on {
color: black;
}
.tabContent .span10 {
margin-left: -25px;
}
.help_step_box {
background: #f1f7e4;
height: 55px;
overflow: hidden;
border-top: 1px solid #FFF;
}
.help_step_item {
float: left;
height: 55px;
line-height: 55px;
padding: 0 25px 0 45px;
cursor: pointer;
position: relative;
font-size: 14px;
font-weight: bold;
}
.help_step_num {
width: 19px;
height: 19px;
line-height: 19px;
position: absolute;
text-align: center;
top: 18px;
left: 20px;
font-size: 16px;
font-weight: bold;
background: url(http://www.codefans.net/jscss/demoimg/201011/num.png);
color: #156600;
}
.help_step_set {
background: #27a806;
color: #FFF;
}
.help_step_set .help_step_left {
width: 8px;
height: 55px;
background: url(http://www.codefans.net/jscss/demoimg/201011/bak.jpg)
left top no-repeat;
position: absolute;
left: 0;
top: 0;
}
.help_step_set .help_step_right {
width: 8px;
height: 55px;
background: url(http://www.codefans.net/jscss/demoimg/201011/bak.jpg)
left bottom no-repeat;
position: absolute;
right: -8px;
top: 0;
}
.btn-page {
background-color: #50A8DC;
margin-top: 20px;
margin-bottom: 20px;
}

View File

@ -7,6 +7,7 @@
<link id="bs-css" href="lib/chrisma/css/bootstrap-cerulean.css"
rel="stylesheet">
<link href="lib/chrisma/css/charisma-app.css" rel="stylesheet">
<link href="css/script-editor.css" rel="stylesheet">
<link rel="shortcut icon" href="images/bench4q.png">
</head>
<body>
@ -16,12 +17,14 @@
<div class="row-fluid">
<jsp:include page="publiccontrol/leftmenubar.jsp"></jsp:include>
<div id="content" class="span10" id="devices">
<button type="button" class="btn btn-primary " id="add-device">添加设备</button>
<button type="button" class="btn btn-primary " id="del-device">删除设备</button>
<button type="button" class="btn btn-primary " id="add-device">add</button>
<button type="button" class="btn btn-primary " id="del-device">remove</button>
</div>
</div>
</div>
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-2.0.3.min.js"></script>
<script src="script/device/EditorFactory.js"></script>
<script src="script/device/device.js"></script>
</body>
</html>

View File

@ -1,48 +1,38 @@
$(function() {
$('#test').append(createContainer("test", "test"));
});
function baseCreateEditor(label, id) {
var div = document.createElement("div");
$(div).addClass("editor");
$(div).attr("id", id);
var p = document.createElement("p")
$(p).html(label);
$(div).append(p);
return div;
}
function createField(label, name, size, id) {
var div = baseCreateEditor(label, id);
$(div).append(createFieldLine(size, name));
return div;
}
function createFieldLine(size, name) {
if (size <= 0) {
size = 10;
var EditorFactory=function(){};
EditorFactory.prototype.createBaseEditor=function(label, id) {
if (label == null) {
label = "";
}
var fieldDiv = document.createElement("div");
$(fieldDiv).attr("class", "field");
var fieldName = document.createElement("label");
$(fieldName).html(name + ":");
var field = document.createElement("input");
$(field).attr("type", "text");
$(field).attr("style", "width:" + size + "px");
$(fieldDiv).append(fieldName.outerHTML + field.outerHTML);
return fieldDiv;
var containerBox = document.createElement("div");
$(containerBox).addClass("containerBox");
var boxHeader = document.createElement("div");
var p = document.createElement("p")
$(p).html(label)
$(boxHeader).append(p);
$(boxHeader).addClass("header")
$(containerBox).append(boxHeader);
var boxBody = document.createElement("div");
$(boxBody).addClass("editor");
$(boxBody).attr("id", id);
$(containerBox).append(boxBody);
return containerBox;
}
function createMultiField(label, name, size, id) {
var div = createField(label, name, size, id);
EditorFactory.prototype.createField=function(label, name, size, id) {
var div = this.createBaseEditor(label, id);
$(div).children(".editor").append(this.createFieldLine(size, name));
return div;
}
EditorFactory.prototype.createMultiField=function(label, name, size, id) {
var div =this. createField(label, name, size, id);
var editorFactory=this;
var addFieldButton = document.createElement("button");
$(addFieldButton).html("add")
$(addFieldButton).attr("type", "submit");
$(addFieldButton).click(function(event) {
$(addFieldButton).click({editorFactory:editorFactory},function(event) {
event.preventDefault()
$(createFieldLine(size, name)).insertBefore($(this));
$(event.data.editorFactory.createFieldLine(size, name)).insertBefore($(this));
});
var removeFieldButton = document.createElement("button");
$(removeFieldButton).html("remove")
@ -52,14 +42,31 @@ function createMultiField(label, name, size, id) {
$(this).parent().children(".field").last().remove();
});
$(div).append(addFieldButton).append(removeFieldButton);
$(div).children(".editor").append(addFieldButton).append(removeFieldButton);
return div;
}
function createFileEditor(label, name, size, id) {
var div = baseCreateEditor(label, id);
EditorFactory.prototype.createFieldLine=function(size, name) {
if (size == null || size <= 0) {
size = 150;
}
var fieldDiv = document.createElement("div");
$(fieldDiv).addClass("field");
var fieldName = document.createElement("label");
$(fieldName).html(name + ":");
var field = document.createElement("input");
$(field).attr("type", "text");
$(field).attr("style", "width:" + size + "px");
$(fieldDiv).append(fieldName.outerHTML + field.outerHTML);
return fieldDiv;
}
EditorFactory.prototype.createFile=function(label, name, size, id) {
if (size == null || size <= 0) {
size = 150;
}
var div = this.createBaseEditor(label, id);
var fileEditor = document.createElement("div");
@ -69,16 +76,15 @@ function createFileEditor(label, name, size, id) {
$(file).attr("type", "file");
$(file).attr("style", "width:" + size + "px");
$(fileEditor).append(fieldName.outerHTML + file.outerHTML);
$(div).append(fileEditor);
$(div).children(".editor").append(fileEditor);
return div;
}
function createTableEditor(label, name, cols, id) {
var div = baseCreateEditor(label, id);
EditorFactory.prototype.createTable=function(label, name, cols, id) {
var div = this.createBaseEditor(label, id);
var headers = getHeaders(cols);
$(div).append(createTable(cols, name, headers));
$(div).children(".editor").append(createTable(cols, name, headers));
var addButton = document.createElement("button");
$(addButton).html("add");
$(addButton).click(
@ -91,15 +97,15 @@ function createTableEditor(label, name, cols, id) {
createTr(event.data.headers));
});
var deleteButton = document.createElement("button");
$(deleteButton).html("delete");
$(deleteButton).html("remove");
$(deleteButton).click(
function(event) {
event.preventDefault();
$(this).parent().children("table").children("tbody").children(
"tr").last().remove();
});
$(div).append(addButton);
$(div).append(deleteButton);
$(div).children(".editor").append(addButton);
$(div).children(".editor").append(deleteButton);
return div;
function getHeaders(col) {
@ -151,15 +157,19 @@ function createTableEditor(label, name, cols, id) {
}
}
function createSelect(label, name, size, options, id) {
EditorFactory.prototype.createSelect=function(label, name, size, options, id) {
if (size == null) {
if (size == null || size <= 0) {
size = 150;
}
var div = baseCreateEditor(label, id);
if(options==null||options.length<=0){
alert("no options in:"+name);
}
var div = this.createBaseEditor(label, id);
var nameLabel = document.createElement("label");
$(nameLabel).html(name + ":");
$(div).append(nameLabel);
$(div).children(".editor").append(nameLabel);
var select = document.createElement("select");
$(select).attr("style", "width:" + size + "px");
for ( var i = 0; i < options.length; i++) {
@ -168,18 +178,39 @@ function createSelect(label, name, size, options, id) {
$(option).html(options[i]);
$(select).append(option);
}
$(div).append(select);
$(div).children(".editor").append(select);
return div;
}
EditorFactory.prototype.createDate=function(label, name, size, id) {
if (size == null || size < 0) {
size = 150
}
var div = this.createBaseEditor(label, id);
var dateLabel = document.createElement("label");
$(dateLabel).html(name);
var date = document.createElement("input");
$(date).attr("type", "date");
$(div).children(".editor").append(dateLabel);
$(div).children(".editor").append(date);
return div;
}
function createContainer(id, name) {
var edtiorFactory=new EditorFactory();
var div = document.createElement("div");
$(div).attr("id", id);
$(div).append(createMultiField("test", "name", 150, "test"));
$(div).append(createFileEditor("file", "file name", 150, "file"));
$(div).append(createField("field", "field name", 150, "field"));
$(div).append(createTableEditor("table", "input", "td1;td1;td3", "id"));
$(div).append(createSelect("select", "select", 150, [ 1, 2, 3 ], "oo"));
$(div).append(edtiorFactory.createMultiField("test", "name", 150, "test"));
$(div).append(edtiorFactory.createFile("file", "file name", 150, "file"));
$(div).append(edtiorFactory.createField("field", "field name", 150, "field"));
$(div).append(edtiorFactory.createTable("table", "input", "td1;td1;td3", "id"));
$(div).append(edtiorFactory.createSelect("select", "select", 150, [ 1, 2, 3 ], "oo"));
$(div).append(edtiorFactory.createDate("date", "date", 150, "dateid"));
return div;
}
$(function() {
$('#test').append(createContainer("test", "test"));
});

View File

@ -1,16 +1,112 @@
var Device=function();
var Device = function(editorUnit) {
this.deviceTypes = [ "1", "2", "3" ];
Device.prototype.createDevice=function(){
}
Device.prototype.createDeviceEditor = function(header, id, editorUnit) {
var deviceContainer = this.createEditorContainer(header, id, editorUnit);
return deviceContainer;
}
Device.prototype.createEditorContainer = function(header, id, containerInfo) {
var container = document.createElement("div");
if (id != null) {
$(container).attr("id", id);
}
var header = document.createElement("p");
$(header).html(header);
$(container).append(header);
if (containerInfo.paramInfoModels = null) {
this.appendEdtiors($(container), containerInfo.paramTypeModel);
} else {
for ( var i = 0; i < containerInfo.length; i++) {
$(container).append(containerInfo[i].name, null, containerInfo[i]);
}
}
return container;
}
Device.prototype.appendEdtiors = function(container, editorUnit) {
var editorFactory = new EditorFactory();
for ( var key in editorUnit) {
var editorInfo = editorUnit[key];
if (editorInfo.type.toLowerCase() == "field") {
$(container).append(
editorFactory.createField(editorInfo.label,
editorInfo.name, editorInfo.size, editorInfo.name));
} else if (editorInfo.type.toLowerCase() == "nfield") {
$(container).append(
editorFactory.createMultiField(editorInfo.label,
editorInfo.name, editorInfo.size, editorInfo.name));
} else if (editorInfo.type.toLowerCase() == "table") {
$(container).append(
editorFactory.createTable(editorInfo.label,
editorInfo.name, edtiorInfo.cols, editorInfo.name));
} else if (editorInfo.type.toLowerCase() == "file") {
$(container).append(
editorFactory.createFile(editorInfo.lable, editorInfo.name,
editorInfo.size, editorInfo.name));
} else if (editorInfo.type.toLowerCase() == "date") {
$(container).append(
editorFactory.createDate(editorInfo.label, editorInfo.name,
editorInfo.size, editorInfo.name));
} else if (editorInfo.type.toLowerCase() == "select") {
$(container).append(
editorFactory.createSelect(editorInfo.label,
editorInfo.name, ediorInfo.size,
editorInfo.options, editorInfo.name));
} else {
alert("no such editor type:" + editorInfo.type);
}
}
}
Device.prototype.addChildDevice = function() {
}
function dataTransfer(serverData) {
var editorInfos = new Array();
var paramInfos = serverData.paramInfoModels;
var groupInfos = serverData.groupModels;
if (serverData.paramInfoModels != null) {
for ( var i = 0; i < paramInfos.length; i++) {
editorInfos.push(paramInfos[i]);
}
}
if (serverData.groupModels != null) {
for ( var i = 0; i < groupInfos.length; i++) {
editorInfos.push(dataTransfer(groupInfos[i]));
}
}
return editorInfos;
}
$(function() {
var pluginName = "hbase";
var plugin;
var url = "/getPlugin/" + pluginName;
$.get(url, {}, function(data) {
if (data.success) {
var device = new Device();
$("#devices").append(
device.createDeviceEditor("device config", "device-0",
dataTransfer(data.pluginInfo)));
} else {
alert(data.failedMessage);
}
});
});