forked from EVOgeek/Vmeda.Online
		
	MOBILE-3644 sync: Always use new offline warning functions
This commit is contained in:
		
							parent
							
								
									8a3fb4a5eb
								
							
						
					
					
						commit
						8e9b550254
					
				| @ -19,9 +19,8 @@ import { CoreCourse } from '@features/course/services/course'; | ||||
| import { CoreCourseLogHelper } from '@features/course/services/log-helper'; | ||||
| import { CoreApp } from '@services/app'; | ||||
| import { CoreSites } from '@services/sites'; | ||||
| import { CoreTextUtils } from '@services/utils/text'; | ||||
| import { CoreUtils } from '@services/utils/utils'; | ||||
| import { makeSingleton, Translate } from '@singletons'; | ||||
| import { makeSingleton } from '@singletons'; | ||||
| import { CoreEvents } from '@singletons/events'; | ||||
| import { AddonModChoice, AddonModChoiceProvider } from './choice'; | ||||
| import { AddonModChoiceOffline } from './choice-offline'; | ||||
| @ -192,11 +191,7 @@ export class AddonModChoiceSyncProvider extends CoreCourseActivitySyncBaseProvid | ||||
|             await AddonModChoiceOffline.deleteResponse(choiceId, siteId, userId); | ||||
| 
 | ||||
|             // Responses deleted, add a warning.
 | ||||
|             result.warnings.push(Translate.instant('core.warningofflinedatadeleted', { | ||||
|                 component: this.componentTranslate, | ||||
|                 name: data.name, | ||||
|                 error: CoreTextUtils.getErrorMessageFromError(error), | ||||
|             })); | ||||
|             this.addOfflineDataDeletedWarning(result.warnings, data.name, error); | ||||
|         } | ||||
| 
 | ||||
|         // Data has been sent to server, prefetch choice if needed.
 | ||||
|  | ||||
| @ -235,28 +235,20 @@ export class AddonModDataSyncProvider extends CoreCourseActivitySyncBaseProvider | ||||
|         result: AddonModDataSyncResult, | ||||
|         siteId: string, | ||||
|     ): Promise<void> { | ||||
|         const synEntryResult = await this.performSyncEntry(database, entryActions, result, siteId); | ||||
|         const syncEntryResult = await this.performSyncEntry(database, entryActions, result, siteId); | ||||
| 
 | ||||
|         if (synEntryResult.discardError) { | ||||
|         if (syncEntryResult.discardError) { | ||||
|             // Submission was discarded, add a warning.
 | ||||
|             const message = Translate.instant('core.warningofflinedatadeleted', { | ||||
|                 component: this.componentTranslate, | ||||
|                 name: database.name, | ||||
|                 error: synEntryResult.discardError, | ||||
|             }); | ||||
| 
 | ||||
|             if (result.warnings.indexOf(message) == -1) { | ||||
|                 result.warnings.push(message); | ||||
|             } | ||||
|             this.addOfflineDataDeletedWarning(result.warnings, database.name, syncEntryResult.discardError); | ||||
|         } | ||||
| 
 | ||||
|         // Sync done. Send event.
 | ||||
|         CoreEvents.trigger(AddonModDataSyncProvider.AUTO_SYNCED, { | ||||
|             dataId: database.id, | ||||
|             entryId: synEntryResult.entryId, | ||||
|             offlineEntryId: synEntryResult.offlineId, | ||||
|             entryId: syncEntryResult.entryId, | ||||
|             offlineEntryId: syncEntryResult.offlineId, | ||||
|             warnings: result.warnings, | ||||
|             deleted: synEntryResult.deleted, | ||||
|             deleted: syncEntryResult.deleted, | ||||
|         }, siteId); | ||||
|     } | ||||
| 
 | ||||
|  | ||||
| @ -23,7 +23,6 @@ import { CoreRatingSync } from '@features/rating/services/rating-sync'; | ||||
| import { CoreApp } from '@services/app'; | ||||
| import { CoreSites } from '@services/sites'; | ||||
| import { CoreSync } from '@services/sync'; | ||||
| import { CoreTextUtils } from '@services/utils/text'; | ||||
| import { CoreUtils } from '@services/utils/utils'; | ||||
| import { CoreWSExternalFile } from '@services/ws'; | ||||
| import { makeSingleton, Translate } from '@singletons'; | ||||
| @ -222,11 +221,7 @@ export class AddonModGlossarySyncProvider extends CoreCourseActivitySyncBaseProv | ||||
|                 await this.deleteAddEntry(glossaryId, data.concept, data.timecreated, siteId); | ||||
| 
 | ||||
|                 // Responses deleted, add a warning.
 | ||||
|                 result.warnings.push(Translate.instant('core.warningofflinedatadeleted', { | ||||
|                     component: this.componentTranslate, | ||||
|                     name: data.concept, | ||||
|                     error: CoreTextUtils.getErrorMessageFromError(error), | ||||
|                 })); | ||||
|                 this.addOfflineDataDeletedWarning(result.warnings, data.concept, error); | ||||
|             } | ||||
|         })); | ||||
| 
 | ||||
