Removed use of absolute urls in dashboard search and dashlist, root_url option is now not required, it is required if you use oauth or proxy grafana under suburl, #1483

This commit is contained in:
Torkel Ödegaard 2015-02-17 18:43:37 +01:00
parent 946afccbb5
commit 26eb6e559e
4 changed files with 11 additions and 18 deletions

View File

@ -4,7 +4,6 @@ import (
"github.com/grafana/grafana/pkg/bus" "github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/middleware" "github.com/grafana/grafana/pkg/middleware"
m "github.com/grafana/grafana/pkg/models" m "github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/setting"
) )
// TODO: this needs to be cached or improved somehow // TODO: this needs to be cached or improved somehow
@ -76,9 +75,6 @@ func Search(c *middleware.Context) {
} }
result.Dashboards = query.Result result.Dashboards = query.Result
for _, dash := range result.Dashboards {
dash.Url = setting.ToAbsUrl("dashboard/db/" + dash.Slug)
}
} }
c.JSON(200, result) c.JSON(200, result)

View File

@ -11,7 +11,6 @@ type DashboardSearchHit struct {
Title string `json:"title"` Title string `json:"title"`
Slug string `json:"slug"` Slug string `json:"slug"`
Tags []string `json:"tags"` Tags []string `json:"tags"`
Url string `json:"url"`
IsStarred bool `json:"isStarred"` IsStarred bool `json:"isStarred"`
} }

View File

@ -48,7 +48,7 @@ function (angular, _, config) {
var selectedDash = $scope.results.dashboards[$scope.selectedIndex]; var selectedDash = $scope.results.dashboards[$scope.selectedIndex];
if (selectedDash) { if (selectedDash) {
$location.search({}); $location.search({});
$location.path("/dashboard/db/" + selectedDash.slug); $location.path(selectedDash.url);
} }
} }
}; };
@ -57,11 +57,6 @@ function (angular, _, config) {
$scope.selectedIndex = Math.max(Math.min($scope.selectedIndex + direction, $scope.resultCount - 1), 0); $scope.selectedIndex = Math.max(Math.min($scope.selectedIndex + direction, $scope.resultCount - 1), 0);
}; };
$scope.goToDashboard = function(slug) {
$location.search({});
$location.path("/dashboard/db/" + slug);
};
$scope.searchDashboards = function() { $scope.searchDashboards = function() {
$scope.currentSearchId = $scope.currentSearchId + 1; $scope.currentSearchId = $scope.currentSearchId + 1;
var localSearchId = $scope.currentSearchId; var localSearchId = $scope.currentSearchId;
@ -70,13 +65,16 @@ function (angular, _, config) {
.then(function(results) { .then(function(results) {
if (localSearchId < $scope.currentSearchId) { return; } if (localSearchId < $scope.currentSearchId) { return; }
if ($scope.query.query === "" && !$scope.query.starred) {
results.dashboards.unshift({ title: 'Home', url: config.appSubUrl + '/', isHome: true });
}
$scope.results.dashboards = results.dashboards;
$scope.results.tags = results.tags;
$scope.resultCount = results.tagsOnly ? results.tags.length : results.dashboards.length; $scope.resultCount = results.tagsOnly ? results.tags.length : results.dashboards.length;
$scope.results.tags = results.tags;
$scope.results.dashboards = _.map(results.dashboards, function(dash) {
dash.url = 'dashboard/db/' + dash.slug;
return dash;
});
if ($scope.query.query === "" && !$scope.query.starred) {
$scope.results.dashboards.unshift({ title: 'Home', url: config.appSubUrl + '/', isHome: true });
}
}); });
}; };

View File

@ -1,7 +1,7 @@
<grafana-panel> <grafana-panel>
<div class="dashlist"> <div class="dashlist">
<div class="dashlist-item" ng-repeat="dash in dashList"> <div class="dashlist-item" ng-repeat="dash in dashList">
<a class="dashlist-link" href="{{dash.url}}"> <a class="dashlist-link" href="dashboard/db/{{dash.slug}}">
<span class="dashlist-title"> <span class="dashlist-title">
{{dash.title}} {{dash.title}}
</span> </span>