Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
L
luna
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ops
luna
Commits
65ccd3dd
Commit
65ccd3dd
authored
Aug 29, 2019
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Update] 提取Model
parent
af908312
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
93 additions
and
50 deletions
+93
-50
app.service.ts
src/app/app.service.ts
+13
-11
asset-tree.component.ts
src/app/elements/asset-tree/asset-tree.component.ts
+35
-39
model.ts
src/app/model.ts
+45
-0
No files found.
src/app/app.service.ts
View file @
65ccd3dd
...
...
@@ -13,14 +13,12 @@ import 'rxjs/add/operator/catch';
import
{
DataStore
,
User
,
Browser
,
i18n
}
from
'./globals'
;
import
{
HttpClient
,
HttpHeaders
,
HttpParams
}
from
'@angular/common/http'
;
import
{
NGXLogger
}
from
'ngx-logger'
;
import
{
SystemUser
,
GuacObjAddResp
,
TreeNode
}
from
'./model'
;
import
*
as
UUID
from
'uuid-js/lib/uuid.js'
;
declare
function
unescape
(
s
:
string
):
string
;
class
GuacObjAddResp
{
code
:
number
;
result
:
string
;
}
@
Injectable
()
export
class
HttpService
{
...
...
@@ -71,18 +69,23 @@ export class HttpService {
getMyGrantedNodes
(
async
:
boolean
,
refresh
?:
boolean
)
{
const
cachePolicy
=
refresh
?
'2'
:
'1'
;
const
syncUrl
=
'/api/perms/v1/users/nodes-with-assets/tree/?cache_policy='
+
cachePolicy
;
const
asyncUrl
=
'/api/perms/v1/users/nodes/children-with-assets/tree/?cache_policy='
+
cachePolicy
;
const
syncUrl
=
`/api/perms/v1/users/nodes-with-assets/tree/?cache_policy=
${
cachePolicy
}
`
;
const
asyncUrl
=
`/api/perms/v1/users/nodes/children-with-assets/tree/?cache_policy=
${
cachePolicy
}
`
;
const
url
=
async
?
asyncUrl
:
syncUrl
;
return
this
.
http
.
get
<
Array
<
Node
>>
(
url
);
return
this
.
http
.
get
<
Array
<
Tree
Node
>>
(
url
);
}
getMyGrantedRemoteApps
()
{
return
this
.
http
.
get
<
Array
<
Node
>>
(
'/api/perms/v1/user/remote-apps/tree/'
);
return
this
.
http
.
get
<
Array
<
TreeNode
>>
(
'/api/perms/v1/user/remote-apps/tree/'
);
}
getMyAssetSystemUsers
(
assetId
:
string
)
{
const
url
=
`/api/v1/perms/users/assets/
${
assetId
}
/system-users/`
;
return
this
.
http
.
get
<
Array
<
SystemUser
>>
(
url
);
}
refreshMyGrantedNodes
()
{
return
this
.
http
.
get
<
Array
<
Node
>>
(
'/api/perms/v1/user/nodes-assets/tree/?cache_policy=2'
);
return
this
.
http
.
get
<
Array
<
Tree
Node
>>
(
'/api/perms/v1/user/nodes-assets/tree/?cache_policy=2'
);
}
getGuacamoleToken
(
user_id
:
string
,
authToken
:
string
)
{
...
...
@@ -180,8 +183,7 @@ export class HttpService {
}
search
(
q
:
string
)
{
const
params
=
new
HttpParams
()
.
set
(
'q'
,
q
);
const
params
=
new
HttpParams
().
set
(
'q'
,
q
);
return
this
.
http
.
get
(
'/api/search'
,
{
params
:
params
});
}
...
...
src/app/elements/asset-tree/asset-tree.component.ts
View file @
65ccd3dd
...
...
@@ -5,6 +5,7 @@ import {MAT_DIALOG_DATA, MatDialog, MatDialogRef} from '@angular/material';
import
{
FormControl
,
Validators
}
from
'@angular/forms'
;
import
{
BehaviorSubject
}
from
'rxjs/BehaviorSubject'
;
import
{
ActivatedRoute
}
from
'@angular/router'
;
import
{
SystemUser
,
TreeNode
,
Asset
,
Node
}
from
'../../model'
;
import
*
as
jQuery
from
'jquery/dist/jquery.min'
;
declare
var
$
:
any
;
...
...
@@ -54,7 +55,7 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges {
}
}
constructor
(
private
_appS
ervice
:
AppService
,
constructor
(
private
_appS
vc
:
AppService
,
public
_dialog
:
MatDialog
,
public
_logger
:
LogService
,
private
activatedRoute
:
ActivatedRoute
,
...
...
@@ -64,19 +65,12 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges {
this
.
searchEvt$
=
new
BehaviorSubject
<
string
>
(
this
.
query
);
}
refreshGrantedAssetsNodes
()
{
this
.
_http
.
refreshMyGrantedNodes
()
.
subscribe
(
response
=>
{
this
.
Data
=
[...
response
,
...
this
.
Data
];
this
.
initTree
();
});
}
ngOnInit
()
{
this
.
initAssetsTree
();
this
.
initRemoteAppsTree
();
this
.
initTree
();
document
.
addEventListener
(
'click'
,
this
.
hideRMenu
.
bind
(
this
),
false
);
this
.
loadTreeAsync
=
this
.
_navSvc
.
treeLoadAsync
;
// Todo: 搜索
this
.
searchEvt$
.
asObservable
()
.
debounceTime
(
300
)
.
distinctUntilChanged
()
...
...
@@ -115,12 +109,12 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges {
}
this
.
_http
.
getMyGrantedNodes
(
this
.
loadTreeAsync
,
refresh
).
subscribe
(
resp
=>
{
const
assetsTree
=
$
.
fn
.
zTree
.
init
(
$
(
'#assetsTree'
),
setting
,
resp
);
this
.
assetsTree
=
assetsTree
;
this
.
rootNodeAddDom
(
assetsTree
,
()
=>
{
this
.
refreshAssetsTree
();
});
const
assetsTree
=
$
.
fn
.
zTree
.
init
(
$
(
'#assetsTree'
),
setting
,
resp
);
this
.
assetsTree
=
assetsTree
;
this
.
rootNodeAddDom
(
assetsTree
,
()
=>
{
this
.
refreshAssetsTree
();
});
});
}
refreshRemoteAppsTree
()
{
...
...
@@ -144,6 +138,7 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges {
this
.
initAssetsTree
();
this
.
initRemoteAppsTree
();
// Todo: connect to some asset, direct
this
.
activatedRoute
.
queryParams
.
subscribe
(
params
=>
{
const
login_to
=
params
[
'login_to'
];
if
(
login_to
&&
!
this
.
hasLoginTo
)
{
...
...
@@ -215,7 +210,7 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges {
}
}
Connect
(
node
)
{
Connect
(
node
:
TreeNode
)
{
switch
(
node
.
meta
.
type
)
{
case
'asset'
:
this
.
connectAsset
(
node
);
...
...
@@ -228,15 +223,16 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges {
}
}
connectAsset
(
node
)
{
const
systemUsers
=
node
.
meta
.
system_users
;
const
host
=
node
.
meta
.
asset
;
let
user
:
any
;
if
(
systemUsers
.
length
>
1
)
{
user
=
this
.
checkPriority
(
systemUsers
);
if
(
user
)
{
return
this
.
manualSetUserAuthLoginIfNeed
(
host
,
user
,
this
.
login
);
}
else
{
connectAsset
(
node
:
TreeNode
)
{
const
host
=
node
.
meta
.
asset
as
Asset
;
this
.
_http
.
getMyAssetSystemUsers
(
host
.
id
).
subscribe
(
systemUsers
=>
{
let
user
:
SystemUser
;
if
(
systemUsers
.
length
>
1
)
{
// 检查系统用户优先级,获取最高优先级的
user
=
this
.
checkPriority
(
systemUsers
);
if
(
user
)
{
return
this
.
manualSetUserAuthLoginIfNeed
(
host
,
user
,
this
.
loginAsset
);
}
const
dialogRef
=
this
.
_dialog
.
open
(
AssetTreeDialogComponent
,
{
height
:
'200px'
,
width
:
'300px'
,
...
...
@@ -251,24 +247,24 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges {
break
;
}
}
return
this
.
manualSetUserAuthLoginIfNeed
(
host
,
user
,
this
.
login
);
return
this
.
manualSetUserAuthLoginIfNeed
(
host
,
user
,
this
.
login
Asset
);
}
});
}
else
if
(
systemUsers
.
length
===
1
)
{
user
=
systemUsers
[
0
];
this
.
manualSetUserAuthLoginIfNeed
(
host
,
user
,
this
.
loginAsset
);
}
else
{
alert
(
'该主机没有授权登录用户'
);
}
}
else
if
(
systemUsers
.
length
===
1
)
{
user
=
systemUsers
[
0
];
this
.
manualSetUserAuthLoginIfNeed
(
host
,
user
,
this
.
login
);
}
else
{
alert
(
'该主机没有授权登录用户'
);
}
});
}
connectRemoteApp
(
node
)
{
const
user
=
node
.
meta
.
user
;
connectRemoteApp
(
node
:
TreeNode
)
{
const
user
=
node
.
meta
.
user
as
SystemUser
;
return
this
.
manualSetUserAuthLoginIfNeed
(
node
,
user
,
this
.
loginRemoteApp
);
}
loginRemoteApp
(
node
,
u
ser
)
{
loginRemoteApp
(
node
:
TreeNode
,
user
:
SystemU
ser
)
{
const
id
=
NavList
.
List
.
length
-
1
;
if
(
node
)
{
NavList
.
List
[
id
].
nick
=
node
.
name
;
...
...
@@ -305,7 +301,7 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges {
this
.
Connect
(
host
);
}
manualSetUserAuthLoginIfNeed
(
host
,
u
ser
,
callback
)
{
manualSetUserAuthLoginIfNeed
(
host
:
Asset
,
user
:
SystemU
ser
,
callback
)
{
if
(
user
.
login_mode
!==
'manual'
||
user
.
protocol
!==
'rdp'
)
{
return
callback
(
host
,
user
);
}
...
...
@@ -328,7 +324,7 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges {
});
}
login
(
host
,
u
ser
)
{
login
Asset
(
host
:
Asset
,
user
:
SystemU
ser
)
{
const
id
=
NavList
.
List
.
length
-
1
;
if
(
user
)
{
...
...
@@ -349,7 +345,7 @@ export class ElementAssetTreeComponent implements OnInit, OnChanges {
}
}
checkPriority
(
sysUsers
)
{
checkPriority
(
sysUsers
:
Array
<
SystemUser
>
)
{
let
priority
=
-
1
;
let
user
:
any
;
for
(
const
u
of
sysUsers
)
{
...
...
src/app/model.ts
0 → 100644
View file @
65ccd3dd
export
class
SystemUser
{
id
:
string
;
name
:
string
;
login_mode
:
string
;
username
:
string
;
priority
:
number
;
protocol
:
string
;
password
:
string
;
actions
:
Array
<
string
>
;
}
export
class
TreeNode
{
id
:
string
;
name
:
string
;
comment
:
string
;
title
:
string
;
isParent
:
boolean
;
pId
:
string
;
open
:
boolean
;
iconSkin
:
string
;
meta
:
any
;
}
export
class
Node
{
id
:
string
;
key
:
string
;
value
:
string
;
}
export
class
Asset
{
id
:
string
;
hostname
:
string
;
ip
:
string
;
comment
:
string
;
domain
:
string
;
os
:
string
;
platform
:
string
;
protocols
:
Array
<
string
>
;
}
export
class
GuacObjAddResp
{
code
:
number
;
result
:
string
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment