Merge pull request #2528 from dpalou/MOBILE-3449

MOBILE-3449 assign: Always allow submit grade if has offline data
main
Juan Leyva 2020-09-18 12:25:32 +02:00 committed by GitHub
commit 1e59f786db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 10 deletions

View File

@ -110,6 +110,7 @@ export class AddonModAssignSubmissionComponent implements OnInit, OnDestroy {
protected originalGrades: any = {}; // Object with the original grade data, to check for changes. protected originalGrades: any = {}; // Object with the original grade data, to check for changes.
protected isDestroyed: boolean; // Whether the component has been destroyed. protected isDestroyed: boolean; // Whether the component has been destroyed.
protected syncObserver: CoreEventObserver; protected syncObserver: CoreEventObserver;
protected hasOfflineGrade = false;
constructor(protected navCtrl: NavController, protected appProvider: CoreAppProvider, protected domUtils: CoreDomUtilsProvider, constructor(protected navCtrl: NavController, protected appProvider: CoreAppProvider, protected domUtils: CoreDomUtilsProvider,
sitesProvider: CoreSitesProvider, protected syncProvider: CoreSyncProvider, protected timeUtils: CoreTimeUtilsProvider, sitesProvider: CoreSitesProvider, protected syncProvider: CoreSyncProvider, protected timeUtils: CoreTimeUtilsProvider,
@ -306,17 +307,23 @@ export class AddonModAssignSubmissionComponent implements OnInit, OnDestroy {
/** /**
* Check if there's data to save (grade). * Check if there's data to save (grade).
* *
* @param isSubmit Whether the user is about to submit the grade.
* @return Promise resolved with boolean: whether there's data to save. * @return Promise resolved with boolean: whether there's data to save.
*/ */
protected hasDataToSave(): Promise<boolean> { protected async hasDataToSave(isSubmit?: boolean): Promise<boolean> {
if (!this.canSaveGrades || !this.loaded) { if (!this.canSaveGrades || !this.loaded) {
return Promise.resolve(false); return false;
}
if (isSubmit && this.hasOfflineGrade) {
// Always allow sending if the grade is saved in offline.
return true;
} }
// Check if numeric grade and toggles changed. // Check if numeric grade and toggles changed.
if (this.originalGrades.grade != this.grade.grade || this.originalGrades.addAttempt != this.grade.addAttempt || if (this.originalGrades.grade != this.grade.grade || this.originalGrades.addAttempt != this.grade.addAttempt ||
this.originalGrades.applyToAll != this.grade.applyToAll) { this.originalGrades.applyToAll != this.grade.applyToAll) {
return Promise.resolve(true); return true;
} }
// Check if outcomes changed. // Check if outcomes changed.
@ -326,20 +333,21 @@ export class AddonModAssignSubmissionComponent implements OnInit, OnDestroy {
if (this.originalGrades.outcomes[outcome.id] == 'undefined' || if (this.originalGrades.outcomes[outcome.id] == 'undefined' ||
this.originalGrades.outcomes[outcome.id] != outcome.selectedId) { this.originalGrades.outcomes[outcome.id] != outcome.selectedId) {
return Promise.resolve(true); return true;
} }
} }
} }
if (this.feedback && this.feedback.plugins) { if (this.feedback && this.feedback.plugins) {
return this.assignHelper.hasFeedbackDataChanged(this.assign, this.userSubmission, this.feedback, this.submitId) try {
.catch(() => { return this.assignHelper.hasFeedbackDataChanged(this.assign, this.userSubmission, this.feedback, this.submitId);
} catch (error) {
// Error ocurred, consider there are no changes. // Error ocurred, consider there are no changes.
return false; return false;
}); }
} }
return Promise.resolve(false); return false;
} }
/** /**
@ -645,11 +653,13 @@ export class AddonModAssignSubmissionComponent implements OnInit, OnDestroy {
return this.assignOfflineProvider.getSubmissionGrade(this.assign.id, this.submitId).catch(() => { return this.assignOfflineProvider.getSubmissionGrade(this.assign.id, this.submitId).catch(() => {
// Grade not found. // Grade not found.
}).then((data) => { }).then((data) => {
this.hasOfflineGrade = false;
// Load offline grades. // Load offline grades.
if (data && (!feedback || !feedback.gradeddate || feedback.gradeddate < data.timemodified)) { if (data && (!feedback || !feedback.gradeddate || feedback.gradeddate < data.timemodified)) {
// If grade has been modified from gradebook, do not use offline. // If grade has been modified from gradebook, do not use offline.
if (this.grade.modified < data.timemodified) { if (this.grade.modified < data.timemodified) {
this.hasOfflineGrade = true;
this.grade.grade = !this.grade.scale ? this.utils.formatFloat(data.grade) : data.grade; this.grade.grade = !this.grade.scale ? this.utils.formatFloat(data.grade) : data.grade;
this.gradingStatusTranslationId = 'addon.mod_assign.gradenotsynced'; this.gradingStatusTranslationId = 'addon.mod_assign.gradenotsynced';
this.gradingColor = ''; this.gradingColor = '';
@ -790,7 +800,7 @@ export class AddonModAssignSubmissionComponent implements OnInit, OnDestroy {
*/ */
submitGrade(): Promise<any> { submitGrade(): Promise<any> {
// Check if there's something to be saved. // Check if there's something to be saved.
return this.hasDataToSave().then((modified) => { return this.hasDataToSave(true).then((modified) => {
if (!modified) { if (!modified) {
return; return;
} }

View File

@ -221,7 +221,7 @@ export class AddonModAssignSyncProvider extends CoreSyncBaseProvider {
*/ */
protected async performSyncAssign(assignId: number, siteId?: string): Promise<AddonModAssignSyncResult> { protected async performSyncAssign(assignId: number, siteId?: string): Promise<AddonModAssignSyncResult> {
this.logger.error('Try to sync assign ' + assignId + ' in site ' + siteId); this.logger.debug('Try to sync assign ' + assignId + ' in site ' + siteId);
const result: AddonModAssignSyncResult = { const result: AddonModAssignSyncResult = {
warnings: [], warnings: [],