MDL-64438 block_myoverview: Optionally display course category
authorMihail Geshoski <mihail@moodle.com>
Wed, 18 Sep 2019 09:55:46 +0000 (17:55 +0800)
committerMihail Geshoski <mihail@moodle.com>
Wed, 18 Sep 2019 09:55:46 +0000 (17:55 +0800)
blocks/myoverview/amd/build/view.min.js
blocks/myoverview/amd/build/view.min.js.map
blocks/myoverview/amd/src/view.js
blocks/myoverview/templates/view-cards.mustache
blocks/myoverview/templates/view-list.mustache
blocks/myoverview/templates/view-summary.mustache
blocks/myoverview/tests/behat/block_myoverview_dashboard.feature

index 01b71bc..d9e5ceb 100644 (file)
Binary files a/blocks/myoverview/amd/build/view.min.js and b/blocks/myoverview/amd/build/view.min.js differ
index 5de1f87..0c0cc3c 100644 (file)
Binary files a/blocks/myoverview/amd/build/view.min.js.map and b/blocks/myoverview/amd/build/view.min.js.map differ
index 40d48b9..b439834 100644 (file)
@@ -470,13 +470,11 @@ function(
             currentTemplate = TEMPLATES.COURSES_SUMMARY;
         }
 
-        // Delete the course category if it is not to be displayed
-        if (filters.displaycategories != 'on') {
-            coursesData.courses = coursesData.courses.map(function(course) {
-                delete course.coursecategory;
-                return course;
-            });
-        }
+        // Whether the course category should be displayed in the course item.
+        coursesData.courses = coursesData.courses.map(function(course) {
+            course.showcoursecategory = filters.displaycategories == 'on' ? true : false;
+            return course;
+        });
 
         if (coursesData.courses.length) {
             return Templates.render(currentTemplate, {
index d3527ff..03196b9 100644 (file)
         </span>
     {{/coursename}}
     {{$coursecategory}}
-        <span class="sr-only">
-            {{#str}}aria:coursecategory, core_course{{/str}}
-        </span>
-        <span class="categoryname text-truncate">
-            {{{coursecategory}}}
-        </span>
+        {{#showcoursecategory}}
+            <span class="sr-only">
+                {{#str}}aria:coursecategory, core_course{{/str}}
+            </span>
+            <span class="categoryname text-truncate">
+                {{{coursecategory}}}
+            </span>
+        {{/showcoursecategory}}
     {{/coursecategory}}
     {{$divider}}
-        <div class="pl-1 pr-1">|</div>
+        {{#showcoursecategory}}
+            <div class="pl-1 pr-1">|</div>
+        {{/showcoursecategory}}
     {{/divider}}
 {{/ core_course/coursecards }}
index 37992f0..c4d527c 100644 (file)
             <div class="{{#hasprogress}}col-md-6{{/hasprogress}}{{^hasprogress}}col-md-11 col-md-11{{/hasprogress}} d-flex align-items-center">
                 <div>
                     <div class="text-muted muted d-flex flex-wrap">
-                        <span class="sr-only">
-                            {{#str}}aria:coursecategory, core_course{{/str}}
-                        </span>
-                        <span class="categoryname">
-                            {{{coursecategory}}}
-                        </span>
+                        {{#showcoursecategory}}
+                            <span class="sr-only">
+                                {{#str}}aria:coursecategory, core_course{{/str}}
+                            </span>
+                            <span class="categoryname">
+                                {{{coursecategory}}}
+                            </span>
+                        {{/showcoursecategory}}
                         {{#showshortname}}
-                        <div class="pl-1 pr-1">|</div>
+                            {{#showcoursecategory}}
+                                <div class="pl-1 pr-1">|</div>
+                            {{/showcoursecategory}}
                         <span class="sr-only">
                             {{#str}}aria:courseshortname, core_course{{/str}}
                         </span>
index c53cc32..9f92990 100644 (file)
                         {{#str}}aria:coursecategory, core_course{{/str}}
                     </span>
                     {{$coursecategory}}
-                    <span class="categoryname">
-                        {{{coursecategory}}}
-                    </span>
+                        {{#showcoursecategory}}
+                            <span class="categoryname">
+                                {{#coursecategory}}
+                                    {{{coursecategory}}}
+                                {{/coursecategory}}
+                            </span>
+                        {{/showcoursecategory}}
                     {{/coursecategory}}
                     {{#showshortname}}
-                    <div class="pl-1 pr-1">|</div>
+                        {{#showcoursecategory}}
+                            <div class="pl-1 pr-1">|</div>
+                        {{/showcoursecategory}}
                     <span class="sr-only">
                         {{#str}}aria:courseshortname, core_course{{/str}}
                     </span>
index 9101de8..b8e799a 100644 (file)
@@ -252,19 +252,49 @@ Feature: The my overview block allows users to easily access their courses
     And I log out
 
   Scenario: Show course category in cards display
-    Given I log in as "student1"
+    Given the following config values are set as admin:
+      | displaycategories | 1 | block_myoverview |
+    And I log in as "student1"
     And I click on "Display drop-down menu" "button" in the "Course overview" "block"
     When I click on "Card" "link" in the "Course overview" "block"
     Then I should see "Category 1" in the "Course overview" "block"
 
   Scenario: Show course category in list display
-    Given I log in as "student1"
+    Given the following config values are set as admin:
+      | displaycategories | 1 | block_myoverview |
+    And I log in as "student1"
     And I click on "Display drop-down menu" "button" in the "Course overview" "block"
     When I click on "List" "link" in the "Course overview" "block"
     Then I should see "Category 1" in the "Course overview" "block"
 
   Scenario: Show course category in summary display
-    Given I log in as "student1"
+    Given the following config values are set as admin:
+      | displaycategories | 1 | block_myoverview |
+    And I log in as "student1"
     And I click on "Display drop-down menu" "button" in the "Course overview" "block"
     When I click on "Summary" "link" in the "Course overview" "block"
     Then I should see "Category 1" in the "Course overview" "block"
+
+  Scenario: Hide course category in cards display
+    Given the following config values are set as admin:
+      | displaycategories | 0 | block_myoverview |
+    And I log in as "student1"
+    And I click on "Display drop-down menu" "button" in the "Course overview" "block"
+    When I click on "Card" "link" in the "Course overview" "block"
+    Then I should not see "Category 1" in the "Course overview" "block"
+
+  Scenario: Hide course category in list display
+    Given the following config values are set as admin:
+      | displaycategories | 0 | block_myoverview |
+    And I log in as "student1"
+    And I click on "Display drop-down menu" "button" in the "Course overview" "block"
+    When I click on "List" "link" in the "Course overview" "block"
+    Then I should not see "Category 1" in the "Course overview" "block"
+
+  Scenario: Show course category in summary display
+    Given the following config values are set as admin:
+      | displaycategories | 0 | block_myoverview |
+    And I log in as "student1"
+    And I click on "Display drop-down menu" "button" in the "Course overview" "block"
+    When I click on "Summary" "link" in the "Course overview" "block"
+    Then I should not see "Category 1" in the "Course overview" "block"