edit_ctrl.ts 1.3 KB

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