mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Merge pull request #4192 from bergquist/last_viewed_dashboards
feat(dashlist): list last x viewed dashboards
This commit is contained in:
commit
fa99a6745d
@ -16,4 +16,5 @@ define([
|
|||||||
'./graphiteImportCtrl',
|
'./graphiteImportCtrl',
|
||||||
'./dynamicDashboardSrv',
|
'./dynamicDashboardSrv',
|
||||||
'./importCtrl',
|
'./importCtrl',
|
||||||
|
'./impressionStore',
|
||||||
], function () {});
|
], function () {});
|
||||||
|
@ -5,8 +5,9 @@ define([
|
|||||||
'jquery',
|
'jquery',
|
||||||
'app/core/utils/kbn',
|
'app/core/utils/kbn',
|
||||||
'app/core/utils/datemath',
|
'app/core/utils/datemath',
|
||||||
|
'./impressionStore',
|
||||||
],
|
],
|
||||||
function (angular, moment, _, $, kbn, dateMath) {
|
function (angular, moment, _, $, kbn, dateMath, impressionStore) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var module = angular.module('grafana.services');
|
var module = angular.module('grafana.services');
|
||||||
@ -24,19 +25,27 @@ function (angular, moment, _, $, kbn, dateMath) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.loadDashboard = function(type, slug) {
|
this.loadDashboard = function(type, slug) {
|
||||||
if (type === 'script') {
|
var promise;
|
||||||
return this._loadScriptedDashboard(slug);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (type === 'snapshot') {
|
if (type === 'script') {
|
||||||
return backendSrv.get('/api/snapshots/' + $routeParams.slug).catch(function() {
|
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'}};
|
return {meta:{isSnapshot: true, canSave: false, canEdit: false}, dashboard: {title: 'Snapshot not found'}};
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
promise = backendSrv.getDashboard($routeParams.type, $routeParams.slug)
|
||||||
|
.catch(function() {
|
||||||
|
return self._dashboardLoadFailed("Not found");
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return backendSrv.getDashboard($routeParams.type, $routeParams.slug).catch(function() {
|
promise.then(function(result) {
|
||||||
return self._dashboardLoadFailed("Not found");
|
impressionStore.impressions.addDashboardImpression(slug);
|
||||||
|
return result;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return promise;
|
||||||
};
|
};
|
||||||
|
|
||||||
this._loadScriptedDashboard = function(file) {
|
this._loadScriptedDashboard = function(file) {
|
||||||
|
41
public/app/features/dashboard/impressionStore.ts
Normal file
41
public/app/features/dashboard/impressionStore.ts
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
///<reference path="../../headers/common.d.ts" />
|
||||||
|
|
||||||
|
import store from 'app/core/store';
|
||||||
|
import _ from 'lodash';
|
||||||
|
|
||||||
|
export class ImpressionsStore {
|
||||||
|
constructor() {}
|
||||||
|
|
||||||
|
addDashboardImpression(slug) {
|
||||||
|
var impressions = [];
|
||||||
|
if (store.exists("dashboard_impressions")) {
|
||||||
|
impressions = JSON.parse(store.get("dashboard_impressions"));
|
||||||
|
if (!_.isArray(impressions)) {
|
||||||
|
impressions = [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var exists = impressions.indexOf(slug);
|
||||||
|
if (exists >= 0) {
|
||||||
|
impressions.splice(exists, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
impressions.unshift(slug);
|
||||||
|
|
||||||
|
if (impressions.length > 20) {
|
||||||
|
impressions.shift();
|
||||||
|
}
|
||||||
|
store.set("dashboard_impressions", JSON.stringify(impressions));
|
||||||
|
}
|
||||||
|
|
||||||
|
getDashboardOpened() {
|
||||||
|
var k = store.get("dashboard_impressions");
|
||||||
|
return JSON.parse(k);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var impressions = new ImpressionsStore();
|
||||||
|
|
||||||
|
export {
|
||||||
|
impressions
|
||||||
|
};
|
@ -5,7 +5,7 @@
|
|||||||
{{dash.title}}
|
{{dash.title}}
|
||||||
</span>
|
</span>
|
||||||
<span class="dashlist-star">
|
<span class="dashlist-star">
|
||||||
<i class="fa" ng-class="{'fa-star': dash.isStarred, 'fa-star-o': !dash.isStarred}"></i>
|
<i class="fa" ng-class="{'fa-star': dash.isStarred, 'fa-star-o': dash.isStarred === false}"></i>
|
||||||
</span>
|
</span>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import config from 'app/core/config';
|
import config from 'app/core/config';
|
||||||
import {PanelCtrl} from 'app/plugins/sdk';
|
import {PanelCtrl} from 'app/plugins/sdk';
|
||||||
|
import {impressions} from 'app/features/dashboard/impressionStore';
|
||||||
|
|
||||||
// Set and populate defaults
|
// Set and populate defaults
|
||||||
var panelDefaults = {
|
var panelDefaults = {
|
||||||
@ -31,7 +32,7 @@ class DashListCtrl extends PanelCtrl {
|
|||||||
|
|
||||||
initEditMode() {
|
initEditMode() {
|
||||||
super.initEditMode();
|
super.initEditMode();
|
||||||
this.modes = ['starred', 'search'];
|
this.modes = ['starred', 'search', 'last viewed'];
|
||||||
this.icon = "fa fa-star";
|
this.icon = "fa fa-star";
|
||||||
this.addEditorTab('Options', () => {
|
this.addEditorTab('Options', () => {
|
||||||
return {templateUrl: 'public/app/plugins/panel/dashlist/editor.html'};
|
return {templateUrl: 'public/app/plugins/panel/dashlist/editor.html'};
|
||||||
@ -41,6 +42,19 @@ class DashListCtrl extends PanelCtrl {
|
|||||||
refresh() {
|
refresh() {
|
||||||
var params: any = {limit: this.panel.limit};
|
var params: any = {limit: this.panel.limit};
|
||||||
|
|
||||||
|
if (this.panel.mode === 'last viewed') {
|
||||||
|
var dashListNames = _.first(impressions.getDashboardOpened(), this.panel.limit).map((dashboard) => {
|
||||||
|
return {
|
||||||
|
title: dashboard,
|
||||||
|
uri: 'db/' + dashboard
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
this.dashList = dashListNames;
|
||||||
|
this.renderingCompleted();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (this.panel.mode === 'starred') {
|
if (this.panel.mode === 'starred') {
|
||||||
params.starred = "true";
|
params.starred = "true";
|
||||||
} else {
|
} else {
|
||||||
|
@ -47,11 +47,11 @@
|
|||||||
{
|
{
|
||||||
"id": 3,
|
"id": 3,
|
||||||
"limit": 10,
|
"limit": 10,
|
||||||
"mode": "search",
|
"mode": "last viewed",
|
||||||
"query": "",
|
"query": "",
|
||||||
"span": 6,
|
"span": 6,
|
||||||
"tags": [],
|
"tags": [],
|
||||||
"title": "Dashboards",
|
"title": "Last 10 viewed dashboards",
|
||||||
"type": "dashlist"
|
"type": "dashlist"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
Loading…
Reference in New Issue
Block a user