MDL-72598 reportbuilder: elements to allow audiences to be renamed.
This allows the user to give the audience more context, particularly when they are used for selection on the forthcoming schedule form editing.
This commit is contained in:
@@ -25,7 +25,6 @@
|
||||
$string['access'] = 'Access';
|
||||
$string['actions'] = 'Actions';
|
||||
$string['addaudience'] = 'Add audience \'{$a}\'';
|
||||
$string['addaudiences'] = 'Add an audience to this report';
|
||||
$string['addcolumn'] = 'Add column \'{$a}\'';
|
||||
$string['addusers'] = 'Add users manually';
|
||||
$string['aggregatecolumn'] = 'Aggregate column \'{$a}\'';
|
||||
@@ -147,6 +146,7 @@ $string['movecondition'] = 'Move condition \'{$a}\'';
|
||||
$string['movefilter'] = 'Move filter \'{$a}\'';
|
||||
$string['movesorting'] = 'Move sorting for column \'{$a}\'';
|
||||
$string['newreport'] = 'New report';
|
||||
$string['noaudiences'] = 'There are no audiences for this report';
|
||||
$string['noconditions'] = 'There are no conditions selected';
|
||||
$string['nofilters'] = 'There are no filters selected';
|
||||
$string['nosortablecolumns'] = 'There are no sortable columns';
|
||||
@@ -173,6 +173,7 @@ $string['privacy:metadata:schedule:name'] = 'The name of the schedule';
|
||||
$string['privacy:metadata:schedule:usercreated'] = 'The ID of the user who created the schedule';
|
||||
$string['privacy:metadata:schedule:usermodified'] = 'The ID of the user who last modified the schedule';
|
||||
$string['privacy:metadata:schedule:userviewas'] = 'The ID of the user who the schedule will be viewed as';
|
||||
$string['renameaudience'] = 'Rename audience \'{$a}\'';
|
||||
$string['renamecolumn'] = 'Rename column \'{$a}\'';
|
||||
$string['renamefilter'] = 'Rename filter \'{$a}\'';
|
||||
$string['reportbuilder'] = 'Report builder';
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
<?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/>.
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace core_reportbuilder\output;
|
||||
|
||||
use core_external;
|
||||
use core\output\inplace_editable;
|
||||
use core_reportbuilder\permission;
|
||||
use core_reportbuilder\local\audiences\base;
|
||||
use core_reportbuilder\local\models\audience;
|
||||
|
||||
/**
|
||||
* Audience heading editable component
|
||||
*
|
||||
* @package core_reportbuilder
|
||||
* @copyright 2021 Paul Holden <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class audience_heading_editable extends inplace_editable {
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param int $audienceid
|
||||
* @param audience|null $audience
|
||||
*/
|
||||
public function __construct(int $audienceid, ?audience $audience = null) {
|
||||
if ($audience === null) {
|
||||
$audience = new audience($audienceid);
|
||||
}
|
||||
|
||||
$report = $audience->get_report();
|
||||
$editable = permission::can_edit_report($report);
|
||||
|
||||
$audienceinstance = base::instance(0, $audience->to_record());
|
||||
|
||||
// Use audience defined title if custom heading not set.
|
||||
if ('' !== $value = (string) $audience->get('heading')) {
|
||||
$displayvalue = $audience->get_formatted_heading($report->get_context());
|
||||
} else {
|
||||
$displayvalue = $value = $audienceinstance->get_name();
|
||||
}
|
||||
|
||||
parent::__construct('core_reportbuilder', 'audienceheading', $audience->get('id'), $editable, $displayvalue, $value,
|
||||
get_string('renameaudience', 'core_reportbuilder', $audienceinstance->get_name()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update audience persistent and return self, called from inplace_editable callback
|
||||
*
|
||||
* @param int $audienceid
|
||||
* @param string $value
|
||||
* @return self
|
||||
*/
|
||||
public static function update(int $audienceid, string $value): self {
|
||||
$audience = new audience($audienceid);
|
||||
|
||||
$report = $audience->get_report();
|
||||
|
||||
core_external::validate_context($report->get_context());
|
||||
permission::require_can_edit_report($report);
|
||||
|
||||
$value = clean_param($value, PARAM_TEXT);
|
||||
$audience
|
||||
->set('heading', $value)
|
||||
->update();
|
||||
|
||||
return new self(0, $audience);
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,7 @@ use core\output\dynamic_tabs\base;
|
||||
use core_reportbuilder\external\custom_report_menu_cards_exporter;
|
||||
use core_reportbuilder\local\helpers\audience as audience_helper;
|
||||
use core_reportbuilder\local\models\report;
|
||||
use core_reportbuilder\output\audience_heading_editable;
|
||||
use core_reportbuilder\permission;
|
||||
use renderer_base;
|
||||
|
||||
@@ -96,6 +97,10 @@ class audience extends base {
|
||||
* @return array
|
||||
*/
|
||||
private function get_all_report_audiences(): array {
|
||||
global $PAGE;
|
||||
|
||||
$renderer = $PAGE->get_renderer('core');
|
||||
|
||||
$audienceinstances = [];
|
||||
$reportaudiences = audience_helper::get_base_records((int)$this->data['reportid']);
|
||||
$showormessage = false;
|
||||
@@ -103,11 +108,14 @@ class audience extends base {
|
||||
$persistent = $reportaudience->get_persistent();
|
||||
$canedit = $reportaudience->user_can_edit();
|
||||
|
||||
$editable = new audience_heading_editable($persistent->get('id'));
|
||||
|
||||
$params = [
|
||||
'identifier' => $persistent->get('classname'),
|
||||
'instanceid' => $persistent->get('id'),
|
||||
'description' => $reportaudience->get_description(),
|
||||
'title' => $reportaudience->get_name(),
|
||||
'heading' => $reportaudience->get_name(),
|
||||
'headingeditable' => $editable->render($renderer),
|
||||
'canedit' => $canedit,
|
||||
'candelete' => $canedit,
|
||||
'showormessage' => $showormessage,
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use core\output\inplace_editable;
|
||||
use core_reportbuilder\form\audience;
|
||||
use core_reportbuilder\form\filter;
|
||||
|
||||
@@ -61,7 +62,8 @@ function core_reportbuilder_output_fragment_audience_form(array $params): string
|
||||
|
||||
$context = [
|
||||
'instanceid' => 0,
|
||||
'title' => $params['title'],
|
||||
'heading' => $params['title'],
|
||||
'headingeditable' => $params['title'],
|
||||
'form' => $audienceform->render(),
|
||||
'canedit' => true,
|
||||
'candelete' => true,
|
||||
@@ -78,11 +80,9 @@ function core_reportbuilder_output_fragment_audience_form(array $params): string
|
||||
* @param string $itemtype
|
||||
* @param int $itemid
|
||||
* @param string $newvalue
|
||||
* @return \core\output\inplace_editable|bool
|
||||
* @return inplace_editable|null
|
||||
*/
|
||||
function core_reportbuilder_inplace_editable($itemtype, $itemid, $newvalue) {
|
||||
$itemid = (int) $itemid;
|
||||
|
||||
function core_reportbuilder_inplace_editable(string $itemtype, int $itemid, string $newvalue): ?inplace_editable {
|
||||
switch ($itemtype) {
|
||||
case 'reportname':
|
||||
return \core_reportbuilder\output\report_name_editable::update($itemid, $newvalue);
|
||||
@@ -96,7 +96,9 @@ function core_reportbuilder_inplace_editable($itemtype, $itemid, $newvalue) {
|
||||
case 'filterheading':
|
||||
return \core_reportbuilder\output\filter_heading_editable::update($itemid, $newvalue);
|
||||
|
||||
default:
|
||||
return false;
|
||||
case 'audienceheading':
|
||||
return \core_reportbuilder\output\audience_heading_editable::update($itemid, $newvalue);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -23,7 +23,8 @@
|
||||
{
|
||||
"instanceid": 1,
|
||||
"classname": "some\\class\\name",
|
||||
"title": "Title",
|
||||
"heading": "Title",
|
||||
"headingeditable": "Title (edit me)",
|
||||
"showormessage": 1,
|
||||
"canedit": 1,
|
||||
"candelete": 1,
|
||||
@@ -31,7 +32,7 @@
|
||||
"form": "form"
|
||||
}
|
||||
}}
|
||||
<div class="instance-card" data-classname="{{identifier}}" data-instanceid="{{instanceid}}" data-title="{{title}}" data-region="audience-card">
|
||||
<div class="instance-card" data-classname="{{identifier}}" data-instanceid="{{instanceid}}" data-title="{{heading}}" data-region="audience-card">
|
||||
{{#showormessage}}
|
||||
<span class="audience-separator d-flex mb-3 justify-content-center align-items-center small text-muted font-weight-bold">
|
||||
{{#str}} or, core_reportbuilder {{/str}}
|
||||
@@ -41,14 +42,14 @@
|
||||
<div class="card-header p-0">
|
||||
<div class="mb-0 d-flex">
|
||||
<h3 class="h6 text-left m-0 align-self-center pl-3">
|
||||
{{title}}
|
||||
{{{headingeditable}}}
|
||||
</h3>
|
||||
<span class="ml-auto">
|
||||
{{#canedit}}
|
||||
<button class="btn btn-link px-0"
|
||||
data-action="edit-audience"
|
||||
title="{{#str}} editaudience, core_reportbuilder, {{title}} {{/str}}"
|
||||
aria-label="{{#str}} editaudience, core_reportbuilder, {{title}} {{/str}}"
|
||||
title="{{#str}} editaudience, core_reportbuilder, {{heading}} {{/str}}"
|
||||
aria-label="{{#str}} editaudience, core_reportbuilder, {{heading}} {{/str}}"
|
||||
{{^description}}disabled{{/description}}>
|
||||
{{#pix}} i/settings, core {{/pix}}
|
||||
</button>
|
||||
@@ -56,8 +57,8 @@
|
||||
{{#candelete}}
|
||||
<button class="btn btn-link px-0 mr-2"
|
||||
data-action="delete-audience"
|
||||
title="{{#str}} deleteaudience, core_reportbuilder, {{title}} {{/str}}"
|
||||
aria-label="{{#str}} deleteaudience, core_reportbuilder, {{title}} {{/str}}"
|
||||
title="{{#str}} deleteaudience, core_reportbuilder, {{heading}} {{/str}}"
|
||||
aria-label="{{#str}} deleteaudience, core_reportbuilder, {{heading}} {{/str}}"
|
||||
{{^description}}disabled{{/description}}>
|
||||
{{#pix}} i/trash, core {{/pix}}
|
||||
</button>
|
||||
|
||||
@@ -27,7 +27,8 @@
|
||||
"instances": [{
|
||||
"instanceid": 1,
|
||||
"classname": "some\\class\\name",
|
||||
"title": "Title",
|
||||
"heading": "Title",
|
||||
"headingeditable": "Title (edit me)",
|
||||
"showormessage": 1,
|
||||
"canedit": 1,
|
||||
"candelete": 1,
|
||||
@@ -54,7 +55,7 @@
|
||||
<div id="audiences-container" class="reportbuilder-audiences-container d-flex flex-column flex-fill" data-region="audiences">
|
||||
{{! No audience container }}
|
||||
<div class="justify-content-center {{#hasinstances}}hidden{{/hasinstances}}" data-region="no-instances-message">
|
||||
<div class="alert alert-info mb-0">{{#str}} addaudiences, core_reportbuilder {{/str}}</div>
|
||||
<div class="alert alert-info mb-0">{{#str}} noaudiences, core_reportbuilder {{/str}}</div>
|
||||
</div>
|
||||
{{#instances}}
|
||||
{{> core_reportbuilder/local/audience/form}}
|
||||
|
||||
@@ -27,7 +27,7 @@ Feature: Configure access to reports based on intended audience
|
||||
And I click on the "Access" dynamic tab
|
||||
And I should see "Nothing to display"
|
||||
And I click on the "Audience" dynamic tab
|
||||
And I should see "Add an audience to this report"
|
||||
And I should see "There are no audiences for this report"
|
||||
Then I click on "Add audience 'Manually added users'" "link"
|
||||
And I should see "Added audience 'Manually added users'"
|
||||
And I set the field "Add users manually" to "User 1,User 3"
|
||||
@@ -36,7 +36,7 @@ Feature: Configure access to reports based on intended audience
|
||||
And I should see "User 1"
|
||||
And I should not see "User 2"
|
||||
And I should see "User 3"
|
||||
And I should not see "Add an audience to this report"
|
||||
And I should not see "There are no audiences for this report"
|
||||
And I click on the "Access" dynamic tab
|
||||
And I should see "User 1" in the "reportbuilder-table" "table"
|
||||
And I should not see "User 2" in the "reportbuilder-table" "table"
|
||||
@@ -57,7 +57,7 @@ Feature: Configure access to reports based on intended audience
|
||||
And I press "Save changes"
|
||||
Then I should see "Audience saved"
|
||||
And I should see "Test role"
|
||||
And I should not see "Add an audience to this report"
|
||||
And I should not see "There are no audiences for this report"
|
||||
And I click on the "Access" dynamic tab
|
||||
And I should not see "User 1" in the "reportbuilder-table" "table"
|
||||
And I should see "User 2" in the "reportbuilder-table" "table"
|
||||
@@ -78,7 +78,7 @@ Feature: Configure access to reports based on intended audience
|
||||
And I press "Save changes"
|
||||
Then I should see "Audience saved"
|
||||
And I should see "Cohort1"
|
||||
And I should not see "Add an audience to this report"
|
||||
And I should not see "There are no audiences for this report"
|
||||
And I click on the "Access" dynamic tab
|
||||
And I should not see "User 1" in the "reportbuilder-table" "table"
|
||||
And I should not see "User 2" in the "reportbuilder-table" "table"
|
||||
@@ -99,14 +99,14 @@ Feature: Configure access to reports based on intended audience
|
||||
When I click on "Delete audience 'All users'" "button"
|
||||
And I click on "Delete" "button" in the "Delete audience 'All users'" "dialogue"
|
||||
Then I should see "Deleted audience 'All users'"
|
||||
And I should see "Add an audience to this report"
|
||||
And I should see "There are no audiences for this report"
|
||||
|
||||
Scenario: Edit report audience with manually added users audience type
|
||||
Given I am on the "My report" "reportbuilder > Editor" page logged in as "admin"
|
||||
And I click on the "Access" dynamic tab
|
||||
And I should see "Nothing to display"
|
||||
And I click on the "Audience" dynamic tab
|
||||
And I should see "Add an audience to this report"
|
||||
And I should see "There are no audiences for this report"
|
||||
And I click on "Add audience 'Manually added users'" "link"
|
||||
And I set the field "Add users manually" to "User 1,User 3"
|
||||
And I press "Save changes"
|
||||
@@ -148,7 +148,7 @@ Feature: Configure access to reports based on intended audience
|
||||
And I navigate to "Reports > Report builder > Custom reports" in site administration
|
||||
And I click on "My report" "link" in the "My report" "table_row"
|
||||
And I click on the "Audience" dynamic tab
|
||||
And I should see "Add an audience to this report"
|
||||
And I should see "There are no audiences for this report"
|
||||
Then I click on "Add audience 'Manually added users'" "link"
|
||||
And I set the field "Add users manually" to "User 1"
|
||||
And I press "Save changes"
|
||||
@@ -192,7 +192,7 @@ Feature: Configure access to reports based on intended audience
|
||||
And I navigate to "Reports > Report builder > Custom reports" in site administration
|
||||
And I click on "My report" "link" in the "My report" "table_row"
|
||||
And I click on the "Audience" dynamic tab
|
||||
And I should see "Add an audience to this report"
|
||||
And I should see "There are no audiences for this report"
|
||||
Then I click on "Add audience 'Manually added users'" "link"
|
||||
And I set the field "Add users manually" to "User 1"
|
||||
And I press "Save changes"
|
||||
|
||||
Reference in New Issue
Block a user