Skip to content

Commit

Permalink
Additional view modes for assignment solutions.
Browse files Browse the repository at this point in the history
  • Loading branch information
krulis-martin committed Jul 30, 2023
1 parent dd220be commit 6aeb6c6
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/locales/cs.json
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,12 @@
"app.assignmentSolutions.pendingReviews": "V tuto chvíli {count, plural, one {je otevřena} =2 {jsou otevřeny} =3 {jsou otevřeny} =4 {jsou otevřeny} other {je otevřeno}} {count} {count, plural, one {revize} =2 {revize} =3 {revize} =4 {revize} other {revizí}} ze všech řešení vybrané úlohy. Nezapomeňte, že autoři úloh vidí vaše komentáře zdrojových kódů až poté, co jsou příslušné revize uzavřeny.",
"app.assignmentSolutions.plagiarismsDetected": "V seznamu {count, plural, one {je zobrazeno} =2 {jsou zobrazena} =3 {jsou zobrazena} =4 {jsou zobrazena} other {je zobrazeno}} {count} řešení, {count, plural, one {ke kterému} other {ke kterým}} byla nelezena podobná řešení. V takových případech se může jednat o plagiáty.",
"app.assignmentSolutions.title": "Všechna řešení zadané úlohy",
"app.assignmentSolutions.viewModes.accepted": "Pouze akceptovaná řešení",
"app.assignmentSolutions.viewModes.best": "Pouze nejlepší řešení",
"app.assignmentSolutions.viewModes.default": "Všechna řešení (výchozí)",
"app.assignmentSolutions.viewModes.grouped": "Seskupit dle uživatelů",
"app.assignmentSolutions.viewModes.last": "Pouze poslední řešení",
"app.assignmentSolutions.viewModes.reviewed": "Pouze revidovaná řešení",
"app.assignmentSolutions.viewModesTitle": "Vyberte způsob zobrazení řešení",
"app.assignments.deadline": "Termín odevzdání",
"app.assignments.deleteAllButton": "Smazat",
Expand Down
3 changes: 3 additions & 0 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,12 @@
"app.assignmentSolutions.pendingReviews": "There {count, plural, one {is} other {are}} {count} pending {count, plural, one {review} other {reviews}} among the solutions of the selected assignment. Remember that the review comments are visible to the author after a review is closed.",
"app.assignmentSolutions.plagiarismsDetected": "There {count, plural, one {is} other {are}} {count} {count, plural, one {solution} other {solutions}} with detected similarities. Such solutions may be plagiarisms.",
"app.assignmentSolutions.title": "All Submissions of The Assignment",
"app.assignmentSolutions.viewModes.accepted": "Accepted solutions only",
"app.assignmentSolutions.viewModes.best": "Best solutions only",
"app.assignmentSolutions.viewModes.default": "All solutions (default)",
"app.assignmentSolutions.viewModes.grouped": "Grouped by users",
"app.assignmentSolutions.viewModes.last": "Latest solutions only",
"app.assignmentSolutions.viewModes.reviewed": "Reviewed solutions only",
"app.assignmentSolutions.viewModesTitle": "Select solutions view filter",
"app.assignments.deadline": "Deadline",
"app.assignments.deleteAllButton": "Delete",
Expand Down
34 changes: 33 additions & 1 deletion src/pages/AssignmentSolutions/AssignmentSolutions.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,14 @@ import { storageGetItem, storageSetItem } from '../../helpers/localStorage';
import withLinks from '../../helpers/withLinks';
import { safeGet, identity, arrayToObject, toPlainAscii, hasPermissions } from '../../helpers/common';

// View mode keys, labels, and filtering functions
const VIEW_MODE_DEFAULT = 'default';
const VIEW_MODE_GROUPED = 'grouped';
const VIEW_MODE_BEST = 'best';
const VIEW_MODE_LAST = 'last';
const VIEW_MODE_ACCEPTED = 'accepted';
const VIEW_MODE_REVIEWD = 'reviewed';

const viewModes = {
[VIEW_MODE_DEFAULT]: (
<FormattedMessage id="app.assignmentSolutions.viewModes.default" defaultMessage="All solutions (default)" />
Expand All @@ -82,6 +87,33 @@ const viewModes = {
[VIEW_MODE_BEST]: (
<FormattedMessage id="app.assignmentSolutions.viewModes.best" defaultMessage="Best solutions only" />
),
[VIEW_MODE_LAST]: (
<FormattedMessage id="app.assignmentSolutions.viewModes.last" defaultMessage="Latest solutions only" />
),
[VIEW_MODE_ACCEPTED]: (
<FormattedMessage id="app.assignmentSolutions.viewModes.accepted" defaultMessage="Accepted solutions only" />
),
[VIEW_MODE_REVIEWD]: (
<FormattedMessage id="app.assignmentSolutions.viewModes.reviewed" defaultMessage="Reviewed solutions only" />
),
};

const _getLastAttemptIndices = defaultMemoize(solutions => {
const lastAttemptIndices = {};
solutions.filter(identity).forEach(s => {
lastAttemptIndices[s.authorId] = Math.max(s.attemptIndex || 0, lastAttemptIndices[s.authorId] || 0);
});
return lastAttemptIndices;
});

const viewModeFilters = {
[VIEW_MODE_DEFAULT]: null,
[VIEW_MODE_GROUPED]: null,
[VIEW_MODE_BEST]: solution => solution && solution.isBestSolution,
[VIEW_MODE_LAST]: (solution, _, solutions) =>
solution && solution.attemptIndex === _getLastAttemptIndices(solutions)[solution.authorId],
[VIEW_MODE_ACCEPTED]: solution => solution && solution.accepted,
[VIEW_MODE_REVIEWD]: solution => solution && solution.review,
};

const prepareTableColumnDescriptors = defaultMemoize((loggedUserId, assignmentId, groupId, viewMode, locale, links) => {
Expand Down Expand Up @@ -262,7 +294,7 @@ const prepareTableData = defaultMemoize(
.toArray()
.map(getJsData)
.filter(solution => solution && usersIndex[solution.authorId])
.filter(viewMode === VIEW_MODE_BEST ? solution => solution && solution.isBestSolution : identity)
.filter(viewModeFilters[viewMode] || identity)
.map(
({
id,
Expand Down

0 comments on commit 6aeb6c6

Please sign in to comment.