Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DiDi
nightingale
提交
4130a5df
N
nightingale
项目概览
DiDi
/
nightingale
9 个月 前同步成功
通知
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 搜索 >>
提交
4130a5df
编写于
10月 18, 2022
作者:
U
Ulric Qin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
board: support ident field
上级
445d03e0
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
45 addition
and
2 deletion
+45
-2
src/models/board.go
src/models/board.go
+26
-0
src/webapi/config/i18n.go
src/webapi/config/i18n.go
+1
-0
src/webapi/router/router_board.go
src/webapi/router/router_board.go
+18
-2
未找到文件。
src/models/board.go
浏览文件 @
4130a5df
...
...
@@ -13,6 +13,7 @@ type Board struct {
Id
int64
`json:"id" gorm:"primaryKey"`
GroupId
int64
`json:"group_id"`
Name
string
`json:"name"`
Ident
string
`json:"ident"`
Tags
string
`json:"tags"`
CreateAt
int64
`json:"create_at"`
CreateBy
string
`json:"create_by"`
...
...
@@ -38,11 +39,36 @@ func (b *Board) Verify() error {
return
nil
}
func
(
b
*
Board
)
CanRenameIdent
(
ident
string
)
(
bool
,
error
)
{
if
ident
==
""
{
return
true
,
nil
}
cnt
,
err
:=
Count
(
DB
()
.
Model
(
b
)
.
Where
(
"ident=? and id <> ?"
,
b
.
Ident
,
b
.
Id
))
if
err
!=
nil
{
return
false
,
err
}
return
cnt
==
0
,
nil
}
func
(
b
*
Board
)
Add
()
error
{
if
err
:=
b
.
Verify
();
err
!=
nil
{
return
err
}
if
b
.
Ident
!=
""
{
// ident duplicate check
cnt
,
err
:=
Count
(
DB
()
.
Model
(
b
)
.
Where
(
"ident=?"
,
b
.
Ident
))
if
err
!=
nil
{
return
err
}
if
cnt
>
0
{
return
errors
.
New
(
"Ident duplicate"
)
}
}
now
:=
time
.
Now
()
.
Unix
()
b
.
CreateAt
=
now
b
.
UpdateAt
=
now
...
...
src/webapi/config/i18n.go
浏览文件 @
4130a5df
...
...
@@ -30,6 +30,7 @@ var (
"Name is blank"
:
"名称不能为空"
,
"Name has invalid characters"
:
"名称含有非法字符"
,
"Dashboard already exists"
:
"监控大盘已存在"
,
"Ident duplicate"
:
"英文标识已存在"
,
"No such dashboard"
:
"监控大盘不存在"
,
"AlertRule already exists"
:
"告警规则已存在,不能重复创建"
,
"No such AlertRule"
:
"告警规则不存在"
,
...
...
src/webapi/router/router_board.go
浏览文件 @
4130a5df
...
...
@@ -6,11 +6,13 @@ import (
"github.com/didi/nightingale/v5/src/models"
"github.com/gin-gonic/gin"
"github.com/google/uuid"
"github.com/toolkits/pkg/ginx"
)
type
boardForm
struct
{
Name
string
`json:"name"`
Ident
string
`json:"ident"`
Tags
string
`json:"tags"`
Configs
string
`json:"configs"`
Public
int
`json:"public"`
...
...
@@ -25,6 +27,7 @@ func boardAdd(c *gin.Context) {
board
:=
&
models
.
Board
{
GroupId
:
ginx
.
UrlParamInt64
(
c
,
"id"
),
Name
:
f
.
Name
,
Ident
:
f
.
Ident
,
Tags
:
f
.
Tags
,
Configs
:
f
.
Configs
,
CreateBy
:
me
.
Username
,
...
...
@@ -42,7 +45,8 @@ func boardAdd(c *gin.Context) {
}
func
boardGet
(
c
*
gin
.
Context
)
{
board
,
err
:=
models
.
BoardGet
(
"id = ?"
,
ginx
.
UrlParamInt64
(
c
,
"bid"
))
bid
:=
ginx
.
UrlParamStr
(
c
,
"bid"
)
board
,
err
:=
models
.
BoardGet
(
"id = ? or ident = ?"
,
bid
,
bid
)
ginx
.
Dangerous
(
err
)
if
board
==
nil
{
...
...
@@ -117,12 +121,20 @@ func boardPut(c *gin.Context) {
// check permission
bgrwCheck
(
c
,
bo
.
GroupId
)
can
,
err
:=
bo
.
CanRenameIdent
(
f
.
Ident
)
ginx
.
Dangerous
(
err
)
if
!
can
{
ginx
.
Bomb
(
http
.
StatusOK
,
"Ident duplicate"
)
}
bo
.
Name
=
f
.
Name
bo
.
Ident
=
f
.
Ident
bo
.
Tags
=
f
.
Tags
bo
.
UpdateBy
=
me
.
Username
bo
.
UpdateAt
=
time
.
Now
()
.
Unix
()
err
:=
bo
.
Update
(
"name
"
,
"tags"
,
"update_by"
,
"update_at"
)
err
=
bo
.
Update
(
"name"
,
"ident
"
,
"tags"
,
"update_by"
,
"update_at"
)
ginx
.
NewRender
(
c
)
.
Data
(
bo
,
err
)
}
...
...
@@ -186,6 +198,10 @@ func boardClone(c *gin.Context) {
UpdateBy
:
me
.
Username
,
}
if
bo
.
Ident
!=
""
{
newBoard
.
Ident
=
uuid
.
NewString
()
}
ginx
.
Dangerous
(
newBoard
.
Add
())
// clone payload
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录