MOBILE-3787 assign: Add enums to different states

main
Pau Ferrer Ocaña 2022-01-13 10:44:47 +01:00
parent 03ccd02636
commit 7cdafca794
8 changed files with 152 additions and 96 deletions

View File

@ -18,13 +18,14 @@ import { CoreGroupInfo, CoreGroups } from '@services/groups';
import { CoreSites } from '@services/sites'; import { CoreSites } from '@services/sites';
import { CoreUtils } from '@services/utils/utils'; import { CoreUtils } from '@services/utils/utils';
import { Translate } from '@singletons'; import { Translate } from '@singletons';
import { CoreIonicColorNames } from '@singletons/colors';
import { CoreEvents } from '@singletons/events'; import { CoreEvents } from '@singletons/events';
import { import {
AddonModAssign, AddonModAssign,
AddonModAssignAssign, AddonModAssignAssign,
AddonModAssignGrade, AddonModAssignGradingStates,
AddonModAssignProvider,
AddonModAssignSubmission, AddonModAssignSubmission,
AddonModAssignSubmissionStatusValues,
} from '../services/assign'; } from '../services/assign';
import { AddonModAssignHelper, AddonModAssignSubmissionFormatted } from '../services/assign-helper'; import { AddonModAssignHelper, AddonModAssignSubmissionFormatted } from '../services/assign-helper';
import { AddonModAssignOffline } from '../services/assign-offline'; import { AddonModAssignOffline } from '../services/assign-offline';
@ -38,15 +39,15 @@ export class AddonModAssignSubmissionsSource extends CoreRoutedItemsManagerSourc
/** /**
* @inheritdoc * @inheritdoc
*/ */
static getSourceId(courseId: number, moduleId: number, selectedStatus?: string): string { static getSourceId(courseId: number, moduleId: number, selectedStatus?: AddonModAssignListFilterName): string {
selectedStatus = selectedStatus ?? '__empty__'; const statusId = selectedStatus ?? '__empty__';
return `submissions-${courseId}-${moduleId}-${selectedStatus}`; return `submissions-${courseId}-${moduleId}-${statusId}`;
} }
readonly COURSE_ID: number; readonly COURSE_ID: number;
readonly MODULE_ID: number; readonly MODULE_ID: number;
readonly SELECTED_STATUS: string | undefined; readonly SELECTED_STATUS: AddonModAssignListFilterName | undefined;
assign?: AddonModAssignAssign; assign?: AddonModAssignAssign;
groupId = 0; groupId = 0;
@ -62,7 +63,7 @@ export class AddonModAssignSubmissionsSource extends CoreRoutedItemsManagerSourc
canviewsubmissions: false, canviewsubmissions: false,
}; };
constructor(courseId: number, moduleId: number, selectedStatus?: string) { constructor(courseId: number, moduleId: number, selectedStatus?: AddonModAssignListFilterName) {
super(); super();
this.COURSE_ID = courseId; this.COURSE_ID = courseId;
@ -169,8 +170,8 @@ export class AddonModAssignSubmissionsSource extends CoreRoutedItemsManagerSourc
: []; : [];
// Filter the submissions to get only the ones with the right status and add some extra data. // Filter the submissions to get only the ones with the right status and add some extra data.
const getNeedGrading = this.SELECTED_STATUS == AddonModAssignProvider.NEED_GRADING; const getNeedGrading = this.SELECTED_STATUS == AddonModAssignListFilterName.NEED_GRADING;
const searchStatus = getNeedGrading ? AddonModAssignProvider.SUBMISSION_STATUS_SUBMITTED : this.SELECTED_STATUS; const searchStatus = getNeedGrading ? AddonModAssignSubmissionStatusValues.SUBMITTED : this.SELECTED_STATUS;
const showSubmissions: AddonModAssignSubmissionForList[] = []; const showSubmissions: AddonModAssignSubmissionForList[] = [];
@ -192,7 +193,7 @@ export class AddonModAssignSubmissionsSource extends CoreRoutedItemsManagerSourc
// Load offline grades. // Load offline grades.
const notSynced = !!gradeData && submission.timemodified < gradeData.timemodified; const notSynced = !!gradeData && submission.timemodified < gradeData.timemodified;
if (submission.gradingstatus == 'graded' && !assign.markingworkflow) { if (submission.gradingstatus == AddonModAssignGradingStates.GRADED && !assign.markingworkflow) {
// Get the last grade of the submission. // Get the last grade of the submission.
const grade = grades const grade = grades
.filter((grade) => grade.userid == submission.userid) .filter((grade) => grade.userid == submission.userid)
@ -202,7 +203,7 @@ export class AddonModAssignSubmissionsSource extends CoreRoutedItemsManagerSourc
); );
if (grade && grade.timemodified < submission.timemodified) { if (grade && grade.timemodified < submission.timemodified) {
submission.gradingstatus = AddonModAssignProvider.GRADED_FOLLOWUP_SUBMIT; submission.gradingstatus = AddonModAssignGradingStates.GRADED_FOLLOWUP_SUBMIT;
} }
} }
submission.statusColor = AddonModAssign.getSubmissionStatusColor(submission.status); submission.statusColor = AddonModAssign.getSubmissionStatusColor(submission.status);
@ -217,7 +218,8 @@ export class AddonModAssignSubmissionsSource extends CoreRoutedItemsManagerSourc
if (notSynced) { if (notSynced) {
submission.gradingStatusTranslationId = 'addon.mod_assign.gradenotsynced'; submission.gradingStatusTranslationId = 'addon.mod_assign.gradenotsynced';
submission.gradingColor = ''; submission.gradingColor = '';
} else if (submission.statusColor != 'danger' || submission.gradingColor != 'danger') { } else if (submission.statusColor != CoreIonicColorNames.DANGER ||
submission.gradingColor != CoreIonicColorNames.DANGER) {
// Show grading status if one of the statuses is not done. // Show grading status if one of the statuses is not done.
submission.gradingStatusTranslationId = AddonModAssign.getSubmissionGradingStatusTranslationId( submission.gradingStatusTranslationId = AddonModAssign.getSubmissionGradingStatusTranslationId(
submission.gradingstatus, submission.gradingstatus,
@ -245,3 +247,13 @@ export type AddonModAssignSubmissionForList = AddonModAssignSubmissionFormatted
statusTranslated?: string; // Calculated in the app. Translated text of the submission status. statusTranslated?: string; // Calculated in the app. Translated text of the submission status.
gradingStatusTranslationId?: string; // Calculated in the app. Key of the text of the submission grading status. gradingStatusTranslationId?: string; // Calculated in the app. Key of the text of the submission grading status.
}; };
/**
* List filter by status name.
*/
export enum AddonModAssignListFilterName {
ALL = '',
NEED_GRADING = 'needgrading',
DRAFT = 'draft',
SUBMITTED = 'submitted',
};

View File

@ -28,6 +28,7 @@ import { CoreTimeUtils } from '@services/utils/time';
import { CoreUtils } from '@services/utils/utils'; import { CoreUtils } from '@services/utils/utils';
import { Translate } from '@singletons'; import { Translate } from '@singletons';
import { CoreEventObserver, CoreEvents } from '@singletons/events'; import { CoreEventObserver, CoreEvents } from '@singletons/events';
import { AddonModAssignListFilterName } from '../../classes/submissions-source';
import { import {
AddonModAssign, AddonModAssign,
AddonModAssignAssign, AddonModAssignAssign,
@ -75,9 +76,9 @@ export class AddonModAssignIndexComponent extends CoreCourseModuleMainActivityCo
}; };
// Status. // Status.
submissionStatusSubmitted = AddonModAssignProvider.SUBMISSION_STATUS_SUBMITTED; submissionStatusSubmitted = AddonModAssignListFilterName.SUBMITTED;
submissionStatusDraft = AddonModAssignProvider.SUBMISSION_STATUS_DRAFT; submissionStatusDraft = AddonModAssignListFilterName.DRAFT;
needGrading = AddonModAssignProvider.NEED_GRADING; needGrading = AddonModAssignListFilterName.NEED_GRADING;
protected currentUserId!: number; // Current user ID. protected currentUserId!: number; // Current user ID.
protected currentSite!: CoreSite; // Current site. protected currentSite!: CoreSite; // Current site.
@ -311,7 +312,7 @@ export class AddonModAssignIndexComponent extends CoreCourseModuleMainActivityCo
* @param status Status to see. * @param status Status to see.
* @param hasSubmissions If the status has any submission. * @param hasSubmissions If the status has any submission.
*/ */
goToSubmissionList(status?: string, hasSubmissions = false): void { goToSubmissionList(status?: AddonModAssignListFilterName, hasSubmissions = false): void {
if (status !== undefined && !hasSubmissions) { if (status !== undefined && !hasSubmissions) {
return; return;
} }

View File

@ -25,6 +25,9 @@ import {
AddonModAssign, AddonModAssign,
AddonModAssignGetSubmissionStatusWSResponse, AddonModAssignGetSubmissionStatusWSResponse,
AddonModAssignSavePluginData, AddonModAssignSavePluginData,
AddonModAssignGradingStates,
AddonModAssignSubmissionStatusValues,
AddonModAssignAttemptReopenMethodValues,
} from '../../services/assign'; } from '../../services/assign';
import { import {
AddonModAssignAutoSyncData, AddonModAssignAutoSyncData,
@ -125,9 +128,9 @@ export class AddonModAssignSubmissionComponent implements OnInit, OnDestroy, Can
showDates = false; // Whether to show some dates. showDates = false; // Whether to show some dates.
// Some constants. // Some constants.
statusNew = AddonModAssignProvider.SUBMISSION_STATUS_NEW; statusNew = AddonModAssignSubmissionStatusValues.NEW;
statusReopened = AddonModAssignProvider.SUBMISSION_STATUS_REOPENED; statusReopened = AddonModAssignSubmissionStatusValues.REOPENED;
attemptReopenMethodNone = AddonModAssignProvider.ATTEMPT_REOPEN_METHOD_NONE; attemptReopenMethodNone = AddonModAssignAttemptReopenMethodValues.NONE;
unlimitedAttempts = AddonModAssignProvider.UNLIMITED_ATTEMPTS; unlimitedAttempts = AddonModAssignProvider.UNLIMITED_ATTEMPTS;
protected siteId: string; // Current site ID. protected siteId: string; // Current site ID.
@ -214,7 +217,7 @@ export class AddonModAssignSubmissionComponent implements OnInit, OnDestroy, Can
} }
// Not submitted. // Not submitted.
if (!this.userSubmission || this.userSubmission.status != AddonModAssignProvider.SUBMISSION_STATUS_SUBMITTED) { if (!this.userSubmission || this.userSubmission.status != AddonModAssignSubmissionStatusValues.SUBMITTED) {
if (response.lastattempt?.submissionsenabled || response.gradingsummary?.submissionsenabled) { if (response.lastattempt?.submissionsenabled || response.gradingsummary?.submissionsenabled) {
this.timeRemaining = Translate.instant( this.timeRemaining = Translate.instant(
@ -651,7 +654,7 @@ export class AddonModAssignSubmissionComponent implements OnInit, OnDestroy, Can
// Treat the grade info. // Treat the grade info.
await this.treatGradeInfo(); await this.treatGradeInfo();
const isManual = this.assign!.attemptreopenmethod == AddonModAssignProvider.ATTEMPT_REOPEN_METHOD_MANUAL; const isManual = this.assign!.attemptreopenmethod == AddonModAssignAttemptReopenMethodValues.MANUAL;
const isUnlimited = this.assign!.maxattempts == AddonModAssignProvider.UNLIMITED_ATTEMPTS; const isUnlimited = this.assign!.maxattempts == AddonModAssignProvider.UNLIMITED_ATTEMPTS;
const isLessThanMaxAttempts = !!this.userSubmission && (this.userSubmission.attemptnumber < (this.assign!.maxattempts - 1)); const isLessThanMaxAttempts = !!this.userSubmission && (this.userSubmission.attemptnumber < (this.assign!.maxattempts - 1));
@ -668,7 +671,7 @@ export class AddonModAssignSubmissionComponent implements OnInit, OnDestroy, Can
if (this.lastAttempt?.gradingstatus == 'graded' && !this.assign!.markingworkflow && this.userSubmission && feedback) { if (this.lastAttempt?.gradingstatus == 'graded' && !this.assign!.markingworkflow && this.userSubmission && feedback) {
if (feedback.gradeddate < this.userSubmission.timemodified) { if (feedback.gradeddate < this.userSubmission.timemodified) {
this.lastAttempt.gradingstatus = AddonModAssignProvider.GRADED_FOLLOWUP_SUBMIT; this.lastAttempt.gradingstatus = AddonModAssignGradingStates.GRADED_FOLLOWUP_SUBMIT;
// Get grading text and color. // Get grading text and color.
this.gradingStatusTranslationId = AddonModAssign.getSubmissionGradingStatusTranslationId( this.gradingStatusTranslationId = AddonModAssign.getSubmissionGradingStatusTranslationId(
@ -749,43 +752,43 @@ export class AddonModAssignSubmissionComponent implements OnInit, OnDestroy, Can
* @param status Submission status. * @param status Submission status.
*/ */
protected setStatusNameAndClass(status: AddonModAssignGetSubmissionStatusWSResponse): void { protected setStatusNameAndClass(status: AddonModAssignGetSubmissionStatusWSResponse): void {
const translateService = Translate.instance;
if (this.hasOffline || this.submittedOffline) { if (this.hasOffline || this.submittedOffline) {
// Offline data. // Offline data.
this.statusTranslated = translateService.instant('core.notsent'); this.statusTranslated = Translate.instant('core.notsent');
this.statusColor = 'warning'; this.statusColor = 'warning';
} else if (!this.assign!.teamsubmission) { } else if (!this.assign!.teamsubmission) {
// Single submission. // Single submission.
if (this.userSubmission && this.userSubmission.status != this.statusNew) { if (this.userSubmission && this.userSubmission.status != this.statusNew) {
this.statusTranslated = translateService.instant('addon.mod_assign.submissionstatus_' + this.userSubmission.status); this.statusTranslated = Translate.instant('addon.mod_assign.submissionstatus_' + this.userSubmission.status);
this.statusColor = AddonModAssign.getSubmissionStatusColor(this.userSubmission.status); this.statusColor = AddonModAssign.getSubmissionStatusColor(this.userSubmission.status);
} else { } else {
if (!status.lastattempt?.submissionsenabled) { if (!status.lastattempt?.submissionsenabled) {
this.statusTranslated = translateService.instant('addon.mod_assign.noonlinesubmissions'); this.statusTranslated = Translate.instant('addon.mod_assign.noonlinesubmissions');
this.statusColor = AddonModAssign.getSubmissionStatusColor('noonlinesubmissions'); this.statusColor =
AddonModAssign.getSubmissionStatusColor(AddonModAssignSubmissionStatusValues.NO_ONLINE_SUBMISSIONS);
} else { } else {
this.statusTranslated = translateService.instant('addon.mod_assign.noattempt'); this.statusTranslated = Translate.instant('addon.mod_assign.noattempt');
this.statusColor = AddonModAssign.getSubmissionStatusColor('noattempt'); this.statusColor = AddonModAssign.getSubmissionStatusColor(AddonModAssignSubmissionStatusValues.NO_ATTEMPT);
} }
} }
} else { } else {
// Team submission. // Team submission.
if (!status.lastattempt?.submissiongroup && this.assign!.preventsubmissionnotingroup) { if (!status.lastattempt?.submissiongroup && this.assign!.preventsubmissionnotingroup) {
this.statusTranslated = translateService.instant('addon.mod_assign.nosubmission'); this.statusTranslated = Translate.instant('addon.mod_assign.nosubmission');
this.statusColor = AddonModAssign.getSubmissionStatusColor('nosubmission'); this.statusColor = AddonModAssign.getSubmissionStatusColor(AddonModAssignSubmissionStatusValues.NO_SUBMISSION);
} else if (this.userSubmission && this.userSubmission.status != this.statusNew) { } else if (this.userSubmission && this.userSubmission.status != this.statusNew) {
this.statusTranslated = translateService.instant('addon.mod_assign.submissionstatus_' + this.userSubmission.status); this.statusTranslated = Translate.instant('addon.mod_assign.submissionstatus_' + this.userSubmission.status);
this.statusColor = AddonModAssign.getSubmissionStatusColor(this.userSubmission.status); this.statusColor = AddonModAssign.getSubmissionStatusColor(this.userSubmission.status);
} else { } else {
if (!status.lastattempt?.submissionsenabled) { if (!status.lastattempt?.submissionsenabled) {
this.statusTranslated = translateService.instant('addon.mod_assign.noonlinesubmissions'); this.statusTranslated = Translate.instant('addon.mod_assign.noonlinesubmissions');
this.statusColor = AddonModAssign.getSubmissionStatusColor('noonlinesubmissions'); this.statusColor =
AddonModAssign.getSubmissionStatusColor(AddonModAssignSubmissionStatusValues.NO_ONLINE_SUBMISSIONS);
} else { } else {
this.statusTranslated = translateService.instant('addon.mod_assign.nosubmission'); this.statusTranslated = Translate.instant('addon.mod_assign.nosubmission');
this.statusColor = AddonModAssign.getSubmissionStatusColor('nosubmission'); this.statusColor = AddonModAssign.getSubmissionStatusColor(AddonModAssignSubmissionStatusValues.NO_SUBMISSION);
} }
} }
} }
@ -1180,7 +1183,7 @@ type AddonModAssignSubmissionGrade = {
grade?: number | string; grade?: number | string;
gradebookGrade?: string; gradebookGrade?: string;
modified?: number; modified?: number;
gradingStatus?: string; gradingStatus?: AddonModAssignGradingStates;
addAttempt: boolean; addAttempt: boolean;
applyToAll: boolean; applyToAll: boolean;
scale?: CoreMenuItem<number>[]; scale?: CoreMenuItem<number>[];

View File

@ -23,7 +23,11 @@ import { CoreSites } from '@services/sites';
import { CoreDomUtils } from '@services/utils/dom'; import { CoreDomUtils } from '@services/utils/dom';
import { Translate } from '@singletons'; import { Translate } from '@singletons';
import { CoreEventObserver, CoreEvents } from '@singletons/events'; import { CoreEventObserver, CoreEvents } from '@singletons/events';
import { AddonModAssignSubmissionForList, AddonModAssignSubmissionsSource } from '../../classes/submissions-source'; import {
AddonModAssignListFilterName,
AddonModAssignSubmissionForList,
AddonModAssignSubmissionsSource,
} from '../../classes/submissions-source';
import { AddonModAssignAssign, AddonModAssignProvider } from '../../services/assign'; import { AddonModAssignAssign, AddonModAssignProvider } from '../../services/assign';
import { import {
AddonModAssignSyncProvider, AddonModAssignSyncProvider,
@ -85,7 +89,7 @@ export class AddonModAssignSubmissionListPage implements AfterViewInit, OnDestro
const moduleId = CoreNavigator.getRequiredRouteNumberParam('cmId'); const moduleId = CoreNavigator.getRequiredRouteNumberParam('cmId');
const courseId = CoreNavigator.getRequiredRouteNumberParam('courseId'); const courseId = CoreNavigator.getRequiredRouteNumberParam('courseId');
const groupId = CoreNavigator.getRouteNumberParam('groupId') || 0; const groupId = CoreNavigator.getRouteNumberParam('groupId') || 0;
const selectedStatus = CoreNavigator.getRouteParam('status'); const selectedStatus = CoreNavigator.getRouteParam<AddonModAssignListFilterName>('status');
const submissionsSource = CoreRoutedItemsManagerSourcesTracker.getOrCreateSource( const submissionsSource = CoreRoutedItemsManagerSourcesTracker.getOrCreateSource(
AddonModAssignSubmissionsSource, AddonModAssignSubmissionsSource,
[courseId, moduleId, selectedStatus], [courseId, moduleId, selectedStatus],
@ -143,7 +147,7 @@ export class AddonModAssignSubmissionListPage implements AfterViewInit, OnDestro
this.title = Translate.instant( this.title = Translate.instant(
selectedStatus selectedStatus
? ( ? (
selectedStatus === AddonModAssignProvider.NEED_GRADING selectedStatus === AddonModAssignListFilterName.NEED_GRADING
? 'addon.mod_assign.numberofsubmissionsneedgrading' ? 'addon.mod_assign.numberofsubmissionsneedgrading'
: `addon.mod_assign.submissionstatus_${selectedStatus}` : `addon.mod_assign.submissionstatus_${selectedStatus}`
) )

View File

@ -22,7 +22,7 @@ import { IonRefresher } from '@ionic/angular';
import { CoreNavigator } from '@services/navigator'; import { CoreNavigator } from '@services/navigator';
import { CoreScreen } from '@services/screen'; import { CoreScreen } from '@services/screen';
import { CoreDomUtils } from '@services/utils/dom'; import { CoreDomUtils } from '@services/utils/dom';
import { AddonModAssignSubmissionsSource } from '../../classes/submissions-source'; import { AddonModAssignListFilterName, AddonModAssignSubmissionsSource } from '../../classes/submissions-source';
import { AddonModAssignSubmissionComponent } from '../../components/submission/submission'; import { AddonModAssignSubmissionComponent } from '../../components/submission/submission';
import { AddonModAssign, AddonModAssignAssign } from '../../services/assign'; import { AddonModAssign, AddonModAssignAssign } from '../../services/assign';
@ -53,7 +53,7 @@ export class AddonModAssignSubmissionReviewPage implements OnInit, OnDestroy, Ca
constructor(protected route: ActivatedRoute) { } constructor(protected route: ActivatedRoute) { }
/** /**
* Component being initialized. * @inheritdoc
*/ */
ngOnInit(): void { ngOnInit(): void {
this.route.queryParams.subscribe((params) => { this.route.queryParams.subscribe((params) => {
@ -63,7 +63,7 @@ export class AddonModAssignSubmissionReviewPage implements OnInit, OnDestroy, Ca
this.submitId = CoreNavigator.getRouteNumberParam('submitId') || 0; this.submitId = CoreNavigator.getRouteNumberParam('submitId') || 0;
this.blindId = CoreNavigator.getRouteNumberParam('blindId', { params }); this.blindId = CoreNavigator.getRouteNumberParam('blindId', { params });
const groupId = CoreNavigator.getRequiredRouteNumberParam('groupId'); const groupId = CoreNavigator.getRequiredRouteNumberParam('groupId');
const selectedStatus = CoreNavigator.getRouteParam('selectedStatus'); const selectedStatus = CoreNavigator.getRouteParam<AddonModAssignListFilterName>('selectedStatus');
const submissionsSource = CoreRoutedItemsManagerSourcesTracker.getOrCreateSource( const submissionsSource = CoreRoutedItemsManagerSourcesTracker.getOrCreateSource(
AddonModAssignSubmissionsSource, AddonModAssignSubmissionsSource,
[this.courseId, this.moduleId, selectedStatus], [this.courseId, this.moduleId, selectedStatus],

View File

@ -25,6 +25,7 @@ import {
AddonModAssign, AddonModAssign,
AddonModAssignPlugin, AddonModAssignPlugin,
AddonModAssignSavePluginData, AddonModAssignSavePluginData,
AddonModAssignSubmissionStatusValues,
} from './assign'; } from './assign';
import { AddonModAssignOffline } from './assign-offline'; import { AddonModAssignOffline } from './assign-offline';
import { CoreUtils } from '@services/utils/utils'; import { CoreUtils } from '@services/utils/utils';
@ -55,8 +56,8 @@ export class AddonModAssignHelperProvider {
return false; return false;
} }
if (submission.status == AddonModAssignProvider.SUBMISSION_STATUS_NEW || if (submission.status == AddonModAssignSubmissionStatusValues.NEW ||
submission.status == AddonModAssignProvider.SUBMISSION_STATUS_REOPENED) { submission.status == AddonModAssignSubmissionStatusValues.REOPENED) {
// It's a new submission, allow creating it in offline. // It's a new submission, allow creating it in offline.
return true; return true;
} }
@ -443,8 +444,8 @@ export class AddonModAssignHelperProvider {
submission.groupname = participant.groupname; submission.groupname = participant.groupname;
} }
submission.status = submission.status ?? (participant.submitted ? AddonModAssignProvider.SUBMISSION_STATUS_SUBMITTED : submission.status = submission.status ?? (participant.submitted ? AddonModAssignSubmissionStatusValues.SUBMITTED :
AddonModAssignProvider.SUBMISSION_STATUS_NEW); AddonModAssignSubmissionStatusValues.NEW);
return submission; return submission;

View File

@ -34,6 +34,7 @@ import { CoreWSError } from '@classes/errors/wserror';
import { AddonModAssignAutoSyncData, AddonModAssignManualSyncData, AddonModAssignSyncProvider } from './assign-sync'; import { AddonModAssignAutoSyncData, AddonModAssignManualSyncData, AddonModAssignSyncProvider } from './assign-sync';
import { CoreFormFields } from '@singletons/form'; import { CoreFormFields } from '@singletons/form';
import { CoreFileHelper } from '@services/file-helper'; import { CoreFileHelper } from '@services/file-helper';
import { CoreIonicColorNames } from '@singletons/colors';
const ROOT_CACHE_KEY = 'mmaModAssign:'; const ROOT_CACHE_KEY = 'mmaModAssign:';
@ -64,23 +65,6 @@ export class AddonModAssignProvider {
static readonly SUBMISSION_COMPONENT = 'mmaModAssignSubmission'; static readonly SUBMISSION_COMPONENT = 'mmaModAssignSubmission';
static readonly UNLIMITED_ATTEMPTS = -1; static readonly UNLIMITED_ATTEMPTS = -1;
// Submission status.
static readonly SUBMISSION_STATUS_NEW = 'new';
static readonly SUBMISSION_STATUS_REOPENED = 'reopened';
static readonly SUBMISSION_STATUS_DRAFT = 'draft';
static readonly SUBMISSION_STATUS_SUBMITTED = 'submitted';
// "Re-open" methods (to retry the assign).
static readonly ATTEMPT_REOPEN_METHOD_NONE = 'none';
static readonly ATTEMPT_REOPEN_METHOD_MANUAL = 'manual';
// Grading status.
static readonly GRADING_STATUS_GRADED = 'graded';
static readonly GRADING_STATUS_NOT_GRADED = 'notgraded';
static readonly MARKING_WORKFLOW_STATE_RELEASED = 'released';
static readonly NEED_GRADING = 'needgrading';
static readonly GRADED_FOLLOWUP_SUBMIT = 'gradedfollowupsubmit';
// Group submissions warnings. // Group submissions warnings.
static readonly WARN_GROUPS_REQUIRED = 'warnrequired'; static readonly WARN_GROUPS_REQUIRED = 'warnrequired';
static readonly WARN_GROUPS_OPTIONAL = 'warnoptional'; static readonly WARN_GROUPS_OPTIONAL = 'warnoptional';
@ -108,17 +92,17 @@ export class AddonModAssignProvider {
const teamSubmission = submissionStatus.lastattempt?.teamsubmission; const teamSubmission = submissionStatus.lastattempt?.teamsubmission;
if (teamSubmission) { if (teamSubmission) {
if (teamSubmission.status === AddonModAssignProvider.SUBMISSION_STATUS_SUBMITTED) { if (teamSubmission.status === AddonModAssignSubmissionStatusValues.SUBMITTED) {
// The assignment submission has been completed. // The assignment submission has been completed.
return false; return false;
} else if (userSubmission && userSubmission.status === AddonModAssignProvider.SUBMISSION_STATUS_SUBMITTED) { } else if (userSubmission && userSubmission.status === AddonModAssignSubmissionStatusValues.SUBMITTED) {
// The user has already clicked the submit button on the team submission. // The user has already clicked the submit button on the team submission.
return false; return false;
} else if (assign.preventsubmissionnotingroup && !submissionStatus.lastattempt?.submissiongroup) { } else if (assign.preventsubmissionnotingroup && !submissionStatus.lastattempt?.submissiongroup) {
return false; return false;
} }
} else if (userSubmission) { } else if (userSubmission) {
if (userSubmission.status === AddonModAssignProvider.SUBMISSION_STATUS_SUBMITTED) { if (userSubmission.status === AddonModAssignSubmissionStatusValues.SUBMITTED) {
// The assignment submission has been completed. // The assignment submission has been completed.
return false; return false;
} }
@ -347,17 +331,17 @@ export class AddonModAssignProvider {
* @param status Grading status name * @param status Grading status name
* @return The color name. * @return The color name.
*/ */
getSubmissionGradingStatusColor(status?: string): string { getSubmissionGradingStatusColor(status?: AddonModAssignGradingStates): CoreIonicColorNames {
if (!status) { if (!status) {
return ''; return CoreIonicColorNames.NONE;
} }
if (status == AddonModAssignProvider.GRADING_STATUS_GRADED || if (status == AddonModAssignGradingStates.GRADED
status == AddonModAssignProvider.MARKING_WORKFLOW_STATE_RELEASED) { || status == AddonModAssignGradingStates.MARKING_WORKFLOW_STATE_RELEASED) {
return 'success'; return CoreIonicColorNames.SUCCESS;
} }
return 'danger'; return CoreIonicColorNames.DANGER;
} }
/** /**
@ -366,13 +350,14 @@ export class AddonModAssignProvider {
* @param status Grading Status name * @param status Grading Status name
* @return The status translation identifier. * @return The status translation identifier.
*/ */
getSubmissionGradingStatusTranslationId(status?: string): string | undefined { getSubmissionGradingStatusTranslationId(status?: AddonModAssignGradingStates): string | undefined {
if (!status) { if (!status) {
return; return;
} }
if (status == AddonModAssignProvider.GRADING_STATUS_GRADED || status == AddonModAssignProvider.GRADING_STATUS_NOT_GRADED if (status == AddonModAssignGradingStates.GRADED
|| status == AddonModAssignProvider.GRADED_FOLLOWUP_SUBMIT) { || status == AddonModAssignGradingStates.NOT_GRADED
|| status == AddonModAssignGradingStates.GRADED_FOLLOWUP_SUBMIT) {
return 'addon.mod_assign.' + status; return 'addon.mod_assign.' + status;
} }
@ -604,20 +589,20 @@ export class AddonModAssignProvider {
* @param status Status name * @param status Status name
* @return The color name. * @return The color name.
*/ */
getSubmissionStatusColor(status: string): string { getSubmissionStatusColor(status: AddonModAssignSubmissionStatusValues): CoreIonicColorNames {
switch (status) { switch (status) {
case 'submitted': case AddonModAssignSubmissionStatusValues.SUBMITTED:
return 'success'; return CoreIonicColorNames.SUCCESS;
case 'draft': case AddonModAssignSubmissionStatusValues.DRAFT:
return 'info'; return CoreIonicColorNames.INFO;
case 'new': case AddonModAssignSubmissionStatusValues.NEW:
case 'noattempt': case AddonModAssignSubmissionStatusValues.NO_ATTEMPT:
case 'noonlinesubmissions': case AddonModAssignSubmissionStatusValues.NO_ONLINE_SUBMISSIONS:
case 'nosubmission': case AddonModAssignSubmissionStatusValues.NO_SUBMISSION:
case 'gradedfollowupsubmit': case AddonModAssignSubmissionStatusValues.GRADED_FOLLOWUP_SUBMIT:
return 'danger'; return CoreIonicColorNames.DANGER;
default: default:
return 'light'; return CoreIonicColorNames.LIGHT;
} }
} }
@ -878,7 +863,7 @@ export class AddonModAssignProvider {
} }
if (submission) { if (submission) {
if (assign.submissiondrafts && submission.status == AddonModAssignProvider.SUBMISSION_STATUS_SUBMITTED) { if (assign.submissiondrafts && submission.status == AddonModAssignSubmissionStatusValues.SUBMITTED) {
// Drafts are tracked and the student has submitted the assignment. // Drafts are tracked and the student has submitted the assignment.
return false; return false;
} }
@ -975,8 +960,8 @@ export class AddonModAssignProvider {
return true; return true;
} }
if (submission.gradingstatus != AddonModAssignProvider.GRADING_STATUS_GRADED && if (submission.gradingstatus != AddonModAssignGradingStates.GRADED &&
submission.gradingstatus != AddonModAssignProvider.MARKING_WORKFLOW_STATE_RELEASED) { submission.gradingstatus != AddonModAssignGradingStates.MARKING_WORKFLOW_STATE_RELEASED) {
// Not graded. // Not graded.
return true; return true;
} }
@ -1349,7 +1334,7 @@ export type AddonModAssignAssign = {
blindmarking: number; // If enabled, hide identities until reveal identities actioned. blindmarking: number; // If enabled, hide identities until reveal identities actioned.
hidegrader?: number; // @since 3.7. If enabled, hide grader to student. hidegrader?: number; // @since 3.7. If enabled, hide grader to student.
revealidentities: number; // Show identities for a blind marking assignment. revealidentities: number; // Show identities for a blind marking assignment.
attemptreopenmethod: string; // Method used to control opening new attempts. attemptreopenmethod: AddonModAssignAttemptReopenMethodValues; // Method used to control opening new attempts.
maxattempts: number; // Maximum number of attempts allowed. maxattempts: number; // Maximum number of attempts allowed.
markingworkflow: number; // Enable marking workflow. markingworkflow: number; // Enable marking workflow.
markingallocation: number; // Enable marking allocation. markingallocation: number; // Enable marking allocation.
@ -1400,12 +1385,12 @@ export type AddonModAssignSubmission = {
attemptnumber: number; // Attempt number. attemptnumber: number; // Attempt number.
timecreated: number; // Submission creation time. timecreated: number; // Submission creation time.
timemodified: number; // Submission last modified time. timemodified: number; // Submission last modified time.
status: string; // Submission status. status: AddonModAssignSubmissionStatusValues; // Submission status.
groupid: number; // Group id. groupid: number; // Group id.
assignment?: number; // Assignment id. assignment?: number; // Assignment id.
latest?: number; // Latest attempt. latest?: number; // Latest attempt.
plugins?: AddonModAssignPlugin[]; // Plugins. plugins?: AddonModAssignPlugin[]; // Plugins.
gradingstatus?: string; // Grading status. gradingstatus?: AddonModAssignGradingStates; // Grading status.
}; };
/** /**
@ -1454,7 +1439,7 @@ export type AddonModAssignSubmissionAttempt = {
cansubmit: boolean; // Whether the user can submit. cansubmit: boolean; // Whether the user can submit.
extensionduedate: number; // Extension due date. extensionduedate: number; // Extension due date.
blindmarking: boolean; // Whether blind marking is enabled. blindmarking: boolean; // Whether blind marking is enabled.
gradingstatus: string; // Grading status. gradingstatus: AddonModAssignGradingStates; // Grading status.
usergroups: number[]; // User groups in the course. usergroups: number[]; // User groups in the course.
}; };
@ -1749,3 +1734,41 @@ export type AddonModAssignSubmissionSavedEventData = AddonModAssignSubmittedForG
* Data sent by GRADED_EVENT event. * Data sent by GRADED_EVENT event.
*/ */
export type AddonModAssignGradedEventData = AddonModAssignSubmittedForGradingEventData; export type AddonModAssignGradedEventData = AddonModAssignSubmittedForGradingEventData;
/**
* Submission status.
* Constants on LMS starting with ASSIGN_SUBMISSION_STATUS_
*/
export enum AddonModAssignSubmissionStatusValues {
SUBMITTED = 'submitted',
DRAFT = 'draft',
NEW = 'new',
REOPENED = 'reopened',
// Added by App Statuses.
NO_ATTEMPT = 'noattempt',
NO_ONLINE_SUBMISSIONS = 'noonlinesubmissions',
NO_SUBMISSION = 'nosubmission',
GRADED_FOLLOWUP_SUBMIT = 'gradedfollowupsubmit',
};
/**
* Grading status.
* Constants on LMS starting with ASSIGN_GRADING_STATUS_
*/
export enum AddonModAssignGradingStates {
GRADED = 'graded',
NOT_GRADED = 'notgraded',
// Added by App Statuses.
MARKING_WORKFLOW_STATE_RELEASED = 'released', // with ASSIGN_MARKING_WORKFLOW_STATE_RELEASED
GRADED_FOLLOWUP_SUBMIT = 'gradedfollowupsubmit',
};
/**
* Reopen attempt methods.
* Constants on LMS starting with ASSIGN_ATTEMPT_REOPEN_METHOD_
*/
export enum AddonModAssignAttemptReopenMethodValues {
NONE = 'none',
MANUAL = 'manual',
UNTILPASS = 'untilpass',
};

View File

@ -21,6 +21,18 @@ interface ColorComponents {
blue: number; // Blue component of an RGB color [0-255]. blue: number; // Blue component of an RGB color [0-255].
} }
/**
* Ionic color names.
*/
export enum CoreIonicColorNames {
SUCCESS = 'success',
INFO = 'info',
DANGER = 'danger',
DARK = 'dark',
LIGHT = 'light',
NONE = '',
};
/** /**
* Singleton with helper functions for colors. * Singleton with helper functions for colors.
*/ */