From e093e48f470d128ac2a81024cf98b508fe3955eb Mon Sep 17 00:00:00 2001 From: Gareth Barnard <1058419+gjb2048@users.noreply.github.com> Date: Mon, 19 Aug 2024 18:18:45 +0100 Subject: [PATCH] Add site default and course 'sectiontitleingridbox' and 'sectionbadgeingridbox' settings, to show the section title and section badges inside the grid box respectively. Both 'Yes' by default. --- Changes.md | 2 ++ classes/output/courseformat/content.php | 6 ++++ lang/en/format_grid.php | 10 +++++++ lib.php | 40 +++++++++++++++++++++++++ settings.php | 22 ++++++++++++++ styles.css | 27 +++++++++++++++-- templates/grid.mustache | 30 +++++++++++++++---- 7 files changed, 130 insertions(+), 7 deletions(-) diff --git a/Changes.md b/Changes.md index 1a5e455f..7b313d91 100644 --- a/Changes.md +++ b/Changes.md @@ -5,6 +5,8 @@ Version 403.1.5 - In development -------------------------------- 1. Fix 'Orphaned sections problem when adding sections', a regression caused by 'Use section anchors in links when editing - pt 2' - #223. +2. Add site default and course 'sectiontitleingridbox' and 'sectionbadgeingridbox' settings, to show + the section title and section badges inside the grid box respectively. Both 'Yes' by default. Version 403.1.4.5 - 28/09/2024 ------------------------------ diff --git a/classes/output/courseformat/content.php b/classes/output/courseformat/content.php index 0ff1cfbb..730be38d 100644 --- a/classes/output/courseformat/content.php +++ b/classes/output/courseformat/content.php @@ -158,6 +158,12 @@ public function export_for_template(\renderer_base $output) { // Image resize is crop. $data->imageresizemethodcrop = ($coursesettings['imageresizemethod'] == 2); + // Section title in grid box. + $data->sectiontitleingridbox = ($coursesettings['sectiontitleingridbox'] == 2); + + // Section badge in grid box. + $data->sectionbadgeingridbox = ($coursesettings['sectionbadgeingridbox'] == 2); + // Popup. if (!$editing) { $data->popup = false; diff --git a/lang/en/format_grid.php b/lang/en/format_grid.php index e060ff0f..4f60bcd6 100644 --- a/lang/en/format_grid.php +++ b/lang/en/format_grid.php @@ -127,6 +127,16 @@ $string['defaultpopup'] = 'Use a popup'; $string['defaultpopup_desc'] = 'Display the section in a popup instead of navigating to a single section page.'; +// Grid section title / badges. +$string['sectiontitleingridbox'] = 'Section title in grid box'; +$string['sectiontitleingridbox_help'] = 'Show the section title in the grid box'; +$string['defaultsectiontitleingridbox'] = 'Section title in grid box'; +$string['defaultsectiontitleingridbox_desc'] = 'Show the section title in the grid box.'; +$string['sectionbadgeingridbox'] = 'Section badge in grid box'; +$string['sectionbadgeingridbox_help'] = 'Show the section badge in the grid box'; +$string['defaultsectionbadgeingridbox'] = 'Section badge in grid box'; +$string['defaultsectionbadgeingridbox_desc'] = 'Show the section badge in the grid box.'; + // Completion. $string['showcompletion'] = 'Show completion'; $string['showcompletion_help'] = 'Show the completion of the section on the grid'; diff --git a/lib.php b/lib.php index d351bd19..474b13b7 100755 --- a/lib.php +++ b/lib.php @@ -419,6 +419,14 @@ public function course_format_options($foreditform = false) { 'default' => 0, 'type' => PARAM_INT, ], + 'sectiontitleingridbox' => [ + 'default' => 0, + 'type' => PARAM_INT, + ], + 'sectionbadgeingridbox' => [ + 'default' => 0, + 'type' => PARAM_INT, + ], 'showcompletion' => [ 'default' => 0, 'type' => PARAM_INT, @@ -533,6 +541,38 @@ public function course_format_options($foreditform = false) { 'element_attributes' => [$imageresizemethodvalues], ]; + $sectiontitleingridboxvalues = $this->generate_default_entry( + 'sectiontitleingridbox', + 0, + [ + 1 => new lang_string('no'), + 2 => new lang_string('yes'), + ], + ); + $courseformatoptionsedit['sectiontitleingridbox'] = [ + 'label' => new lang_string('sectiontitleingridbox', 'format_grid'), + 'help' => 'sectiontitleingridbox', + 'help_component' => 'format_grid', + 'element_type' => 'select', + 'element_attributes' => [$sectiontitleingridboxvalues], + ]; + + $sectionbadgeingridboxvalues = $this->generate_default_entry( + 'sectionbadgeingridbox', + 0, + [ + 1 => new lang_string('no'), + 2 => new lang_string('yes'), + ], + ); + $courseformatoptionsedit['sectionbadgeingridbox'] = [ + 'label' => new lang_string('sectionbadgeingridbox', 'format_grid'), + 'help' => 'sectionbadgeingridbox', + 'help_component' => 'format_grid', + 'element_type' => 'select', + 'element_attributes' => [$sectionbadgeingridboxvalues], + ]; + $showcompletionvalues = $this->generate_default_entry( 'showcompletion', 0, diff --git a/settings.php b/settings.php index 381829e4..53b467d3 100644 --- a/settings.php +++ b/settings.php @@ -147,6 +147,28 @@ $setting->set_updatedcallback('format_grid::update_displayed_images_callback'); $page->add($setting); + // Section title in grid box. + $name = 'format_grid/defaultsectiontitleingridbox'; + $title = get_string('defaultsectiontitleingridbox', 'format_grid'); + $description = get_string('defaultsectiontitleingridbox_desc', 'format_grid'); + $default = 2; + $choices = [ + 1 => new lang_string('no'), + 2 => new lang_string('yes'), + ]; + $page->add(new admin_setting_configselect($name, $title, $description, $default, $choices)); + + // Section badge in grid box. + $name = 'format_grid/defaultsectionbadgeingridbox'; + $title = get_string('defaultsectionbadgeingridbox', 'format_grid'); + $description = get_string('defaultsectionbadgeingridbox_desc', 'format_grid'); + $default = 2; + $choices = [ + 1 => new lang_string('no'), + 2 => new lang_string('yes'), + ]; + $page->add(new admin_setting_configselect($name, $title, $description, $default, $choices)); + // Completion. $name = 'format_grid/defaultshowcompletion'; $title = get_string('defaultshowcompletion', 'format_grid'); diff --git a/styles.css b/styles.css index 52dac12a..b7112c1e 100644 --- a/styles.css +++ b/styles.css @@ -65,10 +65,18 @@ width: 210px; } +.format-grid .thegrid .grid-section.card { + border-width: 2px; +} + .format-grid .thegrid .grid-section.currentgridsection { border: 2px solid var(--primary); } +.format-grid .thegrid .grid-section-inner .card-body { + min-height: 0; +} + .format-grid .thegrid .grid-image-container { height: 140px; } @@ -90,6 +98,21 @@ } /*rtl:end:ignore*/ +.format-grid .thegrid .grid-image .grid-badge-middle { + bottom: 0; + left: 0; + position: absolute; + right: 0; + top: 0; +} + +.format-grid .thegrid .grid-image .grid-badge-bottom { + bottom: 1.5rem; + left: 0; + position: absolute; + right: 0; +} + .format-grid .thegrid .grid-generatedimage { background-size: contain; height: 100%; @@ -117,14 +140,14 @@ border-radius: 45px; border-style: solid; border-width: 3px; - bottom: 8%; + bottom: 1rem; display: flex; flex-direction: column; height: 42px; justify-content: center; padding: 4px; position: absolute; - right: 8%; + right: 0.5rem; width: 42px; } diff --git a/templates/grid.mustache b/templates/grid.mustache index f7986552..e7313b52 100644 --- a/templates/grid.mustache +++ b/templates/grid.mustache @@ -27,6 +27,8 @@ * sectionbreakheading - Section break heading. * number - Section number. * imageresizemethodcrop - Image resize method is crop. + * sectiontitleingridbox - Show the section title? + * sectionbadgeingridbox - Show the section bagde if any? * iscurrent - Current section? * sectionurl - Section URL. * sectionname - Section name. @@ -63,6 +65,8 @@ } ], "imageresizemethodcrop": true, + "sectiontitleingridbox": true, + "sectionbadgeingridbox": true, "showcompletion": true } }} @@ -84,26 +88,42 @@
{{/popup}}
+ {{#sectiontitleingridbox}}

{{{sectionname}}}

- {{#hasbadge}} + {{#sectionbadgeingridbox}}{{#hasbadge}}
{{$ core_courseformat/local/content/section/badges }} {{> core_courseformat/local/content/section/badges }} {{/ core_courseformat/local/content/section/badges }}
- {{/hasbadge}} + {{/hasbadge}}{{/sectionbadgeingridbox}}
+ {{/sectiontitleingridbox}}
{{#imageuri}}
- + + {{^sectiontitleingridbox}}{{#sectionbadgeingridbox}}{{#hasbadge}} +
+ {{$ core_courseformat/local/content/section/badges }} + {{> core_courseformat/local/content/section/badges }} + {{/ core_courseformat/local/content/section/badges }} +
+ {{/hasbadge}}{{/sectionbadgeingridbox}}{{/sectiontitleingridbox}} {{#sectioncompletionmarkup}}{{{sectioncompletionmarkup}}}{{/sectioncompletionmarkup}}
{{/imageuri}} {{#generatedimageuri}} -
+
+ {{^sectiontitleingridbox}}{{#sectionbadgeingridbox}}{{#hasbadge}} +
+ {{$ core_courseformat/local/content/section/badges }} + {{> core_courseformat/local/content/section/badges }} + {{/ core_courseformat/local/content/section/badges }} +
+ {{/hasbadge}}{{/sectionbadgeingridbox}}{{/sectiontitleingridbox}} {{#sectioncompletionmarkup}}{{{sectioncompletionmarkup}}}{{/sectioncompletionmarkup}}
{{/generatedimageuri}} @@ -112,7 +132,7 @@

{{imageerror}}

{{#sectioncompletionmarkup}}{{{sectioncompletionmarkup}}}{{/sectioncompletionmarkup}}
- {{/imageerror}} + {{/imageerror}}
{{^popup}} {{#notavailable}}
{{/notavailable}}