Skip to content

Commit fd270d4

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

37 files changed

+238
-110
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,
@@ -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: 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" />

0 commit comments

Comments
 (0)