Commit f2582cc8 authored by Mikel Martín Corrales's avatar Mikel Martín Corrales
Browse files

MDL-72565 reportbuilder: Use same template for system/custom reports



- rename 'system_report' template to 'report'
- view.php now uses 'report' template

Co-authored-by: Paul Holden's avatarPaul Holden <paulh@moodle.com>
parent d650e652
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.
......@@ -63,6 +63,9 @@ const initConditionsForm = () => {
// Handle dynamic conditions form.
const reportElement = document.querySelector(reportSelectors.regions.report);
const conditionFormContainer = reportElement.querySelector(reportSelectors.regions.settingsConditions);
if (!conditionFormContainer) {
return;
}
const conditionForm = new DynamicForm(conditionFormContainer, '\\core_reportbuilder\\form\\condition');
// Submit report conditions.
......
......@@ -53,6 +53,7 @@ class custom_report_columns_sorting_exporter extends exporter {
return [
'hassortablecolumns' => [
'type' => PARAM_BOOL,
'optional' => true,
],
'sortablecolumns' => [
'type' => [
......@@ -77,6 +78,7 @@ class custom_report_columns_sorting_exporter extends exporter {
],
'helpicon' => [
'type' => PARAM_RAW,
'optional' => true,
],
];
}
......
......@@ -53,6 +53,7 @@ class custom_report_conditions_exporter extends exporter {
return [
'hasavailableconditions' => [
'type' => PARAM_BOOL,
'optional' => true,
],
'availableconditions' => [
'type' => [
......@@ -74,6 +75,7 @@ class custom_report_conditions_exporter extends exporter {
],
'hasactiveconditions' => [
'type' => PARAM_BOOL,
'optional' => true,
],
'activeconditionsform' => [
'type' => PARAM_RAW,
......
......@@ -46,9 +46,6 @@ class custom_report_exporter extends persistent_exporter {
/** @var bool */
protected $editmode;
/** @var bool $showeditbutton When showing the report on view.php the Edit button has to be hidden */
protected $showeditbutton;
/** @var string */
protected $download;
......@@ -58,15 +55,11 @@ class custom_report_exporter extends persistent_exporter {
* @param persistent $persistent
* @param array $related
* @param bool $editmode
* @param bool $showeditbutton
* @param string $download
*/
public function __construct(persistent $persistent, array $related = [], bool $editmode = true,
bool $showeditbutton = true, string $download = '') {
public function __construct(persistent $persistent, array $related = [], bool $editmode = true, string $download = '') {
parent::__construct($persistent, $related);
$this->editmode = $editmode;
$this->showeditbutton = $showeditbutton;
$this->download = $download;
}
/**
......@@ -101,12 +94,12 @@ class custom_report_exporter extends persistent_exporter {
'filters' => ['type' => custom_report_filters_exporter::read_properties_definition()],
'sorting' => ['type' => custom_report_columns_sorting_exporter::read_properties_definition()],
'filtersapplied' => ['type' => PARAM_INT],
'filterspresent' => ['type' => PARAM_BOOL],
'filtersform' => [
'type' => PARAM_RAW,
'optional' => true,
],
'editmode' => ['type' => PARAM_INT],
'showeditbutton' => ['type' => PARAM_BOOL],
'javascript' => ['type' => PARAM_RAW],
];
}
......@@ -118,8 +111,8 @@ class custom_report_exporter extends persistent_exporter {
* @return array
*/
protected function get_other_values(renderer_base $output): array {
$filterspresent = false;
$filtersform = '';
$menucards = [];
if ($this->editmode) {
$table = custom_report_table::create($this->persistent->get('id'));
......@@ -133,33 +126,39 @@ class custom_report_exporter extends persistent_exporter {
/** @var datasource $datasource */
$datasource = new $source($this->persistent);
if (!empty($datasource->get_active_filters())) {
$filterspresent = !empty($datasource->get_active_filters());
if ($filterspresent) {
$filtersform = $this->generate_filters_form()->render();
}
}
$report = manager::get_report_from_persistent($this->persistent);
$conditionsexporter = new custom_report_conditions_exporter(null, ['report' => $report]);
$filtersexporter = new custom_report_filters_exporter(null, ['report' => $report]);
$sortingexporter = new custom_report_columns_sorting_exporter(null, ['report' => $report]);
// If we are editing we need all this information for the template.
if ($this->editmode) {
$menucardexporter = new custom_report_menu_cards_exporter(null, [
'menucards' => report_helper::get_available_columns($report->get_report_persistent())
]);
$menucards = (array) $menucardexporter->export($output);
$conditionsexporter = new custom_report_conditions_exporter(null, ['report' => $report]);
$conditions = (array) $conditionsexporter->export($output);
$filtersexporter = new custom_report_filters_exporter(null, ['report' => $report]);
$filters = (array) $filtersexporter->export($output);
$sortingexporter = new custom_report_columns_sorting_exporter(null, ['report' => $report]);
$sorting = (array) $sortingexporter->export($output);
}
return [
'table' => $output->render($table),
'sidebarmenucards' => $menucards,
'conditions' => (array) $conditionsexporter->export($output),
'filters' => (array) $filtersexporter->export($output),
'sorting' => (array) $sortingexporter->export($output),
'sidebarmenucards' => $menucards ?? [],
'conditions' => $conditions ?? [],
'filters' => $filters ?? [],
'sorting' => $sorting ?? [],
'filtersapplied' => $report->get_applied_filter_count(),
'filterspresent' => $filterspresent,
'filtersform' => $filtersform,
'editmode' => (int)$this->editmode,
'showeditbutton' => $this->showeditbutton,
'javascript' => '',
];
}
......
......@@ -53,6 +53,7 @@ class custom_report_filters_exporter extends exporter {
return [
'hasavailablefilters' => [
'type' => PARAM_BOOL,
'optional' => true,
],
'availablefilters' => [
'type' => [
......@@ -74,6 +75,7 @@ class custom_report_filters_exporter extends exporter {
],
'hasactivefilters' => [
'type' => PARAM_BOOL,
'optional' => true,
],
'activefilters' => [
'type' => [
......@@ -89,6 +91,7 @@ class custom_report_filters_exporter extends exporter {
],
'helpicon' => [
'type' => PARAM_RAW,
'optional' => true,
],
];
}
......
......@@ -103,7 +103,7 @@ class system_report_exporter extends persistent_exporter {
$table->set_filterset($filterset);
// Generate filters form if report contains any filters.
$filterspresent = !empty($source->get_filters());
$filterspresent = !empty($source->get_active_filters());
if ($filterspresent) {
$filtersform = new filter(null, null, 'post', '', [], true, [
'reportid' => $reportid,
......
......@@ -40,9 +40,6 @@ class custom_report implements renderable, templatable {
/** @var bool $editmode */
protected $editmode;
/** @var bool $showeditbutton */
protected $showeditbutton;
/** @var string $download */
protected $download;
......@@ -51,15 +48,11 @@ class custom_report implements renderable, templatable {
*
* @param report $reportpersistent
* @param bool $editmode
* @param bool $showeditbutton
* @param string $download
*/
public function __construct(report $reportpersistent, bool $editmode = true, bool $showeditbutton = true,
string $download = '') {
public function __construct(report $reportpersistent, bool $editmode = true, string $download = '') {
$this->persistent = $reportpersistent;
$this->editmode = $editmode;
$this->showeditbutton = $showeditbutton;
$this->download = $download;
}
......@@ -70,7 +63,7 @@ class custom_report implements renderable, templatable {
* @return stdClass
*/
public function export_for_template(renderer_base $output): stdClass {
$exporter = new custom_report_exporter($this->persistent, [], $this->editmode, $this->showeditbutton, $this->download);
$exporter = new custom_report_exporter($this->persistent, [], $this->editmode, $this->download);
return $exporter->export($output);
}
......
......@@ -42,7 +42,7 @@ class renderer extends plugin_renderer_base {
protected function render_system_report(system_report $report): string {
$context = $report->export_for_template($this);
return $this->render_from_template('core_reportbuilder/system_report', $context);
return $this->render_from_template('core_reportbuilder/report', $context);
}
/**
......
......@@ -58,6 +58,6 @@ if ($reportpersistent->get('type') === \core_reportbuilder\local\report\base::TY
} else {
permission::require_can_view_report($reportpersistent);
$customreport = new \core_reportbuilder\output\custom_report($reportpersistent, false, false, $download);
$customreport = new \core_reportbuilder\output\custom_report($reportpersistent, false, $download);
echo $PAGE->get_renderer('core_reportbuilder')->render($customreport);
}
......@@ -22,10 +22,9 @@
Example context (json):
{
"id": 1,
"source": "some\\class\\name",
"type": 1,
"table": "table",
"editmode": true,
"showeditbutton": true,
"sidebarmenucards": [{
"menucards": [{
"name": "General",
......@@ -87,8 +86,9 @@
}}
<div data-region="core_reportbuilder/report"
data-report-id="{{id}}"
data-source="{{source}}"
data-parameter="[]">
data-report-type="{{type}}"
data-parameter="[]"
{{#editmode}}data-editing{{/editmode}}>
<div class="reportbuilder-wrapper d-flex flex-column flex-md-row">
{{#editmode}}
<!-- Sidebar -->
......@@ -99,19 +99,17 @@
<div class="{{#editmode}}p-2 border{{/editmode}}">
<div data-region="core_reportbuilder/report-header" class="dropdown d-flex justify-content-end">
<!-- Preview/Edit button -->
{{#showeditbutton}}
<button data-action="toggle-edit-preview" data-edit-mode="{{editmode}}" class="btn btn-outline-secondary mr-2"
title="{{#editmode}}{{#str}} switchpreview, core_reportbuilder {{/str}}{{/editmode}}{{^editmode}}{{#str}} switchedit, core_reportbuilder {{/str}}{{/editmode}}">
{{#editmode}}
{{#pix}} i/preview, core, {{/pix}}
{{#str}} preview, core {{/str}}
{{/editmode}}
{{^editmode}}
{{#pix}} t/editstring, core {{/pix}}
{{#str}} edit, core {{/str}}
{{/editmode}}
</button>
{{/showeditbutton}}
<button data-action="toggle-edit-preview" data-edit-mode="{{editmode}}" class="btn btn-outline-secondary mr-2"
title="{{#editmode}}{{#str}} switchpreview, core_reportbuilder {{/str}}{{/editmode}}{{^editmode}}{{#str}} switchedit, core_reportbuilder {{/str}}{{/editmode}}">
{{#editmode}}
{{#pix}} i/preview, core {{/pix}}
{{#str}} preview, core {{/str}}
{{/editmode}}
{{^editmode}}
{{#pix}} t/editstring, core {{/pix}}
{{#str}} edit, core {{/str}}
{{/editmode}}
</button>
<!-- Settings/Filters button -->
{{#editmode}}
<button id="report-settings-collapse" data-toggle="collapse" data-target="#report-settings" class="btn btn-outline-secondary collapsed"
......@@ -122,9 +120,9 @@
{{/editmode}}
{{^editmode}}
<!-- Filters -->
{{#filtersform}}
{{#filterspresent}}
{{>core_reportbuilder/local/filters/area}}
{{/filtersform}}
{{/filterspresent}}
{{/editmode}}
</div>
<div class="mt-2">
......@@ -133,9 +131,11 @@
</div>
</div>
</div>
<!-- Settings sidebar -->
{{> core_reportbuilder/local/settings/area}}
</div>
{{#editmode}}
<!-- Settings sidebar -->
{{> core_reportbuilder/local/settings/area}}
{{/editmode}}
</div>
</div>
{{#js}}
......
......@@ -24,13 +24,12 @@
"id": 3,
"contextid": 1,
"filtersapplied": 3,
"showeditbutton": false,
"filtersform": "form"
}
}}
<!-- Filters button -->
<button class="btn btn-outline-secondary {{^showeditbutton}}btn-sm{{/showeditbutton}}" type="button" id="dropdownFiltersButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" title="{{#str}} filters, moodle {{/str}}">
<button class="btn btn-outline-secondary" type="button" id="dropdownFiltersButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" title="{{#str}} filters, moodle {{/str}}">
{{#pix}} i/filter, core {{/pix}}
<span data-region="filter-button-label">
{{#filtersapplied}} {{#str}} filtersappliedx, core_reportbuilder, {{filtersapplied}} {{/str}} {{/filtersapplied}}
......
......@@ -15,14 +15,15 @@
along with Moodle. If not, see <http://www.gnu.org/licenses/>.
}}
{{!
@template core_reportbuilder/system_report
@template core_reportbuilder/report
Template for a system report
Template for a report
Example context (json):
{
"id": 1,
"source": "some\\class\\name",
"contextid": 1,
"type": 1,
"parameters": [],
"table": "table",
"filterspresent": true,
......@@ -31,7 +32,7 @@
}}
<div data-region="core_reportbuilder/report"
data-report-id="{{id}}"
data-source="{{source}}"
data-report-type="{{type}}"
data-parameter="{{parameters}}">
<div class="reportbuilder-wrapper">
{{#filterspresent}}
......@@ -39,7 +40,7 @@
{{>core_reportbuilder/local/filters/area}}
</div>
{{/filterspresent}}
<!-- Table -->
{{! Table }}
<div class="mt-2">
{{{table}}}
</div>
......
......@@ -140,10 +140,10 @@ Feature: Manage custom reports
When I log in as "admin"
And I navigate to "Reports > Report builder > Custom reports" in site administration
And I click on "<link>" "link" in the "My report" "table_row"
Then <previewvisible> "Preview" in the "[data-region='core_reportbuilder/report-header']" "css_element"
And <editvisible> "Edit" in the "[data-region='core_reportbuilder/report-header']" "css_element"
And <settingsvisible> "Settings" in the "[data-region='core_reportbuilder/report-header']" "css_element"
And <filtersvisible> "Filters" in the "[data-region='core_reportbuilder/report-header']" "css_element"
Then <previewvisible> "Preview" in the "[data-region='core_reportbuilder/report']" "css_element"
And <editvisible> "Edit" in the "[data-region='core_reportbuilder/report']" "css_element"
And <settingsvisible> "Settings" in the "[data-region='core_reportbuilder/report']" "css_element"
And <filtersvisible> "Filters" in the "[data-region='core_reportbuilder/report']" "css_element"
Examples:
| link | previewvisible | editvisible | settingsvisible | filtersvisible |
| My report | I should see | I should not see | I should see | I should not see |
......
......@@ -56,6 +56,10 @@ class get_test extends externallib_advanced_testcase {
'default' => false,
]);
// Add two filters.
$filterfullname = $generator->create_filter(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:fullname']);
$filteremail = $generator->create_filter(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:email']);
$result = get::execute($report->get('id'), true);
$result = external_api::clean_returnvalue(get::execute_returns(), $result);
......@@ -64,13 +68,14 @@ class get_test extends externallib_advanced_testcase {
$this->assertEquals($result['source'], users::class);
$this->assertNotEmpty($result['table']);
$this->assertNotEmpty($result['javascript']);
$this->assertFalse($result['filterspresent']);
$this->assertEmpty($result['filtersform']);
$this->assertEquals(1, $result['editmode']);
$this->assertTrue($result['showeditbutton']);
$this->assertTrue($result['filters']['hasavailablefilters']);
$this->assertNotEmpty($result['filters']['availablefilters']);
$this->assertFalse($result['filters']['hasactivefilters']);
$this->assertEmpty($result['filters']['activefilters']);
$this->assertTrue($result['filters']['hasactivefilters']);
$this->assertEquals($filterfullname->get('id'), $result['filters']['activefilters'][0]['id']);
$this->assertEquals($filteremail->get('id'), $result['filters']['activefilters'][1]['id']);
}
/**
......@@ -90,8 +95,8 @@ class get_test extends externallib_advanced_testcase {
]);
// Add two filters.
$filterfullname = $generator->create_filter(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:fullname']);
$filteremail = $generator->create_filter(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:email']);
$generator->create_filter(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:fullname']);
$generator->create_filter(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:email']);
$result = get::execute($report->get('id'), false);
$result = external_api::clean_returnvalue(get::execute_returns(), $result);
......@@ -101,14 +106,12 @@ class get_test extends externallib_advanced_testcase {
$this->assertEquals($result['source'], users::class);
$this->assertNotEmpty($result['table']);
$this->assertNotEmpty($result['javascript']);
$this->assertTrue($result['filterspresent']);
$this->assertNotEmpty($result['filtersform']);
$this->assertEquals(0, $result['editmode']);
$this->assertTrue($result['showeditbutton']);
$this->assertTrue($result['filters']['hasavailablefilters']);
$this->assertNotEmpty($result['filters']['availablefilters']);
$this->assertTrue($result['filters']['hasactivefilters']);
$this->assertEquals($filterfullname->get('id'), $result['filters']['activefilters'][0]['id']);
$this->assertEquals($filteremail->get('id'), $result['filters']['activefilters'][1]['id']);
$this->assertEmpty($result['filters']);
$this->assertEmpty($result['conditions']);
$this->assertEmpty($result['sorting']);
}
/**
......
......@@ -51,7 +51,7 @@ $PAGE->set_heading($reportname);
echo $OUTPUT->header();
$customreport = (new custom_report($report->get_report_persistent(), false, false));
echo $renderer->render($customreport);
$export = (new custom_report($report->get_report_persistent(), false))->export_for_template($renderer);
echo $renderer->render_from_template('core_reportbuilder/report', $export);
echo $OUTPUT->footer();
......@@ -2,6 +2,13 @@
* Reportbuilder table.
*/
/* Table */
.reportbuilder-table {
td {
@extend .align-middle;
}
}
/* Filters */
.reportbuilder-wrapper {
.filters-dropdown {
......
......@@ -7120,7 +7120,7 @@ a.close.disabled {
.align-top, [data-filterregion="value"] div:first-of-type {
vertical-align: top !important; }
 
.align-middle {
.align-middle, .reportbuilder-table td {
vertical-align: middle !important; }
 
.align-bottom {
......@@ -20632,6 +20632,7 @@ div.editor_atto_toolbar button .icon {
/**
* Reportbuilder table.
*/
/* Table */
/* Filters */
.reportbuilder-wrapper .filters-dropdown {
width: 27rem;
......
......@@ -7120,7 +7120,7 @@ a.close.disabled {
.align-top, [data-filterregion="value"] div:first-of-type {
vertical-align: top !important; }
 
.align-middle {
.align-middle, .reportbuilder-table td {
vertical-align: middle !important; }
 
.align-bottom {
......@@ -20578,6 +20578,7 @@ div.editor_atto_toolbar button .icon {
/**
* Reportbuilder table.
*/
/* Table */
/* Filters */
.reportbuilder-wrapper .filters-dropdown {
width: 27rem;
......
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