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 = [$scope.panel.tag];
  23. delete this.panel.tag;
  24. }
  25. }
  26. initEditMode() {
  27. super.initEditMode();
  28. this.modes = ['starred', 'search', 'recently 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 === 'recently viewed') {
  37. var dashIds = _.first(impressions.getDashboardOpened(), this.panel.limit);
  38. return this.backendSrv.search({dashboardIds: dashIds, limit: this.panel.limit}).then(result => {
  39. this.dashList = dashIds.map(orderId => {
  40. return _.find(result, dashboard => {
  41. return dashboard.id === orderId;
  42. });
  43. }).filter(el => {
  44. return el !== undefined;
  45. });
  46. this.renderingCompleted();
  47. });
  48. }
  49. if (this.panel.mode === 'starred') {
  50. params.starred = "true";
  51. } else {
  52. params.query = this.panel.query;
  53. params.tag = this.panel.tags;
  54. }
  55. return this.backendSrv.search(params).then(result => {
  56. this.dashList = result;
  57. this.renderingCompleted();
  58. });
  59. }
  60. }
  61. export {DashListCtrl, DashListCtrl as PanelCtrl}