app_srv.ts 830 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. ///<reference path="../../headers/common.d.ts" />
  2. import _ from 'lodash';
  3. import angular from 'angular';
  4. export class AppSrv {
  5. apps: any = {};
  6. /** @ngInject */
  7. constructor(
  8. private $rootScope,
  9. private $timeout,
  10. private $q,
  11. private backendSrv) {
  12. }
  13. get(type) {
  14. return this.getAll().then(() => {
  15. return this.apps[type];
  16. });
  17. }
  18. getAll() {
  19. if (!_.isEmpty(this.apps)) {
  20. return this.$q.when(this.apps);
  21. }
  22. return this.backendSrv.get('api/org/apps').then(results => {
  23. return results.reduce((prev, current) => {
  24. prev[current.type] = current;
  25. return prev;
  26. }, this.apps);
  27. });
  28. }
  29. update(app) {
  30. return this.backendSrv.post('api/org/apps', app).then(resp => {
  31. });
  32. }
  33. }
  34. angular.module('grafana.services').service('appSrv', AppSrv);