ai/amd/src/aiprovider_action_management_table.js

  1. // This file is part of Moodle - http://moodle.org/ //
  2. // Moodle is free software: you can redistribute it and/or modify
  3. // it under the terms of the GNU General Public License as published by
  4. // the Free Software Foundation, either version 3 of the License, or
  5. // (at your option) any later version.
  6. //
  7. // Moodle is distributed in the hope that it will be useful,
  8. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. // GNU General Public License for more details.
  11. //
  12. // You should have received a copy of the GNU General Public License
  13. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
  14. import PluginManagementTable from 'core_admin/plugin_management_table';
  15. import {call as fetchMany} from 'core/ajax';
  16. let watching = false;
  17. /**
  18. * Handles setting plugin state for the AI provider management table.
  19. *
  20. * @module core_ai/aiprovider_action_management_table
  21. * @copyright 2024 Matt Porritt <matt.porritt@moodle.com>
  22. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23. */
  24. export default class extends PluginManagementTable {
  25. /**
  26. * Constructor for the class.
  27. *
  28. * @param {int} providerid The provider id.
  29. */
  30. constructor(providerid) {
  31. super(); // Call the parent constructor, so inherited properties and methods initialize properly.
  32. this.providerid = providerid; // Store provider id as an instance field.
  33. }
  34. /**
  35. * Initialise an instance of the class.
  36. *
  37. * @param {int} providerid The provider id.
  38. */
  39. static init(providerid) {
  40. if (watching) {
  41. return;
  42. }
  43. watching = true;
  44. new this(providerid);
  45. }
  46. /**
  47. * Set the plugin state (enabled or disabled).
  48. *
  49. * @param {string} methodname The web service to call.
  50. * @param {string} plugin The name of the plugin and action to set the state for.
  51. * @param {number} state The state to set.
  52. * @returns {Promise}
  53. */
  54. setPluginState(methodname, plugin, state) {
  55. const providerid = this.providerid;
  56. return fetchMany([{
  57. methodname,
  58. args: {
  59. plugin,
  60. state,
  61. providerid,
  62. },
  63. }])[0];
  64. }
  65. }