mirror of
https://github.com/moodle/moodle.git
synced 2025-04-22 08:55:15 +02:00
MDL-73149 reportbuilder: update sorting options after aggregation.
Aggregation types can disable column sorting, e.g. both the current group concatenation types. If such a type is selected for a column we should update the report sorting options, ensuring that only those columns that can be sorted are available for selection.
This commit is contained in:
parent
40818b5212
commit
171c615a1b
@ -2815,6 +2815,12 @@ $functions = array(
|
||||
'type' => 'write',
|
||||
'ajax' => true,
|
||||
],
|
||||
'core_reportbuilder_columns_sort_get' => [
|
||||
'classname' => 'core_reportbuilder\external\columns\sort\get',
|
||||
'description' => 'Retrieve column sorting for report',
|
||||
'type' => 'read',
|
||||
'ajax' => true,
|
||||
],
|
||||
'core_reportbuilder_columns_sort_reorder' => [
|
||||
'classname' => 'core_reportbuilder\external\columns\sort\reorder',
|
||||
'description' => 'Re-order column sorting within report',
|
||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -1,2 +1,2 @@
|
||||
define ("core_reportbuilder/local/repository/sorting",["exports","core/ajax"],function(a,b){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.toggleColumnSorting=a.reorderColumnSorting=void 0;b=function(a){return a&&a.__esModule?a:{default:a}}(b);var c=function(a,c,d){return b.default.call([{methodname:"core_reportbuilder_columns_sort_reorder",args:{reportid:a,columnid:c,position:d}}])[0]};a.reorderColumnSorting=c;var d=function(a,c,d,e){return b.default.call([{methodname:"core_reportbuilder_columns_sort_toggle",args:{reportid:a,columnid:c,enabled:d,direction:e}}])[0]};a.toggleColumnSorting=d});
|
||||
define ("core_reportbuilder/local/repository/sorting",["exports","core/ajax"],function(a,b){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.toggleColumnSorting=a.reorderColumnSorting=a.getColumnSorting=void 0;b=function(a){return a&&a.__esModule?a:{default:a}}(b);var c=function(a){return b.default.call([{methodname:"core_reportbuilder_columns_sort_get",args:{reportid:a}}])[0]};a.getColumnSorting=c;var d=function(a,c,d){return b.default.call([{methodname:"core_reportbuilder_columns_sort_reorder",args:{reportid:a,columnid:c,position:d}}])[0]};a.reorderColumnSorting=d;var e=function(a,c,d,e){return b.default.call([{methodname:"core_reportbuilder_columns_sort_toggle",args:{reportid:a,columnid:c,enabled:d,direction:e}}])[0]};a.toggleColumnSorting=e});
|
||||
//# sourceMappingURL=sorting.min.js.map
|
||||
|
@ -1 +1 @@
|
||||
{"version":3,"sources":["../../../src/local/repository/sorting.js"],"names":["reorderColumnSorting","reportId","columnId","position","Ajax","call","methodname","args","reportid","columnid","toggleColumnSorting","enabled","direction"],"mappings":"8MAuBA,uDAUO,GAAMA,CAAAA,CAAoB,CAAG,SAACC,CAAD,CAAWC,CAAX,CAAqBC,CAArB,CAAkC,CAMlE,MAAOC,WAAKC,IAAL,CAAU,CALD,CACZC,UAAU,CAAE,yCADA,CAEZC,IAAI,CAAE,CAACC,QAAQ,CAAEP,CAAX,CAAqBQ,QAAQ,CAAEP,CAA/B,CAAyCC,QAAQ,CAAEA,CAAnD,CAFM,CAKC,CAAV,EAAqB,CAArB,CACV,CAPM,C,yBAkBA,GAAMO,CAAAA,CAAmB,CAAG,SAACT,CAAD,CAAWC,CAAX,CAAqBS,CAArB,CAA8BC,CAA9B,CAA4C,CAM3E,MAAOR,WAAKC,IAAL,CAAU,CALD,CACZC,UAAU,CAAE,wCADA,CAEZC,IAAI,CAAE,CAACC,QAAQ,CAAEP,CAAX,CAAqBQ,QAAQ,CAAEP,CAA/B,CAAyCS,OAAO,CAAEA,CAAlD,CAA2DC,SAAS,CAAEA,CAAtE,CAFM,CAKC,CAAV,EAAqB,CAArB,CACV,CAPM,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 * Module to handle column AJAX requests\n *\n * @module core_reportbuilder/local/repository/sorting\n * @copyright 2021 David Matamoros <davidmc@moodle.com>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport Ajax from 'core/ajax';\n\n/**\n * Re-order sort column position\n *\n * @param {Number} reportId\n * @param {Number} columnId\n * @param {Number} position\n * @return {Promise}\n */\nexport const reorderColumnSorting = (reportId, columnId, position) => {\n const request = {\n methodname: 'core_reportbuilder_columns_sort_reorder',\n args: {reportid: reportId, columnid: columnId, position: position}\n };\n\n return Ajax.call([request])[0];\n};\n\n/**\n * Enables/disabled sorting on column\n *\n * @param {Number} reportId\n * @param {Number} columnId\n * @param {Boolean} enabled\n * @param {Number} direction\n * @return {Promise}\n */\nexport const toggleColumnSorting = (reportId, columnId, enabled, direction) => {\n const request = {\n methodname: 'core_reportbuilder_columns_sort_toggle',\n args: {reportid: reportId, columnid: columnId, enabled: enabled, direction: direction}\n };\n\n return Ajax.call([request])[0];\n};\n"],"file":"sorting.min.js"}
|
||||
{"version":3,"sources":["../../../src/local/repository/sorting.js"],"names":["getColumnSorting","reportId","Ajax","call","methodname","args","reportid","reorderColumnSorting","columnId","position","columnid","toggleColumnSorting","enabled","direction"],"mappings":"iOAuBA,uDAQO,GAAMA,CAAAA,CAAgB,CAAG,SAAAC,CAAQ,CAAI,CAMxC,MAAOC,WAAKC,IAAL,CAAU,CALD,CACZC,UAAU,CAAE,qCADA,CAEZC,IAAI,CAAE,CAACC,QAAQ,CAAEL,CAAX,CAFM,CAKC,CAAV,EAAqB,CAArB,CACV,CAPM,C,qBAiBA,GAAMM,CAAAA,CAAoB,CAAG,SAACN,CAAD,CAAWO,CAAX,CAAqBC,CAArB,CAAkC,CAMlE,MAAOP,WAAKC,IAAL,CAAU,CALD,CACZC,UAAU,CAAE,yCADA,CAEZC,IAAI,CAAE,CAACC,QAAQ,CAAEL,CAAX,CAAqBS,QAAQ,CAAEF,CAA/B,CAAyCC,QAAQ,CAAEA,CAAnD,CAFM,CAKC,CAAV,EAAqB,CAArB,CACV,CAPM,C,yBAkBA,GAAME,CAAAA,CAAmB,CAAG,SAACV,CAAD,CAAWO,CAAX,CAAqBI,CAArB,CAA8BC,CAA9B,CAA4C,CAM3E,MAAOX,WAAKC,IAAL,CAAU,CALD,CACZC,UAAU,CAAE,wCADA,CAEZC,IAAI,CAAE,CAACC,QAAQ,CAAEL,CAAX,CAAqBS,QAAQ,CAAEF,CAA/B,CAAyCI,OAAO,CAAEA,CAAlD,CAA2DC,SAAS,CAAEA,CAAtE,CAFM,CAKC,CAAV,EAAqB,CAArB,CACV,CAPM,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 * Module to handle column sorting AJAX requests\n *\n * @module core_reportbuilder/local/repository/sorting\n * @copyright 2021 David Matamoros <davidmc@moodle.com>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport Ajax from 'core/ajax';\n\n/**\n * Retrieve column sorting\n *\n * @param {Number} reportId\n * @return {Promise}\n */\nexport const getColumnSorting = reportId => {\n const request = {\n methodname: 'core_reportbuilder_columns_sort_get',\n args: {reportid: reportId}\n };\n\n return Ajax.call([request])[0];\n};\n\n/**\n * Re-order sort column position\n *\n * @param {Number} reportId\n * @param {Number} columnId\n * @param {Number} position\n * @return {Promise}\n */\nexport const reorderColumnSorting = (reportId, columnId, position) => {\n const request = {\n methodname: 'core_reportbuilder_columns_sort_reorder',\n args: {reportid: reportId, columnid: columnId, position: position}\n };\n\n return Ajax.call([request])[0];\n};\n\n/**\n * Enables/disabled sorting on column\n *\n * @param {Number} reportId\n * @param {Number} columnId\n * @param {Boolean} enabled\n * @param {Number} direction\n * @return {Promise}\n */\nexport const toggleColumnSorting = (reportId, columnId, enabled, direction) => {\n const request = {\n methodname: 'core_reportbuilder_columns_sort_toggle',\n args: {reportid: reportId, columnid: columnId, enabled: enabled, direction: direction}\n };\n\n return Ajax.call([request])[0];\n};\n"],"file":"sorting.min.js"}
|
@ -36,6 +36,7 @@ import {add as addToast} from 'core/toast';
|
||||
import * as reportEvents from 'core_reportbuilder/local/events';
|
||||
import * as reportSelectors from 'core_reportbuilder/local/selectors';
|
||||
import {addColumn, deleteColumn, reorderColumn} from 'core_reportbuilder/local/repository/columns';
|
||||
import {getColumnSorting} from 'core_reportbuilder/local/repository/sorting';
|
||||
|
||||
/**
|
||||
* Initialise module
|
||||
@ -150,6 +151,7 @@ export const init = (initialized) => {
|
||||
|
||||
const columnAggregation = event.target.closest('[data-itemtype="columnaggregation"]');
|
||||
if (columnAggregation) {
|
||||
const pendingPromise = new Pending('core_reportbuilder/columns:aggregate');
|
||||
const reportElement = columnAggregation.closest(reportSelectors.regions.report);
|
||||
const columnHeader = columnAggregation.closest(reportSelectors.regions.columnHeader);
|
||||
|
||||
@ -159,9 +161,13 @@ export const init = (initialized) => {
|
||||
// Pass preserveTriggerElement parameter so columnAggregationLink will be focused after the report reload.
|
||||
const columnAggregationLink = `[data-itemtype="columnaggregation"][data-itemid="`
|
||||
+ `${columnAggregation.dataset.itemid}"] > a`;
|
||||
|
||||
// Now reload the table, and notify listeners that columns have been updated.
|
||||
dispatchEvent(reportEvents.tableReload, {preserveTriggerElement: columnAggregationLink}, reportElement);
|
||||
return;
|
||||
return getColumnSorting(reportElement.dataset.reportId);
|
||||
})
|
||||
.then(data => publish(reportEvents.publish.reportColumnsUpdated, data))
|
||||
.then(() => pendingPromise.resolve())
|
||||
.catch(Notification.exception);
|
||||
}
|
||||
});
|
||||
|
@ -14,7 +14,7 @@
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Module to handle column AJAX requests
|
||||
* Module to handle column sorting AJAX requests
|
||||
*
|
||||
* @module core_reportbuilder/local/repository/sorting
|
||||
* @copyright 2021 David Matamoros <davidmc@moodle.com>
|
||||
@ -23,6 +23,21 @@
|
||||
|
||||
import Ajax from 'core/ajax';
|
||||
|
||||
/**
|
||||
* Retrieve column sorting
|
||||
*
|
||||
* @param {Number} reportId
|
||||
* @return {Promise}
|
||||
*/
|
||||
export const getColumnSorting = reportId => {
|
||||
const request = {
|
||||
methodname: 'core_reportbuilder_columns_sort_get',
|
||||
args: {reportid: reportId}
|
||||
};
|
||||
|
||||
return Ajax.call([request])[0];
|
||||
};
|
||||
|
||||
/**
|
||||
* Re-order sort column position
|
||||
*
|
||||
|
89
reportbuilder/classes/external/columns/sort/get.php
vendored
Normal file
89
reportbuilder/classes/external/columns/sort/get.php
vendored
Normal file
@ -0,0 +1,89 @@
|
||||
<?php
|
||||
// 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace core_reportbuilder\external\columns\sort;
|
||||
|
||||
use external_api;
|
||||
use external_function_parameters;
|
||||
use external_single_structure;
|
||||
use external_value;
|
||||
use core_reportbuilder\manager;
|
||||
use core_reportbuilder\permission;
|
||||
use core_reportbuilder\external\custom_report_columns_sorting_exporter;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
global $CFG;
|
||||
require_once("{$CFG->libdir}/externallib.php");
|
||||
|
||||
/**
|
||||
* External method for retrieving report column sorting
|
||||
*
|
||||
* @package core_reportbuilder
|
||||
* @copyright 2021 Paul Holden <paulh@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class get extends external_api {
|
||||
|
||||
/**
|
||||
* External method parameters
|
||||
*
|
||||
* @return external_function_parameters
|
||||
*/
|
||||
public static function execute_parameters(): external_function_parameters {
|
||||
return new external_function_parameters([
|
||||
'reportid' => new external_value(PARAM_INT, 'Report ID'),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* External method execution
|
||||
*
|
||||
* @param int $reportid
|
||||
* @return array
|
||||
*/
|
||||
public static function execute(int $reportid): array {
|
||||
global $PAGE;
|
||||
|
||||
[
|
||||
'reportid' => $reportid,
|
||||
] = self::validate_parameters(self::execute_parameters(), [
|
||||
'reportid' => $reportid,
|
||||
]);
|
||||
|
||||
$report = manager::get_report_from_id($reportid);
|
||||
|
||||
self::validate_context($report->get_context());
|
||||
permission::require_can_edit_report($report->get_report_persistent());
|
||||
|
||||
$exporter = new custom_report_columns_sorting_exporter(null, [
|
||||
'report' => $report,
|
||||
]);
|
||||
|
||||
return (array) $exporter->export($PAGE->get_renderer('core'));
|
||||
}
|
||||
|
||||
/**
|
||||
* External method return value
|
||||
*
|
||||
* @return external_single_structure
|
||||
*/
|
||||
public static function execute_returns(): external_single_structure {
|
||||
return custom_report_columns_sorting_exporter::get_read_structure();
|
||||
}
|
||||
}
|
87
reportbuilder/tests/external/columns/sort/get_test.php
vendored
Normal file
87
reportbuilder/tests/external/columns/sort/get_test.php
vendored
Normal file
@ -0,0 +1,87 @@
|
||||
<?php
|
||||
// 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace core_reportbuilder\external\columns\sort;
|
||||
|
||||
use core_reportbuilder_generator;
|
||||
use external_api;
|
||||
use externallib_advanced_testcase;
|
||||
use core_reportbuilder\report_access_exception;
|
||||
use core_user\reportbuilder\datasource\users;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
global $CFG;
|
||||
require_once("{$CFG->dirroot}/webservice/tests/helpers.php");
|
||||
|
||||
/**
|
||||
* Unit tests of external class for retrieving report column sorting
|
||||
*
|
||||
* @package core_reportbuilder
|
||||
* @covers \core_reportbuilder\external\columns\sort\get
|
||||
* @copyright 2021 Paul Holden <paulh@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class get_test extends externallib_advanced_testcase {
|
||||
|
||||
/**
|
||||
* Text execute method
|
||||
*/
|
||||
public function test_execute(): void {
|
||||
$this->resetAfterTest();
|
||||
$this->setAdminUser();
|
||||
|
||||
/** @var core_reportbuilder_generator $generator */
|
||||
$generator = $this->getDataGenerator()->get_plugin_generator('core_reportbuilder');
|
||||
$report = $generator->create_report(['name' => 'My report', 'source' => users::class, 'default' => false]);
|
||||
|
||||
// Add some columns (note 'user:picture' is not a sortable column).
|
||||
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:fullname']);
|
||||
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:email']);
|
||||
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:picture']);
|
||||
|
||||
$result = get::execute($report->get('id'));
|
||||
$result = external_api::clean_returnvalue(get::execute_returns(), $result);
|
||||
|
||||
$this->assertTrue($result['hassortablecolumns']);
|
||||
|
||||
$sortablecolumntitles = array_column($result['sortablecolumns'], 'title');
|
||||
$this->assertEquals([
|
||||
'Full name',
|
||||
'Email address',
|
||||
], $sortablecolumntitles);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test execute method for a user without permission to edit reports
|
||||
*/
|
||||
public function test_execute_access_exception(): void {
|
||||
$this->resetAfterTest();
|
||||
|
||||
/** @var core_reportbuilder_generator $generator */
|
||||
$generator = $this->getDataGenerator()->get_plugin_generator('core_reportbuilder');
|
||||
$report = $generator->create_report(['name' => 'My report', 'source' => users::class]);
|
||||
|
||||
$user = $this->getDataGenerator()->create_user();
|
||||
$this->setUser($user);
|
||||
|
||||
$this->expectException(report_access_exception::class);
|
||||
$this->expectExceptionMessage('You cannot edit this report');
|
||||
get::execute($report->get('id'));
|
||||
}
|
||||
}
|
@ -29,7 +29,7 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$version = 2021120100.01; // YYYYMMDD = weekly release date of this DEV branch.
|
||||
$version = 2021120100.02; // YYYYMMDD = weekly release date of this DEV branch.
|
||||
// RR = release increments - 00 in DEV branches.
|
||||
// .XX = incremental changes.
|
||||
$release = '4.0dev+ (Build: 20211201)'; // Human-friendly version name
|
||||
|
Loading…
x
Reference in New Issue
Block a user