Commit 8ca9e04f authored by Paul Holden's avatar Paul Holden
Browse files

MDL-70795 reportbuilder: beginnings of the report editor.



Implement UI elements for editing columns of a report, taking their
definitions from the selected datasource.

Co-authored-By: David Matamoros's avatarDavid Matamoros <davidmc@moodle.com>
Co-authored-By: Mikel Martín Corrales's avatarMikel Martín <mikel@moodle.com>
parent 22d896e0
......@@ -23,6 +23,7 @@
*/
$string['actions'] = 'Actions';
$string['addcolumn'] = 'Add column \'{$a}\'';
$string['apply'] = 'Apply';
$string['coursefullnamewithlink'] = 'Course full name with link';
$string['courseidnumberewithlink'] = 'Course ID number with link';
......@@ -30,9 +31,14 @@ $string['courseshortnamewithlink'] = 'Course short name with link';
$string['customfieldcolumn'] = '{$a}';
$string['deletereport'] = 'Delete report';
$string['deletereportconfirm'] = 'Are you sure you want to delete the report \'{$a}\' and all associated data?';
$string['editdetails'] = 'Edit details';
$string['editreportcontent'] = 'Edit report content';
$string['editreportdetails'] = 'Edit report details';
$string['editreportname'] = 'Edit report name';
$string['columnmoved'] = 'Moved column \'{$a}\'';
$string['customreports'] = 'Custom reports';
$string['deletecolumn'] = 'Delete column \'{$a}\'';
$string['deletecolumnconfirm'] = 'Are you sure you want to delete the column \'{$a}\'?';
$string['entitycourse'] = 'Course';
$string['entityuser'] = 'User';
$string['errorreportaccess'] = 'You can not view this report';
......@@ -73,6 +79,7 @@ $string['filtersreset'] = 'Filters reset';
$string['filterstartswith'] = 'Starts with';
$string['includedefaultsetup'] = 'Include default setup';
$string['includedefaultsetup_help'] = 'Populate report with default layout as defined by the selected source. These include pre-defined columns, filters and conditions.';
$string['movecolumn'] = 'Move column \'{$a}\'';
$string['newreport'] = 'New report';
$string['privacy:metadata:column'] = 'Report column definitions';
$string['privacy:metadata:column:uniqueidentifier'] = 'Unique identifier of the column';
......@@ -87,15 +94,20 @@ $string['privacy:metadata:report'] = 'Report definitions';
$string['privacy:metadata:report:name'] = 'The name of the report';
$string['privacy:metadata:report:usercreated'] = 'The ID of the user who created the report';
$string['privacy:metadata:report:usermodified'] = 'The ID of the user who last modified the report';
$string['renamecolumn'] = 'Rename column \'{$a}\'';
$string['reportbuilder'] = 'Report builder';
$string['reportcreated'] = 'Report created';
$string['reportdeleted'] = 'Report deleted';
$string['reportsettingstoggle'] = 'Show/hide settings sidebar';
$string['reportsource'] = 'Report source';
$string['reportsource_help'] = 'The report source defines where the data for the report will come from';
$string['reportupdated'] = 'Report updated';
$string['resetall'] = 'Reset all';
$string['selectareportsource'] = 'Select a report source';
$string['selectcourses'] = 'Select courses';
$string['showhide'] = 'Show/hide \'{$a}\'';
$string['switchedit'] = 'Switch to edit mode';
$string['switchpreview'] = 'Switch to preview mode';
$string['timeadded'] = 'Time added';
$string['timecreated'] = 'Time created';
$string['timemodified'] = 'Time modified';
......
......@@ -2804,6 +2804,84 @@ $functions = array(
'type' => 'write',
'ajax' => true,
],
'core_reportbuilder_reports_get' => [
'classname' => 'core_reportbuilder\external\reports\get',
'description' => 'Get custom report',
'type' => 'read',
'ajax' => true,
],
'core_reportbuilder_columns_add' => [
'classname' => 'core_reportbuilder\external\columns\add',
'description' => 'Add column to report',
'type' => 'write',
'ajax' => true,
],
'core_reportbuilder_columns_delete' => [
'classname' => 'core_reportbuilder\external\columns\delete',
'description' => 'Delete column from report',
'type' => 'write',
'ajax' => true,
],
'core_reportbuilder_columns_reorder' => [
'classname' => 'core_reportbuilder\external\columns\reorder',
'description' => 'Re-order column within report',
'type' => 'write',
'ajax' => true,
],
'core_reportbuilder_columns_sort_reorder' => [
'classname' => 'core_reportbuilder\external\columns\sort\reorder',
'description' => 'Re-order column sorting within report',
'type' => 'write',
'ajax' => true,
],
'core_reportbuilder_columns_sort_toggle' => [
'classname' => 'core_reportbuilder\external\columns\sort\toggle',
'description' => 'Toggle sorting of column within report',
'type' => 'write',
'ajax' => true,
],
'core_reportbuilder_conditions_add' => [
'classname' => 'core_reportbuilder\external\conditions\add',
'description' => 'Add condition to report',
'type' => 'write',
'ajax' => true,
],
'core_reportbuilder_conditions_delete' => [
'classname' => 'core_reportbuilder\external\conditions\delete',
'description' => 'Delete condition from report',
'type' => 'write',
'ajax' => true,
],
'core_reportbuilder_conditions_reorder' => [
'classname' => 'core_reportbuilder\external\conditions\reorder',
'description' => 'Re-order condition within report',
'type' => 'write',
'ajax' => true,
],
'core_reportbuilder_conditions_reset' => [
'classname' => 'core_reportbuilder\external\conditions\reset',
'description' => 'Reset conditions for given report',
'type' => 'write',
'ajax' => true,
],
'core_reportbuilder_filters_add' => [
'classname' => 'core_reportbuilder\external\filters\add',
'description' => 'Add filter to report',
'type' => 'write',
'ajax' => true,
],
'core_reportbuilder_filters_delete' => [
'classname' => 'core_reportbuilder\external\filters\delete',
'description' => 'Delete filter from report',
'type' => 'write',
'ajax' => true,
],
'core_reportbuilder_filters_reorder' => [
'classname' => 'core_reportbuilder\external\filters\reorder',
'description' => 'Re-order filter within report',
'type' => 'write',
'ajax' => true,
],
);
$services = array(
......
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
// 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/>.
/**
* Report builder editor
*
* @module core_reportbuilder/editor
* @package core_reportbuilder
* @copyright 2021 David Matamoros <davidmc@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
"use strict";
import 'core/inplace_editable';
import Notification from 'core/notification';
import Pending from 'core/pending';
import Templates from 'core/templates';
import * as reportSelectors from 'core_reportbuilder/local/selectors';
import {init as columnsEditorInit} from 'core_reportbuilder/local/editor/columns';
import {getReport} from 'core_reportbuilder/local/repository/reports';
let initialized = false;
/**
* Initialise editor and all it's modules
*/
export const init = () => {
const reportElement = document.querySelector(reportSelectors.regions.report);
columnsEditorInit(reportElement, initialized);
// Ensure we only add our listeners once (can be called multiple times by mustache template).
if (initialized) {
return;
}
// Add event handlers to generic report editor elements.
document.addEventListener('click', event => {
// Toggle between edit and preview mode.
const toggleEditViewMode = event.target.closest(reportSelectors.actions.toggleEditPreview);
if (toggleEditViewMode) {
event.preventDefault();
const pendingPromise = new Pending('core_reportbuilder/reports:get');
const toggledEditMode = toggleEditViewMode.dataset.editMode !== "1";
let customjs = '';
getReport(reportElement.dataset.reportId, toggledEditMode)
.then(response => {
customjs = response.javascript;
return Templates.render('core_reportbuilder/custom_report', response);
})
.then((html, js) => {
return Templates.replaceNodeContents(reportElement, html, js + customjs);
})
.then(() => pendingPromise.resolve())
.catch(Notification.exception);
}
});
initialized = true;
};
......@@ -31,7 +31,7 @@ import {add as addToast} from 'core/toast';
import DynamicForm from 'core_form/dynamicform';
import * as reportEvents from 'core_reportbuilder/local/events';
import * as reportSelectors from 'core_reportbuilder/local/selectors';
import {reset as resetFilters} from 'core_reportbuilder/local/repository/filters';
import {resetFilters} from 'core_reportbuilder/local/repository/filters';
/**
* Update filter button text to indicate applied filter count
......@@ -57,7 +57,7 @@ const setFilterButtonCount = async(reportElement, filterCount) => {
* @param {Number} contextId
*/
export const init = (reportId, contextId) => {
const reportElement = document.querySelector(reportSelectors.forSystemReport(reportId));
const reportElement = document.querySelector(reportSelectors.forReport(reportId));
const filterFormContainer = reportElement.querySelector(reportSelectors.regions.filtersForm);
const filterForm = new DynamicForm(filterFormContainer, '\\core_reportbuilder\\form\\filter');
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment