Skip to content

Commit

Permalink
MDL-70226 course: Add more options to the activitychoosertabmode setting
Browse files Browse the repository at this point in the history
Some extra options have been added to the activitychoosertabmode setting, to let
admins decide when to display the Recommended tab.
Apart from that, one of these values have be set as default value for this setting,
as suggested by the UX/PX teams. So the Starter and Full presets have been updated
too with the new values.
  • Loading branch information
sarjona committed Mar 3, 2023
1 parent 5562084 commit 5c20b53
Show file tree
Hide file tree
Showing 10 changed files with 198 additions and 26 deletions.
8 changes: 4 additions & 4 deletions admin/presets/classes/helper.php
Expand Up @@ -190,8 +190,8 @@ public static function create_default_presets(): void {
static::add_item($presetid, 'showdataretentionsummary', '0', 'tool_dataprivacy');
static::add_item($presetid, 'forum_maxattachments', '3');
static::add_item($presetid, 'guestloginbutton', '0');
// Set Activity chooser tabs to "Starred, All, Recommended".
static::add_item($presetid, 'activitychoosertabmode', '1');
// Set Activity chooser tabs to "Starred, Recommended, All".
static::add_item($presetid, 'activitychoosertabmode', '4');

// Modules: Hide chat, database, external tool (lti), IMS content package (imscp), lesson, SCORM, survey, wiki, workshop.
static::add_plugin($presetid, 'mod', 'chat', false);
Expand Down Expand Up @@ -301,8 +301,8 @@ public static function create_default_presets(): void {
static::add_item($presetid, 'showdataretentionsummary', '1', 'tool_dataprivacy');
static::add_item($presetid, 'forum_maxattachments', '9');
static::add_item($presetid, 'guestloginbutton', '1');
// Set Activity chooser tabs to the default value ("Starred, All, Activities, Resources, Recommended").
static::add_item($presetid, 'activitychoosertabmode', '0');
// Set Activity chooser tabs to the default value ("Starred, Recommended, All, Activities, Resources").
static::add_item($presetid, 'activitychoosertabmode', '3');

// Modules: Enable chat, database, external tool (lti), IMS content package (imscp), lesson, SCORM, survey, wiki, workshop.
static::add_plugin($presetid, 'mod', 'chat', true);
Expand Down
5 changes: 4 additions & 1 deletion admin/settings/courses.php
Expand Up @@ -260,8 +260,11 @@
'activitychoosertabmode',
new lang_string('activitychoosertabmode', 'course'),
new lang_string('activitychoosertabmode_desc', 'course'),
0,
3,
[
3 => new lang_string('activitychoosertabmodefour', 'course'),
4 => new lang_string('activitychoosertabmodefive', 'course'),
5 => new lang_string('activitychoosertabmodesix', 'course'),
0 => new lang_string('activitychoosertabmodeone', 'course'),
1 => new lang_string('activitychoosertabmodetwo', 'course'),
2 => new lang_string('activitychoosertabmodethree', 'course'),
Expand Down
2 changes: 1 addition & 1 deletion course/amd/build/activitychooser.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 course/amd/build/activitychooser.min.js.map

Large diffs are not rendered by default.

38 changes: 32 additions & 6 deletions course/amd/src/activitychooser.js
Expand Up @@ -34,8 +34,11 @@ import Pending from 'core/pending';

// Tab config options.
const ALLACTIVITIESRESOURCES = 0;
const ONLYALL = 1;
const ACTIVITIESRESOURCES = 2;
const ALLACTIVITIESRESOURCESREC = 3;
const ONLYALLREC = 4;
const ACTIVITIESRESOURCESREC = 5;


// Module types.
const ACTIVITY = 0;
Expand Down Expand Up @@ -212,27 +215,48 @@ const templateDataBuilder = (data, chooserConfig) => {
const favourites = data.filter(mod => mod.favourite === true);
const recommended = data.filter(mod => mod.recommended === true);

// Both of these modes need Activity & Resource tabs.
if ((tabMode === ALLACTIVITIESRESOURCES || tabMode === ACTIVITIESRESOURCES) && tabMode !== ONLYALL) {
// Whether the activities and resources tabs should be displayed or not.
const showActivitiesAndResources = (tabMode) => {
const acceptableModes = [
ALLACTIVITIESRESOURCES,
ALLACTIVITIESRESOURCESREC,
ACTIVITIESRESOURCES,
ACTIVITIESRESOURCESREC,
];

return acceptableModes.indexOf(tabMode) !== -1;
};

// These modes need Activity & Resource tabs.
if (showActivitiesAndResources(tabMode)) {
// Filter the incoming data to find activities then resources.
activities = data.filter(mod => mod.archetype === ACTIVITY);
resources = data.filter(mod => mod.archetype === RESOURCE);
showActivities = true;
showResources = true;

// We want all of the previous information but no 'All' tab.
if (tabMode === ACTIVITIESRESOURCES) {
if (tabMode === ACTIVITIESRESOURCES || tabMode === ACTIVITIESRESOURCESREC) {
showAll = false;
}
}

const recommendedBeforeTabs = [
ALLACTIVITIESRESOURCESREC,
ONLYALLREC,
ACTIVITIESRESOURCESREC,
];
// Whether the recommended tab should be displayed before the All/Activities/Resources tabs.
const recommendedBeginning = recommendedBeforeTabs.indexOf(tabMode) !== -1;

// Given the results of the above filters lets figure out what tab to set active.
// We have some favourites.
const favouritesFirst = !!favourites.length;
const recommendedFirst = favouritesFirst === false && recommendedBeginning === true && !!recommended.length;
// We are in tabMode 2 without any favourites.
const activitiesFirst = showAll === false && favouritesFirst === false;
const activitiesFirst = showAll === false && favouritesFirst === false && recommendedFirst === false;
// We have nothing fallback to show all modules.
const fallback = showAll === true && favouritesFirst === false;
const fallback = showAll === true && favouritesFirst === false && recommendedFirst === false;

return {
'default': data,
Expand All @@ -244,6 +268,8 @@ const templateDataBuilder = (data, chooserConfig) => {
showResources: showResources,
favourites: favourites,
recommended: recommended,
recommendedFirst: recommendedFirst,
recommendedBeginning: recommendedBeginning,
favouritesFirst: favouritesFirst,
fallback: fallback,
};
Expand Down

0 comments on commit 5c20b53

Please sign in to comment.