MOBILE-3003 feedback: Display range in numeric questions

main
Dani Palou 2019-05-08 14:46:50 +02:00
parent 2e8aab7695
commit a2a291f4d2
6 changed files with 41 additions and 3 deletions

View File

@ -453,6 +453,8 @@
"addon.mod_feedback.feedbackclose": "feedback",
"addon.mod_feedback.feedbackopen": "feedback",
"addon.mod_feedback.mapcourses": "feedback",
"addon.mod_feedback.maximal": "feedback",
"addon.mod_feedback.minimal": "feedback",
"addon.mod_feedback.mode": "feedback",
"addon.mod_feedback.modulenameplural": "feedback",
"addon.mod_feedback.next_page": "feedback",

View File

@ -12,6 +12,8 @@
"feedback_is_not_open": "The feedback is not open",
"feedback_submitted_offline": "This feedback has been saved to be submitted later.",
"mapcourses": "Map feedback to courses",
"maximal": "Maximum",
"minimal": "Minimum",
"mode": "Mode",
"modulenameplural": "Feedback",
"next_page": "Next page",

View File

@ -18,6 +18,7 @@
<ion-label *ngIf="item.name" [core-mark-required]="item.required" stacked>
<span *ngIf="feedback.autonumbering && item.itemnumber">{{item.itemnumber}}. </span>
<core-format-text [component]="component" [componentId]="componentId" [text]="item.name"></core-format-text>
<span *ngIf="item.postfix" class="addon-mod_feedback-postfix">{{item.postfix}}</span>
</ion-label>
<div item-content class="addon-mod_feedback-form-content" *ngIf="item.template">
<ng-container [ngSwitch]="item.template">

View File

@ -12,4 +12,7 @@ ion-app.app-root page-addon-mod-feedback-form {
.item-wp .addon-mod_feedback-form-content {
@include margin($item-wp-padding-media-top, ($item-wp-padding-end / 2), $item-wp-padding-media-bottom, 0);
}
.addon-mod_feedback-postfix {
font-size: 1.4rem;
}
}

View File

@ -22,6 +22,7 @@ import { CoreSitesProvider } from '@providers/sites';
import { CoreDomUtilsProvider } from '@providers/utils/dom';
import { CoreTextUtilsProvider } from '@providers/utils/text';
import { CoreTimeUtilsProvider } from '@providers/utils/time';
import { CoreUtilsProvider } from '@providers/utils/utils';
import { TranslateService } from '@ngx-translate/core';
/**
@ -38,7 +39,7 @@ export class AddonModFeedbackHelperProvider {
protected textUtils: CoreTextUtilsProvider, protected translate: TranslateService,
protected timeUtils: CoreTimeUtilsProvider, protected domUtils: CoreDomUtilsProvider,
protected courseProvider: CoreCourseProvider, protected linkHelper: CoreContentLinksHelperProvider,
protected sitesProvider: CoreSitesProvider) {
protected sitesProvider: CoreSitesProvider, protected utils: CoreUtilsProvider) {
}
/**
@ -346,9 +347,13 @@ export class AddonModFeedbackHelperProvider {
item.template = 'numeric';
const range = item.presentation.split(AddonModFeedbackProvider.LINE_SEP) || [];
item.rangefrom = range.length > 0 ? parseInt(range[0], 10) || '' : '';
item.rangeto = range.length > 1 ? parseInt(range[1], 10) || '' : '';
range[0] = range.length > 0 ? parseInt(range[0], 10) : undefined;
range[1] = range.length > 1 ? parseInt(range[1], 10) : undefined;
item.rangefrom = typeof range[0] == 'number' && !isNaN(range[0]) ? range[0] : '';
item.rangeto = typeof range[1] == 'number' && !isNaN(range[1]) ? range[1] : '';
item.value = typeof item.rawValue != 'undefined' ? parseFloat(item.rawValue) : '';
item.postfix = this.getNumericBoundariesForDisplay(item.rangefrom, item.rangeto);
return item;
}
@ -493,4 +498,27 @@ export class AddonModFeedbackHelperProvider {
return item;
}
/**
* Returns human-readable boundaries (min - max).
* Based on Moodle's get_boundaries_for_display.
*
* @param {number} rangeFrom Range from.
* @param {number} rangeTo Range to.
* @return {string} Human-readable boundaries.
*/
protected getNumericBoundariesForDisplay(rangeFrom: number, rangeTo: number): string {
const rangeFromSet = typeof rangeFrom == 'number',
rangeToSet = typeof rangeTo == 'number';
if (!rangeFromSet && rangeToSet) {
return ' (' + this.translate.instant('addon.mod_feedback.maximal') + ': ' + this.utils.formatFloat(rangeTo) + ')';
} else if (rangeFromSet && !rangeToSet) {
return ' (' + this.translate.instant('addon.mod_feedback.minimal') + ': ' + this.utils.formatFloat(rangeFrom) + ')';
} else if (!rangeFromSet && !rangeToSet) {
return '';
}
return ' (' + this.utils.formatFloat(rangeFrom) + ' - ' + this.utils.formatFloat(rangeTo) + ')';
}
}

View File

@ -453,6 +453,8 @@
"addon.mod_feedback.feedbackclose": "Allow answers to",
"addon.mod_feedback.feedbackopen": "Allow answers from",
"addon.mod_feedback.mapcourses": "Map feedback to courses",
"addon.mod_feedback.maximal": "Maximum",
"addon.mod_feedback.minimal": "Minimum",
"addon.mod_feedback.mode": "Mode",
"addon.mod_feedback.modulenameplural": "Feedback",
"addon.mod_feedback.next_page": "Next page",