MOBILE-2975 dashboard: Allow disabling dashboard
parent
65c202c998
commit
e449496b45
|
@ -14,6 +14,7 @@
|
||||||
|
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { CoreSitesProvider } from '@providers/sites';
|
import { CoreSitesProvider } from '@providers/sites';
|
||||||
|
import { CoreCoursesDashboardProvider } from '@core/courses/providers/dashboard';
|
||||||
import * as moment from 'moment';
|
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.
|
// Cache key was maintained when moving the functions to this file. It comes from core myoverview.
|
||||||
protected ROOT_CACHE_KEY = '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.
|
* Get calendar action events for the given course.
|
||||||
|
@ -218,6 +219,11 @@ export class AddonBlockTimelineProvider {
|
||||||
*/
|
*/
|
||||||
isAvailable(siteId?: string): Promise<boolean> {
|
isAvailable(siteId?: string): Promise<boolean> {
|
||||||
return this.sitesProvider.getSite(siteId).then((site) => {
|
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') &&
|
return site.wsAvailable('core_calendar_get_action_events_by_courses') &&
|
||||||
site.wsAvailable('core_calendar_get_action_events_by_timesort');
|
site.wsAvailable('core_calendar_get_action_events_by_timesort');
|
||||||
});
|
});
|
||||||
|
|
|
@ -142,8 +142,8 @@ export class CoreCoursesDashboardPage implements OnDestroy {
|
||||||
* @return {Promise<any>} Promise resolved when done.
|
* @return {Promise<any>} Promise resolved when done.
|
||||||
*/
|
*/
|
||||||
protected loadDashboardContent(): Promise<any> {
|
protected loadDashboardContent(): Promise<any> {
|
||||||
return this.dashboardProvider.isAvailable().then((enabled) => {
|
return this.dashboardProvider.isAvailable().then((available) => {
|
||||||
if (enabled) {
|
if (available) {
|
||||||
this.userId = this.sitesProvider.getCurrentSiteUserId();
|
this.userId = this.sitesProvider.getCurrentSiteUserId();
|
||||||
|
|
||||||
return this.dashboardProvider.getDashboardBlocks().then((blocks) => {
|
return this.dashboardProvider.getDashboardBlocks().then((blocks) => {
|
||||||
|
@ -154,10 +154,14 @@ export class CoreCoursesDashboardPage implements OnDestroy {
|
||||||
// Cannot get the blocks, just show dashboard if needed.
|
// Cannot get the blocks, just show dashboard if needed.
|
||||||
this.loadFallbackBlocks();
|
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(() => {
|
}).finally(() => {
|
||||||
this.dashboardEnabled = this.blockDelegate.hasSupportedBlock(this.blocks);
|
this.dashboardEnabled = this.blockDelegate.hasSupportedBlock(this.blocks);
|
||||||
this.dashboardLoaded = true;
|
this.dashboardLoaded = true;
|
||||||
|
|
|
@ -16,6 +16,7 @@ import { Injectable } from '@angular/core';
|
||||||
import { CoreContentLinksHandlerBase } from '@core/contentlinks/classes/base-handler';
|
import { CoreContentLinksHandlerBase } from '@core/contentlinks/classes/base-handler';
|
||||||
import { CoreContentLinksAction } from '@core/contentlinks/providers/delegate';
|
import { CoreContentLinksAction } from '@core/contentlinks/providers/delegate';
|
||||||
import { CoreLoginHelperProvider } from '@core/login/providers/helper';
|
import { CoreLoginHelperProvider } from '@core/login/providers/helper';
|
||||||
|
import { CoreDashboardMainMenuHandler } from './mainmenu-handler';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handler to treat links to my overview.
|
* Handler to treat links to my overview.
|
||||||
|
@ -23,10 +24,9 @@ import { CoreLoginHelperProvider } from '@core/login/providers/helper';
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class CoreCoursesDashboardLinkHandler extends CoreContentLinksHandlerBase {
|
export class CoreCoursesDashboardLinkHandler extends CoreContentLinksHandlerBase {
|
||||||
name = 'CoreCoursesMyOverviewLinkHandler';
|
name = 'CoreCoursesMyOverviewLinkHandler';
|
||||||
featureName = 'CoreMainMenuDelegate_CoreCourses';
|
|
||||||
pattern = /\/my\/?$/;
|
pattern = /\/my\/?$/;
|
||||||
|
|
||||||
constructor(private loginHelper: CoreLoginHelperProvider) {
|
constructor(private loginHelper: CoreLoginHelperProvider, private mainMenuHandler: CoreDashboardMainMenuHandler) {
|
||||||
super();
|
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<boolean>} Whether the handler is enabled for the URL and site.
|
||||||
|
*/
|
||||||
|
isEnabled(siteId: string, url: string, params: any, courseId?: number): boolean | Promise<boolean> {
|
||||||
|
return this.mainMenuHandler.isEnabledForSite(siteId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
|
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { CoreSitesProvider } from '@providers/sites';
|
import { CoreSitesProvider } from '@providers/sites';
|
||||||
|
import { CoreSite } from '@classes/site';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Service that provides some features regarding course overview.
|
* Service that provides some features regarding course overview.
|
||||||
|
@ -83,7 +84,36 @@ export class CoreCoursesDashboardProvider {
|
||||||
*/
|
*/
|
||||||
isAvailable(siteId?: string): Promise<boolean> {
|
isAvailable(siteId?: string): Promise<boolean> {
|
||||||
return this.sitesProvider.getSite(siteId).then((site) => {
|
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');
|
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<boolean>} Promise resolved with true if disabled, rejected or resolved with false otherwise.
|
||||||
|
*/
|
||||||
|
isDisabled(siteId?: string): Promise<boolean> {
|
||||||
|
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');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,22 +13,25 @@
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
|
import { CoreSitesProvider } from '@providers/sites';
|
||||||
import { CoreCoursesProvider } from './courses';
|
import { CoreCoursesProvider } from './courses';
|
||||||
import { CoreMainMenuHandler, CoreMainMenuHandlerData } from '@core/mainmenu/providers/delegate';
|
import { CoreMainMenuHandler, CoreMainMenuHandlerData } from '@core/mainmenu/providers/delegate';
|
||||||
import { CoreCoursesDashboardProvider } from '../providers/dashboard';
|
import { CoreCoursesDashboardProvider } from '../providers/dashboard';
|
||||||
import { CoreSiteHomeProvider } from '@core/sitehome/providers/sitehome';
|
import { CoreSiteHomeProvider } from '@core/sitehome/providers/sitehome';
|
||||||
import { AddonBlockTimelineProvider } from '@addon/block/timeline/providers/timeline';
|
import { AddonBlockTimelineProvider } from '@addon/block/timeline/providers/timeline';
|
||||||
|
import { CoreBlockDelegate } from '@core/block/providers/delegate';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handler to add Dashboard into main menu.
|
* Handler to add Dashboard into main menu.
|
||||||
*/
|
*/
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class CoreDashboardMainMenuHandler implements CoreMainMenuHandler {
|
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;
|
priority = 1100;
|
||||||
|
|
||||||
constructor(private coursesProvider: CoreCoursesProvider, private dashboardProvider: CoreCoursesDashboardProvider,
|
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.
|
* Check if the handler is enabled on a site level.
|
||||||
|
@ -36,15 +39,40 @@ export class CoreDashboardMainMenuHandler implements CoreMainMenuHandler {
|
||||||
* @return {boolean | Promise<boolean>} Whether or not the handler is enabled on a site level.
|
* @return {boolean | Promise<boolean>} Whether or not the handler is enabled on a site level.
|
||||||
*/
|
*/
|
||||||
isEnabled(): boolean | Promise<boolean> {
|
isEnabled(): boolean | Promise<boolean> {
|
||||||
|
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<boolean>} Whether or not the handler is enabled on a site level.
|
||||||
|
*/
|
||||||
|
isEnabledForSite(siteId?: string): Promise<boolean> {
|
||||||
|
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.
|
// Check if 3.6 dashboard is enabled.
|
||||||
return this.dashboardProvider.isAvailable().then((enabled) => {
|
return Promise.all(promises).then(() => {
|
||||||
if (enabled) {
|
if (dashboardAvailable && blocksEnabled) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if my overview is enabled.
|
// Check if my overview is enabled.
|
||||||
return this.timelineProvider.isAvailable().then((enabled) => {
|
return this.timelineProvider.isAvailable().then((enabled) => {
|
||||||
if (enabled) {
|
if (enabled && blocksEnabled) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue