MOBILE-3039 workshop: Fix assessment with scales

main
Albert Gasset 2019-06-06 15:23:35 +02:00
parent 56ec20b677
commit 037babba70
5 changed files with 16 additions and 10 deletions

View File

@ -63,8 +63,6 @@ export class AddonModWorkshopAssessmentStrategyAccumulativeHandler implements Ad
field.dimtitle = this.translate.instant( field.dimtitle = this.translate.instant(
'addon.mod_workshop_assessment_accumulative.dimensionnumber', {$a: field.number}); 'addon.mod_workshop_assessment_accumulative.dimensionnumber', {$a: field.number});
const scale = parseInt(field.grade, 10) < 0 ? form.dimensionsinfo[n].scale : null;
if (!form.current[n]) { if (!form.current[n]) {
form.current[n] = {}; form.current[n] = {};
} }
@ -76,7 +74,11 @@ export class AddonModWorkshopAssessmentStrategyAccumulativeHandler implements Ad
form.current[n].grade = form.current[n].grade ? parseInt(form.current[n].grade, 10) : -1; form.current[n].grade = form.current[n].grade ? parseInt(form.current[n].grade, 10) : -1;
promises.push(this.gradesHelper.makeGradesMenu(field.grade, workshopId, defaultGrade, -1, scale).then((grades) => { const gradingType = parseInt(field.grade, 10);
const dimension = form.dimensionsinfo.find((dimension) => dimension.id == field.dimensionid);
const scale = dimension && gradingType < 0 ? dimension.scale : null;
promises.push(this.gradesHelper.makeGradesMenu(gradingType, undefined, defaultGrade, -1, scale).then((grades) => {
field.grades = grades; field.grades = grades;
originalValues[n].grade = form.current[n].grade; originalValues[n].grade = form.current[n].grade;
})); }));

View File

@ -182,8 +182,8 @@ export class AddonModWorkshopAssessmentPage implements OnInit, OnDestroy {
if (accessData.canoverridegrades) { if (accessData.canoverridegrades) {
defaultGrade = this.translate.instant('addon.mod_workshop.notoverridden'); defaultGrade = this.translate.instant('addon.mod_workshop.notoverridden');
promise = this.gradesHelper.makeGradesMenu(this.workshop.gradinggrade, this.workshopId, defaultGrade, promise = this.gradesHelper.makeGradesMenu(this.workshop.gradinggrade, undefined, defaultGrade, -1)
-1).then((grades) => { .then((grades) => {
this.evaluationGrades = grades; this.evaluationGrades = grades;
}); });
} else { } else {

View File

@ -259,8 +259,7 @@ export class AddonModWorkshopSubmissionPage implements OnInit, OnDestroy {
const defaultGrade = this.translate.instant('addon.mod_workshop.notoverridden'); const defaultGrade = this.translate.instant('addon.mod_workshop.notoverridden');
promises.push(this.gradesHelper.makeGradesMenu(this.workshop.grade, this.workshopId, defaultGrade, -1) promises.push(this.gradesHelper.makeGradesMenu(this.workshop.grade, undefined, defaultGrade, -1).then((grades) => {
.then((grades) => {
this.evaluationGrades = grades; this.evaluationGrades = grades;
this.evaluate.grade = { this.evaluate.grade = {

View File

@ -467,6 +467,8 @@ export class CoreCourseProvider {
/** /**
* Gets a module basic grade info by module ID. * Gets a module basic grade info by module ID.
* *
* If the user does not have permision to manage the activity false is returned.
*
* @param {number} moduleId Module ID. * @param {number} moduleId Module ID.
* @param {string} [siteId] Site ID. If not defined, current site. * @param {string} [siteId] Site ID. If not defined, current site.
* @return {Promise<any>} Promise resolved with the module's grade info. * @return {Promise<any>} Promise resolved with the module's grade info.

View File

@ -559,18 +559,19 @@ export class CoreGradesHelperProvider {
* Taken from make_grades_menu on moodlelib.php * Taken from make_grades_menu on moodlelib.php
* *
* @param {number} gradingType If positive, max grade you can provide. If negative, scale Id. * @param {number} gradingType If positive, max grade you can provide. If negative, scale Id.
* @param {number} moduleId Module Id needed to retrieve the scale. * @param {number} [moduleId] Module ID. Used to retrieve the scale items when they are not passed as parameter.
* If the user does not have permision to manage the activity an empty list is returned.
* @param {string} [defaultLabel] Element that will become default option, if not defined, it won't be added. * @param {string} [defaultLabel] Element that will become default option, if not defined, it won't be added.
* @param {any} [defaultValue] Element that will become default option value. Default ''. * @param {any} [defaultValue] Element that will become default option value. Default ''.
* @param {string} [scale] Scale csv list String. If not provided, it will take it from the module grade info. * @param {string} [scale] Scale csv list String. If not provided, it will take it from the module grade info.
* @return {Promise<any[]>} Array with objects with value and label to create a propper HTML select. * @return {Promise<any[]>} Array with objects with value and label to create a propper HTML select.
*/ */
makeGradesMenu(gradingType: number, moduleId: number, defaultLabel: string = '', defaultValue: any = '', scale?: string): makeGradesMenu(gradingType: number, moduleId?: number, defaultLabel: string = '', defaultValue: any = '', scale?: string):
Promise<any[]> { Promise<any[]> {
if (gradingType < 0) { if (gradingType < 0) {
if (scale) { if (scale) {
return Promise.resolve(this.utils.makeMenuFromList(scale, defaultLabel, undefined, defaultValue)); return Promise.resolve(this.utils.makeMenuFromList(scale, defaultLabel, undefined, defaultValue));
} else { } else if (moduleId) {
return this.courseProvider.getModuleBasicGradeInfo(moduleId).then((gradeInfo) => { return this.courseProvider.getModuleBasicGradeInfo(moduleId).then((gradeInfo) => {
if (gradeInfo.scale) { if (gradeInfo.scale) {
return this.utils.makeMenuFromList(gradeInfo.scale, defaultLabel, undefined, defaultValue); return this.utils.makeMenuFromList(gradeInfo.scale, defaultLabel, undefined, defaultValue);
@ -578,6 +579,8 @@ export class CoreGradesHelperProvider {
return []; return [];
}); });
} else {
return Promise.resolve([]);
} }
} }