MOBILE-3449 assign: Don't block all assign sync when edit grade

main
Dani Palou 2020-07-30 11:05:16 +02:00
parent b67ea14abb
commit 88ac2e0c5c
5 changed files with 59 additions and 10 deletions

View File

@ -20,7 +20,7 @@
</ion-item> </ion-item>
<!-- Tabs: see the submission or grade it. --> <!-- Tabs: see the submission or grade it. -->
<core-tabs [selectedIndex]="selectedTab" [hideUntil]="loaded" parentScrollable="true"> <core-tabs [selectedIndex]="selectedTab" [hideUntil]="loaded" parentScrollable="true" (ionChange)="tabSelected($event)">
<!-- View the submission tab. --> <!-- View the submission tab. -->
<core-tab [title]="'addon.mod_assign.submission' | translate"> <core-tab [title]="'addon.mod_assign.submission' | translate">
<ng-template> <ng-template>

View File

@ -35,7 +35,9 @@ import {
} from '../../providers/assign'; } from '../../providers/assign';
import { AddonModAssignHelperProvider } from '../../providers/helper'; import { AddonModAssignHelperProvider } from '../../providers/helper';
import { AddonModAssignOfflineProvider } from '../../providers/assign-offline'; import { AddonModAssignOfflineProvider } from '../../providers/assign-offline';
import { AddonModAssignSync } from '../../providers/assign-sync';
import { CoreTabsComponent } from '@components/tabs/tabs'; import { CoreTabsComponent } from '@components/tabs/tabs';
import { CoreTabComponent } from '@components/tabs/tab';
import { CoreSplitViewComponent } from '@components/split-view/split-view'; import { CoreSplitViewComponent } from '@components/split-view/split-view';
import { AddonModAssignSubmissionPluginComponent } from '../submission-plugin/submission-plugin'; import { AddonModAssignSubmissionPluginComponent } from '../submission-plugin/submission-plugin';
@ -537,11 +539,6 @@ export class AddonModAssignSubmissionComponent implements OnInit, OnDestroy {
// Make sure outcomes is an array. // Make sure outcomes is an array.
gradeInfo.outcomes = gradeInfo.outcomes || []; gradeInfo.outcomes = gradeInfo.outcomes || [];
if (!this.isDestroyed) {
// Block the assignment.
this.syncProvider.blockOperation(AddonModAssignProvider.COMPONENT, this.assign.id);
}
// Treat the grade info. // Treat the grade info.
return this.treatGradeInfo(); return this.treatGradeInfo();
}).then(() => { }).then(() => {
@ -952,15 +949,41 @@ export class AddonModAssignSubmissionComponent implements OnInit, OnDestroy {
} }
} }
/**
* Block or unblock the automatic sync of the user grade.
*
* @param block Whether to block or unblock.
*/
protected setGradeSyncBlocked(block?: boolean): void {
if (this.isDestroyed || !this.assign || !this.isGrading) {
return;
}
const syncId = AddonModAssignSync.instance.getGradeSyncId(this.assign.id, this.submitId);
if (block) {
this.syncProvider.blockOperation(AddonModAssignProvider.COMPONENT, syncId);
} else {
this.syncProvider.unblockOperation(AddonModAssignProvider.COMPONENT, syncId);
}
}
/**
* A certain tab has been selected, either manually or automatically.
*
* @param tab The tab that was selected.
*/
tabSelected(tab: CoreTabComponent): void {
// Block sync when selecting grade tab, unblock when leaving it.
this.setGradeSyncBlocked(this.tabs.getIndex(tab) === 1);
}
/** /**
* Component being destroyed. * Component being destroyed.
*/ */
ngOnDestroy(): void { ngOnDestroy(): void {
this.setGradeSyncBlocked(false);
this.isDestroyed = true; this.isDestroyed = true;
if (this.assign && this.isGrading) {
this.syncProvider.unblockOperation(AddonModAssignProvider.COMPONENT, this.assign.id);
}
} }
} }

View File

