Merge branch 'MDL-57023-master' of git://github.com/andrewnicols/moodle

This commit is contained in:
David Monllao
2016-11-22 10:23:21 +08:00
5 changed files with 52 additions and 9 deletions
File diff suppressed because one or more lines are too long
+41
View File
@@ -37,6 +37,20 @@ function Tour(config) {
*/
Tour.prototype.tourName;
/**
* The name of the tour storage key.
*
* @property {String} storageKey
*/
Tour.prototype.storageKey;
/**
* The session storage object
*
* @property {Storage} storage
*/
Tour.prototype.storage;
/**
* The original configuration as passed into the constructor.
*
@@ -120,6 +134,14 @@ Tour.prototype.init = function (config) {
// Apply configuration.
this.configure.apply(this, arguments);
try {
this.storage = window.sessionStorage;
this.storageKey = 'tourstate_' + this.tourName;
} catch (e) {
this.storage = false;
this.storageKey = '';
}
return this;
};
@@ -280,6 +302,15 @@ Tour.prototype.getCurrentStepNumber = function () {
*/
Tour.prototype.setCurrentStepNumber = function (stepNumber) {
this.currentStepNumber = stepNumber;
if (this.storage) {
try {
this.storage.setItem(this.storageKey, stepNumber);
} catch (e) {
if (e.code === DOMException.QUOTA_EXCEEDED_ERR) {
this.storage.removeItem(this.storageKey);
}
}
}
};
/**
@@ -957,6 +988,16 @@ Tour.prototype.handleKeyDown = function (e) {
* @chainable
*/
Tour.prototype.startTour = function (startAt) {
if (this.storage && typeof startAt === 'undefined') {
var storageStartValue = this.storage.getItem(this.storageKey);
if (storageStartValue) {
var storageStartAt = parseInt(storageStartValue, 10);
if (storageStartAt <= this.steps.length) {
startAt = storageStartAt;
}
}
}
if (typeof startAt === 'undefined') {
startAt = this.getCurrentStepNumber();
}
+3 -1
View File
@@ -608,6 +608,8 @@ class tour {
* This is used in the session cookie to determine whether the user has seen this tour before.
*/
public function get_tour_key() {
global $USER;
$tourtime = $this->get_config('majorupdatetime', null);
if ($tourtime === null) {
@@ -622,7 +624,7 @@ class tour {
$tourtime = max($tourtime, $userresetdate);
}
return sprintf('tool_usertours_%d_%s', $this->get_id(), $tourtime);
return sprintf('tool_usertours_%d_%d_%s', $USER->id, $this->get_id(), $tourtime);
}
/**
+6 -6
View File
@@ -729,7 +729,7 @@ class tour_testcase extends advanced_testcase {
$this->greaterThanOrEqual($time),
true,
null,
sprintf('tool_usertours_%d_%s', $id, $time),
sprintf('tool_usertours_\d_%d_%s', $id, $time),
],
'Initial tour time, no user pref' => [
@@ -738,7 +738,7 @@ class tour_testcase extends advanced_testcase {
null,
false,
null,
sprintf('tool_usertours_%d_%s', $id, $time),
sprintf('tool_usertours_\d_%d_%s', $id, $time),
],
'Initial tour time, with user reset lower' => [
$id,
@@ -746,7 +746,7 @@ class tour_testcase extends advanced_testcase {
null,
false,
$time - DAYSECS,
sprintf('tool_usertours_%d_%s', $id, $time),
sprintf('tool_usertours_\d_%d_%s', $id, $time),
],
'Initial tour time, with user reset higher' => [
$id,
@@ -754,7 +754,7 @@ class tour_testcase extends advanced_testcase {
null,
false,
$time + DAYSECS,
sprintf('tool_usertours_%d_%s', $id, $time + DAYSECS),
sprintf('tool_usertours_\d_%d_%s', $id, $time + DAYSECS),
],
];
}
@@ -823,8 +823,8 @@ class tour_testcase extends advanced_testcase {
set_user_preference(\tool_usertours\tour::TOUR_REQUESTED_BY_USER . $id, $userpref);
}
$this->assertEquals(
$expectation,
$this->assertRegExp(
'/' . $expectation . '/',
$tour->get_tour_key()
);
}
+1 -1
View File
@@ -4,7 +4,7 @@
<location>amd/src/tour.js</location>
<name>Flexitour</name>
<license>GPLv3</license>
<version>0.9.9</version>
<version>0.9.10</version>
<licenseversion>3</licenseversion>
</library>
<library>