Skip to content

Commit 72b8e53

Browse files
authored
Merge pull request #29 from learnweb/enhance/groupedletters
Group letters by date
2 parents 6c9853b + 2dda6d8 commit 72b8e53

18 files changed

+216
-207
lines changed

amd/build/filtercontroller.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

amd/build/filtercontroller.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

amd/build/lettergroup.min.js

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

amd/build/lettergroup.min.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

amd/src/filtercontroller.js

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,38 @@ export function init() {
4646
let letterfilter = letter.classList.contains('ts_letterfilter_approved');
4747

4848
// If all filters approve the letter, show the letter.
49-
if (coursefilter && timefilter && letterfilter) {
50-
letter.style.display = 'block';
51-
} else {
52-
letter.style.display = 'none';
53-
}
49+
letter.style.display = (coursefilter && timefilter && letterfilter) ? 'block' : 'none';
50+
51+
// Check if the letters group should be visible or not.
52+
updatelettergroup(letter);
5453
}
5554
});
5655
});
5756

5857
observer.observe(letter, {attributes: true});
5958
});
6059
}
60+
61+
/**
62+
* Helper function that checks if a letter group should still be visible. Is used if a filter is applied
63+
* that could change the visibility of one letter and therefore the letters group.
64+
* @param {HTMLElement} letter
65+
*/
66+
function updatelettergroup(letter) {
67+
// Get the letters group.
68+
const group = letter.closest('.ts-lettergroup');
69+
if (!group) {
70+
return;
71+
}
72+
73+
// Check every group letters visibility.
74+
const letters = group.querySelectorAll('.ts-letter-box > *');
75+
const anyVisible = Array.from(letters).some(el =>
76+
el.classList.contains('ts_coursefilter_approved') &&
77+
el.classList.contains('ts_timefilter_approved') &&
78+
el.classList.contains('ts_letterfilter_approved')
79+
);
80+
81+
// Group only gets shown if at least one element is visible.
82+
group.style.display = anyVisible ? 'block' : 'none';
83+
}

amd/src/lettergroup.js

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// This file is part of Moodle - http://moodle.org/
2+
//
3+
// Moodle is free software: you can redistribute it and/or modify
4+
// it under the terms of the GNU General Public License as published by
5+
// the Free Software Foundation, either version 3 of the License, or
6+
// (at your option) any later version.
7+
//
8+
// Moodle is distributed in the hope that it will be useful,
9+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
// GNU General Public License for more details.
12+
//
13+
// You should have received a copy of the GNU General Public License
14+
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
15+
16+
/**
17+
* JavaScript for the letter group.
18+
*
19+
* @module block_townsquare/lettergroup
20+
* @copyright 2025 Tamaro Walter
21+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
22+
*/
23+
24+
const letterboxes = document.getElementsByClassName('ts-letter-box');
25+
26+
const Selectors = {
27+
actions: {
28+
collapsegroup: '[data-action="block_townsquare/collapse_group"]',
29+
},
30+
};
31+
32+
/**
33+
* Init function. Adds event listener to orientation marker of letter group to enable
34+
* collapsing a letter group.
35+
*/
36+
export function init() {
37+
letterboxes.forEach(
38+
(element) => {
39+
element.style.maxHeight = `${element.scrollHeight}px`;
40+
element.setAttribute('expanded', 'true');
41+
}
42+
);
43+
44+
document.addEventListener('click', e => {
45+
const group = e.target.closest(Selectors.actions.collapsegroup);
46+
if (group) {
47+
const icon = group.querySelector('i');
48+
let groupid = group.dataset.groupid;
49+
letterboxes.forEach(
50+
(element) => {
51+
if (element.dataset.groupid === groupid) {
52+
if (element.getAttribute('expanded') === 'true') {
53+
icon.classList.remove('fa-chevron-down');
54+
icon.classList.add('fa-chevron-up');
55+
element.style.maxHeight = '0px';
56+
element.setAttribute('expanded', 'false');
57+
} else {
58+
icon.classList.remove('fa-chevron-up');
59+
icon.classList.add('fa-chevron-down');
60+
element.style.maxHeight = `${element.scrollHeight}px`;
61+
element.setAttribute('expanded', 'true');
62+
}
63+
}
64+
}
65+
);
66+
}
67+
});
68+
}

block_townsquare.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ public function get_content(): stdClass {
5757
$this->page->requires->js_call_amd('block_townsquare/timefilter', 'init');
5858
$this->page->requires->js_call_amd('block_townsquare/letterfilter', 'init');
5959
$this->page->requires->js_call_amd('block_townsquare/filtercontroller', 'init');
60+
$this->page->requires->js_call_amd('block_townsquare/lettergroup', 'init');
6061
$this->page->requires->js_call_amd('block_townsquare/usersettings_save', 'init', [$USER->id, $usersettings]);
6162
$this->page->requires->js_call_amd('block_townsquare/usersettings_reset', 'init', [$USER->id]);
6263
return $this->content;

0 commit comments

Comments
 (0)