edit_ctrl.ts 1.0 KB

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