Commit 606c7516 by bergquist

feat(dashlist): add support for scripted dashboards

- dashlist will only show dashboards from same org
- notfound dashboards will not be added

closes #4207
parent c6768a93
......@@ -6,8 +6,9 @@ define([
'app/core/utils/kbn',
'app/core/utils/datemath',
'./impression_store',
'app/core/config',
],
function (angular, moment, _, $, kbn, dateMath, impressionStore) {
function (angular, moment, _, $, kbn, dateMath, impressionStore, config) {
'use strict';
var module = angular.module('grafana.services');
......@@ -20,8 +21,12 @@ function (angular, moment, _, $, kbn, dateMath, impressionStore) {
$rootScope) {
var self = this;
this._dashboardLoadFailed = function(title) {
return {meta: {canStar: false, canDelete: false, canSave: false}, dashboard: {title: title}};
this._dashboardLoadFailed = function(title, snapshot) {
snapshot = snapshot || false;
return {
meta: { canStar: false, isSnapshot: snapshot, canDelete: false, canSave: false, canEdit: false, dashboardNotFound: true },
dashboard: {title: title }
};
};
this.loadDashboard = function(type, slug) {
......@@ -30,9 +35,10 @@ function (angular, moment, _, $, kbn, dateMath, impressionStore) {
if (type === 'script') {
promise = this._loadScriptedDashboard(slug);
} else if (type === 'snapshot') {
promise = backendSrv.get('/api/snapshots/' + $routeParams.slug).catch(function() {
return {meta:{isSnapshot: true, canSave: false, canEdit: false}, dashboard: {title: 'Snapshot not found'}};
});
promise = backendSrv.get('/api/snapshots/' + $routeParams.slug)
.catch(function() {
return self._dashboardLoadFailed("Snapshot not found", true);
});
} else {
promise = backendSrv.getDashboard($routeParams.type, $routeParams.slug)
.catch(function() {
......@@ -41,7 +47,15 @@ function (angular, moment, _, $, kbn, dateMath, impressionStore) {
}
promise.then(function(result) {
impressionStore.impressions.addDashboardImpression(result);
if (result.meta.dashboardNotFound !== true) {
impressionStore.impressions.addDashboardImpression({
type: type,
slug: slug,
title: result.dashboard.title,
orgId: config.bootData.user.orgId
});
}
return result;
});
......
......@@ -16,12 +16,14 @@ export class ImpressionsStore {
}
impressions = impressions.filter((imp) => {
return impression.meta.slug !== imp.slug;
return impression.slug !== imp.slug;
});
impressions.unshift({
title: impression.dashboard.title,
slug: impression.meta.slug
title: impression.title,
slug: impression.slug,
orgId: impression.orgId,
type: impression.type
});
if (impressions.length > 20) {
......
......@@ -43,13 +43,19 @@ class DashListCtrl extends PanelCtrl {
var params: any = {limit: this.panel.limit};
if (this.panel.mode === 'last viewed') {
var dashListNames = _.first(impressions.getDashboardOpened(), this.panel.limit).map((dashboard) => {
var dashListNames = impressions.getDashboardOpened().filter((imp) => {
return imp.orgId === config.bootData.user.orgId;
});
dashListNames = _.first(dashListNames, params.limit).map((dashboard) => {
return {
title: dashboard.title,
uri: 'db/' + dashboard.slug
uri: dashboard.type + '/' + dashboard.slug
};
});
this.dashList = dashListNames;
this.renderingCompleted();
return;
......
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