This commit is contained in:
Jun Pataleta 2022-01-20 18:15:42 +08:00
commit c304ec8d02
4 changed files with 46 additions and 16 deletions

View File

@ -140,15 +140,19 @@ class task_logs extends system_report {
// Action to view individual task log on a popup window.
$this->add_action((new action(
new moodle_url('/admin/tasklogs.php', ['logid' => ':id']),
new pix_icon('e/search', get_string('view')),
new pix_icon('e/search', ''),
[],
true,
new lang_string('view'),
)));
// Action to download individual task log.
$this->add_action((new action(
new moodle_url('/admin/tasklogs.php', ['logid' => ':id', 'download' => true]),
new pix_icon('t/download', get_string('download')),
new pix_icon('t/download', ''),
[],
false,
new lang_string('download'),
)));
}
}

View File

@ -18,6 +18,7 @@ declare(strict_types=1);
namespace core_reportbuilder\local\report;
use lang_string;
use moodle_url;
use pix_icon;
use popup_action;
@ -47,6 +48,9 @@ final class action {
/** @var callable[] $callbacks */
protected $callbacks = [];
/** @var lang_string|string $title */
protected $title;
/**
* Create an instance of an action to be added to a report. Both the parameters of the URL, and the attributes parameter
* support placeholders which will be replaced with appropriate row values, e.g.:
@ -59,17 +63,21 @@ final class action {
* @param pix_icon $icon
* @param array $attributes
* @param bool $popup
* @param ?lang_string $title
*/
public function __construct(
moodle_url $url,
pix_icon $icon,
array $attributes = [],
bool $popup = false
bool $popup = false,
?lang_string $title = null
) {
$this->url = $url;
$this->icon = $icon;
$this->attributes = $attributes;
$this->popup = $popup;
// If title is not passed, check the title attribute from the icon.
$this->title = $title ?? $icon->attributes['title'] ?? '';
}
/**
@ -109,6 +117,9 @@ final class action {
self::replace_placeholders($this->url->params(), $row)
);
$this->attributes['role'] = 'button';
$this->attributes['title'] = $this->attributes['aria-label'] = (string) $this->title;
if ($this->popup) {
$this->attributes['data-action'] = 'report-action-popup';
$this->attributes['data-popup-action'] = json_encode(new popup_action('click', $url));

View File

@ -265,22 +265,28 @@ class report_schedules extends system_report {
// Edit action.
$this->add_action(new action(
new moodle_url('#'),
new pix_icon('t/edit', get_string('editscheduledetails', 'core_reportbuilder')),
['data-action' => 'schedule-edit', 'data-schedule-id' => ':id']
new pix_icon('t/edit', ''),
['data-action' => 'schedule-edit', 'data-schedule-id' => ':id'],
false,
new lang_string('editscheduledetails', 'core_reportbuilder')
));
// Send now action.
$this->add_action(new action(
new moodle_url('#'),
new pix_icon('t/email', get_string('sendschedule', 'core_reportbuilder')),
['data-action' => 'schedule-send', 'data-schedule-id' => ':id', 'data-schedule-name' => ':name']
new pix_icon('t/email', ''),
['data-action' => 'schedule-send', 'data-schedule-id' => ':id', 'data-schedule-name' => ':name'],
false,
new lang_string('sendschedule', 'core_reportbuilder')
));
// Delete action.
$this->add_action(new action(
new moodle_url('#'),
new pix_icon('t/delete', get_string('deleteschedule', 'core_reportbuilder')),
['data-action' => 'schedule-delete', 'data-schedule-id' => ':id', 'data-schedule-name' => ':name']
new pix_icon('t/delete', ''),
['data-action' => 'schedule-delete', 'data-schedule-id' => ':id', 'data-schedule-name' => ':name'],
false,
new lang_string('deleteschedule', 'core_reportbuilder')
));
}
}

View File

@ -238,7 +238,10 @@ class reports_list extends system_report {
// Edit content action.
$this->add_action((new action(
new moodle_url('/reportbuilder/edit.php', ['id' => ':id']),
new pix_icon('t/right', get_string('editreportcontent', 'core_reportbuilder'))
new pix_icon('t/right', ''),
[],
false,
new lang_string('editreportcontent', 'core_reportbuilder')
))
->add_callback(function(stdClass $row): bool {
return $this->report_source_valid($row->source) && permission::can_edit_report($this->get_report_from_row($row));
@ -248,8 +251,10 @@ class reports_list extends system_report {
// Edit details action.
$this->add_action((new action(
new moodle_url('#'),
new pix_icon('t/edit', get_string('editreportdetails', 'core_reportbuilder')),
['data-action' => 'report-edit', 'data-report-id' => ':id']
new pix_icon('t/edit', ''),
['data-action' => 'report-edit', 'data-report-id' => ':id'],
false,
new lang_string('editreportdetails', 'core_reportbuilder')
))
->add_callback(function(stdClass $row): bool {
return $this->report_source_valid($row->source) && permission::can_edit_report($this->get_report_from_row($row));
@ -259,8 +264,10 @@ class reports_list extends system_report {
// Preview action.
$this->add_action((new action(
new moodle_url('/reportbuilder/view.php', ['id' => ':id']),
new pix_icon('i/search', get_string('viewreport', 'core_reportbuilder')),
[]
new pix_icon('i/search', ''),
[],
false,
new lang_string('viewreport', 'core_reportbuilder')
))
->add_callback(function(stdClass $row): bool {
// We check this only to give the action to editors, because normal users can just click on the report name.
@ -271,8 +278,10 @@ class reports_list extends system_report {
// Delete action.
$this->add_action((new action(
new moodle_url('#'),
new pix_icon('t/delete', get_string('deletereport', 'core_reportbuilder')),
['data-action' => 'report-delete', 'data-report-id' => ':id', 'data-report-name' => ':name']
new pix_icon('t/delete', ''),
['data-action' => 'report-delete', 'data-report-id' => ':id', 'data-report-name' => ':name'],
false,
new lang_string('deletereport', 'core_reportbuilder')
))
->add_callback(function(stdClass $row): bool {
// We don't check whether report is valid to ensure editor can always delete them.