Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mobile 4660 #4194

Merged
merged 8 commits into from
Oct 7, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -70,44 +70,41 @@ export class AddonBlockActivityModulesComponent extends CoreBlockBaseComponent i
let modFullNames: Record<string, string> = {};
const brandedIcons: Record<string, boolean|undefined> = {};

sections.forEach((section) => {
if (!section.modules) {
const modules = CoreCourse.getSectionsModules(sections, {
ignoreSection: section => !CoreCourseHelper.canUserViewSection(section),
ignoreModule: module => !CoreCourseHelper.canUserViewModule(module) || !CoreCourse.moduleHasView(module),
});

modules.forEach((mod) => {
if (archetypes[mod.modname] !== undefined) {
return;
}

section.modules.forEach((mod) => {
if (archetypes[mod.modname] !== undefined ||
!CoreCourseHelper.canUserViewModule(mod, section) ||
!CoreCourse.moduleHasView(mod)) {
// Ignore this module.
return;
}

// Get the archetype of the module type.
archetypes[mod.modname] = CoreCourseModuleDelegate.supportsFeature<number>(
mod.modname,
CoreConstants.FEATURE_MOD_ARCHETYPE,
CoreConstants.MOD_ARCHETYPE_OTHER,
);

// Get the full name of the module type.
if (archetypes[mod.modname] === CoreConstants.MOD_ARCHETYPE_RESOURCE) {
// All resources are gathered in a single "Resources" option.
if (!modFullNames['resources']) {
modFullNames['resources'] = Translate.instant('core.resources');
}
} else {
modFullNames[mod.modname] = mod.modplural;
// Get the archetype of the module type.
archetypes[mod.modname] = CoreCourseModuleDelegate.supportsFeature<number>(
mod.modname,
CoreConstants.FEATURE_MOD_ARCHETYPE,
CoreConstants.MOD_ARCHETYPE_OTHER,
);

// Get the full name of the module type.
if (archetypes[mod.modname] === CoreConstants.MOD_ARCHETYPE_RESOURCE) {
// All resources are gathered in a single "Resources" option.
if (!modFullNames['resources']) {
modFullNames['resources'] = Translate.instant('core.resources');
}
} else {
modFullNames[mod.modname] = mod.modplural;
}

brandedIcons[mod.modname] = mod.branded;
brandedIcons[mod.modname] = mod.branded;

// If this is not a theme image, leave it undefined to avoid having specific activity icons.
if (CoreUrl.isThemeImageUrl(mod.modicon)) {
modIcons[mod.modname] = mod.modicon;
}
});
// If this is not a theme image, leave it undefined to avoid having specific activity icons.
if (CoreUrl.isThemeImageUrl(mod.modicon)) {
modIcons[mod.modname] = mod.modicon;
}
});

// Sort the modnames alphabetically.
modFullNames = CoreUtils.sortValues(modFullNames);
for (const modName in modFullNames) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ <h2>{{ 'addon.block_sitemainmenu.pluginname' | translate }}</h2>
</ion-label>
</ion-item>

<core-course-module *ngFor="let module of mainMenuBlock.modules" [module]="module" [section]="mainMenuBlock" />
<ng-container *ngFor="let modOrSubsection of mainMenuBlock.contents">
<core-course-module *ngIf="isModule(modOrSubsection)" [module]="modOrSubsection" [section]="mainMenuBlock" />
</ng-container>
</ion-list>
</core-loading>
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import { Component, OnInit } from '@angular/core';
import { CoreSites } from '@services/sites';
import { CoreCourse } from '@features/course/services/course';
import { CoreCourse, sectionContentIsModule } from '@features/course/services/course';
import { CoreCourseHelper, CoreCourseSection } from '@features/course/services/course-helper';
import { CoreSiteHome, FrontPageItemNames } from '@features/sitehome/services/sitehome';
import { CoreCourseModulePrefetchDelegate } from '@features/course/services/module-prefetch-delegate';
Expand All @@ -39,6 +39,7 @@ export class AddonBlockSiteMainMenuComponent extends CoreBlockBaseComponent impl
component = 'AddonBlockSiteMainMenu';
mainMenuBlock?: CoreCourseSection;
siteHomeId = 1;
isModule = sectionContentIsModule;

protected fetchContentDefaultError = 'Error getting main menu data.';

Expand Down Expand Up @@ -66,9 +67,12 @@ export class AddonBlockSiteMainMenuComponent extends CoreBlockBaseComponent impl
promises.push(CoreCourse.invalidateSections(this.siteHomeId));
promises.push(CoreSiteHome.invalidateNewsForum(this.siteHomeId));

if (this.mainMenuBlock && this.mainMenuBlock.modules) {
if (this.mainMenuBlock?.contents.length) {
// Invalidate modules prefetch data.
promises.push(CoreCourseModulePrefetchDelegate.invalidateModules(this.mainMenuBlock.modules, this.siteHomeId));
promises.push(CoreCourseModulePrefetchDelegate.invalidateModules(
CoreCourse.getSectionsModules([this.mainMenuBlock]),
this.siteHomeId,
));
}

await Promise.all(promises);
Expand Down Expand Up @@ -114,11 +118,11 @@ export class AddonBlockSiteMainMenuComponent extends CoreBlockBaseComponent impl
try {
const forum = await CoreSiteHome.getNewsForum(this.siteHomeId);
// Search the module that belongs to site news.
const forumIndex =
this.mainMenuBlock.modules.findIndex((mod) => mod.modname == 'forum' && mod.instance == forum.id);
const forumIndex = this.mainMenuBlock.contents.findIndex((mod) =>
sectionContentIsModule(mod) && mod.modname == 'forum' && mod.instance == forum.id);

if (forumIndex >= 0) {
this.mainMenuBlock.modules.splice(forumIndex, 1);
this.mainMenuBlock.contents.splice(forumIndex, 1);
}
} catch {
// Ignore errors.
Expand Down
28 changes: 26 additions & 2 deletions src/addons/mod/subsection/services/handlers/index-link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ import { CoreCourse } from '@features/course/services/course';
import { CoreLoadings } from '@services/loadings';
import { CoreDomUtils } from '@services/utils/dom';
import { makeSingleton } from '@singletons';
import { AddonModSubsection } from '../subsection';
import { CoreSites } from '@services/sites';
import { CoreCourseHelper } from '@features/course/services/course-helper';

/**
* Handler to treat links to subsection.
Expand All @@ -33,6 +34,29 @@ export class AddonModSubsectionIndexLinkHandlerService extends CoreContentLinksM
super('AddonModSubsection', 'subsection', 'id');
}

/**
* Open a subsection.
*
* @param sectionId Section ID.
* @param courseId Course ID.
* @param siteId Site ID. If not defined, current site.
* @returns Promise resolved when done.
*/
async openSubsection(sectionId: number, courseId: number, siteId?: string): Promise<void> {
const pageParams = {
sectionId,
};

if (
(!siteId || siteId === CoreSites.getCurrentSiteId()) &&
CoreCourse.currentViewIsCourse(courseId)
) {
CoreCourse.selectCourseTab('', pageParams);
} else {
await CoreCourseHelper.getAndOpenCourse(courseId, pageParams, siteId);
}
}

/**
* @inheritdoc
*/
Expand All @@ -51,7 +75,7 @@ export class AddonModSubsectionIndexLinkHandlerService extends CoreContentLinksM
// Get the module.
const module = await CoreCourse.getModule(moduleId, courseId, undefined, true, false, siteId);

await AddonModSubsection.openSubsection(module.section, module.course, siteId);
await this.openSubsection(module.section, module.course, siteId);
} catch (error) {
CoreDomUtils.showErrorModalDefault(error, 'Error opening link.');
} finally {
Expand Down
88 changes: 0 additions & 88 deletions src/addons/mod/subsection/services/handlers/module.ts

This file was deleted.

51 changes: 0 additions & 51 deletions src/addons/mod/subsection/services/subsection.ts

This file was deleted.

3 changes: 0 additions & 3 deletions src/addons/mod/subsection/subsection.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,14 @@

import { APP_INITIALIZER, NgModule } from '@angular/core';
import { CoreContentLinksDelegate } from '@features/contentlinks/services/contentlinks-delegate';
import { CoreCourseModuleDelegate } from '@features/course/services/module-delegate';
import { AddonModSubsectionIndexLinkHandler } from './services/handlers/index-link';
import { AddonModSubsectionModuleHandler } from './services/handlers/module';

@NgModule({
providers: [
{
provide: APP_INITIALIZER,
multi: true,
useValue: () => {
CoreCourseModuleDelegate.registerHandler(AddonModSubsectionModuleHandler.instance);
CoreContentLinksDelegate.registerHandler(AddonModSubsectionIndexLinkHandler.instance);
},
},
Expand Down
Loading