MOBILE-3657 workshop: Add siteplugins support

main
Pau Ferrer Ocaña 2021-04-26 11:32:48 +02:00
parent 8a5ea5e76f
commit cb835f7031
5 changed files with 143 additions and 21 deletions

View File

@ -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<unknown> {
return CoreSitePluginsWorkshopAssessmentStrategyComponent;
}
/**
* @inheritdoc
*/
async getOriginalValues(): Promise<AddonModWorkshopGetAssessmentFormFieldsParsedData[]> {
return [];
}
/**
* @inheritdoc
*/
hasDataChanged(): boolean {
return false;
}
/**
* @inheritdoc
*/
async isEnabled(): Promise<boolean> {
return true;
}
/**
* @inheritdoc
*/
async prepareAssessmentData(): Promise<CoreFormFields> {
return {};
}
}

View File

@ -25,8 +25,7 @@ import { CoreSitePluginsQuestionBehaviourComponent } from './question-behaviour/
import { CoreSitePluginsQuizAccessRuleComponent } from './quiz-access-rule/quiz-access-rule'; import { CoreSitePluginsQuizAccessRuleComponent } from './quiz-access-rule/quiz-access-rule';
import { CoreSitePluginsAssignFeedbackComponent } from './assign-feedback/assign-feedback'; import { CoreSitePluginsAssignFeedbackComponent } from './assign-feedback/assign-feedback';
import { CoreSitePluginsAssignSubmissionComponent } from './assign-submission/assign-submission'; 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 { CoreSitePluginsBlockComponent } from './block/block';
import { CoreSitePluginsOnlyTitleBlockComponent } from './only-title-block/only-title-block'; import { CoreSitePluginsOnlyTitleBlockComponent } from './only-title-block/only-title-block';
@ -43,7 +42,7 @@ import { CoreSitePluginsOnlyTitleBlockComponent } from './only-title-block/only-
CoreSitePluginsQuizAccessRuleComponent, CoreSitePluginsQuizAccessRuleComponent,
CoreSitePluginsAssignFeedbackComponent, CoreSitePluginsAssignFeedbackComponent,
CoreSitePluginsAssignSubmissionComponent, CoreSitePluginsAssignSubmissionComponent,
// @todo CoreSitePluginsWorkshopAssessmentStrategyComponent, CoreSitePluginsWorkshopAssessmentStrategyComponent,
], ],
imports: [ imports: [
CoreSharedModule, CoreSharedModule,
@ -61,7 +60,7 @@ import { CoreSitePluginsOnlyTitleBlockComponent } from './only-title-block/only-
CoreSitePluginsQuizAccessRuleComponent, CoreSitePluginsQuizAccessRuleComponent,
CoreSitePluginsAssignFeedbackComponent, CoreSitePluginsAssignFeedbackComponent,
CoreSitePluginsAssignSubmissionComponent, CoreSitePluginsAssignSubmissionComponent,
// @todo CoreSitePluginsWorkshopAssessmentStrategyComponent, CoreSitePluginsWorkshopAssessmentStrategyComponent,
], ],
}) })
export class CoreSitePluginsComponentsModule {} export class CoreSitePluginsComponentsModule {}

View File

@ -0,0 +1 @@
<core-compile-html [text]="content" [jsData]="jsData" (created)="componentCreated($event)"></core-compile-html>

View File

@ -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<string, string>;
@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));
}
}

View File

@ -79,6 +79,8 @@ import {
import { makeSingleton } from '@singletons'; import { makeSingleton } from '@singletons';
import { CoreMainMenuHomeDelegate } from '@features/mainmenu/services/home-delegate'; import { CoreMainMenuHomeDelegate } from '@features/mainmenu/services/home-delegate';
import { CoreSitePluginsMainMenuHomeHandler } from '../classes/handlers/main-menu-home-handler'; 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'; 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 handlerName Name of the handler in the plugin.
* @param handlerSchema Data about the handler. * @param handlerSchema Data about the handler.
* @return Promise resolved with a string to identify the handler. * @return Promise resolved with a string to identify the handler.
* @todo
*/ */
protected registerWorkshopAssessmentStrategyHandler( protected registerWorkshopAssessmentStrategyHandler(
plugin: CoreSitePluginsPlugin, // eslint-disable-line @typescript-eslint/no-unused-vars plugin: CoreSitePluginsPlugin,
handlerName: string, // eslint-disable-line @typescript-eslint/no-unused-vars handlerName: string,
handlerSchema: CoreSitePluginsHandlerCommonData, // eslint-disable-line @typescript-eslint/no-unused-vars handlerSchema: CoreSitePluginsHandlerCommonData,
): Promise<string | undefined> { ): Promise<string | undefined> {
// @todo return this.registerComponentInitHandler(
return Promise.resolve(''); plugin,
handlerName,
handlerSchema,
AddonWorkshopAssessmentStrategyDelegate.instance,
(uniqueName) => {
const strategyName = (handlerSchema.moodlecomponent || plugin.component).replace('workshopform_', '');
// return this.registerComponentInitHandler( return new CoreSitePluginsWorkshopAssessmentStrategyHandler(uniqueName, strategyName);
// plugin, },
// handlerName, );
// handlerSchema,
// this.workshopAssessmentStrategyDelegate,
// (uniqueName, result) => {
// const strategyName = (handlerSchema.moodlecomponent || plugin.component).replace('workshopform_', '');
// return new CoreSitePluginsWorkshopAssessmentStrategyHandler(uniqueName, strategyName);
// },
// );
} }
/** /**