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
8ac82950
Commit
8ac82950
authored
Oct 24, 2019
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Update] luna tree 增加收藏取消收藏
parent
7c357ae5
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
105 additions
and
3 deletions
+105
-3
asset-tree.component.ts
src/app/elements/asset-tree/asset-tree.component.ts
+44
-0
http.ts
src/app/services/http.ts
+42
-2
common.ts
src/app/utils/common.ts
+16
-0
zh.json
src/assets/i18n/zh.json
+3
-1
No files found.
src/app/elements/asset-tree/asset-tree.component.ts
View file @
8ac82950
...
...
@@ -48,6 +48,7 @@ export class ElementAssetTreeComponent implements OnInit, OnDestroy {
isLoadTreeAsync
:
boolean
;
filterAssetCancel
$
:
Subject
<
boolean
>
=
new
Subject
();
loading
=
true
;
favoriteAssets
=
[];
constructor
(
private
_appSvc
:
AppService
,
private
_treeFilterSvc
:
TreeFilterService
,
...
...
@@ -105,6 +106,10 @@ export class ElementAssetTreeComponent implements OnInit, OnDestroy {
};
}
this
.
_http
.
getFavoriteAssets
().
subscribe
(
resp
=>
{
this
.
favoriteAssets
=
resp
.
map
(
i
=>
i
.
asset
);
});
this
.
loading
=
true
;
this
.
_http
.
getMyGrantedNodes
(
this
.
isLoadTreeAsync
,
refresh
).
subscribe
(
resp
=>
{
this
.
loading
=
false
;
...
...
@@ -206,6 +211,15 @@ export class ElementAssetTreeComponent implements OnInit, OnDestroy {
return
findSSHProtocol
;
}
isAssetFavorite
()
{
const
host
=
this
.
rightClickSelectNode
.
meta
.
asset
;
if
(
!
host
)
{
return
false
;
}
const
assetId
=
host
.
id
;
return
this
.
favoriteAssets
.
indexOf
(
assetId
)
!==
-
1
;
}
get
RMenuList
()
{
const
menuList
=
[{
'id'
:
'new-connection'
,
...
...
@@ -219,6 +233,18 @@ export class ElementAssetTreeComponent implements OnInit, OnDestroy {
'fa'
:
'fa-file'
,
'hide'
:
!
this
.
nodeSupportSSH
(),
'click'
:
this
.
connectFileManager
.
bind
(
this
)
},
{
'id'
:
'favorite'
,
'name'
:
'Favorite'
,
'fa'
:
'fa-star-o'
,
'hide'
:
this
.
isAssetFavorite
(),
'click'
:
this
.
favoriteAsset
.
bind
(
this
)
},
{
'id'
:
'disfavor'
,
'name'
:
'Disfavor'
,
'fa'
:
'fa-star'
,
'hide'
:
!
this
.
isAssetFavorite
(),
'click'
:
this
.
favoriteAsset
.
bind
(
this
)
}];
if
(
!
this
.
rightClickSelectNode
)
{
return
[];
...
...
@@ -265,6 +291,24 @@ export class ElementAssetTreeComponent implements OnInit, OnDestroy {
window
.
open
(
url
,
'_blank'
);
}
favoriteAsset
()
{
const
host
=
this
.
rightClickSelectNode
.
meta
.
asset
;
if
(
!
host
)
{
return
false
;
}
const
assetId
=
host
.
id
;
if
(
this
.
isAssetFavorite
())
{
this
.
_http
.
favoriteAsset
(
assetId
,
false
).
subscribe
(()
=>
{
const
i
=
this
.
favoriteAssets
.
indexOf
(
assetId
);
this
.
favoriteAssets
.
splice
(
i
,
1
);
});
}
else
{
this
.
_http
.
favoriteAsset
(
assetId
,
true
).
subscribe
(()
=>
{
this
.
favoriteAssets
.
push
(
assetId
);
});
}
}
filterAssets
(
keyword
)
{
if
(
this
.
isLoadTreeAsync
)
{
this
.
_logger
.
debug
(
'Filter assets server'
);
...
...
src/app/services/http.ts
View file @
8ac82950
...
...
@@ -3,6 +3,7 @@ import {HttpClient, HttpHeaders, HttpParams} from '@angular/common/http';
import
{
Browser
,
DataStore
}
from
'@app/globals'
;
import
{
GuacObjAddResp
,
SystemUser
,
TreeNode
,
User
as
_User
}
from
'@app/model'
;
import
{
SettingService
}
from
'./setting'
;
import
{
getCookie
}
from
'@app/utils/common'
;
@
Injectable
()
...
...
@@ -12,23 +13,43 @@ export class HttpService {
constructor
(
private
http
:
HttpClient
,
private
settingSrv
:
SettingService
)
{
}
setOptionsCSRFToken
(
options
)
{
const
csrfToken
=
getCookie
(
'csrftoken'
);
let
headers
;
if
(
!
options
)
{
options
=
{};
}
if
(
!
options
.
headers
)
{
headers
=
new
HttpHeaders
();
}
else
{
headers
=
options
.
headers
;
}
headers
=
headers
.
set
(
'X-CSRFToken'
,
csrfToken
);
options
.
headers
=
headers
;
return
options
;
}
get
(
url
:
string
,
options
?:
any
)
{
return
this
.
http
.
get
(
url
,
options
);
}
post
(
url
:
string
,
options
?:
any
)
{
return
this
.
http
.
post
(
url
,
options
);
post
(
url
:
string
,
body
:
any
,
options
?:
any
)
{
options
=
this
.
setOptionsCSRFToken
(
options
);
return
this
.
http
.
post
(
url
,
body
,
options
);
}
put
(
url
:
string
,
options
?:
any
)
{
options
=
this
.
setOptionsCSRFToken
(
options
);
return
this
.
http
.
put
(
url
,
options
);
}
delete
(
url
:
string
,
options
?:
any
)
{
options
=
this
.
setOptionsCSRFToken
(
options
);
return
this
.
http
.
delete
(
url
,
options
);
}
patch
(
url
:
string
,
options
?:
any
)
{
options
=
this
.
setOptionsCSRFToken
(
options
);
return
this
.
http
.
patch
(
url
,
options
);
}
...
...
@@ -88,6 +109,25 @@ export class HttpService {
return
this
.
http
.
get
<
Array
<
SystemUser
>>
(
url
);
}
favoriteAsset
(
assetId
:
string
,
favorite
:
boolean
)
{
let
url
:
string
;
if
(
favorite
)
{
url
=
`/api/v1/assets/favorite-assets/`
;
const
data
=
{
asset
:
assetId
};
return
this
.
post
(
url
,
data
);
}
else
{
url
=
`/api/v1/assets/favorite-assets/?asset=
${
assetId
}
`
;
return
this
.
delete
(
url
);
}
}
getFavoriteAssets
()
{
const
url
=
'/api/v1/assets/favorite-assets/'
;
return
this
.
http
.
get
<
Array
<
any
>>
(
url
);
}
getGuacamoleToken
(
user_id
:
string
,
authToken
:
string
)
{
const
body
=
new
HttpParams
()
.
set
(
'username'
,
user_id
)
...
...
src/app/utils/common.ts
View file @
8ac82950
...
...
@@ -31,3 +31,19 @@ export function newTerminal(fontSize?: number) {
}
});
}
export
function
getCookie
(
name
:
string
):
string
{
let
cookieValue
=
null
;
if
(
document
.
cookie
&&
document
.
cookie
!==
''
)
{
const
cookies
=
document
.
cookie
.
split
(
';'
);
for
(
let
i
=
0
;
i
<
cookies
.
length
;
i
++
)
{
const
cookie
=
cookies
[
i
].
trim
();
// Does this cookie string begin with the name we want?
if
(
cookie
.
substring
(
0
,
name
.
length
+
1
)
===
(
name
+
'='
))
{
cookieValue
=
decodeURIComponent
(
cookie
.
substring
(
name
.
length
+
1
));
break
;
}
}
}
return
cookieValue
;
}
src/assets/i18n/zh.json
View file @
8ac82950
...
...
@@ -76,5 +76,7 @@
"yes"
:
"是"
,
"no"
:
"否"
,
"cols"
:
"列数"
,
"rows"
:
"行数"
"rows"
:
"行数"
,
"favorite"
:
"收藏"
,
"disfavor"
:
"取消收藏"
}
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