frontend: treat MCQ justification as key flag, instead of special case
This commit is contained in:
parent
2879b697c0
commit
b6769086c2
4 changed files with 126 additions and 99 deletions
|
@ -1,3 +1,32 @@
|
|||
function treatFlagKey(flag) {
|
||||
if (flag.values !== undefined) {
|
||||
if (flag.separator) {
|
||||
for (var i = flag.values.length - 1; i >= 0; i--) {
|
||||
if (!flag.values[i].length)
|
||||
flag.values.splice(i, 1);
|
||||
}
|
||||
|
||||
if (flag.ignore_order)
|
||||
flag.value = flag.values.slice().sort().join(flag.separator) + flag.separator;
|
||||
else
|
||||
flag.value = flag.values.join(flag.separator) + flag.separator;
|
||||
|
||||
if (flag.values.length == 0)
|
||||
flag.values = [""];
|
||||
}
|
||||
else
|
||||
flag.value = flag.values[0];
|
||||
}
|
||||
|
||||
if (flag.found == null && flag.soluce !== undefined) {
|
||||
if (check === undefined) check = true;
|
||||
|
||||
if (flag.value && flag.soluce == b2sum(flag.value))
|
||||
flag.found = new Date();
|
||||
check &= flag.found;
|
||||
}
|
||||
}
|
||||
|
||||
angular.module("FICApp", ["ngRoute", "ngSanitize"])
|
||||
.config(function($routeProvider, $locationProvider) {
|
||||
$routeProvider
|
||||
|
@ -55,6 +84,42 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"])
|
|||
$rootScope.notify_field = 0;
|
||||
});
|
||||
})
|
||||
.component('flagKey', {
|
||||
bindings: {
|
||||
kid: '=',
|
||||
key: '=',
|
||||
settings: '=',
|
||||
wantchoices: '=',
|
||||
},
|
||||
controller: function() {
|
||||
this.additem = function(key) {
|
||||
this.key.values.push("");
|
||||
};
|
||||
},
|
||||
template: `
|
||||
<div class="form-group">
|
||||
<label for="sol_{{ $ctrl.kid }}_0">{{ $ctrl.key.label }} :</label>
|
||||
<span ng-if="$ctrl.key.found && $ctrl.key.value" ng-bind="$ctrl.key.value"></span>
|
||||
<div class="input-group" ng-repeat="v in $ctrl.key.values track by $index" ng-class="{'mt-1': !$first}" ng-if="!$ctrl.key.found">
|
||||
<input type="text" class="form-control flag" id="sol_{{ $ctrl.kid }}_{{ $index }}" autocomplete="off" name="sol_{{ $ctrl.kid }}_{{ $index }}" ng-model="$ctrl.key.values[$index]" ng-if="!$ctrl.key.choices" placeholder="{{ $ctrl.key.help }}" title="{{ $ctrl.key.help }}">
|
||||
<select class="custom-select" id="sol_{{ $ctrl.kid }}" name="sol_{{ $ctrl.kid }}" ng-model="$ctrl.key.values[$index]" ng-if="$ctrl.key.choices" ng-options="l as v for (l, v) in $ctrl.key.choices"></select>
|
||||
<div class="input-group-append" ng-if="$ctrl.key.choices_cost">
|
||||
<button class="btn btn-success" type="button" ng-click="$ctrl.wantchoices($ctrl.kid)" ng-class="{disabled: $ctrl.key.wcsubmitted}" title="Cliquez pour échanger ce champ de texte par une liste de choix. L'opération vous coûtera {{ $ctrl.key.choices_cost * $ctrl.settings.wchoiceCurrentCoefficient }} points.">
|
||||
<span class="glyphicon glyphicon-tasks" aria-hidden="true"></span>
|
||||
Liste de propositions (<ng-pluralize count="$ctrl.key.choices_cost * $ctrl.settings.wchoiceCurrentCoefficient" when="{'one': '{} point', 'other': '{} points'}"></ng-pluralize>)
|
||||
</button>
|
||||
</div>
|
||||
<div class="input-group-append" ng-if="$ctrl.key.separator && $last">
|
||||
<button class="btn btn-success" type="button" ng-click="$ctrl.additem(key)" title="Ajouter un élément.">
|
||||
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<small class="form-text text-muted" ng-if="!$ctrl.key.found && $ctrl.key.help2.length > 0" ng-bind="$ctrl.key.help2"></small>
|
||||
<span class="glyphicon glyphicon-ok form-control-feedback text-success" aria-hidden="true" ng-if="$ctrl.key.found" title="Flag trouvé à {{ $ctrl.key.found | date:'mediumTime'}}"></span>
|
||||
</div>
|
||||
`
|
||||
})
|
||||
.controller("DataController", function($sce, $scope, $http, $rootScope, $interval, $location) {
|
||||
var actMenu = function() {
|
||||
if ($scope.my && $scope.themes) {
|
||||
|
@ -243,17 +308,30 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"])
|
|||
label: choice,
|
||||
};
|
||||
|
||||
this[cid].disabled = mcq.solved || mcq.part_solved || this[cid].solved;
|
||||
|
||||
if (!this[cid].help)
|
||||
this[cid].help = "Flag correspondant";
|
||||
this[cid].disabled = mcq.solved || mcq.part_solved || (this[cid].justification && this[cid].justification.solved);
|
||||
|
||||
if (!this[cid].disabled)
|
||||
this[cid].value = $scope.my && $scope.my.exercices[eid] && $scope.my.exercices[eid].mcqs[mid] && $scope.my.exercices[eid].mcqs[mid].choices[cid] && $scope.my.exercices[eid].mcqs[mid].choices[cid].value
|
||||
|
||||
if ($scope.my && $scope.my.exercices[eid] && $scope.my.exercices[eid].mcqs[mid] && $scope.my.exercices[eid].mcqs[mid].choices[cid]) {
|
||||
if ($scope.my.exercices[eid].mcqs[mid].choices[cid].justify !== undefined)
|
||||
this[cid].justify = $scope.my.exercices[eid].mcqs[mid].choices[cid].justify;
|
||||
if (mcq.justify) {
|
||||
if (!this[cid].justification)
|
||||
this[cid].justification = {};
|
||||
|
||||
if (!this[cid].justification.label) {
|
||||
this[cid].justification.label = "Flag correspondant";
|
||||
this[cid].justification.help2 = "Trouvez et validez les choix du QCM pour avoir des indications supplémentaires";
|
||||
}
|
||||
|
||||
if ($scope.my && $scope.my.exercices[eid] && $scope.my.exercices[eid].mcqs[mid] && $scope.my.exercices[eid].mcqs[mid].choices[cid] && $scope.my.exercices[eid].mcqs[mid].choices[cid].justification) {
|
||||
if ($scope.my.exercices[eid].mcqs[mid].choices[cid].justification.value !== undefined)
|
||||
data.exercices[eid].mcqs[mid].choices[cid].justification.value = $scope.my.exercices[eid].mcqs[mid].choices[cid].justification.value;
|
||||
if ($scope.my.exercices[eid].mcqs[mid].choices[cid].justification.values !== undefined)
|
||||
data.exercices[eid].mcqs[mid].choices[cid].justification.values = $scope.my.exercices[eid].mcqs[mid].choices[cid].justification.values;
|
||||
else
|
||||
data.exercices[eid].mcqs[mid].choices[cid].justification.values = [""];
|
||||
}
|
||||
else
|
||||
data.exercices[eid].mcqs[mid].choices[cid].justification.values = [""];
|
||||
}
|
||||
}, mcq.choices);
|
||||
});
|
||||
|
@ -336,10 +414,6 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"])
|
|||
var cbs;
|
||||
var cbd;
|
||||
|
||||
$scope.additem = function(key) {
|
||||
key.values.push("");
|
||||
};
|
||||
|
||||
$scope.ssubmit = function() {
|
||||
var resp = {}
|
||||
var check = undefined
|
||||
|
@ -349,35 +423,9 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"])
|
|||
{
|
||||
resp["flags"] = {};
|
||||
angular.forEach($scope.my.exercices[$rootScope.current_exercice].flags, function(flag,kid) {
|
||||
if (flag.values !== undefined) {
|
||||
if (flag.separator) {
|
||||
for (var i = flag.values.length - 1; i >= 0; i--) {
|
||||
if (!flag.values[i].length)
|
||||
flag.values.splice(i, 1);
|
||||
}
|
||||
|
||||
if (flag.ignoreorder)
|
||||
flag.value = flag.values.slice().sort().join(flag.separator) + flag.separator;
|
||||
else
|
||||
flag.value = flag.values.join(flag.separator) + flag.separator;
|
||||
|
||||
if (flag.values.length == 0)
|
||||
flag.values = [""];
|
||||
}
|
||||
else
|
||||
flag.value = flag.values[0];
|
||||
}
|
||||
|
||||
if (flag.found == null) {
|
||||
if (flag.soluce !== undefined) {
|
||||
if (check === undefined) check = true;
|
||||
|
||||
if (flag.value && flag.soluce == b2sum(flag.value))
|
||||
flag.found = new Date();
|
||||
check &= flag.found;
|
||||
} else {
|
||||
resp["flags"][kid] = flag.value;
|
||||
}
|
||||
treatFlagKey(flag);
|
||||
if (flag.found == null && flag.soluce === undefined) {
|
||||
resp["flags"][kid] = flag.value;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -396,11 +444,11 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"])
|
|||
} else {
|
||||
if (choice.value) {
|
||||
resp["mcqs"][cid] = choice.value;
|
||||
if (mcq.justify !== undefined) {
|
||||
if (choice.justification !== undefined) {
|
||||
if (resp["justifications"] == undefined)
|
||||
resp["justifications"] = {};
|
||||
if (choice.justify)
|
||||
resp["justifications"][cid] = choice.justify;
|
||||
treatFlagKey(choice.justification);
|
||||
resp["justifications"][cid] = choice.justification.value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue