Skip to content

Commit 40fc6a3

Browse files
committed
documented the extracted functions
1 parent 32cc118 commit 40fc6a3

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

src/main/webapp/app/shared/util/grading-scale.utils.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,13 @@ export function hasGradeLimits(
237237
return limits?.upperLimit != null && limits.upperLimit !== '' && limits.lowerLimit != null && limits.lowerLimit !== '';
238238
}
239239

240+
/**
241+
* Resolves the grading scale limits to show for a given grade.
242+
*
243+
* When persisted/manual limits are available, those take precedence and are only normalized
244+
* to the grade format (for example adding or removing `%`). Otherwise the limits are inferred
245+
* from the entered grade.
246+
*/
240247
export function resolveGradingScaleLimits(grade: string, limits?: Partial<GradingScaleLimitsData> | null): GradingScaleLimitsResult {
241248
if (grade.trim() === '') {
242249
return null;
@@ -252,6 +259,12 @@ export function resolveGradingScaleLimits(grade: string, limits?: Partial<Gradin
252259
return detectGradingScale(grade);
253260
}
254261

262+
/**
263+
* Returns the auto-detected limits as a form patch for grade-limit controls.
264+
*
265+
* This intentionally ignores any previously stored manual limits because it is used when
266+
* the grade input itself changes and the UI should reset to the newly detected defaults.
267+
*/
255268
export function getDetectedGradeLimitsPatch(grade: string): Pick<GradingScaleLimitsData, 'upperLimit' | 'lowerLimit'> {
256269
const limits = detectGradingScale(grade);
257270

@@ -261,6 +274,11 @@ export function getDetectedGradeLimitsPatch(grade: string): Pick<GradingScaleLim
261274
};
262275
}
263276

277+
/**
278+
* Builds the localized helper text that displays the currently active grading scale.
279+
*
280+
* Returns an empty string when no grading scale could be resolved for the current input.
281+
*/
264282
export function getGradeHelperText(translateService: Pick<TranslateService, 'instant'>, limits: GradingScaleLimitsResult): string {
265283
if (!limits) {
266284
return '';
@@ -275,6 +293,11 @@ export function getGradeHelperText(translateService: Pick<TranslateService, 'ins
275293
return `${scale}${gradingScale}`;
276294
}
277295

296+
/**
297+
* Builds the localized warning text for suspicious grade formats.
298+
*
299+
* Returns an empty string when the current grade format does not require a warning.
300+
*/
278301
export function getGradeWarningText(translateService: Pick<TranslateService, 'instant'>, grade: string): string {
279302
return shouldShowGradeWarning(grade) ? (translateService.instant('entity.applicationPage2.warnText') as string) : '';
280303
}

0 commit comments

Comments
 (0)