Commit b67f4dc3 by Torkel Ödegaard

Added stars to search results

parent 1e3970c6
......@@ -18,6 +18,7 @@ function (angular, _, config, $) {
$scope.query = { query: 'title:' };
$scope.db = datasourceSrv.getGrafanaDB();
$scope.currentSearchId = 0;
$scope.starsPromise = $scope.grafana.user.getStars();
// events
$scope.onAppEvent('dashboard-deleted', $scope.dashboardDeleted);
......@@ -64,38 +65,26 @@ function (angular, _, config, $) {
$scope.selectedIndex = Math.max(Math.min($scope.selectedIndex + direction, $scope.resultCount - 1), 0);
};
$scope.goToDashboard = function(id) {
$scope.goToDashboard = function(slug) {
$location.search({});
$location.path("/dashboard/db/" + id);
};
$scope.shareDashboard = function(title, id, $event) {
$event.stopPropagation();
var baseUrl = window.location.href.replace(window.location.hash,'');
$scope.share = {
title: title,
url: baseUrl + '#dashboard/db/' + encodeURIComponent(id)
};
$location.path("/dashboard/db/" + slug);
};
$scope.searchDashboards = function(queryString) {
// bookeeping for determining stale search requests
var searchId = $scope.currentSearchId + 1;
$scope.currentSearchId = searchId > $scope.currentSearchId ? searchId : $scope.currentSearchId;
$scope.currentSearchId = $scope.currentSearchId + 1;
var localSearchId = $scope.currentSearchId;
return $scope.db.searchDashboards(queryString)
.then(function(results) {
// since searches are async, it's possible that these results are not for the latest search. throw
// them away if so
if (searchId < $scope.currentSearchId) {
return;
}
$scope.tagsOnly = results.tagsOnly;
$scope.results.dashboards = results.dashboards;
$scope.results.tags = results.tags;
$scope.resultCount = results.tagsOnly ? results.tags.length : results.dashboards.length;
if (localSearchId < $scope.currentSearchId) { return; }
$scope.starsPromise.then(function(stars) {
$scope.starredIds = stars.dashboardIds;
$scope.tagsOnly = results.tagsOnly;
$scope.results.dashboards = results.dashboards;
$scope.results.tags = results.tags;
$scope.resultCount = results.tagsOnly ? results.tags.length : results.dashboards.length;
});
});
};
......@@ -125,11 +114,11 @@ function (angular, _, config, $) {
$scope.deleteDashboard = function(dash, evt) {
evt.stopPropagation();
$scope.appEvent('delete-dashboard', { id: dash.id, title: dash.title });
$scope.appEvent('delete-dashboard', { slug: dash.slug, title: dash.title });
};
$scope.dashboardDeleted = function(evt, id) {
var dash = _.findWhere($scope.results.dashboards, {id: id});
$scope.dashboardDeleted = function(evt, payload) {
var dash = _.findWhere($scope.results.dashboards, { slug: payload.slug });
$scope.results.dashboards = _.without($scope.results.dashboards, dash);
};
......
......@@ -116,10 +116,10 @@ function (angular, _, moment, config, store) {
};
$scope.deleteDashboardConfirmed = function(options) {
var id = options.id;
$scope.db.deleteDashboard(id).then(function(id) {
$scope.appEvent('dashboard-deleted', id);
$scope.appEvent('alert-success', ['Dashboard Deleted', id + ' has been deleted']);
var slug = options.slug;
$scope.db.deleteDashboard(slug).then(function() {
$scope.appEvent('dashboard-deleted', options);
$scope.appEvent('alert-success', ['Dashboard Deleted', options.title + ' has been deleted']);
}, function(err) {
$scope.appEvent('alert-error', ['Deleted failed', err]);
});
......
......@@ -61,18 +61,12 @@ function (angular, _, kbn) {
};
GrafanaDatasource.prototype.deleteDashboard = function(id) {
return backendSrv.delete('/api/dashboard/' + id)
.then(function(data) {
return data.title;
});
return backendSrv.delete('/api/dashboard/' + id);
};
GrafanaDatasource.prototype.searchDashboards = function(query) {
return backendSrv.get('/api/search/', {q: query})
.then(function(data) {
_.each(data.dashboards, function(item) {
item.id = item.slug;
});
return data;
});
};
......
......@@ -49,12 +49,9 @@
<h6 ng-hide="results.dashboards.length">No dashboards matching your query were found.</h6>
<div class="search-result-item pointer" bindonce ng-repeat="row in results.dashboards"
ng-class="{'selected': $index === selectedIndex }" ng-click="goToDashboard(row.id)">
ng-class="{'selected': $index === selectedIndex }" ng-click="goToDashboard(row.slug)">
<div class="search-result-actions small">
<a ng-click="shareDashboard(row.id, row.id, $event)" config-modal="app/partials/dashLoaderShare.html">
<i class="fa fa-share"></i> share &nbsp;&nbsp;&nbsp;
</a>
<a ng-click="deleteDashboard(row, $event)">
<i class="fa fa-remove"></i> delete
</a>
......@@ -64,6 +61,7 @@
<a ng-click="filterByTag(tag, $event)" ng-repeat="tag in row.tags" tag-color-from-name class="label label-tag">
{{tag}}
</a>
<i class="fa" ng-class="{'fa-star': starredIds[row.id], 'fa-star-o': !starredIds[row.id]}"></i>
</div>
<a class="search-result-link">
......
......@@ -7,7 +7,7 @@ function (angular, _) {
var module = angular.module('grafana.services');
module.service('userSrv', function() {
module.service('userSrv', function(backendSrv, $q) {
function User() {
if (window.grafanaBootData.user) {
......@@ -15,6 +15,16 @@ function (angular, _) {
}
}
User.prototype.getStars = function() {
if (!this.isSignedIn) {
return $q.when([]);
}
return backendSrv.get('/api/user/stars').then(function(stars) {
return stars;
});
};
this.getSignedInUser = function() {
return new User();
};
......
......@@ -35,13 +35,21 @@
}
}
.fa-star, .fa-star-o {
padding-left: 13px;
}
.fa-star {
color: @orange;
}
.search-result-link {
color: @grafanaListMainLinkColor;
.fa {
.fa-th-large {
padding-right: 10px;
color: @grafanaListHighlightContrast;
}
}
}
.search-result-item:nth-child(odd) {
background-color: @grafanaListAccent;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment