MDL-73362 lesson: Marry up implementation with the prototype

- Update/Add page headings
- Add notifications on override pages
- Rename buttons.
This commit is contained in:
Peter Dias
2022-01-17 10:39:18 +08:00
parent 0e1b09615c
commit f956e1acbb
17 changed files with 123 additions and 50 deletions
@@ -75,7 +75,8 @@ class edit_action_area implements templatable, renderable {
'text' => get_string('back', 'core'),
'link' => (new moodle_url('/mod/lesson/view.php', ['id' => $this->cmid]))->out(false)
],
'viewselect' => $selectmenu->export_for_template($output)
'viewselect' => $selectmenu->export_for_template($output),
'heading' => get_string('editinglesson', 'mod_lesson')
];
}
}
@@ -24,6 +24,7 @@
namespace mod_lesson\output;
use core\output\notification;
use moodle_url;
use templatable;
use renderable;
@@ -38,20 +39,29 @@ use single_button;
*/
class edit_action_buttons implements templatable, renderable {
/** @var int The course module ID. */
protected $cmid;
/** @var bool Whether the user can edit this lesson. */
protected $canmanage;
/** @var \lesson The lesson object. */
protected $lesson;
/** @var int The currently viewed lesson page id. */
protected $currentpage;
/**
* Constructor for this object.
*
* @param int $cmid The course module ID.
* @param bool $canmanage Whether the user can edit this lesson.
* @param \lesson $lesson The lesson object.
* @param int|null $currentpage The current lesson page that is being viewed
*/
public function __construct(int $cmid, bool $canmanage) {
$this->cmid = $cmid;
$this->canmanage = $canmanage;
public function __construct(\lesson $lesson, ?int $currentpage = null) {
$this->lesson = $lesson;
$this->currentpage = $currentpage;
}
/**
* Sets the current page being viewed.
*
* @param int|null $page
*/
public function set_currentpage(?int $page) {
$this->currentpage = $page;
}
/**
@@ -63,23 +73,41 @@ class edit_action_buttons implements templatable, renderable {
public function export_for_template(\renderer_base $output) {
global $PAGE;
if (!$this->canmanage || !$PAGE->has_secondary_navigation()) {
return [];
$data = [];
// A shortcut to edit the lesson's question page.
if (has_capability('mod/lesson:edit', $this->lesson->context) &&
!empty($this->currentpage) && $this->currentpage != LESSON_EOL) {
$url = new moodle_url('/mod/lesson/editpage.php', [
'id' => $this->lesson->get_cm()->id,
'pageid' => $this->currentpage,
'edit' => 1,
'returnto' => $PAGE->url->out_as_local_url(false)
]);
$editcontent = new single_button($url, get_string('editpagecontent', 'lesson'));
$data['editcontents']['button'] = $editcontent->export_for_template($output);
}
$url = new moodle_url('/mod/lesson/edit.php', ['id' => $this->cmid]);
$editbutton = new single_button($url, get_string('edit', 'mod_lesson'), 'get', true);
$url = new moodle_url('/mod/lesson/essay.php', ['id' => $this->cmid]);
$essaybutton = new single_button($url, get_string('manualgrading', 'mod_lesson'), 'get');
$data = [
'edit' => [
'button' => $editbutton->export_for_template($output),
],
'gradeessays' => [
'button' => $essaybutton->export_for_template($output),
]
];
if ($this->lesson->can_manage()) {
$url = new moodle_url('/mod/lesson/edit.php', ['id' => $this->lesson->get_cm()->id]);
$editbutton = new single_button($url, get_string('editlesson', 'mod_lesson'), 'get', true);
$url = new moodle_url('/mod/lesson/essay.php', ['id' => $this->lesson->get_cm()->id]);
$essaybutton = new single_button($url, get_string('manualgrading', 'mod_lesson'), 'get');
$data += [
'edit' => [
'button' => $editbutton->export_for_template($output),
],
'gradeessays' => [
'button' => $essaybutton->export_for_template($output),
]
];
}
// Standard notification to indicate the lesson is being previewed.
if ($data) {
$message = new notification(get_string('lessonbeingpreviewed', 'mod_lesson'), notification::NOTIFY_INFO);
$data['notification'] = $message->export_for_template($output);
}
return $data;
}
}
@@ -99,6 +99,7 @@ class override_action_menu implements templatable, renderable {
]))->out(false)
];
}
$data['heading'] = get_string($type == 'user' ? 'useroverrides' : 'groupoverrides', 'mod_lesson');
return $data;
}
}
@@ -57,9 +57,9 @@ class report_action_menu implements templatable, renderable {
* Export this url select menu for navigating between reports.
*
* @param \renderer_base $output Renderer output.
* @return \stdClass The data for a url_select element.
* @return array The data for the template.
*/
public function export_for_template(\renderer_base $output): \stdClass {
public function export_for_template(\renderer_base $output): array {
$overviewlink = new moodle_url('/mod/lesson/report.php', ['id' => $this->lessonid, 'action' => 'reportoverview']);
$fulllink = new moodle_url('/mod/lesson/report.php', ['id' => $this->lessonid, 'action' => 'reportdetail']);
$menu = [
@@ -67,6 +67,10 @@ class report_action_menu implements templatable, renderable {
$fulllink->out(false) => get_string('detailedstats', 'mod_lesson')
];
$reportselect = new \url_select($menu, $this->url->out(false), null, 'lesson-report-select');
return $reportselect->export_for_template($output);
$data = [
'reportselect' => $reportselect->export_for_template($output),
'heading' => $menu[$reportselect->selected]
];
return $data;
}
}
+3
View File
@@ -84,6 +84,9 @@ $PAGE->set_subpage($page->id);
lesson_add_fake_blocks($PAGE, $cm, $lesson, $timer);
echo $lessonoutput->header($lesson, $cm, 'view', true, $page->id, get_string('continue', 'lesson'));
$editbuttons = new \mod_lesson\output\edit_action_buttons($lesson, $page->id ?? null);
echo $lessonoutput->render($editbuttons);
if ($lesson->displayleft) {
echo '<a name="maincontent" id="maincontent" title="'.get_string('anchortitle', 'lesson').'"></a>';
}
+1
View File
@@ -48,6 +48,7 @@ $PAGE->set_url($url);
$PAGE->force_settings_menu();
$PAGE->set_secondary_active_tab('modulepage');
$PAGE->add_body_class('limitedwidth');
$PAGE->activityheader->set_description('');
if ($mode != get_user_preferences('lesson_view', 'collapsed') && $mode !== 'single') {
set_user_preference('lesson_view', $mode);
+4
View File
@@ -183,6 +183,8 @@ $string['editendofcluster'] = 'Editing an end of cluster page';
$string['editendofbranch'] = 'Editing an end of branch page';
$string['editessay'] = 'Editing an Essay question page';
$string['editingquestionpage'] = 'Editing {$a} question page';
$string['editlesson'] = 'Edit lesson';
$string['editinglesson'] = 'Editing lesson';
$string['editlessonsettings'] = 'Edit lesson settings';
$string['editmatching'] = 'Editing a Matching question page';
$string['editmultichoice'] = 'Editing a Multichoice question page';
@@ -295,6 +297,7 @@ $string['leftduringtimednoretake'] = 'You have left during a timed lesson and yo
$string['lesson:addinstance'] = 'Add a new lesson';
$string['lesson:grade'] = 'Grade lesson essay questions';
$string['lessonclosed'] = 'This lesson closed on {$a}.';
$string['lessonbeingpreviewed'] = 'Lesson is currently being previewed.';
$string['lessoncloses'] = 'Lesson closes';
$string['lessoneventcloses'] = '{$a} closes';
$string['lesson:edit'] = 'Edit a lesson activity';
@@ -385,6 +388,7 @@ $string['noonehasansweredgroup'] = 'No one in {$a} has answered an essay questio
$string['noonecheckedthis'] = 'No one checked this.';
$string['noopen'] = 'No open date';
$string['nooverridedata'] = 'You must override at least one of the lesson settings.';
$string['nooverridecreated'] = 'No overrides created.';
$string['noretake'] = 'You are not allowed to retake this lesson.';
$string['normal'] = 'Normal - follow lesson path';
$string['notcompleted'] = 'Not completed';
+10 -4
View File
@@ -67,15 +67,15 @@ $PAGE->set_pagelayout('admin');
$PAGE->add_body_class('limitedwidth');
$PAGE->set_title(get_string('overrides', 'lesson'));
$PAGE->set_heading($course->fullname);
$PAGE->activityheader->set_attrs([
'hidecompletion' => true,
'description' => ''
]);
navigation_node::override_active_url(new moodle_url('/mod/lesson/overrides.php', ['cmid' => $cmid]));
$renderer = $PAGE->get_renderer('mod_lesson');
echo $OUTPUT->header();
if (!$PAGE->has_secondary_navigation()) {
echo $OUTPUT->heading(format_string($lesson->name, true, array('context' => $context)));
}
// Delete orphaned group overrides.
$sql = 'SELECT o.id
@@ -332,6 +332,12 @@ echo html_writer::start_tag('div', array('id' => 'lessonoverrides'));
if (count($table->data)) {
echo html_writer::table($table);
}
// No overrides to be displayed.
if (!$overrides) {
echo $OUTPUT->notification(get_string('nooverridecreated', 'lesson'), 'info', false);
}
if ($hasinactive) {
echo $OUTPUT->notification(get_string('inactiveoverridehelp', 'lesson'), 'dimmed_text');
}
-1
View File
@@ -52,7 +52,6 @@ class mod_lesson_renderer extends plugin_renderer_base {
// Header setup.
$this->page->set_title($title);
$this->page->set_heading($this->page->course->fullname);
lesson_add_header_buttons($cm, $context, $extraeditbuttons, $lessonpageid);
$canmanage = has_capability('mod/lesson:manage', $context);
$activityheader = $this->page->activityheader;
+1
View File
@@ -53,6 +53,7 @@ if ($action == 'reportdetail') {
}
$lessonoutput = $PAGE->get_renderer('mod_lesson');
$PAGE->activityheader->set_description('');
$reportactionmenu = new \mod_lesson\output\report_action_menu($id, $url);
$reportactionarea = $lessonoutput->render($reportactionmenu);
@@ -70,7 +70,7 @@
}}
<div class="container-fluid mb-2">
<div class="row">
<div class="pr-1">
<div class="pr-2">
<a class="btn btn-secondary" href="{{back.link}}">{{back.text}}</a>
</div>
<div>
@@ -80,4 +80,5 @@
</div>
</div>
</div>
<h3>{{heading}}</h3>
@@ -29,6 +29,7 @@
{
"edit": {
"button": {
"id" : "id1",
"method" : "get",
"url" : "#",
"formid": "1",
@@ -45,6 +46,7 @@
},
"gradeessays": {
"button": {
"id" : "id2",
"method" : "get",
"url" : "#",
"formid": "2",
@@ -64,20 +66,29 @@
}}
<div class="container-fluid mb-2">
<div class="row">
<div class="col-xs-6 pr-1">
{{#edit}}
{{#edit}}
<div class="col-xs-6 pr-2">
{{#button}}
{{>core/single_button}}
{{/button}}
{{/edit}}
</div>
<div class="col-xs-6">
{{#gradeessays}}
</div>
{{/edit}}
{{#editcontents}}
<div class="col-xs-6 pr-2">
{{#button}}
{{>core/single_button}}
{{/button}}
{{/gradeessays}}
</div>
</div>
{{/editcontents}}
{{#gradeessays}}
<div class="col-xs-6">
{{#button}}
{{>core/single_button}}
{{/button}}
</div>
{{/gradeessays}}
</div>
</div>
{{#notification}}
{{> core/notification }}
{{/notification}}
@@ -76,9 +76,10 @@
{{/urlselect}}
</div>
{{#addoverride}}
<div class="col-sm-6">
<div class="col-sm-6 pl-2">
<a class="btn btn-primary" href="{{link}}">{{text}}</a>
</div>
{{/addoverride}}
</div>
</div>
<h3>{{heading}}</h3>
@@ -63,7 +63,10 @@
}}
<div class="container-fluid mb-2">
<div class="row">
{{>core/url_select}}
</div>
{{#reportselect}}
<div class="row">
{{>core/url_select}}
</div>
{{/reportselect}}
</div>
<h3>{{heading}}</h3>
@@ -69,10 +69,10 @@ class behat_mod_lesson_behat extends behat_base {
*/
public function i_edit_the_lesson(): void {
try {
$this->execute("behat_general::click_link", [get_string('edit', 'mod_lesson')]);
$this->execute("behat_general::click_link", [get_string('editlesson', 'mod_lesson')]);
} catch (ElementNotFoundException $e) {
$this->execute("behat_general::i_click_on_in_the",
[get_string('edit', 'mod_lesson'), 'button', 'region-main', 'region']
[get_string('editlesson', 'mod_lesson'), 'button', 'region-main', 'region']
);
}
}
@@ -21,6 +21,13 @@ Feature: Display the lesson description in the lesson and optionally in the cour
| name | Test lesson name |
| intro | Test lesson description |
| section | 1 |
And I am on the "Test lesson name" "lesson activity" page logged in as teacher1
And I follow "Add a content page"
And I set the following fields to these values:
| Page title | Test lesson part 1 |
| Description | Lesson part 1 description |
| Jump | Next page |
And I click on "Save page" "button"
And I log in as "teacher1"
Scenario: Description is displayed in the Lesson
+3 -1
View File
@@ -61,7 +61,7 @@ $canmanage = $lesson->can_manage();
$lessonoutput = $PAGE->get_renderer('mod_lesson');
$editbuttons = new \mod_lesson\output\edit_action_buttons($id, $canmanage);
$editbuttons = new \mod_lesson\output\edit_action_buttons($lesson);
$reviewmode = $lesson->is_in_review_mode();
@@ -238,6 +238,7 @@ if ($pageid != LESSON_EOL) {
lesson_add_fake_blocks($PAGE, $cm, $lesson, $timer);
echo $lessonoutput->header($lesson, $cm, $currenttab, $extraeditbuttons, $lessonpageid, $extrapagetitle);
$editbuttons->set_currentpage($lessonpageid);
echo $lessonoutput->render($editbuttons);
if ($attemptflag) {
@@ -266,6 +267,7 @@ if ($pageid != LESSON_EOL) {
lesson_add_fake_blocks($PAGE, $cm, $lesson, $timer);
echo $lessonoutput->header($lesson, $cm, $currenttab, $extraeditbuttons, $lessonpageid, get_string("congratulations", "lesson"));
$editbuttons->set_currentpage($lessonpageid);
echo $lessonoutput->render($editbuttons);
echo $lessoncontent;
echo $lessonoutput->footer();