Commit 26f73559 authored by Andrew Nicols's avatar Andrew Nicols
Browse files

Merge branch 'MDL-72545' of https://github.com/paulholden/moodle

parents d9f4590c 8f3c7e6e
......@@ -44,7 +44,27 @@ Feature: View task logs report and use its filters
And I click on "Apply" "button" in the "[data-region='report-filters']" "css_element"
Then I should see "Filters applied"
And I <shouldornotsee> "Nothing to display"
Examples:
| operator | shouldornotsee |
| Less than | should not see |
| Greater than | should see |
@javascript
Scenario: Reset task log filters
Given I log in as "admin"
And I change window size to "large"
And I navigate to "Server > Tasks > Task logs" in site administration
When I click on "Filters" "button"
And I set the following fields in the "Result" "core_reportbuilder > Filter" to these values:
| Result operator | Is equal to |
| Result value | Fail |
And I click on "Apply" "button" in the "[data-region='report-filters']" "css_element"
Then I should see "Filters applied"
And I should see "Nothing to display"
And I click on "Reset" "button" in the "[data-region='report-filters']" "css_element"
And I should see "Filters reset"
And "[data-region='report-filters']" "css_element" should be visible
And the following fields in the "Result" "core_reportbuilder > Filter" match these values:
| Result operator | Is any value |
And I should not see "Nothing to display"
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.
......@@ -22,9 +22,11 @@
*/
import {dispatchEvent} from 'core/event_dispatcher';
import {loadFragment} from 'core/fragment';
import Notification from 'core/notification';
import Pending from 'core/pending';
import {get_string as getString} from 'core/str';
import Templates from 'core/templates';
import {add as addToast} from 'core/toast';
import DynamicForm from 'core_form/dynamicform';
import * as reportEvents from 'core_reportbuilder/local/events';
......@@ -36,8 +38,9 @@ import {reset as resetFilters} from 'core_reportbuilder/local/repository/filters
*
* @method
* @param {Number} reportId
* @param {Number} contextId
*/
export const init = reportId => {
export const init = (reportId, contextId) => {
const reportElement = document.querySelector(reportSelectors.forSystemReport(reportId));
const filterFormContainer = reportElement.querySelector(reportSelectors.regions.filtersForm);
const filterForm = new DynamicForm(filterFormContainer, '\\core_reportbuilder\\form\\filter');
......@@ -63,10 +66,15 @@ export const init = reportId => {
resetFilters(reportId)
.then(() => getString('filtersreset', 'core_reportbuilder'))
.then(addToast)
.then(() => {
pendingPromise.resolve();
window.location.reload();
return;
.then(() => loadFragment('core_reportbuilder', 'filters_form', contextId, {
reportid: reportId,
parameters: reportElement.dataset.parameter,
}))
.then((html, js) => {
Templates.replaceNodeContents(filterFormContainer, html, js);
dispatchEvent(reportEvents.tableReload, {}, reportElement);
return pendingPromise.resolve();
})
.catch(Notification.exception);
});
......
......@@ -71,12 +71,14 @@ class select extends base {
*/
public function setup_form(MoodleQuickForm $mform): void {
$elements = [];
$elements['operator'] = $mform->createElement('select', $this->name . '_operator', null, $this->get_operators());
$elements['operator'] = $mform->createElement('select', $this->name . '_operator',
get_string('filterfieldoperator', 'core_reportbuilder', $this->get_header()), $this->get_operators());
// If a multi-dimensional array is passed, we need to use a different element type.
$options = $this->get_select_options();
$element = (count($options) == count($options, COUNT_RECURSIVE) ? 'select' : 'selectgroups');
$elements['value'] = $mform->createElement($element, $this->name . '_value', null, $options);
$elements['value'] = $mform->createElement($element, $this->name . '_value',
get_string('filterfieldvalue', 'core_reportbuilder', $this->get_header()), $options);
$mform->addElement('group', $this->name . '_group', '', $elements, '', false);
......
<?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/>.
/**
* Callback methods for reportbuilder component
*
* @package core_reportbuilder
* @copyright 2021 Paul Holden <paulh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
declare(strict_types=1);
use core_reportbuilder\form\filter;
/**
* Return the filters form fragment
*
* @param array $params
* @return string
*/
function core_reportbuilder_output_fragment_filters_form(array $params): string {
$filtersform = new filter(null, null, 'post', '', [], true, [
'reportid' => $params['reportid'],
'parameters' => $params['parameters'],
]);
$filtersform->set_data_for_dynamic_submission();
return $filtersform->render();
}
......@@ -22,6 +22,7 @@
Example context (json):
{
"id": 3,
"contextid": 1,
"filtersform": "form"
}
}}
......@@ -48,6 +49,6 @@
{{#js}}
require(['core_reportbuilder/filters'], function(filters) {
filters.init('{{id}}');
filters.init({{id}}, {{contextid}});
});
{{/js}}
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