mirror of https://github.com/tp4a/teleport
主机运维页面支持模糊搜索了。
parent
df5e76c274
commit
55e049d0e3
|
@ -40,12 +40,21 @@ $app.create_controls = function (cb_stack) {
|
|||
},
|
||||
column_default: {sort: false, align: 'left'},
|
||||
columns: [
|
||||
{
|
||||
title: '<a href="javascript:;" data-reset-filter><i class="fa fa-undo fa-fw"></i></a>',
|
||||
key: 'chkbox',
|
||||
sort: false,
|
||||
width: 36,
|
||||
align: 'center',
|
||||
render: 'make_check_box',
|
||||
fields: {id: 'id'}
|
||||
},
|
||||
{
|
||||
title: '主机',
|
||||
key: 'host',
|
||||
// sort: true,
|
||||
// header_render: 'filter_search',
|
||||
width: 300,
|
||||
header_render: 'filter_search',
|
||||
width: 320,
|
||||
render: 'host_info',
|
||||
fields: {ip: 'ip', router_ip: 'router_ip', router_port: 'router_port', h_name: 'h_name'}
|
||||
},
|
||||
|
@ -97,24 +106,6 @@ $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();
|
||||
// });
|
||||
|
||||
|
||||
//-------------------------------
|
||||
// 对话框
|
||||
//-------------------------------
|
||||
|
@ -142,9 +133,6 @@ $app.on_table_host_cell_created = function (tbl, row_id, col_key, cell_obj) {
|
|||
var acc_id = parseInt($(this).attr('data-acc-id'));
|
||||
var host_id = parseInt($(this).attr('data-host-id'));
|
||||
|
||||
// var policy = $app.table_policy.get_row(row_id);
|
||||
|
||||
|
||||
if (action === 'rdp') {
|
||||
$app.connect_remote(uni_id, acc_id, host_id, TP_PROTOCOL_TYPE_RDP, TP_PROTOCOL_TYPE_RDP_DESKTOP);
|
||||
} else if (action === 'rdp-option') {
|
||||
|
|
|
@ -712,7 +712,7 @@ class DoGetRemotesHandler(TPBaseJsonHandler):
|
|||
# if i == 'user_id' and _filter[i] == 0:
|
||||
# tmp.append(i)
|
||||
# continue
|
||||
if i == '_name':
|
||||
if i == 'search':
|
||||
if len(_filter[i].strip()) == 0:
|
||||
tmp.append(i)
|
||||
continue
|
||||
|
|
|
@ -615,10 +615,19 @@ def get_remotes(handler, sql_filter, sql_order, sql_limit):
|
|||
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':
|
||||
if k == 'search':
|
||||
ss = SQL(get_db())
|
||||
ss.select_from('host', ['id'], alt_name='h')
|
||||
ss.where('(h.name LIKE "%{k}%" OR h.ip LIKE "%{k}%" OR h.router_ip LIKE "%{k}%")'.format(k=sql_filter[k]))
|
||||
err = ss.query()
|
||||
if err != TPE_OK:
|
||||
return err, 0, 1, []
|
||||
if len(ss.recorder) == 0:
|
||||
return TPE_OK, 0, 1, []
|
||||
h_list = ','.join([str(i['id']) for i in ss.recorder])
|
||||
_where.append('(h_id IN ({}))'.format(h_list))
|
||||
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]))
|
||||
|
@ -628,22 +637,12 @@ def get_remotes(handler, sql_filter, sql_order, sql_limit):
|
|||
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))
|
||||
_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']))
|
||||
sql.append(';')
|
||||
|
||||
sql_counter = []
|
||||
sql_counter.append('SELECT COUNT(*)')
|
||||
sql_counter.append('FROM')
|
||||
|
@ -657,6 +656,21 @@ def get_remotes(handler, sql_filter, sql_order, sql_limit):
|
|||
return TPE_OK, 0, 1, []
|
||||
|
||||
total = len(db_ret)
|
||||
if total == 0:
|
||||
return TPE_OK, 0, 1, []
|
||||
|
||||
if total < sql_limit['page_index'] * sql_limit['per_page']:
|
||||
sql_limit['page_index'] = 0
|
||||
|
||||
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']))
|
||||
sql.append(';')
|
||||
|
||||
ret_recorder = [] # 用于构建最终返回的数据
|
||||
h_ids = [] # 涉及到的主机的ID列表
|
||||
|
|
Loading…
Reference in New Issue