|
|
@@ -7,16 +7,19 @@ import {impressions} from 'app/features/dashboard/impression_store';
|
|
|
|
|
|
// Set and populate defaults
|
|
|
var panelDefaults = {
|
|
|
- mode: 'starred',
|
|
|
query: '',
|
|
|
limit: 10,
|
|
|
- tags: []
|
|
|
+ tags: [],
|
|
|
+ recent: false,
|
|
|
+ search: false,
|
|
|
+ starred: true,
|
|
|
+ headings: true,
|
|
|
};
|
|
|
|
|
|
class DashListCtrl extends PanelCtrl {
|
|
|
static templateUrl = 'module.html';
|
|
|
|
|
|
- dashList: any[];
|
|
|
+ groups: any[];
|
|
|
modes: any[];
|
|
|
|
|
|
/** @ngInject */
|
|
|
@@ -31,6 +34,31 @@ class DashListCtrl extends PanelCtrl {
|
|
|
|
|
|
this.events.on('refresh', this.onRefresh.bind(this));
|
|
|
this.events.on('init-edit-mode', this.onInitEditMode.bind(this));
|
|
|
+
|
|
|
+ this.groups = [
|
|
|
+ {list: [], show: false, header: "Starred dashboards",},
|
|
|
+ {list: [], show: false, header: "Recently viewed dashboards"},
|
|
|
+ {list: [], show: false, header: "Search"},
|
|
|
+ ];
|
|
|
+
|
|
|
+ // update capability
|
|
|
+ if (this.panel.mode) {
|
|
|
+ if (this.panel.mode === 'starred') {
|
|
|
+ this.panel.starred = true;
|
|
|
+ this.panel.headings = false;
|
|
|
+ }
|
|
|
+ if (this.panel.mode === 'recently viewed') {
|
|
|
+ this.panel.recent = true;
|
|
|
+ this.panel.starred = false;
|
|
|
+ this.panel.headings = false;
|
|
|
+ }
|
|
|
+ if (this.panel.mode === 'search') {
|
|
|
+ this.panel.search = true;
|
|
|
+ this.panel.starred = false;
|
|
|
+ this.panel.headings = false;
|
|
|
+ }
|
|
|
+ delete this.panel.mode;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
onInitEditMode() {
|
|
|
@@ -40,34 +68,60 @@ class DashListCtrl extends PanelCtrl {
|
|
|
}
|
|
|
|
|
|
onRefresh() {
|
|
|
- var params: any = {limit: this.panel.limit};
|
|
|
-
|
|
|
- if (this.panel.mode === 'recently viewed') {
|
|
|
- var dashIds = _.first(impressions.getDashboardOpened(), this.panel.limit);
|
|
|
-
|
|
|
- return this.backendSrv.search({dashboardIds: dashIds, limit: this.panel.limit}).then(result => {
|
|
|
- this.dashList = dashIds.map(orderId => {
|
|
|
- return _.find(result, dashboard => {
|
|
|
- return dashboard.id === orderId;
|
|
|
- });
|
|
|
- }).filter(el => {
|
|
|
- return el !== undefined;
|
|
|
- });
|
|
|
+ var promises = [];
|
|
|
|
|
|
- this.renderingCompleted();
|
|
|
- });
|
|
|
+ promises.push(this.getRecentDashboards());
|
|
|
+ promises.push(this.getStarred());
|
|
|
+ promises.push(this.getSearch());
|
|
|
+
|
|
|
+ return Promise.all(promises)
|
|
|
+ .then(this.renderingCompleted.bind(this));
|
|
|
+ }
|
|
|
+
|
|
|
+ getSearch() {
|
|
|
+ this.groups[2].show = this.panel.search;
|
|
|
+ if (!this.panel.search) {
|
|
|
+ return Promise.resolve();
|
|
|
}
|
|
|
|
|
|
- if (this.panel.mode === 'starred') {
|
|
|
- params.starred = "true";
|
|
|
- } else {
|
|
|
- params.query = this.panel.query;
|
|
|
- params.tag = this.panel.tags;
|
|
|
+ var params = {
|
|
|
+ limit: this.panel.limit,
|
|
|
+ query: this.panel.query,
|
|
|
+ tag: this.panel.tags,
|
|
|
+ };
|
|
|
+
|
|
|
+ return this.backendSrv.search(params).then(result => {
|
|
|
+ this.groups[2].list = result;
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ getStarred() {
|
|
|
+ this.groups[0].show = this.panel.starred;
|
|
|
+ if (!this.panel.starred) {
|
|
|
+ return Promise.resolve();
|
|
|
}
|
|
|
|
|
|
+ var params = {limit: this.panel.limit, starred: "true"};
|
|
|
return this.backendSrv.search(params).then(result => {
|
|
|
- this.dashList = result;
|
|
|
- this.renderingCompleted();
|
|
|
+ this.groups[0].list = result;
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ getRecentDashboards() {
|
|
|
+ this.groups[1].show = this.panel.recent;
|
|
|
+ if (!this.panel.recent) {
|
|
|
+ return Promise.resolve();
|
|
|
+ }
|
|
|
+
|
|
|
+ var dashIds = _.first(impressions.getDashboardOpened(), this.panel.limit);
|
|
|
+ return this.backendSrv.search({dashboardIds: dashIds, limit: this.panel.limit}).then(result => {
|
|
|
+ this.groups[1].list = dashIds.map(orderId => {
|
|
|
+ return _.find(result, dashboard => {
|
|
|
+ return dashboard.id === orderId;
|
|
|
+ });
|
|
|
+ }).filter(el => {
|
|
|
+ return el !== undefined;
|
|
|
+ });
|
|
|
});
|
|
|
}
|
|
|
}
|