Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DiDi
nightingale
提交
f651af97
N
nightingale
项目概览
DiDi
/
nightingale
10 个月 前同步成功
通知
46
Star
7053
Fork
1161
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
N
nightingale
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
f651af97
编写于
8月 18, 2021
作者:
I
Istil
提交者:
GitHub
8月 18, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: support classpaths prefix tree display (#769)
上级
1eecb324
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
119 addition
and
2 deletion
+119
-2
http/router.go
http/router.go
+4
-0
http/router_classpath.go
http/router_classpath.go
+15
-0
models/classpath.go
models/classpath.go
+100
-2
未找到文件。
http/router.go
浏览文件 @
f651af97
...
...
@@ -83,6 +83,8 @@ func configRoutes(r *gin.Engine) {
pages
.
DELETE
(
"/user-group/:id"
,
login
(),
userGroupDel
)
pages
.
GET
(
"/classpaths"
,
login
(),
classpathListGets
)
pages
.
GET
(
"/classpaths/tree"
,
login
(),
classpathListNodeGets
)
pages
.
GET
(
"/classpaths/tree-node/:id"
,
login
(),
classpathListNodeGetsById
)
pages
.
POST
(
"/classpaths"
,
login
(),
classpathAdd
)
pages
.
PUT
(
"/classpath/:id"
,
login
(),
classpathPut
)
pages
.
DELETE
(
"/classpath/:id"
,
login
(),
classpathDel
)
...
...
@@ -213,6 +215,8 @@ func configRoutes(r *gin.Engine) {
v1
.
DELETE
(
"/user-group/:id"
,
login
(),
userGroupDel
)
v1
.
GET
(
"/classpaths"
,
login
(),
classpathListGets
)
v1
.
GET
(
"/classpaths/tree"
,
login
(),
classpathListNodeGets
)
v1
.
GET
(
"/classpaths/tree-node/:id"
,
login
(),
classpathListNodeGetsById
)
v1
.
POST
(
"/classpaths"
,
login
(),
classpathAdd
)
v1
.
PUT
(
"/classpath/:id"
,
login
(),
classpathPut
)
v1
.
DELETE
(
"/classpath/:id"
,
login
(),
classpathDel
)
...
...
http/router_classpath.go
浏览文件 @
f651af97
...
...
@@ -24,6 +24,21 @@ func classpathListGets(c *gin.Context) {
},
nil
)
}
func
classpathListNodeGets
(
c
*
gin
.
Context
)
{
query
:=
queryStr
(
c
,
"query"
,
""
)
list
,
err
:=
models
.
ClasspathNodeGets
(
query
)
dangerous
(
err
)
renderData
(
c
,
list
,
nil
)
}
func
classpathListNodeGetsById
(
c
*
gin
.
Context
)
{
cp
:=
Classpath
(
urlParamInt64
(
c
,
"id"
))
children
,
err
:=
cp
.
DirectChildren
()
renderData
(
c
,
children
,
err
)
}
func
classpathFavoriteGet
(
c
*
gin
.
Context
)
{
lst
,
err
:=
loginUser
(
c
)
.
FavoriteClasspaths
()
renderData
(
c
,
lst
,
err
)
...
...
models/classpath.go
浏览文件 @
f651af97
...
...
@@ -19,6 +19,14 @@ type Classpath struct {
UpdateBy
string
`json:"update_by"`
}
type
ClasspathNode
struct
{
Id
int64
`json:"id"`
Path
string
`json:"path"`
Note
string
`json:"note"`
Preset
int
`json:"preset"`
Children
[]
*
ClasspathNode
`json:"children"`
}
func
(
c
*
Classpath
)
TableName
()
string
{
return
"classpath"
}
...
...
@@ -104,7 +112,6 @@ func ClasspathGets(query string, limit, offset int) ([]Classpath, error) {
q
:=
"%"
+
query
+
"%"
session
=
session
.
Where
(
"path like ?"
,
q
)
}
var
objs
[]
Classpath
err
:=
session
.
Find
(
&
objs
)
if
err
!=
nil
{
...
...
@@ -151,7 +158,7 @@ func ClasspathGet(where string, args ...interface{}) (*Classpath, error) {
func
ClasspathGetsByPrefix
(
prefix
string
)
([]
Classpath
,
error
)
{
var
objs
[]
Classpath
err
:=
DB
.
Where
(
"path like ?"
,
prefix
+
"%"
)
.
Find
(
&
objs
)
err
:=
DB
.
Where
(
"path like ?"
,
prefix
+
"%"
)
.
OrderBy
(
"path"
)
.
Find
(
&
objs
)
if
err
!=
nil
{
logger
.
Errorf
(
"mysql.error: query classpath fail: %v"
,
err
)
return
objs
,
internalServerError
...
...
@@ -218,3 +225,94 @@ func (c *Classpath) AddResources(idents []string) error {
func
(
c
*
Classpath
)
DelResources
(
idents
[]
string
)
error
{
return
ClasspathResourceDel
(
c
.
Id
,
idents
)
}
func
ClasspathNodeGets
(
query
string
)
([]
*
ClasspathNode
,
error
)
{
session
:=
DB
.
OrderBy
(
"path"
)
if
query
!=
""
{
q
:=
"%"
+
query
+
"%"
session
=
session
.
Where
(
"path like ?"
,
q
)
}
var
objs
[]
Classpath
err
:=
session
.
Find
(
&
objs
)
if
err
!=
nil
{
logger
.
Errorf
(
"mysql.error: query classpath fail: %v"
,
err
)
return
[]
*
ClasspathNode
{},
internalServerError
}
if
len
(
objs
)
==
0
{
return
[]
*
ClasspathNode
{},
nil
}
pcs
:=
ClasspathNodeAllChildren
(
objs
)
return
pcs
,
nil
}
func
(
cp
*
Classpath
)
DirectChildren
()
([]
Classpath
,
error
)
{
var
pcs
[]
Classpath
objs
,
err
:=
ClasspathGetsByPrefix
(
cp
.
Path
)
if
err
!=
nil
{
logger
.
Errorf
(
"mysql.error: query prefix classpath fail: %v"
,
err
)
return
[]
Classpath
{},
internalServerError
}
if
len
(
objs
)
<
2
{
return
[]
Classpath
{},
nil
}
pre
:=
objs
[
1
]
path
:=
pre
.
Path
[
len
(
objs
[
0
]
.
Path
)
:
]
pre
.
Path
=
path
pcs
=
append
(
pcs
,
pre
)
for
_
,
cp
:=
range
objs
[
2
:
]
{
has
:=
strings
.
HasPrefix
(
cp
.
Path
,
pre
.
Path
)
if
!
has
{
path
:=
cp
.
Path
[
len
(
objs
[
0
]
.
Path
)
:
]
pre
.
Path
=
path
pcs
=
append
(
pcs
,
pre
)
pre
=
cp
}
}
return
pcs
,
nil
}
func
ClasspathNodeAllChildren
(
cps
[]
Classpath
)
[]
*
ClasspathNode
{
var
node
ClasspathNode
for
_
,
cp
:=
range
cps
{
ListInsert
(
cp
,
&
node
)
}
return
node
.
Children
}
func
ListInsert
(
obj
Classpath
,
node
*
ClasspathNode
)
{
path
:=
obj
.
Path
has
:=
true
for
{
if
len
(
node
.
Children
)
==
0
{
break
}
children
:=
node
.
Children
[
len
(
node
.
Children
)
-
1
]
prefix
:=
children
.
Path
has
=
strings
.
HasPrefix
(
path
,
prefix
)
if
!
has
{
break
}
path
=
path
[
len
(
prefix
)
:
]
node
=
children
}
newNode
:=
ToClasspathNode
(
obj
,
path
)
node
.
Children
=
append
(
node
.
Children
,
&
newNode
)
}
func
ToClasspathNode
(
cp
Classpath
,
path
string
)
ClasspathNode
{
var
obj
ClasspathNode
obj
.
Id
=
cp
.
Id
obj
.
Path
=
path
obj
.
Note
=
cp
.
Note
obj
.
Preset
=
cp
.
Preset
obj
.
Children
=
[]
*
ClasspathNode
{}
return
obj
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录