mirror of
https://github.com/moodle/moodle.git
synced 2025-03-14 12:40:01 +01:00
MDL-64438 block_recentlyaccessedcourses: Optionally show course category
AMOS BEGIN CPY [displaycategories,block_myoverview],[displaycategories,block_recentlyaccessedcourses] AMOS END
This commit is contained in:
parent
93ad530e8f
commit
d0b237b306
@ -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+o<d){f=n}else{var g=n+o-d;f=n-g;f=0<=f?f:0}var h=k.slice(f,f+o),j=h.reduce(function(a,b){return a+b.attr("data-course-id")},"");if(k.length>h.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+o<d){f=n}else{var g=n+o-d;f=n-g;f=0<=f?f:0}var h=k.slice(f,f+o),j=h.reduce(function(a,b){return a+b.attr("data-course-id")},"");if(k.length>h.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
|
||||
|
File diff suppressed because one or more lines are too long
@ -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);
|
||||
});
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -20,7 +20,9 @@
|
||||
* @copyright 2018 Victor Deniz <victor@moodle.com>
|
||||
* @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';
|
||||
$string['nocourses'] = 'No recent courses';
|
||||
|
34
blocks/recentlyaccessedcourses/settings.php
Normal file
34
blocks/recentlyaccessedcourses/settings.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Settings for the recentlyaccessedcourses block
|
||||
*
|
||||
* @package block_recentlyaccessedcourses
|
||||
* @copyright 2019 Mihail Geshoski <mihail@moodle.com>
|
||||
* @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));
|
||||
}
|
@ -35,10 +35,17 @@
|
||||
|
||||
{{< core_course/coursecard }}
|
||||
{{$coursecategory}}
|
||||
<span class="sr-only">
|
||||
{{#str}}aria:coursecategory, core_course{{/str}}
|
||||
</span>
|
||||
<span class="text-truncate">{{{coursecategory}}}</span>
|
||||
{{#showcoursecategory}}
|
||||
<span class="sr-only">
|
||||
{{#str}}aria:coursecategory, core_course{{/str}}
|
||||
</span>
|
||||
<span class="text-truncate">{{{coursecategory}}}</span>
|
||||
{{/showcoursecategory}}
|
||||
{{/coursecategory}}
|
||||
{{$coursename}} <span class="text-truncate">{{{fullname}}}</span> {{/coursename}}
|
||||
{{$divider}}
|
||||
{{#showcoursecategory}}
|
||||
<div class="pl-1 pr-1">|</div>
|
||||
{{/showcoursecategory}}
|
||||
{{/divider}}
|
||||
{{/ core_course/coursecard }}
|
||||
|
@ -27,7 +27,7 @@
|
||||
}}
|
||||
|
||||
<div id="block-recentlyaccessedcourses-{{uniqid}}" class="block-recentlyaccessedcourses block-cards" data-region="recentlyaccessedcourses"
|
||||
data-userid="{{userid}}">
|
||||
data-userid="{{userid}}" data-displaycoursecategory="{{displaycategories}}">
|
||||
<div class="container-fluid p-0">
|
||||
{{> block_recentlyaccessedcourses/recentlyaccessedcourses-view }}
|
||||
</div>
|
||||
|
@ -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"
|
||||
|
@ -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.
|
@ -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).
|
||||
|
Loading…
x
Reference in New Issue
Block a user