edit_ctrl.ts 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. ///<reference path="../../headers/common.d.ts" />
  2. import config from 'app/core/config';
  3. import angular from 'angular';
  4. import _ from 'lodash';
  5. export class AppEditCtrl {
  6. appModel: any;
  7. /** @ngInject */
  8. constructor(private backendSrv: any, private $routeParams: any) {}
  9. init() {
  10. this.appModel = {};
  11. this.backendSrv.get(`/api/org/apps/${this.$routeParams.appId}/settings`).then(result => {
  12. this.appModel = result;
  13. });
  14. }
  15. update(options) {
  16. var updateCmd = _.extend({
  17. appId: this.appModel.appId,
  18. orgId: this.appModel.orgId,
  19. enabled: this.appModel.enabled,
  20. pinned: this.appModel.pinned,
  21. jsonData: this.appModel.jsonData,
  22. }, options);
  23. this.backendSrv.post(`/api/org/apps/${this.$routeParams.appId}/settings`, updateCmd).then(function() {
  24. window.location.href = window.location.href;
  25. });
  26. }
  27. toggleEnabled() {
  28. this.update({enabled: this.appModel.enabled});
  29. }
  30. togglePinned() {
  31. this.update({pinned: this.appModel.pinned});
  32. }
  33. }
  34. angular.module('grafana.controllers').controller('AppEditCtrl', AppEditCtrl);