module.ts 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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/impressionStore';
  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 = [$scope.panel.tag];
  23. delete this.panel.tag;
  24. }
  25. }
  26. initEditMode() {
  27. super.initEditMode();
  28. this.modes = ['starred', 'search', 'last viewed'];
  29. this.icon = "fa fa-star";
  30. this.addEditorTab('Options', () => {
  31. return {templateUrl: 'public/app/plugins/panel/dashlist/editor.html'};
  32. });
  33. }
  34. refresh() {
  35. var params: any = {limit: this.panel.limit};
  36. if (this.panel.mode === 'last viewed') {
  37. var dashListNames = _.first(impressions.getDashboardOpened(), this.panel.limit).map((dashboard) => {
  38. return {
  39. title: dashboard,
  40. uri: 'db/' + dashboard
  41. };
  42. });
  43. this.dashList = dashListNames;
  44. this.renderingCompleted();
  45. return;
  46. }
  47. if (this.panel.mode === 'starred') {
  48. params.starred = "true";
  49. } else {
  50. params.query = this.panel.query;
  51. params.tag = this.panel.tags;
  52. }
  53. return this.backendSrv.search(params).then(result => {
  54. this.dashList = result;
  55. this.renderingCompleted();
  56. });
  57. }
  58. }
  59. export {DashListCtrl, DashListCtrl as PanelCtrl}