Skip to content

Commit a69f6a5

Browse files
committed
MOBILE-3730 siteplugins: Load styles from site plugins
1 parent c19edbc commit a69f6a5

36 files changed

+242
-109
lines changed

src/core/features/siteplugins/classes/compile-init-component.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ export class CoreSitePluginsCompileInitComponent {
2727
extraImports: Type<unknown>[] = [];
2828
protected handlerSchema?: CoreSitePluginsInitHandlerData; // The handler data.
2929

30+
stylesPath?: string; // Styles to apply to the component.
31+
3032
/**
3133
* Function called when the component is created.
3234
*
@@ -42,18 +44,18 @@ export class CoreSitePluginsCompileInitComponent {
4244
/**
4345
* Get the handler data.
4446
*
45-
* @param name The name of the handler.
47+
* @param handlerName The name of the handler.
4648
*/
47-
getHandlerData(name: string): void {
49+
async getHandlerData(handlerName: string): Promise<void> {
4850
// Retrieve the handler data.
49-
const handler = CoreSitePlugins.getSitePluginHandler(name);
50-
51-
this.handlerSchema = handler?.handlerSchema;
51+
const handler = CoreSitePlugins.getSitePluginHandler(handlerName);
5252

53-
if (!this.handlerSchema) {
53+
if (!handler?.handlerSchema) {
5454
return;
5555
}
5656

57+
this.handlerSchema = handler.handlerSchema;
58+
5759
// Load first template.
5860
if (this.handlerSchema.methodTemplates?.length) {
5961
this.content = this.handlerSchema.methodTemplates[0].html;
@@ -72,6 +74,8 @@ export class CoreSitePluginsCompileInitComponent {
7274
if (this.handlerSchema.methodJSResult) {
7375
this.jsData.CONTENT_JS_RESULT = this.handlerSchema.methodJSResult;
7476
}
77+
78+
this.stylesPath = await CoreSitePlugins.getHandlerDownloadedStyles(handlerName);
7579
}
7680

7781
}

src/core/features/siteplugins/classes/handlers/course-option-handler.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,23 +71,28 @@ export class CoreSitePluginsCourseOptionHandler extends CoreSitePluginsBaseHandl
7171
/**
7272
* @inheritdoc
7373
*/
74-
getDisplayData(): CoreCourseOptionsHandlerData {
74+
async getDisplayData(): Promise<CoreCourseOptionsHandlerData> {
75+
const stylesPath = await this.handlerSchema.styles?.downloadedStyles;
76+
7577
return {
7678
title: this.title,
7779
class: this.handlerSchema.displaydata?.class,
7880
page: `siteplugins/${this.name}`,
79-
pageParams: {},
81+
pageParams: {
82+
stylesPath,
83+
},
8084
};
8185
}
8286

8387
/**
8488
* @inheritdoc
8589
*/
86-
getMenuDisplayData(course: CoreCourseAnyCourseDataWithOptions): CoreCourseOptionsMenuHandlerData {
90+
async getMenuDisplayData(course: CoreCourseAnyCourseDataWithOptions): Promise<CoreCourseOptionsMenuHandlerData> {
8791
const args = {
8892
courseid: course.id,
8993
};
9094
const hash = Md5.hashAsciiStr(JSON.stringify(args));
95+
const stylesPath = await this.handlerSchema.styles?.downloadedStyles;
9196

9297
return {
9398
title: this.title,
@@ -101,6 +106,7 @@ export class CoreSitePluginsCourseOptionHandler extends CoreSitePluginsBaseHandl
101106
ptrEnabled: this.handlerSchema.ptrenabled,
102107
contextLevel: 'course',
103108
contextInstanceId: course.id,
109+
stylesPath,
104110
},
105111
};
106112
}

src/core/features/siteplugins/classes/handlers/main-menu-handler.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import { CoreMainMenuHandler, CoreMainMenuHandlerData } from '@features/mainmenu/services/mainmenu-delegate';
1616
import {
17+
CoreSitePlugins,
1718
CoreSitePluginsContent,
1819
CoreSitePluginsMainMenuHandlerData,
1920
CoreSitePluginsPlugin,
@@ -43,6 +44,8 @@ export class CoreSitePluginsMainMenuHandler extends CoreSitePluginsBaseHandler i
4344
* @inheritdoc
4445
*/
4546
getDisplayData(): CoreMainMenuHandlerData {
47+
const handlerName = CoreSitePlugins.getHandlerNameFromUniqueName(this.name, this.plugin.addon);
48+
4649
return {
4750
title: this.title,
4851
icon: this.handlerSchema.displaydata?.icon || 'fas-question',
@@ -52,6 +55,7 @@ export class CoreSitePluginsMainMenuHandler extends CoreSitePluginsBaseHandler i
5255
title: this.title,
5356
initResult: this.initResult,
5457
ptrEnabled: this.handlerSchema.ptrenabled,
58+
handlerName,
5559
},
5660
onlyInMore: true,
5761
};

src/core/features/siteplugins/classes/handlers/message-output-handler.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import { AddonMessageOutputHandler, AddonMessageOutputHandlerData } from '@addons/messageoutput/services/messageoutput-delegate';
1616
import {
17+
CoreSitePlugins,
1718
CoreSitePluginsContent,
1819
CoreSitePluginsMessageOutputHandlerData,
1920
CoreSitePluginsPlugin,
@@ -40,6 +41,8 @@ export class CoreSitePluginsMessageOutputHandler extends CoreSitePluginsBaseHand
4041
* @inheritdoc
4142
*/
4243
getDisplayData(): AddonMessageOutputHandlerData {
44+
const handlerName = CoreSitePlugins.getHandlerNameFromUniqueName(this.name, this.plugin.addon);
45+
4346
return {
4447
priority: this.handlerSchema.priority || 0,
4548
label: this.title,
@@ -49,6 +52,7 @@ export class CoreSitePluginsMessageOutputHandler extends CoreSitePluginsBaseHand
4952
title: this.title,
5053
initResult: this.initResult,
5154
ptrEnabled: this.handlerSchema.ptrenabled,
55+
handlerName,
5256
},
5357
};
5458
}

src/core/features/siteplugins/classes/handlers/settings-handler.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import { CoreSettingsHandler, CoreSettingsHandlerData } from '@features/settings/services/settings-delegate';
1616
import {
17+
CoreSitePlugins,
1718
CoreSitePluginsContent,
1819
CoreSitePluginsPlugin,
1920
CoreSitePluginsSettingsHandlerData,
@@ -45,6 +46,8 @@ export class CoreSitePluginsSettingsHandler extends CoreSitePluginsBaseHandler i
4546
* @returns Data.
4647
*/
4748
getDisplayData(): CoreSettingsHandlerData {
49+
const handlerName = CoreSitePlugins.getHandlerNameFromUniqueName(this.name, this.plugin.addon);
50+
4851
return {
4952
title: this.title,
5053
icon: this.handlerSchema.displaydata?.icon,
@@ -54,6 +57,7 @@ export class CoreSitePluginsSettingsHandler extends CoreSitePluginsBaseHandler i
5457
title: this.title,
5558
initResult: this.initResult,
5659
ptrEnabled: this.handlerSchema.ptrenabled,
60+
handlerName,
5761
},
5862
};
5963
}

src/core/features/siteplugins/classes/handlers/user-handler.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ export class CoreSitePluginsUserProfileHandler extends CoreSitePluginsBaseHandle
8686
* @inheritdoc
8787
*/
8888
getDisplayData(): CoreUserProfileHandlerData {
89+
8990
return {
9091
title: this.title,
9192
icon: this.handlerSchema.displaydata?.icon,
@@ -94,6 +95,8 @@ export class CoreSitePluginsUserProfileHandler extends CoreSitePluginsBaseHandle
9495
event.preventDefault();
9596
event.stopPropagation();
9697

98+
const handlerName = CoreSitePlugins.getHandlerNameFromUniqueName(this.name, this.plugin.addon);
99+
97100
const args = {
98101
courseid: contextId,
99102
userid: user.id,
@@ -110,6 +113,7 @@ export class CoreSitePluginsUserProfileHandler extends CoreSitePluginsBaseHandle
110113
ptrEnabled: this.handlerSchema.ptrenabled,
111114
contextLevel: 'user',
112115
contextInstanceId: user.id,
116+
handlerName,
113117
},
114118
},
115119
);

src/core/features/siteplugins/components/assign-feedback/assign-feedback.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export class CoreSitePluginsAssignFeedbackComponent extends CoreSitePluginsCompi
6161
this.extraImports = await getModAssignComponentModules();
6262

6363
if (this.plugin) {
64-
this.getHandlerData(AddonModAssignFeedbackDelegate.getHandlerName(this.plugin.type));
64+
await this.getHandlerData(AddonModAssignFeedbackDelegate.getHandlerName(this.plugin.type));
6565
}
6666
}
6767

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<core-compile-html [text]="content" [jsData]="jsData" (created)="componentCreated($event)" [extraImports]="extraImports" />
1+
<core-compile-html [text]="content" [jsData]="jsData" (created)="componentCreated($event)" [stylesPath]="stylesPath" [extraImports]="extraImports" />

src/core/features/siteplugins/components/assign-submission/assign-submission.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export class CoreSitePluginsAssignSubmissionComponent extends CoreSitePluginsCom
5959
this.extraImports = await getModAssignComponentModules();
6060

6161
if (this.plugin) {
62-
this.getHandlerData(AddonModAssignSubmissionDelegate.getHandlerName(this.plugin.type));
62+
await this.getHandlerData(AddonModAssignSubmissionDelegate.getHandlerName(this.plugin.type));
6363
}
6464
}
6565

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<core-compile-html [text]="content" [jsData]="jsData" (created)="componentCreated($event)" [extraImports]="extraImports" />
1+
<core-compile-html [text]="content" [jsData]="jsData" (created)="componentCreated($event)" [stylesPath]="stylesPath" [extraImports]="extraImports" />

src/core/features/siteplugins/components/block/block.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,16 @@ export class CoreSitePluginsBlockComponent extends CoreBlockBaseComponent implem
4242
args?: Record<string, unknown>;
4343
jsData?: Record<string, unknown>; // Data to pass to the component.
4444
initResult?: CoreSitePluginsContent | null;
45+
stylesPath?: string; // Styles to apply to the component.
4546

4647
constructor() {
4748
super('CoreSitePluginsBlockComponent');
4849
}
4950

5051
/**
51-
* Detect changes on input properties.
52+
* @inheritdoc
5253
*/
53-
ngOnChanges(): void {
54+
async ngOnChanges(): Promise<void> {
5455
if (this.component) {
5556
return;
5657
}
@@ -73,12 +74,12 @@ export class CoreSitePluginsBlockComponent extends CoreBlockBaseComponent implem
7374
block: this.block,
7475
};
7576
this.initResult = handler.initResult;
77+
78+
this.stylesPath = await CoreSitePlugins.getHandlerDownloadedStyles(handlerName);
7679
}
7780

7881
/**
79-
* Invalidate block data.
80-
*
81-
* @returns Promise resolved when done.
82+
* @inheritdoc
8283
*/
8384
async invalidateContent(): Promise<void> {
8485
if (!this.component || !this.method) {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
<core-site-plugins-plugin-content *ngIf="component && method" [component]="component" [method]="method" [args]="args"
2-
[initResult]="initResult" [data]="jsData" contextLevel="block" [contextInstanceId]="block.instanceid" />
2+
[initResult]="initResult" [data]="jsData" contextLevel="block" [contextInstanceId]="block.instanceid" [stylesPath]="stylesPath" />
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
<core-site-plugins-plugin-content *ngIf="component && method" [component]="component" [method]="method" [args]="args"
2-
[initResult]="initResult" [data]="data" contextLevel="course" [contextInstanceId]="course?.id" />
2+
[initResult]="initResult" [data]="data" contextLevel="course" [contextInstanceId]="course?.id" [stylesPath]="stylesPath" />

src/core/features/siteplugins/components/course-format/course-format.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,12 @@ export class CoreSitePluginsCourseFormatComponent implements OnChanges {
5555
args?: Record<string, unknown>;
5656
initResult?: CoreSitePluginsContent | null;
5757
data?: Record<string, unknown>;
58+
stylesPath?: string; // Styles to apply to the component.
5859

5960
/**
6061
* @inheritdoc
6162
*/
62-
ngOnChanges(): void {
63+
async ngOnChanges(): Promise<void> {
6364
if (!this.course || !this.course.format) {
6465
return;
6566
}
@@ -76,6 +77,8 @@ export class CoreSitePluginsCourseFormatComponent implements OnChanges {
7677
courseid: this.course.id,
7778
};
7879
this.initResult = handler.initResult;
80+
81+
this.stylesPath = await CoreSitePlugins.getHandlerDownloadedStyles(handlerName);
7982
}
8083
}
8184

src/core/features/siteplugins/components/module-index/core-siteplugins-module-index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<core-site-plugins-plugin-content *ngIf="component && method" [component]="component" [method]="method" [args]="args"
2020
[initResult]="initResult" [data]="jsData" [pageTitle]="pageTitle" [preSets]="preSets" contextLevel="module"
2121
[contextInstanceId]="module?.id" [courseId]="courseId" (onContentLoaded)="contentLoaded($event)"
22-
(onLoadingContent)="contentLoading()" />
22+
(onLoadingContent)="contentLoading()" [stylesPath]="stylesPath" />
2323

2424
<core-course-module-navigation collapsible-footer [appearOnBottom]="collapsibleFooterAppearOnBottom" *ngIf="module" [courseId]="courseId"
2525
[currentModuleId]="module.id" />

src/core/features/siteplugins/components/module-index/module-index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,14 @@ export class CoreSitePluginsModuleIndexComponent implements OnInit, OnDestroy, C
8181
isDestroyed = false;
8282

8383
jsData?: Record<string, unknown>; // Data to pass to the component.
84+
stylesPath?: string; // Styles to apply to the component.
8485

8586
constructor(@Optional() public courseContentsPage?: CoreCourseContentsPage) {}
8687

8788
/**
8889
* @inheritdoc
8990
*/
90-
ngOnInit(): void {
91+
async ngOnInit(): Promise<void> {
9192
if (!this.module) {
9293
return;
9394
}
@@ -120,6 +121,8 @@ export class CoreSitePluginsModuleIndexComponent implements OnInit, OnDestroy, C
120121
this.ptrEnabled = !CoreUtils.isFalseOrZero(handlerSchema.ptrenabled);
121122

122123
this.collapsibleFooterAppearOnBottom = !CoreUtils.isFalseOrZero(handlerSchema.isresource);
124+
125+
this.stylesPath = await CoreSitePlugins.getHandlerDownloadedStyles(handlerName);
123126
}
124127

125128
// Get the data for the context menu.
@@ -142,6 +145,8 @@ export class CoreSitePluginsModuleIndexComponent implements OnInit, OnDestroy, C
142145

143146
/**
144147
* Function called when the data of the site plugin content is loaded.
148+
*
149+
* @param data Data received.
145150
*/
146151
contentLoaded(data: CoreSitePluginsPluginContentLoadedData): void {
147152
this.addDefaultModuleInfo = !data.content.includes('<core-course-module-info');

src/core/features/siteplugins/components/only-title-block/only-title-block.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ export class CoreSitePluginsOnlyTitleBlockComponent extends CoreBlockBaseCompone
7373
ptrEnabled: (<CoreSitePluginsUserHandlerData> handler.handlerSchema).ptrenabled,
7474
contextLevel: 'block',
7575
contextInstanceId: this.instanceId,
76+
handlerName,
7677
},
7778
},
7879
);
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
<core-loading [hideUntil]="dataLoaded" [fullscreen]="false">
2-
<core-compile-html [text]="content" [javascript]="javascript" [jsData]="jsData" [forceCompile]="forceCompile" #compile />
2+
<core-compile-html [text]="content" [javascript]="javascript" [jsData]="jsData" [forceCompile]="forceCompile" [stylesPath]="stylesPath"
3+
#compile />
34
</core-loading>

src/core/features/siteplugins/components/plugin-content/plugin-content.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ export class CoreSitePluginsPluginContentComponent implements OnInit, DoCheck {
6262
@Input() args?: Record<string, unknown>;
6363
@Input() initResult?: CoreSitePluginsContent | null; // Result of the init WS call of the handler.
6464
@Input() data: Record<string, unknown> = {}; // Data to pass to the component.
65+
@Input() stylesPath = ''; // Styles.
6566
@Input() preSets?: CoreSiteWSPreSets; // The preSets for the WS call.
6667
@Input() pageTitle?: string; // Current page title. It can be used by the "new-content" directives.
6768
@Input() contextLevel?: ContextLevel; // The context level to filter text. Can be used by some directives.
@@ -145,7 +146,8 @@ export class CoreSitePluginsPluginContentComponent implements OnInit, DoCheck {
145146
jsData?: Record<string, unknown> | boolean,
146147
preSets?: CoreSiteWSPreSets,
147148
ptrEnabled?: boolean,
148-
) => this.openContent(title, args, component, method, jsData, preSets, ptrEnabled);
149+
stylesPath?: string,
150+
) => this.openContent(title, args, component, method, jsData, preSets, ptrEnabled, stylesPath);
149151
this.jsData.refreshContent = (showSpinner?: boolean) => this.refreshContent(showSpinner);
150152
this.jsData.updateContent = (
151153
args?: Record<string, unknown>,
@@ -181,6 +183,7 @@ export class CoreSitePluginsPluginContentComponent implements OnInit, DoCheck {
181183
* If true is supplied instead of an object, all initial variables from current page will be copied.
182184
* @param preSets The preSets for the WS call of the new content.
183185
* @param ptrEnabled Whether PTR should be enabled in the new page. Defaults to true.
186+
* @param stylesPath Styles to apply to the component.
184187
*/
185188
openContent(
186189
title: string,
@@ -191,6 +194,7 @@ export class CoreSitePluginsPluginContentComponent implements OnInit, DoCheck {
191194
preSets?: CoreSiteWSPreSets,
192195
ptrEnabled?: boolean,
193196
filterOptions?: FilterOptions,
197+
stylesPath?: string,
194198
): void {
195199
if (jsData === true) {
196200
jsData = this.data;
@@ -211,6 +215,7 @@ export class CoreSitePluginsPluginContentComponent implements OnInit, DoCheck {
211215
contextLevel: filterOptions?.contextLevel || this.contextLevel,
212216
contextInstanceId: filterOptions?.contextInstanceId || this.contextInstanceId,
213217
courseId: filterOptions?.courseId || this.courseId,
218+
stylesPath,
214219
},
215220
});
216221
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<core-compile-html [text]="content" [jsData]="jsData" (created)="componentCreated($event)" [extraImports]="extraImports" />
1+
<core-compile-html [text]="content" [jsData]="jsData" (created)="componentCreated($event)" [stylesPath]="stylesPath" [extraImports]="extraImports" />

src/core/features/siteplugins/components/question-behaviour/question-behaviour.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export class CoreSitePluginsQuestionBehaviourComponent extends CoreSitePluginsCo
7272
this.jsData.onAbort = this.onAbort;
7373

7474
if (this.question) {
75-
this.getHandlerData(CoreQuestionBehaviourDelegate.getHandlerName(this.preferredBehaviour || ''));
75+
await this.getHandlerData(CoreQuestionBehaviourDelegate.getHandlerName(this.preferredBehaviour || ''));
7676
}
7777
}
7878

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<core-compile-html [text]="content" [jsData]="jsData" (created)="componentCreated($event)" [extraImports]="extraImports" />
1+
<core-compile-html [text]="content" [jsData]="jsData" (created)="componentCreated($event)" [stylesPath]="stylesPath" [extraImports]="extraImports" />
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<core-compile-html [text]="content" [jsData]="jsData" (created)="componentCreated($event)" [extraImports]="extraImports" />
1+
<core-compile-html [text]="content" [jsData]="jsData" (created)="componentCreated($event)" [stylesPath]="stylesPath" [extraImports]="extraImports" />

src/core/features/siteplugins/components/quiz-access-rule/quiz-access-rule.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export class CoreSitePluginsQuizAccessRuleComponent extends CoreSitePluginsCompi
5757
this.jsData.form = this.form;
5858

5959
if (this.rule) {
60-
this.getHandlerData(AddonModQuizAccessRuleDelegate.getHandlerName(this.rule));
60+
await this.getHandlerData(AddonModQuizAccessRuleDelegate.getHandlerName(this.rule));
6161
}
6262
}
6363

0 commit comments

Comments
 (0)