edit_ctrl.ts 1.1 KB

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