diff --git a/CHANGELOG.md b/CHANGELOG.md
index 72d97aa2f98..de405e1232b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -17,6 +17,7 @@
**Breaking changes**
- [Issue #1928](https://github.com/grafana/grafana/issues/1928). HTTP API: GET /api/dashboards/db/:slug response changed property `model` to `dashboard` to match the POST request nameing
- Backend render URL changed from `/render/dashboard/solo` `render/dashboard-solo/` (in order to have consistent dashboard url `/dashboard/:type/:slug`)
+- Search HTTP API response has changed (simplified), tags list moved to seperate HTTP resource URI
# 2.0.3 (unreleased - 2.0.x branch)
diff --git a/pkg/api/api.go b/pkg/api/api.go
index 7213be5fe87..14e693752b9 100644
--- a/pkg/api/api.go
+++ b/pkg/api/api.go
@@ -102,6 +102,7 @@ func Register(r *macaron.Macaron) {
r.Post("/db", reqEditorRole, bind(m.SaveDashboardCommand{}), PostDashboard)
r.Get("/file/:file", GetDashboardFromJsonFile)
r.Get("/home", GetHomeDashboard)
+ r.Get("/tags", GetDashboardTags)
})
// Search
diff --git a/pkg/api/dashboard.go b/pkg/api/dashboard.go
index 9de62566d4a..3f05d53f3b5 100644
--- a/pkg/api/dashboard.go
+++ b/pkg/api/dashboard.go
@@ -140,3 +140,14 @@ func GetDashboardFromJsonFile(c *middleware.Context) {
c.JSON(200, &dash)
}
+
+func GetDashboardTags(c *middleware.Context) {
+ query := m.GetDashboardTagsQuery{OrgId: c.OrgId}
+ err := bus.Dispatch(&query)
+ if err != nil {
+ c.JsonApiErr(500, "Failed to get tags from database", err)
+ return
+ }
+
+ c.JSON(200, query.Result)
+}
diff --git a/pkg/api/search.go b/pkg/api/search.go
index 588708e2de9..68b24fca38e 100644
--- a/pkg/api/search.go
+++ b/pkg/api/search.go
@@ -3,14 +3,12 @@ package api
import (
"github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/middleware"
- m "github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/search"
)
func Search(c *middleware.Context) {
query := c.Query("query")
tag := c.Query("tag")
- tagcloud := c.Query("tagcloud")
starred := c.Query("starred")
limit := c.QueryInt("limit")
@@ -18,41 +16,20 @@ func Search(c *middleware.Context) {
limit = 200
}
- result := m.SearchResult{
- Dashboards: []*m.DashboardSearchHit{},
- Tags: []*m.DashboardTagCloudItem{},
+ searchQuery := search.Query{
+ Title: query,
+ Tag: tag,
+ UserId: c.UserId,
+ Limit: limit,
+ IsStarred: starred == "true",
+ OrgId: c.OrgId,
}
- if tagcloud == "true" {
-
- query := m.GetDashboardTagsQuery{OrgId: c.OrgId}
- err := bus.Dispatch(&query)
- if err != nil {
- c.JsonApiErr(500, "Failed to get tags from database", err)
- return
- }
- result.Tags = query.Result
- result.TagsOnly = true
-
- } else {
-
- query := search.Query{
- Title: query,
- Tag: tag,
- UserId: c.UserId,
- Limit: limit,
- IsStarred: starred == "true",
- OrgId: c.OrgId,
- }
-
- err := bus.Dispatch(&query)
- if err != nil {
- c.JsonApiErr(500, "Search failed", err)
- return
- }
-
- result.Dashboards = query.Result
+ err := bus.Dispatch(&searchQuery)
+ if err != nil {
+ c.JsonApiErr(500, "Search failed", err)
+ return
}
- c.JSON(200, result)
+ c.JSON(200, searchQuery.Result)
}
diff --git a/pkg/services/search/json_index.go b/pkg/services/search/json_index.go
index c08dece7e71..ac8482f77e1 100644
--- a/pkg/services/search/json_index.go
+++ b/pkg/services/search/json_index.go
@@ -24,11 +24,10 @@ type JsonDashIndexItem struct {
}
func NewJsonDashIndex(path string, orgIds string) *JsonDashIndex {
+ log.Info("Creating json dashboard index for path: ", path)
+
index := JsonDashIndex{}
index.path = path
- // if orgIds != "" || orgIds != "*" {
- // }
-
index.updateIndex()
return &index
}
@@ -37,8 +36,21 @@ func (index *JsonDashIndex) Search(query *Query) ([]*m.DashboardSearchHit, error
results := make([]*m.DashboardSearchHit, 0)
for _, item := range index.items {
+ if len(results) > query.Limit {
+ break
+ }
+
+ // filter out results with tag filter
+ if query.Tag != "" {
+ if !strings.Contains(item.TagsCsv, query.Tag) {
+ continue
+ }
+ }
+
+ // add results with matchig title filter
if strings.Contains(item.TitleLower, query.Title) {
results = append(results, &m.DashboardSearchHit{
+ Type: m.DashTypeJson,
Title: item.Dashboard.Title,
Tags: item.Dashboard.GetTags(),
Uri: "file/" + item.Path,
@@ -60,7 +72,6 @@ func (index *JsonDashIndex) GetDashboard(path string) *m.Dashboard {
}
func (index *JsonDashIndex) updateIndex() error {
- log.Info("Updating JSON dashboard index, path: %v", index.path)
index.items = make([]*JsonDashIndexItem, 0)
diff --git a/pkg/services/sqlstore/dashboard.go b/pkg/services/sqlstore/dashboard.go
index 9cd56bab7b5..56e462fe2f6 100644
--- a/pkg/services/sqlstore/dashboard.go
+++ b/pkg/services/sqlstore/dashboard.go
@@ -176,6 +176,7 @@ func SearchDashboards(query *m.SearchDashboardsQuery) error {
Id: item.Id,
Title: item.Title,
Uri: "db/" + item.Slug,
+ Type: m.DashTypeDB,
Tags: []string{},
}
query.Result = append(query.Result, hit)
diff --git a/public/app/controllers/search.js b/public/app/controllers/search.js
index c013b829e54..c4785c6dd8f 100644
--- a/public/app/controllers/search.js
+++ b/public/app/controllers/search.js
@@ -61,21 +61,21 @@ function (angular, _, config) {
};
$scope.searchDashboards = function() {
+ $scope.tagsMode = false;
$scope.currentSearchId = $scope.currentSearchId + 1;
var localSearchId = $scope.currentSearchId;
return backendSrv.search($scope.query).then(function(results) {
if (localSearchId < $scope.currentSearchId) { return; }
- $scope.resultCount = results.tagsOnly ? results.tags.length : results.dashboards.length;
- $scope.results.tags = results.tags;
- $scope.results.dashboards = _.map(results.dashboards, function(dash) {
+ $scope.resultCount = results.length;
+ $scope.results = _.map(results, function(dash) {
dash.url = 'dashboard/' + dash.uri;
return dash;
});
if ($scope.queryHasNoFilters()) {
- $scope.results.dashboards.unshift({ title: 'Home', url: config.appSubUrl + '/', isHome: true });
+ $scope.results.unshift({ title: 'Home', url: config.appSubUrl + '/', isHome: true });
}
});
};
@@ -96,10 +96,12 @@ function (angular, _, config) {
}
};
- $scope.showTags = function() {
- $scope.query.tagcloud = !$scope.query.tagcloud;
- $scope.giveSearchFocus = $scope.giveSearchFocus + 1;
- $scope.search();
+ $scope.getTags = function() {
+ $scope.tagsMode = true;
+ return backendSrv.get('/api/dashboards/tags').then(function(results) {
+ $scope.resultCount = results.length;
+ $scope.results = results;
+ });
};
$scope.showStarred = function() {
diff --git a/public/app/features/dashboard/dashboardCtrl.js b/public/app/features/dashboard/dashboardCtrl.js
index 3d2b3edbaab..ffead046211 100644
--- a/public/app/features/dashboard/dashboardCtrl.js
+++ b/public/app/features/dashboard/dashboardCtrl.js
@@ -70,7 +70,7 @@ function (angular, $, config) {
};
$scope.updateTopNavPartial = function() {
- if ($scope.dashboard.meta.type === 'snapshot') {
+ if ($scope.dashboard.meta.isSnapshot) {
$scope.topNavPartial = 'app/features/dashboard/partials/snapshotTopNav.html';
}
};
diff --git a/public/app/partials/search.html b/public/app/partials/search.html
index 85383042a21..ad1dcf0d1ba 100644
--- a/public/app/partials/search.html
+++ b/public/app/partials/search.html
@@ -11,8 +11,8 @@
starred
|
-
-
+
+
tags
@@ -25,10 +25,10 @@
-
+
-
-
No dashboards matching your query were found.
+