Skip to content

Commit

Permalink
Merge branch 'MDL-74721' of https://github.com/lostrogit/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
snake committed Aug 3, 2022
2 parents 9c4c5f1 + ac7713b commit d95071b
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 2 deletions.
5 changes: 5 additions & 0 deletions admin/settings/reportbuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,9 @@ static function(accesscallback $accesscallback): bool {
new lang_string('customreportslimit', 'core_reportbuilder'),
new lang_string('customreportslimit_desc', 'core_reportbuilder'), 0, PARAM_INT));

$settings->add(new admin_setting_configcheckbox(
'customreportsliveediting',
new lang_string('customreportsliveediting', 'core_reportbuilder'),
new lang_string('customreportsliveediting_desc', 'core_reportbuilder'), 1));

$ADMIN->add('reportbuilder', $settings);
3 changes: 3 additions & 0 deletions lang/en/reportbuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@
$string['customreports'] = 'Custom reports';
$string['customreportslimit'] = 'Custom reports limit';
$string['customreportslimit_desc'] = 'The number of custom reports may be limited for performance reasons. If set to zero, then there is no limit.';
$string['customreportsliveediting'] = 'Custom reports live editing';
$string['customreportsliveediting_desc'] = 'If enabled, users can view report data while editing the report. This may be disabled for performance reasons.';
$string['customreportsliveeditingdisabled'] = 'Viewing of report data while editing is disabled by the site administrator. Switch to preview mode to view the report.';
$string['customreportssettings'] = 'Custom report settings';
$string['deleteaudience'] = 'Delete audience \'{$a}\'';
$string['deleteaudienceconfirm'] = 'Are you sure you want to delete the audience \'{$a}\'?';
Expand Down
45 changes: 43 additions & 2 deletions reportbuilder/classes/table/custom_report_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,11 @@ public function __construct(string $uniqueid, string $download = '') {
$this->showdownloadbuttonsat = [TABLE_P_BOTTOM];
$this->is_downloading($download ?? null, $this->persistent->get_formatted_name());

// Retrieve all report columns, exit early if there are none.
// Retrieve all report columns, exit early if there are none. Defining empty columns prevents errors during out().
$columns = $this->get_active_columns();
if (empty($columns)) {
$this->init_sql('*', "{{$maintable}} {$maintablealias}", [], '1=0', []);
$this->define_columns([0]);
return;
}

Expand Down Expand Up @@ -281,7 +282,16 @@ public function print_nothing_to_display() {
echo html_writer::end_tag('div');
$this->wrap_html_finish();

$notification = (new notification(get_string('nothingtodisplay'), notification::NOTIFY_INFO, false))
// With the live editing disabled we need to notify user that data is shown only in preview mode.
if ($this->editing && !self::show_live_editing()) {
$notificationmsg = get_string('customreportsliveeditingdisabled', 'core_reportbuilder');
$notificationtype = notification::NOTIFY_WARNING;
} else {
$notificationmsg = get_string('nothingtodisplay');
$notificationtype = notification::NOTIFY_INFO;
}

$notification = (new notification($notificationmsg, $notificationtype, false))
->set_extra_classes(['mt-3']);
echo $OUTPUT->render($notification);

Expand Down Expand Up @@ -315,4 +325,35 @@ public function get_row_cells_html(string $rowid, array $row, ?array $suppressla
}
return $html;
}

/**
* Overriding this method to handle live editing setting.
* @param int $pagesize
* @param bool $useinitialsbar
* @param string $downloadhelpbutton
*/
public function out($pagesize, $useinitialsbar, $downloadhelpbutton = '') {
$this->pagesize = $pagesize;
$this->setup();

// If the live editing setting is disabled, we not need to fetch custom report data except in preview mode.
if (!$this->editing || self::show_live_editing()) {
$this->query_db($pagesize, $useinitialsbar);
$this->build_table();
$this->close_recordset();
}

$this->finish_output();
}

/**
* Whether or not report data should be included in the table while in editing mode
*
* @return bool
*/
private static function show_live_editing(): bool {
global $CFG;

return !empty($CFG->customreportsliveediting);
}
}
14 changes: 14 additions & 0 deletions reportbuilder/tests/behat/customreports.feature
Original file line number Diff line number Diff line change
Expand Up @@ -233,3 +233,17 @@ Feature: Manage custom reports
| customreportslimit | 2 |
And I reload the page
And "New report" "button" should not exist

Scenario: Disable live editing of custom reports
Given the following config values are set as admin:
| customreportsliveediting | 0 |
And the following "core_reportbuilder > Reports" exist:
| name | source |
| Report users | core_user\reportbuilder\datasource\users |
When I am on the "Report users" "reportbuilder > Editor" page logged in as "admin"
Then I should see "Viewing of report data while editing is disabled by the site administrator. Switch to preview mode to view the report." in the "[data-region='core_table/dynamic']" "css_element"
And I click on "Switch to preview mode" "button"
And I should see "admin" in the "reportbuilder-table" "table"
And I click on "Close 'Report users' editor" "button"
And I press "View" action in the "Report users" report row
And I should see "admin" in the "reportbuilder-table" "table"

0 comments on commit d95071b

Please sign in to comment.