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

View File

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

View File

@ -28,6 +28,9 @@ import { CoreConstants } from '../../constants';
@Injectable() @Injectable()
export class CoreCourseProvider { export class CoreCourseProvider {
public static ALL_SECTIONS_ID = -1; 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:'; protected ROOT_CACHE_KEY = 'mmCourse:';
// Variables for database. // Variables for database.

View File

@ -21,7 +21,7 @@ import { CoreDomUtilsProvider } from '../../../providers/utils/dom';
import { CoreTextUtilsProvider } from '../../../providers/utils/text'; import { CoreTextUtilsProvider } from '../../../providers/utils/text';
import { CoreTimeUtilsProvider } from '../../../providers/utils/time'; import { CoreTimeUtilsProvider } from '../../../providers/utils/time';
import { CoreUtilsProvider } from '../../../providers/utils/utils'; 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 { CoreSiteHomeProvider } from '../../sitehome/providers/sitehome';
import { CoreCourseProvider } from './course'; import { CoreCourseProvider } from './course';
import { CoreCourseModuleDelegate } from './module-delegate'; import { CoreCourseModuleDelegate } from './module-delegate';
@ -113,8 +113,8 @@ export class CoreCourseHelperProvider {
private moduleDelegate: CoreCourseModuleDelegate, private prefetchDelegate: CoreCourseModulePrefetchDelegate, private moduleDelegate: CoreCourseModuleDelegate, private prefetchDelegate: CoreCourseModulePrefetchDelegate,
private filepoolProvider: CoreFilepoolProvider, private sitesProvider: CoreSitesProvider, private filepoolProvider: CoreFilepoolProvider, private sitesProvider: CoreSitesProvider,
private textUtils: CoreTextUtilsProvider, private timeUtils: CoreTimeUtilsProvider, private textUtils: CoreTextUtilsProvider, private timeUtils: CoreTimeUtilsProvider,
private utils: CoreUtilsProvider, private translate: TranslateService, private coursesDelegate: CoreCoursesDelegate, private utils: CoreUtilsProvider, private translate: TranslateService, private loginHelper: CoreLoginHelperProvider,
private loginHelper: CoreLoginHelperProvider, private siteHomeProvider: CoreSiteHomeProvider) {} private courseOptionsDelegate: CoreCourseOptionsDelegate, private siteHomeProvider: CoreSiteHomeProvider) {}
/** /**
* This function treats every module on the sections provided to load the handler data, treat completion * 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} 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} course Course to prefetch.
* @param {any[]} [sections] List of course sections. * @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 * @return {Promise<boolean>} Promise resolved with true when the download finishes, resolved with false if user doesn't
* confirm, rejected if an error occurs. * 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> { : Promise<boolean> {
let initialIcon = iconData.prefetchCourseIcon, let initialIcon = iconData.prefetchCourseIcon,
promise, promise,
@ -268,10 +268,10 @@ export class CoreCourseHelperProvider {
if (courseHandlers) { if (courseHandlers) {
promise = Promise.resolve(courseHandlers); promise = Promise.resolve(courseHandlers);
} else { } 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. // Now we have all the data, download the course.
return this.prefetchCourse(course, sections, handlers, siteId); return this.prefetchCourse(course, sections, handlers, siteId);
}).then(() => { }).then(() => {
@ -315,7 +315,7 @@ export class CoreCourseHelperProvider {
subPromises.push(this.courseProvider.getSections(course.id, false, true).then((courseSections) => { subPromises.push(this.courseProvider.getSections(course.id, false, true).then((courseSections) => {
sections = courseSections; sections = courseSections;
})); }));
subPromises.push(this.coursesDelegate.getHandlersToDisplay(course).then((cHandlers) => { subPromises.push(this.courseOptionsDelegate.getHandlersToDisplay(course).then((cHandlers) => {
handlers = cHandlers; handlers = cHandlers;
})); }));
@ -662,11 +662,12 @@ export class CoreCourseHelperProvider {
* *
* @param {any} course The course to prefetch. * @param {any} course The course to prefetch.
* @param {any[]} sections List of course sections. * @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. * @param {string} [siteId] Site ID. If not defined, current site.
* @return {Promise} Promise resolved when the download finishes. * @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(); siteId = siteId || this.sitesProvider.getCurrentSiteId();
if (this.courseDwnPromises[siteId] && this.courseDwnPromises[siteId][course.id]) { 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 { CoreLoggerProvider } from '../../../providers/logger';
import { CoreSitesProvider } from '../../../providers/sites'; import { CoreSitesProvider } from '../../../providers/sites';
import { CoreUtilsProvider, PromiseDefer } from '../../../providers/utils/utils'; 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. * The highest priority is displayed first.
* @type {number} * @type {number}
@ -57,9 +58,9 @@ export interface CoreCoursesHandler extends CoreDelegateHandler {
* Returns the data needed to render the handler. * Returns the data needed to render the handler.
* *
* @param {number} courseId The course ID. * @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. * 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. * 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. * Title to display for the handler.
* @type {string} * @type {string}
@ -113,12 +114,12 @@ export interface CoreCoursesHandlerData {
/** /**
* Data returned by the delegate for each handler. * Data returned by the delegate for each handler.
*/ */
export interface CoreCoursesHandlerToDisplay { export interface CoreCourseOptionsHandlerToDisplay {
/** /**
* Data to display. * Data to display.
* @type {CoreCoursesHandlerData} * @type {CoreCourseOptionsHandlerData}
*/ */
data: CoreCoursesHandlerData; data: CoreCourseOptionsHandlerData;
/** /**
* The highest priority is displayed first. * 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() @Injectable()
export class CoreCoursesDelegate extends CoreDelegate { export class CoreCourseOptionsDelegate extends CoreDelegate {
protected handlers: { [s: string]: CoreCoursesHandler } = {}; // All registered handlers. protected handlers: { [s: string]: CoreCourseOptionsHandler } = {}; // All registered handlers.
protected enabledHandlers: { [s: string]: CoreCoursesHandler } = {}; // Handlers enabled for the current site. protected enabledHandlers: { [s: string]: CoreCourseOptionsHandler } = {}; // Handlers enabled for the current site.
protected loaded: { [courseId: number]: boolean } = {}; protected loaded: { [courseId: number]: boolean } = {};
protected lastUpdateHandlersForCoursesStart: any = {}; protected lastUpdateHandlersForCoursesStart: any = {};
protected coursesHandlers: { protected coursesHandlers: {
[courseId: number]: { [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, constructor(loggerProvider: CoreLoggerProvider, protected sitesProvider: CoreSitesProvider, private utils: CoreUtilsProvider,
protected eventsProvider: CoreEventsProvider, private coursesProvider: CoreCoursesProvider) { protected eventsProvider: CoreEventsProvider, private coursesProvider: CoreCoursesProvider) {
super('CoreMainMenuDelegate', loggerProvider, sitesProvider, eventsProvider); super('CoreCourseOptionsDelegate', loggerProvider, sitesProvider, eventsProvider);
eventsProvider.on(CoreEventsProvider.LOGOUT, () => { eventsProvider.on(CoreEventsProvider.LOGOUT, () => {
this.clearCoursesHandlers(); 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. * @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. // Invalidate course enabled data for the handlers that are enabled at site level.
if (courseId) { if (courseId) {
// Invalidate only options for this course. // Invalidate only options for this course.
promises.push(this.coursesProvider.invalidateCoursesOptions([courseId])); promises.push(this.coursesProvider.invalidateCoursesAdminAndNavOptions([courseId]));
promises.push(this.invalidateCourseHandlers(courseId)); promises.push(this.invalidateCourseHandlers(courseId));
} else { } else {
// Invalidate all options. // Invalidate all options.
@ -225,10 +226,10 @@ export class CoreCoursesDelegate extends CoreDelegate {
* @param {any} accessData Access type and data. Default, guest, ... * @param {any} accessData Access type and data. Default, guest, ...
* @param {any} [navOptions] Course navigation options for current user. See CoreCoursesProvider.getUserNavigationOptions. * @param {any} [navOptions] Course navigation options for current user. See CoreCoursesProvider.getUserNavigationOptions.
* @param {any} [admOptions] Course admin options for current user. See CoreCoursesProvider.getUserAdministrationOptions. * @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, 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 the handlers aren't loaded, do not refresh.
if (!this.loaded[courseId]) { if (!this.loaded[courseId]) {
@ -260,14 +261,14 @@ export class CoreCoursesDelegate extends CoreDelegate {
* @param {boolean} [isGuest] Whether it's guest. * @param {boolean} [isGuest] Whether it's guest.
* @param {any} [navOptions] Course navigation options for current user. See CoreCoursesProvider.getUserNavigationOptions. * @param {any} [navOptions] Course navigation options for current user. See CoreCoursesProvider.getUserNavigationOptions.
* @param {any} [admOptions] Course admin options for current user. See CoreCoursesProvider.getUserAdministrationOptions. * @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): getHandlersToDisplay(course: any, refresh?: boolean, isGuest?: boolean, navOptions?: any, admOptions?: any):
Promise<CoreCoursesHandlerToDisplay[]> { Promise<CoreCourseOptionsHandlerToDisplay[]> {
course.id = parseInt(course.id, 10); course.id = parseInt(course.id, 10);
let accessData = { let accessData = {
type: isGuest ? CoreCoursesProvider.ACCESS_GUEST : CoreCoursesProvider.ACCESS_DEFAULT type: isGuest ? CoreCourseProvider.ACCESS_GUEST : CoreCourseProvider.ACCESS_DEFAULT
}; };
if (navOptions) { if (navOptions) {
@ -281,7 +282,7 @@ export class CoreCoursesDelegate extends CoreDelegate {
// Call getHandlersForAccess to make sure the handlers have been loaded. // Call getHandlersForAccess to make sure the handlers have been loaded.
return this.getHandlersForAccess(course.id, refresh, accessData, course.navOptions, course.admOptions); return this.getHandlersForAccess(course.id, refresh, accessData, course.navOptions, course.admOptions);
}).then(() => { }).then(() => {
let handlersToDisplay: CoreCoursesHandlerToDisplay[] = [], let handlersToDisplay: CoreCourseOptionsHandlerToDisplay[] = [],
promises = [], promises = [],
promise; promise;
@ -342,7 +343,7 @@ export class CoreCoursesDelegate extends CoreDelegate {
hasHandlersForDefault(courseId: number, refresh?: boolean, navOptions?: any, admOptions?: any): Promise<boolean> { hasHandlersForDefault(courseId: number, refresh?: boolean, navOptions?: any, admOptions?: any): Promise<boolean> {
// Default access. // Default access.
let accessData = { let accessData = {
type: CoreCoursesProvider.ACCESS_DEFAULT type: CoreCourseProvider.ACCESS_DEFAULT
}; };
return this.getHandlersForAccess(courseId, refresh, accessData, navOptions, admOptions).then((handlers) => { return this.getHandlersForAccess(courseId, refresh, accessData, navOptions, admOptions).then((handlers) => {
return !!(handlers && handlers.length); return !!(handlers && handlers.length);
@ -361,7 +362,7 @@ export class CoreCoursesDelegate extends CoreDelegate {
hasHandlersForGuest(courseId: number, refresh?: boolean, navOptions?: any, admOptions?: any): Promise<boolean> { hasHandlersForGuest(courseId: number, refresh?: boolean, navOptions?: any, admOptions?: any): Promise<boolean> {
// Guest access. // Guest access.
var accessData = { var accessData = {
type: CoreCoursesProvider.ACCESS_GUEST type: CoreCourseProvider.ACCESS_GUEST
}; };
return this.getHandlersForAccess(courseId, refresh, accessData, navOptions, admOptions).then((handlers) => { return this.getHandlersForAccess(courseId, refresh, accessData, navOptions, admOptions).then((handlers) => {
return !!(handlers && handlers.length); return !!(handlers && handlers.length);
@ -416,7 +417,7 @@ export class CoreCoursesDelegate extends CoreDelegate {
*/ */
protected loadCourseOptions(course: any, refresh?: boolean): Promise<void> { protected loadCourseOptions(course: any, refresh?: boolean): Promise<void> {
if (typeof course.navOptions == 'undefined' || typeof course.admOptions == 'undefined' || refresh) { 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.navOptions = options.navOptions[course.id];
course.admOptions = options.admOptions[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) { if (this.sitesProvider.getCurrentSiteId() === siteId) {
// Update handlers for all courses. // Update handlers for all courses.
for (let courseId in this.coursesHandlers) { for (let courseId in this.coursesHandlers) {
@ -458,7 +464,7 @@ export class CoreCoursesDelegate extends CoreDelegate {
// Checks if the handler is enabled for the user. // Checks if the handler is enabled for the user.
promises.push(Promise.resolve(handler.isEnabledForCourse(courseId, accessData, navOptions, admOptions)) promises.push(Promise.resolve(handler.isEnabledForCourse(courseId, accessData, navOptions, admOptions))
.then(function(enabled) { .then((enabled) => {
if (enabled) { if (enabled) {
enabledForCourse.push(handler); enabledForCourse.push(handler);
} else { } else {

View File

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

View File

@ -21,7 +21,7 @@ import { CoreSitesProvider } from '../../../../providers/sites';
import { CoreDomUtilsProvider } from '../../../../providers/utils/dom'; import { CoreDomUtilsProvider } from '../../../../providers/utils/dom';
import { CoreTextUtilsProvider } from '../../../../providers/utils/text'; import { CoreTextUtilsProvider } from '../../../../providers/utils/text';
import { CoreCoursesProvider } from '../../providers/courses'; import { CoreCoursesProvider } from '../../providers/courses';
import { CoreCoursesDelegate } from '../../providers/delegate'; import { CoreCourseOptionsDelegate } from '../../../course/providers/options-delegate';
import { CoreCourseProvider } from '../../../course/providers/course'; import { CoreCourseProvider } from '../../../course/providers/course';
import { CoreCourseHelperProvider } from '../../../course/providers/helper'; import { CoreCourseHelperProvider } from '../../../course/providers/helper';
@ -65,7 +65,7 @@ export class CoreCoursesCoursePreviewPage implements OnDestroy {
private domUtils: CoreDomUtilsProvider, private textUtils: CoreTextUtilsProvider, appProvider: CoreAppProvider, private domUtils: CoreDomUtilsProvider, private textUtils: CoreTextUtilsProvider, appProvider: CoreAppProvider,
private coursesProvider: CoreCoursesProvider, private platform: Platform, private modalCtrl: ModalController, private coursesProvider: CoreCoursesProvider, private platform: Platform, private modalCtrl: ModalController,
private translate: TranslateService, private eventsProvider: CoreEventsProvider, private translate: TranslateService, private eventsProvider: CoreEventsProvider,
private coursesDelegate: CoreCoursesDelegate, private courseHelper: CoreCourseHelperProvider, private courseOptionsDelegate: CoreCourseOptionsDelegate, private courseHelper: CoreCourseHelperProvider,
private courseProvider: CoreCourseProvider) { private courseProvider: CoreCourseProvider) {
this.course = navParams.get('course'); this.course = navParams.get('course');
this.isMobile = appProvider.isMobile(); this.isMobile = appProvider.isMobile();
@ -228,7 +228,7 @@ export class CoreCoursesCoursePreviewPage implements OnDestroy {
* @param {boolean} guest Whether it's guest access. * @param {boolean} guest Whether it's guest access.
*/ */
protected loadCourseHandlers(refresh: boolean, guest: boolean) : Promise<any> { 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.course._handlers = handlers;
this.handlersShouldBeShown = true; this.handlersShouldBeShown = true;
this.handlersLoaded = true; this.handlersLoaded = true;
@ -375,7 +375,7 @@ export class CoreCoursesCoursePreviewPage implements OnDestroy {
promises.push(this.coursesProvider.invalidateUserCourses()); promises.push(this.coursesProvider.invalidateUserCourses());
promises.push(this.coursesProvider.invalidateCourse(this.course.id)); promises.push(this.coursesProvider.invalidateCourse(this.course.id));
promises.push(this.coursesProvider.invalidateCourseEnrolmentMethods(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) { if (this.guestInstanceId) {
promises.push(this.coursesProvider.invalidateCourseGuestEnrolmentInfo(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 { CoreDomUtilsProvider } from '../../../../providers/utils/dom';
import { CoreCoursesProvider } from '../../providers/courses'; import { CoreCoursesProvider } from '../../providers/courses';
import { CoreCourseHelperProvider } from '../../../course/providers/helper'; 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. * 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, constructor(private navCtrl: NavController, private coursesProvider: CoreCoursesProvider,
private domUtils: CoreDomUtilsProvider, private eventsProvider: CoreEventsProvider, private domUtils: CoreDomUtilsProvider, private eventsProvider: CoreEventsProvider,
private sitesProvider: CoreSitesProvider, private courseHelper: CoreCourseHelperProvider) {} private sitesProvider: CoreSitesProvider, private courseHelper: CoreCourseHelperProvider,
private courseOptionsDelegate: CoreCourseOptionsDelegate) {}
/** /**
* View loaded. * View loaded.
@ -75,7 +77,7 @@ export class CoreCoursesMyCoursesPage implements OnDestroy {
return course.id; return course.id;
}); });
return this.coursesProvider.getCoursesOptions(courseIds).then((options) => { return this.coursesProvider.getCoursesAdminAndNavOptions(courseIds).then((options) => {
courses.forEach((course) => { courses.forEach((course) => {
course.navOptions = options.navOptions[course.id]; course.navOptions = options.navOptions[course.id];
course.admOptions = options.admOptions[course.id]; course.admOptions = options.admOptions[course.id];
@ -100,7 +102,7 @@ export class CoreCoursesMyCoursesPage implements OnDestroy {
let promises = []; let promises = [];
promises.push(this.coursesProvider.invalidateUserCourses()); promises.push(this.coursesProvider.invalidateUserCourses());
// promises.push($mmCoursesDelegate.clearAndInvalidateCoursesOptions()); promises.push(this.courseOptionsDelegate.clearAndInvalidateCoursesOptions());
Promise.all(promises).finally(() => { Promise.all(promises).finally(() => {

View File

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

View File

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

View File

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