edit_ctrl.ts 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. init() {
  9. this.appModel = {};
  10. this.backendSrv.get(`/api/org/apps/${this.$routeParams.appId}/settings`).then(result => {
  11. this.appModel = result;
  12. });
  13. }
  14. update(options) {
  15. var updateCmd = _.extend({
  16. appId: this.appModel.appId,
  17. orgId: this.appModel.orgId,
  18. enabled: this.appModel.enabled,
  19. pinned: this.appModel.pinned,
  20. jsonData: this.appModel.jsonData,
  21. }, options);
  22. this.backendSrv.post(`/api/org/apps/${this.$routeParams.appId}/settings`, updateCmd).then(function() {
  23. window.location.href = window.location.href;
  24. });
  25. }
  26. toggleEnabled() {
  27. this.update({enabled: this.appModel.enabled});
  28. }
  29. togglePinned() {
  30. this.update({pinned: this.appModel.pinned});
  31. }
  32. }
  33. angular.module('grafana.controllers').controller('AppEditCtrl', AppEditCtrl);