mirror of
https://github.com/grafana/grafana.git
synced 2024-12-28 18:01:40 -06:00
Added backend functionality for searching snapshots
This commit is contained in:
parent
870775e863
commit
8f067a5ed2
@ -68,9 +68,11 @@ func Register(r *macaron.Macaron) {
|
||||
r.Post("/api/user/password/reset", bind(dtos.ResetUserPasswordForm{}), wrap(ResetPassword))
|
||||
|
||||
// dashboard snapshots
|
||||
r.Post("/api/snapshots/", bind(m.CreateDashboardSnapshotCommand{}), CreateDashboardSnapshot)
|
||||
r.Get("/dashboard/snapshot/*", Index)
|
||||
r.Get("/dashboard/snapshot/*", Index)
|
||||
r.Get("/dashboard/snapshots/", reqSignedIn, Index)
|
||||
|
||||
// api for dashboard snapshots
|
||||
r.Post("/api/snapshots/", bind(m.CreateDashboardSnapshotCommand{}), CreateDashboardSnapshot)
|
||||
r.Get("/api/snapshot/shared-options/", GetSharingOptions)
|
||||
r.Get("/api/snapshots/:key", GetDashboardSnapshot)
|
||||
r.Get("/api/snapshots-delete/:key", DeleteDashboardSnapshot)
|
||||
@ -182,6 +184,11 @@ func Register(r *macaron.Macaron) {
|
||||
r.Get("/tags", GetDashboardTags)
|
||||
})
|
||||
|
||||
// dashboard snapshots
|
||||
r.Group("/dashboard/snapshots", func() {
|
||||
r.Get("/", wrap(SearchDashboardSnapshots))
|
||||
})
|
||||
|
||||
// Playlist
|
||||
r.Group("/playlists", func() {
|
||||
r.Get("/", wrap(SearchPlaylists))
|
||||
|
@ -98,3 +98,25 @@ func DeleteDashboardSnapshot(c *middleware.Context) {
|
||||
|
||||
c.JSON(200, util.DynMap{"message": "Snapshot deleted. It might take an hour before it's cleared from a CDN cache."})
|
||||
}
|
||||
|
||||
func SearchDashboardSnapshots(c *middleware.Context) Response {
|
||||
query := c.Query("query")
|
||||
limit := c.QueryInt("limit")
|
||||
|
||||
if limit == 0 {
|
||||
limit = 1000
|
||||
}
|
||||
|
||||
searchQuery := m.GetDashboardSnapshotsQuery{
|
||||
Name: query,
|
||||
Limit: limit,
|
||||
OrgId: c.OrgId,
|
||||
}
|
||||
|
||||
err := bus.Dispatch(&searchQuery)
|
||||
if err != nil {
|
||||
return ApiError(500, "Search failed", err)
|
||||
}
|
||||
|
||||
return Json(200, searchQuery.Result)
|
||||
}
|
||||
|
@ -60,6 +60,12 @@ func setIndexViewData(c *middleware.Context) (*dtos.IndexViewData, error) {
|
||||
Url: "/playlists",
|
||||
})
|
||||
|
||||
data.MainNavLinks = append(data.MainNavLinks, &dtos.NavLink{
|
||||
Text: "Snapshots",
|
||||
Icon: "fa fa-fw fa-camera-retro",
|
||||
Url: "/dashboard/snapshots",
|
||||
})
|
||||
|
||||
if c.OrgRole == m.ROLE_ADMIN {
|
||||
data.MainNavLinks = append(data.MainNavLinks, &dtos.NavLink{
|
||||
Text: "Data Sources",
|
||||
|
@ -47,3 +47,13 @@ type GetDashboardSnapshotQuery struct {
|
||||
|
||||
Result *DashboardSnapshot
|
||||
}
|
||||
|
||||
type DashboardSnapshots []*DashboardSnapshot
|
||||
|
||||
type GetDashboardSnapshotsQuery struct {
|
||||
Name string
|
||||
Limit int
|
||||
OrgId int64
|
||||
|
||||
Result DashboardSnapshots
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ func init() {
|
||||
bus.AddHandler("sql", CreateDashboardSnapshot)
|
||||
bus.AddHandler("sql", GetDashboardSnapshot)
|
||||
bus.AddHandler("sql", DeleteDashboardSnapshot)
|
||||
bus.AddHandler("sql", SearchDashboardSnapshots)
|
||||
}
|
||||
|
||||
func CreateDashboardSnapshot(cmd *m.CreateDashboardSnapshotCommand) error {
|
||||
@ -63,3 +64,19 @@ func GetDashboardSnapshot(query *m.GetDashboardSnapshotQuery) error {
|
||||
query.Result = &snapshot
|
||||
return nil
|
||||
}
|
||||
|
||||
func SearchDashboardSnapshots(query *m.GetDashboardSnapshotsQuery) error {
|
||||
var snapshots = make(m.DashboardSnapshots, 0)
|
||||
|
||||
sess := x.Limit(query.Limit)
|
||||
|
||||
if query.Name != "" {
|
||||
sess.Where("name LIKE ?", query.Name)
|
||||
}
|
||||
|
||||
sess.Where("org_id = ?", query.OrgId)
|
||||
err := sess.Find(&snapshots)
|
||||
query.Result = snapshots
|
||||
|
||||
return err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user