diff --git a/.gitignore b/.gitignore index f0b547b..fed987d 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,7 @@ # Node and Grunt files node_modules - +Gruntfile.js ## Core latex/pdflatex auxiliary files: *.aux diff --git a/RELEASENOTES.md b/RELEASENOTES.md index f3f88b4..260c2bd 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -2,10 +2,12 @@ ## Release notes -### Version 1.4.5, 2017-04-xx +### Version 1.5, 2017-04-14 -* Code refactored, not using eval() any more, issue #12 -* TO BE CONTINUED +* Code doesn't use eval() any more, issue #12 +* Javascript code refactored, using AMD, issue #11 +* Documentation updated (release notes have their own file now), issue #13 +* Plugin is now published on Moodle plugin database ### Version 1.4.4, 2017-04-11 diff --git a/amd/build/timediff.min.js b/amd/build/timediff.min.js new file mode 100644 index 0000000..19ae61d --- /dev/null +++ b/amd/build/timediff.min.js @@ -0,0 +1 @@ +define(["core/str","core/notification"],function(a,b){return{init:function(c){var d=Math.round(M.pageloadstarttime.getTime()/1e3);Math.abs(d-c)>=300&&a.get_strings([{key:"datetimesetmessage",component:"tool_moodlebox"}]).done(function(a){b.addNotification({message:a[0],type:"error"})}).fail(b.exception)}}}); \ No newline at end of file diff --git a/amd/src/timediff.js b/amd/src/timediff.js new file mode 100644 index 0000000..d550166 --- /dev/null +++ b/amd/src/timediff.js @@ -0,0 +1,47 @@ +// This file is part of Moodle - http://moodle.org/ +// +// Moodle is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Moodle is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Moodle. If not, see . + +/* + * @see https://github.com/martignoni/moodle-tool_moodlebox + * @package tool_moodlebox + * @copyright 2016 onwards Nicolas Martignoni + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +/** + * @module tool_moodlebox/timediff + */ +define(['core/str', 'core/notification'], function(str, notification) { + + return /** @alias module:tool/moodlebox */ { + /** + * Global init function for this module. + * + * @method init + * @param {Object} servertime The timestamp of current time on the server. + */ + init: function(servertime) { + var usertime = Math.round(M.pageloadstarttime.getTime() / 1000); + if (Math.abs(usertime - servertime) >= 300) { // time difference greater than 5 minutes + str.get_strings([{'key': 'datetimesetmessage', component: 'tool_moodlebox'},]).done(function(s) { + notification.addNotification({ + message: s[0], + type: 'error' + }); + }).fail(notification.exception); + } + } + }; +}); diff --git a/index.php b/index.php index f7016bd..c6c0139 100644 --- a/index.php +++ b/index.php @@ -69,10 +69,8 @@ if ( strpos($platform, 'rpi') !== false ) { // We are on a RPi. - $PAGE->requires->js('/admin/tool/moodlebox/utils.js'); $systemtime = usergetdate(time())[0]; - - $PAGE->requires->js_init_call('checktime', array($systemtime)); + $PAGE->requires->js_call_amd('tool_moodlebox/timediff', 'init', array($systemtime)); // Get kernel version $kernelversion = php_uname('s') . ' ' . php_uname('r') . ' ' . php_uname('m'); diff --git a/package.json b/package.json new file mode 100644 index 0000000..f8cacd0 --- /dev/null +++ b/package.json @@ -0,0 +1,12 @@ +{ + "name": "moodle-tool_moodlebox", + "devDependencies": { + "grunt": "^1.0.1", + "grunt-contrib-less": "^1.4.1", + "grunt-contrib-uglify": "^2.3.0", + "grunt-contrib-watch": "^1.0.0", + "grunt-eslint": "^19.0.0", + "grunt-load-gruntfile": "0.0.2", + "grunt-stylelint": "^0.7.0" + } +} diff --git a/utils.js b/utils.js deleted file mode 100644 index 5cc489c..0000000 --- a/utils.js +++ /dev/null @@ -1,14 +0,0 @@ -var checktime = function(Y, servertime) { - var usertime = Math.round(M.pageloadstarttime.getTime() / 1000); - if (Math.abs(usertime - servertime) >= 60) { // time difference greater than 1 minute - require(['core/str', 'core/notification'], function(str, notification) { - str.get_strings([{'key': 'datetimesetmessage', component: 'tool_moodlebox'},]).done(function(s) { - notification.addNotification({ - message: s[0], - type: 'error' - }); - }).fail(notification.exception); - }); - } - return usertime; -} diff --git a/version.php b/version.php index 61ad195..ca4c999 100644 --- a/version.php +++ b/version.php @@ -26,8 +26,8 @@ $plugin = new stdClass(); -$plugin->version = 2017041200; -$plugin->release = '1.4.5dev'; +$plugin->version = 2017041400; +$plugin->release = '1.5'; $plugin->requires = 2015051103; $plugin->maturity = MATURITY_STABLE; $plugin->component = 'tool_moodlebox';