Skip to content

Commit

Permalink
Grid section title / badges - work in progress.
Browse files Browse the repository at this point in the history
  • Loading branch information
gjb2048 committed Sep 7, 2024
1 parent 71422b2 commit 923cdd0
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 8 deletions.
6 changes: 6 additions & 0 deletions classes/output/courseformat/content.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,12 @@ public function export_for_template(\renderer_base $output) {
// Justification.
$data->gridjustification = $coursesettings['gridjustification'];

// 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;
Expand Down
10 changes: 10 additions & 0 deletions lang/en/format_grid.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,16 @@
$string['defaultsectionzeroingrid'] = 'Section zero in grid';
$string['defaultsectionzeroingrid_desc'] = 'Place section zero in the grid.';

// 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';
Expand Down
40 changes: 40 additions & 0 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,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,
Expand Down Expand Up @@ -554,6 +562,38 @@ public function course_format_options($foreditform = false) {
'element_attributes' => [$sectionzeroingridvalues],
];

$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,
Expand Down
22 changes: 22 additions & 0 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,28 @@
];
$page->add(new admin_setting_configselect($name, $title, $description, $default, $choices));

// 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');
Expand Down
26 changes: 24 additions & 2 deletions styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,40 @@
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;
min-height: 140px;
}

.format-grid .thegrid .grid-image {
position: relative;
}

.format-grid .thegrid .grid-image .grid-badge-middle {
left: 0;
position: absolute;
right: 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%;
Expand Down Expand Up @@ -104,14 +126,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;
}

Expand Down
1 change: 1 addition & 0 deletions templates/coursestyles.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
/* -- Grid -- */
.format-grid .thegrid .grid-image-container {
height: {{height}}px;
min-height: {{height}}px;
}
.format-grid .thegrid .grid-section {
Expand Down
32 changes: 26 additions & 6 deletions templates/grid.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
* sectionbreak - There is a section break for this section.
* sectionbreakheading - Section break heading.
* number - Section number.
* sectiontitleingridbox - Show the section title?
* sectionbadgeingridbox - Show the section bagde if any?
* iscurrent - Current section?
* sectionurl - Section URL.
* sectionname - Section name.
Expand Down Expand Up @@ -61,6 +63,8 @@
"sectioncompletionmarkup": ""
}
],
"sectiontitleingridbox": true,
"sectionbadgeingridbox": true,
"showcompletion": true
}
}}
Expand All @@ -82,35 +86,51 @@
<div class="grid-modal grid-section-inner d-flex flex-column h-100" data-toggle="modal" data-target="#gridPopup" data-section="{{number}}" tabindex="0">
{{/popup}}
<div class="card-body p-0">
{{#sectiontitleingridbox}}
<div class="card-header h-100">
<h3 class="h4 text-truncate">{{{sectionname}}}</h3>
{{#hasbadge}}
{{#sectionbadgeingridbox}}{{#hasbadge}}
<div data-region="sectionbadges" class="sectionbadges d-flex">
{{$ core_courseformat/local/content/section/badges }}
{{> core_courseformat/local/content/section/badges }}
{{/ core_courseformat/local/content/section/badges }}
</div>
{{/hasbadge}}
{{/hasbadge}}{{/sectionbadgeingridbox}}
</div>
{{/sectiontitleingridbox}}
</div>
<div class="grid-image-container">
{{#imageuri}}
<div class="grid-image text-center">
<img class="card-img-bottom" src="{{imageuri}}" alt="{{imagealttext}}" loading="lazy">
<img class="card-img-bottom{{^sectiontitleingridbox}} card-img-top{{/sectiontitleingridbox}}" src="{{imageuri}}" alt="{{imagealttext}}" loading="lazy">
{{^sectiontitleingridbox}}{{#sectionbadgeingridbox}}{{#hasbadge}}
<div data-region="sectionbadges" class="sectionbadges d-flex {{^sectioncompletionmarkup}}justify-content-center{{/sectioncompletionmarkup}}{{#sectioncompletionmarkup}}ml-2{{/sectioncompletionmarkup}} align-items-end grid-badge-bottom">
{{$ core_courseformat/local/content/section/badges }}
{{> core_courseformat/local/content/section/badges }}
{{/ core_courseformat/local/content/section/badges }}
</div>
{{/hasbadge}}{{/sectionbadgeingridbox}}{{/sectiontitleingridbox}}
{{#sectioncompletionmarkup}}{{{sectioncompletionmarkup}}}{{/sectioncompletionmarkup}}
</div>
{{/imageuri}}
{{#generatedimageuri}}
<div class="grid-generatedimage card-img-bottom text-center" style="background-image: url('{{generatedimageuri}}');">
<div class="grid-generatedimage card-img-bottom{{^sectiontitleingridbox}} card-img-top{{/sectiontitleingridbox}} text-center" style="background-image: url('{{generatedimageuri}}');">
{{^sectiontitleingridbox}}{{#sectionbadgeingridbox}}{{#hasbadge}}
<div data-region="sectionbadges" class="sectionbadges d-flex justify-content-center align-items-center h-100">
{{$ core_courseformat/local/content/section/badges }}
{{> core_courseformat/local/content/section/badges }}
{{/ core_courseformat/local/content/section/badges }}
</div>
{{/hasbadge}}{{/sectionbadgeingridbox}}{{/sectiontitleingridbox}}
{{#sectioncompletionmarkup}}{{{sectioncompletionmarkup}}}{{/sectioncompletionmarkup}}
</div>
{{/generatedimageuri}}
{{#imageerror}}
<div class="grid-image-error card-img-bottom text-center">
<div class="grid-image-error card-img-bottom{{^sectiontitleingridbox}} card-img-top{{/sectiontitleingridbox}} text-center">
<p><small>{{imageerror}}</small></p>
{{#sectioncompletionmarkup}}{{{sectioncompletionmarkup}}}{{/sectioncompletionmarkup}}
</div>
{{/imageerror}}
{{/imageerror}}
</div>
{{^popup}}
{{#notavailable}}</div>{{/notavailable}}
Expand Down

0 comments on commit 923cdd0

Please sign in to comment.