@ -89,6 +89,7 @@
"submitassignment": "Submit assignment", "submitassignment": "Submit assignment",
"submittedearly": "Assignment was submitted {{$a}} early", "submittedearly": "Assignment was submitted {{$a}} early",
"submittedlate": "Assignment was submitted {{$a}} late", "submittedlate": "Assignment was submitted {{$a}} late",
"syncblockedusercomponent": "user grade",
"timemodified": "Last modified", "timemodified": "Last modified",
"timeremaining": "Time remaining", "timeremaining": "Time remaining",
"ungroupedusers": "The setting 'Require group to make submission' is enabled and some users are either not a member of any group, or are a member of more than one group, so are unable to make submissions.", "ungroupedusers": "The setting 'Require group to make submission' is enabled and some users are either not a member of any group, or are a member of more than one group, so are unable to make submissions.",

View File

@ -31,6 +31,8 @@ import { AddonModAssignOfflineProvider } from './assign-offline';
import { AddonModAssignSubmissionDelegate } from './submission-delegate'; import { AddonModAssignSubmissionDelegate } from './submission-delegate';
import { AddonModAssignFeedbackDelegate } from './feedback-delegate'; import { AddonModAssignFeedbackDelegate } from './feedback-delegate';
import { makeSingleton } from '@singletons/core.singletons';
/** /**
* Data returned by an assign sync. * Data returned by an assign sync.
*/ */
@ -79,6 +81,17 @@ export class AddonModAssignSyncProvider extends CoreSyncBaseProvider {
this.componentTranslate = courseProvider.translateModuleName('assign'); this.componentTranslate = courseProvider.translateModuleName('assign');
} }
/**
* Get the sync ID for a certain user grade.
*
* @param assignId Assign ID.
* @param userId User the grade belongs to.
* @return Sync ID.
*/
getGradeSyncId(assignId: number, userId: number): string {
return 'assignGrade#' + assignId + '#' + userId;
}
/** /**
* Convenience function to get scale selected option. * Convenience function to get scale selected option.
* *
@ -373,6 +386,15 @@ export class AddonModAssignSyncProvider extends CoreSyncBaseProvider {
const userId = offlineData.userid; const userId = offlineData.userid;
let discardError; let discardError;
const syncId = this.getGradeSyncId(assign.id, userId);
// Check if this grade sync is blocked.
if (this.syncProvider.isBlocked(AddonModAssignProvider.COMPONENT, syncId, siteId)) {
this.logger.error(`Cannot sync grade for assign ${assign.id} and user ${userId} because it is blocked.`);
return Promise.reject(new Error(this.translate.instant('core.errorsyncblocked',
{$a: this.translate.instant('addon.mod_assign.syncblockedusercomponent')})));
}
return this.assignProvider.getSubmissionStatus(assign.id, userId, undefined, false, true, true, siteId).then((status) => { return this.assignProvider.getSubmissionStatus(assign.id, userId, undefined, false, true, true, siteId).then((status) => {
const timemodified = status.feedback && (status.feedback.gradeddate || status.feedback.grade.timemodified); const timemodified = status.feedback && (status.feedback.gradeddate || status.feedback.grade.timemodified);
@ -455,3 +477,5 @@ export class AddonModAssignSyncProvider extends CoreSyncBaseProvider {
}); });
} }
} }
export class AddonModAssignSync extends makeSingleton(AddonModAssignSyncProvider) {}

View File

@ -408,6 +408,7 @@
"addon.mod_assign.submitassignment_help": "Once this assignment is submitted you will not be able to make any more changes.", "addon.mod_assign.submitassignment_help": "Once this assignment is submitted you will not be able to make any more changes.",
"addon.mod_assign.submittedearly": "Assignment was submitted {{$a}} early", "addon.mod_assign.submittedearly": "Assignment was submitted {{$a}} early",
"addon.mod_assign.submittedlate": "Assignment was submitted {{$a}} late", "addon.mod_assign.submittedlate": "Assignment was submitted {{$a}} late",
"addon.mod_assign.syncblockedusercomponent": "user grade",
"addon.mod_assign.timemodified": "Last modified", "addon.mod_assign.timemodified": "Last modified",
"addon.mod_assign.timeremaining": "Time remaining", "addon.mod_assign.timeremaining": "Time remaining",
"addon.mod_assign.ungroupedusers": "The setting 'Require group to make submission' is enabled and some users are either not a member of any group, or are a member of more than one group, so are unable to make submissions.", "addon.mod_assign.ungroupedusers": "The setting 'Require group to make submission' is enabled and some users are either not a member of any group, or are a member of more than one group, so are unable to make submissions.",