monitor_add_single.html
14.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
<html>
<head>
<script th:inline="javascript">
$(function () {
formGroupValidator();
$("#form-sequence").bootstrapValidator({
live: 'enabled',//验证时机,enabled是内容有变化就验证(默认),disabled和submitted是提交再验证
excluded: [':disabled', ':hidden', ':not(:visible)'],//排除无需验证的控件,比如被禁用的或者被隐藏的
//submitButtons: '#btn-submit-sequence',//指定提交按钮,如果验证失败则变成disabled,但我没试成功,反而加了这句话非submit按钮也会提交到action指定页面
message: '通用的验证失败消息',//好像从来没出现过
feedbackIcons: {//根据验证结果显示的各种图标
valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
fields: {
group: {validators: {notEmpty: {message: '所属系统不能为空'}}},
name: {validators: {notEmpty: {message: '监控名称不能为空'}}},
url: {validators: {notEmpty: {message: 'API地址不能为空'},regexp:{regexp:/^(http|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?/,message:'API地址必须使用 http://或https://开始'}}}
}
});
$('#modal-default1').on('hidden.bs.modal', function () {
$("#systemName").val("");
$("#form-group").data('bootstrapValidator').destroy();
$('#form-group').data('bootstrapValidator', null);
formGroupValidator();
});
$("#btn-submit-group").click(function () {//非submit按钮点击后进行验证,如果是submit则无需此句直接验证
$("#form-group").bootstrapValidator('validate');//提交验证
if ($("#form-group").data('bootstrapValidator').isValid()) {//获取验证结果,如果成功,执行下面代码
var params = $("#form-group").serialize();
var systemName = $("#systemName").val();
$.ajax( {
type : "POST",
url : "/addGroup",
data : params,
success : function(msg) {
if(msg){
$('#modal-default1').modal('hide');
loadGroup(systemName);
}else{
alert("保存失败,请检查该系统名称是否已经存在 !");
}
} ,
error:function(){
alert("请求失败!");
}
});
}
});
$("#btn-submit-sequence").click(function () {//非submit按钮点击后进行验证,如果是submit则无需此句直接验证
$("#form-sequence").bootstrapValidator('validate');//提交验证
if ($("#form-sequence").data('bootstrapValidator').isValid()) {//获取验证结果,如果成功,执行下面代码
var params = $("#form-sequence").serialize();
$.ajax( {
type : "POST",
url : "/saveSingleMonitor",
data : params,
success : function(msg) {
if(msg){
alert("保存成功 !");
window.location.href="/";
}else{
alert("保存失败 !");
}
},
error:function(){
alert("请求失败!");
}
});
}
});
var vgroup = [[${form.group}]];
var vhttpMethod = [[${form.httpMethod}+'']];
var vfrequency = [[${form.frequency}+'']];
var vconditionType = [[${form.conditionType}+'']];
loadGroup(vgroup);
$(":radio[name='httpMethod'][value='" + vhttpMethod + "']").prop("checked", "checked");
$(":radio[name='frequency'][value='" + vfrequency + "']").prop("checked", "checked");
$("select[name='conditionType'] option[value='"+vconditionType+"']").attr("selected", "selected");
});
function formGroupValidator(){
$("#form-group").bootstrapValidator({
live: 'enabled',//验证时机,enabled是内容有变化就验证(默认),disabled和submitted是提交再验证
feedbackIcons: {//根据验证结果显示的各种图标
valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
fields: {
systemName: {
validators: {
notEmpty: {//检测非空,radio也可用
message: '系统名称不能为空'
}
}
}
}
});
}
function loadGroup(selected){
$.ajax({
url : "/getGroups" , //获取数据列
type : 'GET',
data : {},
success : function(data) {
var html = "";
$.each(data,function(n,value) {
if(value.name == selected){
html += '<option selected = "selected" value="'+ value.name +'">' + value.name + '</option>';
}else{
html += '<option value="'+ value.name +'">' + value.name + '</option>';
}
});
$("select[name='group']").empty();
$("select[name='group']").append(html);
$("select[name='group']").trigger("change");
}
});
}
</script>
</head>
<body>
<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
<!-- Content Header (Page header) -->
<section class="content-header">
<h1 th:if="${form.guid} eq null">添加监控<small>API监控</small></h1>
<h1 th:if="${form.guid} ne null">配置监控<small>API监控</small></h1>
<ol class="breadcrumb">
<li><a href="#"><i class="fa fa-dashboard"></i> 主页</a></li>
<li><a href="/monitorList">API监控</a></li>
<li th:if="${form.guid} eq null" class="active">添加监控</li>
<li th:if="${form.guid} ne null" class="active">配置监控</li>
</ol>
</section>
<!-- Main content -->
<section class="content">
<div class="row">
<div class="col-xs-12">
<div class="box box-primary">
<div class="box-header with-border">
<h3 class="box-title">单API</h3>
</div>
<!-- /.box-header -->
<!-- form start -->
<form class="form-horizontal" id="form-sequence" th:object="${form}">
<input name="type" type="hidden" value="SINGLE" />
<input name="guid" type="hidden" th:value="*{guid}" />
<input name="pguid" type="hidden" th:value="*{pguid}" />
<div class="box-body">
<!-- select -->
<div class="form-group">
<label for="group" class="col-sm-2 control-label">所属系统<span style="color:red;"> *</span></label>
<div class="col-sm-8">
<select class="form-control" name="group">
</select>
</div>
<div class="col-sm-1">
<button type="button" class="btn btn-default" data-toggle="modal" data-target="#modal-default1"><i class="fa fa-plus"></i></button>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">监控名称<span style="color:red;"> *</span></label>
<div class="col-sm-8">
<input type="text" class="form-control" id="name" name="name" th:value="*{name}" />
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">API类型<span style="color:red;"> *</span></label>
<div class="col-sm-8 radio">
<label>
<input type="radio" name="httpMethod" id="httpMethod1" value="GET" checked="checked" />GET
</label>
<label>
<input type="radio" name="httpMethod" id="httpMethod2" value="POST" />POST
</label>
<label>
<input type="radio" name="httpMethod" id="httpMethod3" value="HEAD" />HEAD
</label>
<label>
<input type="radio" name="httpMethod" id="httpMethod4" value="PUT" />PUT
</label>
<label>
<input type="radio" name="httpMethod" id="httpMethod5" value="DELETE" />DELETE
</label>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">API地址<span style="color:red;"> *</span></label>
<div class="col-sm-8">
<input type="text" class="form-control" name="url" th:value="*{url}"/>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">监控频率<span style="color:red;"> *</span></label>
<div class="col-sm-8 radio">
<label>
<input type="radio" name="frequency" id="frequency1" value="THIRTY" checked="checked" />30秒
</label>
<label>
<input type="radio" name="frequency" id="frequency2" value="SIXTY" />1分钟
</label>
<label>
<input type="radio" name="frequency" id="frequency3" value="FIVE_MINUTES" />5分钟
</label>
<label>
<input type="radio" name="frequency" id="frequency4" value="TEN_MINUTES" />10分钟
</label>
<label>
<input type="radio" name="frequency" id="frequency5" value="THIRTY_MINUTES" />30分钟
</label>
<label>
<input type="radio" name="frequency" id="frequency6" value="ONE_HOUR" />1小时
</label>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">请求头部</label>
<div class="col-sm-8">
<textarea name="headers" class="form-control" rows="3" placeholder="头部key::头部value 头部key::头部value" th:text="*{headers}"></textarea>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">请求参数</label>
<div class="col-sm-8">
<textarea name="parameters" class="form-control" rows="3" placeholder="参数key::参数value 参数key::参数value" th:text="*{parameters}"></textarea>
</div>
</div>
<!-- <div class="form-group">
<label for="maxConnectionSeconds" class="col-sm-2 control-label">最大超时时间</label>
<div class="col-sm-8">
<input type="text" class="form-control" name="maxConnectionSeconds" />
</div>
</div> -->
<div class="form-group">
<label class="col-sm-2 control-label">结果校验</label>
<div class="col-sm-2">
<select class="form-control" name="conditionType">
<option value="DEFAULT"></option>
<option value="STATUSCODE">响应码</option>
<option value="CONTAINS">内容包含</option>
<option value="DOESNT_CONTAIN">内容不包含</option>
</select>
</div>
<div class="col-sm-6">
<input type="text" class="form-control" name="condition" th:value="*{condition}"/>
</div>
</div>
<!-- <div class="form-group">
<label class="col-sm-2 control-label">结果提取</label>
<div class="col-sm-8 radio">
<label>
<input type="radio" name="resultType" id="resultType1" value="XML" />xPath
</label>
<label>
<input type="radio" name="resultType" id="resultType2" value="JSON" />jsonPath
</label>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-8">
<textarea name="variables" class="form-control" rows="3" placeholder="$$变量名::xPath路径 $$变量名::xPath路径"></textarea>
</div>
</div> -->
<!-- textarea -->
<div class="form-group">
<label class="col-sm-2 control-label">备注</label>
<div class="col-sm-8">
<textarea name="remark" class="form-control" rows="3" th:text="*{remark}"></textarea>
</div>
</div>
</div>
<!-- /.box-body -->
<div class="box-footer">
<a class="btn btn-default" href="/monitorList">返回</a>
<button id="btn-submit-sequence" class="btn btn-info pull-right">提交</button>
</div>
<!-- /.box-footer -->
</form>
</div>
</div>
</div>
<div class="modal fade" id="modal-default1">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span></button>
<h4 class="modal-title">添加系统</h4>
</div>
<div class="modal-body">
<form class="form-horizontal" id="form-group">
<div class="box-body">
<div class="form-group">
<label for="systemName" class="col-sm-2 control-label">系统名称<span style="color:red;"> *</span></label>
<div class="col-sm-9">
<input type="text" class="form-control" name="systemName" id="systemName" />
</div>
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default pull-left" data-dismiss="modal">关闭</button>
<button type="button" class="btn btn-primary" id="btn-submit-group">保存</button>
</div>
</div>
<!-- /.modal-content -->
</div>
<!-- /.modal-dialog -->
</div>
<!-- /.modal -->
</section>
</div>
<!-- /.content-wrapper -->
</body>
</html>