MOBILE-2317 core: Move and rename courses delegate

main
Dani Palou 2018-01-26 09:54:01 +01:00
parent 2319cf8074
commit 76eed98cb5
11 changed files with 77 additions and 67 deletions

View File

@ -18,6 +18,7 @@ import { CoreCourseHelperProvider } from './providers/helper';
import { CoreCourseFormatDelegate } from './providers/format-delegate';
import { CoreCourseModuleDelegate } from './providers/module-delegate';
import { CoreCourseModulePrefetchDelegate } from './providers/module-prefetch-delegate';
import { CoreCourseOptionsDelegate } from './providers/options-delegate';
import { CoreCourseFormatDefaultHandler } from './providers/default-format';
import { CoreCourseFormatSingleActivityModule } from './formats/singleactivity/singleactivity.module';
import { CoreCourseFormatSocialModule } from './formats/social/social.module';
@ -38,6 +39,7 @@ import { CoreCourseFormatWeeksModule } from './formats/weeks/weeks.module';
CoreCourseFormatDelegate,
CoreCourseModuleDelegate,
CoreCourseModulePrefetchDelegate,
CoreCourseOptionsDelegate,
CoreCourseFormatDefaultHandler
],
exports: []

View File

@ -22,7 +22,7 @@ import { CoreTextUtilsProvider } from '../../../../providers/utils/text';
import { CoreCourseProvider } from '../../providers/course';
import { CoreCourseHelperProvider } from '../../providers/helper';
import { CoreCourseFormatDelegate } from '../../providers/format-delegate';
import { CoreCoursesDelegate, CoreCoursesHandlerToDisplay } from '../../../courses/providers/delegate';
import { CoreCourseOptionsDelegate, CoreCourseOptionsHandlerToDisplay } from '../../providers/options-delegate';
import { CoreCoursesProvider } from '../../../courses/providers/courses';
/**
@ -41,7 +41,7 @@ export class CoreCourseSectionPage implements OnDestroy {
sections: any[];
sectionId: number;
sectionNumber: number;
courseHandlers: CoreCoursesHandlerToDisplay[];
courseHandlers: CoreCourseOptionsHandlerToDisplay[];
dataLoaded: boolean;
downloadEnabled: boolean;
downloadEnabledIcon: string = 'square-outline'; // Disabled by default.
@ -54,7 +54,7 @@ export class CoreCourseSectionPage implements OnDestroy {
protected isDestroyed = false;
constructor(private navParams: NavParams, private courseProvider: CoreCourseProvider, private domUtils: CoreDomUtilsProvider,
private courseFormatDelegate: CoreCourseFormatDelegate, private coursesDelegate: CoreCoursesDelegate,
private courseFormatDelegate: CoreCourseFormatDelegate, private courseOptionsDelegate: CoreCourseOptionsDelegate,
private translate: TranslateService, private courseHelper: CoreCourseHelperProvider, eventsProvider: CoreEventsProvider,
private textUtils: CoreTextUtilsProvider, private coursesProvider: CoreCoursesProvider,
sitesProvider: CoreSitesProvider, private navCtrl: NavController) {
@ -166,7 +166,7 @@ export class CoreCourseSectionPage implements OnDestroy {
}));
// Load the course handlers.
promises.push(this.coursesDelegate.getHandlersToDisplay(this.course, refresh, false).then((handlers) => {
promises.push(this.courseOptionsDelegate.getHandlersToDisplay(this.course, refresh, false).then((handlers) => {
this.courseHandlers = handlers;
}));

View File

@ -28,6 +28,9 @@ import { CoreConstants } from '../../constants';
@Injectable()
export class CoreCourseProvider {
public static ALL_SECTIONS_ID = -1;
public static ACCESS_GUEST = 'courses_access_guest';
public static ACCESS_DEFAULT = 'courses_access_default';
protected ROOT_CACHE_KEY = 'mmCourse:';
// Variables for database.

View File

@ -21,7 +21,7 @@ import { CoreDomUtilsProvider } from '../../../providers/utils/dom';
import { CoreTextUtilsProvider } from '../../../providers/utils/text';
import { CoreTimeUtilsProvider } from '../../../providers/utils/time';
import { CoreUtilsProvider } from '../../../providers/utils/utils';
import { CoreCoursesDelegate, CoreCoursesHandlerToDisplay } from '../../courses/providers/delegate';
import { CoreCourseOptionsDelegate, CoreCourseOptionsHandlerToDisplay } from './options-delegate';
import { CoreSiteHomeProvider } from '../../sitehome/providers/sitehome';
import { CoreCourseProvider } from './course';
import { CoreCourseModuleDelegate } from './module-delegate';
@ -113,8 +113,8 @@ export class CoreCourseHelperProvider {
private moduleDelegate: CoreCourseModuleDelegate, private prefetchDelegate: CoreCourseModulePrefetchDelegate,
private filepoolProvider: CoreFilepoolProvider, private sitesProvider: CoreSitesProvider,
private textUtils: CoreTextUtilsProvider, private timeUtils: CoreTimeUtilsProvider,
private utils: CoreUtilsProvider, private translate: TranslateService, private coursesDelegate: CoreCoursesDelegate,
private loginHelper: CoreLoginHelperProvider, private siteHomeProvider: CoreSiteHomeProvider) {}
private utils: CoreUtilsProvider, private translate: TranslateService, private loginHelper: CoreLoginHelperProvider,
private courseOptionsDelegate: CoreCourseOptionsDelegate, private siteHomeProvider: CoreSiteHomeProvider) {}
/**
* This function treats every module on the sections provided to load the handler data, treat completion
@ -242,11 +242,11 @@ export class CoreCourseHelperProvider {
* @param {any} iconData An object where to store the course icon. It will be stored with the name "prefetchCourseIcon".
* @param {any} course Course to prefetch.
* @param {any[]} [sections] List of course sections.
* @param {CoreCoursesHandlerToDisplay[]} courseHandlers List of course handlers.
* @param {CoreCourseOptionsHandlerToDisplay[]} courseHandlers List of course handlers.
* @return {Promise<boolean>} Promise resolved with true when the download finishes, resolved with false if user doesn't
* confirm, rejected if an error occurs.
*/
confirmAndPrefetchCourse(iconData: any, course: any, sections?: any[], courseHandlers?: CoreCoursesHandlerToDisplay[])
confirmAndPrefetchCourse(iconData: any, course: any, sections?: any[], courseHandlers?: CoreCourseOptionsHandlerToDisplay[])
: Promise<boolean> {
let initialIcon = iconData.prefetchCourseIcon,
promise,
@ -268,10 +268,10 @@ export class CoreCourseHelperProvider {
if (courseHandlers) {
promise = Promise.resolve(courseHandlers);
} else {
promise = this.coursesDelegate.getHandlersToDisplay(course);
promise = this.courseOptionsDelegate.getHandlersToDisplay(course);
}
return promise.then((handlers: CoreCoursesHandlerToDisplay[]) => {
return promise.then((handlers: CoreCourseOptionsHandlerToDisplay[]) => {
// Now we have all the data, download the course.
return this.prefetchCourse(course, sections, handlers, siteId);
}).then(() => {
@ -315,7 +315,7 @@ export class CoreCourseHelperProvider {
subPromises.push(this.courseProvider.getSections(course.id, false, true).then((courseSections) => {
sections = courseSections;
}));
subPromises.push(this.coursesDelegate.getHandlersToDisplay(course).then((cHandlers) => {
subPromises.push(this.courseOptionsDelegate.getHandlersToDisplay(course).then((cHandlers) => {
handlers = cHandlers;
}));
@ -662,11 +662,12 @@ export class CoreCourseHelperProvider {
*
* @param {any} course The course to prefetch.
* @param {any[]} sections List of course sections.
* @param {CoreCoursesHandlerToDisplay[]} courseHandlers List of course handlers.
* @param {CoreCourseOptionsHandlerToDisplay[]} courseHandlers List of course options handlers.
* @param {string} [siteId] Site ID. If not defined, current site.
* @return {Promise} Promise resolved when the download finishes.
*/
prefetchCourse(course: any, sections: any[], courseHandlers: CoreCoursesHandlerToDisplay[], siteId?: string) : Promise<any> {
prefetchCourse(course: any, sections: any[], courseHandlers: CoreCourseOptionsHandlerToDisplay[], siteId?: string)
: Promise<any> {
siteId = siteId || this.sitesProvider.getCurrentSiteId();
if (this.courseDwnPromises[siteId] && this.courseDwnPromises[siteId][course.id]) {

View File

@ -18,12 +18,13 @@ import { CoreEventsProvider } from '../../../providers/events';
import { CoreLoggerProvider } from '../../../providers/logger';
import { CoreSitesProvider } from '../../../providers/sites';
import { CoreUtilsProvider, PromiseDefer } from '../../../providers/utils/utils';
import { CoreCoursesProvider } from './courses';
import { CoreCoursesProvider } from '../../courses/providers/courses';
import { CoreCourseProvider } from './course';
/**
* Interface that all courses handlers must implement.
* Interface that all course options handlers must implement.
*/
export interface CoreCoursesHandler extends CoreDelegateHandler {
export interface CoreCourseOptionsHandler extends CoreDelegateHandler {
/**
* The highest priority is displayed first.
* @type {number}
@ -57,9 +58,9 @@ export interface CoreCoursesHandler extends CoreDelegateHandler {
* Returns the data needed to render the handler.
*
* @param {number} courseId The course ID.
* @return {CoreCoursesHandlerData} Data.
* @return {CoreCourseOptionsHandlerData} Data.
*/
getDisplayData?(courseId: number): CoreCoursesHandlerData;
getDisplayData?(courseId: number): CoreCourseOptionsHandlerData;
/**
* Should invalidate the data to determine if the handler is enabled for a certain course.
@ -83,7 +84,7 @@ export interface CoreCoursesHandler extends CoreDelegateHandler {
/**
* Data needed to render a course handler. It's returned by the handler.
*/
export interface CoreCoursesHandlerData {
export interface CoreCourseOptionsHandlerData {
/**
* Title to display for the handler.
* @type {string}
@ -113,12 +114,12 @@ export interface CoreCoursesHandlerData {
/**
* Data returned by the delegate for each handler.
*/
export interface CoreCoursesHandlerToDisplay {
export interface CoreCourseOptionsHandlerToDisplay {
/**
* Data to display.
* @type {CoreCoursesHandlerData}
* @type {CoreCourseOptionsHandlerData}
*/
data: CoreCoursesHandlerData;
data: CoreCourseOptionsHandlerData;
/**
* The highest priority is displayed first.
@ -136,17 +137,17 @@ export interface CoreCoursesHandlerToDisplay {
}
/**
* Service to interact with plugins to be shown in each course.
* Service to interact with plugins to be shown in each course (participants, learning plans, ...).
*/
@Injectable()
export class CoreCoursesDelegate extends CoreDelegate {
protected handlers: { [s: string]: CoreCoursesHandler } = {}; // All registered handlers.
protected enabledHandlers: { [s: string]: CoreCoursesHandler } = {}; // Handlers enabled for the current site.
export class CoreCourseOptionsDelegate extends CoreDelegate {
protected handlers: { [s: string]: CoreCourseOptionsHandler } = {}; // All registered handlers.
protected enabledHandlers: { [s: string]: CoreCourseOptionsHandler } = {}; // Handlers enabled for the current site.
protected loaded: { [courseId: number]: boolean } = {};
protected lastUpdateHandlersForCoursesStart: any = {};
protected coursesHandlers: {
[courseId: number]: {
access?: any, navOptions?: any, admOptions?: any, deferred?: PromiseDefer, enabledHandlers?: CoreCoursesHandler[]
access?: any, navOptions?: any, admOptions?: any, deferred?: PromiseDefer, enabledHandlers?: CoreCourseOptionsHandler[]
}
} = {};
@ -154,7 +155,7 @@ export class CoreCoursesDelegate extends CoreDelegate {
constructor(loggerProvider: CoreLoggerProvider, protected sitesProvider: CoreSitesProvider, private utils: CoreUtilsProvider,
protected eventsProvider: CoreEventsProvider, private coursesProvider: CoreCoursesProvider) {
super('CoreMainMenuDelegate', loggerProvider, sitesProvider, eventsProvider);
super('CoreCourseOptionsDelegate', loggerProvider, sitesProvider, eventsProvider);
eventsProvider.on(CoreEventsProvider.LOGOUT, () => {
this.clearCoursesHandlers();
@ -172,7 +173,7 @@ export class CoreCoursesDelegate extends CoreDelegate {
}
/**
* Clear all courses handlers.
* Clear all course options handlers.
*
* @param {number} [courseId] The course ID. If not defined, all handlers will be cleared.
*/
@ -200,7 +201,7 @@ export class CoreCoursesDelegate extends CoreDelegate {
// Invalidate course enabled data for the handlers that are enabled at site level.
if (courseId) {
// Invalidate only options for this course.
promises.push(this.coursesProvider.invalidateCoursesOptions([courseId]));
promises.push(this.coursesProvider.invalidateCoursesAdminAndNavOptions([courseId]));
promises.push(this.invalidateCourseHandlers(courseId));
} else {
// Invalidate all options.
@ -225,10 +226,10 @@ export class CoreCoursesDelegate extends CoreDelegate {
* @param {any} accessData Access type and data. Default, guest, ...
* @param {any} [navOptions] Course navigation options for current user. See CoreCoursesProvider.getUserNavigationOptions.
* @param {any} [admOptions] Course admin options for current user. See CoreCoursesProvider.getUserAdministrationOptions.
* @return {Promise<CoreCoursesHandler[]>} Promise resolved with array of handlers.
* @return {Promise<CoreCourseOptionsHandler[]>} Promise resolved with array of handlers.
*/
protected getHandlersForAccess(courseId: number, refresh: boolean, accessData: any, navOptions?: any,
admOptions?: any): Promise<CoreCoursesHandler[]> {
admOptions?: any): Promise<CoreCourseOptionsHandler[]> {
// If the handlers aren't loaded, do not refresh.
if (!this.loaded[courseId]) {
@ -260,14 +261,14 @@ export class CoreCoursesDelegate extends CoreDelegate {
* @param {boolean} [isGuest] Whether it's guest.
* @param {any} [navOptions] Course navigation options for current user. See CoreCoursesProvider.getUserNavigationOptions.
* @param {any} [admOptions] Course admin options for current user. See CoreCoursesProvider.getUserAdministrationOptions.
* @return {Promise<CoreCoursesHandlerToDisplay[]>} Promise resolved with array of handlers.
* @return {Promise<CoreCourseOptionsHandlerToDisplay[]>} Promise resolved with array of handlers.
*/
getHandlersToDisplay(course: any, refresh?: boolean, isGuest?: boolean, navOptions?: any, admOptions?: any):
Promise<CoreCoursesHandlerToDisplay[]> {
Promise<CoreCourseOptionsHandlerToDisplay[]> {
course.id = parseInt(course.id, 10);
let accessData = {
type: isGuest ? CoreCoursesProvider.ACCESS_GUEST : CoreCoursesProvider.ACCESS_DEFAULT
type: isGuest ? CoreCourseProvider.ACCESS_GUEST : CoreCourseProvider.ACCESS_DEFAULT
};
if (navOptions) {
@ -281,7 +282,7 @@ export class CoreCoursesDelegate extends CoreDelegate {
// Call getHandlersForAccess to make sure the handlers have been loaded.
return this.getHandlersForAccess(course.id, refresh, accessData, course.navOptions, course.admOptions);
}).then(() => {
let handlersToDisplay: CoreCoursesHandlerToDisplay[] = [],
let handlersToDisplay: CoreCourseOptionsHandlerToDisplay[] = [],
promises = [],
promise;
@ -342,7 +343,7 @@ export class CoreCoursesDelegate extends CoreDelegate {
hasHandlersForDefault(courseId: number, refresh?: boolean, navOptions?: any, admOptions?: any): Promise<boolean> {
// Default access.
let accessData = {
type: CoreCoursesProvider.ACCESS_DEFAULT
type: CoreCourseProvider.ACCESS_DEFAULT
};
return this.getHandlersForAccess(courseId, refresh, accessData, navOptions, admOptions).then((handlers) => {
return !!(handlers && handlers.length);
@ -361,7 +362,7 @@ export class CoreCoursesDelegate extends CoreDelegate {
hasHandlersForGuest(courseId: number, refresh?: boolean, navOptions?: any, admOptions?: any): Promise<boolean> {
// Guest access.
var accessData = {
type: CoreCoursesProvider.ACCESS_GUEST
type: CoreCourseProvider.ACCESS_GUEST
};
return this.getHandlersForAccess(courseId, refresh, accessData, navOptions, admOptions).then((handlers) => {
return !!(handlers && handlers.length);
@ -416,7 +417,7 @@ export class CoreCoursesDelegate extends CoreDelegate {
*/
protected loadCourseOptions(course: any, refresh?: boolean): Promise<void> {
if (typeof course.navOptions == 'undefined' || typeof course.admOptions == 'undefined' || refresh) {
return this.coursesProvider.getCoursesOptions([course.id]).then((options) => {
return this.coursesProvider.getCoursesAdminAndNavOptions([course.id]).then((options) => {
course.navOptions = options.navOptions[course.id];
course.admOptions = options.admOptions[course.id];
});
@ -425,7 +426,12 @@ export class CoreCoursesDelegate extends CoreDelegate {
}
}
updateData(siteId?: string) {
/**
* Update handlers for each course.
*
* @param {string} [siteId] Site ID.
*/
updateData(siteId?: string): void {
if (this.sitesProvider.getCurrentSiteId() === siteId) {
// Update handlers for all courses.
for (let courseId in this.coursesHandlers) {
@ -458,7 +464,7 @@ export class CoreCoursesDelegate extends CoreDelegate {
// Checks if the handler is enabled for the user.
promises.push(Promise.resolve(handler.isEnabledForCourse(courseId, accessData, navOptions, admOptions))
.then(function(enabled) {
.then((enabled) => {
if (enabled) {
enabledForCourse.push(handler);
} else {

View File

@ -16,7 +16,6 @@ import { NgModule } from '@angular/core';
import { CoreCoursesProvider } from './providers/courses';
import { CoreCoursesMainMenuHandler } from './providers/mainmenu-handler';
import { CoreCoursesMyOverviewProvider } from './providers/my-overview';
import { CoreCoursesDelegate } from './providers/delegate';
import { CoreCoursesCourseLinkHandler } from './providers/course-link-handler';
import { CoreCoursesIndexLinkHandler } from './providers/courses-index-link-handler';
import { CoreCoursesMyOverviewLinkHandler } from './providers/my-overview-link-handler';
@ -31,7 +30,6 @@ import { CoreContentLinksDelegate } from '../contentlinks/providers/delegate';
CoreCoursesProvider,
CoreCoursesMainMenuHandler,
CoreCoursesMyOverviewProvider,
CoreCoursesDelegate,
CoreCoursesCourseLinkHandler,
CoreCoursesIndexLinkHandler,
CoreCoursesMyOverviewLinkHandler

View File

@ -21,7 +21,7 @@ import { CoreSitesProvider } from '../../../../providers/sites';
import { CoreDomUtilsProvider } from '../../../../providers/utils/dom';
import { CoreTextUtilsProvider } from '../../../../providers/utils/text';
import { CoreCoursesProvider } from '../../providers/courses';
import { CoreCoursesDelegate } from '../../providers/delegate';
import { CoreCourseOptionsDelegate } from '../../../course/providers/options-delegate';
import { CoreCourseProvider } from '../../../course/providers/course';
import { CoreCourseHelperProvider } from '../../../course/providers/helper';
@ -65,7 +65,7 @@ export class CoreCoursesCoursePreviewPage implements OnDestroy {
private domUtils: CoreDomUtilsProvider, private textUtils: CoreTextUtilsProvider, appProvider: CoreAppProvider,
private coursesProvider: CoreCoursesProvider, private platform: Platform, private modalCtrl: ModalController,
private translate: TranslateService, private eventsProvider: CoreEventsProvider,
private coursesDelegate: CoreCoursesDelegate, private courseHelper: CoreCourseHelperProvider,
private courseOptionsDelegate: CoreCourseOptionsDelegate, private courseHelper: CoreCourseHelperProvider,
private courseProvider: CoreCourseProvider) {
this.course = navParams.get('course');
this.isMobile = appProvider.isMobile();
@ -228,7 +228,7 @@ export class CoreCoursesCoursePreviewPage implements OnDestroy {
* @param {boolean} guest Whether it's guest access.
*/
protected loadCourseHandlers(refresh: boolean, guest: boolean) : Promise<any> {
return this.coursesDelegate.getHandlersToDisplay(this.course, refresh, guest, true).then((handlers) => {
return this.courseOptionsDelegate.getHandlersToDisplay(this.course, refresh, guest, true).then((handlers) => {
this.course._handlers = handlers;
this.handlersShouldBeShown = true;
this.handlersLoaded = true;
@ -375,7 +375,7 @@ export class CoreCoursesCoursePreviewPage implements OnDestroy {
promises.push(this.coursesProvider.invalidateUserCourses());
promises.push(this.coursesProvider.invalidateCourse(this.course.id));
promises.push(this.coursesProvider.invalidateCourseEnrolmentMethods(this.course.id));
// promises.push($mmCoursesDelegate.clearAndInvalidateCoursesOptions(course.id));
promises.push(this.courseOptionsDelegate.clearAndInvalidateCoursesOptions(this.course.id));
if (this.guestInstanceId) {
promises.push(this.coursesProvider.invalidateCourseGuestEnrolmentInfo(this.guestInstanceId));
}

View File

@ -19,6 +19,7 @@ import { CoreSitesProvider } from '../../../../providers/sites';
import { CoreDomUtilsProvider } from '../../../../providers/utils/dom';
import { CoreCoursesProvider } from '../../providers/courses';
import { CoreCourseHelperProvider } from '../../../course/providers/helper';
import { CoreCourseOptionsDelegate } from '../../../course/providers/options-delegate';
/**
* Page that displays the list of courses the user is enrolled in.
@ -44,7 +45,8 @@ export class CoreCoursesMyCoursesPage implements OnDestroy {
constructor(private navCtrl: NavController, private coursesProvider: CoreCoursesProvider,
private domUtils: CoreDomUtilsProvider, private eventsProvider: CoreEventsProvider,
private sitesProvider: CoreSitesProvider, private courseHelper: CoreCourseHelperProvider) {}
private sitesProvider: CoreSitesProvider, private courseHelper: CoreCourseHelperProvider,
private courseOptionsDelegate: CoreCourseOptionsDelegate) {}
/**
* View loaded.
@ -75,7 +77,7 @@ export class CoreCoursesMyCoursesPage implements OnDestroy {
return course.id;
});
return this.coursesProvider.getCoursesOptions(courseIds).then((options) => {
return this.coursesProvider.getCoursesAdminAndNavOptions(courseIds).then((options) => {
courses.forEach((course) => {
course.navOptions = options.navOptions[course.id];
course.admOptions = options.admOptions[course.id];
@ -100,7 +102,7 @@ export class CoreCoursesMyCoursesPage implements OnDestroy {
let promises = [];
promises.push(this.coursesProvider.invalidateUserCourses());
// promises.push($mmCoursesDelegate.clearAndInvalidateCoursesOptions());
promises.push(this.courseOptionsDelegate.clearAndInvalidateCoursesOptions());
Promise.all(promises).finally(() => {

View File

@ -17,9 +17,9 @@ import { IonicPage, NavController } from 'ionic-angular';
import { CoreSitesProvider } from '../../../../providers/sites';
import { CoreDomUtilsProvider } from '../../../../providers/utils/dom';
import { CoreCoursesProvider } from '../../providers/courses';
import { CoreCoursesDelegate } from '../../providers/delegate';
import { CoreCoursesMyOverviewProvider } from '../../providers/my-overview';
import { CoreCourseHelperProvider } from '../../../course/providers/helper';
import { CoreCourseOptionsDelegate } from '../../../course/providers/options-delegate';
import { CoreSiteHomeProvider } from '../../../sitehome/providers/sitehome';
import * as moment from 'moment';
@ -71,7 +71,7 @@ export class CoreCoursesMyOverviewPage implements OnDestroy {
constructor(private navCtrl: NavController, private coursesProvider: CoreCoursesProvider,
private domUtils: CoreDomUtilsProvider, private myOverviewProvider: CoreCoursesMyOverviewProvider,
private courseHelper: CoreCourseHelperProvider, private sitesProvider: CoreSitesProvider,
private siteHomeProvider: CoreSiteHomeProvider, private coursesDelegate: CoreCoursesDelegate) {}
private siteHomeProvider: CoreSiteHomeProvider, private courseOptionsDelegate: CoreCourseOptionsDelegate) {}
/**
* View loaded.
@ -185,7 +185,7 @@ export class CoreCoursesMyOverviewPage implements OnDestroy {
});
// Load course options of the course.
return this.coursesProvider.getCoursesOptions(courseIds).then((options) => {
return this.coursesProvider.getCoursesAdminAndNavOptions(courseIds).then((options) => {
courses.forEach((course) => {
course.navOptions = options.navOptions[course.id];
course.admOptions = options.admOptions[course.id];
@ -239,7 +239,7 @@ export class CoreCoursesMyOverviewPage implements OnDestroy {
}
promises.push(this.coursesProvider.invalidateUserCourses());
promises.push(this.coursesDelegate.clearAndInvalidateCoursesOptions());
promises.push(this.courseOptionsDelegate.clearAndInvalidateCoursesOptions());
return Promise.all(promises).finally(() => {
switch (this.tabShown) {

View File

@ -26,8 +26,6 @@ export class CoreCoursesProvider {
public static ENROL_INVALID_KEY = 'CoreCoursesEnrolInvalidKey';
public static EVENT_MY_COURSES_UPDATED = 'courses_my_courses_updated';
public static EVENT_MY_COURSES_REFRESHED = 'courses_my_courses_refreshed';
public static ACCESS_GUEST = 'courses_access_guest';
public static ACCESS_DEFAULT = 'courses_access_default';
protected ROOT_CACHE_KEY = 'mmCourses:';
protected logger;
@ -73,13 +71,13 @@ export class CoreCoursesProvider {
}
/**
* Given a list of course IDs to get course options, return the list of courseIds to use.
* Given a list of course IDs to get course admin and nav options, return the list of courseIds to use.
*
* @param {number[]} courseIds Course IDs.
* @param {string} [siteId] Site Id. If not defined, use current site.
* @return {Promise} Promise resolved with the list of course IDs.
*/
protected getCourseIdsForOptions(courseIds: number[], siteId?: string) : Promise<number[]> {
protected getCourseIdsForAdminAndNavOptions(courseIds: number[], siteId?: string) : Promise<number[]> {
return this.sitesProvider.getSite(siteId).then((site) => {
const siteHomeId = site.getSiteHomeId();
@ -364,11 +362,11 @@ export class CoreCoursesProvider {
* @param {string} [siteId] Site ID. If not defined, current site.
* @return {Promise<{navOptions: any, admOptions: any}>} Promise resolved with the options for each course.
*/
getCoursesOptions(courseIds: number[], siteId?: string) : Promise<{navOptions: any, admOptions: any}> {
getCoursesAdminAndNavOptions(courseIds: number[], siteId?: string) : Promise<{navOptions: any, admOptions: any}> {
siteId = siteId || this.sitesProvider.getCurrentSiteId();
// Get the list of courseIds to use based on the param.
return this.getCourseIdsForOptions(courseIds, siteId).then((courseIds) => {
return this.getCourseIdsForAdminAndNavOptions(courseIds, siteId).then((courseIds) => {
let promises = [],
navOptions,
admOptions;
@ -431,7 +429,7 @@ export class CoreCoursesProvider {
return site.read('core_course_get_user_administration_options', params, preSets).then((response) => {
// Format returned data.
return this.formatUserOptions(response.courses);
return this.formatUserAdminOrNavOptions(response.courses);
});
});
}
@ -473,7 +471,7 @@ export class CoreCoursesProvider {
return site.read('core_course_get_user_navigation_options', params, preSets).then((response) => {
// Format returned data.
return this.formatUserOptions(response.courses);
return this.formatUserAdminOrNavOptions(response.courses);
});
});
}
@ -484,7 +482,7 @@ export class CoreCoursesProvider {
* @param {any[]} courses Navigation or administration options for each course.
* @return {any} Formatted options.
*/
protected formatUserOptions(courses: any[]) : any {
protected formatUserAdminOrNavOptions(courses: any[]) : any {
let result = {};
courses.forEach((course) => {
@ -619,10 +617,10 @@ export class CoreCoursesProvider {
* @param {string} [siteId] Site ID to invalidate. If not defined, use current site.
* @return {Promise<any>} Promise resolved when the data is invalidated.
*/
invalidateCoursesOptions(courseIds: number[], siteId?: string) : Promise<any> {
invalidateCoursesAdminAndNavOptions(courseIds: number[], siteId?: string) : Promise<any> {
siteId = siteId || this.sitesProvider.getCurrentSiteId();
return this.getCourseIdsForOptions(courseIds, siteId).then((ids) => {
return this.getCourseIdsForAdminAndNavOptions(courseIds, siteId).then((ids) => {
let promises = [];
promises.push(this.invalidateUserAdministrationOptionsForCourses(ids, siteId));

View File

@ -145,7 +145,7 @@ export class CoreUserDelegate extends CoreDelegate {
return course.id;
});
return this.coursesProvider.getCoursesOptions(courseIds).then((options) => {
return this.coursesProvider.getCoursesAdminAndNavOptions(courseIds).then((options) => {
// For backwards compatibility we don't modify the courseId.
let courseIdForOptions = courseId || this.sitesProvider.getCurrentSiteHomeId(),
navOptions = options.navOptions[courseIdForOptions],