admin: can perform mass editing on exercices

This commit is contained in:
nemunaire 2018-11-21 01:19:13 +01:00 committed by Pierre-Olivier Mercier
commit 6b54704d59
4 changed files with 97 additions and 9 deletions

View file

@ -205,7 +205,8 @@ angular.module("FICApp")
})
.factory("Exercice", function($resource) {
return $resource("/api/exercices/:exerciceId", { exerciceId: '@id' }, {
update: {method: 'PUT'}
update: {method: 'PUT'},
patch: {method: 'PATCH'}
})
})
.factory("ExerciceTags", function($resource) {
@ -962,10 +963,27 @@ angular.module("FICApp")
};
})
.controller("AllExercicesListController", function($scope, Exercice, $routeParams, $location, $rootScope, $http) {
.controller("AllExercicesListController", function($scope, Exercice, $routeParams, $location, $rootScope, $http, $filter) {
$scope.exercices = Exercice.query();
$scope.exercice = {}; // Array used to save fields to updates in selected exercices
$scope.fields = ["title", "overview"];
$scope.toggleSelectAll = function() {
angular.forEach($filter('filter')($scope.exercices, $scope.query), function(ex) {
ex.selected = !$scope.selectall
})
}
$scope.updateExercices = function() {
angular.forEach($scope.exercices, function(ex) {
if (ex.selected) {
Exercice.patch({exerciceId: ex.id}, $scope.exercice);
}
})
$scope.exercice = {};
$rootScope.newBox('success', 'Édition de masse terminée avec succès');
}
$scope.show = function(id) {
$location.url("/exercices/" + id);
};

View file

@ -24,17 +24,41 @@
<table class="table table-hover table-bordered table-striped table-sm">
<thead class="thead-dark">
<tr>
<th>
<input type="checkbox" ng-click="toggleSelectAll()" ng-model="selectall">
</th>
<th ng-repeat="field in fields">
{{ field }}
</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="exercice in exercices | filter: query" ng-click="show(exercice.id)">
<td ng-repeat="field in fields">
<tr ng-repeat="exercice in exercices | filter: query">
<td>
<input type="checkbox" ng-model="exercice.selected">
</td>
<td ng-repeat="field in fields" ng-click="show(exercice.id)">
{{ exercice[field] }}
</td>
</tr>
</tbody>
</table>
</div>
<form ng-submit="updateExercices()">
<fieldset>
<legend class="text-dark">Édition de masse <button type="submit" class="float-right btn btn-sm btn-success"><span class="glyphicon glyphicon-ok" aria-hidden="true"></span></button></legend>
<div class="form-group row" ng-repeat="field in ['gain','coefficient']">
<label for="{{ field }}" class="col-sm-1 col-form-label-sm">{{ field | capitalize }}</label>
<div class="col-sm-11">
<input type="text" class="form-control form-control-sm" id="{{ field }}" ng-model="exercice[field]" ng-if="field != 'statement' && field != 'overview' && field != 'depend' && field != 'gain' && field != 'coefficient'">
<input type="text" class="form-control form-control-sm" id="{{ field }}" ng-model="exercice[field]" ng-if="field == 'gain'" integer>
<input type="text" class="form-control form-control-sm" id="{{ field }}" ng-model="exercice[field]" ng-if="field == 'coefficient'" float>
<textarea class="form-control form-control-sm" id="{{field}}" ng-model="exercice[field]" ng-if="field == 'statement' || field == 'overview'"></textarea>
<select class="form-control form-control-sm" id="{{field}}" ng-model="exercice[field]" ng-options="ex.id as ex.title group by ex.path.split('/')[0] for ex in exercices" ng-if="field == 'depend'">
<option value="">Aucune</option>
</select>
</div>
</div>
</fieldset>
</form>

View file

@ -6,11 +6,11 @@
<div class="form-group row" ng-repeat="field in fields">
<label for="{{ field }}" class="col-sm-1 col-form-label-sm">{{ field | capitalize }}</label>
<div class="col-sm-11">
<input type="text" class="form-control form-control-sm" id="{{ field }}" ng-model="exercice[field]" ng-show="field != 'statement' && field != 'overview' && field != 'depend' && field != 'gain' && field != 'coefficient'">
<input type="text" class="form-control form-control-sm" id="{{ field }}" ng-model="exercice[field]" ng-show="field == 'gain'" integer>
<input type="text" class="form-control form-control-sm" id="{{ field }}" ng-model="exercice[field]" ng-show="field == 'coefficient'" float>
<textarea class="form-control form-control-sm" id="{{field}}" ng-model="exercice[field]" ng-show="field == 'statement' || field == 'overview'"></textarea>
<select class="form-control form-control-sm" id="{{field}}" ng-model="exercice[field]" ng-options="ex.id as ex.title group by ex.path.split('/')[0] for ex in exercices" ng-show="field == 'depend'">
<input type="text" class="form-control form-control-sm" id="{{ field }}" ng-model="exercice[field]" ng-if="field != 'statement' && field != 'overview' && field != 'depend' && field != 'gain' && field != 'coefficient'">
<input type="text" class="form-control form-control-sm" id="{{ field }}" ng-model="exercice[field]" ng-if="field == 'gain'" integer>
<input type="text" class="form-control form-control-sm" id="{{ field }}" ng-model="exercice[field]" ng-if="field == 'coefficient'" float>
<textarea class="form-control form-control-sm" id="{{field}}" ng-model="exercice[field]" ng-if="field == 'statement' || field == 'overview'"></textarea>
<select class="form-control form-control-sm" id="{{field}}" ng-model="exercice[field]" ng-options="ex.id as ex.title group by ex.path.split('/')[0] for ex in exercices" ng-if="field == 'depend'">
<option value="">Aucune</option>
</select>
</div>