| 1441 |
ariadna |
1 |
// This file is part of Moodle - http://moodle.org/
|
|
|
2 |
//
|
|
|
3 |
// Moodle is free software: you can redistribute it and/or modify
|
|
|
4 |
// it under the terms of the GNU General Public License as published by
|
|
|
5 |
// the Free Software Foundation, either version 3 of the License, or
|
|
|
6 |
// (at your option) any later version.
|
|
|
7 |
//
|
|
|
8 |
// Moodle is distributed in the hope that it will be useful,
|
|
|
9 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
10 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
11 |
// GNU General Public License for more details.
|
|
|
12 |
//
|
|
|
13 |
// You should have received a copy of the GNU General Public License
|
|
|
14 |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
15 |
|
|
|
16 |
/**
|
|
|
17 |
* Tiny AI loading screen handling.
|
|
|
18 |
*
|
|
|
19 |
* @module tiny_aiplacement/loading
|
|
|
20 |
* @copyright 2024 Matt Porritt <matt.porritt@moodle.com>
|
|
|
21 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
22 |
*/
|
|
|
23 |
|
|
|
24 |
import {getString} from 'core/str';
|
|
|
25 |
import {prefetchString} from 'core/prefetch';
|
|
|
26 |
|
|
|
27 |
const strings = [
|
|
|
28 |
{
|
|
|
29 |
key: 'loading_processing',
|
|
|
30 |
component: 'tiny_aiplacement',
|
|
|
31 |
},
|
|
|
32 |
{
|
|
|
33 |
key: 'loading_generating',
|
|
|
34 |
component: 'tiny_aiplacement',
|
|
|
35 |
},
|
|
|
36 |
{
|
|
|
37 |
key: 'loading_applying',
|
|
|
38 |
component: 'tiny_aiplacement',
|
|
|
39 |
},
|
|
|
40 |
{
|
|
|
41 |
key: 'loading_almostdone',
|
|
|
42 |
component: 'tiny_aiplacement',
|
|
|
43 |
}
|
|
|
44 |
];
|
|
|
45 |
|
|
|
46 |
strings.forEach((string) => prefetchString(string.component, string.key));
|
|
|
47 |
|
|
|
48 |
/**
|
|
|
49 |
* Display a series of messages one by one with a specified delay between each message.
|
|
|
50 |
*
|
|
|
51 |
* Returns a promise that resolves when the final message is displayed.
|
|
|
52 |
*
|
|
|
53 |
* @param {HTMLElement} element The element to display the messages in.
|
|
|
54 |
* @param {number} delay The delay between each message in milliseconds.
|
|
|
55 |
* @returns {Promise<function(): void>} A function to stop the message cycling.
|
|
|
56 |
*/
|
|
|
57 |
export async function loadingMessages(element, delay = 6000) {
|
|
|
58 |
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
|
59 |
|
|
|
60 |
for (const {key, component} of strings) {
|
|
|
61 |
element.textContent = await getString(key, component);
|
|
|
62 |
await sleep(delay);
|
|
|
63 |
}
|
|
|
64 |
|
|
|
65 |
return;
|
|
|
66 |
}
|