| @ -275,11 +270,7 @@ export class AddonModGlossarySyncProvider extends CoreCourseActivitySyncBaseProv | ||||
|                 const glossary = await AddonModGlossary.getGlossary(result.itemSet.courseId, result.itemSet.instanceId, { siteId }); | ||||
| 
 | ||||
|                 result.warnings.forEach((warning) => { | ||||
|                     warnings.push(Translate.instant('core.warningofflinedatadeleted', { | ||||
|                         component: this.componentTranslate, | ||||
|                         name: glossary.name, | ||||
|                         error: warning, | ||||
|                     })); | ||||
|                     this.addOfflineDataDeletedWarning(warnings, glossary.name, warning); | ||||
|                 }); | ||||
|             } | ||||
|         })); | ||||
|  | ||||
| @ -20,7 +20,6 @@ import { CoreApp } from '@services/app'; | ||||
| import { CoreGroups } from '@services/groups'; | ||||
| import { CoreSites } from '@services/sites'; | ||||
| import { CoreSync } from '@services/sync'; | ||||
| import { CoreTextUtils } from '@services/utils/text'; | ||||
| import { CoreUtils } from '@services/utils/utils'; | ||||
| import { makeSingleton, Translate } from '@singletons'; | ||||
| import { CoreEvents } from '@singletons/events'; | ||||
| @ -260,11 +259,7 @@ export class AddonModWikiSyncProvider extends CoreSyncBaseProvider<AddonModWikiS | ||||
|                 result.updated = true; | ||||
| 
 | ||||
|                 // Page deleted, add the page to discarded pages and add a warning.
 | ||||
|                 const warning = Translate.instant('core.warningofflinedatadeleted', { | ||||
|                     component: Translate.instant('addon.mod_wiki.wikipage'), | ||||
|                     name: page.title, | ||||
|                     error: CoreTextUtils.getErrorMessageFromError(error), | ||||
|                 }); | ||||
|                 const warning = this.getOfflineDataDeletedWarning(page.title, error); | ||||
| 
 | ||||
|                 result.discarded.push({ | ||||
|                     title: page.title, | ||||
|  | ||||
| @ -72,11 +72,7 @@ export class CoreSyncBaseProvider<T = void> { | ||||
|      * @param error Specific error message. | ||||
|      */ | ||||
|     protected addOfflineDataDeletedWarning(warnings: string[], name: string, error: CoreAnyError): void { | ||||
|         const warning = Translate.instant('core.warningofflinedatadeleted', { | ||||
|             component: this.componentTranslate, | ||||
|             name: name, | ||||
|             error: CoreTextUtils.getErrorMessageFromError(error), | ||||
|         }); | ||||
|         const warning = this.getOfflineDataDeletedWarning(name, error); | ||||
| 
 | ||||
|         if (warnings.indexOf(warning) == -1) { | ||||
|             warnings.push(warning); | ||||
| @ -113,6 +109,21 @@ export class CoreSyncBaseProvider<T = void> { | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Add an offline data deleted warning to a list of warnings. | ||||
|      * | ||||
|      * @param name Instance name. | ||||
|      * @param error Specific error message. | ||||
|      * @return Warning message. | ||||
|      */ | ||||
|     protected getOfflineDataDeletedWarning(name: string, error: CoreAnyError): string { | ||||
|         return Translate.instant('core.warningofflinedatadeleted', { | ||||
|             component: this.componentTranslate, | ||||
|             name: name, | ||||
|             error: CoreTextUtils.getErrorMessageFromError(error), | ||||
|         }); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * If there's an ongoing sync for a certain identifier return it. | ||||
|      * | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user