From 938ee637332eef121e73c54436bcb0832e84ce11 Mon Sep 17 00:00:00 2001 From: Alexander Bias Date: Sun, 15 Sep 2024 16:36:39 +0200 Subject: [PATCH] Add Usage note as Snippet header to be shown in the details popup --- amd/build/snippetsdetailsmodal.min.js | 2 +- amd/build/snippetsdetailsmodal.min.js.map | 2 +- amd/src/snippetsdetailsmodal.js | 1 + classes/snippets.php | 4 +++- classes/table/snippets_overview.php | 1 + lang/en/theme_boost_union.php | 1 + snippets/builtin/international_day_against_homophobia.scss | 3 ++- templates/snippetsdetailsmodal.mustache | 6 ++++++ 8 files changed, 16 insertions(+), 4 deletions(-) diff --git a/amd/build/snippetsdetailsmodal.min.js b/amd/build/snippetsdetailsmodal.min.js index 8113a5bd01e..b5fe69e4299 100644 --- a/amd/build/snippetsdetailsmodal.min.js +++ b/amd/build/snippetsdetailsmodal.min.js @@ -6,6 +6,6 @@ define("theme_boost_union/snippetsdetailsmodal",["exports","core/modal_cancel"," * @copyright 2024 Alexander Bias, lern.link GmbH * based on core_admin/themeselector/preview_modal by David Woloszyn * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=void 0,_modal_cancel=_interopRequireDefault(_modal_cancel),_notification=_interopRequireDefault(_notification),_templates=_interopRequireDefault(_templates);const SELECTORS_DETAILS='[data-action="details"]';_exports.init=()=>{registerListenerEvents()};const registerListenerEvents=()=>{document.addEventListener("click",(e=>{const details=e.target.closest(SELECTORS_DETAILS);details&&buildModal(details).catch(_notification.default.exception)}))},buildModal=async element=>{const data={title:element.getAttribute("data-title"),description:element.getAttribute("data-description"),image:element.getAttribute("data-image"),source:element.getAttribute("data-source"),goal:element.getAttribute("data-goal"),scope:element.getAttribute("data-scope"),creator:element.getAttribute("data-creator")};await _modal_cancel.default.create({title:data.title,body:_templates.default.render("theme_boost_union/snippetsdetailsmodal",data),large:!0,buttons:{cancel:(0,_str.getString)("closebuttontitle","moodle")},show:!0})}})); + */Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=void 0,_modal_cancel=_interopRequireDefault(_modal_cancel),_notification=_interopRequireDefault(_notification),_templates=_interopRequireDefault(_templates);const SELECTORS_DETAILS='[data-action="details"]';_exports.init=()=>{registerListenerEvents()};const registerListenerEvents=()=>{document.addEventListener("click",(e=>{const details=e.target.closest(SELECTORS_DETAILS);details&&buildModal(details).catch(_notification.default.exception)}))},buildModal=async element=>{const data={title:element.getAttribute("data-title"),description:element.getAttribute("data-description"),image:element.getAttribute("data-image"),source:element.getAttribute("data-source"),goal:element.getAttribute("data-goal"),scope:element.getAttribute("data-scope"),creator:element.getAttribute("data-creator"),usagenote:element.getAttribute("data-usagenote")};await _modal_cancel.default.create({title:data.title,body:_templates.default.render("theme_boost_union/snippetsdetailsmodal",data),large:!0,buttons:{cancel:(0,_str.getString)("closebuttontitle","moodle")},show:!0})}})); //# sourceMappingURL=snippetsdetailsmodal.min.js.map \ No newline at end of file diff --git a/amd/build/snippetsdetailsmodal.min.js.map b/amd/build/snippetsdetailsmodal.min.js.map index 9320ce3cb1f..4f30da6201f 100644 --- a/amd/build/snippetsdetailsmodal.min.js.map +++ b/amd/build/snippetsdetailsmodal.min.js.map @@ -1 +1 @@ -{"version":3,"file":"snippetsdetailsmodal.min.js","sources":["../src/snippetsdetailsmodal.js"],"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 * Theme Boost Union - JS code for snippets details modal.\n *\n * @module theme_boost_union/snippetsdetailsmodal\n * @copyright 2024 Alexander Bias, lern.link GmbH \n * based on core_admin/themeselector/preview_modal by David Woloszyn \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport ModalCancel from 'core/modal_cancel';\nimport Notification from 'core/notification';\nimport Templates from 'core/templates';\nimport {getString} from 'core/str';\n\nconst SELECTORS = {\n SNIPPETS_CONTAINER: 'theme_boost_union_snippets',\n DETAILS: '[data-action=\"details\"]',\n};\n\n/**\n * Entrypoint of the js.\n *\n * @method init\n */\nexport const init = () => {\n registerListenerEvents();\n};\n\n/**\n * Register snippet related event listeners.\n *\n * @method registerListenerEvents\n */\nconst registerListenerEvents = () => {\n document.addEventListener('click', (e) => {\n const details = e.target.closest(SELECTORS.DETAILS);\n if (details) {\n buildModal(details).catch(Notification.exception);\n }\n });\n};\n\n/**\n * Build the modal with the provided data.\n *\n * @method buildModal\n * @param {object} element\n */\nconst buildModal = async(element) => {\n\n // Prepare data for modal.\n const data = {\n title: element.getAttribute('data-title'),\n description: element.getAttribute('data-description'),\n image: element.getAttribute('data-image'),\n source: element.getAttribute('data-source'),\n goal: element.getAttribute('data-goal'),\n scope: element.getAttribute('data-scope'),\n creator: element.getAttribute('data-creator'),\n };\n\n await ModalCancel.create({\n title: data.title,\n body: Templates.render('theme_boost_union/snippetsdetailsmodal', data),\n large: true,\n buttons: {\n 'cancel': getString('closebuttontitle', 'moodle'),\n },\n show: true,\n });\n};\n"],"names":["SELECTORS","registerListenerEvents","document","addEventListener","e","details","target","closest","buildModal","catch","Notification","exception","async","data","title","element","getAttribute","description","image","source","goal","scope","creator","ModalCancel","create","body","Templates","render","large","buttons","show"],"mappings":";;;;;;;;8OA6BMA,kBAEO,wCAQO,KAChBC,gCAQEA,uBAAyB,KAC3BC,SAASC,iBAAiB,SAAUC,UAC1BC,QAAUD,EAAEE,OAAOC,QAAQP,mBAC7BK,SACAG,WAAWH,SAASI,MAAMC,sBAAaC,eAW7CH,WAAaI,MAAAA,gBAGTC,KAAO,CACTC,MAAOC,QAAQC,aAAa,cAC5BC,YAAaF,QAAQC,aAAa,oBAClCE,MAAOH,QAAQC,aAAa,cAC5BG,OAAQJ,QAAQC,aAAa,eAC7BI,KAAML,QAAQC,aAAa,aAC3BK,MAAON,QAAQC,aAAa,cAC5BM,QAASP,QAAQC,aAAa,uBAG5BO,sBAAYC,OAAO,CACrBV,MAAOD,KAAKC,MACZW,KAAMC,mBAAUC,OAAO,yCAA0Cd,MACjEe,OAAO,EACPC,QAAS,SACK,kBAAU,mBAAoB,WAE5CC,MAAM"} \ No newline at end of file +{"version":3,"file":"snippetsdetailsmodal.min.js","sources":["../src/snippetsdetailsmodal.js"],"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 * Theme Boost Union - JS code for snippets details modal.\n *\n * @module theme_boost_union/snippetsdetailsmodal\n * @copyright 2024 Alexander Bias, lern.link GmbH \n * based on core_admin/themeselector/preview_modal by David Woloszyn \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport ModalCancel from 'core/modal_cancel';\nimport Notification from 'core/notification';\nimport Templates from 'core/templates';\nimport {getString} from 'core/str';\n\nconst SELECTORS = {\n SNIPPETS_CONTAINER: 'theme_boost_union_snippets',\n DETAILS: '[data-action=\"details\"]',\n};\n\n/**\n * Entrypoint of the js.\n *\n * @method init\n */\nexport const init = () => {\n registerListenerEvents();\n};\n\n/**\n * Register snippet related event listeners.\n *\n * @method registerListenerEvents\n */\nconst registerListenerEvents = () => {\n document.addEventListener('click', (e) => {\n const details = e.target.closest(SELECTORS.DETAILS);\n if (details) {\n buildModal(details).catch(Notification.exception);\n }\n });\n};\n\n/**\n * Build the modal with the provided data.\n *\n * @method buildModal\n * @param {object} element\n */\nconst buildModal = async(element) => {\n\n // Prepare data for modal.\n const data = {\n title: element.getAttribute('data-title'),\n description: element.getAttribute('data-description'),\n image: element.getAttribute('data-image'),\n source: element.getAttribute('data-source'),\n goal: element.getAttribute('data-goal'),\n scope: element.getAttribute('data-scope'),\n creator: element.getAttribute('data-creator'),\n usagenote: element.getAttribute('data-usagenote'),\n };\n\n await ModalCancel.create({\n title: data.title,\n body: Templates.render('theme_boost_union/snippetsdetailsmodal', data),\n large: true,\n buttons: {\n 'cancel': getString('closebuttontitle', 'moodle'),\n },\n show: true,\n });\n};\n"],"names":["SELECTORS","registerListenerEvents","document","addEventListener","e","details","target","closest","buildModal","catch","Notification","exception","async","data","title","element","getAttribute","description","image","source","goal","scope","creator","usagenote","ModalCancel","create","body","Templates","render","large","buttons","show"],"mappings":";;;;;;;;8OA6BMA,kBAEO,wCAQO,KAChBC,gCAQEA,uBAAyB,KAC3BC,SAASC,iBAAiB,SAAUC,UAC1BC,QAAUD,EAAEE,OAAOC,QAAQP,mBAC7BK,SACAG,WAAWH,SAASI,MAAMC,sBAAaC,eAW7CH,WAAaI,MAAAA,gBAGTC,KAAO,CACTC,MAAOC,QAAQC,aAAa,cAC5BC,YAAaF,QAAQC,aAAa,oBAClCE,MAAOH,QAAQC,aAAa,cAC5BG,OAAQJ,QAAQC,aAAa,eAC7BI,KAAML,QAAQC,aAAa,aAC3BK,MAAON,QAAQC,aAAa,cAC5BM,QAASP,QAAQC,aAAa,gBAC9BO,UAAWR,QAAQC,aAAa,yBAG9BQ,sBAAYC,OAAO,CACrBX,MAAOD,KAAKC,MACZY,KAAMC,mBAAUC,OAAO,yCAA0Cf,MACjEgB,OAAO,EACPC,QAAS,SACK,kBAAU,mBAAoB,WAE5CC,MAAM"} \ No newline at end of file diff --git a/amd/src/snippetsdetailsmodal.js b/amd/src/snippetsdetailsmodal.js index 01b8417e6de..48b2a1329c3 100644 --- a/amd/src/snippetsdetailsmodal.js +++ b/amd/src/snippetsdetailsmodal.js @@ -72,6 +72,7 @@ const buildModal = async(element) => { goal: element.getAttribute('data-goal'), scope: element.getAttribute('data-scope'), creator: element.getAttribute('data-creator'), + usagenote: element.getAttribute('data-usagenote'), }; await ModalCancel.create({ diff --git a/classes/snippets.php b/classes/snippets.php index ea64f414462..3842ce90440 100644 --- a/classes/snippets.php +++ b/classes/snippets.php @@ -44,7 +44,8 @@ class snippets { 'Goal', 'Description', 'Scope', - 'Creator' + 'Creator', + 'Usage note', ]; /** @@ -219,6 +220,7 @@ public static function get_snippet_meta($path, $source): stdClass|null { $snippet->scope = $headers['Scope']; $snippet->goal = $headers['Goal']; $snippet->creator = $headers['Creator']; + $snippet->usagenote = $headers['Usage note']; $snippet->source = $source; $snippet->image = $image; diff --git a/classes/table/snippets_overview.php b/classes/table/snippets_overview.php index 213382006eb..3d924fceb98 100644 --- a/classes/table/snippets_overview.php +++ b/classes/table/snippets_overview.php @@ -241,6 +241,7 @@ public function col_actions($data) { 'data-scope' => $this->pick_and_build_badge('snippetsscope'.$data->scope), 'data-description' => $data->description, 'data-creator' => $data->creator, + 'data-usagenote' => $data->usagenote, 'data-image' => $data->image, ], ]; diff --git a/lang/en/theme_boost_union.php b/lang/en/theme_boost_union.php index a7f9a16ed72..2d75c72dc70 100644 --- a/lang/en/theme_boost_union.php +++ b/lang/en/theme_boost_union.php @@ -1129,6 +1129,7 @@ $string['snippetssource'] = 'Source'; $string['snippetssourcetheme_boost_union'] = 'Boost Union built-in'; $string['snippetstitle'] = 'Title'; +$string['snippetsusagenote'] = 'Usage note'; // Settings: Smart menus page. $string['smartmenus'] = 'Smart menus'; diff --git a/snippets/builtin/international_day_against_homophobia.scss b/snippets/builtin/international_day_against_homophobia.scss index 70072cbc60d..dd051c5d938 100644 --- a/snippets/builtin/international_day_against_homophobia.scss +++ b/snippets/builtin/international_day_against_homophobia.scss @@ -2,7 +2,8 @@ * Snippet Title: Rainbow navbar for anti-homophobia day * Scope: global * Goal: eyecandy - * Description: 17 May is a special day for the queer community - the International Day against Homophobia, Biphobia and Transphobia. This CSS changes the background of the primary navbar to rainbow colors to commemorate and support the special day.
Please note: To make this CSS snippet work, you have to set the 'theme_boost_union | navbarcolor' setting to 'Dark navbar with light font color' as well. + * Description: 17 May is a special day for the queer community - the International Day against Homophobia, Biphobia and Transphobia. This CSS changes the background of the primary navbar to rainbow colors to commemorate and support the special day. + * Usage note: To make this CSS snippet work, you have to set the 'theme_boost_union | navbarcolor' setting to 'Dark navbar with light font color' as well. * Creator: Nils Promer and Alexander Brehm * * @package theme_boost_union diff --git a/templates/snippetsdetailsmodal.mustache b/templates/snippetsdetailsmodal.mustache index 8c98a02a44e..a085956e396 100644 --- a/templates/snippetsdetailsmodal.mustache +++ b/templates/snippetsdetailsmodal.mustache @@ -38,6 +38,12 @@ {{#str}}snippetsdetailspreview, theme_boost_union{{/str}} {{/image}} + {{#usagenote}} +
+
{{#str}}snippetsusagenote, theme_boost_union{{/str}}
+

{{{usagenote}}}

+
+ {{/usagenote}}
{{#str}}snippetsdetails, theme_boost_union{{/str}}