Merge branch 'MDL-71938-master' of git://github.com/HuongNV13/moodle

This commit is contained in:
Shamim Rezaie
2021-10-07 17:05:11 +11:00
18 changed files with 193 additions and 16 deletions
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+54 -8
View File
@@ -26,6 +26,8 @@ import * as Aria from 'core/aria';
import Popper from 'core/popper';
import {dispatchEvent} from 'core/event_dispatcher';
import {eventTypes} from './events';
import {get_string as getString} from 'core/str';
import {prefetchStrings} from 'core/prefetch';
/**
* A user tour.
@@ -72,6 +74,10 @@ const Tour = class {
this.storageKey = '';
}
prefetchStrings('tool_usertours', [
'nextstep_sequence'
]);
return this;
}
@@ -352,6 +358,27 @@ const Tour = class {
return false;
}
/**
* Get potentially visible steps in a tour.
*
* @return {{stepId: number, position: number}[]} An associative array with stepNumber as keys
* and an object of stepId and position as values.
*/
getPotentiallyVisibleSteps() {
let position = 1;
let result = [];
// Checking the total steps.
for (let stepNumber = 0; stepNumber < this.steps.length; stepNumber++) {
const stepConfig = this.getStepConfig(stepNumber);
if (this.isStepPotentiallyVisible(stepConfig)) {
result[stepNumber] = {stepId: stepConfig.stepid, position: position};
position++;
}
}
return result;
}
/**
* Is this step actually visible?
*
@@ -659,24 +686,43 @@ const Tour = class {
template.find('[data-placeholder="body"]')
.html(stepConfig.body);
// Buttons.
const nextBtn = template.find('[data-role="next"]');
const previousBtn = template.find('[data-role="previous"]');
const endBtn = template.find('[data-role="end"]');
// Is this the first step?
if (this.isFirstStep(stepConfig.stepNumber)) {
template.find('[data-role="previous"]').hide();
previousBtn.hide();
} else {
template.find('[data-role="previous"]').prop('disabled', false);
previousBtn.prop('disabled', false);
}
// Is this the final step?
if (this.isLastStep(stepConfig.stepNumber)) {
template.find('[data-role="next"]').hide();
template.find('[data-role="end"]').removeClass("btn-secondary").addClass("btn-primary");
nextBtn.hide();
endBtn.removeClass("btn-secondary").addClass("btn-primary");
} else {
template.find('[data-role="next"]').prop('disabled', false);
nextBtn.prop('disabled', false);
}
template.find('[data-role="previous"]').attr('role', 'button');
template.find('[data-role="next"]').attr('role', 'button');
template.find('[data-role="end"]').attr('role', 'button');
previousBtn.attr('role', 'button');
nextBtn.attr('role', 'button');
endBtn.attr('role', 'button');
if (this.originalConfiguration.displaystepnumbers) {
const stepsPotentiallyVisible = this.getPotentiallyVisibleSteps();
const totalStepsPotentiallyVisible = stepsPotentiallyVisible.length;
const position = stepsPotentiallyVisible[stepConfig.stepNumber].position;
if (totalStepsPotentiallyVisible > 1) {
// Change the label of the Next button to include the sequence.
getString('nextstep_sequence', 'tool_usertours',
{position: position, total: totalStepsPotentiallyVisible}).then(value => {
nextBtn.html(value);
return;
}).catch();
}
}
// Replace the template with the updated version.
stepConfig.template = template;
+1
View File
@@ -105,6 +105,7 @@ class tour extends external_api {
'name' => new external_value(PARAM_RAW, 'Tour Name'),
'steps' => new external_multiple_structure(self::step_structure_returns()),
'endtourlabel' => new external_value(PARAM_RAW, 'Label of the end tour button'),
'displaystepnumbers' => new external_value(PARAM_BOOL, 'display step number'),
], 'Tour config', VALUE_OPTIONAL)
]);
}
@@ -83,6 +83,9 @@ class edittour extends \moodleform {
$mform->setType('endtourlabel', PARAM_TEXT);
$mform->addHelpButton('endtourlabel', 'endtourlabel', 'tool_usertours');
$mform->addElement('checkbox', 'displaystepnumbers', get_string('displaystepnumbers', 'tool_usertours'));
$mform->addHelpButton('displaystepnumbers', 'displaystepnumbers', 'tool_usertours');
// Configuration.
$this->tour->add_config_to_form($mform);
+1
View File
@@ -371,6 +371,7 @@ class manager {
$tour->set_pathmatch($data->pathmatch);
$tour->set_enabled(!empty($data->enabled));
$tour->set_endtourlabel($data->endtourlabel);
$tour->set_display_step_numbers(!empty($data->displaystepnumbers));
foreach (configuration::get_defaultable_keys() as $key) {
$tour->set_config($key, $data->$key);
@@ -61,6 +61,7 @@ class tour implements \renderable {
'name' => $this->tour->get_tour_key(),
'steps' => [],
'endtourlabel' => $this->tour->get_endtourlabel(),
'displaystepnumbers' => $this->tour->get_display_step_numbers(),
];
foreach ($this->tour->get_steps() as $step) {
+29
View File
@@ -119,6 +119,11 @@ class tour {
*/
protected $steps = [];
/**
* @var bool $displaystepnumbers Display the step numbers in this tour.
*/
protected $displaystepnumbers = true;
/**
* Create an instance of the specified tour.
*
@@ -196,6 +201,7 @@ class tour {
$this->config = json_decode($record->configdata);
$this->dirty = false;
$this->steps = [];
$this->displaystepnumbers = !empty($record->displaystepnumbers);
return $this;
}
@@ -427,6 +433,7 @@ class tour {
'sortorder' => $this->sortorder,
'endtourlabel' => $this->endtourlabel,
'configdata' => json_encode($this->config),
'displaystepnumbers' => $this->displaystepnumbers,
);
}
@@ -843,4 +850,26 @@ class tour {
return $results;
}
/**
* Set the value for the display step numbers setting.
*
* @param bool $value True for enable.
* @return $this
*/
public function set_display_step_numbers(bool $value): tour {
$this->displaystepnumbers = $value;
$this->dirty = true;
return $this;
}
/**
* Get the value of the display step numbers setting.
*
* @return bool
*/
public function get_display_step_numbers(): bool {
return $this->displaystepnumbers;
}
}
+2 -1
View File
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="admin/tool/usertours/db" VERSION="20210923" COMMENT="XMLDB file for Moodle tool/usertours"
<XMLDB PATH="admin/tool/usertours/db" VERSION="20211007" COMMENT="XMLDB file for Moodle tool/usertours"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../../lib/xmldb/xmldb.xsd"
>
@@ -14,6 +14,7 @@
<FIELD NAME="sortorder" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="endtourlabel" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false" COMMENT="Custom label for the end tour button"/>
<FIELD NAME="configdata" TYPE="text" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="displaystepnumbers" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="Setting to display step numbers of the tour"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
+15
View File
@@ -99,5 +99,20 @@ function xmldb_tool_usertours_upgrade($oldversion) {
upgrade_plugin_savepoint(true, 2021092300, 'tool', 'usertours');
}
if ($oldversion < 2021100700) {
// Define field displaystepnumbers to be added to tool_usertours_tours.
$table = new xmldb_table('tool_usertours_tours');
$field = new xmldb_field('displaystepnumbers', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0', 'configdata');
// Conditionally launch add field displaystepnumbers.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
// Usertours savepoint reached.
upgrade_plugin_savepoint(true, 2021100700, 'tool', 'usertours');
}
return true;
}
@@ -31,6 +31,8 @@ $string['block_named'] = 'Block named \'{$a}\'';
$string['cachedef_stepdata'] = 'List of user tour steps';
$string['cachedef_tourdata'] = 'List of enabled user tours information which is fetched on every page';
$string['description'] = 'Description';
$string['displaystepnumbers'] = 'Display step numbers';
$string['displaystepnumbers_help'] = 'Whether the number of steps remaining is displayed within the tour navigation';
$string['confirmstepremovalquestion'] = 'Are you sure that you wish to remove this step?';
$string['confirmstepremovaltitle'] = 'Confirm step removal';
$string['confirmtourremovalquestion'] = 'Are you sure that you wish to remove this tour?';
@@ -89,6 +91,7 @@ $string['newstep'] = 'New step';
$string['newtour'] = 'Create a new tour';
$string['next'] = 'Next';
$string['nextstep'] = 'Next';
$string['nextstep_sequence'] = 'Next ({$a->position}/{$a->total})';
$string['options_heading'] = 'Options';
$string['pathmatch'] = 'Apply to URL match';
$string['pathmatch_help'] = 'Tours will be displayed on any page whose URL matches this value.
@@ -79,3 +79,79 @@ Feature: Add a new user tour
When I click on "Enable" "link" in the "My first tour" "table_row"
And I am on homepage
Then I should see "Welcome to your personal learning space. We'd like to give you a quick tour to show you some of the areas you may find helpful"
@javascript
Scenario: Display step numbers was enabled
Given the following "users" exist:
| username | firstname | lastname | email |
| student1 | Student | 1 | student1@example.com |
And I log in as "admin"
And I add a new user tour with:
| Name | Steps tour |
| Description | My steps tour |
| Apply to URL match | /my/% |
| Tour is enabled | 1 |
| Display step numbers | 1 |
And I add steps to the "Steps tour" tour:
| targettype | Title | Content |
| Display in middle of page | Welcome | First step of the Tour |
And I add steps to the "Steps tour" tour:
| targettype | targetvalue_block | Title | Content |
| Block | Course overview | Course overview | Second step of the Tour |
| Block | Calendar | Calendar | Third step of the Tour |
When I am on homepage
Then I should see "First step of the Tour"
And I should see "Next (1/3)"
And I click on "Next (1/3)" "button" in the "[data-role='flexitour-step']" "css_element"
And I should see "Second step of the Tour"
And I should see "Next (2/3)"
And I click on "Next (2/3)" "button" in the "[data-role='flexitour-step']" "css_element"
And I should see "Third step of the Tour"
And I should not see "Next (3/3)"
@javascript
Scenario: Display step numbers was disabled
Given the following "users" exist:
| username | firstname | lastname | email |
| student1 | Student | 1 | student1@example.com |
And I log in as "admin"
And I add a new user tour with:
| Name | Steps tour |
| Description | My steps tour |
| Apply to URL match | /my/% |
| Tour is enabled | 1 |
| Display step numbers | 0 |
And I add steps to the "Steps tour" tour:
| targettype | Title | Content |
| Display in middle of page | Welcome | First step of the Tour |
And I add steps to the "Steps tour" tour:
| targettype | targetvalue_block | Title | Content |
| Block | Course overview | Course overview | Second step of the Tour |
| Block | Calendar | Calendar | Third step of the Tour |
When I am on homepage
Then I should see "First step of the Tour"
And I should see "Next"
And I should not see "Next (1/3)"
And I click on "Next" "button" in the "[data-role='flexitour-step']" "css_element"
And I should see "Second step of the Tour"
And I should see "Next"
And I should not see "Next (2/3)"
@javascript
Scenario: Single step tour with display step numbers was enable
Given the following "users" exist:
| username | firstname | lastname | email |
| student1 | Student | 1 | student1@example.com |
And I log in as "admin"
And I add a new user tour with:
| Name | Steps tour |
| Description | My steps tour |
| Apply to URL match | /my/% |
| Tour is enabled | 1 |
| Display step numbers | 1 |
And I add steps to the "Steps tour" tour:
| targettype | Title | Content |
| Display in middle of page | Welcome | This is a single step tour |
When I am on homepage
Then I should see "This is a single step tour"
And I should not see "Next (1/1)"
@@ -47,6 +47,7 @@ trait tool_usertours_helper_trait {
'name' => '',
'description' => '',
'configdata' => '',
'displaystepnumbers' => true
];
if ($tourconfig === null) {
@@ -1 +1 @@
{"name":"Activity information in activity page (Student)","description":"A tour of the activity information for Student display on the activity page","pathmatch":"\/mod\/%\/view.php%","enabled":"1","sortorder":"0","configdata":"{\"placement\":\"bottom\",\"orphan\":\"0\",\"backdrop\":\"1\",\"reflex\":\"0\",\"filtervalues\":{\"accessdate\":{\"filter_accessdate\":\"tool_usertours_accountcreation\",\"filter_accessdate_range\":0,\"filter_accessdate_enabled\":\"0\"},\"category\":[],\"course\":[],\"courseformat\":[],\"role\":[\"student\"],\"theme\":[],\"cssselector\":[\"[data-region=activity-information]\"]},\"majorupdatetime\":1620110287,\"shipped_tour\":true,\"shipped_filename\":\"311_activity_information_activity_page_student.json\",\"shipped_version\":1}","version":"2021052507","steps":[{"title":"tour_activityinfo_activity_student_title,tool_usertours","content":"tour_activityinfo_activity_student_content,tool_usertours","targettype":"0","targetvalue":"[data-region=activity-information]","sortorder":"0","configdata":"{}"}]}
{"name":"Activity information in activity page (Student)","description":"A tour of the activity information for Student display on the activity page","pathmatch":"\/mod\/%\/view.php%","enabled":"1","sortorder":"0","configdata":"{\"placement\":\"bottom\",\"orphan\":\"0\",\"backdrop\":\"1\",\"reflex\":\"0\",\"filtervalues\":{\"accessdate\":{\"filter_accessdate\":\"tool_usertours_accountcreation\",\"filter_accessdate_range\":0,\"filter_accessdate_enabled\":\"0\"},\"category\":[],\"course\":[],\"courseformat\":[],\"role\":[\"student\"],\"theme\":[],\"cssselector\":[\"[data-region=activity-information]\"]},\"majorupdatetime\":1620110287,\"shipped_tour\":true,\"shipped_filename\":\"311_activity_information_activity_page_student.json\",\"shipped_version\":1}","displaystepnumbers":"1","version":"2021052507","steps":[{"title":"tour_activityinfo_activity_student_title,tool_usertours","content":"tour_activityinfo_activity_student_content,tool_usertours","targettype":"0","targetvalue":"[data-region=activity-information]","sortorder":"0","configdata":"{}"}]}
@@ -1 +1 @@
{"name":"Activity information in activity page (Teacher)","description":"A tour of the activity information for Teacher display on the activity page","pathmatch":"\/mod\/%\/view.php%","enabled":"1","sortorder":"1","configdata":"{\"placement\":\"bottom\",\"orphan\":\"0\",\"backdrop\":\"1\",\"reflex\":\"0\",\"filtervalues\":{\"accessdate\":{\"filter_accessdate\":\"tool_usertours_accountcreation\",\"filter_accessdate_range\":0,\"filter_accessdate_enabled\":\"0\"},\"category\":[],\"course\":[],\"courseformat\":[],\"role\":[\"manager\",\"teacher\",\"editingteacher\"],\"theme\":[],\"cssselector\":[\"[data-region=activity-information]\"]},\"majorupdatetime\":1620110287,\"shipped_tour\":true,\"shipped_filename\":\"311_activity_information_activity_page_teacher.json\",\"shipped_version\":1}","version":"2021052507","steps":[{"title":"tour_activityinfo_activity_teacher_title,tool_usertours","content":"tour_activityinfo_activity_teacher_content,tool_usertours","targettype":"0","targetvalue":"[data-region=activity-information]","sortorder":"0","configdata":"{}"}]}
{"name":"Activity information in activity page (Teacher)","description":"A tour of the activity information for Teacher display on the activity page","pathmatch":"\/mod\/%\/view.php%","enabled":"1","sortorder":"1","configdata":"{\"placement\":\"bottom\",\"orphan\":\"0\",\"backdrop\":\"1\",\"reflex\":\"0\",\"filtervalues\":{\"accessdate\":{\"filter_accessdate\":\"tool_usertours_accountcreation\",\"filter_accessdate_range\":0,\"filter_accessdate_enabled\":\"0\"},\"category\":[],\"course\":[],\"courseformat\":[],\"role\":[\"manager\",\"teacher\",\"editingteacher\"],\"theme\":[],\"cssselector\":[\"[data-region=activity-information]\"]},\"majorupdatetime\":1620110287,\"shipped_tour\":true,\"shipped_filename\":\"311_activity_information_activity_page_teacher.json\",\"shipped_version\":1}","displaystepnumbers":"1","version":"2021052507","steps":[{"title":"tour_activityinfo_activity_teacher_title,tool_usertours","content":"tour_activityinfo_activity_teacher_content,tool_usertours","targettype":"0","targetvalue":"[data-region=activity-information]","sortorder":"0","configdata":"{}"}]}
@@ -1 +1 @@
{"name":"Activity information in course homepage (Student)","description":"A tour of the activity information for Student display on the course homepage","pathmatch":"\/course\/view.php%","enabled":"1","sortorder":"2","configdata":"{\"placement\":\"bottom\",\"orphan\":\"0\",\"backdrop\":\"1\",\"reflex\":\"0\",\"filtervalues\":{\"accessdate\":{\"filter_accessdate\":\"tool_usertours_accountcreation\",\"filter_accessdate_range\":0,\"filter_accessdate_enabled\":\"0\"},\"category\":[],\"course\":[],\"courseformat\":[],\"role\":[\"student\"],\"theme\":[],\"cssselector\":[\"[data-region=activity-information]\"]},\"majorupdatetime\":1620109487,\"shipped_tour\":true,\"shipped_filename\":\"311_activity_information_course_page_student.json\",\"shipped_version\":1}","version":"2021052507","steps":[{"title":"tour_activityinfo_course_student_title,tool_usertours","content":"tour_activityinfo_course_student_content,tool_usertours","targettype":"0","targetvalue":"[data-region=activity-information]","sortorder":"0","configdata":"{}"}]}
{"name":"Activity information in course homepage (Student)","description":"A tour of the activity information for Student display on the course homepage","pathmatch":"\/course\/view.php%","enabled":"1","sortorder":"2","configdata":"{\"placement\":\"bottom\",\"orphan\":\"0\",\"backdrop\":\"1\",\"reflex\":\"0\",\"filtervalues\":{\"accessdate\":{\"filter_accessdate\":\"tool_usertours_accountcreation\",\"filter_accessdate_range\":0,\"filter_accessdate_enabled\":\"0\"},\"category\":[],\"course\":[],\"courseformat\":[],\"role\":[\"student\"],\"theme\":[],\"cssselector\":[\"[data-region=activity-information]\"]},\"majorupdatetime\":1620109487,\"shipped_tour\":true,\"shipped_filename\":\"311_activity_information_course_page_student.json\",\"shipped_version\":1}","displaystepnumbers":"1","version":"2021052507","steps":[{"title":"tour_activityinfo_course_student_title,tool_usertours","content":"tour_activityinfo_course_student_content,tool_usertours","targettype":"0","targetvalue":"[data-region=activity-information]","sortorder":"0","configdata":"{}"}]}
@@ -1 +1 @@
{"name":"Activity information in course homepage (Teacher)","description":"A tour of the activity information for Teacher display on the course homepage","pathmatch":"\/course\/view.php%","enabled":"1","sortorder":"3","configdata":"{\"placement\":\"bottom\",\"orphan\":\"0\",\"backdrop\":\"1\",\"reflex\":\"0\",\"filtervalues\":{\"accessdate\":{\"filter_accessdate\":\"tool_usertours_accountcreation\",\"filter_accessdate_range\":0,\"filter_accessdate_enabled\":\"0\"},\"category\":[],\"course\":[],\"courseformat\":[],\"role\":[\"manager\",\"teacher\",\"editingteacher\"],\"theme\":[],\"cssselector\":[\"[data-region=activity-information]\"]},\"majorupdatetime\":1620109487,\"shipped_tour\":true,\"shipped_filename\":\"311_activity_information_course_page_teacher.json\",\"shipped_version\":1}","version":"2021052507","steps":[{"title":"tour_activityinfo_course_teacher_title,tool_usertours","content":"tour_activityinfo_course_teacher_content,tool_usertours","targettype":"0","targetvalue":"[data-region=activity-information]","sortorder":"0","configdata":"{}"}]}
{"name":"Activity information in course homepage (Teacher)","description":"A tour of the activity information for Teacher display on the course homepage","pathmatch":"\/course\/view.php%","enabled":"1","sortorder":"3","configdata":"{\"placement\":\"bottom\",\"orphan\":\"0\",\"backdrop\":\"1\",\"reflex\":\"0\",\"filtervalues\":{\"accessdate\":{\"filter_accessdate\":\"tool_usertours_accountcreation\",\"filter_accessdate_range\":0,\"filter_accessdate_enabled\":\"0\"},\"category\":[],\"course\":[],\"courseformat\":[],\"role\":[\"manager\",\"teacher\",\"editingteacher\"],\"theme\":[],\"cssselector\":[\"[data-region=activity-information]\"]},\"majorupdatetime\":1620109487,\"shipped_tour\":true,\"shipped_filename\":\"311_activity_information_course_page_teacher.json\",\"shipped_version\":1}","displaystepnumbers":"1","version":"2021052507","steps":[{"title":"tour_activityinfo_course_teacher_title,tool_usertours","content":"tour_activityinfo_course_teacher_content,tool_usertours","targettype":"0","targetvalue":"[data-region=activity-information]","sortorder":"0","configdata":"{}"}]}
+1 -1
View File
@@ -24,6 +24,6 @@
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2021092300; // The current module version (Date: YYYYMMDDXX).
$plugin->version = 2021100700; // The current module version (Date: YYYYMMDDXX).
$plugin->requires = 2021052500; // Requires this Moodle version.
$plugin->component = 'tool_usertours'; // Full name of the plugin (used for diagnostics).