forked from EVOgeek/Vmeda.Online
		
	MOBILE-2764 assign: Improve text and separator handling in grades
This commit is contained in:
		
							parent
							
								
									8248890189
								
							
						
					
					
						commit
						971112c7d3
					
				| @ -146,10 +146,10 @@ | ||||
|                     </a> | ||||
|                 </ion-item> | ||||
| 
 | ||||
|                 <!-- Numeric grade. --> | ||||
|                 <!-- Numeric grade. Use a text input because otherwise we cannot read the value if it has an invalid character. --> | ||||
|                 <ion-item text-wrap *ngIf="grade.method == 'simple' && !grade.scale"> | ||||
|                     <ion-label stacked><h2>{{ 'addon.mod_assign.gradeoutof' | translate: {$a: gradeInfo.grade} }}</h2></ion-label> | ||||
|                     <ion-input *ngIf="!grade.disabled" [type]="grade.type" [(ngModel)]="grade.grade" min="0" [max]="gradeInfo.grade" [lang]="grade.lang"></ion-input> | ||||
|                     <ion-input *ngIf="!grade.disabled" type="text" [(ngModel)]="grade.grade" min="0" [max]="gradeInfo.grade" [lang]="grade.lang"></ion-input> | ||||
|                     <p item-content *ngIf="grade.disabled">{{ 'addon.mod_assign.gradelocked' | translate }}</p> | ||||
|                 </ion-item> | ||||
| 
 | ||||
|  | ||||
| @ -472,8 +472,7 @@ export class AddonModAssignSubmissionComponent implements OnInit, OnDestroy { | ||||
|             applyToAll: false, | ||||
|             scale: false, | ||||
|             lang: false, | ||||
|             disabled: false, | ||||
|             type: this.domUtils.numberInputSupportsComma() ? 'number' : 'text' | ||||
|             disabled: false | ||||
|         }; | ||||
| 
 | ||||
|         this.originalGrades =  { | ||||
| @ -586,8 +585,7 @@ export class AddonModAssignSubmissionComponent implements OnInit, OnDestroy { | ||||
|                     if (data && (!feedback || !feedback.gradeddate || feedback.gradeddate < data.timemodified)) { | ||||
|                         // If grade has been modified from gradebook, do not use offline.
 | ||||
|                         if (this.grade.modified < data.timemodified) { | ||||
|                             this.grade.grade = !this.grade.scale && this.grade.type == 'text' ? | ||||
|                                     this.utils.formatFloat(data.grade) : data.grade; | ||||
|                             this.grade.grade = !this.grade.scale ? this.utils.formatFloat(data.grade) : data.grade; | ||||
|                             this.gradingStatusTranslationId = 'addon.mod_assign.gradenotsynced'; | ||||
|                             this.gradingColor = ''; | ||||
|                             this.originalGrades.grade = this.grade.grade; | ||||
| @ -735,7 +733,7 @@ export class AddonModAssignSubmissionComponent implements OnInit, OnDestroy { | ||||
|             const attemptNumber = this.userSubmission ? this.userSubmission.attemptnumber : -1, | ||||
|                 outcomes = {}, | ||||
|                 // Scale "no grade" uses -1 instead of 0.
 | ||||
|                 grade = this.grade.scale && this.grade.grade == 0 ? -1 : this.utils.unformatFloat(this.grade.grade); | ||||
|                 grade = this.grade.scale && this.grade.grade == 0 ? -1 : this.utils.unformatFloat(this.grade.grade, true); | ||||
| 
 | ||||
|             if (grade === false) { | ||||
|                 // Grade is invalid.
 | ||||
| @ -802,8 +800,8 @@ export class AddonModAssignSubmissionComponent implements OnInit, OnDestroy { | ||||
|         if (this.gradeInfo.scale) { | ||||
|             this.grade.scale = this.utils.makeMenuFromList(this.gradeInfo.scale, this.translate.instant('core.nograde')); | ||||
|         } else { | ||||
|             // If the grade uses a text input, format it.
 | ||||
|             this.grade.grade = this.grade.type == 'text' ? this.utils.formatFloat(this.grade.grade) : this.grade.grade; | ||||
|             // Format the grade.
 | ||||
|             this.grade.grade = this.utils.formatFloat(this.grade.grade); | ||||
|             this.originalGrades.grade = this.grade.grade; | ||||
| 
 | ||||
|             // Get current language to format grade input field.
 | ||||
|  | ||||
| @ -603,15 +603,6 @@ export class CoreDomUtilsProvider { | ||||
|         return movedChildren; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Check whether input number supports writing comma as a decimal separator. | ||||
|      * | ||||
|      * @return {boolean} Whether input number supports writing comma as a decimal separator. | ||||
|      */ | ||||
|     numberInputSupportsComma(): boolean { | ||||
|         return !this.platform.is('android') || this.platform.version().major > 5; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Search and remove a certain element from inside another element. | ||||
|      * | ||||
|  | ||||
| @ -471,7 +471,7 @@ export class CoreUtilsProvider { | ||||
|      * @return {string} Locale float. | ||||
|      */ | ||||
|     formatFloat(float: any): string { | ||||
|         if (typeof float == 'undefined' || float === null) { | ||||
|         if (typeof float == 'undefined' || float === null || typeof float == 'boolean') { | ||||
|             return ''; | ||||
|         } | ||||
| 
 | ||||
| @ -1168,9 +1168,10 @@ export class CoreUtilsProvider { | ||||
|      * Based on Moodle's unformat_float function. | ||||
|      * | ||||
|      * @param {any} localeFloat Locale aware float representation. | ||||
|      * @param {boolean} [strict] If true, then check the input and return false if it is not a valid number. | ||||
|      * @return {any} False if bad format, empty string if empty value or the parsed float if not. | ||||
|      */ | ||||
|     unformatFloat(localeFloat: any): any { | ||||
|     unformatFloat(localeFloat: any, strict?: boolean): any { | ||||
|         // Bad format on input type number.
 | ||||
|         if (typeof localeFloat == 'undefined') { | ||||
|             return false; | ||||
| @ -1189,18 +1190,17 @@ export class CoreUtilsProvider { | ||||
|             return ''; | ||||
|         } | ||||
| 
 | ||||
|         const localeSeparator = this.translate.instant('core.decsep'); | ||||
| 
 | ||||
|         localeFloat = localeFloat.replace(' ', ''); // No spaces - those might be used as thousand separators.
 | ||||
|         localeFloat = localeFloat.replace(localeSeparator, '.'); | ||||
|         localeFloat = localeFloat.replace(this.translate.instant('core.decsep'), '.'); | ||||
| 
 | ||||
|         const parsedFloat = parseFloat(localeFloat); | ||||
| 
 | ||||
|         localeFloat = parseFloat(localeFloat); | ||||
|         // Bad format.
 | ||||
|         if (isNaN(localeFloat)) { | ||||
|         if (strict && (!isFinite(localeFloat) || isNaN(parsedFloat))) { | ||||
|             return false; | ||||
|         } | ||||
| 
 | ||||
|         return localeFloat; | ||||
|         return parsedFloat; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user