Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
K
koko
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
koko
Commits
03b21775
Commit
03b21775
authored
May 16, 2019
by
Eric
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Update] improve search result
parent
1a883bef
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
8 deletions
+17
-8
session.go
pkg/handler/session.go
+17
-8
No files found.
pkg/handler/session.go
View file @
03b21775
...
@@ -63,7 +63,7 @@ func (h *interactiveHandler) Initial() {
...
@@ -63,7 +63,7 @@ func (h *interactiveHandler) Initial() {
h
.
displayBanner
()
h
.
displayBanner
()
h
.
loadUserAssets
()
h
.
loadUserAssets
()
h
.
loadUserAssetNodes
()
h
.
loadUserAssetNodes
()
h
.
searchResult
=
h
.
assets
h
.
searchResult
=
h
.
assets
[
:
0
]
h
.
winWatchChan
=
make
(
chan
bool
)
h
.
winWatchChan
=
make
(
chan
bool
)
}
}
...
@@ -135,7 +135,6 @@ func (h *interactiveHandler) Dispatch(ctx cctx.Context) {
...
@@ -135,7 +135,6 @@ func (h *interactiveHandler) Dispatch(ctx cctx.Context) {
return
return
default
:
default
:
assets
:=
h
.
searchAsset
(
line
)
assets
:=
h
.
searchAsset
(
line
)
h
.
searchResult
=
assets
h
.
displayAssetsOrProxy
(
assets
)
h
.
displayAssetsOrProxy
(
assets
)
}
}
default
:
default
:
...
@@ -143,7 +142,6 @@ func (h *interactiveHandler) Dispatch(ctx cctx.Context) {
...
@@ -143,7 +142,6 @@ func (h *interactiveHandler) Dispatch(ctx cctx.Context) {
case
strings
.
Index
(
line
,
"/"
)
==
0
:
case
strings
.
Index
(
line
,
"/"
)
==
0
:
searchWord
:=
strings
.
TrimSpace
(
line
[
1
:
])
searchWord
:=
strings
.
TrimSpace
(
line
[
1
:
])
assets
:=
h
.
searchAsset
(
searchWord
)
assets
:=
h
.
searchAsset
(
searchWord
)
h
.
searchResult
=
assets
h
.
displayAssets
(
assets
)
h
.
displayAssets
(
assets
)
case
strings
.
Index
(
line
,
"g"
)
==
0
:
case
strings
.
Index
(
line
,
"g"
)
==
0
:
searchWord
:=
strings
.
TrimSpace
(
strings
.
TrimPrefix
(
line
,
"g"
))
searchWord
:=
strings
.
TrimSpace
(
strings
.
TrimPrefix
(
line
,
"g"
))
...
@@ -151,13 +149,11 @@ func (h *interactiveHandler) Dispatch(ctx cctx.Context) {
...
@@ -151,13 +149,11 @@ func (h *interactiveHandler) Dispatch(ctx cctx.Context) {
if
num
>=
0
{
if
num
>=
0
{
assets
:=
h
.
searchNodeAssets
(
num
)
assets
:=
h
.
searchNodeAssets
(
num
)
h
.
displayAssets
(
assets
)
h
.
displayAssets
(
assets
)
h
.
searchResult
=
assets
continue
continue
}
}
}
}
default
:
default
:
assets
:=
h
.
searchAsset
(
line
)
assets
:=
h
.
searchAsset
(
line
)
h
.
searchResult
=
assets
h
.
displayAssetsOrProxy
(
assets
)
h
.
displayAssetsOrProxy
(
assets
)
}
}
}
}
...
@@ -229,6 +225,11 @@ func (h *interactiveHandler) displayAssets(assets model.AssetList) {
...
@@ -229,6 +225,11 @@ func (h *interactiveHandler) displayAssets(assets model.AssetList) {
h
.
systemUserSelect
=
&
systemUser
h
.
systemUserSelect
=
&
systemUser
h
.
Proxy
(
context
.
TODO
())
h
.
Proxy
(
context
.
TODO
())
}
}
if
pag
.
page
.
GetPageSize
()
>=
pag
.
page
.
TotalCount
()
{
h
.
searchResult
=
assets
}
else
{
h
.
searchResult
=
h
.
searchResult
[
:
0
]
}
}
}
}
}
...
@@ -263,14 +264,22 @@ func (h *interactiveHandler) loadUserAssetNodes() {
...
@@ -263,14 +264,22 @@ func (h *interactiveHandler) loadUserAssetNodes() {
}
}
func
(
h
*
interactiveHandler
)
searchAsset
(
key
string
)
(
assets
[]
model
.
Asset
)
{
func
(
h
*
interactiveHandler
)
searchAsset
(
key
string
)
(
assets
[]
model
.
Asset
)
{
if
indexNum
,
err
:=
strconv
.
Atoi
(
key
);
err
==
nil
{
if
indexNum
,
err
:=
strconv
.
Atoi
(
key
);
err
==
nil
&&
len
(
h
.
searchResult
)
>
0
{
if
indexNum
>
0
&&
indexNum
<=
len
(
h
.
searchResult
)
{
if
indexNum
>
0
&&
indexNum
<=
len
(
h
.
searchResult
)
{
assets
=
[]
model
.
Asset
{
h
.
searchResult
[
indexNum
-
1
]}
assets
=
[]
model
.
Asset
{
h
.
searchResult
[
indexNum
-
1
]}
return
return
}
}
}
}
for
_
,
assetValue
:=
range
h
.
searchResult
{
var
searchData
[]
model
.
Asset
contents
:=
[]
string
{
assetValue
.
Ip
,
assetValue
.
Hostname
,
assetValue
.
Comment
}
switch
len
(
h
.
searchResult
)
{
case
0
:
searchData
=
h
.
assets
default
:
searchData
=
h
.
searchResult
}
for
_
,
assetValue
:=
range
searchData
{
contents
:=
[]
string
{
assetValue
.
Hostname
,
assetValue
.
Ip
,
assetValue
.
Comment
}
if
isSubstring
(
contents
,
key
)
{
if
isSubstring
(
contents
,
key
)
{
assets
=
append
(
assets
,
assetValue
)
assets
=
append
(
assets
,
assetValue
)
}
}
...
...
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