From cb835f7031fb7704b14edd576db10069c313c311 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Mon, 26 Apr 2021 11:32:48 +0200 Subject: [PATCH] MOBILE-3657 workshop: Add siteplugins support --- .../workshop-assessment-strategy-handler.ts | 70 +++++++++++++++++++ .../components/components.module.ts | 7 +- ...eplugins-workshop-assessment-strategy.html | 1 + .../workshop-assessment-strategy.ts | 54 ++++++++++++++ .../services/siteplugins-helper.ts | 32 ++++----- 5 files changed, 143 insertions(+), 21 deletions(-) create mode 100644 src/core/features/siteplugins/classes/handlers/workshop-assessment-strategy-handler.ts create mode 100644 src/core/features/siteplugins/components/workshop-assessment-strategy/core-siteplugins-workshop-assessment-strategy.html create mode 100644 src/core/features/siteplugins/components/workshop-assessment-strategy/workshop-assessment-strategy.ts diff --git a/src/core/features/siteplugins/classes/handlers/workshop-assessment-strategy-handler.ts b/src/core/features/siteplugins/classes/handlers/workshop-assessment-strategy-handler.ts new file mode 100644 index 000000000..f78b2f60b --- /dev/null +++ b/src/core/features/siteplugins/classes/handlers/workshop-assessment-strategy-handler.ts @@ -0,0 +1,70 @@ +// (C) Copyright 2015 Moodle Pty Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import { AddonWorkshopAssessmentStrategyHandler } from '@addons/mod/workshop/services/assessment-strategy-delegate'; +import { AddonModWorkshopGetAssessmentFormFieldsParsedData } from '@addons/mod/workshop/services/workshop'; +import { Type } from '@angular/core'; +import { + CoreSitePluginsWorkshopAssessmentStrategyComponent, +} from '@features/siteplugins/components/workshop-assessment-strategy/workshop-assessment-strategy'; +import { CoreFormFields } from '@singletons/form'; +import { CoreSitePluginsBaseHandler } from './base-handler'; + +/** + * Handler to display a workshop assessment strategy site plugin. + */ +export class CoreSitePluginsWorkshopAssessmentStrategyHandler + extends CoreSitePluginsBaseHandler + implements AddonWorkshopAssessmentStrategyHandler { + + constructor(public name: string, public strategyName: string) { + super(name); + } + + /** + * @inheritdoc + */ + getComponent(): Type { + return CoreSitePluginsWorkshopAssessmentStrategyComponent; + } + + /** + * @inheritdoc + */ + async getOriginalValues(): Promise { + return []; + } + + /** + * @inheritdoc + */ + hasDataChanged(): boolean { + return false; + } + + /** + * @inheritdoc + */ + async isEnabled(): Promise { + return true; + } + + /** + * @inheritdoc + */ + async prepareAssessmentData(): Promise { + return {}; + } + +} diff --git a/src/core/features/siteplugins/components/components.module.ts b/src/core/features/siteplugins/components/components.module.ts index 8ffc0cdef..2969000e5 100644 --- a/src/core/features/siteplugins/components/components.module.ts +++ b/src/core/features/siteplugins/components/components.module.ts @@ -25,8 +25,7 @@ import { CoreSitePluginsQuestionBehaviourComponent } from './question-behaviour/ import { CoreSitePluginsQuizAccessRuleComponent } from './quiz-access-rule/quiz-access-rule'; import { CoreSitePluginsAssignFeedbackComponent } from './assign-feedback/assign-feedback'; import { CoreSitePluginsAssignSubmissionComponent } from './assign-submission/assign-submission'; -// @todo -// import { CoreSitePluginsWorkshopAssessmentStrategyComponent } from './workshop-assessment-strategy/workshop-assessment-strategy'; +import { CoreSitePluginsWorkshopAssessmentStrategyComponent } from './workshop-assessment-strategy/workshop-assessment-strategy'; import { CoreSitePluginsBlockComponent } from './block/block'; import { CoreSitePluginsOnlyTitleBlockComponent } from './only-title-block/only-title-block'; @@ -43,7 +42,7 @@ import { CoreSitePluginsOnlyTitleBlockComponent } from './only-title-block/only- CoreSitePluginsQuizAccessRuleComponent, CoreSitePluginsAssignFeedbackComponent, CoreSitePluginsAssignSubmissionComponent, - // @todo CoreSitePluginsWorkshopAssessmentStrategyComponent, + CoreSitePluginsWorkshopAssessmentStrategyComponent, ], imports: [ CoreSharedModule, @@ -61,7 +60,7 @@ import { CoreSitePluginsOnlyTitleBlockComponent } from './only-title-block/only- CoreSitePluginsQuizAccessRuleComponent, CoreSitePluginsAssignFeedbackComponent, CoreSitePluginsAssignSubmissionComponent, - // @todo CoreSitePluginsWorkshopAssessmentStrategyComponent, + CoreSitePluginsWorkshopAssessmentStrategyComponent, ], }) export class CoreSitePluginsComponentsModule {} diff --git a/src/core/features/siteplugins/components/workshop-assessment-strategy/core-siteplugins-workshop-assessment-strategy.html b/src/core/features/siteplugins/components/workshop-assessment-strategy/core-siteplugins-workshop-assessment-strategy.html new file mode 100644 index 000000000..f58bcd913 --- /dev/null +++ b/src/core/features/siteplugins/components/workshop-assessment-strategy/core-siteplugins-workshop-assessment-strategy.html @@ -0,0 +1 @@ + diff --git a/src/core/features/siteplugins/components/workshop-assessment-strategy/workshop-assessment-strategy.ts b/src/core/features/siteplugins/components/workshop-assessment-strategy/workshop-assessment-strategy.ts new file mode 100644 index 000000000..ea9e56c18 --- /dev/null +++ b/src/core/features/siteplugins/components/workshop-assessment-strategy/workshop-assessment-strategy.ts @@ -0,0 +1,54 @@ +// (C) Copyright 2015 Moodle Pty Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import { AddonWorkshopAssessmentStrategyDelegate } from '@addons/mod/workshop/services/assessment-strategy-delegate'; +import { AddonModWorkshopGetAssessmentFormFieldsParsedData } from '@addons/mod/workshop/services/workshop'; +import { AddonModWorkshopSubmissionAssessmentWithFormData } from '@addons/mod/workshop/services/workshop-helper'; +import { Component, OnInit, Input } from '@angular/core'; +import { CoreSitePluginsCompileInitComponent } from '@features/siteplugins/classes/compile-init-component'; + +/** + * Component that displays a workshop assessment strategy plugin created using a site plugin. + */ +@Component({ + selector: 'core-siteplugins-workshop-assessment-strategy', + templateUrl: 'core-siteplugins-workshop-assessment-strategy.html', +}) +export class CoreSitePluginsWorkshopAssessmentStrategyComponent extends CoreSitePluginsCompileInitComponent implements OnInit { + + @Input() workshopId!: number; + @Input() assessment!: AddonModWorkshopSubmissionAssessmentWithFormData; + @Input() edit!: boolean; + @Input() selectedValues!: AddonModWorkshopGetAssessmentFormFieldsParsedData[]; + @Input() fieldErrors!: Record; + @Input() strategy!: string; + @Input() moduleId!: number; + @Input() courseId?: number; + + /** + * @inheritdoc + */ + ngOnInit(): void { + // Pass the input and output data to the component. + 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(AddonWorkshopAssessmentStrategyDelegate.getHandlerName(this.strategy)); + } + +} diff --git a/src/core/features/siteplugins/services/siteplugins-helper.ts b/src/core/features/siteplugins/services/siteplugins-helper.ts index fd637602c..9acacb577 100644 --- a/src/core/features/siteplugins/services/siteplugins-helper.ts +++ b/src/core/features/siteplugins/services/siteplugins-helper.ts @@ -79,6 +79,8 @@ import { import { makeSingleton } from '@singletons'; import { CoreMainMenuHomeDelegate } from '@features/mainmenu/services/home-delegate'; import { CoreSitePluginsMainMenuHomeHandler } from '../classes/handlers/main-menu-home-handler'; +import { AddonWorkshopAssessmentStrategyDelegate } from '@addons/mod/workshop/services/assessment-strategy-delegate'; +import { CoreSitePluginsWorkshopAssessmentStrategyHandler } from '../classes/handlers/workshop-assessment-strategy-handler'; const HANDLER_DISABLED = 'core_site_plugins_helper_handler_disabled'; @@ -1094,27 +1096,23 @@ export class CoreSitePluginsHelperProvider { * @param handlerName Name of the handler in the plugin. * @param handlerSchema Data about the handler. * @return Promise resolved with a string to identify the handler. - * @todo */ protected registerWorkshopAssessmentStrategyHandler( - plugin: CoreSitePluginsPlugin, // eslint-disable-line @typescript-eslint/no-unused-vars - handlerName: string, // eslint-disable-line @typescript-eslint/no-unused-vars - handlerSchema: CoreSitePluginsHandlerCommonData, // eslint-disable-line @typescript-eslint/no-unused-vars + plugin: CoreSitePluginsPlugin, + handlerName: string, + handlerSchema: CoreSitePluginsHandlerCommonData, ): Promise { - // @todo - return Promise.resolve(''); + return this.registerComponentInitHandler( + plugin, + handlerName, + handlerSchema, + AddonWorkshopAssessmentStrategyDelegate.instance, + (uniqueName) => { + const strategyName = (handlerSchema.moodlecomponent || plugin.component).replace('workshopform_', ''); - // return this.registerComponentInitHandler( - // plugin, - // handlerName, - // handlerSchema, - // this.workshopAssessmentStrategyDelegate, - // (uniqueName, result) => { - // const strategyName = (handlerSchema.moodlecomponent || plugin.component).replace('workshopform_', ''); - - // return new CoreSitePluginsWorkshopAssessmentStrategyHandler(uniqueName, strategyName); - // }, - // ); + return new CoreSitePluginsWorkshopAssessmentStrategyHandler(uniqueName, strategyName); + }, + ); } /**