浏览代码

Added limit to dashboard list panel and search

Torkel Ödegaard 11 年之前
父节点
当前提交
8e1b753664

+ 6 - 0
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,
 		}

+ 1 - 0
pkg/models/search.go

@@ -25,6 +25,7 @@ type SearchDashboardsQuery struct {
 	Tag       string
 	AccountId int64
 	UserId    int64
+	Limit     int
 	IsStarred bool
 
 	Result []*DashboardSearchHit

+ 3 - 0
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 {

+ 4 - 4
src/app/features/account/partials/import.html

@@ -19,18 +19,18 @@
 			<div class="section">
 				<div class="tight-form">
 					<ul class="tight-form-list">
-						<li class="tight-form-item" style="width: 160px">
+						<li class="tight-form-item" style="width: 150px">
 							<strong>Dashboard source</strong>
 						</li>
 						<li>
-							<select type="text" ng-model="sourceName" class="input-small tight-form-input" ng-options="f for f in datasources">
+							<select type="text" ng-model="sourceName" class="input-medium tight-form-input" ng-options="f for f in datasources">
 							</select>
 						</li>
-						<li class="tight-form-item" style="width: 160px">
+						<li class="tight-form-item">
 							<strong>Destination</strong>
 						</li>
 						<li>
-							<select type="text" ng-model="destName" class="input-small tight-form-input" ng-options="f for f in datasources">
+							<select type="text" ng-model="destName" class="input-medium tight-form-input" ng-options="f for f in datasources">
 							</select>
 						</li>
 						<li>

+ 16 - 0
src/app/panels/dashlist/editor.html

@@ -39,3 +39,19 @@
 	</div>
 </div>
 
+<div class="editor-row">
+	<div class="section" style="margin-bottom: 20px">
+		<div class="tight-form">
+			<ul class="tight-form-list">
+				<li class="tight-form-item" style="width: 110px">
+					<strong>Limit number to</strong>
+				</li>
+				<li>
+					<input class="input-small tight-form-input" type="number" ng-model="panel.limit" ng-model-onblur ng-change="get_data">
+				</li>
+			</ul>
+			<div class="clearfix"></div>
+		</div>
+	</div>
+</div>
+

+ 4 - 1
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 {