module.ts 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 dashListNames = impressions.getDashboardOpened().filter((imp) => {
  38. return imp.orgId === config.bootData.user.orgId;
  39. });
  40. dashListNames = _.first(dashListNames, params.limit).map((dashboard) => {
  41. return {
  42. title: dashboard.title,
  43. uri: dashboard.type + '/' + dashboard.slug
  44. };
  45. });
  46. this.dashList = dashListNames;
  47. this.renderingCompleted();
  48. return;
  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}