dashboard_selector.ts 900 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. ///<reference path="../../headers/common.d.ts" />
  2. import coreModule from 'app/core/core_module';
  3. var 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) {
  11. }
  12. $onInit() {
  13. this.options = [{value: 0, text: 'Default'}];
  14. return this.backendSrv.search({starred: true}).then(res => {
  15. res.forEach(dash => {
  16. this.options.push({value: dash.id, text: dash.title});
  17. });
  18. });
  19. }
  20. }
  21. export function dashboardSelector() {
  22. return {
  23. restrict: 'E',
  24. controller: DashboardSelectorCtrl,
  25. bindToController: true,
  26. controllerAs: 'ctrl',
  27. template: template,
  28. scope: {
  29. model: '='
  30. }
  31. };
  32. }
  33. coreModule.directive('dashboardSelector', dashboardSelector);