mirror of
https://github.com/moodle/moodle.git
synced 2025-04-13 20:42:22 +02:00
Merge branch 'MDL-68286-master' of git://github.com/andrewnicols/moodle
This commit is contained in:
commit
2c50e08a3b
2
lib/table/amd/build/dynamic.min.js
vendored
2
lib/table/amd/build/dynamic.min.js
vendored
@ -1,2 +1,2 @@
|
||||
define ("core_table/dynamic",["exports","core_table/local/dynamic/repository","core_table/local/dynamic/selectors"],function(a,b,c){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.init=a.setSortOrder=a.setFilters=a.updateTable=a.refreshTableContent=void 0;c=function(a){if(a&&a.__esModule){return a}else{var b={};if(null!=a){for(var c in a){if(Object.prototype.hasOwnProperty.call(a,c)){var d=Object.defineProperty&&Object.getOwnPropertyDescriptor?Object.getOwnPropertyDescriptor(a,c):{};if(d.get||d.set){Object.defineProperty(b,c,d)}else{b[c]=a[c]}}}}b.default=a;return b}}(c);function d(a){return g(a)||f(a)||e()}function e(){throw new TypeError("Invalid attempt to spread non-iterable instance")}function f(a){if(Symbol.iterator in Object(a)||"[object Arguments]"===Object.prototype.toString.call(a))return Array.from(a)}function g(a){if(Array.isArray(a)){for(var b=0,c=Array(a.length);b<a.length;b++){c[b]=a[b]}return c}}var h=!1,i=function(a){if(!a){throw new Error("The table specified is not a dynamic table and cannot be updated")}if(!a.matches(c.table.region)){throw new Error("The table specified is not a dynamic table and cannot be updated")}return!0},j=function(a){return JSON.parse(a.dataset.tableFilters)},k=function(a){var c=j(a);return(0,b.fetch)(a.dataset.tableHandler,a.dataset.tableUniqueid,{sortBy:a.dataset.tableSortBy,sortOrder:a.dataset.tableSortOrder,joinType:c.jointype,filters:c.filters}).then(function(b){var c=document.createElement("div");c.innerHTML=b.html;a.replaceWith.apply(a,d(c.childNodes));return b})};a.refreshTableContent=k;var l=function(a){var b=1<arguments.length&&arguments[1]!==void 0?arguments[1]:{},c=b.sortBy,d=void 0===c?null:c,e=b.sortOrder,f=void 0===e?null:e,g=b.filters,h=void 0===g?null:g,j=2<arguments.length&&arguments[2]!==void 0?arguments[2]:!0;i(a);if(d&&f){a.dataset.tableSortBy=d;a.dataset.tableSortOrder=f}if(h){a.dataset.tableFilters=JSON.stringify(h)}if(j){return k(a)}else{return Promise.resolve()}};a.updateTable=l;a.setFilters=function setFilters(a,b){var c=2<arguments.length&&arguments[2]!==void 0?arguments[2]:!0;return l(a,{filters:b},c)};var m=function(a,b,c){var d=3<arguments.length&&arguments[3]!==void 0?arguments[3]:!0;return l(a,{sortBy:b,sortOrder:c},d)};a.setSortOrder=m;var n=function(){if(h){return}h=!0;document.addEventListener("click",function(a){var b=a.target.closest(c.table.region);if(!b){return}var d=a.target.closest(c.table.links.sortableColumn);if(d){a.preventDefault();m(b,d.dataset.sortby,d.dataset.sortorder)}})};a.init=n});
|
||||
define ("core_table/dynamic",["exports","core_table/local/dynamic/repository","core_table/local/dynamic/selectors"],function(a,b,c){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.init=a.setLastInitial=a.setFirstInitial=a.setSortOrder=a.setFilters=a.updateTable=a.refreshTableContent=void 0;c=function(a){if(a&&a.__esModule){return a}else{var b={};if(null!=a){for(var c in a){if(Object.prototype.hasOwnProperty.call(a,c)){var d=Object.defineProperty&&Object.getOwnPropertyDescriptor?Object.getOwnPropertyDescriptor(a,c):{};if(d.get||d.set){Object.defineProperty(b,c,d)}else{b[c]=a[c]}}}}b.default=a;return b}}(c);function d(a){return g(a)||f(a)||e()}function e(){throw new TypeError("Invalid attempt to spread non-iterable instance")}function f(a){if(Symbol.iterator in Object(a)||"[object Arguments]"===Object.prototype.toString.call(a))return Array.from(a)}function g(a){if(Array.isArray(a)){for(var b=0,c=Array(a.length);b<a.length;b++){c[b]=a[b]}return c}}var h=!1,i=function(a){if(!a){throw new Error("The table specified is not a dynamic table and cannot be updated")}if(!a.matches(c.main.region)){throw new Error("The table specified is not a dynamic table and cannot be updated")}return!0},j=function(a){return JSON.parse(a.dataset.tableFilters)},k=function(a){var c=j(a);return(0,b.fetch)(a.dataset.tableHandler,a.dataset.tableUniqueid,{sortBy:a.dataset.tableSortBy,sortOrder:a.dataset.tableSortOrder,joinType:c.jointype,filters:c.filters,firstinitial:a.dataset.tableFirstInitial,lastinitial:a.dataset.tableLastInitial}).then(function(b){var c=document.createElement("div");c.innerHTML=b.html;a.replaceWith.apply(a,d(c.childNodes));return b})};a.refreshTableContent=k;var l=function(a){var b=1<arguments.length&&arguments[1]!==void 0?arguments[1]:{},c=b.sortBy,d=void 0===c?null:c,e=b.sortOrder,f=void 0===e?null:e,g=b.filters,h=void 0===g?null:g,j=b.firstInitial,l=void 0===j?null:j,m=b.lastInitial,n=void 0===m?null:m,o=2<arguments.length&&arguments[2]!==void 0?arguments[2]:!0;i(a);if(d&&f){a.dataset.tableSortBy=d;a.dataset.tableSortOrder=f}if(null!==l){a.dataset.tableFirstInitial=l}if(null!==n){a.dataset.tableLastInitial=n}if(h){a.dataset.tableFilters=JSON.stringify(h)}if(o){return k(a)}else{return Promise.resolve()}};a.updateTable=l;a.setFilters=function setFilters(a,b){var c=2<arguments.length&&arguments[2]!==void 0?arguments[2]:!0;return l(a,{filters:b},c)};var m=function(a,b,c){var d=3<arguments.length&&arguments[3]!==void 0?arguments[3]:!0;return l(a,{sortBy:b,sortOrder:c},d)};a.setSortOrder=m;var n=function(a,b){var c=2<arguments.length&&arguments[2]!==void 0?arguments[2]:!0;return l(a,{firstInitial:b},c)};a.setFirstInitial=n;var o=function(a,b){var c=2<arguments.length&&arguments[2]!==void 0?arguments[2]:!0;return l(a,{lastInitial:b},c)};a.setLastInitial=o;var p=function(){if(h){return}h=!0;document.addEventListener("click",function(a){var b=a.target.closest(c.main.region);if(!b){return}var d=a.target.closest(c.table.links.sortableColumn);if(d){a.preventDefault();m(b,d.dataset.sortby,d.dataset.sortorder)}var e=a.target.closest(c.initialsBar.links.firstInitial);if(null!==e){a.preventDefault();n(b,e.dataset.initial)}var f=a.target.closest(c.initialsBar.links.lastInitial);if(null!==f){a.preventDefault();o(b,f.dataset.initial)}})};a.init=p});
|
||||
//# sourceMappingURL=dynamic.min.js.map
|
||||
|
File diff suppressed because one or more lines are too long
@ -1,2 +1,2 @@
|
||||
define ("core_table/local/dynamic/repository",["exports","core/ajax"],function(a,b){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.fetch=void 0;a.fetch=function fetch(a,c){var d=2<arguments.length&&arguments[2]!==void 0?arguments[2]:{},e=d.sortBy,f=void 0===e?null:e,g=d.sortOrder,h=void 0===g?null:g,i=d.joinType,j=void 0===i?null:i,k=d.filters,l=void 0===k?{}:k;return(0,b.call)([{methodname:"core_table_dynamic_fetch",args:{handler:a,uniqueid:c,sortby:f,sortorder:h,jointype:j,filters:l}}])[0]}});
|
||||
define ("core_table/local/dynamic/repository",["exports","core/ajax"],function(a,b){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.fetch=void 0;a.fetch=function fetch(a,c){var d=2<arguments.length&&arguments[2]!==void 0?arguments[2]:{},e=d.sortBy,f=void 0===e?null:e,g=d.sortOrder,h=void 0===g?null:g,i=d.joinType,j=void 0===i?null:i,k=d.filters,l=void 0===k?{}:k,m=d.firstinitial,n=void 0===m?null:m,o=d.lastinitial,p=void 0===o?null:o;return(0,b.call)([{methodname:"core_table_dynamic_fetch",args:{handler:a,uniqueid:c,sortby:f,sortorder:h,jointype:j,filters:l,firstinitial:n,lastinitial:p}}])[0]}});
|
||||
//# sourceMappingURL=repository.min.js.map
|
||||
|
@ -1 +1 @@
|
||||
{"version":3,"sources":["../../../src/local/dynamic/repository.js"],"names":["fetch","handler","uniqueid","sortBy","sortOrder","joinType","filters","methodname","args","sortby","sortorder","jointype"],"mappings":"yKAmCqB,QAARA,CAAAA,KAAQ,CAACC,CAAD,CAAUC,CAAV,CAMhB,8DADG,EACH,KALGC,MAKH,CALGA,CAKH,YALY,IAKZ,OAJGC,SAIH,CAJGA,CAIH,YAJe,IAIf,OAHGC,QAGH,CAHGA,CAGH,YAHc,IAGd,OAFGC,OAEH,CAFGA,CAEH,YAFa,EAEb,GACD,MAAO,WAAU,CAAC,CACdC,UAAU,2BADI,CAEdC,IAAI,CAAE,CACFP,OAAO,CAAPA,CADE,CAEFC,QAAQ,CAARA,CAFE,CAGFO,MAAM,CAAEN,CAHN,CAIFO,SAAS,CAAEN,CAJT,CAKFO,QAAQ,CAAEN,CALR,CAMFC,OAAO,CAAPA,CANE,CAFQ,CAAD,CAAV,EAUH,CAVG,CAWV,C","sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\n\n/**\n * A javascript module to handle calendar ajax actions.\n *\n * @module core_calendar/repository\n * @class repository\n * @package core_calendar\n * @copyright 2017 Simey Lameze <lameze@moodle.com>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\nimport {call as fetchMany} from 'core/ajax';\n\n/**\n * Fetch table view.\n *\n * @method fetch\n * @param {String} handler The name of the handler\n * @param {String} uniqueid The unique id of the table\n * @param {Number} params parameters to request table\n * @return {Promise} Resolved with requested table view\n */\nexport const fetch = (handler, uniqueid, {\n sortBy = null,\n sortOrder = null,\n joinType = null,\n filters = {}\n } = {}\n) => {\n return fetchMany([{\n methodname: `core_table_dynamic_fetch`,\n args: {\n handler,\n uniqueid,\n sortby: sortBy,\n sortorder: sortOrder,\n jointype: joinType,\n filters,\n },\n }])[0];\n};\n"],"file":"repository.min.js"}
|
||||
{"version":3,"sources":["../../../src/local/dynamic/repository.js"],"names":["fetch","handler","uniqueid","sortBy","sortOrder","joinType","filters","firstinitial","lastinitial","methodname","args","sortby","sortorder","jointype"],"mappings":"yKAsCqB,QAARA,CAAAA,KAAQ,CAACC,CAAD,CAAUC,CAAV,CAQhB,8DADG,EACH,KAPGC,MAOH,CAPGA,CAOH,YAPY,IAOZ,OANGC,SAMH,CANGA,CAMH,YANe,IAMf,OALGC,QAKH,CALGA,CAKH,YALc,IAKd,OAJGC,OAIH,CAJGA,CAIH,YAJa,EAIb,OAHGC,YAGH,CAHGA,CAGH,YAHkB,IAGlB,OAFGC,WAEH,CAFGA,CAEH,YAFiB,IAEjB,GACD,MAAO,WAAU,CAAC,CACdC,UAAU,2BADI,CAEdC,IAAI,CAAE,CACFT,OAAO,CAAPA,CADE,CAEFC,QAAQ,CAARA,CAFE,CAGFS,MAAM,CAAER,CAHN,CAIFS,SAAS,CAAER,CAJT,CAKFS,QAAQ,CAAER,CALR,CAMFC,OAAO,CAAPA,CANE,CAOFC,YAAY,CAAZA,CAPE,CAQFC,WAAW,CAAXA,CARE,CAFQ,CAAD,CAAV,EAYH,CAZG,CAaV,C","sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\n\n/**\n * A javascript module to handle calendar ajax actions.\n *\n * @module core_calendar/repository\n * @class repository\n * @package core_calendar\n * @copyright 2017 Simey Lameze <lameze@moodle.com>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\nimport {call as fetchMany} from 'core/ajax';\n\n/**\n * Fetch table view.\n *\n * @method fetch\n * @param {String} handler The name of the handler\n * @param {String} uniqueid The unique id of the table\n * @param {Object} filters The filters to apply when searching\n * @param {String} firstinitial The first name initial to filter on\n * @param {String} lastinitial The last name initial to filter on\n * @param {Number} params parameters to request table\n * @return {Promise} Resolved with requested table view\n */\nexport const fetch = (handler, uniqueid, {\n sortBy = null,\n sortOrder = null,\n joinType = null,\n filters = {},\n firstinitial = null,\n lastinitial = null,\n } = {}\n) => {\n return fetchMany([{\n methodname: `core_table_dynamic_fetch`,\n args: {\n handler,\n uniqueid,\n sortby: sortBy,\n sortorder: sortOrder,\n jointype: joinType,\n filters,\n firstinitial,\n lastinitial,\n },\n }])[0];\n};\n"],"file":"repository.min.js"}
|
@ -1,2 +1,2 @@
|
||||
define ("core_table/local/dynamic/selectors",["exports"],function(a){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.default=void 0;a.default={table:{region:"[data-region=\"core_table/dynamic\"]",links:{sortableColumn:"a[data-sortable=\"1\"]"}}};return a.default});
|
||||
define ("core_table/local/dynamic/selectors",["exports"],function(a){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.default=void 0;a.default={main:{region:"[data-region=\"core_table/dynamic\"]"},table:{links:{sortableColumn:"a[data-sortable=\"1\"]"}},initialsBar:{links:{firstInitial:".firstinitial [data-initial]",lastInitial:".lastinitial [data-initial]"}}};return a.default});
|
||||
//# sourceMappingURL=selectors.min.js.map
|
||||
|
@ -1 +1 @@
|
||||
{"version":3,"sources":["../../../src/local/dynamic/selectors.js"],"names":["table","region","links","sortableColumn"],"mappings":"8JAuBe,CACXA,KAAK,CAAE,CACHC,MAAM,CAAE,sCADL,CAEHC,KAAK,CAAE,CACHC,cAAc,CAAE,wBADb,CAFJ,CADI,C","sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\n\n/**\n * Dynamic table selectors.\n *\n * @module core_table/selectors\n * @package core_table\n * @copyright 2020 Simey Lameze <simey@moodle.com>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\nexport default {\n table: {\n region: '[data-region=\"core_table/dynamic\"]',\n links: {\n sortableColumn: 'a[data-sortable=\"1\"]',\n },\n },\n};\n"],"file":"selectors.min.js"}
|
||||
{"version":3,"sources":["../../../src/local/dynamic/selectors.js"],"names":["main","region","table","links","sortableColumn","initialsBar","firstInitial","lastInitial"],"mappings":"8JAuBe,CACXA,IAAI,CAAE,CACFC,MAAM,CAAE,sCADN,CADK,CAIXC,KAAK,CAAE,CACHC,KAAK,CAAE,CACHC,cAAc,CAAE,wBADb,CADJ,CAJI,CASXC,WAAW,CAAE,CACTF,KAAK,CAAE,CACHG,YAAY,CAAE,8BADX,CAEHC,WAAW,CAAE,6BAFV,CADE,CATF,C","sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\n\n/**\n * Dynamic table selectors.\n *\n * @module core_table/selectors\n * @package core_table\n * @copyright 2020 Simey Lameze <simey@moodle.com>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\nexport default {\n main: {\n region: '[data-region=\"core_table/dynamic\"]',\n },\n table: {\n links: {\n sortableColumn: 'a[data-sortable=\"1\"]',\n },\n },\n initialsBar: {\n links: {\n firstInitial: '.firstinitial [data-initial]',\n lastInitial: '.lastinitial [data-initial]',\n },\n },\n};\n"],"file":"selectors.min.js"}
|
@ -38,7 +38,7 @@ const checkTableIsDynamic = tableRoot => {
|
||||
throw new Error("The table specified is not a dynamic table and cannot be updated");
|
||||
}
|
||||
|
||||
if (!tableRoot.matches(Selectors.table.region)) {
|
||||
if (!tableRoot.matches(Selectors.main.region)) {
|
||||
// The table is not a dynamic table.
|
||||
throw new Error("The table specified is not a dynamic table and cannot be updated");
|
||||
}
|
||||
@ -73,6 +73,8 @@ export const refreshTableContent = tableRoot => {
|
||||
sortOrder: tableRoot.dataset.tableSortOrder,
|
||||
joinType: filterset.jointype,
|
||||
filters: filterset.filters,
|
||||
firstinitial: tableRoot.dataset.tableFirstInitial,
|
||||
lastinitial: tableRoot.dataset.tableLastInitial,
|
||||
}
|
||||
)
|
||||
.then(data => {
|
||||
@ -88,6 +90,8 @@ export const updateTable = (tableRoot, {
|
||||
sortBy = null,
|
||||
sortOrder = null,
|
||||
filters = null,
|
||||
firstInitial = null,
|
||||
lastInitial = null,
|
||||
} = {}, refreshContent = true) => {
|
||||
checkTableIsDynamic(tableRoot);
|
||||
|
||||
@ -97,6 +101,15 @@ export const updateTable = (tableRoot, {
|
||||
tableRoot.dataset.tableSortOrder = sortOrder;
|
||||
}
|
||||
|
||||
// Update initials.
|
||||
if (firstInitial !== null) {
|
||||
tableRoot.dataset.tableFirstInitial = firstInitial;
|
||||
}
|
||||
|
||||
if (lastInitial !== null) {
|
||||
tableRoot.dataset.tableLastInitial = lastInitial;
|
||||
}
|
||||
|
||||
// Update filters.
|
||||
if (filters) {
|
||||
tableRoot.dataset.tableFilters = JSON.stringify(filters);
|
||||
@ -133,6 +146,28 @@ export const setFilters = (tableRoot, filters, refreshContent = true) =>
|
||||
export const setSortOrder = (tableRoot, sortBy, sortOrder, refreshContent = true) =>
|
||||
updateTable(tableRoot, {sortBy, sortOrder}, refreshContent);
|
||||
|
||||
/**
|
||||
* Update the first initial to show.
|
||||
*
|
||||
* @param {HTMLElement} tableRoot
|
||||
* @param {String} firstInitial
|
||||
* @param {Bool} refreshContent
|
||||
* @returns {Promise}
|
||||
*/
|
||||
export const setFirstInitial = (tableRoot, firstInitial, refreshContent = true) =>
|
||||
updateTable(tableRoot, {firstInitial}, refreshContent);
|
||||
|
||||
/**
|
||||
* Update the last initial to show.
|
||||
*
|
||||
* @param {HTMLElement} tableRoot
|
||||
* @param {String} lastInitial
|
||||
* @param {Bool} refreshContent
|
||||
* @returns {Promise}
|
||||
*/
|
||||
export const setLastInitial = (tableRoot, lastInitial, refreshContent = true) =>
|
||||
updateTable(tableRoot, {lastInitial}, refreshContent);
|
||||
|
||||
/**
|
||||
* Set up listeners to handle table updates.
|
||||
*/
|
||||
@ -144,7 +179,7 @@ export const init = () => {
|
||||
watching = true;
|
||||
|
||||
document.addEventListener('click', e => {
|
||||
const tableRoot = e.target.closest(Selectors.table.region);
|
||||
const tableRoot = e.target.closest(Selectors.main.region);
|
||||
|
||||
if (!tableRoot) {
|
||||
return;
|
||||
@ -156,5 +191,19 @@ export const init = () => {
|
||||
|
||||
setSortOrder(tableRoot, sortableLink.dataset.sortby, sortableLink.dataset.sortorder);
|
||||
}
|
||||
|
||||
const firstInitialLink = e.target.closest(Selectors.initialsBar.links.firstInitial);
|
||||
if (firstInitialLink !== null) {
|
||||
e.preventDefault();
|
||||
|
||||
setFirstInitial(tableRoot, firstInitialLink.dataset.initial);
|
||||
}
|
||||
|
||||
const lastInitialLink = e.target.closest(Selectors.initialsBar.links.lastInitial);
|
||||
if (lastInitialLink !== null) {
|
||||
e.preventDefault();
|
||||
|
||||
setLastInitial(tableRoot, lastInitialLink.dataset.initial);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
@ -30,6 +30,9 @@ import {call as fetchMany} from 'core/ajax';
|
||||
* @method fetch
|
||||
* @param {String} handler The name of the handler
|
||||
* @param {String} uniqueid The unique id of the table
|
||||
* @param {Object} filters The filters to apply when searching
|
||||
* @param {String} firstinitial The first name initial to filter on
|
||||
* @param {String} lastinitial The last name initial to filter on
|
||||
* @param {Number} params parameters to request table
|
||||
* @return {Promise} Resolved with requested table view
|
||||
*/
|
||||
@ -37,7 +40,9 @@ export const fetch = (handler, uniqueid, {
|
||||
sortBy = null,
|
||||
sortOrder = null,
|
||||
joinType = null,
|
||||
filters = {}
|
||||
filters = {},
|
||||
firstinitial = null,
|
||||
lastinitial = null,
|
||||
} = {}
|
||||
) => {
|
||||
return fetchMany([{
|
||||
@ -49,6 +54,8 @@ export const fetch = (handler, uniqueid, {
|
||||
sortorder: sortOrder,
|
||||
jointype: joinType,
|
||||
filters,
|
||||
firstinitial,
|
||||
lastinitial,
|
||||
},
|
||||
}])[0];
|
||||
};
|
||||
|
@ -22,10 +22,18 @@
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
export default {
|
||||
table: {
|
||||
main: {
|
||||
region: '[data-region="core_table/dynamic"]',
|
||||
},
|
||||
table: {
|
||||
links: {
|
||||
sortableColumn: 'a[data-sortable="1"]',
|
||||
},
|
||||
},
|
||||
initialsBar: {
|
||||
links: {
|
||||
firstInitial: '.firstinitial [data-initial]',
|
||||
lastInitial: '.lastinitial [data-initial]',
|
||||
},
|
||||
},
|
||||
};
|
||||
|
38
lib/table/classes/external/dynamic/fetch.php
vendored
38
lib/table/classes/external/dynamic/fetch.php
vendored
@ -86,6 +86,18 @@ class fetch extends external_api {
|
||||
VALUE_OPTIONAL
|
||||
),
|
||||
'jointype' => new external_value(PARAM_INT, 'Type of join to join all filters together', VALUE_REQUIRED),
|
||||
'firstinitial' => new external_value(
|
||||
PARAM_ALPHANUMEXT,
|
||||
'The first initial to sort filter on',
|
||||
VALUE_REQUIRED,
|
||||
null
|
||||
),
|
||||
'lastinitial' => new external_value(
|
||||
PARAM_ALPHANUMEXT,
|
||||
'The last initial to sort filter on',
|
||||
VALUE_REQUIRED,
|
||||
null
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
@ -98,11 +110,21 @@ class fetch extends external_api {
|
||||
* @param string $sortorder The sort order.
|
||||
* @param array $filters The filters that will be applied in the request.
|
||||
* @param string $jointype The join type.
|
||||
* @param string $firstinitial The first name initial to filter on
|
||||
* @param string $lastinitial The last name initial to filter on
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function execute(string $handler, string $uniqueid, string $sortby, string $sortorder,
|
||||
array $filters = [], string $jointype = null) {
|
||||
public static function execute(
|
||||
string $handler,
|
||||
string $uniqueid,
|
||||
string $sortby,
|
||||
string $sortorder,
|
||||
?array $filters = null,
|
||||
?string $jointype = null,
|
||||
?string $firstinitial = null,
|
||||
?string $lastinitial = null
|
||||
) {
|
||||
|
||||
global $PAGE;
|
||||
|
||||
@ -117,6 +139,8 @@ class fetch extends external_api {
|
||||
'sortorder' => $sortorder,
|
||||
'filters' => $filters,
|
||||
'jointype' => $jointype,
|
||||
'firstinitial' => $firstinitial,
|
||||
'lastinitial' => $lastinitial,
|
||||
] = self::validate_parameters(self::execute_parameters(), [
|
||||
'handler' => $handler,
|
||||
'uniqueid' => $uniqueid,
|
||||
@ -124,6 +148,8 @@ class fetch extends external_api {
|
||||
'sortorder' => $sortorder,
|
||||
'filters' => $filters,
|
||||
'jointype' => $jointype,
|
||||
'firstinitial' => $firstinitial,
|
||||
'lastinitial' => $lastinitial,
|
||||
]);
|
||||
|
||||
$filterset = new \core_user\table\participants_filterset();
|
||||
@ -139,6 +165,14 @@ class fetch extends external_api {
|
||||
$instance->set_filterset($filterset);
|
||||
$instance->set_sorting($sortby, $sortorder);
|
||||
|
||||
if ($firstinitial !== null) {
|
||||
$instance->set_first_initial($firstinitial);
|
||||
}
|
||||
|
||||
if ($lastinitial !== null) {
|
||||
$instance->set_last_initial($lastinitial);
|
||||
}
|
||||
|
||||
$context = $instance->get_context();
|
||||
|
||||
self::validate_context($context);
|
||||
|
116
lib/tablelib.php
116
lib/tablelib.php
@ -95,6 +95,12 @@ class flexible_table {
|
||||
*/
|
||||
protected $sortorder;
|
||||
|
||||
/** @var string The manually set first name initial preference */
|
||||
protected $ifirst;
|
||||
|
||||
/** @var string The manually set last name initial preference */
|
||||
protected $ilast;
|
||||
|
||||
var $use_pages = false;
|
||||
var $use_initials = false;
|
||||
|
||||
@ -525,16 +531,7 @@ class flexible_table {
|
||||
}
|
||||
|
||||
$this->set_sorting_preferences();
|
||||
|
||||
$ilast = optional_param($this->request[TABLE_VAR_ILAST], null, PARAM_RAW);
|
||||
if (!is_null($ilast) && ($ilast ==='' || strpos(get_string('alphabet', 'langconfig'), $ilast) !== false)) {
|
||||
$this->prefs['i_last'] = $ilast;
|
||||
}
|
||||
|
||||
$ifirst = optional_param($this->request[TABLE_VAR_IFIRST], null, PARAM_RAW);
|
||||
if (!is_null($ifirst) && ($ifirst === '' || strpos(get_string('alphabet', 'langconfig'), $ifirst) !== false)) {
|
||||
$this->prefs['i_first'] = $ifirst;
|
||||
}
|
||||
$this->set_initials_preferences();
|
||||
|
||||
// Save user preferences if they have changed.
|
||||
if ($this->prefs != $oldprefs) {
|
||||
@ -1002,12 +999,18 @@ class flexible_table {
|
||||
function print_nothing_to_display() {
|
||||
global $OUTPUT;
|
||||
|
||||
// Render the dynamic table header.
|
||||
echo $this->get_dynamic_table_html_start();
|
||||
|
||||
// Render button to allow user to reset table preferences.
|
||||
echo $this->render_reset_button();
|
||||
|
||||
$this->print_initials_bar();
|
||||
|
||||
echo $OUTPUT->heading(get_string('nothingtodisplay'));
|
||||
|
||||
// Render the dynamic table footer.
|
||||
echo $this->get_dynamic_table_html_end();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1172,12 +1175,8 @@ class flexible_table {
|
||||
echo $OUTPUT->render($pagingbar);
|
||||
}
|
||||
|
||||
// Dynamic Table content.
|
||||
if (is_a($this, \core_table\dynamic::class)) {
|
||||
echo html_writer::end_tag('div');
|
||||
|
||||
$PAGE->requires->js_call_amd('core_table/dynamic', 'init');
|
||||
}
|
||||
// Render the dynamic table footer.
|
||||
echo $this->get_dynamic_table_html_end();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1353,6 +1352,31 @@ class flexible_table {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill in the preferences for the initials bar.
|
||||
*/
|
||||
protected function set_initials_preferences(): void {
|
||||
$ifirst = $this->ifirst;
|
||||
$ilast = $this->ilast;
|
||||
|
||||
if ($ifirst === null) {
|
||||
$ifirst = optional_param($this->request[TABLE_VAR_IFIRST], null, PARAM_RAW);
|
||||
}
|
||||
|
||||
if ($ilast === null) {
|
||||
$ilast = optional_param($this->request[TABLE_VAR_ILAST], null, PARAM_RAW);
|
||||
}
|
||||
|
||||
if (!is_null($ifirst) && ($ifirst === '' || strpos(get_string('alphabet', 'langconfig'), $ifirst) !== false)) {
|
||||
$this->prefs['i_first'] = $ifirst;
|
||||
}
|
||||
|
||||
if (!is_null($ilast) && ($ilast === '' || strpos(get_string('alphabet', 'langconfig'), $ilast) !== false)) {
|
||||
$this->prefs['i_last'] = $ilast;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the preferred table sorting attributes.
|
||||
*
|
||||
@ -1364,6 +1388,24 @@ class flexible_table {
|
||||
$this->sortorder = $sortorder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the preferred first name initial in an initials bar.
|
||||
*
|
||||
* @param string $initial The character to set
|
||||
*/
|
||||
public function set_first_initial(string $initial): void {
|
||||
$this->ifirst = $initial;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the preferred last name initial in an initials bar.
|
||||
*
|
||||
* @param string $initial The character to set
|
||||
*/
|
||||
public function set_last_initial(string $initial): void {
|
||||
$this->ilast = $initial;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the HTML for the sort icon. This is a helper method used by {@link sort_link()}.
|
||||
* @param bool $isprimary whether an icon is needed (it is only needed for the primary sort column.)
|
||||
@ -1446,23 +1488,55 @@ class flexible_table {
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is not part of the public api.
|
||||
* Get the dynamic table start wrapper.
|
||||
* If this is not a dynamic table, then an empty string is returned making this safe to blindly call.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function start_html() {
|
||||
global $OUTPUT;
|
||||
|
||||
protected function get_dynamic_table_html_start(): string {
|
||||
if (is_a($this, \core_table\dynamic::class)) {
|
||||
$sortdata = $this->get_sort_order();
|
||||
echo html_writer::start_tag('div', [
|
||||
return html_writer::start_tag('div', [
|
||||
'data-region' => 'core_table/dynamic',
|
||||
'data-table-handler' => get_class($this),
|
||||
'data-table-uniqueid' => $this->uniqueid,
|
||||
'data-table-filters' => json_encode($this->get_filterset()),
|
||||
'data-table-sort-by' => $sortdata['sortby'],
|
||||
'data-table-sort-order' => $sortdata['sortorder'],
|
||||
'data-table-first-initial' => $this->prefs['i_first'],
|
||||
'data-table-last-initial' => $this->prefs['i_last'],
|
||||
]);
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the dynamic table end wrapper.
|
||||
* If this is not a dynamic table, then an empty string is returned making this safe to blindly call.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function get_dynamic_table_html_end(): string {
|
||||
global $PAGE;
|
||||
|
||||
if (is_a($this, \core_table\dynamic::class)) {
|
||||
$PAGE->requires->js_call_amd('core_table/dynamic', 'init');
|
||||
return html_writer::end_tag('div');
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is not part of the public api.
|
||||
*/
|
||||
function start_html() {
|
||||
global $OUTPUT;
|
||||
|
||||
// Render the dynamic table header.
|
||||
echo $this->get_dynamic_table_html_start();
|
||||
|
||||
// Render button to allow user to reset table preferences.
|
||||
echo $this->render_reset_button();
|
||||
|
||||
|
@ -80,12 +80,12 @@
|
||||
<ul class="pagination pagination-sm">
|
||||
{{#current}}
|
||||
<li class="initialbarall page-item">
|
||||
<a class="page-link" href="{{url}}">{{all}}</a>
|
||||
<a data-initial="" class="page-link" href="{{url}}">{{all}}</a>
|
||||
</li>
|
||||
{{/current}}
|
||||
{{^current}}
|
||||
<li class="initialbarall page-item active">
|
||||
<a class="page-link">{{all}}</a>
|
||||
<a data-initial="" class="page-link">{{all}}</a>
|
||||
</li>
|
||||
{{/current}}
|
||||
</ul>
|
||||
@ -93,10 +93,10 @@
|
||||
<ul class="pagination pagination-sm">
|
||||
{{#letter}}
|
||||
{{#selected}}
|
||||
<li class="page-item active {{name}}"><span class="page-link">{{name}}</span></li>
|
||||
<li data-initial="{{name}}" class="page-item active {{name}}"><span class="page-link">{{name}}</span></li>
|
||||
{{/selected}}
|
||||
{{^selected}}
|
||||
<li class="page-item {{name}}"><a class="page-link" href="{{url}}">{{name}}</a></li>
|
||||
<li data-initial="{{name}}" class="page-item {{name}}"><a class="page-link" href="{{url}}">{{name}}</a></li>
|
||||
{{/selected}}
|
||||
{{/letter}}
|
||||
</ul>
|
||||
|
@ -701,4 +701,91 @@ class core_tablelib_testcase extends advanced_testcase {
|
||||
$this->assertEquals("Col1,Col2,Col3\na,b,c\n", substr($output, 3));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the initials functionality.
|
||||
*
|
||||
* @dataProvider initials_provider
|
||||
* @param string|null $getvalue
|
||||
* @param string|null $setvalue
|
||||
* @param string|null $finalvalue
|
||||
*/
|
||||
public function test_initials_first_set(?string $getvalue, ?string $setvalue, ?string $finalvalue): void {
|
||||
global $_GET;
|
||||
|
||||
$this->resetAfterTest(true);
|
||||
|
||||
$table = new flexible_table('tablelib_test');
|
||||
|
||||
$user = $this->getDataGenerator()->create_user();
|
||||
|
||||
$table->define_columns(['fullname']);
|
||||
$table->define_headers(['Fullname']);
|
||||
$table->define_baseurl('/invalid.php');
|
||||
$table->initialbars(true);
|
||||
|
||||
if ($getvalue !== null) {
|
||||
$_GET['tifirst'] = $getvalue;
|
||||
}
|
||||
|
||||
if ($setvalue !== null) {
|
||||
$table->set_first_initial($setvalue);
|
||||
}
|
||||
|
||||
$table->setup();
|
||||
|
||||
$this->assertEquals($finalvalue, $table->get_initial_first());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the initials functionality.
|
||||
*
|
||||
* @dataProvider initials_provider
|
||||
* @param string|null $getvalue
|
||||
* @param string|null $setvalue
|
||||
* @param string|null $finalvalue
|
||||
*/
|
||||
public function test_initials_last_set(?string $getvalue, ?string $setvalue, ?string $finalvalue): void {
|
||||
global $_GET;
|
||||
|
||||
$this->resetAfterTest(true);
|
||||
|
||||
$table = new flexible_table('tablelib_test');
|
||||
|
||||
$user = $this->getDataGenerator()->create_user();
|
||||
|
||||
$table->define_columns(['fullname']);
|
||||
$table->define_headers(['Fullname']);
|
||||
$table->define_baseurl('/invalid.php');
|
||||
$table->initialbars(true);
|
||||
|
||||
if ($getvalue !== null) {
|
||||
$_GET['tilast'] = $getvalue;
|
||||
}
|
||||
|
||||
if ($setvalue !== null) {
|
||||
$table->set_last_initial($setvalue);
|
||||
}
|
||||
|
||||
$table->setup();
|
||||
|
||||
$this->assertEquals($finalvalue, $table->get_initial_last());
|
||||
}
|
||||
|
||||
/**
|
||||
* Data for testing initials providers.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function initials_provider(): array {
|
||||
return [
|
||||
[null, null, null],
|
||||
['A', null, 'A'],
|
||||
['Z', null, 'Z'],
|
||||
[null, 'A', 'A'],
|
||||
[null, 'Z', 'Z'],
|
||||
['A', 'Z', 'Z'],
|
||||
['Z', 'A', 'A'],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user