diff --git a/src/core/siteplugins/classes/compile-init-component.ts b/src/core/siteplugins/classes/compile-init-component.ts index 9f9e7270f..96bf80965 100644 --- a/src/core/siteplugins/classes/compile-init-component.ts +++ b/src/core/siteplugins/classes/compile-init-component.ts @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +import { CoreUtilsProvider } from '@providers/utils/utils'; import { CoreSitePluginsProvider } from '../providers/siteplugins'; /** @@ -20,10 +21,10 @@ import { CoreSitePluginsProvider } from '../providers/siteplugins'; */ export class CoreSitePluginsCompileInitComponent { content = ''; // Content. - jsData: any; // Data to pass to the component. + jsData: any = {}; // Data to pass to the component. protected handlerSchema: any; // The handler data. - constructor(protected sitePluginsProvider: CoreSitePluginsProvider) { } + constructor(protected sitePluginsProvider: CoreSitePluginsProvider, protected utils: CoreUtilsProvider) { } /** * Function called when the component is created. @@ -53,6 +54,16 @@ export class CoreSitePluginsCompileInitComponent { // Load first template. if (this.handlerSchema.methodTemplates && this.handlerSchema.methodTemplates.length) { this.content = handler.handlerSchema.methodTemplates[0].html; + this.jsData.CONTENT_TEMPLATES = this.utils.objectToKeyValueMap(handler.handlerSchema.methodTemplates, 'id', 'html'); + } + + // Pass data from the method result to the component. + if (this.handlerSchema.methodOtherdata) { + this.jsData.CONTENT_OTHERDATA = this.handlerSchema.methodOtherdata; + } + + if (this.handlerSchema.methodJSResult) { + this.jsData.CONTENT_JS_RESULT = this.handlerSchema.methodJSResult; } } } diff --git a/src/core/siteplugins/components/assign-feedback/assign-feedback.ts b/src/core/siteplugins/components/assign-feedback/assign-feedback.ts index 210b7f4a8..b8e1d8dcb 100644 --- a/src/core/siteplugins/components/assign-feedback/assign-feedback.ts +++ b/src/core/siteplugins/components/assign-feedback/assign-feedback.ts @@ -13,6 +13,7 @@ // limitations under the License. import { Component, OnInit, Input } from '@angular/core'; +import { CoreUtilsProvider } from '@providers/utils/utils'; import { CoreSitePluginsProvider } from '../../providers/siteplugins'; import { CoreSitePluginsCompileInitComponent } from '../../classes/compile-init-component'; @@ -32,8 +33,8 @@ export class CoreSitePluginsAssignFeedbackComponent extends CoreSitePluginsCompi @Input() canEdit: boolean; // Whether the user can edit. @Input() edit: boolean; // Whether the user is editing. - constructor(sitePluginsProvider: CoreSitePluginsProvider) { - super(sitePluginsProvider); + constructor(sitePluginsProvider: CoreSitePluginsProvider, utils: CoreUtilsProvider) { + super(sitePluginsProvider, utils); } /** @@ -41,15 +42,13 @@ export class CoreSitePluginsAssignFeedbackComponent extends CoreSitePluginsCompi */ ngOnInit(): void { // Pass the input and output data to the component. - this.jsData = { - assign: this.assign, - submission: this.submission, - plugin: this.plugin, - userId: this.userId, - configs: this.configs, - edit: this.edit, - canEdit: this.canEdit - }; + this.jsData.assign = this.assign; + this.jsData.submission = this.submission; + this.jsData.plugin = this.plugin; + this.jsData.userId = this.userId; + this.jsData.configs = this.configs; + this.jsData.edit = this.edit; + this.jsData.canEdit = this.canEdit; if (this.plugin) { this.getHandlerData('assignfeedback_' + this.plugin.type); diff --git a/src/core/siteplugins/components/assign-submission/assign-submission.ts b/src/core/siteplugins/components/assign-submission/assign-submission.ts index 991989d04..cd7af884e 100644 --- a/src/core/siteplugins/components/assign-submission/assign-submission.ts +++ b/src/core/siteplugins/components/assign-submission/assign-submission.ts @@ -13,6 +13,7 @@ // limitations under the License. import { Component, OnInit, Input } from '@angular/core'; +import { CoreUtilsProvider } from '@providers/utils/utils'; import { CoreSitePluginsProvider } from '../../providers/siteplugins'; import { CoreSitePluginsCompileInitComponent } from '../../classes/compile-init-component'; @@ -31,8 +32,8 @@ export class CoreSitePluginsAssignSubmissionComponent extends CoreSitePluginsCom @Input() edit: boolean; // Whether the user is editing. @Input() allowOffline: boolean; // Whether to allow offline. - constructor(sitePluginsProvider: CoreSitePluginsProvider) { - super(sitePluginsProvider); + constructor(sitePluginsProvider: CoreSitePluginsProvider, utils: CoreUtilsProvider) { + super(sitePluginsProvider, utils); } /** @@ -40,14 +41,12 @@ export class CoreSitePluginsAssignSubmissionComponent extends CoreSitePluginsCom */ ngOnInit(): void { // Pass the input and output data to the component. - this.jsData = { - assign: this.assign, - submission: this.submission, - plugin: this.plugin, - configs: this.configs, - edit: this.edit, - allowOffline: this.allowOffline - }; + this.jsData.assign = this.assign; + this.jsData.submission = this.submission; + this.jsData.plugin = this.plugin; + this.jsData.configs = this.configs; + this.jsData.edit = this.edit; + this.jsData.allowOffline = this.allowOffline; if (this.plugin) { this.getHandlerData('assignsubmission_' + this.plugin.type); diff --git a/src/core/siteplugins/components/question-behaviour/question-behaviour.ts b/src/core/siteplugins/components/question-behaviour/question-behaviour.ts index 0b8fba773..0f0bcee48 100644 --- a/src/core/siteplugins/components/question-behaviour/question-behaviour.ts +++ b/src/core/siteplugins/components/question-behaviour/question-behaviour.ts @@ -13,6 +13,7 @@ // limitations under the License. import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core'; +import { CoreUtilsProvider } from '@providers/utils/utils'; import { CoreSitePluginsProvider } from '../../providers/siteplugins'; import { CoreSitePluginsCompileInitComponent } from '../../classes/compile-init-component'; @@ -32,8 +33,8 @@ export class CoreSitePluginsQuestionBehaviourComponent extends CoreSitePluginsCo @Output() buttonClicked: EventEmitter; // Should emit an event when a behaviour button is clicked. @Output() onAbort: EventEmitter; // Should emit an event if the question should be aborted. - constructor(sitePluginsProvider: CoreSitePluginsProvider) { - super(sitePluginsProvider); + constructor(sitePluginsProvider: CoreSitePluginsProvider, utils: CoreUtilsProvider) { + super(sitePluginsProvider, utils); } /** @@ -41,15 +42,13 @@ export class CoreSitePluginsQuestionBehaviourComponent extends CoreSitePluginsCo */ ngOnInit(): void { // Pass the input and output data to the component. - this.jsData = { - question: this.question, - component: this.component, - componentId: this.componentId, - attemptId: this.attemptId, - offlineEnabled: this.offlineEnabled, - buttonClicked: this.buttonClicked, - onAbort: this.onAbort - }; + this.jsData.question = this.question; + this.jsData.component = this.component; + this.jsData.componentId = this.componentId; + this.jsData.attemptId = this.attemptId; + this.jsData.offlineEnabled = this.offlineEnabled; + this.jsData.buttonClicked = this.buttonClicked; + this.jsData.onAbort = this.onAbort; if (this.question) { this.getHandlerData('qbehaviour_' + this.question.preferredBehaviour); diff --git a/src/core/siteplugins/components/question/question.ts b/src/core/siteplugins/components/question/question.ts index f5352adef..012d23af9 100644 --- a/src/core/siteplugins/components/question/question.ts +++ b/src/core/siteplugins/components/question/question.ts @@ -13,6 +13,7 @@ // limitations under the License. import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core'; +import { CoreUtilsProvider } from '@providers/utils/utils'; import { CoreSitePluginsProvider } from '../../providers/siteplugins'; import { CoreSitePluginsCompileInitComponent } from '../../classes/compile-init-component'; @@ -32,8 +33,8 @@ export class CoreSitePluginsQuestionComponent extends CoreSitePluginsCompileInit @Output() buttonClicked: EventEmitter; // Should emit an event when a behaviour button is clicked. @Output() onAbort: EventEmitter; // Should emit an event if the question should be aborted. - constructor(sitePluginsProvider: CoreSitePluginsProvider) { - super(sitePluginsProvider); + constructor(sitePluginsProvider: CoreSitePluginsProvider, utils: CoreUtilsProvider) { + super(sitePluginsProvider, utils); } /** @@ -41,15 +42,13 @@ export class CoreSitePluginsQuestionComponent extends CoreSitePluginsCompileInit */ ngOnInit(): void { // Pass the input and output data to the component. - this.jsData = { - question: this.question, - component: this.component, - componentId: this.componentId, - attemptId: this.attemptId, - offlineEnabled: this.offlineEnabled, - buttonClicked: this.buttonClicked, - onAbort: this.onAbort - }; + this.jsData.question = this.question; + this.jsData.component = this.component; + this.jsData.componentId = this.componentId; + this.jsData.attemptId = this.attemptId; + this.jsData.offlineEnabled = this.offlineEnabled; + this.jsData.buttonClicked = this.buttonClicked; + this.jsData.onAbort = this.onAbort; if (this.question) { this.getHandlerData('qtype_' + this.question.type); diff --git a/src/core/siteplugins/components/quiz-access-rule/quiz-access-rule.ts b/src/core/siteplugins/components/quiz-access-rule/quiz-access-rule.ts index 661d5c008..caa3f382c 100644 --- a/src/core/siteplugins/components/quiz-access-rule/quiz-access-rule.ts +++ b/src/core/siteplugins/components/quiz-access-rule/quiz-access-rule.ts @@ -13,6 +13,7 @@ // limitations under the License. import { Component, OnInit, Input } from '@angular/core'; +import { CoreUtilsProvider } from '@providers/utils/utils'; import { CoreSitePluginsProvider } from '../../providers/siteplugins'; import { CoreSitePluginsCompileInitComponent } from '../../classes/compile-init-component'; import { FormGroup } from '@angular/forms'; @@ -32,8 +33,8 @@ export class CoreSitePluginsQuizAccessRuleComponent extends CoreSitePluginsCompi @Input() siteId: string; // Site ID. @Input() form: FormGroup; // Form where to add the form control. - constructor(sitePluginsProvider: CoreSitePluginsProvider) { - super(sitePluginsProvider); + constructor(sitePluginsProvider: CoreSitePluginsProvider, utils: CoreUtilsProvider) { + super(sitePluginsProvider, utils); } /** @@ -41,14 +42,12 @@ export class CoreSitePluginsQuizAccessRuleComponent extends CoreSitePluginsCompi */ ngOnInit(): void { // Pass the input and output data to the component. - this.jsData = { - rule: this.rule, - quiz: this.quiz, - attempt: this.attempt, - prefetch: this.prefetch, - siteId: this.siteId, - form: this.form - }; + this.jsData.rule = this.rule; + this.jsData.quiz = this.quiz; + this.jsData.attempt = this.attempt; + this.jsData.prefetch = this.prefetch; + this.jsData.siteId = this.siteId; + this.jsData.form = this.form; if (this.rule) { this.getHandlerData(this.rule); diff --git a/src/core/siteplugins/components/user-profile-field/user-profile-field.ts b/src/core/siteplugins/components/user-profile-field/user-profile-field.ts index 46e4ff7af..5e460eb5a 100644 --- a/src/core/siteplugins/components/user-profile-field/user-profile-field.ts +++ b/src/core/siteplugins/components/user-profile-field/user-profile-field.ts @@ -13,6 +13,7 @@ // limitations under the License. import { Component, OnInit, Input } from '@angular/core'; +import { CoreUtilsProvider } from '@providers/utils/utils'; import { CoreSitePluginsProvider } from '../../providers/siteplugins'; import { CoreSitePluginsCompileInitComponent } from '../../classes/compile-init-component'; import { FormGroup } from '@angular/forms'; @@ -32,8 +33,8 @@ export class CoreSitePluginsUserProfileFieldComponent extends CoreSitePluginsCom @Input() signup = false; // True if editing the field in signup. Defaults to false. @Input() registerAuth?: string; // Register auth method. E.g. 'email'. - constructor(sitePluginsProvider: CoreSitePluginsProvider) { - super(sitePluginsProvider); + constructor(sitePluginsProvider: CoreSitePluginsProvider, utils: CoreUtilsProvider) { + super(sitePluginsProvider, utils); } /** @@ -42,14 +43,12 @@ export class CoreSitePluginsUserProfileFieldComponent extends CoreSitePluginsCom ngOnInit(): void { // Pass the input data to the component. - this.jsData = { - field: this.field, - signup: this.signup, - edit: this.edit, - disabled: this.disabled, - form: this.form, - registerAuth: this.registerAuth - }; + this.jsData.field = this.field; + this.jsData.signup = this.signup; + this.jsData.edit = this.edit; + this.jsData.disabled = this.disabled; + this.jsData.form = this.form; + this.jsData.registerAuth = this.registerAuth; if (this.field) { this.getHandlerData('profilefield_' + (this.field.type || this.field.datatype)); diff --git a/src/core/siteplugins/components/workshop-assessment-strategy/workshop-assessment-strategy.ts b/src/core/siteplugins/components/workshop-assessment-strategy/workshop-assessment-strategy.ts index ef72738d1..3da761007 100644 --- a/src/core/siteplugins/components/workshop-assessment-strategy/workshop-assessment-strategy.ts +++ b/src/core/siteplugins/components/workshop-assessment-strategy/workshop-assessment-strategy.ts @@ -13,6 +13,7 @@ // limitations under the License. import { Component, OnInit, Input } from '@angular/core'; +import { CoreUtilsProvider } from '@providers/utils/utils'; import { CoreSitePluginsProvider } from '../../providers/siteplugins'; import { CoreSitePluginsCompileInitComponent } from '../../classes/compile-init-component'; @@ -31,8 +32,8 @@ export class CoreSitePluginsWorkshopAssessmentStrategyComponent extends CoreSite @Input() fieldErrors: any; @Input() strategy: string; - constructor(sitePluginsProvider: CoreSitePluginsProvider) { - super(sitePluginsProvider); + constructor(sitePluginsProvider: CoreSitePluginsProvider, utils: CoreUtilsProvider) { + super(sitePluginsProvider, utils); } /** @@ -40,14 +41,12 @@ export class CoreSitePluginsWorkshopAssessmentStrategyComponent extends CoreSite */ ngOnInit(): void { // Pass the input and output data to the component. - this.jsData = { - workshopId: this.workshopId, - assessment: this.assessment, - edit: this.edit, - selectedValues: this.selectedValues, - fieldErrors: this.fieldErrors, - strategy: this.strategy - }; + this.jsData.workshopId = this.workshopId; + this.jsData.assessment = this.assessment; + this.jsData.edit = this.edit; + this.jsData.selectedValues = this.selectedValues; + this.jsData.fieldErrors = this.fieldErrors; + this.jsData.strategy = this.strategy; this.getHandlerData('workshopform_' + this.strategy); } diff --git a/src/core/siteplugins/providers/helper.ts b/src/core/siteplugins/providers/helper.ts index 7aa65b72d..26124d2b6 100644 --- a/src/core/siteplugins/providers/helper.ts +++ b/src/core/siteplugins/providers/helper.ts @@ -547,6 +547,7 @@ export class CoreSitePluginsHelperProvider { // Store in handlerSchema some data required by the component. handlerSchema.methodTemplates = result.templates; handlerSchema.methodJSResult = result.jsResult; + handlerSchema.methodOtherdata = result.otherdata; if (result && result.jsResult) { // Override default handler functions with the result of the method JS.