diff --git a/src/addon/block/timeline/providers/timeline.ts b/src/addon/block/timeline/providers/timeline.ts index 942ba4ba5..148aed267 100644 --- a/src/addon/block/timeline/providers/timeline.ts +++ b/src/addon/block/timeline/providers/timeline.ts @@ -14,6 +14,7 @@ import { Injectable } from '@angular/core'; import { CoreSitesProvider } from '@providers/sites'; +import { CoreCoursesDashboardProvider } from '@core/courses/providers/dashboard'; import * as moment from 'moment'; /** @@ -26,7 +27,7 @@ export class AddonBlockTimelineProvider { // Cache key was maintained when moving the functions to this file. It comes from core myoverview. protected ROOT_CACHE_KEY = 'myoverview:'; - constructor(private sitesProvider: CoreSitesProvider) { } + constructor(private sitesProvider: CoreSitesProvider, private dashboardProvider: CoreCoursesDashboardProvider) { } /** * Get calendar action events for the given course. @@ -218,6 +219,11 @@ export class AddonBlockTimelineProvider { */ isAvailable(siteId?: string): Promise { return this.sitesProvider.getSite(siteId).then((site) => { + // First check if dashboard is disabled. + if (this.dashboardProvider.isDisabledInSite(site)) { + return false; + } + return site.wsAvailable('core_calendar_get_action_events_by_courses') && site.wsAvailable('core_calendar_get_action_events_by_timesort'); }); diff --git a/src/core/courses/pages/dashboard/dashboard.ts b/src/core/courses/pages/dashboard/dashboard.ts index cff6155b2..94bd5243a 100644 --- a/src/core/courses/pages/dashboard/dashboard.ts +++ b/src/core/courses/pages/dashboard/dashboard.ts @@ -142,8 +142,8 @@ export class CoreCoursesDashboardPage implements OnDestroy { * @return {Promise} Promise resolved when done. */ protected loadDashboardContent(): Promise { - return this.dashboardProvider.isAvailable().then((enabled) => { - if (enabled) { + return this.dashboardProvider.isAvailable().then((available) => { + if (available) { this.userId = this.sitesProvider.getCurrentSiteUserId(); return this.dashboardProvider.getDashboardBlocks().then((blocks) => { @@ -154,10 +154,14 @@ export class CoreCoursesDashboardPage implements OnDestroy { // Cannot get the blocks, just show dashboard if needed. this.loadFallbackBlocks(); }); + } else if (!this.dashboardProvider.isDisabledInSite()) { + // Not available, but not disabled either. Use fallback. + this.loadFallbackBlocks(); + } else { + // Disabled. + this.blocks = []; } - // Not enabled, check separated tabs. - this.loadFallbackBlocks(); }).finally(() => { this.dashboardEnabled = this.blockDelegate.hasSupportedBlock(this.blocks); this.dashboardLoaded = true; diff --git a/src/core/courses/providers/dashboard-link-handler.ts b/src/core/courses/providers/dashboard-link-handler.ts index bd325c80e..26f00164e 100644 --- a/src/core/courses/providers/dashboard-link-handler.ts +++ b/src/core/courses/providers/dashboard-link-handler.ts @@ -16,6 +16,7 @@ import { Injectable } from '@angular/core'; import { CoreContentLinksHandlerBase } from '@core/contentlinks/classes/base-handler'; import { CoreContentLinksAction } from '@core/contentlinks/providers/delegate'; import { CoreLoginHelperProvider } from '@core/login/providers/helper'; +import { CoreDashboardMainMenuHandler } from './mainmenu-handler'; /** * Handler to treat links to my overview. @@ -23,10 +24,9 @@ import { CoreLoginHelperProvider } from '@core/login/providers/helper'; @Injectable() export class CoreCoursesDashboardLinkHandler extends CoreContentLinksHandlerBase { name = 'CoreCoursesMyOverviewLinkHandler'; - featureName = 'CoreMainMenuDelegate_CoreCourses'; pattern = /\/my\/?$/; - constructor(private loginHelper: CoreLoginHelperProvider) { + constructor(private loginHelper: CoreLoginHelperProvider, private mainMenuHandler: CoreDashboardMainMenuHandler) { super(); } @@ -48,4 +48,17 @@ export class CoreCoursesDashboardLinkHandler extends CoreContentLinksHandlerBase } }]; } + + /** + * Check if the handler is enabled for a certain site (site + user) and a URL. + * + * @param {string} siteId The site ID. + * @param {string} url The URL to treat. + * @param {any} params The params of the URL. E.g. 'mysite.com?id=1' -> {id: 1} + * @param {number} [courseId] Course ID related to the URL. Optional but recommended. + * @return {boolean|Promise} Whether the handler is enabled for the URL and site. + */ + isEnabled(siteId: string, url: string, params: any, courseId?: number): boolean | Promise { + return this.mainMenuHandler.isEnabledForSite(siteId); + } } diff --git a/src/core/courses/providers/dashboard.ts b/src/core/courses/providers/dashboard.ts index 7270bf539..5f2a2792d 100644 --- a/src/core/courses/providers/dashboard.ts +++ b/src/core/courses/providers/dashboard.ts @@ -14,6 +14,7 @@ import { Injectable } from '@angular/core'; import { CoreSitesProvider } from '@providers/sites'; +import { CoreSite } from '@classes/site'; /** * Service that provides some features regarding course overview. @@ -83,7 +84,36 @@ export class CoreCoursesDashboardProvider { */ isAvailable(siteId?: string): Promise { return this.sitesProvider.getSite(siteId).then((site) => { + // First check if it's disabled. + if (this.isDisabledInSite(site)) { + return false; + } + return site.wsAvailable('core_block_get_dashboard_blocks'); }); } + + /** + * Check if Site Home is disabled in a certain site. + * + * @param {string} [siteId] Site Id. If not defined, use current site. + * @return {Promise} Promise resolved with true if disabled, rejected or resolved with false otherwise. + */ + isDisabled(siteId?: string): Promise { + return this.sitesProvider.getSite(siteId).then((site) => { + return this.isDisabledInSite(site); + }); + } + + /** + * Check if Site Home is disabled in a certain site. + * + * @param {CoreSite} [site] Site. If not defined, use current site. + * @return {boolean} Whether it's disabled. + */ + isDisabledInSite(site?: CoreSite): boolean { + site = site || this.sitesProvider.getCurrentSite(); + + return site.isFeatureDisabled('CoreMainMenuDelegate_CoreCoursesDashboard'); + } } diff --git a/src/core/courses/providers/mainmenu-handler.ts b/src/core/courses/providers/mainmenu-handler.ts index 6f4679e48..4b32ced23 100644 --- a/src/core/courses/providers/mainmenu-handler.ts +++ b/src/core/courses/providers/mainmenu-handler.ts @@ -13,22 +13,25 @@ // limitations under the License. import { Injectable } from '@angular/core'; +import { CoreSitesProvider } from '@providers/sites'; import { CoreCoursesProvider } from './courses'; import { CoreMainMenuHandler, CoreMainMenuHandlerData } from '@core/mainmenu/providers/delegate'; import { CoreCoursesDashboardProvider } from '../providers/dashboard'; import { CoreSiteHomeProvider } from '@core/sitehome/providers/sitehome'; import { AddonBlockTimelineProvider } from '@addon/block/timeline/providers/timeline'; +import { CoreBlockDelegate } from '@core/block/providers/delegate'; /** * Handler to add Dashboard into main menu. */ @Injectable() export class CoreDashboardMainMenuHandler implements CoreMainMenuHandler { - name = 'CoreDashboard'; // Old name CoreCourses cannot be used because it would be all disabled by site. + name = 'CoreHome'; // This handler contains several different features, so we use a generic name like "CoreHome". priority = 1100; constructor(private coursesProvider: CoreCoursesProvider, private dashboardProvider: CoreCoursesDashboardProvider, - private siteHomeProvider: CoreSiteHomeProvider, private timelineProvider: AddonBlockTimelineProvider) { } + private siteHomeProvider: CoreSiteHomeProvider, private timelineProvider: AddonBlockTimelineProvider, + private blockDelegate: CoreBlockDelegate, private sitesProvider: CoreSitesProvider) { } /** * Check if the handler is enabled on a site level. @@ -36,15 +39,40 @@ export class CoreDashboardMainMenuHandler implements CoreMainMenuHandler { * @return {boolean | Promise} Whether or not the handler is enabled on a site level. */ isEnabled(): boolean | Promise { + return this.isEnabledForSite(); + } + + /** + * Check if the handler is enabled on a certain site. + * + * @param {string} [siteId] Site ID. If not defined, current site. + * @return {boolean | Promise} Whether or not the handler is enabled on a site level. + */ + isEnabledForSite(siteId?: string): Promise { + siteId = siteId || this.sitesProvider.getCurrentSiteId(); + + const promises = []; + let blocksEnabled, + dashboardAvailable; + + // Check if blocks and 3.6 dashboard is enabled. + promises.push(this.blockDelegate.areBlocksDisabled(siteId).then((disabled) => { + blocksEnabled = !disabled; + })); + + promises.push(this.dashboardProvider.isAvailable().then((available) => { + dashboardAvailable = available; + })); + // Check if 3.6 dashboard is enabled. - return this.dashboardProvider.isAvailable().then((enabled) => { - if (enabled) { + return Promise.all(promises).then(() => { + if (dashboardAvailable && blocksEnabled) { return true; } // Check if my overview is enabled. return this.timelineProvider.isAvailable().then((enabled) => { - if (enabled) { + if (enabled && blocksEnabled) { return true; }