MOBILE-4272 workshop: Decouple assessment
This commit is contained in:
		
							parent
							
								
									cd66097a8f
								
							
						
					
					
						commit
						2a0a079b47
					
				| @ -13,15 +13,11 @@ | ||||
| // limitations under the License.
 | ||||
| 
 | ||||
| import { APP_INITIALIZER, NgModule } from '@angular/core'; | ||||
| import { AddonModWorkshopAssessmentStrategyAccumulativeComponent } from './component/accumulative'; | ||||
| import { AddonModWorkshopAssessmentStrategyAccumulativeHandler } from './services/handler'; | ||||
| import { AddonWorkshopAssessmentStrategyDelegate } from '../../services/assessment-strategy-delegate'; | ||||
| import { CoreSharedModule } from '@/core/shared.module'; | ||||
| import { getAssessmentStrategyHandlerInstance } from '@addons/mod/workshop/assessment/accumulative/services/handler'; | ||||
| 
 | ||||
| @NgModule({ | ||||
|     declarations: [ | ||||
|         AddonModWorkshopAssessmentStrategyAccumulativeComponent, | ||||
|     ], | ||||
|     imports: [ | ||||
|         CoreSharedModule, | ||||
|     ], | ||||
| @ -30,14 +26,9 @@ import { CoreSharedModule } from '@/core/shared.module'; | ||||
|             provide: APP_INITIALIZER, | ||||
|             multi: true, | ||||
|             useValue: () => { | ||||
|                 AddonWorkshopAssessmentStrategyDelegate.registerHandler( | ||||
|                     AddonModWorkshopAssessmentStrategyAccumulativeHandler.instance, | ||||
|                 ); | ||||
|                 AddonWorkshopAssessmentStrategyDelegate.registerHandler(getAssessmentStrategyHandlerInstance()); | ||||
|             }, | ||||
|         }, | ||||
|     ], | ||||
|     exports: [ | ||||
|         AddonModWorkshopAssessmentStrategyAccumulativeComponent, | ||||
|     ], | ||||
| }) | ||||
| export class AddonModWorkshopAssessmentStrategyAccumulativeModule {} | ||||
|  | ||||
| @ -0,0 +1,149 @@ | ||||
| // (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 { | ||||
|     AddonModWorkshopAssessmentStrategyFieldErrors, | ||||
| } from '@addons/mod/workshop/components/assessment-strategy/assessment-strategy'; | ||||
| import { | ||||
|     AddonModWorkshopGetAssessmentFormDefinitionData, | ||||
|     AddonModWorkshopGetAssessmentFormFieldsParsedData, | ||||
| } from '@addons/mod/workshop/services/workshop'; | ||||
| import { Injectable, Type } from '@angular/core'; | ||||
| import { CoreGradesHelper } from '@features/grades/services/grades-helper'; | ||||
| import { makeSingleton, Translate } from '@singletons'; | ||||
| import { CoreFormFields } from '@singletons/form'; | ||||
| import { AddonWorkshopAssessmentStrategyHandler } from '../../../services/assessment-strategy-delegate'; | ||||
| import { AddonModWorkshopAssessmentStrategyAccumulativeComponent } from '../component/accumulative'; | ||||
| import { AddonModWorkshopAssessmentStrategyAccumulativeHandlerService } from './handler'; | ||||
| 
 | ||||
