module.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 dashboardIds = impressions.getDashboardOpened();
  38. return this.backendSrv.search({
  39. dashboardIds: impressions.getDashboardOpened(),
  40. limit: this.panel.limit
  41. }).then(result => {
  42. this.dashList = dashboardIds.map(orderId => {
  43. return _.find(result, dashboard => {
  44. return dashboard.id === orderId;
  45. });
  46. });
  47. this.renderingCompleted();
  48. });
  49. }
  50. if (this.panel.mode === 'starred') {
  51. params.starred = "true";
  52. } else {
  53. params.query = this.panel.query;
  54. params.tag = this.panel.tags;
  55. }
  56. return this.backendSrv.search(params).then(result => {
  57. this.dashList = result;
  58. this.renderingCompleted();
  59. });
  60. }
  61. }
  62. export {DashListCtrl, DashListCtrl as PanelCtrl}