dashboard_selector.ts 849 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. import coreModule from 'app/core/core_module';
  2. var template = `
  3. <select class="gf-form-input" ng-model="ctrl.model" ng-options="f.value as f.text for f in ctrl.options"></select>
  4. `;
  5. export class DashboardSelectorCtrl {
  6. model: any;
  7. options: any;
  8. /** @ngInject */
  9. constructor(private backendSrv) {
  10. }
  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);