| @@ -15,27 +15,17 @@ type listReq struct { | |||||
| Name string `json:"name"` | Name string `json:"name"` | ||||
| Type string `json:"plugin_type"` | Type string `json:"plugin_type"` | ||||
| Category string `json:"category"` | Category string `json:"category"` | ||||
| Limit int `json:"limit"` | |||||
| P int `json:"p"` | |||||
| } | } | ||||
| func (rt *Router) datasourceList(c *gin.Context) { | func (rt *Router) datasourceList(c *gin.Context) { | ||||
| var req listReq | var req listReq | ||||
| ginx.BindJSON(c, &req) | ginx.BindJSON(c, &req) | ||||
| if req.Limit == 0 { | |||||
| req.Limit = 10 | |||||
| } | |||||
| if req.P == 0 { | |||||
| req.P = 1 | |||||
| } | |||||
| typ := req.Type | typ := req.Type | ||||
| category := req.Category | category := req.Category | ||||
| name := req.Name | name := req.Name | ||||
| limit := req.Limit | |||||
| p := req.P | |||||
| list, err := models.GetDatasourcesGetsBy(rt.Ctx, typ, category, name, limit, (p-1)*limit) | |||||
| list, err := models.GetDatasourcesGetsBy(rt.Ctx, typ, category, name, "") | |||||
| Render(c, list, err) | Render(c, list, err) | ||||
| } | } | ||||
| @@ -158,7 +158,7 @@ func GetDatasourcesCountBy(ctx *ctx.Context, typ, cate, name string) (int64, err | |||||
| return Count(session) | return Count(session) | ||||
| } | } | ||||
| func GetDatasourcesGetsBy(ctx *ctx.Context, typ, cate, name string, limit, offset int) ([]*Datasource, error) { | |||||
| func GetDatasourcesGetsBy(ctx *ctx.Context, typ, cate, name, status string) ([]*Datasource, error) { | |||||
| session := DB(ctx) | session := DB(ctx) | ||||
| if name != "" { | if name != "" { | ||||
| @@ -177,8 +177,12 @@ func GetDatasourcesGetsBy(ctx *ctx.Context, typ, cate, name string, limit, offse | |||||
| session = session.Where("category = ?", cate) | session = session.Where("category = ?", cate) | ||||
| } | } | ||||
| if status != "" { | |||||
| session = session.Where("status = ?", status) | |||||
| } | |||||
| var lst []*Datasource | var lst []*Datasource | ||||
| err := session.Order("id desc").Limit(limit).Offset(offset).Find(&lst).Error | |||||
| err := session.Order("id desc").Find(&lst).Error | |||||
| if err == nil { | if err == nil { | ||||
| for i := 0; i < len(lst); i++ { | for i := 0; i < len(lst); i++ { | ||||
| lst[i].DB2FE() | lst[i].DB2FE() | ||||
| @@ -42,7 +42,7 @@ type PromSetting struct { | |||||
| } | } | ||||
| func (pc *PromClientMap) loadFromDatabase() { | func (pc *PromClientMap) loadFromDatabase() { | ||||
| datasources, err := models.GetDatasourcesGetsBy(pc.ctx, models.PROMETHEUS, "", "", 1000, 0) | |||||
| datasources, err := models.GetDatasourcesGetsBy(pc.ctx, models.PROMETHEUS, "", "", "enabled") | |||||
| if err != nil { | if err != nil { | ||||
| logger.Errorf("failed to get datasources, error: %v", err) | logger.Errorf("failed to get datasources, error: %v", err) | ||||
| return | return | ||||