module.ts 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. ///<reference path="../../../headers/common.d.ts" />
  2. import _ from 'lodash';
  3. import config from 'app/core/config';
  4. import {PanelDirective, PanelCtrl} from '../../../features/panel/panel';
  5. // Set and populate defaults
  6. var panelDefaults = {
  7. mode: 'starred',
  8. query: '',
  9. limit: 10,
  10. tags: []
  11. };
  12. class DashListCtrl extends PanelCtrl {
  13. dashList: any[];
  14. modes: any[];
  15. /** @ngInject */
  16. constructor($scope, $injector, private backendSrv) {
  17. super($scope, $injector);
  18. _.defaults(this.panel, panelDefaults);
  19. if (this.panel.tag) {
  20. this.panel.tags = [$scope.panel.tag];
  21. delete this.panel.tag;
  22. }
  23. }
  24. initEditMode() {
  25. super.initEditMode();
  26. this.modes = ['starred', 'search'];
  27. this.icon = "fa fa-star";
  28. this.addEditorTab('Options', () => {
  29. return {templateUrl: 'public/app/plugins/panel/dashlist/editor.html'};
  30. });
  31. }
  32. refresh() {
  33. var params: any = {limit: this.panel.limit};
  34. if (this.panel.mode === 'starred') {
  35. params.starred = "true";
  36. } else {
  37. params.query = this.panel.query;
  38. params.tag = this.panel.tags;
  39. }
  40. return this.backendSrv.search(params).then(result => {
  41. this.dashList = result;
  42. this.renderingCompleted();
  43. });
  44. }
  45. }
  46. class DashListPanel extends PanelDirective {
  47. controller = DashListCtrl;
  48. templateUrl = 'public/app/plugins/panel/dashlist/module.html';
  49. }
  50. export {
  51. DashListCtrl,
  52. DashListPanel as Panel
  53. }