Skip to content

Commit 3a7848e

Browse files
committed
MOBILE-3730: Load styles from site plugins
1 parent 8b34f1f commit 3a7848e

37 files changed

+245
-118
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
@@ -25,6 +25,8 @@ export class CoreSitePluginsCompileInitComponent {
2525
jsData: Record<string, unknown> = {}; // Data to pass to the component.
2626
protected handlerSchema?: CoreSitePluginsInitHandlerData; // The handler data.
2727

28+
stylesPath?: string; // Styles to apply to the component.
29+
2830
/**
2931
* Function called when the component is created.
3032
*
@@ -40,18 +42,18 @@ export class CoreSitePluginsCompileInitComponent {
4042
/**
4143
* Get the handler data.
4244
*
43-
* @param name The name of the handler.
45+
* @param handlerName The name of the handler.
4446
*/
45-
getHandlerData(name: string): void {
47+
async getHandlerData(handlerName: string): Promise<void> {
4648
// Retrieve the handler data.
47-
const handler = CoreSitePlugins.getSitePluginHandler(name);
48-
49-
this.handlerSchema = handler?.handlerSchema;
49+
const handler = CoreSitePlugins.getSitePluginHandler(handlerName);
5050

51-
if (!this.handlerSchema) {
51+
if (!handler?.handlerSchema) {
5252
return;
5353
}
5454

55+
this.handlerSchema = handler.handlerSchema;
56+
5557
// Load first template.
5658
if (this.handlerSchema.methodTemplates?.length) {
5759
this.content = this.handlerSchema.methodTemplates[0].html;
@@ -70,6 +72,8 @@ export class CoreSitePluginsCompileInitComponent {
7072
if (this.handlerSchema.methodJSResult) {
7173
this.jsData.CONTENT_JS_RESULT = this.handlerSchema.methodJSResult;
7274
}
75+
76+
this.stylesPath = await CoreSitePlugins.getHandlerDownloadedStyles(handlerName);
7377
}
7478

7579
}

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,
@@ -99,6 +104,7 @@ export class CoreSitePluginsCourseOptionHandler extends CoreSitePluginsBaseHandl
99104
args,
100105
initResult: this.initResult,
101106
ptrEnabled: this.handlerSchema.ptrenabled,
107+
stylesPath,
102108
},
103109
};
104110
}

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,
@@ -108,6 +111,7 @@ export class CoreSitePluginsUserProfileHandler extends CoreSitePluginsBaseHandle
108111
args,
109112
initResult: this.initResult,
110113
ptrEnabled: this.handlerSchema.ptrenabled,
114+
handlerName,
111115
},
112116
},
113117
);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export class CoreSitePluginsAssignFeedbackComponent extends CoreSitePluginsCompi
3939
/**
4040
* @inheritdoc
4141
*/
42-
ngOnInit(): void {
42+
async ngOnInit(): Promise<void> {
4343
// Pass the input and output data to the component.
4444
this.jsData.assign = this.assign;
4545
this.jsData.submission = this.submission;
@@ -50,7 +50,7 @@ export class CoreSitePluginsAssignFeedbackComponent extends CoreSitePluginsCompi
5050
this.jsData.canEdit = this.canEdit;
5151

5252
if (this.plugin) {
53-
this.getHandlerData(AddonModAssignFeedbackDelegate.getHandlerName(this.plugin.type));
53+
await this.getHandlerData(AddonModAssignFeedbackDelegate.getHandlerName(this.plugin.type));
5454
}
5555
}
5656

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)" />
1+
<core-compile-html [text]="content" [jsData]="jsData" (created)="componentCreated($event)" [stylesPath]="stylesPath" />

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export class CoreSitePluginsAssignSubmissionComponent extends CoreSitePluginsCom
3838
/**
3939
* @inheritdoc
4040
*/
41-
ngOnInit(): void {
41+
async ngOnInit(): Promise<void> {
4242
// Pass the input and output data to the component.
4343
this.jsData.assign = this.assign;
4444
this.jsData.submission = this.submission;
@@ -48,7 +48,7 @@ export class CoreSitePluginsAssignSubmissionComponent extends CoreSitePluginsCom
4848
this.jsData.allowOffline = this.allowOffline;
4949

5050
if (this.plugin) {
51-
this.getHandlerData(AddonModAssignSubmissionDelegate.getHandlerName(this.plugin.type));
51+
await this.getHandlerData(AddonModAssignSubmissionDelegate.getHandlerName(this.plugin.type));
5252
}
5353
}
5454

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)" />
1+
<core-compile-html [text]="content" [jsData]="jsData" (created)="componentCreated($event)" [stylesPath]="stylesPath" />

0 commit comments

Comments
 (0)