| 1441 |
ariadna |
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 |
|
|
|
15 |
import PluginManagementTable from 'core_admin/plugin_management_table';
|
|
|
16 |
import {call as fetchMany} from 'core/ajax';
|
|
|
17 |
|
|
|
18 |
let watching = false;
|
|
|
19 |
|
|
|
20 |
/**
|
|
|
21 |
* Handles setting plugin state for the AI provider management table.
|
|
|
22 |
*
|
|
|
23 |
* @module core_ai/aiprovider_action_management_table
|
|
|
24 |
* @copyright 2024 Matt Porritt <matt.porritt@moodle.com>
|
|
|
25 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
26 |
*/
|
|
|
27 |
export default class extends PluginManagementTable {
|
|
|
28 |
|
|
|
29 |
/**
|
|
|
30 |
* Constructor for the class.
|
|
|
31 |
*
|
|
|
32 |
* @param {int} providerid The provider id.
|
|
|
33 |
*/
|
|
|
34 |
constructor(providerid) {
|
|
|
35 |
super(); // Call the parent constructor, so inherited properties and methods initialize properly.
|
|
|
36 |
this.providerid = providerid; // Store provider id as an instance field.
|
|
|
37 |
}
|
|
|
38 |
|
|
|
39 |
/**
|
|
|
40 |
* Initialise an instance of the class.
|
|
|
41 |
*
|
|
|
42 |
* @param {int} providerid The provider id.
|
|
|
43 |
*/
|
|
|
44 |
static init(providerid) {
|
|
|
45 |
if (watching) {
|
|
|
46 |
return;
|
|
|
47 |
}
|
|
|
48 |
watching = true;
|
|
|
49 |
new this(providerid);
|
|
|
50 |
}
|
|
|
51 |
|
|
|
52 |
/**
|
|
|
53 |
* Set the plugin state (enabled or disabled).
|
|
|
54 |
*
|
|
|
55 |
* @param {string} methodname The web service to call.
|
|
|
56 |
* @param {string} plugin The name of the plugin and action to set the state for.
|
|
|
57 |
* @param {number} state The state to set.
|
|
|
58 |
* @returns {Promise}
|
|
|
59 |
*/
|
|
|
60 |
setPluginState(methodname, plugin, state) {
|
|
|
61 |
const providerid = this.providerid;
|
|
|
62 |
return fetchMany([{
|
|
|
63 |
methodname,
|
|
|
64 |
args: {
|
|
|
65 |
plugin,
|
|
|
66 |
state,
|
|
|
67 |
providerid,
|
|
|
68 |
},
|
|
|
69 |
}])[0];
|
|
|
70 |
}
|
|
|
71 |
|
|
|
72 |
}
|