module.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. define([
  2. 'angular',
  3. 'app/app',
  4. 'lodash',
  5. 'app/core/config',
  6. 'app/features/panel/panel_meta',
  7. ],
  8. function (angular, app, _, config, PanelMeta) {
  9. 'use strict';
  10. var module = angular.module('grafana.panels.dashlist', []);
  11. app.useModule(module);
  12. /** @ngInject */
  13. function DashListPanelCtrl($scope, panelSrv, backendSrv) {
  14. $scope.panelMeta = new PanelMeta({
  15. panelName: 'Dashboard list',
  16. editIcon: "fa fa-star",
  17. fullscreen: true,
  18. });
  19. $scope.panelMeta.addEditorTab('Options', 'app/plugins/panel/dashlist/editor.html');
  20. var defaults = {
  21. mode: 'starred',
  22. query: '',
  23. limit: 10,
  24. tags: []
  25. };
  26. $scope.modes = ['starred', 'search'];
  27. _.defaults($scope.panel, defaults);
  28. $scope.dashList = [];
  29. $scope.init = function() {
  30. panelSrv.init($scope);
  31. if ($scope.panel.tag) {
  32. $scope.panel.tags = [$scope.panel.tag];
  33. delete $scope.panel.tag;
  34. }
  35. if ($scope.isNewPanel()) {
  36. $scope.panel.title = "Starred Dashboards";
  37. }
  38. };
  39. $scope.refreshData = function() {
  40. var params = {
  41. limit: $scope.panel.limit
  42. };
  43. if ($scope.panel.mode === 'starred') {
  44. params.starred = "true";
  45. } else {
  46. params.query = $scope.panel.query;
  47. params.tag = $scope.panel.tags;
  48. }
  49. return backendSrv.search(params).then(function(result) {
  50. $scope.dashList = result;
  51. $scope.panelRenderingComplete();
  52. });
  53. };
  54. $scope.init();
  55. }
  56. function dashListPanelDirective() {
  57. return {
  58. controller: DashListPanelCtrl,
  59. templateUrl: 'app/plugins/panel/dashlist/module.html',
  60. };
  61. }
  62. return {
  63. panel: dashListPanelDirective
  64. };
  65. });