dashboard_selector.ts 922 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. import coreModule from 'app/core/core_module';
  2. import { BackendSrv } from '../services/backend_srv';
  3. const template = `
  4. <select class="gf-form-input" ng-model="ctrl.model" ng-options="f.value as f.text for f in ctrl.options"></select>
  5. `;
  6. export class DashboardSelectorCtrl {
  7. model: any;
  8. options: any;
  9. /** @ngInject */
  10. constructor(private backendSrv: BackendSrv) {}
  11. $onInit() {
  12. this.options = [{ value: 0, text: 'Default' }];
  13. return this.backendSrv.search({ starred: true }).then(res => {
  14. res.forEach(dash => {
  15. this.options.push({ value: dash.id, text: dash.title });
  16. });
  17. });
  18. }
  19. }
  20. export function dashboardSelector() {
  21. return {
  22. restrict: 'E',
  23. controller: DashboardSelectorCtrl,
  24. bindToController: true,
  25. controllerAs: 'ctrl',
  26. template: template,
  27. scope: {
  28. model: '=',
  29. },
  30. };
  31. }
  32. coreModule.directive('dashboardSelector', dashboardSelector);