Skip to content

Commit

Permalink
增加模块入口控制
Browse files Browse the repository at this point in the history
  • Loading branch information
leon.chen committed Jan 29, 2021
1 parent eb5de3a commit 151e351
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 19 deletions.
9 changes: 5 additions & 4 deletions backend/controllers/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ import (
// @Success 200 {string} string "{}"
// @Router /api/v1/loki/settings/load/ [get]
func LoadSettings(c *gin.Context) {
allowSignUp, err := runtime.Cfg.Bool("users", "allow_sign_up")
if err != nil {
c.AbortWithStatusJSON(400, gin.H{"success": false, "message": fmt.Sprintf("配置加载失败:%s", err.Error())})
allowSignUp, errSign := runtime.Cfg.Bool("users", "allow_sign_up")
alertEnabled, errAlert := runtime.Cfg.Bool("global", "alert_enabled")
if errSign != nil || errAlert != nil {
c.AbortWithStatusJSON(400, gin.H{"success": false, "message": fmt.Sprintf("配置加载失败")})
return
}

c.AbortWithStatusJSON(200, gin.H{"success": true, "data": map[string]interface{}{"allowSignUp": allowSignUp}})
c.AbortWithStatusJSON(200, gin.H{"success": true, "data": map[string]interface{}{"allowSignUp": allowSignUp, "alertEnabled": alertEnabled}})
return
}
2 changes: 2 additions & 0 deletions backend/dagger.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
debug = true
; 邮件接收者,仅当未开启用户注册时生效
to =
alert_enabled = true
; 是否需要告警模块

[users]
; 允许注册
Expand Down
2 changes: 2 additions & 0 deletions production/config/dagger.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
debug = false
; 邮件接收者,仅当未开启用户注册时生效
to =
alert_enabled = true
; 是否需要告警模块

[users]
; 允许注册
Expand Down
1 change: 1 addition & 0 deletions production/kubernetes/dagger-kubernetes-install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ data:
debug = false
; 邮件接收者,仅当未开启用户注册时生效
to =
alert_enabled = true
[users]
; 允许注册
Expand Down
2 changes: 1 addition & 1 deletion ui/src/components/BaseSidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export default {
computed: {
...mapState(['sidebar', 'app', 'settings']),
items() {
return DrawerItems(this.settings.allowSignUp).children
return DrawerItems(this.settings).children
},
},
mounted() {
Expand Down
33 changes: 19 additions & 14 deletions ui/src/components/DrawerItems.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
function DrawerItems(signUp) {
function DrawerItems(settings) {
let alertBar = []
if (signUp) {
if (settings.allowSignUp) {
alertBar = [
{
text: '告警事件',
Expand Down Expand Up @@ -42,7 +42,7 @@ function DrawerItems(signUp) {
},
]
}
return {
const items = {
text: 'logs',
icon: 'notes',
children: [
Expand Down Expand Up @@ -79,19 +79,24 @@ function DrawerItems(signUp) {
},
],
},
{
heading: 'ALERTS',
},
{
icon: 'keyboard_arrow_up',
'icon-alt': 'warning',
text: '告警',
model: false,
index: 'loki-alert',
children: alertBar,
},
],
}

if (settings.alertEnabled) {
items.children.push({
heading: 'ALERTS',
})
items.children.push({
icon: 'keyboard_arrow_up',
'icon-alt': 'warning',
text: '告警',
model: false,
index: 'loki-alert',
children: alertBar,
})
}

return items
}

export default DrawerItems

0 comments on commit 151e351

Please sign in to comment.