Skip to content

Commit e1ffadc

Browse files
authored
Bugfix: Course details modal did not work on category overview pages, resolves moodle-an-hochschulen#851 (moodle-an-hochschulen#852)
1 parent 40b0f25 commit e1ffadc

4 files changed

+85
-19
lines changed

amd/build/courselistingdetailsmodal.min.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

amd/src/courselistingdetailsmodal.js

-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import Templates from 'core/templates';
2828
import {getString} from 'core/str';
2929

3030
const SELECTORS = {
31-
SNIPPETS_CONTAINER: 'theme_boost_union-courselisting',
3231
DETAILS: '[data-action="courselisting-details"]',
3332
};
3433

classes/output/core/course_renderer.php

+28-17
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ class course_renderer extends \core_course_renderer {
5858
*/
5959
protected function coursecat_courses(coursecat_helper $chelper, $courses, $totalcount = null) {
6060
// If the course listing should remain unchanged.
61-
$courselistingpresetation = get_config('theme_boost_union', 'courselistingpresentation');
62-
if (!isset($courselistingpresetation) || $courselistingpresetation == THEME_BOOST_UNION_SETTING_COURSELISTPRES_NOCHANGE) {
61+
$courselistingpresentation = get_config('theme_boost_union', 'courselistingpresentation');
62+
if (!isset($courselistingpresentation) || $courselistingpresentation == THEME_BOOST_UNION_SETTING_COURSELISTPRES_NOCHANGE) {
6363
// Call the parent function to present the default view.
6464
return parent::coursecat_courses($chelper, $courses, $totalcount);
6565
}
@@ -130,7 +130,7 @@ protected function coursecat_courses(coursecat_helper $chelper, $courses, $total
130130
}
131131

132132
// If course cards are enabled.
133-
if ($courselistingpresetation == THEME_BOOST_UNION_SETTING_COURSELISTPRES_CARDS) {
133+
if ($courselistingpresentation == THEME_BOOST_UNION_SETTING_COURSELISTPRES_CARDS) {
134134
// Start the course listing as card grid.
135135
// And add the theme_boost_union-courselisting class to be used in the CSS.
136136
$content .= html_writer::start_tag('div',
@@ -209,7 +209,7 @@ protected function coursecat_courses(coursecat_helper $chelper, $courses, $total
209209
$content .= html_writer::end_tag('div');
210210

211211
// Or if the course list is enabled.
212-
} else if ($courselistingpresetation == THEME_BOOST_UNION_SETTING_COURSELISTPRES_LIST) {
212+
} else if ($courselistingpresentation == THEME_BOOST_UNION_SETTING_COURSELISTPRES_LIST) {
213213
// Start the course listing as course list.
214214
// And add the theme_boost_union-courselisting class to be used in the CSS.
215215
$content .= html_writer::start_tag('div',
@@ -267,11 +267,6 @@ protected function coursecat_courses(coursecat_helper $chelper, $courses, $total
267267
$content .= html_writer::end_tag('div');
268268
}
269269

270-
// If the course listing details modal is enabled, add the necessary JS.
271-
if (get_config('theme_boost_union', 'courselistinghowpopup') == THEME_BOOST_UNION_SETTING_SELECT_YES) {
272-
$this->page->requires->js_call_amd('theme_boost_union/courselistingdetailsmodal', 'init');
273-
}
274-
275270
if (!empty($pagingbar)) {
276271
$content .= $pagingbar;
277272
}
@@ -301,8 +296,8 @@ protected function coursecat_courses(coursecat_helper $chelper, $courses, $total
301296
*/
302297
protected function coursecat_coursebox(coursecat_helper $chelper, $course, $additionalclasses = '') {
303298
// If the course listing should remain unchanged.
304-
$courselistingpresetation = get_config('theme_boost_union', 'courselistingpresentation');
305-
if (!isset($courselistingpresetation) || $courselistingpresetation == THEME_BOOST_UNION_SETTING_COURSELISTPRES_NOCHANGE) {
299+
$courselistingpresentation = get_config('theme_boost_union', 'courselistingpresentation');
300+
if (!isset($courselistingpresentation) || $courselistingpresentation == THEME_BOOST_UNION_SETTING_COURSELISTPRES_NOCHANGE) {
306301
// Call the parent function to present the default view.
307302
return parent::coursecat_coursebox($chelper, $course, $additionalclasses);
308303
}
@@ -338,8 +333,8 @@ protected function coursecat_coursebox(coursecat_helper $chelper, $course, $addi
338333
*/
339334
protected function coursecat_coursebox_content(coursecat_helper $chelper, $course) {
340335
// If the course listing should remain unchanged.
341-
$courselistingpresetation = get_config('theme_boost_union', 'courselistingpresentation');
342-
if (!isset($courselistingpresetation) || $courselistingpresetation == THEME_BOOST_UNION_SETTING_COURSELISTPRES_NOCHANGE) {
336+
$courselistingpresentation = get_config('theme_boost_union', 'courselistingpresentation');
337+
if (!isset($courselistingpresentation) || $courselistingpresentation == THEME_BOOST_UNION_SETTING_COURSELISTPRES_NOCHANGE) {
343338
// Call the parent function to compose the default view.
344339
return parent::coursecat_coursebox_content($chelper, $course);
345340
}
@@ -509,12 +504,12 @@ protected function coursecat_coursebox_content(coursecat_helper $chelper, $cours
509504
}
510505

511506
// If course cards are enabled.
512-
if ($courselistingpresetation == THEME_BOOST_UNION_SETTING_COURSELISTPRES_CARDS) {
507+
if ($courselistingpresentation == THEME_BOOST_UNION_SETTING_COURSELISTPRES_CARDS) {
513508
// Render the card template.
514509
$content = $this->render_from_template('theme_boost_union/courselistingcard', $templatedata);
515510

516511
// Or if the course list is enabled.
517-
} else if ($courselistingpresetation == THEME_BOOST_UNION_SETTING_COURSELISTPRES_LIST) {
512+
} else if ($courselistingpresentation == THEME_BOOST_UNION_SETTING_COURSELISTPRES_LIST) {
518513
// Render the list template.
519514
$content = $this->render_from_template('theme_boost_union/courselistinglist', $templatedata);
520515
}
@@ -639,6 +634,22 @@ protected function coursecat_category(coursecat_helper $chelper, $coursecat, $de
639634
* @return string
640635
*/
641636
protected function coursecat_tree(coursecat_helper $chelper, $coursecat) {
637+
// If the course listing details modal is enabled and should be shown, add the necessary JS.
638+
// This has to be done here even if categorylistingpresentation is set to nochange to make sure that
639+
// the JS is loaded in any case.
640+
static $detailsmodalchecked = null;
641+
if ($detailsmodalchecked == null) {
642+
$courselistingpresentation = get_config('theme_boost_union', 'courselistingpresentation');
643+
$courselistinghowpopup = get_config('theme_boost_union', 'courselistinghowpopup');
644+
if (isset($courselistingpresentation) &&
645+
$courselistingpresentation != THEME_BOOST_UNION_SETTING_COURSELISTPRES_NOCHANGE &&
646+
isset($courselistinghowpopup) &&
647+
$courselistinghowpopup == THEME_BOOST_UNION_SETTING_SELECT_YES) {
648+
$this->page->requires->js_call_amd('theme_boost_union/courselistingdetailsmodal', 'init');
649+
}
650+
$detailsmodalchecked = true;
651+
}
652+
642653
// If the category listing should remain unchanged.
643654
$categorylistingpresentation = get_config('theme_boost_union', 'categorylistingpresentation');
644655
if (!isset($categorylistingpresentation) ||
@@ -658,9 +669,9 @@ protected function coursecat_tree(coursecat_helper $chelper, $coursecat) {
658669
}
659670

660671
// If the modified course listing within the category tree is enabled.
661-
$courselistingpresetation = get_config('theme_boost_union', 'courselistingpresentation');
672+
$courselistingpresentation = get_config('theme_boost_union', 'courselistingpresentation');
662673
$additionalclasses = '';
663-
if (isset($courselistingpresetation) && $courselistingpresetation != THEME_BOOST_UNION_SETTING_COURSELISTPRES_NOCHANGE) {
674+
if (isset($courselistingpresentation) && $courselistingpresentation != THEME_BOOST_UNION_SETTING_COURSELISTPRES_NOCHANGE) {
664675
// Add a CSS class to allow styling the category listing.
665676
$additionalclasses = 'theme_boost_union-catlisting-cl';
666677
}

tests/behat/theme_boost_union_looksettings_categoryindexsitehome.feature

+56
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,62 @@ Feature: Configuring the theme_boost_union plugin for the "Category index / site
681681
| list | no | .course-listitem .popupbutton | should not |
682682
| list | yes | .course-listitem .popupbutton | should |
683683

684+
@javascript
685+
Scenario Outline: Setting: Show details popup in the course listing: Click the button
686+
Given the following config values are set as admin:
687+
| config | value | plugin |
688+
| courselistingpresentation | <coursevalue> | theme_boost_union |
689+
| courselistinghowpopup | yes | theme_boost_union |
690+
When I log in as "student1"
691+
And I am on site homepage
692+
# Check the 'Combo list' view on site home as a whole
693+
Then "<selector>" "css_element" should exist in the "#frontpage-category-combo" "css_element"
694+
And I click on "<selector>" "css_element" in the "#frontpage-category-combo" "css_element"
695+
And ".modal-dialog" "css_element" should be visible
696+
And I click on ".modal-dialog .btn-close" "css_element"
697+
# Check a subcategory in the 'Combo list' view on site home
698+
And I reload the page
699+
And I click on ".info" "css_element" in the "#frontpage-category-combo > .course_category_tree > .content > .subcategories > .category.with_children:nth-child(3) > .content > .subcategories > .category.with_children" "css_element"
700+
And "<selector>" "css_element" should exist in the "#frontpage-category-combo > .course_category_tree > .content > .subcategories > .category.with_children:nth-child(3) > .content > .subcategories > .category.with_children" "css_element"
701+
And I click on "<selector>" "css_element" in the "#frontpage-category-combo > .course_category_tree > .content > .subcategories > .category.with_children:nth-child(3) > .content > .subcategories > .category.with_children" "css_element"
702+
And ".modal-dialog" "css_element" should be visible
703+
And I click on ".modal-dialog .btn-close" "css_element"
704+
# Check the 'Enrolled courses' view on site home
705+
And I reload the page
706+
And "<selector>" "css_element" should exist in the "#frontpage-course-list" "css_element"
707+
And I click on "<selector>" "css_element" in the "#frontpage-course-list" "css_element"
708+
And ".modal-dialog" "css_element" should be visible
709+
And I click on ".modal-dialog .btn-close" "css_element"
710+
# Check the 'List of courses' view on site home
711+
And I reload the page
712+
And "<selector>" "css_element" should exist in the "#frontpage-available-course-list" "css_element"
713+
And I click on "<selector>" "css_element" in the "#frontpage-available-course-list" "css_element"
714+
And ".modal-dialog" "css_element" should be visible
715+
And I click on ".modal-dialog .btn-close" "css_element"
716+
# Check the categoriy overview page of a category without subcategories
717+
And I am on the "CATA" category page
718+
Then "<selector>" "css_element" should exist in the ".course_category_tree" "css_element"
719+
And I click on "<selector>" "css_element" in the ".course_category_tree" "css_element"
720+
And ".modal-dialog" "css_element" should be visible
721+
And I click on ".modal-dialog .btn-close" "css_element"
722+
# Check the categoriy overview page of a category with subcategories
723+
And I am on the "CATB" category page
724+
Then "<selector>" "css_element" should exist in the ".course_category_tree" "css_element"
725+
And I click on "<selector>" "css_element" in the ".course_category_tree" "css_element"
726+
And ".modal-dialog" "css_element" should be visible
727+
And I click on ".modal-dialog .btn-close" "css_element"
728+
And I reload the page
729+
And I click on ".info" "css_element" in the ".course_category_tree > .content > .subcategories > .category.with_children" "css_element"
730+
And "<selector>" "css_element" should exist in the ".course_category_tree > .content > .subcategories > .category.with_children" "css_element"
731+
And I click on "<selector>" "css_element" in the ".course_category_tree > .content > .subcategories > .category.with_children" "css_element"
732+
And ".modal-dialog" "css_element" should be visible
733+
And I click on ".modal-dialog .btn-close" "css_element"
734+
735+
Examples:
736+
| coursevalue | selector |
737+
| cards | .course-card .card-footer .popupbutton |
738+
| list | .course-listitem .popupbutton |
739+
684740
@javascript
685741
Scenario Outline: Setting: Show details popup in the course listing: Check the content: Course summary
686742
Given the following config values are set as admin:

0 commit comments

Comments
 (0)