Commit 6582ff89 authored by ibuler's avatar ibuler

[Update] 修改树形结构

parent b521a9d0
...@@ -14,7 +14,7 @@ import {DataStore, User, Browser, i18n} from './globals'; ...@@ -14,7 +14,7 @@ import {DataStore, User, Browser, i18n} from './globals';
import {environment} from '../environments/environment'; import {environment} from '../environments/environment';
import {HttpClient, HttpHeaders, HttpParams} from '@angular/common/http'; import {HttpClient, HttpHeaders, HttpParams} from '@angular/common/http';
import {NGXLogger} from 'ngx-logger'; import {NGXLogger} from 'ngx-logger';
import {HostGroup} from './pages/control/cleftbar/cleftbar.component'; import {HostGroup, Node} from './pages/control/cleftbar/cleftbar.component';
import * as UUID from 'uuid-js/lib/uuid.js'; import * as UUID from 'uuid-js/lib/uuid.js';
declare function unescape(s: string): string; declare function unescape(s: string): string;
...@@ -66,8 +66,8 @@ export class HttpService { ...@@ -66,8 +66,8 @@ export class HttpService {
return this.http.get('/api/users/v1/profile/'); return this.http.get('/api/users/v1/profile/');
} }
get_my_asset_groups_assets() { get_my_granted_nodes() {
return this.http.get<Array<HostGroup>>('/api/perms/v1/user/nodes-assets/'); return this.http.get<Array<Node>>('/api/perms/v1/user/nodes-assets/tree/');
} }
get_guacamole_token(user_id: string, authToken: string) { get_guacamole_token(user_id: string, authToken: string) {
......
...@@ -81,57 +81,8 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges { ...@@ -81,57 +81,8 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges {
} }
draw() { draw() {
const nodes = {}; $.fn.zTree.init($('#ztree'), this.setting, this.Data);
const assets = {};
this.Data.forEach(node => {
if (!nodes[node['id']]) {
nodes[node['id']] = true;
this.nodes.push({
'id': node['id'],
'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'
});
}
node['assets_granted'].forEach(asset => {
if (!assets[asset['id']]) {
const platform = asset['platform'].toLowerCase().indexOf('win') === 0 ? 'windows' : 'linux';
this.nodes.push({
'id': asset['id'],
'name': asset['hostname'],
'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) {
if (node1.isParent && !node2.isParent) {
return -1;
} else if (!node1.isParent && node2.isParent) {
return 1;
} else {
return node1.name < node2.name ? -1 : 1;
}
});
$.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];
this.zTree.expandNode(root, true);
} }
showRMenu(left, top) { showRMenu(left, top) {
...@@ -145,9 +96,13 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges { ...@@ -145,9 +96,13 @@ 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 ) {
return null; return null;
} }
const host = treeNode.meta.asset;
if (host.protocol.toLowerCase() === 'rdp') {
alert('Windows 请使用Ctrl+Shift+Alt呼出侧边栏上传下载');
}
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) {
this.zTree.cancelSelectedNode(); this.zTree.cancelSelectedNode();
this.showRMenu(event.clientX, event.clientY); this.showRMenu(event.clientX, event.clientY);
...@@ -158,22 +113,24 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges { ...@@ -158,22 +113,24 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges {
} }
} }
Connect(host) { Connect(node) {
const system_users = node.meta.system_users;
const host = node.meta.asset;
let user: any; let user: any;
if (host.system_users_granted.length > 1) { if (system_users.length > 1) {
user = this.checkPriority(host.system_users_granted); user = this.checkPriority(system_users);
if (user) { if (user) {
this.login(host, user); this.login(host, user);
} else { } else {
const dialogRef = this._dialog.open(AssetTreeDialogComponent, { const dialogRef = this._dialog.open(AssetTreeDialogComponent, {
height: '200px', height: '200px',
width: '300px', width: '300px',
data: {users: host.system_users_granted} data: {users: system_users}
}); });
dialogRef.afterClosed().subscribe(result => { dialogRef.afterClosed().subscribe(result => {
if (result) { if (result) {
for (const i of host.system_users_granted) { for (const i of system_users) {
if (i.id.toString() === result.toString()) { if (i.id.toString() === result.toString()) {
user = i; user = i;
break; break;
...@@ -183,8 +140,8 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges { ...@@ -183,8 +140,8 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges {
} }
}); });
} }
} else if (host.system_users_granted.length === 1) { } else if (system_users.length === 1) {
user = host.system_users_granted[0]; user = system_users[0];
this.login(host, user); this.login(host, user);
} else { } else {
alert('该主机没有授权登录用户'); alert('该主机没有授权登录用户');
...@@ -192,10 +149,10 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges { ...@@ -192,10 +149,10 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges {
} }
connectFileManager() { connectFileManager() {
const host = this.rightClickSelectNode; const host = this.rightClickSelectNode.meta.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.hostname;
NavList.List[id].connected = true; NavList.List[id].connected = true;
NavList.List[id].edit = false; NavList.List[id].edit = false;
NavList.List[id].closed = false; NavList.List[id].closed = false;
...@@ -217,7 +174,7 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges { ...@@ -217,7 +174,7 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges {
this._logger.debug(NavList); this._logger.debug(NavList);
this._logger.debug(host); this._logger.debug(host);
if (user) { if (user) {
NavList.List[id].nick = host.name; NavList.List[id].nick = host.hostname;
NavList.List[id].connected = true; NavList.List[id].connected = true;
NavList.List[id].edit = false; NavList.List[id].edit = false;
NavList.List[id].closed = false; NavList.List[id].closed = false;
...@@ -297,8 +254,13 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges { ...@@ -297,8 +254,13 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges {
return null; return null;
} }
let shouldShow = []; let shouldShow = [];
const matchedNodes = zTreeObj.getNodesByFilter(function(node){ const matchedNodes = zTreeObj.getNodesByFilter(function(node) {
return node.name.indexOf(_keywords) !== -1 || node.ip.indexOf(_keywords) !== -1; if (node.meta.type === 'asset') {
const host = node.meta.asset;
return host.hostname.indexOf(_keywords) !== -1 || host.ip.indexOf(_keywords) !== -1;
} else {
return node.name.indexOf(_keywords) !== -1;
}
}); });
matchedNodes.forEach((node) => { matchedNodes.forEach((node) => {
const parents = this.recurseParent(node); const parents = this.recurseParent(node);
......
...@@ -25,6 +25,18 @@ export interface HostGroup { ...@@ -25,6 +25,18 @@ export interface HostGroup {
children: Array<Host>; children: Array<Host>;
} }
export interface Node {
id: string;
name: string;
comment: string;
title: string;
isParent: boolean;
pId: string;
open: boolean;
iconSkin: string;
meta: object;
}
export class Host { export class Host {
name: string; name: string;
id: string; id: string;
...@@ -93,7 +105,7 @@ export class CleftbarComponent implements OnInit { ...@@ -93,7 +105,7 @@ export class CleftbarComponent implements OnInit {
} }
ngOnInit() { ngOnInit() {
this._http.get_my_asset_groups_assets() this._http.get_my_granted_nodes()
.subscribe(response => { .subscribe(response => {
this.zNodes = response; this.zNodes = response;
// this.HostGroups = response; // this.HostGroups = response;
......
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