Skip to content

Commit 0554b1d

Browse files
committed
MOBILE-3730: Load styles from site plugins
1 parent 9c11261 commit 0554b1d

37 files changed

+247
-132
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" />

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

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

4041
constructor() {
4142
super('CoreSitePluginsBlockComponent');
4243
}
4344

4445
/**
45-
* Detect changes on input properties.
46+
* @inheritdoc
4647
*/
47-
ngOnChanges(): void {
48+
async ngOnChanges(): Promise<void> {
4849
if (this.component) {
4950
return;
5051
}
@@ -67,12 +68,12 @@ export class CoreSitePluginsBlockComponent extends CoreBlockBaseComponent implem
6768
block: this.block,
6869
};
6970
this.initResult = handler.initResult;
71+
72+
this.stylesPath = await CoreSitePlugins.getHandlerDownloadedStyles(handlerName);
7073
}
7174

7275
/**
73-
* Invalidate block data.
74-
*
75-
* @returns Promise resolved when done.
76+
* @inheritdoc
7677
*/
7778
async invalidateContent(): Promise<void> {
7879
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" />
2+
[initResult]="initResult" [data]="jsData" [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" />
2+
[initResult]="initResult" [data]="data" [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
@@ -49,11 +49,12 @@ export class CoreSitePluginsCourseFormatComponent implements OnChanges {
4949
args?: Record<string, unknown>;
5050
initResult?: CoreSitePluginsContent | null;
5151
data?: Record<string, unknown>;
52+
stylesPath?: string; // Styles to apply to the component.
5253

5354
/**
5455
* @inheritdoc
5556
*/
56-
ngOnChanges(): void {
57+
async ngOnChanges(): Promise<void> {
5758
if (!this.course || !this.course.format) {
5859
return;
5960
}
@@ -70,6 +71,8 @@ export class CoreSitePluginsCourseFormatComponent implements OnChanges {
7071
courseid: this.course.id,
7172
};
7273
this.initResult = handler.initResult;
74+
75+
this.stylesPath = await CoreSitePlugins.getHandlerDownloadedStyles(handlerName);
7376
}
7477
}
7578

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
@@ -11,7 +11,7 @@
1111

1212
<core-site-plugins-plugin-content *ngIf="component && method" [component]="component" [method]="method" [args]="args"
1313
[initResult]="initResult" [data]="jsData" [pageTitle]="pageTitle" [preSets]="preSets" (onContentLoaded)="contentLoaded($event)"
14-
(onLoadingContent)="contentLoading()" />
14+
(onLoadingContent)="contentLoading()" [stylesPath]="stylesPath" />
1515

1616
<core-course-module-navigation collapsible-footer [appearOnBottom]="collapsibleFooterAppearOnBottom" *ngIf="module" [courseId]="courseId"
1717
[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
@@ -73,11 +73,12 @@ export class CoreSitePluginsModuleIndexComponent implements OnInit, OnDestroy, C
7373
isDestroyed = false;
7474

7575
jsData?: Record<string, unknown>; // Data to pass to the component.
76+
stylesPath?: string; // Styles to apply to the component.
7677

7778
/**
7879
* @inheritdoc
7980
*/
80-
ngOnInit(): void {
81+
async ngOnInit(): Promise<void> {
8182
if (!this.module) {
8283
return;
8384
}
@@ -110,6 +111,8 @@ export class CoreSitePluginsModuleIndexComponent implements OnInit, OnDestroy, C
110111
this.ptrEnabled = !CoreUtils.isFalseOrZero(handlerSchema.ptrenabled);
111112

112113
this.collapsibleFooterAppearOnBottom = !CoreUtils.isFalseOrZero(handlerSchema.isresource);
114+
115+
this.stylesPath = await CoreSitePlugins.getHandlerDownloadedStyles(handlerName);
113116
}
114117

115118
// Get the data for the context menu.
@@ -132,6 +135,8 @@ export class CoreSitePluginsModuleIndexComponent implements OnInit, OnDestroy, C
132135

133136
/**
134137
* Function called when the data of the site plugin content is loaded.
138+
*
139+
* @param data Data received.
135140
*/
136141
contentLoaded(data: CoreSitePluginsPluginContentLoadedData): void {
137142
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
@@ -68,6 +68,7 @@ export class CoreSitePluginsOnlyTitleBlockComponent extends CoreBlockBaseCompone
6868
args,
6969
initResult: handler.initResult,
7070
ptrEnabled: (<CoreSitePluginsUserHandlerData> handler.handlerSchema).ptrenabled,
71+
handlerName,
7172
},
7273
},
7374
);
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
@@ -54,6 +54,7 @@ export class CoreSitePluginsPluginContentComponent implements OnInit, DoCheck {
5454
@Input() args?: Record<string, unknown>;
5555
@Input() initResult?: CoreSitePluginsContent | null; // Result of the init WS call of the handler.
5656
@Input() data: Record<string, unknown> = {}; // Data to pass to the component.
57+
@Input() stylesPath = ''; // Styles.
5758
@Input() preSets?: CoreSiteWSPreSets; // The preSets for the WS call.
5859
@Input() pageTitle?: string; // Current page title. It can be used by the "new-content" directives.
5960
@Output() onContentLoaded = new EventEmitter<CoreSitePluginsPluginContentLoadedData>(); // Emits event when content is loaded.
@@ -134,7 +135,8 @@ export class CoreSitePluginsPluginContentComponent implements OnInit, DoCheck {
134135
jsData?: Record<string, unknown> | boolean,
135136
preSets?: CoreSiteWSPreSets,
136137
ptrEnabled?: boolean,
137-
) => this.openContent(title, args, component, method, jsData, preSets, ptrEnabled);
138+
stylesPath?: string,
139+
) => this.openContent(title, args, component, method, jsData, preSets, ptrEnabled, stylesPath);
138140
this.jsData.refreshContent = (showSpinner?: boolean) => this.refreshContent(showSpinner);
139141
this.jsData.updateContent = (
140142
args?: Record<string, unknown>,
@@ -170,6 +172,7 @@ export class CoreSitePluginsPluginContentComponent implements OnInit, DoCheck {
170172
* If true is supplied instead of an object, all initial variables from current page will be copied.
171173
* @param preSets The preSets for the WS call of the new content.
172174
* @param ptrEnabled Whether PTR should be enabled in the new page. Defaults to true.
175+
* @param stylesPath Styles to apply to the component.
173176
*/
174177
openContent(
175178
title: string,
@@ -179,6 +182,7 @@ export class CoreSitePluginsPluginContentComponent implements OnInit, DoCheck {
179182
jsData?: Record<string, unknown> | boolean,
180183
preSets?: CoreSiteWSPreSets,
181184
ptrEnabled?: boolean,
185+
stylesPath?: string,
182186
): void {
183187
if (jsData === true) {
184188
jsData = this.data;
@@ -196,6 +200,7 @@ export class CoreSitePluginsPluginContentComponent implements OnInit, DoCheck {
196200
jsData,
197201
preSets,
198202
ptrEnabled,
203+
stylesPath,
199204
},
200205
});
201206
}
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)