From fb7caf79829cb859904e7f9e965c20e63d2d297b Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Thu, 11 Nov 2021 10:50:40 +0800 Subject: [PATCH] MDL-68913 assign: Address coding style issues --- mod/assign/amd/build/timer.min.js | 2 +- mod/assign/amd/build/timer.min.js.map | 2 +- mod/assign/amd/src/timer.js | 8 ++------ mod/assign/classes/output/timelimit_panel.php | 2 -- mod/assign/settings.php | 6 ++++-- 5 files changed, 8 insertions(+), 12 deletions(-) diff --git a/mod/assign/amd/build/timer.min.js b/mod/assign/amd/build/timer.min.js index 025a507d590..fd1b30a0d51 100644 --- a/mod/assign/amd/build/timer.min.js +++ b/mod/assign/amd/build/timer.min.js @@ -1,2 +1,2 @@ -define ("mod_assign/timer",["exports","core/notification","core/str"],function(a,b,c){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.init=void 0;b=function(a){return a&&a.__esModule?a:{default:a}}(b);var d=0,e=null,f=null,g=function(a){var b=Math.floor(a/3600),c=Math.floor(a/60)%60;return[b,c,a%60].filter(function(a,b){return 0!==a||0=j){f.classList.add("alert","alert-danger");f.innerHTML="00:00:00";if(document.getElementById("mod_assign_timelimit_block")){(0,c.get_string)("caneditsubmission","mod_assign").done(function(a){return b.default.addNotification({type:"error",message:a})}).fail(b.default.exception)}h();return}else if(300>j){f.classList.remove("alert-warning");f.classList.add("alert","alert-danger")}else if(900>j){f.classList.remove("alert-danger");f.classList.add("alert","alert-warning")}f.innerHTML=g(j);e=setTimeout(i,500)},j=function(a){f=document.getElementById(a);d=M.pageloadstarttime.getTime()+1e3*f.dataset.starttime;i()};a.init=j}); +define ("mod_assign/timer",["exports","core/notification","core/str"],function(a,b,c){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.init=void 0;b=function(a){return a&&a.__esModule?a:{default:a}}(b);var d=0,e=null,f=null,g=function(a){var b=Math.floor(a/3600),c=Math.floor(a/60)%60;return[b,c,a%60].filter(function(a,b){return 0!==a||0=j){f.classList.add("alert","alert-danger");f.innerHTML="00:00:00";if(document.getElementById("mod_assign_timelimit_block")){(0,c.get_string)("caneditsubmission","mod_assign").then(function(a){return b.default.addNotification({message:a})}).catch(b.default.exception)}h();return}else if(300>j){f.classList.remove("alert-warning");f.classList.add("alert","alert-danger")}else if(900>j){f.classList.remove("alert-danger");f.classList.add("alert","alert-warning")}f.innerHTML=g(j);e=setTimeout(i,500)},j=function(a){f=document.getElementById(a);d=M.pageloadstarttime.getTime()+1e3*f.dataset.starttime;i()};a.init=j}); //# sourceMappingURL=timer.min.js.map diff --git a/mod/assign/amd/build/timer.min.js.map b/mod/assign/amd/build/timer.min.js.map index d8d0350720a..14f7575846c 100644 --- a/mod/assign/amd/build/timer.min.js.map +++ b/mod/assign/amd/build/timer.min.js.map @@ -1 +1 @@ -{"version":3,"sources":["../src/timer.js"],"names":["endTime","timeoutId","timer","formatSeconds","secs","hours","Math","floor","minutes","filter","value","index","map","padStart","join","stop","clearTimeout","update","now","Date","getTime","secondsLeft","classList","add","innerHTML","document","getElementById","done","str","Notification","addNotification","type","message","fail","exception","remove","setTimeout","init","timerId","M","pageloadstarttime","dataset","starttime"],"mappings":"kKAeA,uD,GAeIA,CAAAA,CAAO,CAAG,C,CAOVC,CAAS,CAAG,I,CAOZC,CAAK,CAAG,I,CASNC,CAAa,CAAG,SAACC,CAAD,CAAU,IACtBC,CAAAA,CAAK,CAAGC,IAAI,CAACC,KAAL,CAAWH,CAAI,CAAG,IAAlB,CADc,CAEtBI,CAAO,CAAGF,IAAI,CAACC,KAAL,CAAWH,CAAI,CAAG,EAAlB,EAAwB,EAFZ,CAK5B,MAAO,CAACC,CAAD,CAAQG,CAAR,CAFSJ,CAAI,CAAG,EAEhB,EAEFK,MAFE,CAEK,SAACC,CAAD,CAAQC,CAAR,QAA4B,EAAV,GAAAD,CAAK,EAAkB,CAAR,CAAAC,CAAjC,CAFL,EAIFC,GAJE,CAIE,SAAAF,CAAK,QAAI,UAAGA,CAAH,EAAWG,QAAX,CAAoB,CAApB,C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,CAACnB,CAAD,CAAS,GAAT,CACzB,C,CAQYoB,CAAI,CAAG,SAACC,CAAD,CAAa,CAC7BpC,CAAK,CAAGuB,QAAQ,CAACC,cAAT,CAAwBY,CAAxB,CAAR,CACAtC,CAAO,CAAGuC,CAAC,CAACC,iBAAF,CAAoBpB,OAApB,GAA2D,GAA1B,CAAAlB,CAAK,CAACuC,OAAN,CAAcC,SAAzD,CACAzB,CAAM,EACT,C","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\nimport Notification from 'core/notification';\nimport {get_string as getString} from 'core/str';\n\n/**\n * A javascript module for the time in the assign module.\n *\n * @copyright 2020 Matt Porritt \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\n/**\n * Timestamp at which time runs out.\n *\n * @property {Number} endTime\n */\nlet endTime = 0;\n\n/**\n * ID of the timeout that updates the clock.\n *\n * @property {Number} timeoutId\n */\nlet timeoutId = null;\n\n/**\n * The timer element.\n *\n * @property {Element} timer\n */\nlet timer = null;\n\n/**\n * Helper method to convert time remaining in seconds into HH:MM:SS format.\n *\n * @method formatSeconds\n * @param {Number} secs Time remaining in seconds to get value for.\n * @return {String} Time remaining in HH:MM:SS format.\n */\nconst formatSeconds = (secs) => {\n const hours = Math.floor(secs / 3600);\n const minutes = Math.floor(secs / 60) % 60;\n const seconds = secs % 60;\n\n return [hours, minutes, seconds]\n // Remove the hours column if there is less than 1 hour left.\n .filter((value, index) => value !== 0 || index > 0)\n // Ensure that all fields are two digit numbers.\n .map(value => `${value}`.padStart(2, '0'))\n .join(\":\");\n};\n\n/**\n * Stop the timer, if it is running.\n *\n * @method stop\n */\nconst stop = () => {\n if (timeoutId) {\n clearTimeout(timeoutId);\n }\n};\n\n/**\n * Function to update the clock with the current time left.\n *\n * @method update\n */\nconst update = () => {\n const now = new Date().getTime();\n const secondsLeft = Math.floor((endTime - now) / 1000);\n\n // If time has expired, set the hidden form field that says time has expired.\n if (secondsLeft <= 0) {\n timer.classList.add('alert', 'alert-danger');\n timer.innerHTML = '00:00:00';\n\n // Only add a notification on the assign submission page.\n if (document.getElementById(\"mod_assign_timelimit_block\")) {\n getString('caneditsubmission', 'mod_assign')\n .done(\n str => Notification.addNotification({\n type: \"error\",\n message: str\n })\n ).fail(Notification.exception);\n }\n\n stop();\n return;\n } else if (secondsLeft < 300) { // Add danger style when less than 5 minutes left.\n timer.classList.remove('alert-warning');\n timer.classList.add('alert', 'alert-danger');\n } else if (secondsLeft < 900) { // Add warning style when less than 15 minutes left.\n timer.classList.remove('alert-danger');\n timer.classList.add('alert', 'alert-warning');\n }\n\n // Update the time display.\n timer.innerHTML = formatSeconds(secondsLeft);\n\n // Arrange for this method to be called again soon.\n timeoutId = setTimeout(update, 500);\n};\n\n/**\n * Set up the submission timer.\n *\n * @method init\n * @param {Number} timerId Unique ID of the timer element.\n */\nexport const init = (timerId) => {\n timer = document.getElementById(timerId);\n endTime = M.pageloadstarttime.getTime() + (timer.dataset.starttime * 1000);\n update();\n};\n"],"file":"timer.min.js"} \ No newline at end of file +{"version":3,"sources":["../src/timer.js"],"names":["endTime","timeoutId","timer","formatSeconds","secs","hours","Math","floor","minutes","filter","value","index","map","padStart","join","stop","clearTimeout","update","now","Date","getTime","secondsLeft","classList","add","innerHTML","document","getElementById","then","message","Notification","addNotification","catch","exception","remove","setTimeout","init","timerId","M","pageloadstarttime","dataset","starttime"],"mappings":"kKAeA,uD,GAeIA,CAAAA,CAAO,CAAG,C,CAOVC,CAAS,CAAG,I,CAOZC,CAAK,CAAG,I,CASNC,CAAa,CAAG,SAAC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AACoB,SAAN,CAAgBW,MAAhB,CAAuB,eAAvB,EACA/B,CAAK,CAACoB,SAAN,CAAgBC,GAAhB,CAAoB,OAApB,CAA6B,cAA7B,CACH,CAHM,IAGA,IAAkB,GAAd,CAAAF,CAAJ,CAAuB,CAC1BnB,CAAK,CAACoB,SAAN,CAAgBW,MAAhB,CAAuB,cAAvB,EACA/B,CAAK,CAACoB,SAAN,CAAgBC,GAAhB,CAAoB,OAApB,CAA6B,eAA7B,CACH,CAGDrB,CAAK,CAACsB,SAAN,CAAkBrB,CAAa,CAACkB,CAAD,CAA/B,CAGApB,CAAS,CAAGiC,UAAU,CAACjB,CAAD,CAAS,GAAT,CACzB,C,CAQYkB,CAAI,CAAG,SAACC,CAAD,CAAa,CAC7BlC,CAAK,CAAGuB,QAAQ,CAACC,cAAT,CAAwBU,CAAxB,CAAR,CACApC,CAAO,CAAGqC,CAAC,CAACC,iBAAF,CAAoBlB,OAApB,GAA2D,GAA1B,CAAAlB,CAAK,CAACqC,OAAN,CAAcC,SAAzD,CACAvB,CAAM,EACT,C","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\nimport Notification from 'core/notification';\nimport {get_string as getString} from 'core/str';\n\n/**\n * A javascript module for the time in the assign module.\n *\n * @copyright 2020 Matt Porritt \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\n/**\n * Timestamp at which time runs out.\n *\n * @property {Number} endTime\n */\nlet endTime = 0;\n\n/**\n * ID of the timeout that updates the clock.\n *\n * @property {Number} timeoutId\n */\nlet timeoutId = null;\n\n/**\n * The timer element.\n *\n * @property {Element} timer\n */\nlet timer = null;\n\n/**\n * Helper method to convert time remaining in seconds into HH:MM:SS format.\n *\n * @method formatSeconds\n * @param {Number} secs Time remaining in seconds to get value for.\n * @return {String} Time remaining in HH:MM:SS format.\n */\nconst formatSeconds = (secs) => {\n const hours = Math.floor(secs / 3600);\n const minutes = Math.floor(secs / 60) % 60;\n const seconds = secs % 60;\n\n return [hours, minutes, seconds]\n // Remove the hours column if there is less than 1 hour left.\n .filter((value, index) => value !== 0 || index > 0)\n // Ensure that all fields are two digit numbers.\n .map(value => `${value}`.padStart(2, '0'))\n .join(\":\");\n};\n\n/**\n * Stop the timer, if it is running.\n *\n * @method stop\n */\nconst stop = () => {\n if (timeoutId) {\n clearTimeout(timeoutId);\n }\n};\n\n/**\n * Function to update the clock with the current time left.\n *\n * @method update\n */\nconst update = () => {\n const now = new Date().getTime();\n const secondsLeft = Math.floor((endTime - now) / 1000);\n\n // If time has expired, set the hidden form field that says time has expired.\n if (secondsLeft <= 0) {\n timer.classList.add('alert', 'alert-danger');\n timer.innerHTML = '00:00:00';\n\n // Only add a notification on the assign submission page.\n if (document.getElementById(\"mod_assign_timelimit_block\")) {\n getString('caneditsubmission', 'mod_assign')\n .then(message => Notification.addNotification({message}))\n .catch(Notification.exception);\n }\n\n stop();\n return;\n } else if (secondsLeft < 300) { // Add danger style when less than 5 minutes left.\n timer.classList.remove('alert-warning');\n timer.classList.add('alert', 'alert-danger');\n } else if (secondsLeft < 900) { // Add warning style when less than 15 minutes left.\n timer.classList.remove('alert-danger');\n timer.classList.add('alert', 'alert-warning');\n }\n\n // Update the time display.\n timer.innerHTML = formatSeconds(secondsLeft);\n\n // Arrange for this method to be called again soon.\n timeoutId = setTimeout(update, 500);\n};\n\n/**\n * Set up the submission timer.\n *\n * @method init\n * @param {Number} timerId Unique ID of the timer element.\n */\nexport const init = (timerId) => {\n timer = document.getElementById(timerId);\n endTime = M.pageloadstarttime.getTime() + (timer.dataset.starttime * 1000);\n update();\n};\n"],"file":"timer.min.js"} \ No newline at end of file diff --git a/mod/assign/amd/src/timer.js b/mod/assign/amd/src/timer.js index bc3523b5315..1ce7cce0d33 100644 --- a/mod/assign/amd/src/timer.js +++ b/mod/assign/amd/src/timer.js @@ -92,12 +92,8 @@ const update = () => { // Only add a notification on the assign submission page. if (document.getElementById("mod_assign_timelimit_block")) { getString('caneditsubmission', 'mod_assign') - .done( - str => Notification.addNotification({ - type: "error", - message: str - }) - ).fail(Notification.exception); + .then(message => Notification.addNotification({message})) + .catch(Notification.exception); } stop(); diff --git a/mod/assign/classes/output/timelimit_panel.php b/mod/assign/classes/output/timelimit_panel.php index 40da292d4f0..33025588b04 100644 --- a/mod/assign/classes/output/timelimit_panel.php +++ b/mod/assign/classes/output/timelimit_panel.php @@ -23,8 +23,6 @@ */ namespace mod_assign\output; -defined('MOODLE_INTERNAL') || die(); - use renderable; use renderer_base; use stdClass; diff --git a/mod/assign/settings.php b/mod/assign/settings.php index 7c83395123b..5d89597fa90 100644 --- a/mod/assign/settings.php +++ b/mod/assign/settings.php @@ -153,10 +153,12 @@ if ($ADMIN->fulltree) { $name = new lang_string('enabletimelimit', 'mod_assign'); $description = new lang_string('enabletimelimit_help', 'mod_assign'); - $setting = new admin_setting_configcheckbox('assign/enabletimelimit', + $setting = new admin_setting_configcheckbox( + 'assign/enabletimelimit', $name, $description, - 0); + 0 + ); $settings->add($setting); $name = new lang_string('gradingduedate', 'mod_assign');