update widget struct
This commit is contained in:
parent
b349c66b14
commit
14f391b58b
|
@ -8,34 +8,6 @@ import "infini.sh/framework/core/orm"
|
|||
|
||||
type Widget struct {
|
||||
orm.ORMObjectBase
|
||||
Formatter string `json:"formatter" elastic_mapping:"formatter: { type: keyword }"`
|
||||
Series [] WidgetSeriesItem `json:"series" elastic_mapping:"series: { type: object,enabled:false }"`
|
||||
Title string `json:"title" elastic_mapping:"title: { type: text }"`
|
||||
}
|
||||
|
||||
type WidgetSeriesItem struct {
|
||||
Metric WidgetMetric `json:"metric"`
|
||||
Queries WidgetQuery `json:"queries"`
|
||||
Type string `json:"type"`
|
||||
}
|
||||
|
||||
type WidgetQuery struct {
|
||||
ClusterId string `json:"cluster_id"`
|
||||
Indices []string `json:"indices"`
|
||||
Query string `json:"query"`
|
||||
TimeField string `json:"time_field"`
|
||||
}
|
||||
type WidgetMetric struct {
|
||||
BucketSize string `json:"bucket_size"`
|
||||
FormatType string `json:"format_type"`
|
||||
Formula string `json:"formula"`
|
||||
Groups []struct {
|
||||
Field string `json:"field"`
|
||||
Limit int `json:"limit"`
|
||||
} `json:"groups"`
|
||||
Items []struct {
|
||||
Field string `json:"field"`
|
||||
Name string `json:"name"`
|
||||
Statistic string `json:"statistic"`
|
||||
} `json:"items"`
|
||||
Config interface{}`json:"config" elastic_mapping:"config: { type: object,enabled:false }"`
|
||||
}
|
||||
|
|
|
@ -29,4 +29,5 @@ func InitAPI() {
|
|||
api.HandleAPIMethod(api.GET, "/insight/dashboard/_search", insight.searchDashboard)
|
||||
api.HandleAPIMethod(api.POST, "/elasticsearch/:id/map_label/_render", insight.renderMapLabelTemplate)
|
||||
api.HandleAPIMethod(api.GET, "/insight/widget/:widget_id", insight.getWidget)
|
||||
api.HandleAPIMethod(api.POST, "/insight/widget", insight.RequireLogin(insight.createWidget))
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
package insight
|
||||
|
||||
import (
|
||||
log "github.com/cihub/seelog"
|
||||
"infini.sh/console/model/insight"
|
||||
httprouter "infini.sh/framework/core/api/router"
|
||||
"infini.sh/framework/core/orm"
|
||||
|
@ -12,6 +13,25 @@ import (
|
|||
"net/http"
|
||||
)
|
||||
|
||||
func (h *InsightAPI) createWidget(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
||||
var obj = &insight.Widget{}
|
||||
err := h.DecodeJSON(req, obj)
|
||||
if err != nil {
|
||||
h.WriteError(w, err.Error(), http.StatusInternalServerError)
|
||||
log.Error(err)
|
||||
return
|
||||
}
|
||||
err = orm.Create(nil, obj)
|
||||
if err != nil {
|
||||
h.WriteError(w, err.Error(), http.StatusInternalServerError)
|
||||
log.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
h.WriteCreatedOKJSON(w, obj.ID)
|
||||
|
||||
}
|
||||
|
||||
func (h *InsightAPI) getWidget(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
||||
id := ps.MustGetParameter("widget_id")
|
||||
|
||||
|
@ -27,9 +47,5 @@ func (h *InsightAPI) getWidget(w http.ResponseWriter, req *http.Request, ps http
|
|||
return
|
||||
}
|
||||
|
||||
h.WriteJSON(w, util.MapStr{
|
||||
"found": true,
|
||||
"_id": id,
|
||||
"_source": obj,
|
||||
}, 200)
|
||||
h.WriteGetOKJSON(w, id, obj)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue