Skip to content

Commit

Permalink
Merge branch 'MDL-71528-master' of git://github.com/aanabit/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnicols committed Jun 16, 2021
2 parents 12ce136 + 377aee9 commit 6ad0f55
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 29 deletions.
2 changes: 1 addition & 1 deletion admin/tool/usertours/amd/build/usertours.min.js

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

2 changes: 1 addition & 1 deletion admin/tool/usertours/amd/build/usertours.min.js.map

Large diffs are not rendered by default.

39 changes: 17 additions & 22 deletions admin/tool/usertours/amd/src/usertours.js
Expand Up @@ -79,37 +79,32 @@ function(ajax, BootstrapTour, $, templates, str, log, notification) {
* @method fetchTour
* @param {Number} tourId The ID of the tour to start.
*/
fetchTour: function(tourId) {
fetchTour: async function(tourId) {
M.util.js_pending('admin_usertour_fetchTour' + tourId);
$.when(
ajax.call([

try {
const response = await ajax.call([
{
methodname: 'tool_usertours_fetch_and_start_tour',
args: {
tourid: tourId,
context: M.cfg.contextid,
pageurl: window.location.href,
tourid: tourId,
context: M.cfg.contextid,
pageurl: window.location.href,
}
}
])[0],
templates.render('tool_usertours/tourstep', {})
)
.then(function(response, template) {
// If we don't have any tour config (because it doesn't need showing for the current user), return early.
if (!response.hasOwnProperty('tourconfig')) {
return;
}
])[0];
if (response.hasOwnProperty('tourconfig')) {
const template = await templates.renderForPromise('tool_usertours/tourstep', response.tourconfig);

return usertours.startBootstrapTour(tourId, template[0], response.tourconfig);
})
.always(function() {
M.util.js_complete('admin_usertour_fetchTour' + tourId);

return;
})
.fail(notification.exception);
usertours.startBootstrapTour(tourId, template.html, response.tourconfig);
}
} catch (error) {
notification.exception(error);
}
M.util.js_complete('admin_usertour_fetchTour' + tourId);
},


/**
* Add a reset link to the page.
*
Expand Down
7 changes: 4 additions & 3 deletions admin/tool/usertours/classes/external/tour.php
Expand Up @@ -101,9 +101,10 @@ public static function fetch_and_start_tour_parameters() {
*/
public static function fetch_and_start_tour_returns() {
return new external_single_structure([
'tourconfig' => new external_single_structure([
'name' => new external_value(PARAM_RAW, 'Tour Name'),
'steps' => new external_multiple_structure(self::step_structure_returns()),
'tourconfig' => new external_single_structure([
'name' => new external_value(PARAM_RAW, 'Tour Name'),
'steps' => new external_multiple_structure(self::step_structure_returns()),
'onesteptour' => new external_value(PARAM_BOOL, 'Is a one step tour', VALUE_DEFAULT, false),
], 'Tour config', VALUE_OPTIONAL)
]);
}
Expand Down
6 changes: 6 additions & 0 deletions admin/tool/usertours/classes/output/tour.php
Expand Up @@ -60,12 +60,18 @@ public function export_for_template(\renderer_base $output) {
$result = (object) [
'name' => $this->tour->get_tour_key(),
'steps' => [],
'onesteptour' => false,
];

foreach ($this->tour->get_steps() as $step) {
$result->steps[] = (new step($step))->export_for_template($output);
}

// Check if its a only one step tour.
if (count($result->steps) == 1) {
$result->onesteptour = true;
}

return $result;
}
}
1 change: 1 addition & 0 deletions admin/tool/usertours/lang/en/tool_usertours.php
Expand Up @@ -130,6 +130,7 @@
$string['tours'] = 'Tours';
$string['pausetour'] = 'Pause';
$string['resumetour'] = 'Resume';
$string['endonesteptour'] = 'Got it!';
$string['endtour'] = 'End tour';
$string['orphan'] = 'Show if target not found';
$string['orphan_help'] = 'Show the step if the target could not be found on the page.';
Expand Down
15 changes: 14 additions & 1 deletion admin/tool/usertours/templates/tourstep.mustache
Expand Up @@ -42,6 +42,14 @@
Example context (json):
{
"name" : "tour_activity_completion",
"onesteptour" : true,
"steps": [
{
"stepid": 10,
"title": "Activity information"
}
]
}

}}
Expand All @@ -60,7 +68,12 @@
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-role="previous">{{# str }} previousstep, tool_usertours {{/ str }}</button>
<button type="button" class="btn btn-primary" data-role="next">{{# str }} nextstep, tool_usertours {{/ str }}</button>
<button class="btn btn-secondary" data-role="end"> {{# str }} endtour, tool_usertours {{/ str }} </button>
{{#onesteptour}}
<button class="btn btn-secondary" data-role="end"> {{# str }} endonesteptour, tool_usertours {{/ str }} </button>
{{/onesteptour}}
{{^onesteptour}}
<button class="btn btn-secondary" data-role="end"> {{# str }} endtour, tool_usertours {{/ str }} </button>
{{/onesteptour}}
</div>
</div>
</div>
2 changes: 1 addition & 1 deletion admin/tool/usertours/tests/behat/tour_filter.feature
Expand Up @@ -37,7 +37,7 @@ Feature: Apply tour filters to a tour
And I log in as "student1"
And I am on "Course 1" course homepage
And I should see "Welcome to your course tour."
And I click on "End tour" "button"
And I click on "Got it!" "button"
And I log out
And I log in as "teacher1"
And I am on "Course 1" course homepage
Expand Down
38 changes: 38 additions & 0 deletions admin/tool/usertours/tests/behat/tour_navigation.feature
Expand Up @@ -22,3 +22,41 @@ Feature: Steps can be navigated within a tour
When I click on ".block_calendar_month .calendar-controls .next" "css_element"
And I wait until the page is ready
Then I should see "Calendar events"

@javascript
Scenario: End tour button text for one step tours
Given I log in as "admin"
And I add a new user tour with:
| Name | Calendar tour |
| Description | Calendar tour |
| Apply to URL match | /my/% |
| Tour is enabled | 1 |
And I add steps to the "Calendar tour" tour:
| targettype | Block | Title | Content |
| Block | Calendar | Calendar events | This is the calendar block |
And I change window size to "large"
And I follow "Dashboard" in the user menu
And I wait until the page is ready
And I should see "This is the calendar block"
Then I should see "Got it!"

@javascript
Scenario: End tour button text for multiple step tours
Given I log in as "admin"
And I add a new user tour with:
| Name | First tour |
| Description | My first tour |
| Apply to URL match | /my/% |
| Tour is enabled | 1 |
And I add steps to the "First tour" tour:
| targettype | Title | Content |
| Display in middle of page | Welcome | 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 |
And I add steps to the "First tour" tour:
| targettype | targetvalue_block | Title | Content |
| Block | Course overview | Course overview | This area shows you what's happening in some of your courses |
| Block | Calendar | Calendar | This is the Calendar. All of your assignments and due dates can be found here |
When I am on homepage
Then I should see "End tour"
And I should see "Next"
And I click on "Next" "button"
And I should see "End tour"
5 changes: 5 additions & 0 deletions admin/tool/usertours/upgrade.txt
@@ -1,5 +1,10 @@
This files describes API changes in the tool_usertours code.

=== 4.0 ===
* The `tourconfig` property returned by the `tool_usertours_fetch_and_start_tour`
external method has also a `onsteptour` property to differentiate between
one step tours and multiple step tours.

=== 3.9 ===
* The `tourconfig` property returned by the `tool_usertours_fetch_and_start_tour`
external method is now optional, and will be omitted if the tour shouldn't be
Expand Down

0 comments on commit 6ad0f55

Please sign in to comment.