-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3960 from NoelDeMartin/MOBILE-4529
MOBILE-4529: Decouple Survey
- Loading branch information
Showing
20 changed files
with
326 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// (C) Copyright 2015 Moodle Pty Ltd. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
export const ADDON_MOD_SURVEY_COMPONENT = 'mmaModSurvey'; | ||
|
||
// Routing. | ||
export const ADDON_MOD_SURVEY_PAGE_NAME = 'mod_survey'; | ||
|
||
// Handlers. | ||
export const ADDON_MOD_SURVEY_PREFETCH_NAME = 'AddonModSurvey'; | ||
export const ADDON_MOD_SURVEY_PREFETCH_MODNAME = 'survey'; | ||
export const ADDON_MOD_SURVEY_PREFETCH_COMPONENT = ADDON_MOD_SURVEY_COMPONENT; | ||
export const ADDON_MOD_SURVEY_PREFETCH_UPDATE_NAMES = /^configuration$|^.*files$|^answers$/; | ||
|
||
export const ADDON_MOD_SURVEY_SYNC_CRON_NAME = 'AddonModSurveySyncCronHandler'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
src/addons/mod/survey/services/handlers/prefetch-lazy.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
// (C) Copyright 2015 Moodle Pty Ltd. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
import { Injectable } from '@angular/core'; | ||
import { CoreCourseAnyModuleData } from '@features/course/services/course'; | ||
import { CoreFilepool } from '@services/filepool'; | ||
import { CoreSitesReadingStrategy } from '@services/sites'; | ||
import { CoreUtils } from '@services/utils/utils'; | ||
import { CoreWSFile } from '@services/ws'; | ||
import { makeSingleton } from '@singletons'; | ||
import { AddonModSurvey, AddonModSurveyProvider } from '../survey'; | ||
import { AddonModSurveySync, AddonModSurveySyncResult } from '../survey-sync'; | ||
import { AddonModSurveyPrefetchHandlerService } from '@addons/mod/survey/services/handlers/prefetch'; | ||
|
||
/** | ||
* Handler to prefetch surveys. | ||
*/ | ||
@Injectable( { providedIn: 'root' }) | ||
export class AddonModSurveyPrefetchHandlerLazyService extends AddonModSurveyPrefetchHandlerService { | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
async getIntroFiles(module: CoreCourseAnyModuleData, courseId: number): Promise<CoreWSFile[]> { | ||
const survey = await CoreUtils.ignoreErrors(AddonModSurvey.getSurvey(courseId, module.id)); | ||
|
||
return this.getIntroFilesFromInstance(module, survey); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
async invalidateContent(moduleId: number, courseId: number): Promise<void> { | ||
return AddonModSurvey.invalidateContent(moduleId, courseId); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
async invalidateModule(module: CoreCourseAnyModuleData, courseId: number): Promise<void> { | ||
await AddonModSurvey.invalidateSurveyData(courseId); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
async isEnabled(): Promise<boolean> { | ||
return true; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
prefetch(module: CoreCourseAnyModuleData, courseId: number): Promise<void> { | ||
return this.prefetchPackage(module, courseId, (siteId) => this.prefetchSurvey(module, courseId, siteId)); | ||
} | ||
|
||
/** | ||
* Prefetch a survey. | ||
* | ||
* @param module Module. | ||
* @param courseId Course ID the module belongs to. | ||
* @param siteId SiteId or current site. | ||
* @returns Promise resolved when done. | ||
*/ | ||
protected async prefetchSurvey(module: CoreCourseAnyModuleData, courseId: number, siteId: string): Promise<void> { | ||
const survey = await AddonModSurvey.getSurvey(courseId, module.id, { | ||
readingStrategy: CoreSitesReadingStrategy.ONLY_NETWORK, | ||
siteId, | ||
}); | ||
|
||
const promises: Promise<unknown>[] = []; | ||
const files = this.getIntroFilesFromInstance(module, survey); | ||
|
||
// Prefetch files. | ||
promises.push(CoreFilepool.addFilesToQueue(siteId, files, AddonModSurveyProvider.COMPONENT, module.id)); | ||
|
||
// If survey isn't answered, prefetch the questions. | ||
if (!survey.surveydone) { | ||
promises.push(AddonModSurvey.getQuestions(survey.id, { | ||
cmId: module.id, | ||
readingStrategy: CoreSitesReadingStrategy.ONLY_NETWORK, | ||
siteId, | ||
})); | ||
} | ||
|
||
await Promise.all(promises); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
sync(module: CoreCourseAnyModuleData, courseId: number, siteId?: string): Promise<AddonModSurveySyncResult> { | ||
return AddonModSurveySync.syncSurvey(module.instance, undefined, siteId); | ||
} | ||
|
||
} | ||
export const AddonModSurveyPrefetchHandler = makeSingleton(AddonModSurveyPrefetchHandlerLazyService); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// (C) Copyright 2015 Moodle Pty Ltd. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
import { Injectable } from '@angular/core'; | ||
import { CoreCronHandler } from '@services/cron'; | ||
import { makeSingleton } from '@singletons'; | ||
import { AddonModSurveySync } from '../survey-sync'; | ||
import { AddonModSurveySyncCronHandlerService } from '@addons/mod/survey/services/handlers/sync-cron'; | ||
|
||
/** | ||
* Synchronization cron handler. | ||
*/ | ||
@Injectable( { providedIn: 'root' }) | ||
export class AddonModSurveySyncCronHandlerLazyService | ||
extends AddonModSurveySyncCronHandlerService | ||
implements CoreCronHandler { | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
async execute(siteId?: string, force?: boolean): Promise<void> { | ||
await AddonModSurveySync.syncAllSurveys(siteId, force); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
getInterval(): number { | ||
return AddonModSurveySync.syncInterval; | ||
} | ||
|
||
} | ||
export const AddonModSurveySyncCronHandler = makeSingleton(AddonModSurveySyncCronHandlerLazyService); |
Oops, something went wrong.