From d0b237b30675b0f04bc8979a136579505aa61cb6 Mon Sep 17 00:00:00 2001 From: Mihail Geshoski Date: Wed, 18 Sep 2019 17:57:47 +0800 Subject: [PATCH] MDL-64438 block_recentlyaccessedcourses: Optionally show course category AMOS BEGIN CPY [displaycategories,block_myoverview],[displaycategories,block_recentlyaccessedcourses] AMOS END --- .../amd/build/main.min.js | 2 +- .../amd/build/main.min.js.map | 2 +- .../recentlyaccessedcourses/amd/src/main.js | 3 + .../block_recentlyaccessedcourses.php | 9 +++ .../classes/output/main.php | 4 +- .../lang/en/block_recentlyaccessedcourses.php | 4 +- blocks/recentlyaccessedcourses/settings.php | 34 ++++++++++++ .../templates/course-card.mustache | 15 +++-- .../templates/main.mustache | 2 +- ..._recentlyaccessedcourses_dashboard.feature | 55 +++++++++++++++++-- blocks/recentlyaccessedcourses/upgrade.txt | 5 ++ blocks/recentlyaccessedcourses/version.php | 2 +- 12 files changed, 121 insertions(+), 16 deletions(-) create mode 100644 blocks/recentlyaccessedcourses/settings.php diff --git a/blocks/recentlyaccessedcourses/amd/build/main.min.js b/blocks/recentlyaccessedcourses/amd/build/main.min.js index 6c3de1c93c6..4d8e69fd15a 100644 --- a/blocks/recentlyaccessedcourses/amd/build/main.min.js +++ b/blocks/recentlyaccessedcourses/amd/build/main.min.js @@ -1,2 +1,2 @@ -define ("block_recentlyaccessedcourses/main",["jquery","core/custom_interaction_events","core/notification","core/pubsub","core/paged_content_paging_bar","core/templates","core_course/events","core_course/repository"],function(a,b,c,d,e,f,g,h){var i={CARD_CONTAINER:"[data-region=\"card-deck\"]",COURSE_IS_FAVOURITE:"[data-region=\"is-favourite\"]",CONTENT:"[data-region=\"view-content\"]",EMPTY_MESSAGE:"[data-region=\"empty-message\"]",LOADING_PLACEHOLDER:"[data-region=\"loading-placeholder\"]",PAGING_BAR:"[data-region=\"paging-bar\"]",PAGING_BAR_NEXT:"[data-control=\"next\"]",PAGING_BAR_PREVIOUS:"[data-control=\"previous\"]"},j=!1,k=[],l=null,m=null,n=0,o=1,p=function(a){a.find(i.EMPTY_MESSAGE).removeClass("hidden");a.find(i.LOADING_PLACEHOLDER).addClass("hidden");a.find(i.CONTENT).addClass("hidden")},q=function(a){a.find(i.CONTENT).removeClass("hidden");a.find(i.EMPTY_MESSAGE).addClass("hidden");a.find(i.LOADING_PLACEHOLDER).addClass("hidden")},r=function(a){var b=a.find(i.PAGING_BAR);b.css("opacity",1);b.css("visibility","visible");b.attr("aria-hidden","false")},s=function(a){var b=a.find(i.PAGING_BAR);b.css("opacity",0);b.css("visibility","hidden");b.attr("aria-hidden","true")},t=function(a,b){k.forEach(function(a){if(a.attr("data-course-id")==b){a.find(i.COURSE_IS_FAVOURITE).removeClass("hidden")}})},u=function(a,b){k.forEach(function(a){if(a.attr("data-course-id")==b){a.find(i.COURSE_IS_FAVOURITE).addClass("hidden")}})},v=function(b){var d=b.map(function(a){return f.render("block_recentlyaccessedcourses/course-card",a)});return a.when.apply(null,d).then(function(){var b=[];d.forEach(function(d){d.then(function(c){b.push(a(c))}).catch(c.exception)});return b})},w=function(a){return h.getLastAccessedCourses(a,10).then(function(a){return v(a)})},x=function(a){var b=a.find(i.CONTENT).find(i.CARD_CONTAINER),c=parseFloat(a.css("width")),d=k.length,f=0;if(!m){b.html(k[0]);m=k[0].outerWidth(!0)}o=Math.floor(c/m);if(n+oh.length){b.addClass("justify-content-center");b.removeClass("justify-content-start")}else{b.removeClass("justify-content-center");b.addClass("justify-content-start")}if(l!=j){var p=a.find(e.rootSelector);b.html(h);l=j;if(o>=k.length){s(a)}else{r(a);if(0===n){e.disablePreviousControlButtons(p)}else{e.enablePreviousControlButtons(p)}if(n+o>=k.length){e.disableNextControlButtons(p)}else{e.enableNextControlButtons(p)}}}},y=function(c){var e=null,f=!1;d.subscribe(g.favourited,function(a){t(c,a)});d.subscribe(g.unfavorited,function(a){u(c,a)});d.subscribe("nav-drawer-toggle-start",function(){if(!j||!k.length||f){return}f=!0;var a=0,b=function(){setTimeout(function(){x(c);a++;if(5>a&&f){b()}},100)};b(c)});d.subscribe("nav-drawer-toggle-end",function(){f=!1});a(window).on("resize",function(){if(!j||!k.length){return}if(!e){e=setTimeout(function(){e=null;x(c)},66)}});b.define(c,[b.events.activate]);c.on(b.events.activate,i.PAGING_BAR_NEXT,function(b,d){var e=a(b.target).closest(i.PAGING_BAR_NEXT);if(!e.hasClass("disabled")){n=n+o;x(c)}d.originalEvent.preventDefault()});c.on(b.events.activate,i.PAGING_BAR_PREVIOUS,function(b,d){var e=a(b.target).closest(i.PAGING_BAR_PREVIOUS);if(!e.hasClass("disabled")){n=n-o;n=0>n?0:n;x(c)}d.originalEvent.preventDefault()})};return{init:function init(b,d){d=a(d);y(d);w(b).then(function(a){k=a;j=!0;if(k.length){q(d);x(d)}else{p(d)}}).catch(c.exception)}}}); +define ("block_recentlyaccessedcourses/main",["jquery","core/custom_interaction_events","core/notification","core/pubsub","core/paged_content_paging_bar","core/templates","core_course/events","core_course/repository"],function(a,b,c,d,e,f,g,h){var i={BLOCK_CONTAINER:"[data-region=\"recentlyaccessedcourses\"]",CARD_CONTAINER:"[data-region=\"card-deck\"]",COURSE_IS_FAVOURITE:"[data-region=\"is-favourite\"]",CONTENT:"[data-region=\"view-content\"]",EMPTY_MESSAGE:"[data-region=\"empty-message\"]",LOADING_PLACEHOLDER:"[data-region=\"loading-placeholder\"]",PAGING_BAR:"[data-region=\"paging-bar\"]",PAGING_BAR_NEXT:"[data-control=\"next\"]",PAGING_BAR_PREVIOUS:"[data-control=\"previous\"]"},j=!1,k=[],l=null,m=null,n=0,o=1,p=function(a){a.find(i.EMPTY_MESSAGE).removeClass("hidden");a.find(i.LOADING_PLACEHOLDER).addClass("hidden");a.find(i.CONTENT).addClass("hidden")},q=function(a){a.find(i.CONTENT).removeClass("hidden");a.find(i.EMPTY_MESSAGE).addClass("hidden");a.find(i.LOADING_PLACEHOLDER).addClass("hidden")},r=function(a){var b=a.find(i.PAGING_BAR);b.css("opacity",1);b.css("visibility","visible");b.attr("aria-hidden","false")},s=function(a){var b=a.find(i.PAGING_BAR);b.css("opacity",0);b.css("visibility","hidden");b.attr("aria-hidden","true")},t=function(a,b){k.forEach(function(a){if(a.attr("data-course-id")==b){a.find(i.COURSE_IS_FAVOURITE).removeClass("hidden")}})},u=function(a,b){k.forEach(function(a){if(a.attr("data-course-id")==b){a.find(i.COURSE_IS_FAVOURITE).addClass("hidden")}})},v=function(b){var d=a(i.BLOCK_CONTAINER).data("displaycoursecategory"),e=b.map(function(a){a.showcoursecategory=d;return f.render("block_recentlyaccessedcourses/course-card",a)});return a.when.apply(null,e).then(function(){var b=[];e.forEach(function(d){d.then(function(c){b.push(a(c))}).catch(c.exception)});return b})},w=function(a){return h.getLastAccessedCourses(a,10).then(function(a){return v(a)})},x=function(a){var b=a.find(i.CONTENT).find(i.CARD_CONTAINER),c=parseFloat(a.css("width")),d=k.length,f=0;if(!m){b.html(k[0]);m=k[0].outerWidth(!0)}o=Math.floor(c/m);if(n+oh.length){b.addClass("justify-content-center");b.removeClass("justify-content-start")}else{b.removeClass("justify-content-center");b.addClass("justify-content-start")}if(l!=j){var p=a.find(e.rootSelector);b.html(h);l=j;if(o>=k.length){s(a)}else{r(a);if(0===n){e.disablePreviousControlButtons(p)}else{e.enablePreviousControlButtons(p)}if(n+o>=k.length){e.disableNextControlButtons(p)}else{e.enableNextControlButtons(p)}}}},y=function(c){var e=null,f=!1;d.subscribe(g.favourited,function(a){t(c,a)});d.subscribe(g.unfavorited,function(a){u(c,a)});d.subscribe("nav-drawer-toggle-start",function(){if(!j||!k.length||f){return}f=!0;var a=0,b=function(){setTimeout(function(){x(c);a++;if(5>a&&f){b()}},100)};b(c)});d.subscribe("nav-drawer-toggle-end",function(){f=!1});a(window).on("resize",function(){if(!j||!k.length){return}if(!e){e=setTimeout(function(){e=null;x(c)},66)}});b.define(c,[b.events.activate]);c.on(b.events.activate,i.PAGING_BAR_NEXT,function(b,d){var e=a(b.target).closest(i.PAGING_BAR_NEXT);if(!e.hasClass("disabled")){n=n+o;x(c)}d.originalEvent.preventDefault()});c.on(b.events.activate,i.PAGING_BAR_PREVIOUS,function(b,d){var e=a(b.target).closest(i.PAGING_BAR_PREVIOUS);if(!e.hasClass("disabled")){n=n-o;n=0>n?0:n;x(c)}d.originalEvent.preventDefault()})};return{init:function init(b,d){d=a(d);y(d);w(b).then(function(a){k=a;j=!0;if(k.length){q(d);x(d)}else{p(d)}}).catch(c.exception)}}}); //# sourceMappingURL=main.min.js.map diff --git a/blocks/recentlyaccessedcourses/amd/build/main.min.js.map b/blocks/recentlyaccessedcourses/amd/build/main.min.js.map index d8e8d129f39..6fdffbc47ca 100644 --- a/blocks/recentlyaccessedcourses/amd/build/main.min.js.map +++ b/blocks/recentlyaccessedcourses/amd/build/main.min.js.map @@ -1 +1 @@ -{"version":3,"sources":["../src/main.js"],"names":["define","$","CustomEvents","Notification","PubSub","PagedContentPagingBar","Templates","CourseEvents","CoursesRepository","SELECTORS","CARD_CONTAINER","COURSE_IS_FAVOURITE","CONTENT","EMPTY_MESSAGE","LOADING_PLACEHOLDER","PAGING_BAR","PAGING_BAR_NEXT","PAGING_BAR_PREVIOUS","contentLoaded","allCourses","visibleCoursesId","cardWidth","viewIndex","availableVisibleCards","showEmptyMessage","root","find","removeClass","addClass","showContent","showPagingBar","pagingBar","css","attr","hidePagingBar","favouriteCourse","courseId","forEach","course","unfavouriteCourse","renderAllCourses","courses","promises","map","render","when","apply","then","renderedCourses","promise","html","push","catch","exception","loadContent","userid","getLastAccessedCourses","recalculateVisibleCourses","container","availableWidth","parseFloat","numberOfCourses","length","start","outerWidth","Math","floor","overflow","coursesToShow","slice","newVisibleCoursesId","reduce","carry","rootSelector","disablePreviousControlButtons","enablePreviousControlButtons","disableNextControlButtons","enableNextControlButtons","registerEventListeners","resizeTimeout","drawerToggling","subscribe","favourited","unfavorited","recalculationCount","doRecalculation","setTimeout","window","on","events","activate","e","data","button","target","closest","hasClass","originalEvent","preventDefault","init"],"mappings":"AAwBAA,OAAM,s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YC,OAAZ,CAAoBtF,CAAS,CAACQ,mBAA9B,CAAb,CACA,GAAI,CAAC4E,CAAM,CAACG,QAAP,CAAgB,UAAhB,CAAL,CAAkC,CAC9B1E,CAAS,CAAGA,CAAS,CAAGC,CAAxB,CACAD,CAAS,CAAe,CAAZ,CAAAA,CAAS,CAAO,CAAP,CAAWA,CAAhC,CACAmC,CAAyB,CAAChC,CAAD,CAC5B,CAEDmE,CAAI,CAACK,aAAL,CAAmBC,cAAnB,EACH,CATD,CAUH,CAlSH,CA+TE,MAAO,CACHC,IAAI,CAtBG,QAAPA,CAAAA,IAAO,CAAS5C,CAAT,CAAiB9B,CAAjB,CAAuB,CAC9BA,CAAI,CAAGxB,CAAC,CAACwB,CAAD,CAAR,CAEAqD,CAAsB,CAACrD,CAAD,CAAtB,CACA6B,CAAW,CAACC,CAAD,CAAX,CACKR,IADL,CACU,SAASC,CAAT,CAA0B,CAC5B7B,CAAU,CAAG6B,CAAb,CACA9B,CAAa,GAAb,CAEA,GAAIC,CAAU,CAAC2C,MAAf,CAAuB,CACnBjC,CAAW,CAACJ,CAAD,CAAX,CACAgC,CAAyB,CAAChC,CAAD,CAC5B,CAHD,IAGO,CACHD,CAAgB,CAACC,CAAD,CACnB,CAGJ,CAbL,EAcK2B,KAdL,CAcWjD,CAAY,CAACkD,SAdxB,CAeH,CAEM,CAGV,CAtVC,CAAN","sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * Javascript to initialise the Recently accessed courses block.\n *\n * @module block_recentlyaccessedcourses/main.js\n * @package block_recentlyaccessedcourses\n * @copyright 2018 Victor Deniz \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\ndefine(\n [\n 'jquery',\n 'core/custom_interaction_events',\n 'core/notification',\n 'core/pubsub',\n 'core/paged_content_paging_bar',\n 'core/templates',\n 'core_course/events',\n 'core_course/repository',\n ],\n function(\n $,\n CustomEvents,\n Notification,\n PubSub,\n PagedContentPagingBar,\n Templates,\n CourseEvents,\n CoursesRepository\n ) {\n\n // Constants.\n var NUM_COURSES_TOTAL = 10;\n var SELECTORS = {\n CARD_CONTAINER: '[data-region=\"card-deck\"]',\n COURSE_IS_FAVOURITE: '[data-region=\"is-favourite\"]',\n CONTENT: '[data-region=\"view-content\"]',\n EMPTY_MESSAGE: '[data-region=\"empty-message\"]',\n LOADING_PLACEHOLDER: '[data-region=\"loading-placeholder\"]',\n PAGING_BAR: '[data-region=\"paging-bar\"]',\n PAGING_BAR_NEXT: '[data-control=\"next\"]',\n PAGING_BAR_PREVIOUS: '[data-control=\"previous\"]'\n };\n // Module variables.\n var contentLoaded = false;\n var allCourses = [];\n var visibleCoursesId = null;\n var cardWidth = null;\n var viewIndex = 0;\n var availableVisibleCards = 1;\n\n /**\n * Show the empty message when no course are found.\n *\n * @param {object} root The root element for the courses view.\n */\n var showEmptyMessage = function(root) {\n root.find(SELECTORS.EMPTY_MESSAGE).removeClass('hidden');\n root.find(SELECTORS.LOADING_PLACEHOLDER).addClass('hidden');\n root.find(SELECTORS.CONTENT).addClass('hidden');\n };\n\n /**\n * Show the empty message when no course are found.\n *\n * @param {object} root The root element for the courses view.\n */\n var showContent = function(root) {\n root.find(SELECTORS.CONTENT).removeClass('hidden');\n root.find(SELECTORS.EMPTY_MESSAGE).addClass('hidden');\n root.find(SELECTORS.LOADING_PLACEHOLDER).addClass('hidden');\n };\n\n /**\n * Show the paging bar.\n *\n * @param {object} root The root element for the courses view.\n */\n var showPagingBar = function(root) {\n var pagingBar = root.find(SELECTORS.PAGING_BAR);\n pagingBar.css('opacity', 1);\n pagingBar.css('visibility', 'visible');\n pagingBar.attr('aria-hidden', 'false');\n };\n\n /**\n * Hide the paging bar.\n *\n * @param {object} root The root element for the courses view.\n */\n var hidePagingBar = function(root) {\n var pagingBar = root.find(SELECTORS.PAGING_BAR);\n pagingBar.css('opacity', 0);\n pagingBar.css('visibility', 'hidden');\n pagingBar.attr('aria-hidden', 'true');\n };\n\n /**\n * Show the favourite indicator for the given course (if it's in the list).\n *\n * @param {object} root The root element for the courses view.\n * @param {number} courseId The id of the course to be favourited.\n */\n var favouriteCourse = function(root, courseId) {\n allCourses.forEach(function(course) {\n if (course.attr('data-course-id') == courseId) {\n course.find(SELECTORS.COURSE_IS_FAVOURITE).removeClass('hidden');\n }\n });\n };\n\n /**\n * Hide the favourite indicator for the given course (if it's in the list).\n *\n * @param {object} root The root element for the courses view.\n * @param {number} courseId The id of the course to be unfavourited.\n */\n var unfavouriteCourse = function(root, courseId) {\n allCourses.forEach(function(course) {\n if (course.attr('data-course-id') == courseId) {\n course.find(SELECTORS.COURSE_IS_FAVOURITE).addClass('hidden');\n }\n });\n };\n\n /**\n * Render the a list of courses.\n *\n * @param {array} courses containing array of courses.\n * @return {promise} Resolved with list of rendered courses as jQuery objects.\n */\n var renderAllCourses = function(courses) {\n var promises = courses.map(function(course) {\n return Templates.render('block_recentlyaccessedcourses/course-card', course);\n });\n\n return $.when.apply(null, promises).then(function() {\n var renderedCourses = [];\n\n promises.forEach(function(promise) {\n promise.then(function(html) {\n renderedCourses.push($(html));\n return;\n })\n .catch(Notification.exception);\n });\n\n return renderedCourses;\n });\n };\n\n /**\n * Fetch user's recently accessed courses and reload the content of the block.\n *\n * @param {int} userid User whose courses will be shown\n * @returns {promise} The updated content for the block.\n */\n var loadContent = function(userid) {\n return CoursesRepository.getLastAccessedCourses(userid, NUM_COURSES_TOTAL)\n .then(function(courses) {\n return renderAllCourses(courses);\n });\n };\n\n /**\n * Recalculate the number of courses that should be visible.\n *\n * @param {object} root The root element for the courses view.\n */\n var recalculateVisibleCourses = function(root) {\n var container = root.find(SELECTORS.CONTENT).find(SELECTORS.CARD_CONTAINER);\n var availableWidth = parseFloat(root.css('width'));\n var numberOfCourses = allCourses.length;\n var start = 0;\n\n if (!cardWidth) {\n container.html(allCourses[0]);\n // Render one card initially to calculate the width of the cards\n // including the margins.\n cardWidth = allCourses[0].outerWidth(true);\n }\n\n availableVisibleCards = Math.floor(availableWidth / cardWidth);\n\n if (viewIndex + availableVisibleCards < numberOfCourses) {\n start = viewIndex;\n } else {\n var overflow = (viewIndex + availableVisibleCards) - numberOfCourses;\n start = viewIndex - overflow;\n start = start >= 0 ? start : 0;\n }\n\n var coursesToShow = allCourses.slice(start, start + availableVisibleCards);\n // Create an id for the list of courses we expect to be displayed.\n var newVisibleCoursesId = coursesToShow.reduce(function(carry, course) {\n return carry + course.attr('data-course-id');\n }, '');\n\n // Centre the courses if we have an overflow of courses.\n if (allCourses.length > coursesToShow.length) {\n container.addClass('justify-content-center');\n container.removeClass('justify-content-start');\n } else {\n container.removeClass('justify-content-center');\n container.addClass('justify-content-start');\n }\n\n // Don't bother updating the DOM unless the visible courses have changed.\n if (visibleCoursesId != newVisibleCoursesId) {\n var pagingBar = root.find(PagedContentPagingBar.rootSelector);\n container.html(coursesToShow);\n visibleCoursesId = newVisibleCoursesId;\n\n if (availableVisibleCards >= allCourses.length) {\n hidePagingBar(root);\n } else {\n showPagingBar(root);\n\n if (viewIndex === 0) {\n PagedContentPagingBar.disablePreviousControlButtons(pagingBar);\n } else {\n PagedContentPagingBar.enablePreviousControlButtons(pagingBar);\n }\n\n if (viewIndex + availableVisibleCards >= allCourses.length) {\n PagedContentPagingBar.disableNextControlButtons(pagingBar);\n } else {\n PagedContentPagingBar.enableNextControlButtons(pagingBar);\n }\n }\n }\n };\n\n /**\n * Register event listeners for the block.\n *\n * @param {object} root The root element for the recentlyaccessedcourses block.\n */\n var registerEventListeners = function(root) {\n var resizeTimeout = null;\n var drawerToggling = false;\n\n PubSub.subscribe(CourseEvents.favourited, function(courseId) {\n favouriteCourse(root, courseId);\n });\n\n PubSub.subscribe(CourseEvents.unfavorited, function(courseId) {\n unfavouriteCourse(root, courseId);\n });\n\n PubSub.subscribe('nav-drawer-toggle-start', function() {\n if (!contentLoaded || !allCourses.length || drawerToggling) {\n // Nothing to recalculate.\n return;\n }\n\n drawerToggling = true;\n var recalculationCount = 0;\n // This function is going to recalculate the number of courses while\n // the nav drawer is opening or closes (up to a maximum of 5 recalcs).\n var doRecalculation = function() {\n setTimeout(function() {\n recalculateVisibleCourses(root);\n recalculationCount++;\n\n if (recalculationCount < 5 && drawerToggling) {\n // If we haven't done too many recalculations and the drawer\n // is still toggling then recurse.\n doRecalculation();\n }\n }, 100);\n };\n\n // Start the recalculations.\n doRecalculation(root);\n });\n\n PubSub.subscribe('nav-drawer-toggle-end', function() {\n drawerToggling = false;\n });\n\n $(window).on('resize', function() {\n if (!contentLoaded || !allCourses.length) {\n // Nothing to reclculate.\n return;\n }\n\n // Resize events fire rapidly so recalculating the visible courses each\n // time can be expensive. Let's debounce them,\n if (!resizeTimeout) {\n resizeTimeout = setTimeout(function() {\n resizeTimeout = null;\n recalculateVisibleCourses(root);\n // The recalculateVisibleCourses function will execute at a rate of 15fps.\n }, 66);\n }\n });\n\n CustomEvents.define(root, [CustomEvents.events.activate]);\n root.on(CustomEvents.events.activate, SELECTORS.PAGING_BAR_NEXT, function(e, data) {\n var button = $(e.target).closest(SELECTORS.PAGING_BAR_NEXT);\n if (!button.hasClass('disabled')) {\n viewIndex = viewIndex + availableVisibleCards;\n recalculateVisibleCourses(root);\n }\n\n data.originalEvent.preventDefault();\n });\n\n root.on(CustomEvents.events.activate, SELECTORS.PAGING_BAR_PREVIOUS, function(e, data) {\n var button = $(e.target).closest(SELECTORS.PAGING_BAR_PREVIOUS);\n if (!button.hasClass('disabled')) {\n viewIndex = viewIndex - availableVisibleCards;\n viewIndex = viewIndex < 0 ? 0 : viewIndex;\n recalculateVisibleCourses(root);\n }\n\n data.originalEvent.preventDefault();\n });\n };\n\n /**\n * Get and show the recent courses into the block.\n *\n * @param {int} userid User from which the courses will be obtained\n * @param {object} root The root element for the recentlyaccessedcourses block.\n */\n var init = function(userid, root) {\n root = $(root);\n\n registerEventListeners(root);\n loadContent(userid)\n .then(function(renderedCourses) {\n allCourses = renderedCourses;\n contentLoaded = true;\n\n if (allCourses.length) {\n showContent(root);\n recalculateVisibleCourses(root);\n } else {\n showEmptyMessage(root);\n }\n\n return;\n })\n .catch(Notification.exception);\n };\n\n return {\n init: init\n };\n });\n"],"file":"main.min.js"} \ No newline at end of file +{"version":3,"sources":["../src/main.js"],"names":["define","$","CustomEvents","Notification","PubSub","PagedContentPagingBar","Templates","CourseEvents","CoursesRepository","SELECTORS","BLOCK_CONTAINER","CARD_CONTAINER","COURSE_IS_FAVOURITE","CONTENT","EMPTY_MESSAGE","LOADING_PLACEHOLDER","PAGING_BAR","PAGING_BAR_NEXT","PAGING_BAR_PREVIOUS","contentLoaded","allCourses","visibleCoursesId","cardWidth","viewIndex","availableVisibleCards","showEmptyMessage","root","find","removeClass","addClass","showContent","showPagingBar","pagingBar","css","attr","hidePagingBar","favouriteCourse","courseId","forEach","course","unfavouriteCourse","renderAllCourses","courses","showcoursecategory","data","promises","map","render","when","apply","then","renderedCourses","promise","html","push","catch","exception","loadContent","userid","getLastAccessedCourses","recalculateVisibleCourses","container","availableWidth","parseFloat","numberOfCourses","length","start","outerWidth","Math","floor","overflow","coursesToShow","slice","newVisibleCoursesId","reduce","carry","rootSelector","disablePreviousControlButtons","enablePreviousControlButtons","disableNextControlButtons","enableNextControlButtons","registerEventListeners","resizeTimeout","drawerToggling","subscribe","favourited","unfavorited","recalculationCount","doRecalculation","setTimeout","window","on","events","activate","e","button","target","closest","hasClass","originalEvent","preventDefault","init"],"mappings":"AAwBAA,OAAM,sCACF,CACI,QADJ,CAEI,gCAFJ,CAGI,mBAHJ,CAII,aAJJ,CAKI,+BALJ,CAMI,gBANJ,CAOI,oB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D,CAAAA,CAAM,CAAG9F,CAAC,CAAC6F,CAAC,CAACE,MAAH,CAAD,CAAYC,OAAZ,CAAoBxF,CAAS,CAACS,mBAA9B,CAAb,CACA,GAAI,CAAC6E,CAAM,CAACG,QAAP,CAAgB,UAAhB,CAAL,CAAkC,CAC9B3E,CAAS,CAAGA,CAAS,CAAGC,CAAxB,CACAD,CAAS,CAAe,CAAZ,CAAAA,CAAS,CAAO,CAAP,CAAWA,CAAhC,CACAqC,CAAyB,CAAClC,CAAD,CAC5B,CAEDkB,CAAI,CAACuD,aAAL,CAAmBC,cAAnB,EACH,CATD,CAUH,CArSH,CAkUE,MAAO,CACHC,IAAI,CAtBG,QAAPA,CAAAA,IAAO,CAAS3C,CAAT,CAAiBhC,CAAjB,CAAuB,CAC9BA,CAAI,CAAGzB,CAAC,CAACyB,CAAD,CAAR,CAEAuD,CAAsB,CAACvD,CAAD,CAAtB,CACA+B,CAAW,CAACC,CAAD,CAAX,CACKR,IADL,CACU,SAASC,CAAT,CAA0B,CAC5B/B,CAAU,CAAG+B,CAAb,CACAhC,CAAa,GAAb,CAEA,GAAIC,CAAU,CAAC6C,MAAf,CAAuB,CACnBnC,CAAW,CAACJ,CAAD,CAAX,CACAkC,CAAyB,CAAClC,CAAD,CAC5B,CAHD,IAGO,CACHD,CAAgB,CAACC,CAAD,CACnB,CAGJ,CAbL,EAcK6B,KAdL,CAcWpD,CAAY,CAACqD,SAdxB,CAeH,CAEM,CAGV,CAzVC,CAAN","sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * Javascript to initialise the Recently accessed courses block.\n *\n * @module block_recentlyaccessedcourses/main.js\n * @package block_recentlyaccessedcourses\n * @copyright 2018 Victor Deniz \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\ndefine(\n [\n 'jquery',\n 'core/custom_interaction_events',\n 'core/notification',\n 'core/pubsub',\n 'core/paged_content_paging_bar',\n 'core/templates',\n 'core_course/events',\n 'core_course/repository',\n ],\n function(\n $,\n CustomEvents,\n Notification,\n PubSub,\n PagedContentPagingBar,\n Templates,\n CourseEvents,\n CoursesRepository\n ) {\n\n // Constants.\n var NUM_COURSES_TOTAL = 10;\n var SELECTORS = {\n BLOCK_CONTAINER: '[data-region=\"recentlyaccessedcourses\"]',\n CARD_CONTAINER: '[data-region=\"card-deck\"]',\n COURSE_IS_FAVOURITE: '[data-region=\"is-favourite\"]',\n CONTENT: '[data-region=\"view-content\"]',\n EMPTY_MESSAGE: '[data-region=\"empty-message\"]',\n LOADING_PLACEHOLDER: '[data-region=\"loading-placeholder\"]',\n PAGING_BAR: '[data-region=\"paging-bar\"]',\n PAGING_BAR_NEXT: '[data-control=\"next\"]',\n PAGING_BAR_PREVIOUS: '[data-control=\"previous\"]'\n };\n // Module variables.\n var contentLoaded = false;\n var allCourses = [];\n var visibleCoursesId = null;\n var cardWidth = null;\n var viewIndex = 0;\n var availableVisibleCards = 1;\n\n /**\n * Show the empty message when no course are found.\n *\n * @param {object} root The root element for the courses view.\n */\n var showEmptyMessage = function(root) {\n root.find(SELECTORS.EMPTY_MESSAGE).removeClass('hidden');\n root.find(SELECTORS.LOADING_PLACEHOLDER).addClass('hidden');\n root.find(SELECTORS.CONTENT).addClass('hidden');\n };\n\n /**\n * Show the empty message when no course are found.\n *\n * @param {object} root The root element for the courses view.\n */\n var showContent = function(root) {\n root.find(SELECTORS.CONTENT).removeClass('hidden');\n root.find(SELECTORS.EMPTY_MESSAGE).addClass('hidden');\n root.find(SELECTORS.LOADING_PLACEHOLDER).addClass('hidden');\n };\n\n /**\n * Show the paging bar.\n *\n * @param {object} root The root element for the courses view.\n */\n var showPagingBar = function(root) {\n var pagingBar = root.find(SELECTORS.PAGING_BAR);\n pagingBar.css('opacity', 1);\n pagingBar.css('visibility', 'visible');\n pagingBar.attr('aria-hidden', 'false');\n };\n\n /**\n * Hide the paging bar.\n *\n * @param {object} root The root element for the courses view.\n */\n var hidePagingBar = function(root) {\n var pagingBar = root.find(SELECTORS.PAGING_BAR);\n pagingBar.css('opacity', 0);\n pagingBar.css('visibility', 'hidden');\n pagingBar.attr('aria-hidden', 'true');\n };\n\n /**\n * Show the favourite indicator for the given course (if it's in the list).\n *\n * @param {object} root The root element for the courses view.\n * @param {number} courseId The id of the course to be favourited.\n */\n var favouriteCourse = function(root, courseId) {\n allCourses.forEach(function(course) {\n if (course.attr('data-course-id') == courseId) {\n course.find(SELECTORS.COURSE_IS_FAVOURITE).removeClass('hidden');\n }\n });\n };\n\n /**\n * Hide the favourite indicator for the given course (if it's in the list).\n *\n * @param {object} root The root element for the courses view.\n * @param {number} courseId The id of the course to be unfavourited.\n */\n var unfavouriteCourse = function(root, courseId) {\n allCourses.forEach(function(course) {\n if (course.attr('data-course-id') == courseId) {\n course.find(SELECTORS.COURSE_IS_FAVOURITE).addClass('hidden');\n }\n });\n };\n\n /**\n * Render the a list of courses.\n *\n * @param {array} courses containing array of courses.\n * @return {promise} Resolved with list of rendered courses as jQuery objects.\n */\n var renderAllCourses = function(courses) {\n var showcoursecategory = $(SELECTORS.BLOCK_CONTAINER).data('displaycoursecategory');\n var promises = courses.map(function(course) {\n course.showcoursecategory = showcoursecategory;\n return Templates.render('block_recentlyaccessedcourses/course-card', course);\n });\n\n return $.when.apply(null, promises).then(function() {\n var renderedCourses = [];\n\n promises.forEach(function(promise) {\n promise.then(function(html) {\n renderedCourses.push($(html));\n return;\n })\n .catch(Notification.exception);\n });\n\n return renderedCourses;\n });\n };\n\n /**\n * Fetch user's recently accessed courses and reload the content of the block.\n *\n * @param {int} userid User whose courses will be shown\n * @returns {promise} The updated content for the block.\n */\n var loadContent = function(userid) {\n return CoursesRepository.getLastAccessedCourses(userid, NUM_COURSES_TOTAL)\n .then(function(courses) {\n return renderAllCourses(courses);\n });\n };\n\n /**\n * Recalculate the number of courses that should be visible.\n *\n * @param {object} root The root element for the courses view.\n */\n var recalculateVisibleCourses = function(root) {\n var container = root.find(SELECTORS.CONTENT).find(SELECTORS.CARD_CONTAINER);\n var availableWidth = parseFloat(root.css('width'));\n var numberOfCourses = allCourses.length;\n var start = 0;\n\n if (!cardWidth) {\n container.html(allCourses[0]);\n // Render one card initially to calculate the width of the cards\n // including the margins.\n cardWidth = allCourses[0].outerWidth(true);\n }\n\n availableVisibleCards = Math.floor(availableWidth / cardWidth);\n\n if (viewIndex + availableVisibleCards < numberOfCourses) {\n start = viewIndex;\n } else {\n var overflow = (viewIndex + availableVisibleCards) - numberOfCourses;\n start = viewIndex - overflow;\n start = start >= 0 ? start : 0;\n }\n\n var coursesToShow = allCourses.slice(start, start + availableVisibleCards);\n // Create an id for the list of courses we expect to be displayed.\n var newVisibleCoursesId = coursesToShow.reduce(function(carry, course) {\n return carry + course.attr('data-course-id');\n }, '');\n\n // Centre the courses if we have an overflow of courses.\n if (allCourses.length > coursesToShow.length) {\n container.addClass('justify-content-center');\n container.removeClass('justify-content-start');\n } else {\n container.removeClass('justify-content-center');\n container.addClass('justify-content-start');\n }\n\n // Don't bother updating the DOM unless the visible courses have changed.\n if (visibleCoursesId != newVisibleCoursesId) {\n var pagingBar = root.find(PagedContentPagingBar.rootSelector);\n container.html(coursesToShow);\n visibleCoursesId = newVisibleCoursesId;\n\n if (availableVisibleCards >= allCourses.length) {\n hidePagingBar(root);\n } else {\n showPagingBar(root);\n\n if (viewIndex === 0) {\n PagedContentPagingBar.disablePreviousControlButtons(pagingBar);\n } else {\n PagedContentPagingBar.enablePreviousControlButtons(pagingBar);\n }\n\n if (viewIndex + availableVisibleCards >= allCourses.length) {\n PagedContentPagingBar.disableNextControlButtons(pagingBar);\n } else {\n PagedContentPagingBar.enableNextControlButtons(pagingBar);\n }\n }\n }\n };\n\n /**\n * Register event listeners for the block.\n *\n * @param {object} root The root element for the recentlyaccessedcourses block.\n */\n var registerEventListeners = function(root) {\n var resizeTimeout = null;\n var drawerToggling = false;\n\n PubSub.subscribe(CourseEvents.favourited, function(courseId) {\n favouriteCourse(root, courseId);\n });\n\n PubSub.subscribe(CourseEvents.unfavorited, function(courseId) {\n unfavouriteCourse(root, courseId);\n });\n\n PubSub.subscribe('nav-drawer-toggle-start', function() {\n if (!contentLoaded || !allCourses.length || drawerToggling) {\n // Nothing to recalculate.\n return;\n }\n\n drawerToggling = true;\n var recalculationCount = 0;\n // This function is going to recalculate the number of courses while\n // the nav drawer is opening or closes (up to a maximum of 5 recalcs).\n var doRecalculation = function() {\n setTimeout(function() {\n recalculateVisibleCourses(root);\n recalculationCount++;\n\n if (recalculationCount < 5 && drawerToggling) {\n // If we haven't done too many recalculations and the drawer\n // is still toggling then recurse.\n doRecalculation();\n }\n }, 100);\n };\n\n // Start the recalculations.\n doRecalculation(root);\n });\n\n PubSub.subscribe('nav-drawer-toggle-end', function() {\n drawerToggling = false;\n });\n\n $(window).on('resize', function() {\n if (!contentLoaded || !allCourses.length) {\n // Nothing to reclculate.\n return;\n }\n\n // Resize events fire rapidly so recalculating the visible courses each\n // time can be expensive. Let's debounce them,\n if (!resizeTimeout) {\n resizeTimeout = setTimeout(function() {\n resizeTimeout = null;\n recalculateVisibleCourses(root);\n // The recalculateVisibleCourses function will execute at a rate of 15fps.\n }, 66);\n }\n });\n\n CustomEvents.define(root, [CustomEvents.events.activate]);\n root.on(CustomEvents.events.activate, SELECTORS.PAGING_BAR_NEXT, function(e, data) {\n var button = $(e.target).closest(SELECTORS.PAGING_BAR_NEXT);\n if (!button.hasClass('disabled')) {\n viewIndex = viewIndex + availableVisibleCards;\n recalculateVisibleCourses(root);\n }\n\n data.originalEvent.preventDefault();\n });\n\n root.on(CustomEvents.events.activate, SELECTORS.PAGING_BAR_PREVIOUS, function(e, data) {\n var button = $(e.target).closest(SELECTORS.PAGING_BAR_PREVIOUS);\n if (!button.hasClass('disabled')) {\n viewIndex = viewIndex - availableVisibleCards;\n viewIndex = viewIndex < 0 ? 0 : viewIndex;\n recalculateVisibleCourses(root);\n }\n\n data.originalEvent.preventDefault();\n });\n };\n\n /**\n * Get and show the recent courses into the block.\n *\n * @param {int} userid User from which the courses will be obtained\n * @param {object} root The root element for the recentlyaccessedcourses block.\n */\n var init = function(userid, root) {\n root = $(root);\n\n registerEventListeners(root);\n loadContent(userid)\n .then(function(renderedCourses) {\n allCourses = renderedCourses;\n contentLoaded = true;\n\n if (allCourses.length) {\n showContent(root);\n recalculateVisibleCourses(root);\n } else {\n showEmptyMessage(root);\n }\n\n return;\n })\n .catch(Notification.exception);\n };\n\n return {\n init: init\n };\n });\n"],"file":"main.min.js"} \ No newline at end of file diff --git a/blocks/recentlyaccessedcourses/amd/src/main.js b/blocks/recentlyaccessedcourses/amd/src/main.js index 6a3ca163f6e..ca3186b5899 100644 --- a/blocks/recentlyaccessedcourses/amd/src/main.js +++ b/blocks/recentlyaccessedcourses/amd/src/main.js @@ -47,6 +47,7 @@ define( // Constants. var NUM_COURSES_TOTAL = 10; var SELECTORS = { + BLOCK_CONTAINER: '[data-region="recentlyaccessedcourses"]', CARD_CONTAINER: '[data-region="card-deck"]', COURSE_IS_FAVOURITE: '[data-region="is-favourite"]', CONTENT: '[data-region="view-content"]', @@ -145,7 +146,9 @@ define( * @return {promise} Resolved with list of rendered courses as jQuery objects. */ var renderAllCourses = function(courses) { + var showcoursecategory = $(SELECTORS.BLOCK_CONTAINER).data('displaycoursecategory'); var promises = courses.map(function(course) { + course.showcoursecategory = showcoursecategory; return Templates.render('block_recentlyaccessedcourses/course-card', course); }); diff --git a/blocks/recentlyaccessedcourses/block_recentlyaccessedcourses.php b/blocks/recentlyaccessedcourses/block_recentlyaccessedcourses.php index 9f1127bd100..0c8c388d737 100644 --- a/blocks/recentlyaccessedcourses/block_recentlyaccessedcourses.php +++ b/blocks/recentlyaccessedcourses/block_recentlyaccessedcourses.php @@ -67,4 +67,13 @@ class block_recentlyaccessedcourses extends block_base { public function applicable_formats() { return array('my' => true); } + + /** + * Allow the block to have a configuration page + * + * @return boolean + */ + public function has_config() { + return true; + } } diff --git a/blocks/recentlyaccessedcourses/classes/output/main.php b/blocks/recentlyaccessedcourses/classes/output/main.php index 631af28407b..0534d17670e 100644 --- a/blocks/recentlyaccessedcourses/classes/output/main.php +++ b/blocks/recentlyaccessedcourses/classes/output/main.php @@ -46,6 +46,7 @@ class main implements renderable, templatable { global $USER; $nocoursesurl = $output->image_url('courses', 'block_recentlyaccessedcourses')->out(false); + $config = get_config('block_recentlyaccessedcourses'); return [ 'userid' => $USER->id, @@ -53,7 +54,8 @@ class main implements renderable, templatable { 'pagingbar' => [ 'next' => true, 'previous' => true - ] + ], + 'displaycategories' => !empty($config->displaycategories) ]; } } diff --git a/blocks/recentlyaccessedcourses/lang/en/block_recentlyaccessedcourses.php b/blocks/recentlyaccessedcourses/lang/en/block_recentlyaccessedcourses.php index 8a722478083..86e88c38c33 100644 --- a/blocks/recentlyaccessedcourses/lang/en/block_recentlyaccessedcourses.php +++ b/blocks/recentlyaccessedcourses/lang/en/block_recentlyaccessedcourses.php @@ -20,7 +20,9 @@ * @copyright 2018 Victor Deniz * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +$string['displaycategories'] = 'Display categories'; +$string['displaycategories_help'] = 'Display the course category on the recently accessed courses block items.'; $string['pluginname'] = 'Recently accessed courses'; $string['privacy:metadata'] = 'The Recently accessed courses block does not store any personal data.'; $string['recentlyaccessedcourses:myaddinstance'] = 'Add a new recently accessed courses block to Dashboard'; -$string['nocourses'] = 'No recent courses'; \ No newline at end of file +$string['nocourses'] = 'No recent courses'; diff --git a/blocks/recentlyaccessedcourses/settings.php b/blocks/recentlyaccessedcourses/settings.php new file mode 100644 index 00000000000..2e763433818 --- /dev/null +++ b/blocks/recentlyaccessedcourses/settings.php @@ -0,0 +1,34 @@ +. + +/** + * Settings for the recentlyaccessedcourses block + * + * @package block_recentlyaccessedcourses + * @copyright 2019 Mihail Geshoski + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die; + +if ($ADMIN->fulltree) { + // Display Course Categories on the recently accessed courses block items. + $settings->add(new admin_setting_configcheckbox( + 'block_recentlyaccessedcourses/displaycategories', + get_string('displaycategories', 'block_recentlyaccessedcourses'), + get_string('displaycategories_help', 'block_recentlyaccessedcourses'), + 1)); +} diff --git a/blocks/recentlyaccessedcourses/templates/course-card.mustache b/blocks/recentlyaccessedcourses/templates/course-card.mustache index 7b98a5eb203..c18f12438f1 100644 --- a/blocks/recentlyaccessedcourses/templates/course-card.mustache +++ b/blocks/recentlyaccessedcourses/templates/course-card.mustache @@ -35,10 +35,17 @@ {{< core_course/coursecard }} {{$coursecategory}} - - {{#str}}aria:coursecategory, core_course{{/str}} - - {{{coursecategory}}} + {{#showcoursecategory}} + + {{#str}}aria:coursecategory, core_course{{/str}} + + {{{coursecategory}}} + {{/showcoursecategory}} {{/coursecategory}} {{$coursename}} {{{fullname}}} {{/coursename}} + {{$divider}} + {{#showcoursecategory}} +
|
+ {{/showcoursecategory}} + {{/divider}} {{/ core_course/coursecard }} diff --git a/blocks/recentlyaccessedcourses/templates/main.mustache b/blocks/recentlyaccessedcourses/templates/main.mustache index 84e64d532eb..1a072606902 100644 --- a/blocks/recentlyaccessedcourses/templates/main.mustache +++ b/blocks/recentlyaccessedcourses/templates/main.mustache @@ -27,7 +27,7 @@ }}
+ data-userid="{{userid}}" data-displaycoursecategory="{{displaycategories}}">
{{> block_recentlyaccessedcourses/recentlyaccessedcourses-view }}
diff --git a/blocks/recentlyaccessedcourses/tests/behat/block_recentlyaccessedcourses_dashboard.feature b/blocks/recentlyaccessedcourses/tests/behat/block_recentlyaccessedcourses_dashboard.feature index 1361760cec8..731e1efc670 100644 --- a/blocks/recentlyaccessedcourses/tests/behat/block_recentlyaccessedcourses_dashboard.feature +++ b/blocks/recentlyaccessedcourses/tests/behat/block_recentlyaccessedcourses_dashboard.feature @@ -8,13 +8,16 @@ Feature: The recently accessed courses block allows users to easily access their Given the following "users" exist: | username | firstname | lastname | email | | student1 | Student | 1 | student1@example.com | + And the following "categories" exist: + | name | category | idnumber | + | Category 1 | 0 | CAT1 | And the following "courses" exist: - | fullname | shortname | - | Course 1 | C1 | - | Course 2 | C2 | - | Course 3 | C3 | - | Course 4 | C4 | - | Course 5 | C5 | + | fullname | shortname | category | + | Course 1 | C1 | 0 | + | Course 2 | C2 | 0 | + | Course 3 | C3 | 0 | + | Course 4 | C4 | CAT1 | + | Course 5 | C5 | 0 | And the following "course enrolments" exist: | user | course | role | | student1 | C1 | student | @@ -40,3 +43,43 @@ Feature: The recently accessed courses block allows users to easily access their And I should not see "Course 3" in the "Recently accessed courses" "block" And I should not see "Course 4" in the "Recently accessed courses" "block" And I should not see "Course 5" in the "Recently accessed courses" "block" + + Scenario: Show course category name + Given the following config values are set as admin: + | displaycategories | 1 | block_recentlyaccessedcourses | + And I log in as "student1" + And I am on "Course 1" course homepage + And I am on "Course 4" course homepage + And I follow "Dashboard" in the user menu + And I should see "Miscellaneous" in the "Recently accessed courses" "block" + And I should see "Category 1" in the "Recently accessed courses" "block" + + Scenario: Hide course category name + Given the following config values are set as admin: + | displaycategories | 0 | block_recentlyaccessedcourses | + And I log in as "student1" + And I am on "Course 1" course homepage + And I am on "Course 4" course homepage + And I follow "Dashboard" in the user menu + And I should not see "Miscellaneous" in the "Recently accessed courses" "block" + And I should not see "Category 1" in the "Recently accessed courses" "block" + + Scenario: Show short course name + Given the following config values are set as admin: + | courselistshortnames | 1 | + And I log in as "student1" + And I am on "Course 1" course homepage + And I am on "Course 4" course homepage + And I follow "Dashboard" in the user menu + And I should see "C1" in the "Recently accessed courses" "block" + And I should see "C4" in the "Recently accessed courses" "block" + + Scenario: Hide short course name + Given the following config values are set as admin: + | courselistshortnames | 0 | + And I log in as "student1" + And I am on "Course 1" course homepage + And I am on "Course 4" course homepage + And I follow "Dashboard" in the user menu + And I should not see "C1" in the "Recently accessed courses" "block" + And I should not see "C4" in the "Recently accessed courses" "block" diff --git a/blocks/recentlyaccessedcourses/upgrade.txt b/blocks/recentlyaccessedcourses/upgrade.txt index 2f6b9225310..97340542227 100644 --- a/blocks/recentlyaccessedcourses/upgrade.txt +++ b/blocks/recentlyaccessedcourses/upgrade.txt @@ -1,5 +1,10 @@ This file describes API changes in the recentlyaccessedcourses block code. +=== 3.8 === + +* New admin setting block_recentlyaccessedcourses/displaycategories which enables the recently accessed + courses block to display the course category. + === 3.7 === * The 'block/recentlyaccessedcourses:addinstance' capability has been removed. It has never been used in code. \ No newline at end of file diff --git a/blocks/recentlyaccessedcourses/version.php b/blocks/recentlyaccessedcourses/version.php index a05f8fb9ece..08dcbadd91d 100644 --- a/blocks/recentlyaccessedcourses/version.php +++ b/blocks/recentlyaccessedcourses/version.php @@ -22,6 +22,6 @@ */ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2019052000; // The current plugin version (Date: YYYYMMDDXX). +$plugin->version = 2019052001; // The current plugin version (Date: YYYYMMDDXX). $plugin->requires = 2019051100; // Requires this Moodle version. $plugin->component = 'block_recentlyaccessedcourses'; // Full name of the plugin (used for diagnostics).