module.ts 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import _ from "lodash";
  2. import { PanelCtrl } from "../../../features/panel/panel_ctrl";
  3. class PluginListCtrl extends PanelCtrl {
  4. static templateUrl = "module.html";
  5. static scrollable = true;
  6. pluginList: any[];
  7. viewModel: any;
  8. // Set and populate defaults
  9. panelDefaults = {};
  10. /** @ngInject */
  11. constructor($scope, $injector, private backendSrv, private $location) {
  12. super($scope, $injector);
  13. _.defaults(this.panel, this.panelDefaults);
  14. this.events.on("init-edit-mode", this.onInitEditMode.bind(this));
  15. this.pluginList = [];
  16. this.viewModel = [
  17. { header: "Installed Apps", list: [], type: "app" },
  18. { header: "Installed Panels", list: [], type: "panel" },
  19. { header: "Installed Datasources", list: [], type: "datasource" }
  20. ];
  21. this.update();
  22. }
  23. onInitEditMode() {
  24. this.editorTabIndex = 1;
  25. this.addEditorTab(
  26. "Options",
  27. "public/app/plugins/panel/pluginlist/editor.html"
  28. );
  29. }
  30. gotoPlugin(plugin, evt) {
  31. if (evt) {
  32. evt.stopPropagation();
  33. }
  34. this.$location.url(`plugins/${plugin.id}/edit`);
  35. }
  36. updateAvailable(plugin, $event) {
  37. $event.stopPropagation();
  38. $event.preventDefault();
  39. var modalScope = this.$scope.$new(true);
  40. modalScope.plugin = plugin;
  41. this.publishAppEvent("show-modal", {
  42. src: "public/app/features/plugins/partials/update_instructions.html",
  43. scope: modalScope
  44. });
  45. }
  46. update() {
  47. this.backendSrv
  48. .get("api/plugins", { embedded: 0, core: 0 })
  49. .then(plugins => {
  50. this.pluginList = plugins;
  51. this.viewModel[0].list = _.filter(plugins, { type: "app" });
  52. this.viewModel[1].list = _.filter(plugins, { type: "panel" });
  53. this.viewModel[2].list = _.filter(plugins, { type: "datasource" });
  54. for (let plugin of this.pluginList) {
  55. if (plugin.hasUpdate) {
  56. plugin.state = "has-update";
  57. } else if (!plugin.enabled) {
  58. plugin.state = "not-enabled";
  59. }
  60. }
  61. });
  62. }
  63. }
  64. export { PluginListCtrl, PluginListCtrl as PanelCtrl };