forked from EVOgeek/Vmeda.Online
		
	Merge pull request #1649 from dpalou/MOBILE-2764
MOBILE-2764 assign: Improve text and separator handling in grades
This commit is contained in:
		
						commit
						21899c74f7
					
				| @ -146,10 +146,10 @@ | |||||||
|                     </a> |                     </a> | ||||||
|                 </ion-item> |                 </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-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-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> |                     <p item-content *ngIf="grade.disabled">{{ 'addon.mod_assign.gradelocked' | translate }}</p> | ||||||
|                 </ion-item> |                 </ion-item> | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -472,8 +472,7 @@ export class AddonModAssignSubmissionComponent implements OnInit, OnDestroy { | |||||||
|             applyToAll: false, |             applyToAll: false, | ||||||
|             scale: false, |             scale: false, | ||||||
|             lang: false, |             lang: false, | ||||||
|             disabled: false, |             disabled: false | ||||||
|             type: this.domUtils.numberInputSupportsComma() ? 'number' : 'text' |  | ||||||
|         }; |         }; | ||||||
| 
 | 
 | ||||||
|         this.originalGrades =  { |         this.originalGrades =  { | ||||||
| @ -586,8 +585,7 @@ export class AddonModAssignSubmissionComponent implements OnInit, OnDestroy { | |||||||
|                     if (data && (!feedback || !feedback.gradeddate || feedback.gradeddate < data.timemodified)) { |                     if (data && (!feedback || !feedback.gradeddate || feedback.gradeddate < data.timemodified)) { | ||||||
|                         // If grade has been modified from gradebook, do not use offline.
 |                         // If grade has been modified from gradebook, do not use offline.
 | ||||||
|                         if (this.grade.modified < data.timemodified) { |                         if (this.grade.modified < data.timemodified) { | ||||||
|                             this.grade.grade = !this.grade.scale && this.grade.type == 'text' ? |                             this.grade.grade = !this.grade.scale ? this.utils.formatFloat(data.grade) : data.grade; | ||||||
|                                     this.utils.formatFloat(data.grade) : data.grade; |  | ||||||
|                             this.gradingStatusTranslationId = 'addon.mod_assign.gradenotsynced'; |                             this.gradingStatusTranslationId = 'addon.mod_assign.gradenotsynced'; | ||||||
|                             this.gradingColor = ''; |                             this.gradingColor = ''; | ||||||
|                             this.originalGrades.grade = this.grade.grade; |                             this.originalGrades.grade = this.grade.grade; | ||||||
| @ -735,7 +733,7 @@ export class AddonModAssignSubmissionComponent implements OnInit, OnDestroy { | |||||||
|             const attemptNumber = this.userSubmission ? this.userSubmission.attemptnumber : -1, |             const attemptNumber = this.userSubmission ? this.userSubmission.attemptnumber : -1, | ||||||
|                 outcomes = {}, |                 outcomes = {}, | ||||||
|                 // Scale "no grade" uses -1 instead of 0.
 |                 // 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) { |             if (grade === false) { | ||||||
|                 // Grade is invalid.
 |                 // Grade is invalid.
 | ||||||
| @ -802,8 +800,8 @@ export class AddonModAssignSubmissionComponent implements OnInit, OnDestroy { | |||||||
|         if (this.gradeInfo.scale) { |         if (this.gradeInfo.scale) { | ||||||
|             this.grade.scale = this.utils.makeMenuFromList(this.gradeInfo.scale, this.translate.instant('core.nograde')); |             this.grade.scale = this.utils.makeMenuFromList(this.gradeInfo.scale, this.translate.instant('core.nograde')); | ||||||
|         } else { |         } else { | ||||||
|             // If the grade uses a text input, format it.
 |             // Format the grade.
 | ||||||
|             this.grade.grade = this.grade.type == 'text' ? this.utils.formatFloat(this.grade.grade) : this.grade.grade; |             this.grade.grade = this.utils.formatFloat(this.grade.grade); | ||||||
|             this.originalGrades.grade = this.grade.grade; |             this.originalGrades.grade = this.grade.grade; | ||||||
| 
 | 
 | ||||||
|             // Get current language to format grade input field.
 |             // Get current language to format grade input field.
 | ||||||
|  | |||||||
| @ -603,15 +603,6 @@ export class CoreDomUtilsProvider { | |||||||
|         return movedChildren; |         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. |      * Search and remove a certain element from inside another element. | ||||||
|      * |      * | ||||||
|  | |||||||
| @ -471,7 +471,7 @@ export class CoreUtilsProvider { | |||||||
|      * @return {string} Locale float. |      * @return {string} Locale float. | ||||||
|      */ |      */ | ||||||
|     formatFloat(float: any): string { |     formatFloat(float: any): string { | ||||||
|         if (typeof float == 'undefined' || float === null) { |         if (typeof float == 'undefined' || float === null || typeof float == 'boolean') { | ||||||
|             return ''; |             return ''; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
| @ -1168,9 +1168,10 @@ export class CoreUtilsProvider { | |||||||
|      * Based on Moodle's unformat_float function. |      * Based on Moodle's unformat_float function. | ||||||
|      * |      * | ||||||
|      * @param {any} localeFloat Locale aware float representation. |      * @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. |      * @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.
 |         // Bad format on input type number.
 | ||||||
|         if (typeof localeFloat == 'undefined') { |         if (typeof localeFloat == 'undefined') { | ||||||
|             return false; |             return false; | ||||||
| @ -1189,18 +1190,17 @@ export class CoreUtilsProvider { | |||||||
|             return ''; |             return ''; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         const localeSeparator = this.translate.instant('core.decsep'); |  | ||||||
| 
 |  | ||||||
|         localeFloat = localeFloat.replace(' ', ''); // No spaces - those might be used as thousand separators.
 |         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.
 |         // Bad format.
 | ||||||
|         if (isNaN(localeFloat)) { |         if (strict && (!isFinite(localeFloat) || isNaN(parsedFloat))) { | ||||||
|             return false; |             return false; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         return localeFloat; |         return parsedFloat; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user