Skip to content

Commit

Permalink
BC-6609 Sort files in submission by parentType (#3428)
Browse files Browse the repository at this point in the history
  • Loading branch information
dyedwiper authored Mar 25, 2024
1 parent 2c002d9 commit 782b958
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
12 changes: 7 additions & 5 deletions controllers/homework.js
Original file line number Diff line number Diff line change
Expand Up @@ -577,29 +577,31 @@ router.get('/:assignmentId', (req, res, next) => {
async function findSubmissionFiles(submission, submitters, teachers, readonly) {
const { schoolId } = submission;
const parentId = submission._id;
const parentType = 'submissions';
const submissionParentType = 'submissions';
const gradeParentType = 'gradings';
const isTeacher = teachers.has(res.locals.currentUser._id);
const isCreator = submitters.has(res.locals.currentUser._id);
let filesStorage = {
schoolId,
parentId,
parentType,
files: [],
readonly,
};

if (submission.submitted || isCreator) {
const result = await filesStoragesHelper.filesStorageInit(schoolId, parentId, parentType, readonly, req);
const result = await filesStoragesHelper.filesStorageInit(schoolId, parentId, submissionParentType, readonly, req);
// eslint-disable-next-line prefer-destructuring
filesStorage = result.filesStorage;
}

const submissionFilesStorageData = _.clone(filesStorage);
submissionFilesStorageData.files = filesStorage.files.filter((file) => !file.creatorId || submitters.has(file.creatorId));
submissionFilesStorageData.files = filesStorage.files.filter((file) => file.parentType === submissionParentType);
submissionFilesStorageData.parentType = submissionParentType;
submissionFilesStorageData.readonly = readonly || (!isCreator && isTeacher);

const gradeFilesStorageData = _.clone(filesStorage);
gradeFilesStorageData.files = filesStorage.files.filter((file) => !file.creatorId || teachers.has(file.creatorId));
gradeFilesStorageData.files = filesStorage.files.filter((file) => file.parentType === gradeParentType);
gradeFilesStorageData.parentType = gradeParentType;
gradeFilesStorageData.readonly = !isTeacher;

submission.submissionFiles = { filesStorage: submissionFilesStorageData };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default class FileBrowserHelper {
sourceElement.setAttribute('data-parent-id', parentId);
$('.section-upload').attr('data-parent-id', parentId);

if (parentType === 'submissions') {
if (parentType === 'submissions' || parentType === 'gradings') {
const referrer = `/homework/${homeworkId}#activetabid=submission`;
$('input[name="referrer"]').val(referrer);
} else {
Expand Down
2 changes: 1 addition & 1 deletion static/scripts/files-storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ function submitAfterUpload(type, id) {
$('#homework-form').trigger('submit');
}

if (type === 'submissions') {
if (type === 'submissions' || type === 'gradings') {
window.localStorage.setItem('afterUploadFiles', 'true');
$(`form.${id}`).trigger('submit');
}
Expand Down
2 changes: 1 addition & 1 deletion views/homework/evaluation.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
placeholder="{{$t "homework.input.gradeComment"}}"
data-parent-id="{{this.submission._id}}"
data-school-id="{{this.submission.schoolId}}"
data-parent-type="submissions"
data-parent-type="gradings"
data-testid="submission-comment"
>
{{this.submission.gradeComment}}
Expand Down

0 comments on commit 782b958

Please sign in to comment.