module.ts 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. ///<reference path="../../../headers/common.d.ts" />
  2. import _ from 'lodash';
  3. import config from 'app/core/config';
  4. import {PanelCtrl} from 'app/plugins/sdk';
  5. import {impressions} from 'app/features/dashboard/impression_store';
  6. // Set and populate defaults
  7. var panelDefaults = {
  8. mode: 'starred',
  9. query: '',
  10. limit: 10,
  11. tags: []
  12. };
  13. class DashListCtrl extends PanelCtrl {
  14. static templateUrl = 'module.html';
  15. dashList: any[];
  16. modes: any[];
  17. /** @ngInject */
  18. constructor($scope, $injector, private backendSrv) {
  19. super($scope, $injector);
  20. _.defaults(this.panel, panelDefaults);
  21. if (this.panel.tag) {
  22. this.panel.tags = [this.panel.tag];
  23. delete this.panel.tag;
  24. }
  25. this.events.on('refresh', this.onRefresh.bind(this));
  26. this.events.on('init-edit-mode', this.onInitEditMode.bind(this));
  27. }
  28. onInitEditMode() {
  29. this.editorTabIndex = 1;
  30. this.modes = ['starred', 'search', 'recently viewed'];
  31. this.addEditorTab('Options', 'public/app/plugins/panel/dashlist/editor.html');
  32. }
  33. onRefresh() {
  34. var params: any = {limit: this.panel.limit};
  35. if (this.panel.mode === 'recently viewed') {
  36. var dashIds = _.first(impressions.getDashboardOpened(), this.panel.limit);
  37. return this.backendSrv.search({dashboardIds: dashIds, limit: this.panel.limit}).then(result => {
  38. this.dashList = dashIds.map(orderId => {
  39. return _.find(result, dashboard => {
  40. return dashboard.id === orderId;
  41. });
  42. }).filter(el => {
  43. return el !== undefined;
  44. });
  45. this.renderingCompleted();
  46. });
  47. }
  48. if (this.panel.mode === 'starred') {
  49. params.starred = "true";
  50. } else {
  51. params.query = this.panel.query;
  52. params.tag = this.panel.tags;
  53. }
  54. return this.backendSrv.search(params).then(result => {
  55. this.dashList = result;
  56. this.renderingCompleted();
  57. });
  58. }
  59. }
  60. export {DashListCtrl, DashListCtrl as PanelCtrl}