[admin] Add exercices related pages
This commit is contained in:
parent
6a4868b9b3
commit
863070c037
@ -9,7 +9,15 @@ angular.module("FICApp", ["ngRoute", "ngResource", "ngSanitize"])
|
||||
controller: "ThemeController",
|
||||
templateUrl: "views/theme.html"
|
||||
})
|
||||
.when("/themes/:themeId/:exerciceId", {
|
||||
.when("/themes/:themeId/exercices/:exerciceId", {
|
||||
controller: "ExerciceController",
|
||||
templateUrl: "views/exercice.html"
|
||||
})
|
||||
.when("/exercices", {
|
||||
controller: "AllExercicesListController",
|
||||
templateUrl: "views/exercice-list.html"
|
||||
})
|
||||
.when("/exercices/:exerciceId", {
|
||||
controller: "ExerciceController",
|
||||
templateUrl: "views/exercice.html"
|
||||
})
|
||||
@ -65,10 +73,30 @@ angular.module("FICApp")
|
||||
'get': {method: 'GET'},
|
||||
})
|
||||
})
|
||||
.factory("ThemedExercice", function($resource) {
|
||||
return $resource("/api/themes/:themeId/exercices/:exerciceId", { exerciceId: '@id' }, {
|
||||
update: {method: 'PUT'}
|
||||
})
|
||||
})
|
||||
.factory("Exercice", function($resource) {
|
||||
return $resource("/api/exercices/:exerciceId", { exerciceId: '@id' }, {
|
||||
update: {method: 'PUT'}
|
||||
})
|
||||
})
|
||||
.factory("ExerciceFile", function($resource) {
|
||||
return $resource("/api/exercices/:exerciceId/files", { exerciceId: '@idExercice' }, {
|
||||
update: {method: 'PATCH'}
|
||||
})
|
||||
})
|
||||
.factory("ExerciceHint", function($resource) {
|
||||
return $resource("/api/exercices/:exerciceId/hints", { exerciceId: '@idExercice' }, {
|
||||
update: {method: 'PATCH'}
|
||||
})
|
||||
})
|
||||
.factory("ExerciceKey", function($resource) {
|
||||
return $resource("/api/exercices/:exerciceId/keys", { exerciceId: '@idExercice' }, {
|
||||
update: {method: 'PATCH'}
|
||||
})
|
||||
});
|
||||
|
||||
String.prototype.capitalize = function() {
|
||||
@ -87,6 +115,41 @@ angular.module("FICApp")
|
||||
return input.capitalize();
|
||||
}
|
||||
})
|
||||
.filter("size", function() {
|
||||
var units = [
|
||||
"o",
|
||||
"kio",
|
||||
"Mio",
|
||||
"Gio",
|
||||
"Tio",
|
||||
"Pio",
|
||||
"Eio",
|
||||
"Zio",
|
||||
"Yio",
|
||||
]
|
||||
return function(input) {
|
||||
var res = input;
|
||||
var unit = 0;
|
||||
while (res > 1024) {
|
||||
unit += 1;
|
||||
res = res / 1024;
|
||||
}
|
||||
return (Math.round(res * 100) / 100) + " " + units[unit];
|
||||
}
|
||||
})
|
||||
.filter("cksum", function() {
|
||||
return function(input) {
|
||||
if (input == undefined)
|
||||
return input;
|
||||
var raw = atob(input).toString(16);
|
||||
var hex = '';
|
||||
for (var i = 0; i < raw.length; i++ ) {
|
||||
var _hex = raw.charCodeAt(i).toString(16)
|
||||
hex += (_hex.length == 2 ? _hex : '0' + _hex);
|
||||
}
|
||||
return hex
|
||||
}
|
||||
})
|
||||
.filter("time", function() {
|
||||
return function(input) {
|
||||
if (input == undefined) {
|
||||
@ -123,20 +186,62 @@ angular.module("FICApp")
|
||||
}
|
||||
})
|
||||
|
||||
.controller("ExercicesListController", function($scope, Exercice, $routeParams, $location) {
|
||||
$scope.exercices = Exercice.query({ themeId: $routeParams.themeId });
|
||||
.controller("AllExercicesListController", function($scope, Exercice, $routeParams, $location) {
|
||||
$scope.exercices = Exercice.query();
|
||||
$scope.fields = ["id", "title", "statement", "videoURI"];
|
||||
|
||||
$scope.show = function(id) {
|
||||
$location.url("/themes/" + $routeParams.themeId + "/" + id);
|
||||
$location.url("/exercices/" + id);
|
||||
};
|
||||
})
|
||||
.controller("ExerciceController", function($scope, Theme, $routeParams) {
|
||||
$scope.exercice = Exercice.get({ themeId: $routeParams.themeId });
|
||||
$scope.fields = ["name", "statement", "hint", "videoURI"];
|
||||
.controller("ExercicesListController", function($scope, ThemedExercice, $routeParams, $location) {
|
||||
$scope.exercices = ThemedExercice.query({ themeId: $routeParams.themeId });
|
||||
$scope.fields = ["id", "title", "statement", "videoURI"];
|
||||
|
||||
$scope.saveTheme = function() {
|
||||
this.exercice.$save({ themeId: this.exercice.themeId, exerciceId: this.exercice.exerciceId});
|
||||
$scope.show = function(id) {
|
||||
$location.url("/themes/" + $routeParams.themeId + "/exercices/" + id);
|
||||
};
|
||||
})
|
||||
.controller("ExerciceController", function($scope, Exercice, $routeParams) {
|
||||
$scope.exercice = Exercice.get({ exerciceId: $routeParams.exerciceId });
|
||||
$scope.exercices = Exercice.query();
|
||||
$scope.fields = ["title", "statement", "depend", "gain", "videoURI"];
|
||||
|
||||
$scope.saveExercice = function() {
|
||||
this.exercice.$update();
|
||||
}
|
||||
})
|
||||
|
||||
.controller("ExerciceFilesController", function($scope, ExerciceFile, $routeParams) {
|
||||
$scope.files = ExerciceFile.query({ exerciceId: $routeParams.exerciceId });
|
||||
|
||||
$scope.deleteFile = function() {
|
||||
this.file.$delete();
|
||||
}
|
||||
$scope.saveFile = function() {
|
||||
this.file.$update();
|
||||
}
|
||||
})
|
||||
|
||||
.controller("ExerciceHintsController", function($scope, ExerciceHint, $routeParams) {
|
||||
$scope.hints = ExerciceHint.query({ exerciceId: $routeParams.exerciceId });
|
||||
|
||||
$scope.deleteHint = function() {
|
||||
this.hint.$delete();
|
||||
}
|
||||
$scope.saveHint = function() {
|
||||
this.hint.$update();
|
||||
}
|
||||
})
|
||||
|
||||
.controller("ExerciceKeysController", function($scope, ExerciceKey, $routeParams) {
|
||||
$scope.keys = ExerciceKey.query({ exerciceId: $routeParams.exerciceId });
|
||||
|
||||
$scope.deleteKey = function() {
|
||||
this.key.$delete();
|
||||
}
|
||||
$scope.saveKey = function() {
|
||||
this.key.$update();
|
||||
}
|
||||
})
|
||||
|
||||
|
21
admin/static/views/exercice-list.html
Normal file
21
admin/static/views/exercice-list.html
Normal file
@ -0,0 +1,21 @@
|
||||
<h2>Exercices</h2>
|
||||
|
||||
<div>
|
||||
<p><input type="search" class="form-control" placeholder="Search" ng-model="query"></p>
|
||||
<table class="table table-hover table-bordered">
|
||||
<thead>
|
||||
<tr>
|
||||
<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">
|
||||
{{ exercice[field] }}
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
98
admin/static/views/exercice.html
Normal file
98
admin/static/views/exercice.html
Normal file
@ -0,0 +1,98 @@
|
||||
<h2>{{exercice.title}}</h2>
|
||||
|
||||
<form class="form form-horizontal" ng-submit="saveExercice()">
|
||||
<div class="form-group" ng-repeat="field in fields">
|
||||
<label for="{{ field }}" class="col-xs-1 control-label">{{ field | capitalize }}</label>
|
||||
<div class="col-xs-11">
|
||||
<input type="text" class="form-control" id="{{ field }}" ng-model="exercice[field]" ng-show="field != 'statement' && field != 'depend'">
|
||||
<textarea class="form-control" id="hcnt{{hint.id}}" ng-bind-html="exercice[field]" ng-show="field == 'statement'"></textarea>
|
||||
<select class="form-control" id="hcnt{{hint.id}}" ng-model="exercice[field]" ng-options="ex.id as ex.title for ex in exercices" ng-show="field == 'depend'">
|
||||
<option value="">Aucune</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="text-right">
|
||||
<button type="submit" class="btn btn-primary"><span class="glyphicon glyphicon-save" aria-hidden="true"></span> Save</button>
|
||||
<button class="btn btn-danger" ng-click="deleteExercice()"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span> Delete</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<hr>
|
||||
|
||||
<div class="row">
|
||||
|
||||
<div class="col-md-4" ng-controller="ExerciceHintsController">
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<h3 class="panel-title">Indices<a ng-click="addHint()" class="pull-right btn btn-xs btn-primary"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span></a></h3>
|
||||
</div>
|
||||
<div class="list-group">
|
||||
<form ng-submit="saveHint()" class="list-group-item form-horizontal" ng-repeat="hint in hints">
|
||||
<div class="form-group">
|
||||
<label for="htitle{{hint.id}}" class="col-xs-2 control-label">Titre</label>
|
||||
<div class="col-xs-10">
|
||||
<input type="text" id="htitle{{hint.id}}" ng-model="hint.title" class="form-control">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="hcnt{{hint.id}}" class="col-xs-2 control-label">Contenu</label>
|
||||
<div class="col-xs-10">
|
||||
<textarea class="form-control" id="hcnt{{hint.id}}" ng-bind-html="hint.content"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="hcost{{hint.id}}" class="col-xs-2 control-label">Coût</label>
|
||||
<div class="col-xs-10">
|
||||
<input type="text" id="hcost{{hint.id}}" ng-model="hint.cost" class="form-control">
|
||||
</div>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-success"><span class="glyphicon glyphicon-ok" aria-hidden="true"></span></button>
|
||||
<button class="btn btn-danger"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-4" ng-controller="ExerciceFilesController">
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<h3 class="panel-title">Téléchargements<a ng-click="addFile()" class="pull-right btn btn-xs btn-primary"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span></a></h3>
|
||||
</div>
|
||||
<div class="list-group">
|
||||
<form ng-submit="saveFile()" class="list-group-item form" ng-repeat="file in files">
|
||||
<input type="text" ng-model="file.name">
|
||||
<a href="{{file.path}}" class="btn btn-default"><span class="glyphicon glyphicon-download" aria-hidden="true"></span></a>
|
||||
<a ng-click="deleteFile()" class="btn btn-danger"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></a>
|
||||
<button type="submit" class="btn btn-success"><span class="glyphicon glyphicon-ok" aria-hidden="true"></span></button><br>
|
||||
Taille : <span title="{{ file.size }} octets">{{ file.size | size }}</span><br>
|
||||
SHA-1 : <samp>{{ file.checksum | cksum }}</samp>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-4" ng-controller="ExerciceKeysController">
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<h3 class="panel-title">Drapeaux<a ng-click="addKey()" class="pull-right btn btn-xs btn-primary"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span></a></h3>
|
||||
</div>
|
||||
<div class="list-group">
|
||||
<form ng-submit="saveKey()" class="list-group-item form-horizontal" ng-repeat="key in keys">
|
||||
<div class="form-group">
|
||||
<label for="ktype{{key.id}}" class="col-xs-2 control-label">Intitulé</label>
|
||||
<div class="col-xs-10">
|
||||
<input type="text" id="ktype{{key.id}}" ng-model="key.type" class="form-control">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="kvalue{{key.id}}" class="col-xs-2 control-label">Hash</label>
|
||||
<div class="col-xs-10">
|
||||
<input type="text" id="kvalue{{key.id}}" ng-model="key.value" class="form-control">
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
Loading…
Reference in New Issue
Block a user