MDL-67144 mod_forum: If no users exist do not show the grading interface
authorMathew May <mathewm@hotmail.co.nz>
Thu, 14 Nov 2019 03:49:25 +0000 (11:49 +0800)
committerMathew May <mathewm@hotmail.co.nz>
Thu, 14 Nov 2019 07:00:30 +0000 (15:00 +0800)
lang/en/grades.php
mod/forum/amd/build/local/grades/grader.min.js
mod/forum/amd/build/local/grades/grader.min.js.map
mod/forum/amd/src/local/grades/grader.js

index c60964c..649b684 100644 (file)
@@ -563,6 +563,7 @@ $string['noselecteditems'] = 'no items were selected.';
 $string['notteachererror'] = 'You must be a teacher to use this feature.';
 $string['notenrolled'] = 'You are currently not enrolled in any courses.';
 $string['nousersloaded'] = 'No users loaded';
+$string['nouserstograde'] = 'No users to grade';
 $string['numberofgrades'] = 'Number of grades';
 $string['onascaleof'] = 'on a scale of {$a->grademin} to {$a->grademax}';
 $string['operations'] = 'Operations';
index d6a8f84..45c4a7d 100644 (file)
Binary files a/mod/forum/amd/build/local/grades/grader.min.js and b/mod/forum/amd/build/local/grades/grader.min.js differ
index 49c47b3..2b554b9 100644 (file)
Binary files a/mod/forum/amd/build/local/grades/grader.min.js.map and b/mod/forum/amd/build/local/grades/grader.min.js.map differ
index 44acca8..f2c4aa9 100644 (file)
@@ -27,6 +27,7 @@ import getUserPicker from './local/grader/user_picker';
 import {createLayout as createFullScreenWindow} from 'mod_forum/local/layout/fullscreen';
 import getGradingPanelFunctions from './local/grader/gradingpanel';
 import {add as addToast} from 'core/toast';
+import {addNotification} from 'core/notification';
 import {get_string as getString} from 'core/str';
 import {failedUpdate} from 'core_grades/grades/grader/gradingpanel/normalise';
 import {addIconToContainerWithPromise} from 'core/loadingicon';
@@ -342,10 +343,21 @@ export const launch = async(getListOfUsers, getContentForUser, getGradeForUser,
 
     // We need all of these functions to be executed in series, if one step runs before another the interface
     // will not work.
+
+    // We need this promise to resolve separately so that we can avoid loading the whole interface if there are no users.
+    const userList = await getListOfUsers();
+    if (!userList.length) {
+        addNotification({
+            message: await getString('nouserstograde', 'core_grades'),
+            type: "error",
+        });
+        return;
+    }
+
+    // Now that we have confirmed there are at least some users let's boot up the grader interface.
     const [
         graderLayout,
         {html, js},
-        userList,
     ] = await Promise.all([
         createFullScreenWindow({
             fullscreen: false,
@@ -359,8 +371,8 @@ export const launch = async(getListOfUsers, getContentForUser, getGradeForUser,
             drawer: {show: true},
             defaultsendnotifications: sendStudentNotifications,
         }),
-        getListOfUsers(),
     ]);
+
     const graderContainer = graderLayout.getContainer();
 
     const saveGradeFunction = getSaveUserGradeFunction(graderContainer, setGradeForUser);