From 028ec17c94dbdae505c395327e5b317b93c5c466 Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Fri, 3 Apr 2020 20:41:43 +0800 Subject: [PATCH] MDL-68169 user: Add keyword filter Part of MDL-67743 --- lang/en/user.php | 4 +- .../local/participantsfilter/filter.min.js | Bin 3028 -> 3184 bytes .../participantsfilter/filter.min.js.map | Bin 7708 -> 8212 bytes .../filtertypes/keyword.min.js | Bin 0 -> 2300 bytes .../filtertypes/keyword.min.js.map | Bin 0 -> 2148 bytes .../src/local/participantsfilter/filter.js | 22 ++++++- .../participantsfilter/filtertypes/keyword.js | 58 ++++++++++++++++++ user/classes/output/participants_filter.php | 26 +++++++- 8 files changed, 105 insertions(+), 5 deletions(-) create mode 100644 user/amd/build/local/participantsfilter/filtertypes/keyword.min.js create mode 100644 user/amd/build/local/participantsfilter/filtertypes/keyword.min.js.map create mode 100644 user/amd/src/local/participantsfilter/filtertypes/keyword.js diff --git a/lang/en/user.php b/lang/en/user.php index 0c768b1c8cd..1f832af9194 100644 --- a/lang/en/user.php +++ b/lang/en/user.php @@ -28,6 +28,8 @@ $string['clearfilterrow'] = 'Remove filter row'; $string['clearfilters'] = 'Clear filters'; $string['countparticipantsfound'] = '{$a} participants found'; $string['match'] = 'Match'; +$string['placeholdertypeorselect'] = 'Type or select...'; +$string['placeholdertype'] = 'Type...'; $string['privacy:courserequestpath'] = 'Requested courses'; $string['privacy:descriptionpath'] = 'Profile description'; $string['privacy:devicespath'] = 'User devices'; @@ -131,8 +133,8 @@ $string['privacy:passwordresetpath'] = 'Password resets'; $string['privacy:profileimagespath'] = 'Profile images'; $string['privacy:privatefilespath'] = 'Private files'; $string['privacy:sessionpath'] = 'Session data'; +$string['filterbykeyword'] = 'Keyword'; $string['selectfiltertype'] = 'Select'; $string['target:upcomingactivitiesdue'] = 'Upcoming activities due'; $string['target:upcomingactivitiesdue_help'] = 'This target generates reminders for upcoming activities due.'; $string['target:upcomingactivitiesdueinfo'] = 'All upcoming activities due insights are listed here. These students have received these insights directly.'; -$string['typeorselect'] = 'Type or select...'; diff --git a/user/amd/build/local/participantsfilter/filter.min.js b/user/amd/build/local/participantsfilter/filter.min.js index 740ef173f772d4f9841b25ee10af8577070cf650..3ef1d57004cfb809258876640b670d54aadcd384 100644 GIT binary patch delta 247 zcmca2{y}2H9u~%w$$MEA0m%ebeclx7M7V*YCwdUrgd^+ajJr$@n${ttBl;p798Y~_R}!XNzqGBEr~BKDay=C*VIr# zQc+S_keXjqoSKuGT%x3-l$>9b8edwRTBM{|TdPx@omy$7gzC1*2e@RI6b&~2;<&{G E0LAB5v;Y7A delta 144 zcmew$aYcN?9u~&b$$MEA0m%ebecn{-M7PE*j*R*>rKNGq;sj3s@6imsb+cV)Aa%*+}> zDE$y4c+k5Zg}sOuKZ95O5Q3k;nN7h()IBUS|L6BS^Mjdpw_o4=xNkH^q2m&th6BQu z;WGE>9Q*y z{E%z zD9X1qwym&Fg|+h-Beomp2oID4>cYU%$16E>sKK#PMTlWdr~ux;s5?&iP#fXtJ?4D2Ndevj`|=-rF)WsF;ojWt@b>6($6xOBs0@ z=Q&}fyw+&0ANfT1gz2-jAK<^=5C|fmYQTvFb?I;v5<%oyy{;#t delta 325 zcmbQ@Fvn(tALHgcMqVaH-^sPi`}H%O934Y-k{unxbetU>4V-ks9UTpwbewf6og5?m zKw{2bATkup^q!o~63ZAl`6!DXW7gz2HgU$#$vmuXydgS?j*e*{C1y^cljB+S7^^1t zv1-cz%?ovO^Z`kvJ7qb6RAm4ScXYG>D!a<6D_-pESmKlp5^_$`@pW|c2NB-JP@~J( zlz|4#VspoD&|fxtM&rr0?CShRV8b)Pq`Rrp+; z3nrbjH=knn=G?qdXcrTAdTL2*%B#%a@Oeo~^8>399O)V5;;LtB9)M+Z5%PPTfFD{DVGkQ25m{IFBcKyST3z-DK zs5h3h<*oEaFOZ5*PTbxDCA<@uX5451vEdMze5Drg;w~+7{wvFr(0gC!{Nu*}7<=STd6@~_8~{b8M6rCiTvnf870R#V zz8Th6cYU9Fnqa9>Ny_YGrSFYl@&8y>WzN z-k#e(fVneiGjAT?q|o~;r2jTb61Jz0i$jLA9f{He3Ulf?s4}9z`m`8FflRHwP2&4e zO8YBnZzn=d9?^o{m&;A7(C5hZ5VH%kHO10b9mq-YfzQuZ=Mw|6!Ko<*9>NG3`v)U1 zKoXdch8^7=d_1-=(6+cAgm5H7_EX9TUZBsTbuh~;J^dF>R@ZguV0cuNi`uAC*mtZG z7!?_~+l5nH?@59ecHxW}F97|8BAfuDcUPO!L$lut7w!Y^U6yK_Nu5^G1(m5vn&1ni z1G==ig;j+<{f?`pb$R=nZ~c|DjGQ;N8j&%Hw31e{7-67iCzoHOu1P9sokw%5HY~wZNk?tq$7Uru=`)41Z^Zo zB>xasx|94ax|g(-I(M)k7QEj&*;q`#x(H`q1_tlIR;+kHh*zK`0o&@fUy1%X$Q+c3=u2BsJSCZ< z2$xE0m?G33i&`hq6Qu<1dgIIf?HI((1n$IeC~n4+4HjiUH1hQi|mdj;(X6i^h;sDp*r=JK7SvfqsH*g4_n-*sZQ=#Yxn*9^vSxp?~Pi7r{ zrTn}9H8rC7lS*da zoxpmA;VbtdWu5wmR-?Fh+URg(DV?**y}`$5HOE5MIzXnS_kfQyG;+W7wI&2Hvxd~_ zELgYSc;%^@Y^p&+^#C@KEbZ$Ge%ZU@IzByembOPcCZ=cKGLgDh6cleM>UTv z8a9HuBeJiFk{Qdokqq$;Ck{jHjE8l9`VF%{o*D_tBR^158jF7aU!WT`a;toM_kMT_ z?FAX)fmCUkVQF<7aF+WYmL+vHwa=0Z!7@z<9yI~7k-ZV@7TOjxtOrzE)ttgzY(X-)Kqba2J_>7dy@Qa%miS*Lm{tK8Z!~X=H{sD=- B!*~Dy literal 0 HcmV?d00001 diff --git a/user/amd/src/local/participantsfilter/filter.js b/user/amd/src/local/participantsfilter/filter.js index b3180ad66dd..7895ca0cf42 100644 --- a/user/amd/src/local/participantsfilter/filter.js +++ b/user/amd/src/local/participantsfilter/filter.js @@ -59,6 +59,24 @@ export default class { // eslint-disable-line no-empty-function } + /** + * Get the placeholder to use when showing the value selector. + * + * @return {Promise} Resolving to a String + */ + get placeholder() { + return getString('placeholdertypeorselect', 'core_user'); + } + + /** + * Whether to show suggestions in the autocomplete. + * + * @return {Boolean} + */ + get showSuggestions() { + return true; + } + /** * Add the value selector to the filter row. */ @@ -81,13 +99,13 @@ export default class { null, // The string to use as a placeholder. - await getString('typeorselect', 'core_user'), + await this.placeholder, // Disable case sensitivity on searches. false, // Show suggestions. - true, + this.showSuggestions, // Do not override the 'no suggestions' string. null, diff --git a/user/amd/src/local/participantsfilter/filtertypes/keyword.js b/user/amd/src/local/participantsfilter/filtertypes/keyword.js new file mode 100644 index 00000000000..c7b7872e7a7 --- /dev/null +++ b/user/amd/src/local/participantsfilter/filtertypes/keyword.js @@ -0,0 +1,58 @@ +// This file is part of Moodle - http://moodle.org/ +// +// Moodle is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Moodle is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Moodle. If not, see . + +/** + * Keyword filter. + * + * @module core_user/local/participantsfilter/filtertypes/keyword + * @package core_user + * @copyright 2020 Andrew Nicols + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +import Filter from '../filter'; +import {get_string as getString} from 'core/str'; + +export default class extends Filter { + constructor(filterType, filterSet) { + super(filterType, filterSet); + } + + /** + * For keywords the final value is an Array of strings. + * + * @returns {Object} + */ + get values() { + return this.rawValues; + } + + /** + * Get the placeholder to use when showing the value selector. + * + * @return {Promise} Resolving to a String + */ + get placeholder() { + return getString('placeholdertype', 'core_user'); + } + + /** + * Whether to show suggestions in the autocomplete. + * + * @return {Boolean} + */ + get showSuggestions() { + return false; + } +} diff --git a/user/classes/output/participants_filter.php b/user/classes/output/participants_filter.php index c88ec045996..c98fccb472d 100644 --- a/user/classes/output/participants_filter.php +++ b/user/classes/output/participants_filter.php @@ -67,6 +67,8 @@ class participants_filter implements renderable, templatable { protected function get_filtertypes(): array { $filtertypes = []; + $filtertypes[] = $this->get_keyword_filter(); + if ($filtertype = $this->get_enrolmentstatus_filter()) { $filtertypes[] = $filtertype; } @@ -319,6 +321,23 @@ class participants_filter implements renderable, templatable { ); } + /** + * Get data for the keywords filter. + * + * @return stdClass|null + */ + protected function get_keyword_filter(): ?stdClass { + return $this->get_filter_object( + 'keywords', + get_string('filterbykeyword', 'core_user'), + true, + true, + 'core_user/local/participantsfilter/filtertypes/keyword', + [], + true + ); + } + /** * Export the renderer data in a mustache template friendly format. * @@ -344,6 +363,7 @@ class participants_filter implements renderable, templatable { * @param bool $multiple * @param string|null $filterclass * @param array $values + * @param bool $allowempty * @return stdClass|null */ protected function get_filter_object( @@ -352,9 +372,11 @@ class participants_filter implements renderable, templatable { bool $custom, bool $multiple, ?string $filterclass, - array $values + array $values, + bool $allowempty = false ): ?stdClass { - if (empty($values)) { + + if (!$allowempty && empty($values)) { // Do not show empty filters. return null; } -- 2.43.0