server/frontend/static/js/app.js

68 lines
2.1 KiB
JavaScript

angular.module("FICApp", ["ngRoute"])
.config(function($routeProvider, $locationProvider) {
$routeProvider
.when("/edit", {
controller: "MyTeamController",
templateUrl: "views/team-edit.html"
})
.when("/rank", {
controller: "TeamListController",
templateUrl: "views/team-list.html"
})
.when("/:theme", {
controller: "ThemeController",
templateUrl: "views/theme.html"
})
.when("/:theme/:exercice", {
controller: "ExerciceController",
templateUrl: "views/theme.html"
})
.otherwise({
controller: "HomeController",
templateUrl: "views/home.html"
});
$locationProvider.html5Mode(true);
})
.run(function($rootScope, $http) {
$http.get("/themes.json").success(function(themes) {
$rootScope.themes = themes;
angular.forEach(themes, function(value, key) {
this[key].exercice_count = Object.keys(value.exercices).length;
}, themes);
});
$http.get("/teams.json").success(function(teams) {
$rootScope.teams_count = Object.keys(teams).length
$rootScope.teams = teams;
});
$http.get("/my.json").success(function(my) {
$rootScope.my = my;
});
});
angular.module("FICApp")
.controller("ExerciceController", function($scope, $routeParams, $rootScope) {
$rootScope.current_theme = $routeParams.theme;
$rootScope.current_exercice = $routeParams.exercice;
})
.controller("MyTeamController", function($scope, $rootScope) {
$rootScope.current_theme = 0;
$rootScope.current_exercice = 0;
$rootScope.title = "Edit team";
})
.controller("HomeController", function($scope, $rootScope) {
$rootScope.current_theme = 0;
$rootScope.current_exercice = 0;
$rootScope.title = "";
})
.controller("ThemeController", function($scope, $routeParams, $rootScope) {
$rootScope.current_theme = $routeParams.theme;
var exos = Object.keys($rootScope.themes[$rootScope.current_theme].exercices);
var i = 0;
for (; i < exos.length - 1; i++) {
if (!$rootScope.my.exercices[exos[i]] || !$rootScope.my.exercices[exos[i]].solved)
break;
}
$rootScope.current_exercice = exos[i];
});