From 8e1b75366446a63a735538efc95b67aa1bd66f54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Thu, 5 Feb 2015 11:10:56 +0100 Subject: [PATCH] Added limit to dashboard list panel and search --- pkg/api/search.go | 6 ++++++ pkg/models/search.go | 1 + pkg/services/sqlstore/dashboard.go | 3 +++ src/app/features/account/partials/import.html | 8 ++++---- src/app/panels/dashlist/editor.html | 16 ++++++++++++++++ src/app/panels/dashlist/module.js | 5 ++++- 6 files changed, 34 insertions(+), 5 deletions(-) diff --git a/pkg/api/search.go b/pkg/api/search.go index b1ae9bcc241..b848d2a097c 100644 --- a/pkg/api/search.go +++ b/pkg/api/search.go @@ -33,6 +33,11 @@ func setIsStarredFlagOnSearchResults(c *middleware.Context, hits []*m.DashboardS func Search(c *middleware.Context) { queryText := c.Query("q") starred := c.Query("starred") + limit := c.QueryInt("limit") + + if limit == 0 { + limit = 200 + } result := m.SearchResult{ Dashboards: []*m.DashboardSearchHit{}, @@ -58,6 +63,7 @@ func Search(c *middleware.Context) { Title: matches[3], Tag: matches[2], UserId: c.UserId, + Limit: limit, IsStarred: starred == "1", AccountId: c.AccountId, } diff --git a/pkg/models/search.go b/pkg/models/search.go index e23b5dbd5aa..4f5b24ff084 100644 --- a/pkg/models/search.go +++ b/pkg/models/search.go @@ -25,6 +25,7 @@ type SearchDashboardsQuery struct { Tag string AccountId int64 UserId int64 + Limit int IsStarred bool Result []*DashboardSearchHit diff --git a/pkg/services/sqlstore/dashboard.go b/pkg/services/sqlstore/dashboard.go index f9668731ab5..b3c0495a42f 100644 --- a/pkg/services/sqlstore/dashboard.go +++ b/pkg/services/sqlstore/dashboard.go @@ -2,6 +2,7 @@ package sqlstore import ( "bytes" + "fmt" "github.com/go-xorm/xorm" "github.com/grafana/grafana/pkg/bus" @@ -116,6 +117,8 @@ func SearchDashboards(query *m.SearchDashboardsQuery) error { params = append(params, query.Tag) } + sql.WriteString(fmt.Sprintf(" LIMIT %d", query.Limit)) + var res []DashboardSearchProjection err := x.Sql(sql.String(), params...).Find(&res) if err != nil { diff --git a/src/app/features/account/partials/import.html b/src/app/features/account/partials/import.html index 28c695ca068..f94b5e7c7e8 100644 --- a/src/app/features/account/partials/import.html +++ b/src/app/features/account/partials/import.html @@ -19,18 +19,18 @@
    -
  • +
  • Dashboard source
  • -
  • -
  • +
  • Destination
  • -
  • diff --git a/src/app/panels/dashlist/editor.html b/src/app/panels/dashlist/editor.html index 87a00132827..a6de7570f07 100644 --- a/src/app/panels/dashlist/editor.html +++ b/src/app/panels/dashlist/editor.html @@ -39,3 +39,19 @@
+
+
+
+
    +
  • + Limit number to +
  • +
  • + +
  • +
+
+
+
+
+ diff --git a/src/app/panels/dashlist/module.js b/src/app/panels/dashlist/module.js index 7dd3aebcc4e..a0f773956bc 100644 --- a/src/app/panels/dashlist/module.js +++ b/src/app/panels/dashlist/module.js @@ -31,6 +31,7 @@ function (angular, app, _, config, PanelMeta) { var defaults = { mode: 'starred', query: '', + limit: 10, tag: '', }; @@ -51,7 +52,9 @@ function (angular, app, _, config, PanelMeta) { }; $scope.get_data = function() { - var params = {}; + var params = { + limit: $scope.panel.limit + }; if ($scope.panel.mode === 'starred') { params.starred = 1; } else {