From 606c75162fedd9bdb3b194cc05baedd8a215ef40 Mon Sep 17 00:00:00 2001 From: bergquist Date: Tue, 1 Mar 2016 12:05:35 +0100 Subject: [PATCH] feat(dashlist): add support for scripted dashboards - dashlist will only show dashboards from same org - notfound dashboards will not be added closes #4207 --- .../features/dashboard/dashboardLoaderSrv.js | 28 ++++++++++++++----- .../features/dashboard/impression_store.ts | 8 ++++-- public/app/plugins/panel/dashlist/module.ts | 10 +++++-- 3 files changed, 34 insertions(+), 12 deletions(-) diff --git a/public/app/features/dashboard/dashboardLoaderSrv.js b/public/app/features/dashboard/dashboardLoaderSrv.js index c7078512e02..eba0a962629 100644 --- a/public/app/features/dashboard/dashboardLoaderSrv.js +++ b/public/app/features/dashboard/dashboardLoaderSrv.js @@ -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; }); diff --git a/public/app/features/dashboard/impression_store.ts b/public/app/features/dashboard/impression_store.ts index 02fa938728c..7f7ecb9a9ba 100644 --- a/public/app/features/dashboard/impression_store.ts +++ b/public/app/features/dashboard/impression_store.ts @@ -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) { diff --git a/public/app/plugins/panel/dashlist/module.ts b/public/app/plugins/panel/dashlist/module.ts index 036e26e9e5b..75007410269 100644 --- a/public/app/plugins/panel/dashlist/module.ts +++ b/public/app/plugins/panel/dashlist/module.ts @@ -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;