edit_ctrl.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. ///<reference path="../../headers/common.d.ts" />
  2. import angular from 'angular';
  3. import _ from 'lodash';
  4. export class AppEditCtrl {
  5. appModel: any;
  6. includedPanels: any;
  7. /** @ngInject */
  8. constructor(private backendSrv: any, private $routeParams: any) {
  9. this.appModel = {};
  10. this.backendSrv.get(`/api/org/apps/${this.$routeParams.appId}/settings`).then(result => {
  11. this.appModel = result;
  12. this.includedPanels = _.where(result.includes, {type: 'panel'});
  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. secureJsonData: this.appModel.secureJsonData,
  23. }, options);
  24. this.backendSrv.post(`/api/org/apps/${this.$routeParams.appId}/settings`, updateCmd).then(function() {
  25. window.location.href = window.location.href;
  26. });
  27. }
  28. toggleEnabled() {
  29. this.update({enabled: this.appModel.enabled});
  30. }
  31. togglePinned() {
  32. this.update({pinned: this.appModel.pinned});
  33. }
  34. }
  35. angular.module('grafana.controllers').controller('AppEditCtrl', AppEditCtrl);