mirror of https://github.com/tp4a/teleport
支持主机列表和主机运维界面的按主机分组进行过滤了。
parent
30dd82ba12
commit
df5e76c274
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -2,10 +2,6 @@
|
|||
|
||||
$app.on_init = function (cb_stack) {
|
||||
$app.dom = {
|
||||
// assist_ver: $('#tp-assist-ver'),
|
||||
btn_sel_group: $('#btn-sel-group button'),
|
||||
group_list_for_sel: $('#btn-sel-group ul'),
|
||||
|
||||
btn_refresh_host: $('#btn-refresh-host'),
|
||||
btn_add_host: $('#btn-add-host'),
|
||||
chkbox_host_select_all: $('#table-host-select-all'),
|
||||
|
@ -22,36 +18,6 @@ $app.on_init = function (cb_stack) {
|
|||
upload_file_message: $('#upload-file-message')
|
||||
};
|
||||
|
||||
console.log($app.options.host_groups);
|
||||
// var i = 0;
|
||||
// var html = [];
|
||||
// html.push('<optioin value="0">所有分组</optioin>');
|
||||
// html.push('<optioin value="-1">----------</optioin>');
|
||||
// for(i = 0; i < $app.options.host_groups.length; ++i) {
|
||||
// html.push('<optioin value="'+$app.options.host_groups[i].id+'">'+$app.options.host_groups[i].name+'</optioin>');
|
||||
// }
|
||||
// $app.dom.sel_host_group.ap
|
||||
|
||||
var html = [];
|
||||
$.each($app.options.host_groups, function (i, item) {
|
||||
html.push('<li><a href="javascript:;" data-tp-selector="' + item.id + '" data-name="' + item.name + '"><i class="fa fa-caret-right fa-fw"></i> ' + item.name + '</a></li>');
|
||||
});
|
||||
$app.dom.group_list_for_sel.append($(html.join('')));
|
||||
$app.dom.group_list_for_sel.find('a[data-tp-selector]').click(function () {
|
||||
var obj = $(this);
|
||||
//$app.set_selected_to_role(parseInt(obj.attr('data-tp-selector')), obj.attr('data-name'));
|
||||
});
|
||||
|
||||
|
||||
// $tp.assist_checked = function () {
|
||||
// console.log("---------");
|
||||
// if ($tp.assist.running) {
|
||||
// $app.dom.assist_ver.html($tp.assist.version);
|
||||
// } else {
|
||||
// $app.dom.assist_ver.html('<a href="http://teleport.eomsoft.net/download" target="_blank" class="error">未能检测到</a>');
|
||||
// }
|
||||
// };
|
||||
|
||||
cb_stack
|
||||
.add($app.create_controls)
|
||||
.add($app.load_role_list);
|
||||
|
@ -162,6 +128,8 @@ $app.create_controls = function (cb_stack) {
|
|||
// 主机没有“临时锁定”状态,因此要排除掉
|
||||
$tp.create_table_header_filter_state($app.table_host, 'state', $app.obj_states, [TP_STATE_LOCKED]);
|
||||
|
||||
$tp.create_table_filter_group($app.table_host, 'host_group', '#filter-host-group', $app.options.host_groups);
|
||||
|
||||
// 从cookie中读取用户分页限制的选择
|
||||
$tp.create_table_paging($app.table_host, 'table-host-paging',
|
||||
{
|
||||
|
|
|
@ -2,27 +2,14 @@
|
|||
|
||||
$app.on_init = function (cb_stack) {
|
||||
$app.dom = {
|
||||
// assist_ver: $('#tp-assist-ver'),
|
||||
btn_sel_group: $('#btn-sel-group button'),
|
||||
group_list_for_sel: $('#btn-sel-group ul'),
|
||||
|
||||
btn_refresh_host: $('#btn-refresh-host')
|
||||
// box_rdp_option: $('#rdp-options')
|
||||
btn_sel_group: $('#btn-sel-group button')
|
||||
, btn_refresh_host: $('#btn-refresh-host')
|
||||
// , group_list_for_sel: $('#btn-sel-group ul')
|
||||
// , group_selected: $('#group-selected')
|
||||
};
|
||||
|
||||
console.log($app.options);
|
||||
|
||||
var html = [];
|
||||
$.each($app.options.host_groups, function (i, item) {
|
||||
html.push('<li><a href="javascript:;" data-tp-selector="' + item.id + '" data-name="' + item.name + '"><i class="fa fa-caret-right fa-fw"></i> ' + item.name + '</a></li>');
|
||||
});
|
||||
$app.dom.group_list_for_sel.append($(html.join('')));
|
||||
$app.dom.group_list_for_sel.find('a[data-tp-selector]').click(function () {
|
||||
var obj = $(this);
|
||||
//$app.set_selected_to_role(parseInt(obj.attr('data-tp-selector')), obj.attr('data-name'));
|
||||
});
|
||||
|
||||
|
||||
cb_stack
|
||||
.add($app.create_controls)
|
||||
.add($app.load_role_list);
|
||||
|
@ -35,6 +22,13 @@ $app.on_init = function (cb_stack) {
|
|||
//===================================
|
||||
$app.create_controls = function (cb_stack) {
|
||||
|
||||
// var html = [];
|
||||
// $.each($app.options.host_groups, function (i, item) {
|
||||
// html.push('<li><a href="javascript:;" data-tp-selector="' + item.id + '" data-name="' + item.name + '"><i class="fa fa-caret-right fa-fw"></i> ' + item.name + '</a></li>');
|
||||
// });
|
||||
// $app.dom.group_list_for_sel.append($(html.join('')));
|
||||
//
|
||||
|
||||
//-------------------------------
|
||||
// 资产列表表格
|
||||
//-------------------------------
|
||||
|
@ -84,14 +78,16 @@ $app.create_controls = function (cb_stack) {
|
|||
.add($app.table_host.init);
|
||||
|
||||
//-------------------------------
|
||||
// 用户列表相关过滤器
|
||||
// 过滤器
|
||||
//-------------------------------
|
||||
$tp.create_table_header_filter_search($app.table_host, {
|
||||
name: 'search',
|
||||
place_holder: '搜索:主机IP/名称/描述/资产编号/等等...'
|
||||
});
|
||||
|
||||
// 从cookie中读取用户分页限制的选择
|
||||
$tp.create_table_filter_group($app.table_host, 'host_group', '#filter-host-group', $app.options.host_groups);
|
||||
|
||||
// 分页设置
|
||||
$tp.create_table_paging($app.table_host, 'table-host-paging',
|
||||
{
|
||||
per_page: Cookies.get($app.page_id('asset_host') + '_per_page'),
|
||||
|
@ -101,6 +97,24 @@ $app.create_controls = function (cb_stack) {
|
|||
});
|
||||
$tp.create_table_pagination($app.table_host, 'table-host-pagination');
|
||||
|
||||
|
||||
// $app.dom.group_list_for_sel.find('a[data-tp-selector]').click(function () {
|
||||
// var obj = $(this);
|
||||
// //console.log(parseInt(obj.attr('data-tp-selector')));
|
||||
// //$app.set_selected_to_role(parseInt(obj.attr('data-tp-selector')), obj.attr('data-name'));
|
||||
// //$app.dom.group_selected.text(obj.attr('data-name'));
|
||||
//
|
||||
// CALLBACK_STACK.create()
|
||||
// .add(function (cb) {
|
||||
// $app.dom.group_selected.text(obj.attr('data-name'));
|
||||
// cb.exec();
|
||||
// })
|
||||
// .add($app.table_host.load_data)
|
||||
// //.add($app.table_host.reset_filters)
|
||||
// .exec();
|
||||
// });
|
||||
|
||||
|
||||
//-------------------------------
|
||||
// 对话框
|
||||
//-------------------------------
|
||||
|
|
|
@ -1705,3 +1705,60 @@ $tp.create_table_header_filter_state = function (tbl, name, states, exclude_ids)
|
|||
});
|
||||
};
|
||||
};
|
||||
|
||||
$tp.create_table_filter_group = function (tbl, name, dom_id, groups) {
|
||||
var _tblf = {};
|
||||
_tblf._table_ctrl = tbl;
|
||||
_tblf.dom_id = dom_id;
|
||||
_tblf.name = name;
|
||||
_tblf.default_value = -1;
|
||||
_tblf.filter_value = -1;
|
||||
_tblf.groups = groups;
|
||||
|
||||
_tblf._table_ctrl.add_filter_ctrl(_tblf.name, _tblf);
|
||||
|
||||
_tblf.init = function (cb_stack) {
|
||||
var html = [];
|
||||
html.push('<li><a href="javascript:;" data-tp-selector="-1" data-name="所有"><i class="fa fa-caret-right fa-fw"></i> 所有</a></li>');
|
||||
$.each(_tblf.groups, function (i, item) {
|
||||
html.push('<li><a href="javascript:;" data-tp-selector="' + item.id + '" data-name="' + item.name + '"><i class="fa fa-caret-right fa-fw"></i> ' + item.name + '</a></li>');
|
||||
});
|
||||
$(_tblf.dom_id + ' ul').append($(html.join('')));
|
||||
|
||||
|
||||
$(_tblf.dom_id + ' li a[data-tp-selector]').click(function () {
|
||||
var select = parseInt($(this).attr('data-tp-selector'));
|
||||
if (_tblf.filter_value === select)
|
||||
return;
|
||||
_tblf.filter_value = select;
|
||||
|
||||
var name = _tblf._id2name(select);
|
||||
$(_tblf.dom_id + ' span[data-tp-select-result]').text(name);
|
||||
|
||||
// 刷新数据
|
||||
_tblf._table_ctrl.load_data(CALLBACK_STACK.create(), {});
|
||||
});
|
||||
|
||||
|
||||
cb_stack.exec();
|
||||
};
|
||||
|
||||
_tblf.get_filter = function () {
|
||||
var ret = {};
|
||||
ret[_tblf.name] = _tblf.filter_value;
|
||||
return ret;
|
||||
};
|
||||
|
||||
_tblf._id2name = function (id_) {
|
||||
if (id_ === -1)
|
||||
return '所有';
|
||||
// if (id_ === 0)
|
||||
// return '尚未设置';
|
||||
for (var i = 0; i < _tblf.groups.length; ++i) {
|
||||
if (_tblf.groups[i].id === id_)
|
||||
return _tblf.groups[i].name;
|
||||
}
|
||||
console.error('on', _tblf.name, 'filter select, no such id.', id_);
|
||||
return '-未知-';
|
||||
};
|
||||
};
|
||||
|
|
|
@ -288,3 +288,11 @@ label.form-control-static {
|
|||
font-size: @text-size-normal;
|
||||
}
|
||||
}
|
||||
|
||||
.table-extend-cell {
|
||||
.btn-group-sm {
|
||||
.btn {
|
||||
padding: 5px 5px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -224,7 +224,7 @@ body {
|
|||
display: inline-block;
|
||||
padding-right: 8px;
|
||||
line-height: 20px;
|
||||
content: "\f105";
|
||||
content: "\f0da";
|
||||
font-family: 'Font Awesome 5 Free';
|
||||
font-style: normal;
|
||||
font-weight: 900;
|
||||
|
@ -247,7 +247,6 @@ body {
|
|||
&:after {
|
||||
content: "\e251";
|
||||
font-family: 'Glyphicons Halflings';
|
||||
//font-family: "glyphicons-halflings-regular";
|
||||
position: relative;
|
||||
top: -1px;
|
||||
display: inline-block;
|
||||
|
|
|
@ -34,20 +34,13 @@
|
|||
|
||||
<!-- begin box -->
|
||||
<div class="box">
|
||||
|
||||
<p>filter goes here...</p>
|
||||
<div class="btn-group dropdown" id="btn-sel-group">
|
||||
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown"><i class="fa fa-edit fa-fw"></i> 所有分组 <i class="fa fa-caret-right"></i></button>
|
||||
<ul class="dropdown-menu dropdown-menu-sm"></ul>
|
||||
</div>
|
||||
|
||||
|
||||
<hr/>
|
||||
|
||||
<div class="table-prefix-area">
|
||||
<div class="table-extend-cell">
|
||||
<span class="table-name"><i class="fa fa-list fa-fw"></i> 主机列表</span>
|
||||
|
||||
<div class="btn-group btn-group-sm dropdown" id="filter-host-group">
|
||||
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown"><i class="fa fa-filter fa-fw"></i>主机分组:<span data-tp-select-result>所有</span> <i class="fa fa-caret-right"></i></button>
|
||||
<ul class="dropdown-menu dropdown-menu-sm"></ul>
|
||||
</div>
|
||||
<button id="btn-refresh-host" class="btn btn-sm btn-default"><i class="fa fa-redo fa-fw"></i> 刷新列表</button>
|
||||
</div>
|
||||
<div class="table-extend-cell table-extend-cell-right group-actions">
|
||||
|
|
|
@ -6,7 +6,8 @@
|
|||
<%inherit file="../page_base.mako"/>
|
||||
|
||||
<%block name="extend_js_file">
|
||||
## <script type="text/javascript" src="${ static_url('js/tp-assist.js') }"></script>
|
||||
## <script type="text/javascript" src="${ static_url('js/tp-assist.js') }"></script>
|
||||
|
||||
<script type="text/javascript" src="${ static_url('js/ops/remote-list.js') }"></script>
|
||||
</%block>
|
||||
<%block name="embed_js">
|
||||
|
@ -26,40 +27,22 @@
|
|||
|
||||
<!-- begin box -->
|
||||
<div class="box">
|
||||
|
||||
<p>filter goes here...</p>
|
||||
<div class="btn-group dropdown" id="btn-sel-group">
|
||||
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown"><i class="fa fa-edit fa-fw"></i> 所有分组 <i class="fa fa-caret-right"></i></button>
|
||||
<ul class="dropdown-menu dropdown-menu-sm"></ul>
|
||||
</div>
|
||||
|
||||
|
||||
<hr/>
|
||||
|
||||
<div class="table-prefix-area">
|
||||
<div class="table-extend-cell">
|
||||
<span class="table-name"><i class="fa fa-list fa-fw"></i> 主机列表</span>
|
||||
<div class="btn-group btn-group-sm dropdown" id="filter-host-group">
|
||||
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown"><i class="fa fa-filter fa-fw"></i>主机分组:<span data-tp-select-result>所有</span> <i class="fa fa-caret-right"></i></button>
|
||||
<ul class="dropdown-menu dropdown-menu-sm"></ul>
|
||||
</div>
|
||||
<button id="btn-refresh-host" class="btn btn-sm btn-default"><i class="fa fa-redo fa-fw"></i> 刷新列表</button>
|
||||
</div>
|
||||
<div class="table-extend-cell table-extend-cell-right group-actions">
|
||||
## <button id="btn-add-host" class="btn btn-sm btn-primary"><i class="fa fa-plus-circle fa-fw"></i> 添加主机</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<table id="table-host" class="table table-striped table-bordered table-hover table-data no-footer dtr-inline"></table>
|
||||
|
||||
<div class="table-extend-area">
|
||||
## <div class="table-extend-cell checkbox-select-all"><input id="table-host-select-all" type="checkbox"/></div>
|
||||
## <div class="table-extend-cell group-actions">
|
||||
## <div class="btn-group" role="group">
|
||||
## ## <button id="btn-edit-host" type="button" class="btn btn-default"><i class="fa fa-edit fa-fw"></i> 编辑</button>
|
||||
##
|
||||
## <button id="btn-lock-host" type="button" class="btn btn-default"><i class="fa fa-lock fa-fw"></i> 禁用</button>
|
||||
## <button id="btn-unlock-host" type="button" class="btn btn-default"><i class="fa fa-unlock fa-fw"></i> 解禁</button>
|
||||
## <button id="btn-remove-host" type="button" class="btn btn-default"><i class="fa fa-times-circle fa-fw"></i> 删除</button>
|
||||
## </div>
|
||||
## </div>
|
||||
|
||||
<div class="table-extend-cell table-item-counter">
|
||||
<ol id="table-host-paging"></ol>
|
||||
</div>
|
||||
|
|
|
@ -72,6 +72,10 @@ class DoGetHostsHandler(TPBaseJsonHandler):
|
|||
if len(_x) == 0:
|
||||
tmp.append(i)
|
||||
continue
|
||||
elif i == 'host_group':
|
||||
if _filter[i] == -1:
|
||||
tmp.append(i)
|
||||
continue
|
||||
|
||||
for i in tmp:
|
||||
del _filter[i]
|
||||
|
|
|
@ -715,6 +715,11 @@ class DoGetRemotesHandler(TPBaseJsonHandler):
|
|||
if i == '_name':
|
||||
if len(_filter[i].strip()) == 0:
|
||||
tmp.append(i)
|
||||
continue
|
||||
elif i == 'host_group':
|
||||
if _filter[i] == -1:
|
||||
tmp.append(i)
|
||||
continue
|
||||
|
||||
for i in tmp:
|
||||
del _filter[i]
|
||||
|
|
|
@ -55,6 +55,17 @@ def get_hosts(sql_filter, sql_order, sql_limit, sql_restrict, sql_exclude):
|
|||
_where.append('h.state={}'.format(sql_filter[k]))
|
||||
elif k == 'search':
|
||||
_where.append('(h.name LIKE "%{filter}%" OR h.ip LIKE "%{filter}%" OR h.router_ip LIKE "%{filter}%" OR h.desc LIKE "%{filter}%" OR h.cid LIKE "%{filter}%")'.format(filter=sql_filter[k]))
|
||||
elif k == 'host_group':
|
||||
shg = SQL(get_db())
|
||||
shg.select_from('group_map', ['mid'], alt_name='g')
|
||||
shg.where('g.type={} AND g.gid={}'.format(TP_GROUP_HOST, sql_filter[k]))
|
||||
err = shg.query()
|
||||
if err != TPE_OK:
|
||||
return err, 0, 1, []
|
||||
if len(shg.recorder) == 0:
|
||||
return TPE_OK, 0, 1, []
|
||||
h_list = ','.join([str(i['mid']) for i in shg.recorder])
|
||||
_where.append('h.id IN ({})'.format(h_list))
|
||||
|
||||
if len(_where) > 0:
|
||||
str_where = '( {} )'.format(' AND '.join(_where))
|
||||
|
|
|
@ -495,6 +495,17 @@ def get_all_remotes(handler, sql_filter, sql_order, sql_limit):
|
|||
_where.append('h.state={}'.format(sql_filter[k]))
|
||||
elif k == 'search':
|
||||
_where.append('(h.name LIKE "%{k}%" OR h.ip LIKE "%{k}%" OR h.router_ip LIKE "%{k}%")'.format(k=sql_filter[k]))
|
||||
elif k == 'host_group':
|
||||
shg = SQL(get_db())
|
||||
shg.select_from('group_map', ['mid'], alt_name='g')
|
||||
shg.where('g.type={} AND g.gid={}'.format(TP_GROUP_HOST, sql_filter[k]))
|
||||
err = shg.query()
|
||||
if err != TPE_OK:
|
||||
return err, 0, 1, []
|
||||
if len(shg.recorder) == 0:
|
||||
return TPE_OK, 0, 1, []
|
||||
h_list = ','.join([str(i['mid']) for i in shg.recorder])
|
||||
_where.append('h.id IN ({})'.format(h_list))
|
||||
|
||||
if len(_where) > 0:
|
||||
str_where = '( {} )'.format(' AND '.join(_where))
|
||||
|
@ -599,10 +610,35 @@ def get_remotes(handler, sql_filter, sql_order, sql_limit):
|
|||
######################################################
|
||||
# step 3.
|
||||
######################################################
|
||||
_where = list()
|
||||
if len(sql_filter) > 0:
|
||||
for k in sql_filter:
|
||||
# if k == 'state':
|
||||
# _where.append('h.state={}'.format(sql_filter[k]))
|
||||
# elif k == 'search':
|
||||
# _where.append('(h.name LIKE "%{k}%" OR h.ip LIKE "%{k}%" OR h.router_ip LIKE "%{k}%")'.format(k=sql_filter[k]))
|
||||
# el
|
||||
if k == 'host_group':
|
||||
shg = SQL(get_db())
|
||||
shg.select_from('group_map', ['mid'], alt_name='g')
|
||||
shg.where('g.type={} AND g.gid={}'.format(TP_GROUP_HOST, sql_filter[k]))
|
||||
err = shg.query()
|
||||
if err != TPE_OK:
|
||||
return err, 0, 1, []
|
||||
if len(shg.recorder) == 0:
|
||||
return TPE_NOT_EXISTS, 0, 1, []
|
||||
h_list = ','.join([str(i['mid']) for i in shg.recorder])
|
||||
_where.append('h_id IN ({})'.format(h_list))
|
||||
|
||||
str_where = ''
|
||||
if len(_where) > 0:
|
||||
str_where = 'WHERE ( {} )'.format(' AND '.join(_where))
|
||||
|
||||
sql = []
|
||||
sql.append('SELECT {}'.format(','.join(_f)))
|
||||
sql.append('FROM')
|
||||
sql.append('({}) AS s2'.format(sql_2))
|
||||
sql.append(str_where)
|
||||
sql.append('GROUP BY h_id')
|
||||
sql.append('ORDER BY ip')
|
||||
sql.append('LIMIT {},{}'.format(sql_limit['page_index'] * sql_limit['per_page'], sql_limit['per_page']))
|
||||
|
@ -612,6 +648,7 @@ def get_remotes(handler, sql_filter, sql_order, sql_limit):
|
|||
sql_counter.append('SELECT COUNT(*)')
|
||||
sql_counter.append('FROM')
|
||||
sql_counter.append('({}) AS s3'.format(sql_2))
|
||||
sql_counter.append(str_where)
|
||||
sql_counter.append('GROUP BY h_id')
|
||||
sql_counter.append(';')
|
||||
|
||||
|
|
Loading…
Reference in New Issue