MDL-82936 reportbuilder: implement report actions for existing reports.

Applied to the admin user listing page, and the report/schedule pages
to align the "New X" buttons.
This commit is contained in:
Paul Holden 2025-02-28 10:28:18 +00:00
parent c439e2d3c1
commit e44c23c982
No known key found for this signature in database
GPG Key ID: A81A96D6045F6164
4 changed files with 21 additions and 20 deletions

View File

@ -159,16 +159,6 @@
echo $OUTPUT->header();
if (has_capability('moodle/user:create', $sitecontext)) {
echo html_writer::start_div('d-flex mb-2');
$url = new moodle_url('/user/editadvanced.php', ['id' => -1]);
echo html_writer::link($url, get_string('addnewuser', 'moodle'), [
'class' => 'btn btn-primary ms-auto',
'data-action' => 'add-user',
]);
echo html_writer::end_div();
}
echo html_writer::start_div('', ['data-region' => 'report-user-list-wrapper']);
$bulkactions = new user_bulk_action_form(new moodle_url('/admin/user/user_bulk.php'),
@ -179,6 +169,15 @@
$report = \core_reportbuilder\system_report_factory::create(\core_admin\reportbuilder\local\systemreports\users::class,
context_system::instance(), parameters: ['withcheckboxes' => $bulkactions->has_bulk_actions()]);
if (has_capability('moodle/user:create', $sitecontext)) {
$url = new moodle_url('/user/editadvanced.php', ['id' => -1]);
$report->set_report_action(new \core_reportbuilder\output\report_action(
get_string('addnewuser', 'moodle'),
['class' => 'btn btn-primary ms-auto', 'data-action' => 'add-user', 'href' => (string) $url],
'a',
));
}
echo $report->output();
if ($bulkactions->has_bulk_actions()) {

View File

@ -25,6 +25,7 @@ use core_reportbuilder\permission;
use core_reportbuilder\system_report_factory;
use core_reportbuilder\local\models\report;
use core_reportbuilder\local\systemreports\report_schedules;
use core_reportbuilder\output\report_action;
/**
* Schedules dynamic tab
@ -44,6 +45,10 @@ class schedules extends base {
public function export_for_template(renderer_base $output): array {
$report = system_report_factory::create(report_schedules::class, context_system::instance(), '', '', 0,
['reportid' => $this->data['reportid']]);
$report->set_report_action(new report_action(
get_string('newschedule', 'core_reportbuilder'),
['class' => 'btn btn-primary ms-auto', 'data-action' => 'schedule-create'],
));
return [
'reportid' => $this->data['reportid'],

View File

@ -27,6 +27,7 @@ declare(strict_types=1);
use core_reportbuilder\permission;
use core_reportbuilder\system_report_factory;
use core_reportbuilder\local\systemreports\reports_list;
use core_reportbuilder\output\report_action;
require_once(__DIR__ . '/../config.php');
require_once("{$CFG->libdir}/adminlib.php");
@ -36,18 +37,16 @@ admin_externalpage_setup('customreports');
$PAGE->requires->js_call_amd('core_reportbuilder/reports_list', 'init');
echo $OUTPUT->header();
echo html_writer::start_div('d-flex justify-content-between mb-2');
echo $OUTPUT->heading(get_string('customreports', 'core_reportbuilder'));
$report = system_report_factory::create(reports_list::class, context_system::instance());
if (permission::can_create_report()) {
/** @var \core_reportbuilder\output\renderer $renderer */
$renderer = $PAGE->get_renderer('core_reportbuilder');
echo $renderer->render_new_report_button();
$report->set_report_action(new report_action(
get_string('newreport', 'core_reportbuilder'),
['class' => 'btn btn-primary my-auto', 'data-action' => 'report-create'],
));
}
echo html_writer::end_div();
$report = system_report_factory::create(reports_list::class, context_system::instance());
echo $report->output();
echo $OUTPUT->footer();

View File

@ -25,10 +25,8 @@
"reportid": 10
}
}}
<h2 class="visually-hidden">{{#str}} schedules, core_reportbuilder {{/str}}</h2>
<div class="reportbuilder-schedules-container">
<div class="d-flex mb-2">
<button class="btn btn-primary ms-auto" data-action="schedule-create">{{#str}} newschedule, core_reportbuilder {{/str}}</button>
</div>
{{{ report }}}
</div>