From 60983cc2a605b3a1830d522f7ff00fa09a236314 Mon Sep 17 00:00:00 2001 From: Mihail Geshoski Date: Wed, 18 Sep 2019 17:58:24 +0800 Subject: [PATCH] MDL-64438 block_starredcourses: Optionally show course category AMOS BEGIN CPY [displaycategories,block_myoverview],[displaycategories,block_starredcourses] AMOS END --- blocks/starredcourses/amd/build/main.min.js | 2 +- .../starredcourses/amd/build/main.min.js.map | 2 +- blocks/starredcourses/amd/src/main.js | 7 ++++ .../starredcourses/block_starredcourses.php | 9 +++++ blocks/starredcourses/classes/output/main.php | 4 ++- .../lang/en/block_starredcourses.php | 2 ++ blocks/starredcourses/settings.php | 34 +++++++++++++++++++ blocks/starredcourses/templates/main.mustache | 3 +- blocks/starredcourses/upgrade.txt | 5 +++ blocks/starredcourses/version.php | 2 +- 10 files changed, 65 insertions(+), 5 deletions(-) create mode 100644 blocks/starredcourses/settings.php diff --git a/blocks/starredcourses/amd/build/main.min.js b/blocks/starredcourses/amd/build/main.min.js index bb939cd6800..060eb3e88ef 100644 --- a/blocks/starredcourses/amd/build/main.min.js +++ b/blocks/starredcourses/amd/build/main.min.js @@ -1,2 +1,2 @@ -define ("block_starredcourses/main",["jquery","core/notification","block_starredcourses/repository","core/pubsub","core/templates","core_course/events"],function(a,b,c,d,e,f){var g={STARRED_COURSES_REGION_VIEW:"[data-region=\"starred-courses-view\"]",STARRED_COURSES_REGION:"[data-region=\"starred-courses-view-content\"]"},h=function(a,b){if(0.\n\n/**\n * Javascript to initialise the starred courses block.\n *\n * @copyright 2018 Simey Lameze \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\ndefine(\n[\n 'jquery',\n 'core/notification',\n 'block_starredcourses/repository',\n 'core/pubsub',\n 'core/templates',\n 'core_course/events'\n],\nfunction(\n $,\n Notification,\n Repository,\n PubSub,\n Templates,\n CourseEvents\n) {\n\n var SELECTORS = {\n STARRED_COURSES_REGION_VIEW: '[data-region=\"starred-courses-view\"]',\n STARRED_COURSES_REGION: '[data-region=\"starred-courses-view-content\"]'\n };\n\n /**\n * Render the starred courses.\n *\n * @method renderCourses\n * @param {object} root The root element for the starred view.\n * @param {array} courses containing array of returned courses.\n * @returns {promise} Resolved with HTML and JS strings\n */\n var renderCourses = function(root, courses) {\n if (courses.length > 0) {\n return Templates.render('core_course/view-cards', {\n courses: courses\n });\n } else {\n var nocoursesimg = root.find(SELECTORS.STARRED_COURSES_REGION_VIEW).attr('data-nocoursesimg');\n return Templates.render('block_starredcourses/no-courses', {\n nocoursesimg: nocoursesimg\n });\n }\n };\n\n /**\n * Fetch user's starred courses and reload the content of the block.\n *\n * @param {object} root The root element for the starred view.\n * @returns {promise} The updated content for the block.\n */\n var reloadContent = function(root) {\n var content = root.find(SELECTORS.STARRED_COURSES_REGION);\n\n var args = {\n limit: 0,\n offset: 0,\n };\n\n return Repository.getStarredCourses(args)\n .then(function(courses) {\n return renderCourses(root, courses);\n }).then(function(html, js) {\n return Templates.replaceNodeContents(content, html, js);\n }).catch(Notification.exception);\n };\n\n /**\n * Register event listeners for the block.\n *\n * @param {object} root The calendar root element\n */\n var registerEventListeners = function(root) {\n PubSub.subscribe(CourseEvents.favourited, function() {\n reloadContent(root);\n });\n\n PubSub.subscribe(CourseEvents.unfavorited, function() {\n reloadContent(root);\n });\n };\n\n /**\n * Initialise all of the modules for the starred courses block.\n *\n * @param {object} root The root element for the block.\n */\n var init = function(root) {\n root = $(root);\n\n registerEventListeners(root);\n reloadContent(root);\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","$","Notification","Repository","PubSub","Templates","CourseEvents","SELECTORS","BLOCK_CONTAINER","STARRED_COURSES_REGION_VIEW","STARRED_COURSES_REGION","renderCourses","root","courses","length","render","nocoursesimg","find","attr","reloadContent","content","getStarredCourses","limit","offset","then","showcoursecategory","data","map","course","html","js","replaceNodeContents","catch","exception","registerEventListeners","subscribe","favourited","unfavorited","init"],"mappings":"AAsBAA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CACA,MAAOG,CAAAA,CACV,CAHS,CAAV,CAIA,MAAOjB,CAAAA,CAAa,CAACC,CAAD,CAAOC,CAAP,CACvB,CATE,EASAW,IATA,CASK,SAASK,CAAT,CAAeC,CAAf,CAAmB,CACvB,MAAOzB,CAAAA,CAAS,CAAC0B,mBAAV,CAA8BX,CAA9B,CAAuCS,CAAvC,CAA6CC,CAA7C,CACV,CAXE,EAWAE,KAXA,CAWM9B,CAAY,CAAC+B,SAXnB,CAYV,CAvDH,CA8DMC,CAAsB,CAAG,SAAStB,CAAT,CAAe,CACxCR,CAAM,CAAC+B,SAAP,CAAiB7B,CAAY,CAAC8B,UAA9B,CAA0C,UAAW,CACjDjB,CAAa,CAACP,CAAD,CAChB,CAFD,EAIAR,CAAM,CAAC+B,SAAP,CAAiB7B,CAAY,CAAC+B,WAA9B,CAA2C,UAAW,CAClDlB,CAAa,CAACP,CAAD,CAChB,CAFD,CAGH,CAtEH,CAoFE,MAAO,CACH0B,IAAI,CARG,QAAPA,CAAAA,IAAO,CAAS1B,CAAT,CAAe,CACtBA,CAAI,CAAGX,CAAC,CAACW,CAAD,CAAR,CAEAsB,CAAsB,CAACtB,CAAD,CAAtB,CACAO,CAAa,CAACP,CAAD,CAChB,CAEM,CAGV,CAvGK,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 starred courses block.\n *\n * @copyright 2018 Simey Lameze \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\ndefine(\n[\n 'jquery',\n 'core/notification',\n 'block_starredcourses/repository',\n 'core/pubsub',\n 'core/templates',\n 'core_course/events'\n],\nfunction(\n $,\n Notification,\n Repository,\n PubSub,\n Templates,\n CourseEvents\n) {\n\n var SELECTORS = {\n BLOCK_CONTAINER: '[data-region=\"starred-courses\"]',\n STARRED_COURSES_REGION_VIEW: '[data-region=\"starred-courses-view\"]',\n STARRED_COURSES_REGION: '[data-region=\"starred-courses-view-content\"]'\n };\n\n /**\n * Render the starred courses.\n *\n * @method renderCourses\n * @param {object} root The root element for the starred view.\n * @param {array} courses containing array of returned courses.\n * @returns {promise} Resolved with HTML and JS strings\n */\n var renderCourses = function(root, courses) {\n if (courses.length > 0) {\n return Templates.render('core_course/view-cards', {\n courses: courses\n });\n } else {\n var nocoursesimg = root.find(SELECTORS.STARRED_COURSES_REGION_VIEW).attr('data-nocoursesimg');\n return Templates.render('block_starredcourses/no-courses', {\n nocoursesimg: nocoursesimg\n });\n }\n };\n\n /**\n * Fetch user's starred courses and reload the content of the block.\n *\n * @param {object} root The root element for the starred view.\n * @returns {promise} The updated content for the block.\n */\n var reloadContent = function(root) {\n var content = root.find(SELECTORS.STARRED_COURSES_REGION);\n\n var args = {\n limit: 0,\n offset: 0,\n };\n\n return Repository.getStarredCourses(args)\n .then(function(courses) {\n // Whether the course category should be displayed in the course item.\n var showcoursecategory = $(SELECTORS.BLOCK_CONTAINER).data('displaycoursecategory');\n courses = courses.map(function(course) {\n course.showcoursecategory = showcoursecategory;\n return course;\n });\n return renderCourses(root, courses);\n }).then(function(html, js) {\n return Templates.replaceNodeContents(content, html, js);\n }).catch(Notification.exception);\n };\n\n /**\n * Register event listeners for the block.\n *\n * @param {object} root The calendar root element\n */\n var registerEventListeners = function(root) {\n PubSub.subscribe(CourseEvents.favourited, function() {\n reloadContent(root);\n });\n\n PubSub.subscribe(CourseEvents.unfavorited, function() {\n reloadContent(root);\n });\n };\n\n /**\n * Initialise all of the modules for the starred courses block.\n *\n * @param {object} root The root element for the block.\n */\n var init = function(root) {\n root = $(root);\n\n registerEventListeners(root);\n reloadContent(root);\n };\n\n return {\n init: init\n };\n});\n"],"file":"main.min.js"} \ No newline at end of file diff --git a/blocks/starredcourses/amd/src/main.js b/blocks/starredcourses/amd/src/main.js index 0c6d9c0a3cc..5ad14b0e91d 100644 --- a/blocks/starredcourses/amd/src/main.js +++ b/blocks/starredcourses/amd/src/main.js @@ -39,6 +39,7 @@ function( ) { var SELECTORS = { + BLOCK_CONTAINER: '[data-region="starred-courses"]', STARRED_COURSES_REGION_VIEW: '[data-region="starred-courses-view"]', STARRED_COURSES_REGION: '[data-region="starred-courses-view-content"]' }; @@ -80,6 +81,12 @@ function( return Repository.getStarredCourses(args) .then(function(courses) { + // Whether the course category should be displayed in the course item. + var showcoursecategory = $(SELECTORS.BLOCK_CONTAINER).data('displaycoursecategory'); + courses = courses.map(function(course) { + course.showcoursecategory = showcoursecategory; + return course; + }); return renderCourses(root, courses); }).then(function(html, js) { return Templates.replaceNodeContents(content, html, js); diff --git a/blocks/starredcourses/block_starredcourses.php b/blocks/starredcourses/block_starredcourses.php index 2da98ce2ebd..46bfda9aa1e 100644 --- a/blocks/starredcourses/block_starredcourses.php +++ b/blocks/starredcourses/block_starredcourses.php @@ -72,4 +72,13 @@ class block_starredcourses 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/starredcourses/classes/output/main.php b/blocks/starredcourses/classes/output/main.php index 6b7d4272e10..9daec068697 100644 --- a/blocks/starredcourses/classes/output/main.php +++ b/blocks/starredcourses/classes/output/main.php @@ -50,10 +50,12 @@ class main implements renderable, templatable { global $USER; $nocoursesurl = $output->image_url('courses', 'block_starredcourses')->out(); + $config = get_config('block_starredcourses'); return [ 'userid' => $USER->id, - 'nocoursesimg' => $nocoursesurl + 'nocoursesimg' => $nocoursesurl, + 'displaycategories' => !empty($config->displaycategories) ]; } } diff --git a/blocks/starredcourses/lang/en/block_starredcourses.php b/blocks/starredcourses/lang/en/block_starredcourses.php index 06706b868cd..db56aaf3bab 100644 --- a/blocks/starredcourses/lang/en/block_starredcourses.php +++ b/blocks/starredcourses/lang/en/block_starredcourses.php @@ -22,6 +22,8 @@ * @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 starred courses block items.'; $string['pluginname'] = 'Starred courses'; $string['privacy:metadata'] = 'The starred courses block does not store any personal data.'; $string['starredcourses:myaddinstance'] = 'Add a new starred courses block to Dashboard'; diff --git a/blocks/starredcourses/settings.php b/blocks/starredcourses/settings.php new file mode 100644 index 00000000000..fd5f62e6537 --- /dev/null +++ b/blocks/starredcourses/settings.php @@ -0,0 +1,34 @@ +. + +/** + * Settings for the starredcourses block + * + * @package block_starredcourses + * @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 starred courses block items. + $settings->add(new admin_setting_configcheckbox( + 'block_starredcourses/displaycategories', + get_string('displaycategories', 'block_starredcourses'), + get_string('displaycategories_help', 'block_starredcourses'), + 1)); +} diff --git a/blocks/starredcourses/templates/main.mustache b/blocks/starredcourses/templates/main.mustache index a25abf6dbc3..e8826ffb020 100644 --- a/blocks/starredcourses/templates/main.mustache +++ b/blocks/starredcourses/templates/main.mustache @@ -23,7 +23,8 @@ {} }} -
+
{{> block_starredcourses/view }}
diff --git a/blocks/starredcourses/upgrade.txt b/blocks/starredcourses/upgrade.txt index 4f3953633fc..1513824ffce 100644 --- a/blocks/starredcourses/upgrade.txt +++ b/blocks/starredcourses/upgrade.txt @@ -1,5 +1,10 @@ This file describes API changes in the starredcourses block code. +=== 3.8 === + +* New admin setting block_starredcourses/displaycategories which enables the starred courses block + to display the course category. + === 3.7 === * The 'block/starredcourses:addinstance' capability has been removed. It has never been used in code. \ No newline at end of file diff --git a/blocks/starredcourses/version.php b/blocks/starredcourses/version.php index e3065320683..83a69d19a64 100644 --- a/blocks/starredcourses/version.php +++ b/blocks/starredcourses/version.php @@ -23,6 +23,6 @@ */ defined('MOODLE_INTERNAL') || die; -$plugin->version = 2019052000; +$plugin->version = 2019052001; $plugin->requires = 2019051100; $plugin->component = 'block_starredcourses'; \ No newline at end of file