Commit 22a082e1 authored by ibuler's avatar ibuler

[Update] Luna支持异步加载ztree

parent 38579112
#!/usr/bin/env python3 #!/usr/bin/env python3
# coding: utf-8
import eventlet import eventlet
...@@ -40,7 +41,7 @@ app = Flask(__name__, template_folder='dist') ...@@ -40,7 +41,7 @@ app = Flask(__name__, template_folder='dist')
socketio = None socketio = None
nodes = '[{"id":"03059e2e-06b8-4ef1-b949-72e230b706fa","key":"0:9:5","name":"部门1","value":"部门1","parent":"ea4688ef-2b65-40cd-944d-5fca39e34f42","assets_granted":[{"id":"ad594b10-9f64-4913-b7b1-135fe63561d1","hostname":"ali-windows","ip":"47.104.243.139","port":3389,"system_users_granted":[{"id":"8763b81a-bb5e-484a-abca-10514c7bb185","name":"组织1-部门1-Administrator","username":"administrator","priority":10,"protocol":"rdp","comment":"windows 服务器而已"}],"is_active":true,"system_users_join":"administrator","os":null,"domain":null,"platform":"Windows","comment":"只是个windows而已"},{"id":"d9020939-1dd7-4b18-9165-5124f20d1f77","hostname":"newwindows","ip":"10.1.10.114","port":3389,"system_users_granted":[{"id":"46b57293-c662-46f9-8bc4-dcf64f01bedc","name":"newwindows","username":"administrator","priority":10,"protocol":"rdp","comment":"只是个windows而已"},{"id":"8763b81a-bb5e-484a-abca-10514c7bb185","name":"组织1-部门1-Administrator","username":"administrator","priority":10,"protocol":"rdp","comment":"只是个windows而已"}],"is_active":true,"system_users_join":"administrator, administrator","os":null,"domain":null,"platform":"Windows","comment":"只是个windows而已"},{"id":"9ef36bb3-1bed-455f-be09-3770d3f4bf97","hostname":"test-vm1","ip":"172.19.185.6","port":22,"system_users_granted":[{"id":"7e326f71-aee5-4688-8cc1-717919470a09","name":"root","username":"root","priority":10,"protocol":"ssh","comment":"只是个windows而已"}],"is_active":true,"system_users_join":"root","os":null,"domain":null,"platform":"Linux","comment":"只是个windows而已"},{"id":"1600ed6d-e3b6-434c-a960-c5bb818806b6","hostname":"windows1","ip":"10.1.10.178","port":3389,"system_users_granted":[{"id":"413ea1d2-ef73-4a90-bae3-571ac1b39d93","name":"2012-test-no-passwd-rdp","username":"administrator","priority":10,"protocol":"rdp","comment":"只是个windows而已"},{"id":"46b57293-c662-46f9-8bc4-dcf64f01bedc","name":"newwindows","username":"administrator","priority":10,"protocol":"rdp","comment":"只是个windows而已"},{"id":"8763b81a-bb5e-484a-abca-10514c7bb185","name":"组织1-部门1-Administrator","username":"administrator","priority":10,"protocol":"rdp","comment":"只是个windows而已"}],"is_active":true,"system_users_join":"administrator, administrator, administrator","os":null,"domain":null,"platform":"Windows","comment":"只是个windows而已"},{"id":"27e50edc-52d9-41ef-8c9e-1bff9d1628b2","hostname":"test-vm2","ip":"172.19.185.7","port":22,"system_users_granted":[{"id":"7e326f71-aee5-4688-8cc1-717919470a09","name":"root","username":"root","priority":10,"protocol":"ssh","comment":"只是个windows而已"}],"is_active":true,"system_users_join":"root","os":null,"domain":null,"platform":"Linux","comment":"只是个windows而已"},{"id":"b6f16269-d02a-4055-9cd8-460fa10b1540","hostname":"test-vm3","ip":"172.19.185.8","port":22,"system_users_granted":[{"id":"7e326f71-aee5-4688-8cc1-717919470a09","name":"root","username":"root","priority":10,"protocol":"ssh","comment":"只是个windows而已"}],"is_active":true,"system_users_join":"root","os":null,"domain":null,"platform":"Linux","comment":"只是个windows而已"},{"id":"b952a481-a624-467e-b97f-9435155f0d53","hostname":"testserver","ip":"10.1.10.192","port":22,"system_users_granted":[{"id":"7e326f71-aee5-4688-8cc1-717919470a09","name":"root","username":"root","priority":10,"protocol":"ssh","comment":"只是个windows而已"}],"is_active":true,"system_users_join":"root","os":"CentOS","domain":"8789580f-b5ca-4478-b6d3-d0dafc4c48e8","platform":"Linux","comment":"只是个windows而已"},{"id":"969247e0-3796-4090-9aa6-3248560079e6","hostname":"test01","ip":"123.123.123.1","port":22,"system_users_granted":[{"id":"7e326f71-aee5-4688-8cc1-717919470a09","name":"root","username":"root","priority":10,"protocol":"ssh","comment":"只是个windows而已"}],"is_active":true,"system_users_join":"root","os":null,"domain":null,"platform":"Linux","comment":"只是个windows而已"},{"id":"7e8451cb-8eb7-4c9d-b652-961a6fdce3c4","hostname":"wz-test","ip":"54.222.180.235","port":22,"system_users_granted":[{"id":"7e326f71-aee5-4688-8cc1-717919470a09","name":"root","username":"root","priority":10,"protocol":"ssh","comment":"只是个windows而已"}],"is_active":true,"system_users_join":"root","os":"RedHat","domain":null,"platform":"Linux","comment":"只是个windows而已"}],"assets_amount":9}]' nodes = [{"id":"03059e2e-06b8-4ef1-b949-72e230b706fa","key":"0:9:5","name":"部门1","value":"部门1","parent":"ea4688ef-2b65-40cd-944d-5fca39e34f42","assets_granted":[{"id":"ad594b10-9f64-4913-b7b1-135fe63561d1","hostname":"ali-windows","ip":"47.104.243.139","port":3389,"system_users_granted":[{"id":"8763b81a-bb5e-484a-abca-10514c7bb185","name":"组织1-部门1-Administrator","username":"administrator","priority":10,"protocol":"rdp","comment":"windows 服务器而已"}],"is_active":True,"system_users_join":"administrator","os":None,"domain":None,"platform":"Windows","comment":"只是个windows而已"},{"id":"d9020939-1dd7-4b18-9165-5124f20d1f77","hostname":"newwindows","ip":"10.1.10.114","port":3389,"system_users_granted":[{"id":"46b57293-c662-46f9-8bc4-dcf64f01bedc","name":"newwindows","username":"administrator","priority":10,"protocol":"rdp","comment":"只是个windows而已"},{"id":"8763b81a-bb5e-484a-abca-10514c7bb185","name":"组织1-部门1-Administrator","username":"administrator","priority":10,"protocol":"rdp","comment":"只是个windows而已"}],"is_active":True,"system_users_join":"administrator, administrator","os":None,"domain":None,"platform":"Windows","comment":"只是个windows而已"},{"id":"9ef36bb3-1bed-455f-be09-3770d3f4bf97","hostname":"test-vm1","ip":"172.19.185.6","port":22,"system_users_granted":[{"id":"7e326f71-aee5-4688-8cc1-717919470a09","name":"root","username":"root","priority":10,"protocol":"ssh","comment":"只是个windows而已"}],"is_active":True,"system_users_join":"root","os":None,"domain":None,"platform":"Linux","comment":"只是个windows而已"},{"id":"1600ed6d-e3b6-434c-a960-c5bb818806b6","hostname":"windows1","ip":"10.1.10.178","port":3389,"system_users_granted":[{"id":"413ea1d2-ef73-4a90-bae3-571ac1b39d93","name":"2012-test-no-passwd-rdp","username":"administrator","priority":10,"protocol":"rdp","comment":"只是个windows而已"},{"id":"46b57293-c662-46f9-8bc4-dcf64f01bedc","name":"newwindows","username":"administrator","priority":10,"protocol":"rdp","comment":"只是个windows而已"},{"id":"8763b81a-bb5e-484a-abca-10514c7bb185","name":"组织1-部门1-Administrator","username":"administrator","priority":10,"protocol":"rdp","comment":"只是个windows而已"}],"is_active":True,"system_users_join":"administrator, administrator, administrator","os":None,"domain":None,"platform":"Windows","comment":"只是个windows而已"},{"id":"27e50edc-52d9-41ef-8c9e-1bff9d1628b2","hostname":"test-vm2","ip":"172.19.185.7","port":22,"system_users_granted":[{"id":"7e326f71-aee5-4688-8cc1-717919470a09","name":"root","username":"root","priority":10,"protocol":"ssh","comment":"只是个windows而已"}],"is_active":True,"system_users_join":"root","os":None,"domain":None,"platform":"Linux","comment":"只是个windows而已"},{"id":"b6f16269-d02a-4055-9cd8-460fa10b1540","hostname":"test-vm3","ip":"172.19.185.8","port":22,"system_users_granted":[{"id":"7e326f71-aee5-4688-8cc1-717919470a09","name":"root","username":"root","priority":10,"protocol":"ssh","comment":"只是个windows而已"}],"is_active":True,"system_users_join":"root","os":None,"domain":None,"platform":"Linux","comment":"只是个windows而已"},{"id":"b952a481-a624-467e-b97f-9435155f0d53","hostname":"testserver","ip":"10.1.10.192","port":22,"system_users_granted":[{"id":"7e326f71-aee5-4688-8cc1-717919470a09","name":"root","username":"root","priority":10,"protocol":"ssh","comment":"只是个windows而已"}],"is_active":True,"system_users_join":"root","os":"CentOS","domain":"8789580f-b5ca-4478-b6d3-d0dafc4c48e8","platform":"Linux","comment":"只是个windows而已"},{"id":"969247e0-3796-4090-9aa6-3248560079e6","hostname":"test01","ip":"123.123.123.1","port":22,"system_users_granted":[{"id":"7e326f71-aee5-4688-8cc1-717919470a09","name":"root","username":"root","priority":10,"protocol":"ssh","comment":"只是个windows而已"}],"is_active":True,"system_users_join":"root","os":None,"domain":None,"platform":"Linux","comment":"只是个windows而已"},{"id":"7e8451cb-8eb7-4c9d-b652-961a6fdce3c4","hostname":"wz-test","ip":"54.222.180.235","port":22,"system_users_granted":[{"id":"7e326f71-aee5-4688-8cc1-717919470a09","name":"root","username":"root","priority":10,"protocol":"ssh","comment":"只是个windows而已"}],"is_active":True,"system_users_join":"root","os":"RedHat","domain":None,"platform":"Linux","comment":"只是个windows而已"}],"assets_amount":9}]
class ProxyServer: class ProxyServer:
...@@ -142,8 +143,8 @@ def send_js(path): ...@@ -142,8 +143,8 @@ def send_js(path):
@app.route('/api/perms/v1/user/nodes-assets/') @app.route('/api/perms/v1/user/nodes-assets/')
def asset_groups_assets(): def asset_groups_assets():
node = json.loads(nodes) # node = json.loads(nodes)
return jsonify(node) return jsonify([])
@app.route('/api/terminal/v1/sessions/test/replay/') @app.route('/api/terminal/v1/sessions/test/replay/')
...@@ -166,6 +167,784 @@ def get_session_replay(pk): ...@@ -166,6 +167,784 @@ def get_session_replay(pk):
}) })
@app.route('/api/perms/v1/user/nodes/children/')
def get_nodes_children():
data1 = [
{
"id": "3e1930e1-759d-430e-8935-fbd563463373",
"key": "0:3",
"value": "Node 2",
"system_users_granted": [],
"is_node": True,
"org_id": "",
"tree_id": "0:3",
"tree_parent": "0",
"assets_amount": 9
},
{
"id": "508e8674-0c51-471c-98b5-13f0612c6aba",
"key": "0",
"value": "ROOT",
"system_users_granted": [],
"is_node": True,
"org_id": "",
"tree_id": "0",
"tree_parent": "",
"assets_amount": 9
},
{
"id": "52b8aa5e-5e5e-4721-a749-2f4f4655ae35",
"key": "0:0",
"value": "新节点 1",
"system_users_granted": [],
"is_node": True,
"org_id": "",
"tree_id": "0:0",
"tree_parent": "0",
"assets_amount": 9
},
{
"id": "5904ae0e-bf06-447d-a963-c89369295d5a",
"key": "0:4",
"value": "Node 4",
"system_users_granted": [],
"is_node": True,
"org_id": "",
"tree_id": "0:4",
"tree_parent": "0",
"assets_amount": 9
},
{
"id": "60daaa36-92ac-4d0f-b59e-f7f153ecc302",
"key": "0:1",
"value": "新节点 2",
"system_users_granted": [],
"is_node": True,
"org_id": "",
"tree_id": "0:1",
"tree_parent": "0",
"assets_amount": 9
},
{
"id": "8e8999f3-9093-4218-af12-cc126a15cb94",
"key": "0:5",
"value": "Node 5",
"system_users_granted": [],
"is_node": True,
"org_id": "",
"tree_id": "0:5",
"tree_parent": "0",
"assets_amount": 9
},
{
"id": "a5a2d42e-7b6d-4e45-905a-74a0bd8c2266",
"key": "0:7",
"value": "Node 37",
"system_users_granted": [],
"is_node": True,
"org_id": "",
"tree_id": "0:7",
"tree_parent": "0",
"assets_amount": 9
},
{
"id": "b8dd922e-fac0-4f15-b70a-01263203002d",
"key": "0:2",
"value": "Node 0",
"system_users_granted": [],
"is_node": True,
"org_id": "",
"tree_id": "0:2",
"tree_parent": "0",
"assets_amount": 9
},
{
"id": "e16c04d3-84a5-4b6d-8f10-ccb195729035",
"key": "0:6",
"value": "Node 15",
"system_users_granted": [],
"is_node": True,
"org_id": "",
"tree_id": "0:6",
"tree_parent": "0",
"assets_amount": 9
},
{
"id": "051142d0-9090-44f7-aa9d-d8a563cc04d4",
"key": "0:0",
"value": "lillian64",
"system_users_granted": [
{
"id": "f78cfcb2-d473-43b6-a72a-8cc18979aabd",
"name": "web",
"username": "web"
}
],
"is_node": False,
"org_id": "",
"tree_id": "0:0",
"tree_parent": "0",
"assets_amount": 0
},
{
"id": "12a542c1-f787-485e-ac46-de6421c93d2d",
"key": "0:0",
"value": "sandra76",
"system_users_granted": [
{
"id": "f78cfcb2-d473-43b6-a72a-8cc18979aabd",
"name": "web",
"username": "web"
}
],
"is_node": False,
"org_id": "",
"tree_id": "0:0",
"tree_parent": "0",
"assets_amount": 0
},
{
"id": "2cba1640-6e7e-470a-9da7-2f736b4d0aa5",
"key": "0:0",
"value": "wanda88",
"system_users_granted": [
{
"id": "f78cfcb2-d473-43b6-a72a-8cc18979aabd",
"name": "web",
"username": "web"
}
],
"is_node": False,
"org_id": "",
"tree_id": "0:0",
"tree_parent": "0",
"assets_amount": 0
},
{
"id": "58839e9c-5649-4e00-8e77-073b800091ff",
"key": "0:0",
"value": "mildred87",
"system_users_granted": [
{
"id": "f78cfcb2-d473-43b6-a72a-8cc18979aabd",
"name": "web",
"username": "web"
}
],
"is_node": False,
"org_id": "",
"tree_id": "0:0",
"tree_parent": "0",
"assets_amount": 0
},
{
"id": "64ce5de9-18df-40a8-b663-8c6515e37e42",
"key": "0:0",
"value": "jessica82",
"system_users_granted": [
{
"id": "f78cfcb2-d473-43b6-a72a-8cc18979aabd",
"name": "web",
"username": "web"
}
],
"is_node": False,
"org_id": "",
"tree_id": "0:0",
"tree_parent": "0",
"assets_amount": 0
},
{
"id": "72e26e8c-2146-49ad-8803-1c95e47d4447",
"key": "0:0",
"value": "paula79",
"system_users_granted": [
{
"id": "f78cfcb2-d473-43b6-a72a-8cc18979aabd",
"name": "web",
"username": "web"
}
],
"is_node": False,
"org_id": "",
"tree_id": "0:0",
"tree_parent": "0",
"assets_amount": 0
},
{
"id": "aa7bb5e1-57ba-4c68-933c-aa2bc9204880",
"key": "0:0",
"value": "patricia77",
"system_users_granted": [
{
"id": "f78cfcb2-d473-43b6-a72a-8cc18979aabd",
"name": "web",
"username": "web"
}
],
"is_node": False,
"org_id": "",
"tree_id": "0:0",
"tree_parent": "0",
"assets_amount": 0
},
{
"id": "ced63974-9ade-4081-b0ba-2befc55ea380",
"key": "0:0",
"value": "irene94",
"system_users_granted": [
{
"id": "f78cfcb2-d473-43b6-a72a-8cc18979aabd",
"name": "web",
"username": "web"
}
],
"is_node": False,
"org_id": "",
"tree_id": "0:0",
"tree_parent": "0",
"assets_amount": 0
},
{
"id": "db152e40-8a49-4206-bea8-d05cf0cda50d",
"key": "0:0",
"value": "karen77",
"system_users_granted": [
{
"id": "f78cfcb2-d473-43b6-a72a-8cc18979aabd",
"name": "web",
"username": "web"
}
],
"is_node": False,
"org_id": "",
"tree_id": "0:0",
"tree_parent": "0",
"assets_amount": 0
}
]
data2 = [
{
"id": "02db2050-882f-4f42-8af5-cbb2b3262f88",
"key": "0:3:3",
"value": "Node 42",
"system_users_granted": [],
"is_node": True,
"org_id": "",
"tree_id": "0:3:3",
"tree_parent": "0:3",
"assets_amount": 27
},
{
"id": "3e1930e1-759d-430e-8935-fbd563463373",
"key": "0:3",
"value": "Node 2",
"system_users_granted": [],
"is_node": True,
"org_id": "",
"tree_id": "0:3",
"tree_parent": "0",
"assets_amount": 27
},
{
"id": "77963655-c559-4cad-8534-a1f7e20efb61",
"key": "0:3:1",
"value": "Node 18",
"system_users_granted": [],
"is_node": True,
"org_id": "",
"tree_id": "0:3:1",
"tree_parent": "0:3",
"assets_amount": 27
},
{
"id": "950453cd-3e1d-4d89-addc-3fa77e34e7a9",
"key": "0:3:2",
"value": "Node 28",
"system_users_granted": [],
"is_node": True,
"org_id": "",
"tree_id": "0:3:2",
"tree_parent": "0:3",
"assets_amount": 27
},
{
"id": "e24377ec-f63e-4dd0-970b-c047ad40b3f2",
"key": "0:3:0",
"value": "Node 8",
"system_users_granted": [],
"is_node": True,
"org_id": "",
"tree_id": "0:3:0",
"tree_parent": "0:3",
"assets_amount": 27
},
{
"id": "00671d2e-0e45-43b8-8765-8a677676aed0",
"key": "0:3:0",
"value": "robin65",
"system_users_granted": [
{
"id": "f78cfcb2-d473-43b6-a72a-8cc18979aabd",
"name": "web",
"username": "web"
}
],
"is_node": False,
"org_id": "",
"tree_id": "0:3:0",
"tree_parent": "0:3",
"assets_amount": 0
},
{
"id": "1495d4f8-882c-48c1-a9f4-2369f0f0ea09",
"key": "0:3:0",
"value": "phyllis94",
"system_users_granted": [
{
"id": "f78cfcb2-d473-43b6-a72a-8cc18979aabd",
"name": "web",
"username": "web"
}
],
"is_node": False,
"org_id": "",
"tree_id": "0:3:0",
"tree_parent": "0:3",
"assets_amount": 0
},
{
"id": "1a2f4ff7-76c6-4ff2-b1dc-c81b5979ff1b",
"key": "0:3:0",
"value": "pamela84",
"system_users_granted": [
{
"id": "f78cfcb2-d473-43b6-a72a-8cc18979aabd",
"name": "web",
"username": "web"
}
],
"is_node": False,
"org_id": "",
"tree_id": "0:3:0",
"tree_parent": "0:3",
"assets_amount": 0
},
{
"id": "1d302510-4860-437b-a3cc-f7b6a883fb87",
"key": "0:3:0",
"value": "janet89",
"system_users_granted": [
{
"id": "f78cfcb2-d473-43b6-a72a-8cc18979aabd",
"name": "web",
"username": "web"
}
],
"is_node": False,
"org_id": "",
"tree_id": "0:3:0",
"tree_parent": "0:3",
"assets_amount": 0
},
{
"id": "40f059b2-1acf-4f16-ab7c-32403d38260a",
"key": "0:3:0",
"value": "susan63",
"system_users_granted": [
{
"id": "f78cfcb2-d473-43b6-a72a-8cc18979aabd",
"name": "web",
"username": "web"
}
],
"is_node": False,
"org_id": "",
"tree_id": "0:3:0",
"tree_parent": "0:3",
"assets_amount": 0
},
{
"id": "52f7aba9-56a0-4af2-ad77-bf4807092123",
"key": "0:3:0",
"value": "brenda64",
"system_users_granted": [
{
"id": "f78cfcb2-d473-43b6-a72a-8cc18979aabd",
"name": "web",
"username": "web"
}
],
"is_node": False,
"org_id": "",
"tree_id": "0:3:0",
"tree_parent": "0:3",
"assets_amount": 0
},
{
"id": "53f16504-8add-4bef-8125-f87abf52d3cc",
"key": "0:3:0",
"value": "marilyn74",
"system_users_granted": [
{
"id": "f78cfcb2-d473-43b6-a72a-8cc18979aabd",
"name": "web",
"username": "web"
}
],
"is_node": False,
"org_id": "",
"tree_id": "0:3:0",
"tree_parent": "0:3",
"assets_amount": 0
},
{
"id": "7c17089b-67d1-43c8-8f5e-d213bde59ef1",
"key": "0:3:0",
"value": "betty90",
"system_users_granted": [
{
"id": "f78cfcb2-d473-43b6-a72a-8cc18979aabd",
"name": "web",
"username": "web"
}
],
"is_node": False,
"org_id": "",
"tree_id": "0:3:0",
"tree_parent": "0:3",
"assets_amount": 0
},
{
"id": "80478c9a-0e7f-4d50-b94c-c7f0fd40f5b2",
"key": "0:3:0",
"value": "lisa94",
"system_users_granted": [
{
"id": "f78cfcb2-d473-43b6-a72a-8cc18979aabd",
"name": "web",
"username": "web"
}
],
"is_node": False,
"org_id": "",
"tree_id": "0:3:0",
"tree_parent": "0:3",
"assets_amount": 0
},
{
"id": "82e8d997-923a-4fc2-8358-0c02626ecc8f",
"key": "0:3:0",
"value": "carolyn87",
"system_users_granted": [
{
"id": "f78cfcb2-d473-43b6-a72a-8cc18979aabd",
"name": "web",
"username": "web"
}
],
"is_node": False,
"org_id": "",
"tree_id": "0:3:0",
"tree_parent": "0:3",
"assets_amount": 0
},
{
"id": "8943134f-9f3d-4731-89ad-61bd1d0b068b",
"key": "0:3:0",
"value": "ann66",
"system_users_granted": [
{
"id": "f78cfcb2-d473-43b6-a72a-8cc18979aabd",
"name": "web",
"username": "web"
}
],
"is_node": False,
"org_id": "",
"tree_id": "0:3:0",
"tree_parent": "0:3",
"assets_amount": 0
},
{
"id": "8d7dadcf-5f09-4c7d-971b-e65413378ee1",
"key": "0:3:0",
"value": "norma78",
"system_users_granted": [
{
"id": "f78cfcb2-d473-43b6-a72a-8cc18979aabd",
"name": "web",
"username": "web"
}
],
"is_node": False,
"org_id": "",
"tree_id": "0:3:0",
"tree_parent": "0:3",
"assets_amount": 0
},
{
"id": "8da3e293-a487-4018-87b7-3bef2405fd03",
"key": "0:3:0",
"value": "susan80",
"system_users_granted": [
{
"id": "f78cfcb2-d473-43b6-a72a-8cc18979aabd",
"name": "web",
"username": "web"
}
],
"is_node": False,
"org_id": "",
"tree_id": "0:3:0",
"tree_parent": "0:3",
"assets_amount": 0
},
{
"id": "93326d6c-06e1-4630-8c36-3505492cfefb",
"key": "0:3:0",
"value": "janet93",
"system_users_granted": [
{
"id": "f78cfcb2-d473-43b6-a72a-8cc18979aabd",
"name": "web",
"username": "web"
}
],
"is_node": False,
"org_id": "",
"tree_id": "0:3:0",
"tree_parent": "0:3",
"assets_amount": 0
},
{
"id": "93a0ece4-b582-425b-9103-0156eaf49f22",
"key": "0:3:0",
"value": "louise77",
"system_users_granted": [
{
"id": "f78cfcb2-d473-43b6-a72a-8cc18979aabd",
"name": "web",
"username": "web"
}
],
"is_node": False,
"org_id": "",
"tree_id": "0:3:0",
"tree_parent": "0:3",
"assets_amount": 0
},
{
"id": "9cb0af28-ca60-4e4e-983f-bd5069579264",
"key": "0:3:0",
"value": "wanda79",
"system_users_granted": [
{
"id": "f78cfcb2-d473-43b6-a72a-8cc18979aabd",
"name": "web",
"username": "web"
}
],
"is_node": False,
"org_id": "",
"tree_id": "0:3:0",
"tree_parent": "0:3",
"assets_amount": 0
},
{
"id": "b45f40b9-0607-42a0-9643-0e8f71a6b33d",
"key": "0:3:0",
"value": "kathryn73",
"system_users_granted": [
{
"id": "f78cfcb2-d473-43b6-a72a-8cc18979aabd",
"name": "web",
"username": "web"
}
],
"is_node": False,
"org_id": "",
"tree_id": "0:3:0",
"tree_parent": "0:3",
"assets_amount": 0
},
{
"id": "c0ccd5d2-d6cb-49e1-ad27-6368289f407e",
"key": "0:3:0",
"value": "mildred89",
"system_users_granted": [
{
"id": "f78cfcb2-d473-43b6-a72a-8cc18979aabd",
"name": "web",
"username": "web"
}
],
"is_node": False,
"org_id": "",
"tree_id": "0:3:0",
"tree_parent": "0:3",
"assets_amount": 0
},
{
"id": "d042c10a-a117-4ef1-96ad-e97b84c59517",
"key": "0:3:0",
"value": "patricia92",
"system_users_granted": [
{
"id": "f78cfcb2-d473-43b6-a72a-8cc18979aabd",
"name": "web",
"username": "web"
}
],
"is_node": False,
"org_id": "",
"tree_id": "0:3:0",
"tree_parent": "0:3",
"assets_amount": 0
},
{
"id": "d0901a25-d233-4466-8f92-e6cbb069a765",
"key": "0:3:0",
"value": "joyce90",
"system_users_granted": [
{
"id": "f78cfcb2-d473-43b6-a72a-8cc18979aabd",
"name": "web",
"username": "web"
}
],
"is_node": False,
"org_id": "",
"tree_id": "0:3:0",
"tree_parent": "0:3",
"assets_amount": 0
},
{
"id": "d621bca0-a6e8-4c95-bf93-e822faf42b0a",
"key": "0:3:0",
"value": "julia74",
"system_users_granted": [
{
"id": "f78cfcb2-d473-43b6-a72a-8cc18979aabd",
"name": "web",
"username": "web"
}
],
"is_node": False,
"org_id": "",
"tree_id": "0:3:0",
"tree_parent": "0:3",
"assets_amount": 0
},
{
"id": "db17f755-e977-4d71-ab79-96e359b6fc76",
"key": "0:3:0",
"value": "betty78",
"system_users_granted": [
{
"id": "f78cfcb2-d473-43b6-a72a-8cc18979aabd",
"name": "web",
"username": "web"
}
],
"is_node": False,
"org_id": "",
"tree_id": "0:3:0",
"tree_parent": "0:3",
"assets_amount": 0
},
{
"id": "db20e2d8-7f97-4d91-8c87-5a51772bcea8",
"key": "0:3:0",
"value": "kathryn74",
"system_users_granted": [
{
"id": "f78cfcb2-d473-43b6-a72a-8cc18979aabd",
"name": "web",
"username": "web"
}
],
"is_node": False,
"org_id": "",
"tree_id": "0:3:0",
"tree_parent": "0:3",
"assets_amount": 0
},
{
"id": "df112a11-b1b6-41f9-bb58-d3a14ec2cfad",
"key": "0:3:0",
"value": "lois88",
"system_users_granted": [
{
"id": "f78cfcb2-d473-43b6-a72a-8cc18979aabd",
"name": "web",
"username": "web"
}
],
"is_node": False,
"org_id": "",
"tree_id": "0:3:0",
"tree_parent": "0:3",
"assets_amount": 0
},
{
"id": "e1ab8523-1b35-4d07-8acd-082ca33f03b9",
"key": "0:3:0",
"value": "jennifer93",
"system_users_granted": [
{
"id": "f78cfcb2-d473-43b6-a72a-8cc18979aabd",
"name": "web",
"username": "web"
}
],
"is_node": False,
"org_id": "",
"tree_id": "0:3:0",
"tree_parent": "0:3",
"assets_amount": 0
},
{
"id": "f3bef5a9-fb9d-4ead-be0b-a1d5f300d6a7",
"key": "0:3:0",
"value": "jacqueline83",
"system_users_granted": [
{
"id": "f78cfcb2-d473-43b6-a72a-8cc18979aabd",
"name": "web",
"username": "web"
}
],
"is_node": False,
"org_id": "",
"tree_id": "0:3:0",
"tree_parent": "0:3",
"assets_amount": 0
},
{
"id": "f5488aac-a474-42c3-b321-a872f2d1826d",
"key": "0:3:0",
"value": "cheryl92",
"system_users_granted": [
{
"id": "f78cfcb2-d473-43b6-a72a-8cc18979aabd",
"name": "web",
"username": "web"
}
],
"is_node": False,
"org_id": "",
"tree_id": "0:3:0",
"tree_parent": "0:3",
"assets_amount": 0
}
]
if request.args.get('id'):
return jsonify(data2)
else:
return jsonify(data1)
@app.route('/luna/i18n/<i18n>') @app.route('/luna/i18n/<i18n>')
def i18n(i18n): def i18n(i18n):
return send_file('./i18n/' + i18n) return send_file('./i18n/' + i18n)
......
...@@ -33,25 +33,25 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges { ...@@ -33,25 +33,25 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges {
}, },
callback: { callback: {
onClick: this.onCzTreeOnClick.bind(this), onClick: this.onCzTreeOnClick.bind(this),
onRightClick: this.onRightClick.bind(this) onRightClick: this.onRightClick.bind(this),
onAsyncSuccess: this.onzTreeAsyncSuccess.bind(this)
}, },
async: {
enable: true,
url: '/api/perms/v1/user/nodes/children/',
autoParam: ['node_id=id', 'name=n', 'level=lv'],
type: 'get',
dataFilter: this.nodeFilter
}
}; };
pos = {left: '100px', top: '200px'}; pos = {left: '100px', top: '200px'};
hiddenNodes: any; hiddenNodes: any;
expandNodes: any; expandNodes: any;
zTree: any; zTree: any;
searching = false;
isShowRMenu = false; isShowRMenu = false;
rightClickSelectNode: any; rightClickSelectNode: any;
onCzTreeOnClick(event, treeId, treeNode, clickFlag) {
if (treeNode.isParent) {
const zTreeObj = $.fn.zTree.getZTreeObj('ztree');
zTreeObj.expandNode(treeNode);
} else {
this.Connect(treeNode);
}
}
constructor(private _appService: AppService, constructor(private _appService: AppService,
public _dialog: MatDialog, public _dialog: MatDialog,
public _logger: LogService) { public _logger: LogService) {
...@@ -67,7 +67,7 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges { ...@@ -67,7 +67,7 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges {
.debounceTime(300) .debounceTime(300)
.distinctUntilChanged() .distinctUntilChanged()
.subscribe((n) => { .subscribe((n) => {
this.filter(); this.searchNode();
}); });
} }
...@@ -80,58 +80,53 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges { ...@@ -80,58 +80,53 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges {
} }
} }
draw() { nodeFilter(treeId, parentNode, childNodes) {
const nodes = {}; $.each(childNodes, function (index, value) {
const assets = {}; value['node_id'] = value['id'];
this.Data.forEach(node => { value['id'] = value['tree_id'];
if (!nodes[node['id']]) { if (value['tree_id'] !== value['tree_parent']) {
nodes[node['id']] = true; value['pId'] = value['tree_parent'];
this.nodes.push({ } else {
'id': node['id'], value['isParent'] = true;
'key': node['key'],
'name': node['name'],
'title': node['name'],
'value': node['value'],
'pId': node['parent'],
'ip': '',
'assets_amount': node['assets_amount'],
'isParent': true,
'open': node['key'] === '0'
});
} }
value['name'] = value['value'];
node['assets_granted'].forEach(asset => { if (!value['is_node']) {
if (!assets[asset['id']]) { const platform = value['asset']['platform'].toLowerCase().indexOf('win') === 0 ? 'windows' : 'linux';
const platform = asset['platform'].toLowerCase().indexOf('win') === 0 ? 'windows' : 'linux'; value['title'] = value['asset']['ip'] || value['name'];
this.nodes.push({ value['iconSkin'] = platform;
'id': asset['id'], }
'name': asset['hostname'], value['isParent'] = value['is_node'];
'value': asset['hostname'],
'system_users_granted': asset['system_users_granted'],
'platform': asset['platform'],
'ip': asset['ip'],
'title': asset['ip'],
'isParent': false,
'pId': node['id'],
'iconSkin': platform
});
assets[asset['id'] + '@' + node['id']] = true;
}
});
}); });
this.nodes.sort(function(node1, node2) { return childNodes;
if (node1.isParent && !node2.isParent) { }
return -1;
} else if (!node1.isParent && node2.isParent) { onzTreeAsyncSuccess(event, treeId, treeNode, msg) {
return 1; // 代表第一次加载
if (!treeNode) {
this.zTree = $.fn.zTree.getZTreeObj(treeId);
if (this.searching) {
this.zTree.expandAll(true);
} else { } else {
return node1.name < node2.name ? -1 : 1; const root = this.zTree.getNodes()[0];
this.zTree.expandNode(root, true);
} }
}); }
}
onCzTreeOnClick(event, treeId, treeNode, clickFlag) {
if (treeNode.isParent) {
const zTreeObj = $.fn.zTree.getZTreeObj('ztree');
zTreeObj.expandNode(treeNode);
} else {
this.Connect(treeNode.asset);
}
}
draw() {
$.fn.zTree.init($('#ztree'), this.setting, this.nodes); $.fn.zTree.init($('#ztree'), this.setting, this.nodes);
this.zTree = $.fn.zTree.getZTreeObj('ztree'); // this.zTree = $.fn.zTree.getZTreeObj('ztree');
const root = this.zTree.getNodes()[0]; // const root = this.zTree.getNodes()[0];
this.zTree.expandNode(root, true); // this.zTree.expandNode(root, true);
} }
showRMenu(left, top) { showRMenu(left, top) {
...@@ -145,7 +140,7 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges { ...@@ -145,7 +140,7 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges {
} }
onRightClick(event, treeId, treeNode) { onRightClick(event, treeId, treeNode) {
if (!treeNode || treeNode.isParent || treeNode.platform.toLowerCase() === 'windows') { if (!treeNode || treeNode.isParent || treeNode.asset.platform.toLowerCase() === 'windows') {
return null; return null;
} }
if (!treeNode && event.target.tagName.toLowerCase() !== 'button' && $(event.target).parents('a').length === 0) { if (!treeNode && event.target.tagName.toLowerCase() !== 'button' && $(event.target).parents('a').length === 0) {
...@@ -192,7 +187,7 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges { ...@@ -192,7 +187,7 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges {
} }
connectFileManager() { connectFileManager() {
const host = this.rightClickSelectNode; const host = this.rightClickSelectNode.asset;
const id = NavList.List.length - 1; const id = NavList.List.length - 1;
if (host) { if (host) {
NavList.List[id].nick = '[FILE]' + host.name; NavList.List[id].nick = '[FILE]' + host.name;
...@@ -214,8 +209,6 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges { ...@@ -214,8 +209,6 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges {
login(host, user) { login(host, user) {
const id = NavList.List.length - 1; const id = NavList.List.length - 1;
this._logger.debug(NavList);
this._logger.debug(host);
if (user) { if (user) {
NavList.List[id].nick = host.name; NavList.List[id].nick = host.name;
NavList.List[id].connected = true; NavList.List[id].connected = true;
...@@ -248,73 +241,25 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges { ...@@ -248,73 +241,25 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges {
return user; return user;
} }
recurseParent(node) { searchNode() {
const parentNode = node.getParentNode();
if (parentNode && parentNode.pId) {
return [parentNode, ...this.recurseParent(parentNode)];
} else if (parentNode) {
return [parentNode];
} else {
return [];
}
}
recurseChildren(node) {
if (!node.isParent) {
return [];
}
const children = node.children;
if (!children) {
return [];
}
let all_children = [];
children.forEach((n) => {
all_children = [...children, ...this.recurseChildren(n)];
});
return all_children;
}
filter() {
const zTreeObj = $.fn.zTree.getZTreeObj('ztree'); const zTreeObj = $.fn.zTree.getZTreeObj('ztree');
if (!zTreeObj) { if (!zTreeObj) {
return null; return null;
} }
const _keywords = this.query; const _keywords = this.query;
const nodes = zTreeObj.transformToArray(zTreeObj.getNodes());
if (!_keywords) { if (!_keywords) {
if (this.hiddenNodes) { // 第一次刷新
zTreeObj.showNodes(this.hiddenNodes); if (!this.searching) {
this.hiddenNodes = null; return null;
}
if (this.expandNodes) {
this.expandNodes.forEach((node) => {
if (node.id !== nodes[0].id) {
zTreeObj.expandNode(node, false);
}
});
this.expandNodes = null;
} }
return null; // 以后搜索后回来
this.searching = false;
zTreeObj.setting.async.url = '/api/perms/v1/user/nodes/children/';
} else {
this.searching = true;
zTreeObj.setting.async.url = `/api/perms/v1/user/nodes/children/?search=${_keywords}`;
} }
let shouldShow = []; zTreeObj.reAsyncChildNodes(null, 'refresh');
const matchedNodes = zTreeObj.getNodesByFilter(function(node){
return node.name.indexOf(_keywords) !== -1 || node.ip.indexOf(_keywords) !== -1;
});
matchedNodes.forEach((node) => {
const parents = this.recurseParent(node);
const children = this.recurseChildren(node);
shouldShow = [...shouldShow, ...parents, ...children, node];
});
this.hiddenNodes = nodes;
this.expandNodes = shouldShow;
zTreeObj.hideNodes(nodes);
zTreeObj.showNodes(shouldShow);
shouldShow.forEach((node) => {
if (node.isParent) {
zTreeObj.expandNode(node, true);
}
});
// zTreeObj.expandAll(true);
} }
} }
......
...@@ -10,14 +10,6 @@ ...@@ -10,14 +10,6 @@
import {Component, OnInit} from '@angular/core'; import {Component, OnInit} from '@angular/core';
import {TermWS} from '../../../globals'; import {TermWS} from '../../../globals';
// export class Term {
// machine: string;
// socket: any;
// term: any;
// }
export class View { export class View {
nick: string; nick: string;
type: string; type: string;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment