Skip to content

Commit

Permalink
Javascript code refactored, using AMD, issue #11
Browse files Browse the repository at this point in the history
  • Loading branch information
martignoni committed Apr 14, 2017
1 parent 7bebebb commit 85a39e7
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

# Node and Grunt files
node_modules

Gruntfile.js

## Core latex/pdflatex auxiliary files:
*.aux
Expand Down
8 changes: 5 additions & 3 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions amd/build/timediff.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 47 additions & 0 deletions amd/src/timediff.js
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.

/*
* @see https://github.com/martignoni/moodle-tool_moodlebox
* @package tool_moodlebox
* @copyright 2016 onwards Nicolas Martignoni <[email protected]>
* @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);
}
}
};
});
4 changes: 1 addition & 3 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
12 changes: 12 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
14 changes: 0 additions & 14 deletions utils.js

This file was deleted.

4 changes: 2 additions & 2 deletions version.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

0 comments on commit 85a39e7

Please sign in to comment.