[admin] Add new routes to manage hints, files and keys

This commit is contained in:
nemunaire 2016-12-27 21:08:36 +01:00 committed by Pierre-Olivier Mercier
parent 8d725ef35b
commit ddc9a515f6
7 changed files with 259 additions and 43 deletions

View file

@ -97,18 +97,18 @@ angular.module("FICApp")
})
})
.factory("ExerciceFile", function($resource) {
return $resource("/api/exercices/:exerciceId/files", { exerciceId: '@idExercice' }, {
update: {method: 'PATCH'}
return $resource("/api/exercices/:exerciceId/files/:fileId", { exerciceId: '@idExercice', fileId: '@id' }, {
update: {method: 'PUT'}
})
})
.factory("ExerciceHint", function($resource) {
return $resource("/api/exercices/:exerciceId/hints", { exerciceId: '@idExercice' }, {
update: {method: 'PATCH'}
return $resource("/api/exercices/:exerciceId/hints/:hintId", { exerciceId: '@idExercice', hintId: '@id' }, {
update: {method: 'PUT'}
})
})
.factory("ExerciceKey", function($resource) {
return $resource("/api/exercices/:exerciceId/keys", { exerciceId: '@idExercice' }, {
update: {method: 'PATCH'}
return $resource("/api/exercices/:exerciceId/keys/:keyId", { exerciceId: '@idExercice', keyId: '@id' }, {
update: {method: 'PUT'}
})
});
@ -175,6 +175,17 @@ angular.module("FICApp")
}
})
.directive('integer', function() {
return {
require: 'ngModel',
link: function(scope, ele, attr, ctrl){
ctrl.$parsers.unshift(function(viewValue){
return parseInt(viewValue, 10);
});
}
};
})
.controller("VersionController", function($scope, Version) {
$scope.v = Version.get();
})
@ -228,7 +239,13 @@ angular.module("FICApp")
$scope.fields = ["name", "authors"];
$scope.saveTheme = function() {
this.theme.$update();
if (this.theme.id) {
this.theme.$update();
} else {
this.theme.$save(function() {
$location.url("/themes/" + $scope.theme.id);
});
}
}
$scope.deleteTheme = function() {
this.theme.$remove(function() { $location.url("/themes/");});
@ -237,7 +254,7 @@ angular.module("FICApp")
.controller("AllExercicesListController", function($scope, Exercice, $routeParams, $location) {
$scope.exercices = Exercice.query();
$scope.fields = ["id", "title", "statement", "videoURI"];
$scope.fields = ["title", "statement", "videoURI"];
$scope.show = function(id) {
$location.url("/exercices/" + id);
@ -245,27 +262,40 @@ angular.module("FICApp")
})
.controller("ExercicesListController", function($scope, ThemedExercice, $routeParams, $location) {
$scope.exercices = ThemedExercice.query({ themeId: $routeParams.themeId });
$scope.fields = ["id", "title", "statement", "videoURI"];
$scope.fields = ["title", "statement", "videoURI"];
$scope.show = function(id) {
$location.url("/themes/" + $routeParams.themeId + "/exercices/" + id);
};
})
.controller("ExerciceController", function($scope, Exercice, $routeParams) {
$scope.exercice = Exercice.get({ exerciceId: $routeParams.exerciceId });
.controller("ExerciceController", function($scope, Exercice, ThemedExercice, $routeParams, $location) {
if ($routeParams.themeId && $routeParams.exerciceId == "new") {
$scope.exercice = new ThemedExercice();
} else {
$scope.exercice = Exercice.get({ exerciceId: $routeParams.exerciceId });
}
$scope.exercices = Exercice.query();
$scope.fields = ["title", "statement", "depend", "gain", "videoURI"];
$scope.saveExercice = function() {
this.exercice.$update();
if (this.exercice.id) {
this.exercice.$update();
} else if ($routeParams.themeId) {
this.exercice.$save({ themeId: $routeParams.themeId }, function() {
$location.url("/themes/" + $scope.exercice.idTheme + "/exercices/" + $scope.exercice.id);
});
}
}
})
.controller("ExerciceFilesController", function($scope, ExerciceFile, $routeParams) {
.controller("ExerciceFilesController", function($scope, ExerciceFile, $routeParams, $location) {
$scope.files = ExerciceFile.query({ exerciceId: $routeParams.exerciceId });
$scope.deleteFile = function() {
this.file.$delete();
this.file.$delete(function() {
$scope.files.splice($scope.files.indexOf(this.file), 1);
});
return false;
}
$scope.saveFile = function() {
this.file.$update();
@ -275,22 +305,40 @@ angular.module("FICApp")
.controller("ExerciceHintsController", function($scope, ExerciceHint, $routeParams) {
$scope.hints = ExerciceHint.query({ exerciceId: $routeParams.exerciceId });
$scope.addHint = function() {
$scope.hints.push(new ExerciceHint());
}
$scope.deleteHint = function() {
this.hint.$delete();
this.hint.$delete(function() {
$scope.hints.splice($scope.hints.indexOf(this.hint), 1);
});
}
$scope.saveHint = function() {
this.hint.$update();
if (this.hint.id) {
this.hint.$update();
} else {
this.hint.$save({ exerciceId: $routeParams.exerciceId });
}
}
})
.controller("ExerciceKeysController", function($scope, ExerciceKey, $routeParams) {
$scope.keys = ExerciceKey.query({ exerciceId: $routeParams.exerciceId });
$scope.addKey = function() {
$scope.keys.push(new ExerciceKey());
}
$scope.deleteKey = function() {
this.key.$delete();
this.key.$delete(function() {
$scope.keys.splice($scope.keys.indexOf(this.key), 1);
});
}
$scope.saveKey = function() {
this.key.$update();
if (this.key.id) {
this.key.$update();
} else {
this.key.$save({ exerciceId: $routeParams.exerciceId });
}
}
})