| /** | ||||
|  * Handler for accumulative assessment strategy plugin. | ||||
|  */ | ||||
| @Injectable({ providedIn: 'root' }) | ||||
| export class AddonModWorkshopAssessmentStrategyAccumulativeHandlerLazyService | ||||
|     extends AddonModWorkshopAssessmentStrategyAccumulativeHandlerService | ||||
|     implements AddonWorkshopAssessmentStrategyHandler { | ||||
| 
 | ||||
|     /** | ||||
|      * @inheritdoc | ||||
|      */ | ||||
|     async isEnabled(): Promise<boolean> { | ||||
|         return true; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * @inheritdoc | ||||
|      */ | ||||
|     getComponent(): Type<unknown> { | ||||
|         return AddonModWorkshopAssessmentStrategyAccumulativeComponent; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * @inheritdoc | ||||
|      */ | ||||
|     async getOriginalValues( | ||||
|         form: AddonModWorkshopGetAssessmentFormDefinitionData, | ||||
|     ): Promise<AddonModWorkshopGetAssessmentFormFieldsParsedData[]> { | ||||
|         const defaultGrade = Translate.instant('core.choosedots'); | ||||
|         const originalValues: AddonModWorkshopGetAssessmentFormFieldsParsedData[] = []; | ||||
|         const promises: Promise<void>[] = []; | ||||
| 
 | ||||
|         form.fields.forEach((field, n) => { | ||||
|             field.dimtitle = Translate.instant('addon.mod_workshop_assessment_accumulative.dimensionnumber', { $a: field.number }); | ||||
| 
 | ||||
|             if (!form.current[n]) { | ||||
|                 form.current[n] = {}; | ||||
|             } | ||||
| 
 | ||||
|             originalValues[n] = {}; | ||||
|             originalValues[n].peercomment = form.current[n].peercomment || ''; | ||||
|             originalValues[n].number = field.number; // eslint-disable-line id-blacklist
 | ||||
| 
 | ||||
|             form.current[n].grade = form.current[n].grade ? parseInt(String(form.current[n].grade), 10) : -1; | ||||
| 
 | ||||
|             const gradingType = parseInt(String(field.grade), 10); | ||||
|             const dimension = form.dimensionsinfo.find((dimension) => dimension.id == parseInt(field.dimensionid, 10)); | ||||
|             const scale = dimension && gradingType < 0 ? dimension.scale : undefined; | ||||
| 
 | ||||
|             promises.push(CoreGradesHelper.makeGradesMenu(gradingType, undefined, defaultGrade, -1, scale).then((grades) => { | ||||
|                 field.grades = grades; | ||||
|                 originalValues[n].grade = form.current[n].grade; | ||||
| 
 | ||||
|                 return; | ||||
|             })); | ||||
|         }); | ||||
| 
 | ||||
|         await Promise.all(promises); | ||||
| 
 | ||||
|         return originalValues; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * @inheritdoc | ||||
|      */ | ||||
|     hasDataChanged( | ||||
|         originalValues: AddonModWorkshopGetAssessmentFormFieldsParsedData[], | ||||
|         currentValues: AddonModWorkshopGetAssessmentFormFieldsParsedData[], | ||||
|     ): boolean { | ||||
|         for (const x in originalValues) { | ||||
|             if (originalValues[x].grade != currentValues[x].grade) { | ||||
|                 return true; | ||||
|             } | ||||
|             if (originalValues[x].peercomment != currentValues[x].peercomment) { | ||||
|                 return true; | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         return false; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * @inheritdoc | ||||
|      */ | ||||
|     async prepareAssessmentData( | ||||
|         currentValues: AddonModWorkshopGetAssessmentFormFieldsParsedData[], | ||||
|         form: AddonModWorkshopGetAssessmentFormDefinitionData, | ||||
|     ): Promise<CoreFormFields> { | ||||
|         const data: CoreFormFields = {}; | ||||
|         const errors: AddonModWorkshopAssessmentStrategyFieldErrors = {}; | ||||
|         let hasErrors = false; | ||||
| 
 | ||||
|         form.fields.forEach((field, idx) => { | ||||
|             if (idx < form.dimenssionscount) { | ||||
|                 const grade = parseInt(String(currentValues[idx].grade), 10); | ||||
|                 if (!isNaN(grade) && grade >= 0) { | ||||
|                     data['grade__idx_' + idx] = grade; | ||||
|                 } else { | ||||
|                     errors['grade_' + idx] = Translate.instant('addon.mod_workshop_assessment_accumulative.mustchoosegrade'); | ||||
|                     hasErrors = true; | ||||
|                 } | ||||
| 
 | ||||
|                 data['peercomment__idx_' + idx] = currentValues[idx].peercomment ?? ''; | ||||
| 
 | ||||
|                 data['gradeid__idx_' + idx] = parseInt(form.current[idx].gradeid, 10) || 0; | ||||
|                 data['dimensionid__idx_' + idx] = parseInt(field.dimensionid, 10); | ||||
|                 data['weight__idx_' + idx] = parseInt(field.weight, 10) || 0; | ||||
|             } | ||||
|         }); | ||||
| 
 | ||||
|         if (hasErrors) { | ||||
|             throw errors; | ||||
|         } | ||||
| 
 | ||||
|         return data; | ||||
|     } | ||||
| 
 | ||||
| } | ||||
| export const AddonModWorkshopAssessmentStrategyAccumulativeHandler = | ||||
|     makeSingleton(AddonModWorkshopAssessmentStrategyAccumulativeHandlerLazyService); | ||||
| @ -12,138 +12,33 @@ | ||||
| // See the License for the specific language governing permissions and
 | ||||
| // limitations under the License.
 | ||||
| 
 | ||||
| import { asyncInstance } from '@/core/utils/async-instance'; | ||||
| import { AddonWorkshopAssessmentStrategyHandler } from '@addons/mod/workshop/services/assessment-strategy-delegate'; | ||||
| import { | ||||
|     AddonModWorkshopAssessmentStrategyFieldErrors, | ||||
| } from '@addons/mod/workshop/components/assessment-strategy/assessment-strategy'; | ||||
| import { | ||||
|     AddonModWorkshopGetAssessmentFormDefinitionData, | ||||
|     AddonModWorkshopGetAssessmentFormFieldsParsedData, | ||||
| } from '@addons/mod/workshop/services/workshop'; | ||||
| import { Injectable, Type } from '@angular/core'; | ||||
| import { CoreGradesHelper } from '@features/grades/services/grades-helper'; | ||||
| import { makeSingleton, Translate } from '@singletons'; | ||||
| import { CoreFormFields } from '@singletons/form'; | ||||
| import { AddonWorkshopAssessmentStrategyHandler } from '../../../services/assessment-strategy-delegate'; | ||||
| import { AddonModWorkshopAssessmentStrategyAccumulativeComponent } from '../component/accumulative'; | ||||
|     ADDON_MOD_WORKSHOP_ASSESSMENT_STRATEGY_ACCUMULATIVE_NAME, | ||||
|     ADDON_MOD_WORKSHOP_ASSESSMENT_STRATEGY_ACCUMULATIVE_STRATEGY_NAME, | ||||
| } from '@addons/mod/workshop/assessment/constants'; | ||||
| 
 | ||||
| /** | ||||
|  * Handler for accumulative assessment strategy plugin. | ||||
|  */ | ||||
| @Injectable({ providedIn: 'root' }) | ||||
| export class AddonModWorkshopAssessmentStrategyAccumulativeHandlerService implements AddonWorkshopAssessmentStrategyHandler { | ||||
| export class AddonModWorkshopAssessmentStrategyAccumulativeHandlerService { | ||||
| 
 | ||||
|     name = 'AddonModWorkshopAssessmentStrategyAccumulative'; | ||||
|     strategyName = 'accumulative'; | ||||
| 
 | ||||
|     /** | ||||
|      * @inheritdoc | ||||
|      */ | ||||
|     async isEnabled(): Promise<boolean> { | ||||
|         return true; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * @inheritdoc | ||||
|      */ | ||||
|     getComponent(): Type<unknown> { | ||||
|         return AddonModWorkshopAssessmentStrategyAccumulativeComponent; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * @inheritdoc | ||||
|      */ | ||||
|     async getOriginalValues( | ||||
|         form: AddonModWorkshopGetAssessmentFormDefinitionData, | ||||
|     ): Promise<AddonModWorkshopGetAssessmentFormFieldsParsedData[]> { | ||||
|         const defaultGrade = Translate.instant('core.choosedots'); | ||||
|         const originalValues: AddonModWorkshopGetAssessmentFormFieldsParsedData[] = []; | ||||
|         const promises: Promise<void>[] = []; | ||||
| 
 | ||||
|         form.fields.forEach((field, n) => { | ||||
|             field.dimtitle = Translate.instant('addon.mod_workshop_assessment_accumulative.dimensionnumber', { $a: field.number }); | ||||
| 
 | ||||
|             if (!form.current[n]) { | ||||
|                 form.current[n] = {}; | ||||
|             } | ||||
| 
 | ||||
|             originalValues[n] = {}; | ||||
|             originalValues[n].peercomment = form.current[n].peercomment || ''; | ||||
|             originalValues[n].number = field.number; // eslint-disable-line id-blacklist
 | ||||
| 
 | ||||
|             form.current[n].grade = form.current[n].grade ? parseInt(String(form.current[n].grade), 10) : -1; | ||||
| 
 | ||||
|             const gradingType = parseInt(String(field.grade), 10); | ||||
|             const dimension = form.dimensionsinfo.find((dimension) => dimension.id == parseInt(field.dimensionid, 10)); | ||||
|             const scale = dimension && gradingType < 0 ? dimension.scale : undefined; | ||||
| 
 | ||||
|             promises.push(CoreGradesHelper.makeGradesMenu(gradingType, undefined, defaultGrade, -1, scale).then((grades) => { | ||||
|                 field.grades = grades; | ||||
|                 originalValues[n].grade = form.current[n].grade; | ||||
| 
 | ||||
|                 return; | ||||
|             })); | ||||
|         }); | ||||
| 
 | ||||
|         await Promise.all(promises); | ||||
| 
 | ||||
|         return originalValues; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * @inheritdoc | ||||
|      */ | ||||
|     hasDataChanged( | ||||
|         originalValues: AddonModWorkshopGetAssessmentFormFieldsParsedData[], | ||||
|         currentValues: AddonModWorkshopGetAssessmentFormFieldsParsedData[], | ||||
|     ): boolean { | ||||
|         for (const x in originalValues) { | ||||
|             if (originalValues[x].grade != currentValues[x].grade) { | ||||
|                 return true; | ||||
|             } | ||||
|             if (originalValues[x].peercomment != currentValues[x].peercomment) { | ||||
|                 return true; | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         return false; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * @inheritdoc | ||||
|      */ | ||||
|     async prepareAssessmentData( | ||||
|         currentValues: AddonModWorkshopGetAssessmentFormFieldsParsedData[], | ||||
|         form: AddonModWorkshopGetAssessmentFormDefinitionData, | ||||
|     ): Promise<CoreFormFields> { | ||||
|         const data: CoreFormFields = {}; | ||||
|         const errors: AddonModWorkshopAssessmentStrategyFieldErrors = {}; | ||||
|         let hasErrors = false; | ||||
| 
 | ||||
|         form.fields.forEach((field, idx) => { | ||||
|             if (idx < form.dimenssionscount) { | ||||
|                 const grade = parseInt(String(currentValues[idx].grade), 10); | ||||
|                 if (!isNaN(grade) && grade >= 0) { | ||||
|                     data['grade__idx_' + idx] = grade; | ||||
|                 } else { | ||||
|                     errors['grade_' + idx] = Translate.instant('addon.mod_workshop_assessment_accumulative.mustchoosegrade'); | ||||
|                     hasErrors = true; | ||||
|                 } | ||||
| 
 | ||||
|                 data['peercomment__idx_' + idx] = currentValues[idx].peercomment ?? ''; | ||||
| 
 | ||||
|                 data['gradeid__idx_' + idx] = parseInt(form.current[idx].gradeid, 10) || 0; | ||||
|                 data['dimensionid__idx_' + idx] = parseInt(field.dimensionid, 10); | ||||
|                 data['weight__idx_' + idx] = parseInt(field.weight, 10) || 0; | ||||
|             } | ||||
|         }); | ||||
| 
 | ||||
|         if (hasErrors) { | ||||
|             throw errors; | ||||
|         } | ||||
| 
 | ||||
|         return data; | ||||
|     } | ||||
|     name = ADDON_MOD_WORKSHOP_ASSESSMENT_STRATEGY_ACCUMULATIVE_NAME; | ||||
|     strategyName = ADDON_MOD_WORKSHOP_ASSESSMENT_STRATEGY_ACCUMULATIVE_STRATEGY_NAME; | ||||
| 
 | ||||
| } | ||||
| export const AddonModWorkshopAssessmentStrategyAccumulativeHandler = | ||||
|     makeSingleton(AddonModWorkshopAssessmentStrategyAccumulativeHandlerService); | ||||
| 
 | ||||
| /** | ||||
|  * Get assessment strategy handler instance. | ||||
|  * | ||||
|  * @returns Assessment strategy handler. | ||||
|  */ | ||||
| export function getAssessmentStrategyHandlerInstance(): AddonWorkshopAssessmentStrategyHandler { | ||||
|     const lazyHandler = asyncInstance(async () => { | ||||
|         const { AddonModWorkshopAssessmentStrategyAccumulativeHandler } = await import('./handler-lazy'); | ||||
| 
 | ||||
|         return AddonModWorkshopAssessmentStrategyAccumulativeHandler.instance; | ||||
|     }); | ||||
| 
 | ||||
|     lazyHandler.setEagerInstance(new AddonModWorkshopAssessmentStrategyAccumulativeHandlerService()); | ||||
| 
 | ||||
|     return lazyHandler; | ||||
| } | ||||
|  | ||||
| @ -0,0 +1,39 @@ | ||||
| // (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 { AddonModWorkshopAssessmentStrategyCommentsComponent } from './comments/component/comments'; | ||||
| import { AddonModWorkshopAssessmentStrategyAccumulativeComponent } from './accumulative/component/accumulative'; | ||||
| import { AddonModWorkshopAssessmentStrategyNumErrorsComponent } from './numerrors/component/numerrors'; | ||||
| import { AddonModWorkshopAssessmentStrategyRubricComponent } from './rubric/component/rubric'; | ||||
| import { NgModule } from '@angular/core'; | ||||
| import { CoreSharedModule } from '@/core/shared.module'; | ||||
| 
 | ||||
| @NgModule({ | ||||
|     imports: [ | ||||
|         CoreSharedModule, | ||||
|     ], | ||||
|     declarations: [ | ||||
|         AddonModWorkshopAssessmentStrategyAccumulativeComponent, | ||||
|         AddonModWorkshopAssessmentStrategyCommentsComponent, | ||||
|         AddonModWorkshopAssessmentStrategyNumErrorsComponent, | ||||
|         AddonModWorkshopAssessmentStrategyRubricComponent, | ||||
|     ], | ||||
|     exports: [ | ||||
|         AddonModWorkshopAssessmentStrategyAccumulativeComponent, | ||||
|         AddonModWorkshopAssessmentStrategyCommentsComponent, | ||||
|         AddonModWorkshopAssessmentStrategyNumErrorsComponent, | ||||
|         AddonModWorkshopAssessmentStrategyRubricComponent, | ||||
|     ], | ||||
| }) | ||||
| export class AddonModWorkshopAssessmentComponentsModule {} | ||||
| @ -15,13 +15,9 @@ | ||||
| import { CoreSharedModule } from '@/core/shared.module'; | ||||
| import { APP_INITIALIZER, NgModule } from '@angular/core'; | ||||
| import { AddonWorkshopAssessmentStrategyDelegate } from '../../services/assessment-strategy-delegate'; | ||||
| import { AddonModWorkshopAssessmentStrategyCommentsComponent } from './component/comments'; | ||||
| import { AddonModWorkshopAssessmentStrategyCommentsHandler } from './services/handler'; | ||||
| import { getAssessmentStrategyHandlerInstance } from './services/handler'; | ||||
| 
 | ||||
| @NgModule({ | ||||
|     declarations: [ | ||||
|         AddonModWorkshopAssessmentStrategyCommentsComponent, | ||||
|     ], | ||||
|     imports: [ | ||||
|         CoreSharedModule, | ||||
|     ], | ||||
| @ -30,14 +26,9 @@ import { AddonModWorkshopAssessmentStrategyCommentsHandler } from './services/ha | ||||
|             provide: APP_INITIALIZER, | ||||
|             multi: true, | ||||
|             useValue: () => { | ||||
|                 AddonWorkshopAssessmentStrategyDelegate.registerHandler( | ||||
|                     AddonModWorkshopAssessmentStrategyCommentsHandler.instance, | ||||
|                 ); | ||||
|                 AddonWorkshopAssessmentStrategyDelegate.registerHandler(getAssessmentStrategyHandlerInstance()); | ||||
|             }, | ||||
|         }, | ||||
|     ], | ||||
|     exports: [ | ||||
|         AddonModWorkshopAssessmentStrategyCommentsComponent, | ||||
|     ], | ||||
| }) | ||||
| export class AddonModWorkshopAssessmentStrategyCommentsModule {} | ||||
|  | ||||
| @ -0,0 +1,124 @@ | ||||
| // (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 { | ||||
|     AddonModWorkshopAssessmentStrategyFieldErrors, | ||||
| } from '@addons/mod/workshop/components/assessment-strategy/assessment-strategy'; | ||||
| import { AddonWorkshopAssessmentStrategyHandler } from '@addons/mod/workshop/services/assessment-strategy-delegate'; | ||||
| import { | ||||
|     AddonModWorkshopGetAssessmentFormDefinitionData, | ||||
|     AddonModWorkshopGetAssessmentFormFieldsParsedData, | ||||
| } from '@addons/mod/workshop/services/workshop'; | ||||
| import { Injectable, Type } from '@angular/core'; | ||||
| import { makeSingleton, Translate } from '@singletons'; | ||||
| import { CoreFormFields } from '@singletons/form'; | ||||
| import { AddonModWorkshopAssessmentStrategyCommentsComponent } from '../component/comments'; | ||||
| import { AddonModWorkshopAssessmentStrategyCommentsHandlerService } from './handler'; | ||||
| 
 | ||||
| /** | ||||
|  * Handler for comments assessment strategy plugin. | ||||
|  */ | ||||
| @Injectable({ providedIn: 'root' }) | ||||
| export class AddonModWorkshopAssessmentStrategyCommentsHandlerLazyService | ||||
|     extends AddonModWorkshopAssessmentStrategyCommentsHandlerService | ||||
|     implements AddonWorkshopAssessmentStrategyHandler { | ||||
| 
 | ||||
|     /** | ||||
|      * @inheritdoc | ||||
|      */ | ||||
|     async isEnabled(): Promise<boolean> { | ||||
|         return true; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * @inheritdoc | ||||
|      */ | ||||
|     getComponent(): Type<unknown> { | ||||
|         return AddonModWorkshopAssessmentStrategyCommentsComponent; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * @inheritdoc | ||||
|      */ | ||||
|     async getOriginalValues( | ||||
|         form: AddonModWorkshopGetAssessmentFormDefinitionData, | ||||
|     ): Promise<AddonModWorkshopGetAssessmentFormFieldsParsedData[]> { | ||||
|         const originalValues: AddonModWorkshopGetAssessmentFormFieldsParsedData[] = []; | ||||
| 
 | ||||
|         form.fields.forEach((field, n) => { | ||||
|             field.dimtitle = Translate.instant('addon.mod_workshop_assessment_comments.dimensionnumber', { $a: field.number }); | ||||
| 
 | ||||
|             if (!form.current[n]) { | ||||
|                 form.current[n] = {}; | ||||
|             } | ||||
| 
 | ||||
|             originalValues[n] = {}; | ||||
|             originalValues[n].peercomment = form.current[n].peercomment || ''; | ||||
|             originalValues[n].number = field.number; // eslint-disable-line id-blacklist
 | ||||
|         }); | ||||
| 
 | ||||
|         return originalValues; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * @inheritdoc | ||||
|      */ | ||||
|     hasDataChanged( | ||||
|         originalValues: AddonModWorkshopGetAssessmentFormFieldsParsedData[], | ||||
|         currentValues: AddonModWorkshopGetAssessmentFormFieldsParsedData[], | ||||
|     ): boolean { | ||||
|         for (const x in originalValues) { | ||||
|             if (originalValues[x].peercomment != currentValues[x].peercomment) { | ||||
|                 return true; | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         return false; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * @inheritdoc | ||||
|      */ | ||||
|     async prepareAssessmentData( | ||||
|         currentValues: AddonModWorkshopGetAssessmentFormFieldsParsedData[], | ||||
|         form: AddonModWorkshopGetAssessmentFormDefinitionData, | ||||
|     ): Promise<CoreFormFields> { | ||||
|         const data: CoreFormFields = {}; | ||||
|         const errors: AddonModWorkshopAssessmentStrategyFieldErrors = {}; | ||||
|         let hasErrors = false; | ||||
| 
 | ||||
|         form.fields.forEach((field, idx) => { | ||||
|             if (idx < form.dimenssionscount) { | ||||
|                 if (currentValues[idx].peercomment) { | ||||
|                     data['peercomment__idx_' + idx] = currentValues[idx].peercomment; | ||||
|                 } else { | ||||
|                     errors['peercomment_' + idx] = Translate.instant('core.err_required'); | ||||
|                     hasErrors = true; | ||||
|                 } | ||||
| 
 | ||||
|                 data['gradeid__idx_' + idx] = parseInt(form.current[idx].gradeid, 10) || 0; | ||||
|                 data['dimensionid__idx_' + idx] = parseInt(field.dimensionid, 10); | ||||
|             } | ||||
|         }); | ||||
| 
 | ||||
|         if (hasErrors) { | ||||
|             throw errors; | ||||
|         } | ||||
| 
 | ||||
|         return data; | ||||
|     } | ||||
| 
 | ||||
| } | ||||
| export const AddonModWorkshopAssessmentStrategyCommentsHandler = | ||||
|     makeSingleton(AddonModWorkshopAssessmentStrategyCommentsHandlerLazyService); | ||||
| @ -12,113 +12,33 @@ | ||||
| // See the License for the specific language governing permissions and
 | ||||
| // limitations under the License.
 | ||||
| 
 | ||||
| import { | ||||
|     AddonModWorkshopAssessmentStrategyFieldErrors, | ||||
| } from '@addons/mod/workshop/components/assessment-strategy/assessment-strategy'; | ||||
| import { asyncInstance } from '@/core/utils/async-instance'; | ||||
| import { AddonWorkshopAssessmentStrategyHandler } from '@addons/mod/workshop/services/assessment-strategy-delegate'; | ||||
| import { | ||||
|     AddonModWorkshopGetAssessmentFormDefinitionData, | ||||
|     AddonModWorkshopGetAssessmentFormFieldsParsedData, | ||||
| } from '@addons/mod/workshop/services/workshop'; | ||||
| import { Injectable, Type } from '@angular/core'; | ||||
| import { makeSingleton, Translate } from '@singletons'; | ||||
| import { CoreFormFields } from '@singletons/form'; | ||||
| import { AddonModWorkshopAssessmentStrategyCommentsComponent } from '../component/comments'; | ||||
|     ADDON_MOD_WORKSHOP_ASSESSMENT_STRATEGY_COMMENTS_NAME, | ||||
|     ADDON_MOD_WORKSHOP_ASSESSMENT_STRATEGY_COMMENTS_STRATEGY_NAME, | ||||
| } from '@addons/mod/workshop/assessment/constants'; | ||||
| 
 | ||||
| /** | ||||
|  * Handler for comments assessment strategy plugin. | ||||
|  */ | ||||
| @Injectable({ providedIn: 'root' }) | ||||
| export class AddonModWorkshopAssessmentStrategyCommentsHandlerService implements AddonWorkshopAssessmentStrategyHandler { | ||||
| export class AddonModWorkshopAssessmentStrategyCommentsHandlerService { | ||||
| 
 | ||||
|     name = 'AddonModWorkshopAssessmentStrategyComments'; | ||||
|     strategyName = 'comments'; | ||||
| 
 | ||||
|     /** | ||||
|      * @inheritdoc | ||||
|      */ | ||||
|     async isEnabled(): Promise<boolean> { | ||||
|         return true; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * @inheritdoc | ||||
|      */ | ||||
|     getComponent(): Type<unknown> { | ||||
|         return AddonModWorkshopAssessmentStrategyCommentsComponent; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * @inheritdoc | ||||
|      */ | ||||
|     async getOriginalValues( | ||||
|         form: AddonModWorkshopGetAssessmentFormDefinitionData, | ||||
|     ): Promise<AddonModWorkshopGetAssessmentFormFieldsParsedData[]> { | ||||
|         const originalValues: AddonModWorkshopGetAssessmentFormFieldsParsedData[] = []; | ||||
| 
 | ||||
|         form.fields.forEach((field, n) => { | ||||
|             field.dimtitle = Translate.instant('addon.mod_workshop_assessment_comments.dimensionnumber', { $a: field.number }); | ||||
| 
 | ||||
|             if (!form.current[n]) { | ||||
|                 form.current[n] = {}; | ||||
|             } | ||||
| 
 | ||||
|             originalValues[n] = {}; | ||||
|             originalValues[n].peercomment = form.current[n].peercomment || ''; | ||||
|             originalValues[n].number = field.number; // eslint-disable-line id-blacklist
 | ||||
|         }); | ||||
| 
 | ||||
|         return originalValues; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * @inheritdoc | ||||
|      */ | ||||
|     hasDataChanged( | ||||
|         originalValues: AddonModWorkshopGetAssessmentFormFieldsParsedData[], | ||||
|         currentValues: AddonModWorkshopGetAssessmentFormFieldsParsedData[], | ||||
|     ): boolean { | ||||
|         for (const x in originalValues) { | ||||
|             if (originalValues[x].peercomment != currentValues[x].peercomment) { | ||||
|                 return true; | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         return false; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * @inheritdoc | ||||
|      */ | ||||
|     async prepareAssessmentData( | ||||
|         currentValues: AddonModWorkshopGetAssessmentFormFieldsParsedData[], | ||||
|         form: AddonModWorkshopGetAssessmentFormDefinitionData, | ||||
|     ): Promise<CoreFormFields> { | ||||
|         const data: CoreFormFields = {}; | ||||
|         const errors: AddonModWorkshopAssessmentStrategyFieldErrors = {}; | ||||
|         let hasErrors = false; | ||||
| 
 | ||||
|         form.fields.forEach((field, idx) => { | ||||
|             if (idx < form.dimenssionscount) { | ||||
|                 if (currentValues[idx].peercomment) { | ||||
|                     data['peercomment__idx_' + idx] = currentValues[idx].peercomment; | ||||
|                 } else { | ||||
|                     errors['peercomment_' + idx] = Translate.instant('core.err_required'); | ||||
|                     hasErrors = true; | ||||
|                 } | ||||
| 
 | ||||
|                 data['gradeid__idx_' + idx] = parseInt(form.current[idx].gradeid, 10) || 0; | ||||
|                 data['dimensionid__idx_' + idx] = parseInt(field.dimensionid, 10); | ||||
|             } | ||||
|         }); | ||||
| 
 | ||||
|         if (hasErrors) { | ||||
|             throw errors; | ||||
|         } | ||||
| 
 | ||||
|         return data; | ||||
|     } | ||||
|     name = ADDON_MOD_WORKSHOP_ASSESSMENT_STRATEGY_COMMENTS_NAME; | ||||
|     strategyName = ADDON_MOD_WORKSHOP_ASSESSMENT_STRATEGY_COMMENTS_STRATEGY_NAME; | ||||
| 
 | ||||
| } | ||||
| export const AddonModWorkshopAssessmentStrategyCommentsHandler = | ||||
|     makeSingleton(AddonModWorkshopAssessmentStrategyCommentsHandlerService); | ||||
| 
 | ||||
| /** | ||||
|  * Get assessment strategy handler instance. | ||||
|  * | ||||
|  * @returns Assessment strategy handler. | ||||
|  */ | ||||
| export function getAssessmentStrategyHandlerInstance(): AddonWorkshopAssessmentStrategyHandler { | ||||
|     const lazyHandler = asyncInstance(async () => { | ||||
|         const { AddonModWorkshopAssessmentStrategyCommentsHandler } = await import('./handler-lazy'); | ||||
| 
 | ||||
|         return AddonModWorkshopAssessmentStrategyCommentsHandler.instance; | ||||
|     }); | ||||
| 
 | ||||
|     lazyHandler.setEagerInstance(new AddonModWorkshopAssessmentStrategyCommentsHandlerService()); | ||||
| 
 | ||||
|     return lazyHandler; | ||||
| } | ||||
|  | ||||
							
								
								
									
										25
									
								
								src/addons/mod/workshop/assessment/constants.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								src/addons/mod/workshop/assessment/constants.ts
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,25 @@ | ||||
| // (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.
 | ||||
| 
 | ||||
| export const ADDON_MOD_WORKSHOP_ASSESSMENT_STRATEGY_ACCUMULATIVE_NAME = 'AddonModWorkshopAssessmentStrategyAccumulative'; | ||||
| export const ADDON_MOD_WORKSHOP_ASSESSMENT_STRATEGY_ACCUMULATIVE_STRATEGY_NAME = 'accumulative'; | ||||
| 
 | ||||
| export const ADDON_MOD_WORKSHOP_ASSESSMENT_STRATEGY_COMMENTS_NAME = 'AddonModWorkshopAssessmentStrategyComments'; | ||||
| export const ADDON_MOD_WORKSHOP_ASSESSMENT_STRATEGY_COMMENTS_STRATEGY_NAME = 'comments'; | ||||
| 
 | ||||
| export const ADDON_MOD_WORKSHOP_ASSESSMENT_STRATEGY_NUMERRORS_NAME = 'AddonModWorkshopAssessmentStrategyNumErrors'; | ||||
| export const ADDON_MOD_WORKSHOP_ASSESSMENT_STRATEGY_NUMERRORS_STRATEGY_NAME = 'numerrors'; | ||||
| 
 | ||||
| export const ADDON_MOD_WORKSHOP_ASSESSMENT_STRATEGY_RUBRIC_NAME = 'AddonModWorkshopAssessmentStrategyRubric'; | ||||
| export const ADDON_MOD_WORKSHOP_ASSESSMENT_STRATEGY_RUBRIC_STRATEGY_NAME = 'rubric'; | ||||
| @ -15,13 +15,9 @@ | ||||
| import { CoreSharedModule } from '@/core/shared.module'; | ||||
| import { APP_INITIALIZER, NgModule } from '@angular/core'; | ||||
| import { AddonWorkshopAssessmentStrategyDelegate } from '../../services/assessment-strategy-delegate'; | ||||
| import { AddonModWorkshopAssessmentStrategyNumErrorsComponent } from './component/numerrors'; | ||||
| import { AddonModWorkshopAssessmentStrategyNumErrorsHandler } from './services/handler'; | ||||
| import { getAssessmentStrategyHandlerInstance } from './services/handler'; | ||||
| 
 | ||||
| @NgModule({ | ||||
|     declarations: [ | ||||
|         AddonModWorkshopAssessmentStrategyNumErrorsComponent, | ||||
|     ], | ||||
|     imports: [ | ||||
|         CoreSharedModule, | ||||
|     ], | ||||
| @ -30,14 +26,9 @@ import { AddonModWorkshopAssessmentStrategyNumErrorsHandler } from './services/h | ||||
|             provide: APP_INITIALIZER, | ||||
|             multi: true, | ||||
|             useValue: () => { | ||||
|                 AddonWorkshopAssessmentStrategyDelegate.registerHandler( | ||||
|                     AddonModWorkshopAssessmentStrategyNumErrorsHandler.instance, | ||||
|                 ); | ||||
|                 AddonWorkshopAssessmentStrategyDelegate.registerHandler(getAssessmentStrategyHandlerInstance()); | ||||
|             }, | ||||
|         }, | ||||
|     ], | ||||
|     exports: [ | ||||
|         AddonModWorkshopAssessmentStrategyNumErrorsComponent, | ||||
|     ], | ||||
| }) | ||||
| export class AddonModWorkshopAssessmentStrategyNumErrorsModule {} | ||||
|  | ||||
| @ -0,0 +1,132 @@ | ||||
| // (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 { | ||||
|     AddonModWorkshopAssessmentStrategyFieldErrors, | ||||
| } from '@addons/mod/workshop/components/assessment-strategy/assessment-strategy'; | ||||
| import { AddonWorkshopAssessmentStrategyHandler } from '@addons/mod/workshop/services/assessment-strategy-delegate'; | ||||
| import { | ||||
|     AddonModWorkshopGetAssessmentFormDefinitionData, | ||||
|     AddonModWorkshopGetAssessmentFormFieldsParsedData, | ||||
| } from '@addons/mod/workshop/services/workshop'; | ||||
| import { Injectable, Type } from '@angular/core'; | ||||
| import { Translate, makeSingleton } from '@singletons'; | ||||
| import { CoreFormFields } from '@singletons/form'; | ||||
| import { AddonModWorkshopAssessmentStrategyNumErrorsComponent } from '../component/numerrors'; | ||||
| import { AddonModWorkshopAssessmentStrategyNumErrorsHandlerService } from './handler'; | ||||
| 
 | ||||
| /** | ||||
|  * Handler for numerrors assessment strategy plugin. | ||||
|  */ | ||||
| @Injectable({ providedIn: 'root' }) | ||||
| export class AddonModWorkshopAssessmentStrategyNumErrorsHandlerLazyService | ||||
|     extends AddonModWorkshopAssessmentStrategyNumErrorsHandlerService | ||||
|     implements AddonWorkshopAssessmentStrategyHandler { | ||||
| 
 | ||||
|     /** | ||||
|      * @inheritdoc | ||||
|      */ | ||||
|     async isEnabled(): Promise<boolean> { | ||||
|         return true; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * @inheritdoc | ||||
|      */ | ||||
|     getComponent(): Type<unknown> { | ||||
|         return AddonModWorkshopAssessmentStrategyNumErrorsComponent; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * @inheritdoc | ||||
|      */ | ||||
|     async getOriginalValues( | ||||
|         form: AddonModWorkshopGetAssessmentFormDefinitionData, | ||||
|     ): Promise<AddonModWorkshopGetAssessmentFormFieldsParsedData[]> { | ||||
|         const originalValues: AddonModWorkshopGetAssessmentFormFieldsParsedData[] = []; | ||||
| 
 | ||||
|         form.fields.forEach((field, n) => { | ||||
|             field.dimtitle = Translate.instant('addon.mod_workshop_assessment_numerrors.dimensionnumber', { $a: field.number }); | ||||
| 
 | ||||
|             if (!form.current[n]) { | ||||
|                 form.current[n] = {}; | ||||
|             } | ||||
| 
 | ||||
|             originalValues[n] = {}; | ||||
|             originalValues[n].peercomment = form.current[n].peercomment || ''; | ||||
|             originalValues[n].number = field.number; // eslint-disable-line id-blacklist
 | ||||
|             originalValues[n].grade = form.current[n].grade || ''; | ||||
|         }); | ||||
| 
 | ||||
|         return originalValues; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * @inheritdoc | ||||
|      */ | ||||
|     hasDataChanged( | ||||
|         originalValues: AddonModWorkshopGetAssessmentFormFieldsParsedData[], | ||||
|         currentValues: AddonModWorkshopGetAssessmentFormFieldsParsedData[], | ||||
|     ): boolean { | ||||
|         for (const x in originalValues) { | ||||
|             if (originalValues[x].grade != currentValues[x].grade) { | ||||
|                 return true; | ||||
|             } | ||||
|             if (originalValues[x].peercomment != currentValues[x].peercomment) { | ||||
|                 return true; | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         return false; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * @inheritdoc | ||||
|      */ | ||||
|     async prepareAssessmentData( | ||||
|         currentValues: AddonModWorkshopGetAssessmentFormFieldsParsedData[], | ||||
|         form: AddonModWorkshopGetAssessmentFormDefinitionData, | ||||
|     ): Promise<CoreFormFields> { | ||||
|         const data: CoreFormFields = {}; | ||||
|         const errors: AddonModWorkshopAssessmentStrategyFieldErrors = {}; | ||||
|         let hasErrors = false; | ||||
| 
 | ||||
|         form.fields.forEach((field, idx) => { | ||||
|             if (idx < form.dimenssionscount) { | ||||
|                 const grade = parseInt(String(currentValues[idx].grade), 10); | ||||
|                 if (!isNaN(grade) && (grade == 1 || grade == -1)) { | ||||
|                     data['grade__idx_' + idx] = grade; | ||||
|                 } else { | ||||
|                     errors['grade_' + idx] = Translate.instant('core.required'); | ||||
|                     hasErrors = true; | ||||
|                 } | ||||
| 
 | ||||
|                 data['peercomment__idx_' + idx] = currentValues[idx].peercomment ?? ''; | ||||
| 
 | ||||
|                 data['gradeid__idx_' + idx] = parseInt(form.current[idx].gradeid, 10) || 0; | ||||
|                 data['dimensionid__idx_' + idx] = parseInt(field.dimensionid, 10); | ||||
|                 data['weight__idx_' + idx] = parseInt(field.weight, 10) || 0; | ||||
|             } | ||||
|         }); | ||||
| 
 | ||||
|         if (hasErrors) { | ||||
|             throw errors; | ||||
|         } | ||||
| 
 | ||||
|         return data; | ||||
|     } | ||||
| 
 | ||||
| } | ||||
| export const AddonModWorkshopAssessmentStrategyNumErrorsHandler = | ||||
|     makeSingleton(AddonModWorkshopAssessmentStrategyNumErrorsHandlerLazyService); | ||||
| @ -12,121 +12,33 @@ | ||||
| // See the License for the specific language governing permissions and
 | ||||
| // limitations under the License.
 | ||||
| 
 | ||||
| import { | ||||
|     AddonModWorkshopAssessmentStrategyFieldErrors, | ||||
| } from '@addons/mod/workshop/components/assessment-strategy/assessment-strategy'; | ||||
| import { asyncInstance } from '@/core/utils/async-instance'; | ||||
| import { AddonWorkshopAssessmentStrategyHandler } from '@addons/mod/workshop/services/assessment-strategy-delegate'; | ||||
| import { | ||||
|     AddonModWorkshopGetAssessmentFormDefinitionData, | ||||
|     AddonModWorkshopGetAssessmentFormFieldsParsedData, | ||||
| } from '@addons/mod/workshop/services/workshop'; | ||||
| import { Injectable, Type } from '@angular/core'; | ||||
| import { Translate, makeSingleton } from '@singletons'; | ||||
| import { CoreFormFields } from '@singletons/form'; | ||||
| import { AddonModWorkshopAssessmentStrategyNumErrorsComponent } from '../component/numerrors'; | ||||
|     ADDON_MOD_WORKSHOP_ASSESSMENT_STRATEGY_NUMERRORS_NAME, | ||||
|     ADDON_MOD_WORKSHOP_ASSESSMENT_STRATEGY_NUMERRORS_STRATEGY_NAME, | ||||
| } from '@addons/mod/workshop/assessment/constants'; | ||||
| 
 | ||||
| /** | ||||
|  * Handler for numerrors assessment strategy plugin. | ||||
|  */ | ||||
| @Injectable({ providedIn: 'root' }) | ||||
| export class AddonModWorkshopAssessmentStrategyNumErrorsHandlerService implements AddonWorkshopAssessmentStrategyHandler { | ||||
| export class AddonModWorkshopAssessmentStrategyNumErrorsHandlerService { | ||||
| 
 | ||||
|     name = 'AddonModWorkshopAssessmentStrategyNumErrors'; | ||||
|     strategyName = 'numerrors'; | ||||
| 
 | ||||
|     /** | ||||
|      * @inheritdoc | ||||
|      */ | ||||
|     async isEnabled(): Promise<boolean> { | ||||
|         return true; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * @inheritdoc | ||||
|      */ | ||||
|     getComponent(): Type<unknown> { | ||||
|         return AddonModWorkshopAssessmentStrategyNumErrorsComponent; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * @inheritdoc | ||||
|      */ | ||||
|     async getOriginalValues( | ||||
|         form: AddonModWorkshopGetAssessmentFormDefinitionData, | ||||
|     ): Promise<AddonModWorkshopGetAssessmentFormFieldsParsedData[]> { | ||||
|         const originalValues: AddonModWorkshopGetAssessmentFormFieldsParsedData[] = []; | ||||
| 
 | ||||
|         form.fields.forEach((field, n) => { | ||||
|             field.dimtitle = Translate.instant('addon.mod_workshop_assessment_numerrors.dimensionnumber', { $a: field.number }); | ||||
| 
 | ||||
|             if (!form.current[n]) { | ||||
|                 form.current[n] = {}; | ||||
|             } | ||||
| 
 | ||||
|             originalValues[n] = {}; | ||||
|             originalValues[n].peercomment = form.current[n].peercomment || ''; | ||||
|             originalValues[n].number = field.number; // eslint-disable-line id-blacklist
 | ||||
|             originalValues[n].grade = form.current[n].grade || ''; | ||||
|         }); | ||||
| 
 | ||||
|         return originalValues; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * @inheritdoc | ||||
|      */ | ||||
|     hasDataChanged( | ||||
|         originalValues: AddonModWorkshopGetAssessmentFormFieldsParsedData[], | ||||
|         currentValues: AddonModWorkshopGetAssessmentFormFieldsParsedData[], | ||||
|     ): boolean { | ||||
|         for (const x in originalValues) { | ||||
|             if (originalValues[x].grade != currentValues[x].grade) { | ||||
|                 return true; | ||||
|             } | ||||
|             if (originalValues[x].peercomment != currentValues[x].peercomment) { | ||||
|                 return true; | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         return false; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * @inheritdoc | ||||
|      */ | ||||
|     async prepareAssessmentData( | ||||
|         currentValues: AddonModWorkshopGetAssessmentFormFieldsParsedData[], | ||||
|         form: AddonModWorkshopGetAssessmentFormDefinitionData, | ||||
|     ): Promise<CoreFormFields> { | ||||
|         const data: CoreFormFields = {}; | ||||
|         const errors: AddonModWorkshopAssessmentStrategyFieldErrors = {}; | ||||
|         let hasErrors = false; | ||||
| 
 | ||||
|         form.fields.forEach((field, idx) => { | ||||
|             if (idx < form.dimenssionscount) { | ||||
|                 const grade = parseInt(String(currentValues[idx].grade), 10); | ||||
|                 if (!isNaN(grade) && (grade == 1 || grade == -1)) { | ||||
|                     data['grade__idx_' + idx] = grade; | ||||
|                 } else { | ||||
|                     errors['grade_' + idx] = Translate.instant('core.required'); | ||||
|                     hasErrors = true; | ||||
|                 } | ||||
| 
 | ||||
|                 data['peercomment__idx_' + idx] = currentValues[idx].peercomment ?? ''; | ||||
| 
 | ||||
|                 data['gradeid__idx_' + idx] = parseInt(form.current[idx].gradeid, 10) || 0; | ||||
|                 data['dimensionid__idx_' + idx] = parseInt(field.dimensionid, 10); | ||||
|                 data['weight__idx_' + idx] = parseInt(field.weight, 10) || 0; | ||||
|             } | ||||
|         }); | ||||
| 
 | ||||
|         if (hasErrors) { | ||||
|             throw errors; | ||||
|         } | ||||
| 
 | ||||
|         return data; | ||||
|     } | ||||
|     name = ADDON_MOD_WORKSHOP_ASSESSMENT_STRATEGY_NUMERRORS_NAME; | ||||
|     strategyName = ADDON_MOD_WORKSHOP_ASSESSMENT_STRATEGY_NUMERRORS_STRATEGY_NAME; | ||||
| 
 | ||||
| } | ||||
| export const AddonModWorkshopAssessmentStrategyNumErrorsHandler = | ||||
|     makeSingleton(AddonModWorkshopAssessmentStrategyNumErrorsHandlerService); | ||||
| 
 | ||||
| /** | ||||
|  * Get assessment strategy handler instance. | ||||
|  * | ||||
|  * @returns Assessment strategy handler. | ||||
|  */ | ||||
| export function getAssessmentStrategyHandlerInstance(): AddonWorkshopAssessmentStrategyHandler { | ||||
|     const lazyHandler = asyncInstance(async () => { | ||||
|         const { AddonModWorkshopAssessmentStrategyNumErrorsHandler } = await import('./handler-lazy'); | ||||
| 
 | ||||
|         return AddonModWorkshopAssessmentStrategyNumErrorsHandler.instance; | ||||
|     }); | ||||
| 
 | ||||
|     lazyHandler.setEagerInstance(new AddonModWorkshopAssessmentStrategyNumErrorsHandlerService()); | ||||
| 
 | ||||
|     return lazyHandler; | ||||
| } | ||||
|  | ||||
| @ -15,13 +15,9 @@ | ||||
| import { CoreSharedModule } from '@/core/shared.module'; | ||||
| import { APP_INITIALIZER, NgModule } from '@angular/core'; | ||||
| import { AddonWorkshopAssessmentStrategyDelegate } from '../../services/assessment-strategy-delegate'; | ||||
| import { AddonModWorkshopAssessmentStrategyRubricComponent } from './component/rubric'; | ||||
| import { AddonModWorkshopAssessmentStrategyRubricHandler } from './services/handler'; | ||||
| import { getAssessmentStrategyHandlerInstance } from './services/handler'; | ||||
| 
 | ||||
| @NgModule({ | ||||
|     declarations: [ | ||||
|         AddonModWorkshopAssessmentStrategyRubricComponent, | ||||
|     ], | ||||
|     imports: [ | ||||
|         CoreSharedModule, | ||||
|     ], | ||||
| @ -30,14 +26,9 @@ import { AddonModWorkshopAssessmentStrategyRubricHandler } from './services/hand | ||||
|             provide: APP_INITIALIZER, | ||||
|             multi: true, | ||||
|             useValue: () => { | ||||
|                 AddonWorkshopAssessmentStrategyDelegate.registerHandler( | ||||
|                     AddonModWorkshopAssessmentStrategyRubricHandler.instance, | ||||
|                 ); | ||||
|                 AddonWorkshopAssessmentStrategyDelegate.registerHandler(getAssessmentStrategyHandlerInstance()); | ||||
|             }, | ||||
|         }, | ||||
|     ], | ||||
|     exports: [ | ||||
|         AddonModWorkshopAssessmentStrategyRubricComponent, | ||||
|     ], | ||||
| }) | ||||
| export class AddonModWorkshopAssessmentStrategyRubricModule {} | ||||
|  | ||||
| @ -0,0 +1,125 @@ | ||||
| // (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 { | ||||
|     AddonModWorkshopAssessmentStrategyFieldErrors, | ||||
| } from '@addons/mod/workshop/components/assessment-strategy/assessment-strategy'; | ||||
| import { AddonWorkshopAssessmentStrategyHandler } from '@addons/mod/workshop/services/assessment-strategy-delegate'; | ||||
| import { | ||||
|     AddonModWorkshopGetAssessmentFormDefinitionData, | ||||
|     AddonModWorkshopGetAssessmentFormFieldsParsedData, | ||||
| } from '@addons/mod/workshop/services/workshop'; | ||||
| import { Injectable, Type } from '@angular/core'; | ||||
| import { Translate, makeSingleton } from '@singletons'; | ||||
| import { CoreFormFields } from '@singletons/form'; | ||||
| import { AddonModWorkshopAssessmentStrategyRubricComponent } from '../component/rubric'; | ||||
| import { AddonModWorkshopAssessmentStrategyRubricHandlerService } from './handler'; | ||||
| 
 | ||||
| /** | ||||
|  * Handler for rubric assessment strategy plugin. | ||||
|  */ | ||||
| @Injectable({ providedIn: 'root' }) | ||||
| export class AddonModWorkshopAssessmentStrategyRubricHandlerLazyService | ||||
|     extends AddonModWorkshopAssessmentStrategyRubricHandlerService | ||||
|     implements AddonWorkshopAssessmentStrategyHandler { | ||||
| 
 | ||||
|     /** | ||||
|      * @inheritdoc | ||||
|      */ | ||||
|     async isEnabled(): Promise<boolean> { | ||||
|         return true; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * @inheritdoc | ||||
|      */ | ||||
|     getComponent(): Type<unknown> { | ||||
|         return AddonModWorkshopAssessmentStrategyRubricComponent; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * @inheritdoc | ||||
|      */ | ||||
|     async getOriginalValues( | ||||
|         form: AddonModWorkshopGetAssessmentFormDefinitionData, | ||||
|     ): Promise<AddonModWorkshopGetAssessmentFormFieldsParsedData[]> { | ||||
|         const originalValues: AddonModWorkshopGetAssessmentFormFieldsParsedData[] = []; | ||||
| 
 | ||||
|         form.fields.forEach((field, n) => { | ||||
|             field.dimtitle = Translate.instant('addon.mod_workshop_assessment_rubric.dimensionnumber', { $a: field.number }); | ||||
| 
 | ||||
|             if (!form.current[n]) { | ||||
|                 form.current[n] = {}; | ||||
|             } | ||||
| 
 | ||||
|             originalValues[n] = {}; | ||||
|             originalValues[n].chosenlevelid = form.current[n].chosenlevelid || ''; | ||||
|             originalValues[n].number = field.number; // eslint-disable-line id-blacklist
 | ||||
|         }); | ||||
| 
 | ||||
|         return originalValues; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * @inheritdoc | ||||
|      */ | ||||
|     hasDataChanged( | ||||
|         originalValues: AddonModWorkshopGetAssessmentFormFieldsParsedData[], | ||||
|         currentValues: AddonModWorkshopGetAssessmentFormFieldsParsedData[], | ||||
|     ): boolean { | ||||
|         for (const x in originalValues) { | ||||
|             if (originalValues[x].chosenlevelid != (currentValues[x].chosenlevelid || '')) { | ||||
|                 return true; | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         return false; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * @inheritdoc | ||||
|      */ | ||||
|     async prepareAssessmentData( | ||||
|         currentValues: AddonModWorkshopGetAssessmentFormFieldsParsedData[], | ||||
|         form: AddonModWorkshopGetAssessmentFormDefinitionData, | ||||
|     ): Promise<CoreFormFields> { | ||||
|         const data: CoreFormFields = {}; | ||||
|         const errors: AddonModWorkshopAssessmentStrategyFieldErrors = {}; | ||||
|         let hasErrors = false; | ||||
| 
 | ||||
|         form.fields.forEach((field, idx) => { | ||||
|             if (idx < form.dimenssionscount) { | ||||
|                 const id = parseInt(currentValues[idx].chosenlevelid, 10); | ||||
|                 if (!isNaN(id) && id >= 0) { | ||||
|                     data['chosenlevelid__idx_' + idx] = id; | ||||
|                 } else { | ||||
|                     errors['chosenlevelid_' + idx] = Translate.instant('addon.mod_workshop_assessment_rubric.mustchooseone'); | ||||
|                     hasErrors = true; | ||||
|                 } | ||||
| 
 | ||||
|                 data['gradeid__idx_' + idx] = parseInt(form.current[idx].gradeid, 10) || 0; | ||||
|                 data['dimensionid__idx_' + idx] = parseInt(field.dimensionid, 10); | ||||
|             } | ||||
|         }); | ||||
| 
 | ||||
|         if (hasErrors) { | ||||
|             throw errors; | ||||
|         } | ||||
| 
 | ||||
|         return data; | ||||
|     } | ||||
| 
 | ||||
| } | ||||
| export const AddonModWorkshopAssessmentStrategyRubricHandler = | ||||
|     makeSingleton(AddonModWorkshopAssessmentStrategyRubricHandlerLazyService); | ||||
| @ -12,114 +12,33 @@ | ||||
| // See the License for the specific language governing permissions and
 | ||||
| // limitations under the License.
 | ||||
| 
 | ||||
| import { | ||||
|     AddonModWorkshopAssessmentStrategyFieldErrors, | ||||
| } from '@addons/mod/workshop/components/assessment-strategy/assessment-strategy'; | ||||
| import { asyncInstance } from '@/core/utils/async-instance'; | ||||
| import { AddonWorkshopAssessmentStrategyHandler } from '@addons/mod/workshop/services/assessment-strategy-delegate'; | ||||
| import { | ||||
|     AddonModWorkshopGetAssessmentFormDefinitionData, | ||||
|     AddonModWorkshopGetAssessmentFormFieldsParsedData, | ||||
| } from '@addons/mod/workshop/services/workshop'; | ||||
| import { Injectable, Type } from '@angular/core'; | ||||
| import { Translate, makeSingleton } from '@singletons'; | ||||
| import { CoreFormFields } from '@singletons/form'; | ||||
| import { AddonModWorkshopAssessmentStrategyRubricComponent } from '../component/rubric'; | ||||
|     ADDON_MOD_WORKSHOP_ASSESSMENT_STRATEGY_RUBRIC_NAME, | ||||
|     ADDON_MOD_WORKSHOP_ASSESSMENT_STRATEGY_RUBRIC_STRATEGY_NAME, | ||||
| } from '@addons/mod/workshop/assessment/constants'; | ||||
| 
 | ||||
| /** | ||||
|  * Handler for rubric assessment strategy plugin. | ||||
|  */ | ||||
| @Injectable({ providedIn: 'root' }) | ||||
| export class AddonModWorkshopAssessmentStrategyRubricHandlerService implements AddonWorkshopAssessmentStrategyHandler { | ||||
| export class AddonModWorkshopAssessmentStrategyRubricHandlerService { | ||||
| 
 | ||||
|     name = 'AddonModWorkshopAssessmentStrategyRubric'; | ||||
|     strategyName = 'rubric'; | ||||
| 
 | ||||
|     /** | ||||
|      * @inheritdoc | ||||
|      */ | ||||
|     async isEnabled(): Promise<boolean> { | ||||
|         return true; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * @inheritdoc | ||||
|      */ | ||||
|     getComponent(): Type<unknown> { | ||||
|         return AddonModWorkshopAssessmentStrategyRubricComponent; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * @inheritdoc | ||||
|      */ | ||||
|     async getOriginalValues( | ||||
|         form: AddonModWorkshopGetAssessmentFormDefinitionData, | ||||
|     ): Promise<AddonModWorkshopGetAssessmentFormFieldsParsedData[]> { | ||||
|         const originalValues: AddonModWorkshopGetAssessmentFormFieldsParsedData[] = []; | ||||
| 
 | ||||
|         form.fields.forEach((field, n) => { | ||||
|             field.dimtitle = Translate.instant('addon.mod_workshop_assessment_rubric.dimensionnumber', { $a: field.number }); | ||||
| 
 | ||||
|             if (!form.current[n]) { | ||||
|                 form.current[n] = {}; | ||||
|             } | ||||
| 
 | ||||
|             originalValues[n] = {}; | ||||
|             originalValues[n].chosenlevelid = form.current[n].chosenlevelid || ''; | ||||
|             originalValues[n].number = field.number; // eslint-disable-line id-blacklist
 | ||||
|         }); | ||||
| 
 | ||||
|         return originalValues; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * @inheritdoc | ||||
|      */ | ||||
|     hasDataChanged( | ||||
|         originalValues: AddonModWorkshopGetAssessmentFormFieldsParsedData[], | ||||
|         currentValues: AddonModWorkshopGetAssessmentFormFieldsParsedData[], | ||||
|     ): boolean { | ||||
|         for (const x in originalValues) { | ||||
|             if (originalValues[x].chosenlevelid != (currentValues[x].chosenlevelid || '')) { | ||||
|                 return true; | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         return false; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * @inheritdoc | ||||
|      */ | ||||
|     async prepareAssessmentData( | ||||
|         currentValues: AddonModWorkshopGetAssessmentFormFieldsParsedData[], | ||||
|         form: AddonModWorkshopGetAssessmentFormDefinitionData, | ||||
|     ): Promise<CoreFormFields> { | ||||
|         const data: CoreFormFields = {}; | ||||
|         const errors: AddonModWorkshopAssessmentStrategyFieldErrors = {}; | ||||
|         let hasErrors = false; | ||||
| 
 | ||||
|         form.fields.forEach((field, idx) => { | ||||
|             if (idx < form.dimenssionscount) { | ||||
|                 const id = parseInt(currentValues[idx].chosenlevelid, 10); | ||||
|                 if (!isNaN(id) && id >= 0) { | ||||
|                     data['chosenlevelid__idx_' + idx] = id; | ||||
|                 } else { | ||||
|                     errors['chosenlevelid_' + idx] = Translate.instant('addon.mod_workshop_assessment_rubric.mustchooseone'); | ||||
|                     hasErrors = true; | ||||
|                 } | ||||
| 
 | ||||
|                 data['gradeid__idx_' + idx] = parseInt(form.current[idx].gradeid, 10) || 0; | ||||
|                 data['dimensionid__idx_' + idx] = parseInt(field.dimensionid, 10); | ||||
|             } | ||||
|         }); | ||||
| 
 | ||||
|         if (hasErrors) { | ||||
|             throw errors; | ||||
|         } | ||||
| 
 | ||||
|         return data; | ||||
|     } | ||||
|     name = ADDON_MOD_WORKSHOP_ASSESSMENT_STRATEGY_RUBRIC_NAME; | ||||
|     strategyName = ADDON_MOD_WORKSHOP_ASSESSMENT_STRATEGY_RUBRIC_STRATEGY_NAME; | ||||
| 
 | ||||
| } | ||||
| export const AddonModWorkshopAssessmentStrategyRubricHandler = | ||||
|     makeSingleton(AddonModWorkshopAssessmentStrategyRubricHandlerService); | ||||
| 
 | ||||
| /** | ||||
|  * Get assessment strategy handler instance. | ||||
|  * | ||||
|  * @returns Assessment strategy handler. | ||||
|  */ | ||||
| export function getAssessmentStrategyHandlerInstance(): AddonWorkshopAssessmentStrategyHandler { | ||||
|     const lazyHandler = asyncInstance(async () => { | ||||
|         const { AddonModWorkshopAssessmentStrategyRubricHandler } = await import('./handler-lazy'); | ||||
| 
 | ||||
|         return AddonModWorkshopAssessmentStrategyRubricHandler.instance; | ||||
|     }); | ||||
| 
 | ||||
|     lazyHandler.setEagerInstance(new AddonModWorkshopAssessmentStrategyRubricHandlerService()); | ||||
| 
 | ||||
|     return lazyHandler; | ||||
| } | ||||
|  | ||||
| @ -111,7 +111,7 @@ export class AddonModWorkshopAssessmentStrategyComponent implements OnInit, OnDe | ||||
|         this.data.moduleId = this.workshop.coursemodule; | ||||
|         this.data.courseId = this.workshop.course; | ||||
| 
 | ||||
|         this.componentClass = AddonWorkshopAssessmentStrategyDelegate.getComponentForPlugin(this.strategy); | ||||
|         this.componentClass = await AddonWorkshopAssessmentStrategyDelegate.getComponentForPlugin(this.strategy); | ||||
|         if (this.componentClass) { | ||||
|             this.overallFeedkback = this.workshop.overallfeedbackmode != AddonModWorkshopOverallFeedbackMode.DISABLED; | ||||
|             this.overallFeedkbackRequired = | ||||
|  | ||||
| @ -18,6 +18,7 @@ import { AddonModWorkshopSubmissionComponent } from './submission/submission'; | ||||
| import { CoreCourseComponentsModule } from '@features/course/components/components.module'; | ||||
| import { CoreEditorComponentsModule } from '@features/editor/components/components.module'; | ||||
| import { CoreSharedModule } from '@/core/shared.module'; | ||||
| import { AddonModWorkshopAssessmentComponentsModule } from '@addons/mod/workshop/assessment/assesment-components.module'; | ||||
| import { AddonModWorkshopPhaseInfoComponent } from './phase/phase'; | ||||
| import { AddonModWorkshopAssessmentComponent } from './assessment/assessment'; | ||||
| import { AddonModWorkshopAssessmentStrategyComponent } from './assessment-strategy/assessment-strategy'; | ||||
| @ -34,6 +35,7 @@ import { AddonModWorkshopAssessmentStrategyComponent } from './assessment-strate | ||||
|         CoreSharedModule, | ||||
|         CoreCourseComponentsModule, | ||||
|         CoreEditorComponentsModule, | ||||
|         AddonModWorkshopAssessmentComponentsModule, | ||||
|     ], | ||||
|     exports: [ | ||||
|         AddonModWorkshopIndexComponent, | ||||
|  | ||||
| @ -34,7 +34,7 @@ export interface AddonWorkshopAssessmentStrategyHandler extends CoreDelegateHand | ||||
|      * @param injector Injector. | ||||
|      * @returns The component (or promise resolved with component) to use, undefined if not found. | ||||
|      */ | ||||
|     getComponent?(): Type<unknown>; | ||||
|     getComponent?(): Promise<Type<unknown>> | Type<unknown>; | ||||
| 
 | ||||
|     /** | ||||
|      * Prepare original values to be shown and compared. | ||||
| @ -58,7 +58,7 @@ export interface AddonWorkshopAssessmentStrategyHandler extends CoreDelegateHand | ||||
|     hasDataChanged?( | ||||
|         originalValues: AddonModWorkshopGetAssessmentFormFieldsParsedData[], | ||||
|         currentValues: AddonModWorkshopGetAssessmentFormFieldsParsedData[], | ||||
|     ): boolean; | ||||
|     ): Promise<boolean> | boolean; | ||||
| 
 | ||||
|     /** | ||||
|      * Prepare assessment data to be sent to the server depending on the strategy selected. | ||||
| @ -102,7 +102,7 @@ export class AddonWorkshopAssessmentStrategyDelegateService extends CoreDelegate | ||||
|      * @param workshopStrategy Assessment strategy name. | ||||
|      * @returns The component, undefined if not found. | ||||
|      */ | ||||
|     getComponentForPlugin(workshopStrategy: string): Type<unknown> | undefined { | ||||
|     getComponentForPlugin(workshopStrategy: string): Promise<Type<unknown>> | Type<unknown> | undefined { | ||||
|         return this.executeFunctionOnEnabled(workshopStrategy, 'getComponent'); | ||||
|     } | ||||
| 
 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user