Skip to content

Commit 4c09172

Browse files
committed
Add filter queries feature
Remove unnecessary comma Language string
1 parent 2dda6be commit 4c09172

File tree

7 files changed

+113
-3
lines changed

7 files changed

+113
-3
lines changed

amd/build/reportsearch.min.js

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

amd/build/reportsearch.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/reportsearch.js

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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+
* Filter queries by search term.
18+
*
19+
* @module report_customsql/reportsearch
20+
* @copyright 2025 Southampton Solent University {@link https://www.solent.ac.uk}
21+
* @author Mark Sharp <[email protected]>
22+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23+
*/
24+
import {updateExpandCollapseAll} from 'report_customsql/reportcategories';
25+
26+
export const init = () => {
27+
const searchBox = document.querySelector('#csl_search');
28+
if (!searchBox) {
29+
return;
30+
}
31+
searchBox.addEventListener('keyup', doSearch);
32+
const clearbutton = document.querySelector('#csl_clearsearch');
33+
if (clearbutton) {
34+
clearbutton.addEventListener('click', () => {
35+
searchBox.value = '';
36+
doSearch({currentTarget: searchBox});
37+
});
38+
}
39+
};
40+
41+
const doSearch = (e) => {
42+
const searchBox = e.currentTarget;
43+
const searchTerm = searchBox.value.toLowerCase();
44+
const queries = document.querySelectorAll('.csql_query');
45+
queries.forEach(query => {
46+
const title = query.querySelector('.csql_displayname').textContent.toLowerCase();
47+
if (title.includes(searchTerm)) {
48+
query.style.display = '';
49+
} else {
50+
query.style.display = 'none';
51+
}
52+
});
53+
document.querySelectorAll('.csql_category').forEach(cat => {
54+
const hasVisibleQueries = Array.from(cat.querySelectorAll('.csql_query')).some(q => q.style.display !== 'none');
55+
if (hasVisibleQueries) {
56+
cat.classList.remove('csql_categoryhidden');
57+
cat.classList.add('csql_categoryshown');
58+
} else {
59+
cat.classList.remove('csql_categoryshown');
60+
cat.classList.add('csql_categoryhidden');
61+
}
62+
});
63+
// Update the expand/collapse all button state.
64+
updateExpandCollapseAll();
65+
};
66+

lang/en/report_customsql.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@
176176
$string['runquery'] = 'Run query';
177177
$string['schedulednote'] = 'These queries are automatically run on the first day of each week or month, to report on the previous week or month. These links let you view the results that has already been accumulated.';
178178
$string['scheduledqueries'] = 'Scheduled queries';
179+
$string['searchqueries'] = 'Search queries...';
179180
$string['showonlythiscategory'] = 'Show only {$a}';
180181
$string['startofweek'] = 'Day to run weekly reports';
181182
$string['startofweek_default'] = 'Use site calendar start of week ({$a})';

templates/category_query.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@
4949
}
5050
}}
5151

52-
<p>
53-
<a href="{{url}}">{{{displayname}}}</a> {{{timenote}}}
52+
<p class="csql_query">
53+
<a href="{{url}}" class="csql_displayname">{{{displayname}}}</a> {{{timenote}}}
5454
{{#canedit}}
5555
<span class="admin_note">{{#str}}availableto, report_customsql, {{capability}} {{/str}}</span>
5656
{{#editbutton}}

templates/index_page.mustache

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"categories": []
3636
}
3737
}}
38+
{{>report_customsql/search_queries}}
3839
{{#expandable}}
3940
{{>report_customsql/expand_collapse_link}}
4041
{{/expandable}}
@@ -51,7 +52,7 @@
5152
{{{managecategorybutton}}}
5253

5354
{{#js}}
54-
require(['report_customsql/reportcategories'], function(reportcategories) {
55+
require(['report_customsql/reportcategories', 'report_customsql/reportsearch'], function(reportcategories, reportsearch) {
5556
reportcategories.init();
5657
});
5758
{{/js}}

templates/search_queries.mustache

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{{!
2+
This file is part of Moodle - http://moodle.org/
3+
4+
Moodle is free software: you can redistribute it and/or modify
5+
it under the terms of the GNU General Public License as published by
6+
the Free Software Foundation, either version 3 of the License, or
7+
(at your option) any later version.
8+
9+
Moodle is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
GNU General Public License for more details.
13+
14+
You should have received a copy of the GNU General Public License
15+
along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16+
}}
17+
{{!
18+
@template report_customsql/search_queries
19+
20+
Adds search form to filter queries
21+
22+
Example context (json):
23+
{
24+
}
25+
}}
26+
<div class="input-group mb-3">
27+
<input type="text" id="csl_search" class="form-control" placeholder="{{#str}} searchqueries, report_customsql {{/str}}">
28+
<span class="input-group-append">
29+
<button class="btn btn-secondary border-left-0 border" type="button" id="csl_clearsearch">
30+
<i class="fa fa-times"></i>
31+
</button>
32+
</span>
33+
</div>
34+
{{#js}}
35+
require(['report_customsql/reportsearch'], function(reportsearch) {
36+
reportsearch.init();
37+
});
38+
{{/js}}

0 commit comments

Comments
 (0)