Skip to content

Commit

Permalink
Component modules
Browse files Browse the repository at this point in the history
  • Loading branch information
crazyserver committed Jan 31, 2025
1 parent 66e61e4 commit 4ee0484
Show file tree
Hide file tree
Showing 12 changed files with 53 additions and 122 deletions.
10 changes: 8 additions & 2 deletions src/addons/mod/assign/assign.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,15 @@ export async function getModAssignServices(): Promise<Type<unknown>[]> {
* @returns Assign component modules.
*/
export async function getModAssignComponentModules(): Promise<unknown[]> {
const { AddonModAssignComponentsModule } = await import('@addons/mod/assign/components/components.module');
const { AddonModAssignSubmissionPluginComponent } =
await import('@addons/mod/assign/components/submission-plugin/submission-plugin');
const { AddonModAssignFeedbackPluginComponent } =
await import('@addons/mod/assign/components/feedback-plugin/feedback-plugin');

return [AddonModAssignComponentsModule];
return [
AddonModAssignSubmissionPluginComponent,
AddonModAssignFeedbackPluginComponent,
];
}

const routes: Routes = [
Expand Down
26 changes: 0 additions & 26 deletions src/addons/mod/assign/components/components.module.ts

This file was deleted.

26 changes: 0 additions & 26 deletions src/addons/mod/data/components/components.module.ts

This file was deleted.

6 changes: 4 additions & 2 deletions src/addons/mod/data/components/index/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import {
import { AddonModDataHelper, AddonModDatDisplayFieldsOptions } from '../../services/data-helper';
import { AddonModDataAutoSyncData, AddonModDataSyncResult } from '../../services/data-sync';
import { AddonModDataPrefetchHandler } from '../../services/handlers/prefetch-lazy';
import { AddonModDataComponentsCompileModule } from '../components.module';

import { CoreUrl } from '@singletons/url';
import { CoreTime } from '@singletons/time';
import {
Expand Down Expand Up @@ -107,7 +107,7 @@ export class AddonModDataIndexComponent extends CoreCourseModuleMainActivityComp

hasNextPage = false;
entriesRendered = '';
extraImports: Type<unknown>[] = [AddonModDataComponentsCompileModule];
extraImports: Type<unknown>[] = [];

jsData?: {
fields: Record<number, AddonModDataField>;
Expand Down Expand Up @@ -149,6 +149,8 @@ export class AddonModDataIndexComponent extends CoreCourseModuleMainActivityComp
async ngOnInit(): Promise<void> {
await super.ngOnInit();

this.extraImports = await AddonModDataHelper.getComponentsToCompile();

this.selectedGroup = this.group || 0;

// Refresh entries on change.
Expand Down
8 changes: 5 additions & 3 deletions src/addons/mod/data/components/search-modal/search-modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
} from '../../services/data';
import { AddonModDataFieldsDelegate } from '../../services/data-fields-delegate';
import { AddonModDataHelper } from '../../services/data-helper';
import { AddonModDataComponentsCompileModule } from '../components.module';

import { AddonModDataSearchDataParams } from '../index';
import { AddonModDataTemplateType } from '../../constants';
import { CoreSharedModule } from '@/core/shared.module';
Expand Down Expand Up @@ -56,7 +56,7 @@ export class AddonModDataSearchModalComponent implements OnInit {

advancedSearch = '';
advancedIndexed: CoreFormFields = {};
extraImports: Type<unknown>[] = [AddonModDataComponentsCompileModule];
extraImports: Type<unknown>[] = [];

searchForm: FormGroup;
jsData?: {
Expand All @@ -73,7 +73,7 @@ export class AddonModDataSearchModalComponent implements OnInit {
this.searchForm = new FormGroup({});
}

ngOnInit(): void {
async ngOnInit(): Promise<void> {
this.advancedIndexed = {};
this.search.advanced?.forEach((field) => {
if (field !== undefined) {
Expand All @@ -91,6 +91,8 @@ export class AddonModDataSearchModalComponent implements OnInit {

this.fieldsArray = CoreObject.toArray(this.fields);
this.advancedSearch = this.renderAdvancedSearchFields();

this.extraImports = await AddonModDataHelper.getComponentsToCompile();
}

/**
Expand Down
8 changes: 5 additions & 3 deletions src/addons/mod/data/pages/edit/edit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { CoreForms } from '@singletons/form';
import { CoreUtils } from '@singletons/utils';
import { Translate } from '@singletons';
import { CoreEvents } from '@singletons/events';
import { AddonModDataComponentsCompileModule } from '../../components/components.module';

import {
AddonModDataData,
AddonModDataField,
Expand Down Expand Up @@ -91,7 +91,7 @@ export default class AddonModDataEditPage implements OnInit {
groupInfo?: CoreGroupInfo;
editFormRender = '';
editForm: FormGroup;
extraImports: Type<unknown>[] = [AddonModDataComponentsCompileModule];
extraImports: Type<unknown>[] = [];
jsData?: {
fields: Record<number, AddonModDataField>;
database?: AddonModDataData;
Expand Down Expand Up @@ -125,7 +125,7 @@ export default class AddonModDataEditPage implements OnInit {
/**
* @inheritdoc
*/
ngOnInit(): void {
async ngOnInit(): Promise<void> {
try {
this.moduleId = CoreNavigator.getRequiredRouteNumberParam('cmId');
this.courseId = CoreNavigator.getRequiredRouteNumberParam('courseId');
Expand All @@ -140,6 +140,8 @@ export default class AddonModDataEditPage implements OnInit {
return;
}

this.extraImports = await AddonModDataHelper.getComponentsToCompile();

// If entryId is lower than 0 or null, it is a new entry or an offline entry.
this.isEditing = this.entryId !== undefined && this.entryId > 0;

Expand Down
6 changes: 4 additions & 2 deletions src/addons/mod/data/pages/entry/entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { CoreNavigator } from '@services/navigator';
import { CoreSites } from '@services/sites';
import { CoreArray } from '@singletons/array';
import { CoreEventObserver, CoreEvents } from '@singletons/events';
import { AddonModDataComponentsCompileModule } from '../../components/components.module';

import {
AddonModData,
AddonModDataData,
Expand Down Expand Up @@ -99,7 +99,7 @@ export default class AddonModDataEntryPage implements OnInit, OnDestroy {
showComments = false;
entryHtml = '';
siteId: string;
extraImports: Type<unknown>[] = [AddonModDataComponentsCompileModule];
extraImports: Type<unknown>[] = [];
jsData?: {
fields: Record<number, AddonModDataField>;
entries: Record<number, AddonModDataEntry>;
Expand Down Expand Up @@ -174,6 +174,8 @@ export default class AddonModDataEntryPage implements OnInit, OnDestroy {
return;
}

this.extraImports = await AddonModDataHelper.getComponentsToCompile();

this.commentsEnabled = CoreComments.areCommentsEnabledInSite();

await this.fetchEntryData();
Expand Down
17 changes: 16 additions & 1 deletion src/addons/mod/data/services/data-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.

import { ContextLevel } from '@/core/constants';
import { Injectable } from '@angular/core';
import { Injectable, Type } from '@angular/core';
import { CoreCourse } from '@features/course/services/course';
import { CoreFileUploader, CoreFileUploaderStoreFilesResult } from '@features/fileuploader/services/fileuploader';
import { CoreRatingOffline } from '@features/rating/services/rating-offline';
Expand Down Expand Up @@ -982,6 +982,21 @@ export class AddonModDataHelperProvider {
return CoreFileUploader.uploadOrReuploadFiles(files, ADDON_MOD_DATA_COMPONENT, itemId, siteId);
}

/**
* Get data components to compile.
*
* @returns Database components to compile.
*/
async getComponentsToCompile(): Promise<Type<unknown>[]> {
const { AddonModDataFieldPluginComponent } = await import('@addons/mod/data/components/field-plugin/field-plugin');
const { AddonModDataActionComponent } = await import('@addons/mod/data/components/action/action');

return [
AddonModDataFieldPluginComponent,
AddonModDataActionComponent,
];
}

}
export const AddonModDataHelper = makeSingleton(AddonModDataHelperProvider);

Expand Down
30 changes: 0 additions & 30 deletions src/addons/mod/quiz/components/components.module.ts

This file was deleted.

10 changes: 8 additions & 2 deletions src/addons/mod/quiz/quiz.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,15 @@ export async function getModQuizServices(): Promise<Type<unknown>[]> {
* @returns Quiz component modules.
*/
export async function getModQuizComponentModules(): Promise<unknown[]> {
const { AddonModQuizComponentsModule } = await import('@addons/mod/quiz/components/components.module');
const { AddonModQuizAttemptInfoComponent } = await import('@addons/mod/quiz/components/attempt-info/attempt-info');
const { AddonModQuizAttemptStateComponent } = await import('@addons/mod/quiz/components/attempt-state/attempt-state');
const { AddonModQuizQuestionCardComponent } = await import('@addons/mod/quiz/components/question-card/question-card');

return [AddonModQuizComponentsModule];
return [
AddonModQuizAttemptInfoComponent,
AddonModQuizAttemptStateComponent,
AddonModQuizQuestionCardComponent,
];
}

const routes: Routes = [
Expand Down
23 changes: 0 additions & 23 deletions src/addons/mod/workshop/components/components.module.ts

This file was deleted.

5 changes: 3 additions & 2 deletions src/addons/mod/workshop/workshop.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,10 @@ export async function getModWorkshopServices(): Promise<Type<unknown>[]> {
* @returns Workshop component modules.
*/
export async function getModWorkshopComponentModules(): Promise<unknown[]> {
const { AddonModWorkshopComponentsModule } = await import('@addons/mod/workshop/components/components.module');
const { AddonModWorkshopAssessmentStrategyComponent } =
await import('@addons/mod/workshop/components/assessment-strategy/assessment-strategy');

return [AddonModWorkshopComponentsModule];
return [AddonModWorkshopAssessmentStrategyComponent];
}

const routes: Routes = [
Expand Down

0 comments on commit 4ee0484

Please sign in to comment.