edit_ctrl.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. /** @ngInject */
  10. constructor(private backendSrv: any, private $routeParams: any) {
  11. this.model = {};
  12. this.pluginId = $routeParams.pluginId;
  13. this.backendSrv.get(`/api/org/plugins/${this.pluginId}/settings`).then(result => {
  14. this.model = result;
  15. this.includedPanels = _.where(result.includes, {type: 'panel'});
  16. this.includedDatasources = _.where(result.includes, {type: 'datasource'});
  17. });
  18. }
  19. update() {
  20. var updateCmd = _.extend({
  21. pluginId: this.model.pluginId,
  22. orgId: this.model.orgId,
  23. enabled: this.model.enabled,
  24. pinned: this.model.pinned,
  25. jsonData: this.model.jsonData,
  26. secureJsonData: this.model.secureJsonData,
  27. }, {});
  28. this.backendSrv.post(`/api/org/plugins/${this.pluginId}/settings`, updateCmd).then(function() {
  29. window.location.href = window.location.href;
  30. });
  31. }
  32. toggleEnabled() {
  33. this.update();
  34. }
  35. togglePinned() {
  36. this.update();
  37. }
  38. }
  39. angular.module('grafana.controllers').controller('PluginEditCtrl', PluginEditCtrl);