diff --git a/admin/tool/componentlibrary/content/moodle/components/task-indicator.md b/admin/tool/componentlibrary/content/moodle/components/task-indicator.md index 580b3fa658d62..6b8dc9d2b73ef 100644 --- a/admin/tool/componentlibrary/content/moodle/components/task-indicator.md +++ b/admin/tool/componentlibrary/content/moodle/components/task-indicator.md @@ -89,10 +89,12 @@ if ($taskindicator->has_task_record()) { {{< /php >}} +When the task begins running and the progress is updated, the progress bar will automatically be displayed. + If the optional `redirecturl` parameter is set when creating the indicator, the page will automatically reload or redirect to this URL when the progress bar completes. -While the task is still queued, admins will see a "Run now" button below the progress bar. This is designed for convenience if +While the task is still queued, admins will see a "Run now" button below the indicator. This is designed for convenience if a user is blocked on a job and needs the task run immediately. It will run the specific instance of the task tracked by the indicator. @@ -110,6 +112,7 @@ indicator. "id": "progressbar_test", "message": "Task pending", "idnumber": "progressbar_test", + "class": "stored-progress-bar stored-progress-notstarted", "width": "500", "value": "0" }, diff --git a/grade/tests/behat/grade_async_regrade.feature b/grade/tests/behat/grade_async_regrade.feature index 87e793a1d6107..effe1f13cb719 100644 --- a/grade/tests/behat/grade_async_regrade.feature +++ b/grade/tests/behat/grade_async_regrade.feature @@ -58,12 +58,10 @@ Feature: Asynchronous regrade on a large course Scenario Outline: Task indicator displays on all grade reports when a calculation is pending Given I am on the "Test course 2" "" page logged in as "" - Then I should not see "Grades are being recalculated due to recent changes." + Then I should not see "The report will update automatically. You don't need to do anything." And should exist When I am on the "Test course 1" "" page logged in as "" - Then I should see "Grades are being recalculated due to recent changes." - And I should see "Task pending" - And I should see "0.0%" + Then I should see "The report will update automatically. You don't need to do anything." And should not exist Examples: @@ -78,10 +76,10 @@ Feature: Asynchronous regrade on a large course Scenario Outline: Gradebook settings can be accessed when a regrade is pending Given I am on the "Test course 2" "" page logged in as "teacher1" Then I should see "" - And I should not see "Grades are being recalculated due to recent changes." + And I should not see "The report will update automatically. You don't need to do anything." Given I am on the "Test course 1" "" page logged in as "teacher1" Then I should see "" - And I should not see "Grades are being recalculated due to recent changes." + And I should not see "The report will update automatically. You don't need to do anything." Examples: | page | text | @@ -93,37 +91,32 @@ Feature: Asynchronous regrade on a large course When I follow "Grades" in the user menu And I follow "Test course 2" Then "table.user-grade" "css_element" should exist - Then I should not see "Grades are being recalculated due to recent changes." + Then I should not see "The report will update automatically. You don't need to do anything." When I follow "Grades" in the user menu And I follow "Test course 1" Then "table.user-grade" "css_element" should not exist - Then I should see "Grades are being recalculated due to recent changes." + Then I should see "The report will update automatically. You don't need to do anything." Scenario: Task indicator progresses and redirects when the task is run. When I am on the "Test course 1" "grades > Grader report > View" page logged in as teacher1 - And I should see "Grades are being recalculated due to recent changes." - And I should see "Task pending" + And I should see "The report will update automatically. You don't need to do anything." And I should not see "Run now" - And I should see "0.0%" + And I should not see "0.0%" And "user-grades" "table" should not exist - When I run all adhoc tasks + And I run all adhoc tasks # Progress bar should update. - # Manual wait is a bit of a fudge, but we need the progress bar to poll for an update. - And I wait "1" seconds - Then I should not see "Task pending" - And I should see "Recalculating grades" + And I wait until "Recalculating grades" "text" exists And I should see "100%" - When I wait "2" seconds # The page should reload after a short delay. - Then I should not see "Grades are being recalculated due to recent changes." + Then I wait until "Recalculating grades" "text" does not exist And I set the field "Search users" to "Student 1" And "user-grades" "table" should exist And "40.00" "text" should exist in the "student1@example.com" "table_row" Scenario: Admin should see a "Run now" button in the task indicator When I am on the "Test course 1" "grades > Grader report > View" page logged in as admin - And I should see "Grades are being recalculated due to recent changes." - And I should see "Task pending" + And I should see "The report will update automatically. You don't need to do anything." + And I should not see "0.0%" And I should see "Run now" Scenario: Making changes on course with less than 100 grades performs the regrade synchronously, no indicator is shown. @@ -133,17 +126,17 @@ Feature: Asynchronous regrade on a large course And I set the field "Maximum grade" to "50" And I press "Save and return to course" When I am on the "Test course 2" "grades > Grader report > View" page - Then I should not see "Grades are being recalculated due to recent changes." + Then I should not see "The report will update automatically. You don't need to do anything." And "user-grades" "table" should exist Scenario: Editing weights triggers a regrade, but further edits are possible Given I run all adhoc tasks And I am on the "Test course 1" "grades > Grader report > View" page logged in as "teacher1" - And I should not see "Grades are being recalculated due to recent changes." + And I should not see "The report will update automatically. You don't need to do anything." And I am on the "Test course 1" "grades > Gradebook setup" page When I set the field "Override weight of Test assignment 1" to "1" And I press "Save changes" And I am on the "Test course 1" "grades > Grader report > View" page - And I should see "Grades are being recalculated due to recent changes." + And I should see "The report will update automatically. You don't need to do anything." And I am on the "Test course 1" "grades > Gradebook setup" page - And I should not see "Grades are being recalculated due to recent changes." + And I should not see "The report will update automatically. You don't need to do anything." diff --git a/lib/amd/build/task_indicator.min.js b/lib/amd/build/task_indicator.min.js index 799b99c2ef64b..f6de3367f6634 100644 --- a/lib/amd/build/task_indicator.min.js +++ b/lib/amd/build/task_indicator.min.js @@ -9,6 +9,6 @@ define("core/task_indicator",["exports"],(function(_exports){Object.defineProper * @author Mark Johnson * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class{static init(id,redirectUrl){document.getElementById(id).addEventListener("update",(event=>{const runlink=document.querySelector(".runlink[data-idnumber=".concat(id,"]"));runlink&&event.detail.percent>0&&runlink.remove(),""!==redirectUrl&&100===event.detail.percent&&window.setTimeout((()=>window.location.assign(redirectUrl)),2e3)}))}},_exports.default})); +class{static init(id,redirectUrl){const bar=document.getElementById(id);bar.addEventListener("update",(event=>{if(event.detail.percent>0){bar.classList.remove("stored-progress-notstarted");const runlink=document.querySelector(".runlink[data-idnumber=".concat(id,"]"));runlink&&event.detail.percent>0&&runlink.remove()}""!==redirectUrl&&100===event.detail.percent&&window.setTimeout((()=>window.location.assign(redirectUrl)),2e3)}))}},_exports.default})); //# sourceMappingURL=task_indicator.min.js.map \ No newline at end of file diff --git a/lib/amd/build/task_indicator.min.js.map b/lib/amd/build/task_indicator.min.js.map index f2428452b3bed..46134469bea6e 100644 --- a/lib/amd/build/task_indicator.min.js.map +++ b/lib/amd/build/task_indicator.min.js.map @@ -1 +1 @@ -{"version":3,"file":"task_indicator.min.js","sources":["../src/task_indicator.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * Task indicator\n *\n * Watches the progress bar inside the task indicator for updates, and redirects when the progress is complete.\n *\n * @module core/task_indicator\n * @copyright 2024 Catalyst IT Europe Ltd\n * @author Mark Johnson \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\nexport default class {\n /**\n * Watch the progress bar for updates.\n *\n * When the progress bar is updated to 100%, wait a couple of seconds so the user gets to see it if they are watching,\n * then redirect to the specified URL.\n *\n * @param {String} id\n * @param {String} redirectUrl\n */\n static init(id, redirectUrl) {\n document.getElementById(id).addEventListener('update', (event) => {\n // Once progress has started, remove the run link.\n const runlink = document.querySelector(`.runlink[data-idnumber=${id}]`);\n if (runlink && event.detail.percent > 0) {\n runlink.remove();\n }\n // Once the progress bar completes, redirect the page.\n if (redirectUrl !== '' && event.detail.percent === 100) {\n window.setTimeout(() => window.location.assign(redirectUrl), 2000);\n }\n });\n }\n}\n"],"names":["id","redirectUrl","document","getElementById","addEventListener","event","runlink","querySelector","detail","percent","remove","window","setTimeout","location","assign"],"mappings":";;;;;;;;;;;kBAmCgBA,GAAIC,aACZC,SAASC,eAAeH,IAAII,iBAAiB,UAAWC,cAE9CC,QAAUJ,SAASK,+CAAwCP,SAC7DM,SAAWD,MAAMG,OAAOC,QAAU,GAClCH,QAAQI,SAGQ,KAAhBT,aAA+C,MAAzBI,MAAMG,OAAOC,SACnCE,OAAOC,YAAW,IAAMD,OAAOE,SAASC,OAAOb,cAAc"} \ No newline at end of file +{"version":3,"file":"task_indicator.min.js","sources":["../src/task_indicator.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * Task indicator\n *\n * Watches the progress bar inside the task indicator for updates, and redirects when the progress is complete.\n *\n * @module core/task_indicator\n * @copyright 2024 Catalyst IT Europe Ltd\n * @author Mark Johnson \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\nexport default class {\n /**\n * Watch the progress bar for updates.\n *\n * When the progress bar is updated to 100%, wait a couple of seconds so the user gets to see it if they are watching,\n * then redirect to the specified URL.\n *\n * @param {String} id\n * @param {String} redirectUrl\n */\n static init(id, redirectUrl) {\n const bar = document.getElementById(id);\n bar.addEventListener('update', (event) => {\n if (event.detail.percent > 0) {\n // Once progress starts, display the progress bar and remove the run link.\n bar.classList.remove('stored-progress-notstarted');\n const runlink = document.querySelector(`.runlink[data-idnumber=${id}]`);\n if (runlink && event.detail.percent > 0) {\n runlink.remove();\n }\n }\n // Once the progress bar completes, redirect the page.\n if (redirectUrl !== '' && event.detail.percent === 100) {\n window.setTimeout(() => window.location.assign(redirectUrl), 2000);\n }\n });\n }\n}\n"],"names":["id","redirectUrl","bar","document","getElementById","addEventListener","event","detail","percent","classList","remove","runlink","querySelector","window","setTimeout","location","assign"],"mappings":";;;;;;;;;;;kBAmCgBA,GAAIC,mBACNC,IAAMC,SAASC,eAAeJ,IACpCE,IAAIG,iBAAiB,UAAWC,WACxBA,MAAMC,OAAOC,QAAU,EAAG,CAE1BN,IAAIO,UAAUC,OAAO,oCACfC,QAAUR,SAASS,+CAAwCZ,SAC7DW,SAAWL,MAAMC,OAAOC,QAAU,GAClCG,QAAQD,SAII,KAAhBT,aAA+C,MAAzBK,MAAMC,OAAOC,SACnCK,OAAOC,YAAW,IAAMD,OAAOE,SAASC,OAAOf,cAAc"} \ No newline at end of file diff --git a/lib/amd/src/task_indicator.js b/lib/amd/src/task_indicator.js index 189513a83e81d..77ec08a8d599b 100644 --- a/lib/amd/src/task_indicator.js +++ b/lib/amd/src/task_indicator.js @@ -34,11 +34,15 @@ export default class { * @param {String} redirectUrl */ static init(id, redirectUrl) { - document.getElementById(id).addEventListener('update', (event) => { - // Once progress has started, remove the run link. - const runlink = document.querySelector(`.runlink[data-idnumber=${id}]`); - if (runlink && event.detail.percent > 0) { - runlink.remove(); + const bar = document.getElementById(id); + bar.addEventListener('update', (event) => { + if (event.detail.percent > 0) { + // Once progress starts, display the progress bar and remove the run link. + bar.classList.remove('stored-progress-notstarted'); + const runlink = document.querySelector(`.runlink[data-idnumber=${id}]`); + if (runlink && event.detail.percent > 0) { + runlink.remove(); + } } // Once the progress bar completes, redirect the page. if (redirectUrl !== '' && event.detail.percent === 100) { diff --git a/lib/templates/task_indicator.mustache b/lib/templates/task_indicator.mustache index 15981e9661726..507aad198edf5 100644 --- a/lib/templates/task_indicator.mustache +++ b/lib/templates/task_indicator.mustache @@ -33,6 +33,7 @@ "id": "progressbar_test", "message": "Recalculating grades", "idnumber": "progressbar_test", + "class": "stored-progress-bar", "width": "500", "value": "50" } @@ -48,14 +49,15 @@

{{heading}}

{{message}}

- {{#progress}} - {{>core/progress_bar}} - {{/progress}} {{#runurl}}

{{runlabel}}

{{/runurl}} + {{#progress}} + {{>core/progress_bar}} + {{/progress}} +