Skip to content

Commit

Permalink
MDL-78666 core_courseformat: Add empty state in conditions dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
roland04 committed Aug 10, 2023
1 parent 848a90d commit fd48f18
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 56 deletions.
Expand Up @@ -110,6 +110,7 @@ private function get_completion_dialog(\renderer_base $output, stdClass $complet
);
$completioninfo->editurl = $editurl->out(false);
$completioninfo->editing = $PAGE->user_is_editing();
$completioninfo->hasconditions = $completioninfo->ismanual || count($completioninfo->completiondetails) > 0;
$dialogcontent = $output->render_from_template('core_courseformat/local/content/cm/completion_dialog', $completioninfo);

$buttoncontent = get_string('completionmenuitem', 'completion');
Expand Down
128 changes: 72 additions & 56 deletions course/format/templates/local/content/cm/completion_dialog.mustache
Expand Up @@ -19,6 +19,7 @@
Example context (json):
{
"istrackeduser": true,
"hasconditions": true,
"completiondetails": [
{
"statuscomplete": 1,
Expand All @@ -32,73 +33,88 @@
}
}}
<div class="completion-dialog px-2">
{{! Dialog header. }}
{{#istrackeduser}}
<strong>{{#str}}youmust, completion{{/str}}</strong>
{{/istrackeduser}}
{{^istrackeduser}}
<strong>{{#str}}studentsmust, completion{{/str}}</strong>
{{/istrackeduser}}
{{! Completion criterias. }}
{{#hasconditions}}
{{! Dialog header. }}
{{#istrackeduser}}
<strong>{{#str}}youmust, completion{{/str}}</strong>
{{/istrackeduser}}
{{^istrackeduser}}
<strong>{{#str}}studentsmust, completion{{/str}}</strong>
{{/istrackeduser}}

{{! Completion criterias.}}
<div class="ml-2" role="list">
{{#completiondetails}}
{{! Show completion status and description to tracked users. }}
{{#istrackeduser}}
{{#statuscomplete}}
<div class="d-flex mt-2 text-success" role="listitem" {{#accessibledescription}}title="{{.}}" aria-label="{{.}}"{{/accessibledescription}}>
<div>
{{#pix}}i/checked{{/pix}}
<span class="sr-only">{{#str}}completion_automatic:done, core_course{{/str}}</span>
<div class="ml-2" role="list">
{{#completiondetails}}
{{! Show completion status and description to tracked users. }}
{{#istrackeduser}}
{{#statuscomplete}}
<div class="d-flex mt-2 text-success" role="listitem" {{#accessibledescription}}title="{{.}}" aria-label="{{.}}"{{/accessibledescription}}>
<div>
{{#pix}}i/checked{{/pix}}
<span class="sr-only">{{#str}}completion_automatic:done, core_course{{/str}}</span>
</div>
<span>{{description}}</span>
</div>
<span>{{description}}</span>
</div>
{{/statuscomplete}}
{{#statuscompletefail}}
<div class="d-flex mt-2 text-danger" role="listitem" {{#accessibledescription}}title="{{.}}" aria-label="{{.}}"{{/accessibledescription}}>
<div>
{{#pix}}e/cancel{{/pix}}
<span class="sr-only">{{#str}}completion_automatic:failed, core_course{{/str}}</span>
{{/statuscomplete}}
{{#statuscompletefail}}
<div class="d-flex mt-2 text-danger" role="listitem" {{#accessibledescription}}title="{{.}}" aria-label="{{.}}"{{/accessibledescription}}>
<div>
{{#pix}}e/cancel{{/pix}}
<span class="sr-only">{{#str}}completion_automatic:failed, core_course{{/str}}</span>
</div>
<span>{{description}}</span>
</div>
<span>{{description}}</span>
</div>
{{/statuscompletefail}}
{{#statusincomplete}}
<div class="d-flex mt-2" role="listitem" {{#accessibledescription}}title="{{.}}" aria-label="{{.}}"{{/accessibledescription}}>
<div>
{{#pix}}i/dot{{/pix}}
<span class="sr-only">{{#str}}completion_automatic:todo, core_course{{/str}}</span>
{{/statuscompletefail}}
{{#statusincomplete}}
<div class="d-flex mt-2" role="listitem" {{#accessibledescription}}title="{{.}}" aria-label="{{.}}"{{/accessibledescription}}>
<div>
{{#pix}}i/dot{{/pix}}
<span class="sr-only">{{#str}}completion_automatic:todo, core_course{{/str}}</span>
</div>
<span>{{description}}</span>
</div>
<span>{{description}}</span>
</div>
{{/statusincomplete}}
{{/istrackeduser}}
{{/statusincomplete}}
{{/istrackeduser}}

{{! Show only description (without status) to non-tracked users. }}
{{^istrackeduser}}
<div class="d-flex mt-2" role="listitem">
<div>{{#pix}}i/dot{{/pix}}</div>
<span>{{description}}</span>
</div>
{{/istrackeduser}}
{{/completiondetails}}
{{! Show only description (without status) to non-tracked users. }}
{{^istrackeduser}}
<div class="d-flex mt-2" role="listitem">
<div>{{#pix}}i/dot{{/pix}}</div>
<span>{{description}}</span>
</div>
{{/istrackeduser}}
{{/completiondetails}}

{{! Show also manual completion description in the list to non-tracked users. }}
{{#ismanual}}
{{^istrackeduser}}
<div class="d-flex mt-2" role="listitem">
<div>{{#pix}}i/dot{{/pix}}</div>
<span>{{#str}} completion_manual:markdone, core_course {{/str}}</span>
</div>
{{/istrackeduser}}
{{/ismanual}}
</div>
{{/hasconditions}}

{{! Show also manual completion description in the list to non-tracked users. }}
{{#ismanual}}
{{^istrackeduser}}
<div class="d-flex mt-2" role="listitem">
<div>{{#pix}}i/dot{{/pix}}</div>
<span>{{#str}} completion_manual:markdone, core_course {{/str}}</span>
</div>
{{/istrackeduser}}
{{/ismanual}}
</div>
{{! Show message if there are no completion criterias. }}
{{^hasconditions}}
{{#istrackeduser}}
<span>{{#str}}emptyconditionsinfo, completion{{/str}}</span>
{{/istrackeduser}}
{{^istrackeduser}}
<span class="text-danger">{{#pix}} req, core {{/pix}}{{#str}}emptyconditionswarning, completion{{/str}}</span>
{{/istrackeduser}}
{{/hasconditions}}

{{! Show edit link to editing teachers. }}
{{#editing}}
{{#editurl}}
<div class="editcompletion border-top mt-3 pt-3">
<a href="{{editurl}}" class="px-2 py-1">{{#pix}} i/edit, core {{/pix}}{{#str}}editconditions, completion{{/str}}</a>
<a href="{{editurl}}" class="px-2 py-1">
{{#hasconditions}}{{#pix}} i/edit, core {{/pix}}{{#str}}editconditions, completion{{/str}}{{/hasconditions}}
{{^hasconditions}}{{#pix}} t/add, core {{/pix}}{{#str}}addconditions, completion{{/str}}{{/hasconditions}}
</a>
</div>
{{/editurl}}
{{/editing}}
Expand Down
17 changes: 17 additions & 0 deletions course/format/tests/behat/coursepage_completion.feature
Expand Up @@ -87,3 +87,20 @@ Feature: Course page activities completion
And I should see "Activity sample" in the "page-header" "region"
And I should see "Updating: Assignment"
And I should see "Activity completion"

Scenario: Completion dialog shows warning message if there are no criterias
# Create an activity with automatic completion but without completion criterias.
Given the following "activity" exists:
| activity | assign |
| name | Activity sample |
| course | C1 |
| completion | 2 |
# Teacher view.
When I am on the "C1" "Course" page logged in as "teacher1"
And I turn editing mode on
And "You have to add at least one completion condition." "text" should exist in the "Activity sample" "core_courseformat > Activity completion"
And "Add conditions" "link" should exist in the "Activity sample" "core_courseformat > Activity completion"
And I log out
# Student view.
And I am on the "C1" "Course" page logged in as "student1"
And "There are no completion conditions set for this activity." "text" should exist in the "Activity sample" "core_courseformat > Activity completion"
3 changes: 3 additions & 0 deletions lang/en/completion.php
Expand Up @@ -37,6 +37,7 @@
$string['activitycompletionupdated'] = 'Changes saved';
$string['activitygradenotrequired'] = 'Grade not required';
$string['activitygradetopassnotset'] = 'This activity does not have a valid grade to pass set. It may be set in the Grade section of the activity settings.';
$string['addconditions'] = 'Add conditions';
$string['affectedactivities'] = 'The changes will affect the following <b>{$a}</b> activities or resources:';
$string['aggregationmethod'] = 'Aggregation method';
$string['all'] = 'All';
Expand Down Expand Up @@ -159,6 +160,8 @@
$string['enablecompletion_help'] = 'If enabled, activity completion conditions may be set in the activity settings and/or course completion conditions may be set. It is recommended to have this enabled so that meaningful data is displayed in the course overview on the Dashboard.';
$string['enrolmentduration'] = 'Enrolment duration';
$string['enrolmentdurationlength'] = 'User must remain enrolled for';
$string['emptyconditionsinfo'] = 'There are no completion conditions set for this activity.';
$string['emptyconditionswarning'] = 'You have to add at least one completion condition.';
$string['err_noactivities'] = 'Completion information is not enabled for any activity, so none can be displayed. You can enable completion information by editing the settings for an activity.';
$string['err_nocourses'] = 'Course completion is not enabled for any other courses, so none can be displayed. You can enable course completion in the course settings.';
$string['err_nograde'] = 'A course pass grade has not been set for this course. To enable this criteria type you must create a pass grade for this course.';
Expand Down

0 comments on commit fd48f18

Please sign in to comment.