From 0ddd6c4899b4fa20d79170870505da5d18bc0c3a Mon Sep 17 00:00:00 2001 From: nemunaire Date: Sun, 13 May 2018 14:15:53 +0200 Subject: [PATCH 0001/1903] Export themes as array --- frontend/static/js/challenge.js | 37 +++++++++------ frontend/static/views/theme.html | 38 ++++++++-------- libfic/theme_export.go | 78 +++++++++++++++++--------------- 3 files changed, 83 insertions(+), 70 deletions(-) diff --git a/frontend/static/js/challenge.js b/frontend/static/js/challenge.js index 27e45622..83a22f10 100644 --- a/frontend/static/js/challenge.js +++ b/frontend/static/js/challenge.js @@ -41,6 +41,7 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"]) .run(function($rootScope, $interval) { $rootScope.current_theme = 0; $rootScope.current_exercice = 0; + $rootScope.current_exercice_my = 0; $rootScope.time = {}; $('[data-toggle="popover"]').popover(); @@ -170,29 +171,30 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"]) $rootScope.current_exercice = $scope.exercicesUrl[$routeParams.exercice]; } else { if ($scope.themes && $scope.my && $scope.themes[$scope.current_theme]) { - var exos = Object.keys($scope.themes[$scope.current_theme].exercices); + var exos = $scope.themes[$scope.current_theme].exercices; var i = 0; for (; i < exos.length; i++) { - if (!$scope.my.exercices || !$scope.my.exercices[exos[i]] || !$scope.my.exercices[exos[i]].solved) + if (!$scope.my.exercices || !$scope.my.exercices[exos[i].id] || !$scope.my.exercices[exos[i].id].solved) break; } if (i < exos.length) { - $rootScope.current_exercice = exos[i]; + $rootScope.current_exercice = i; } else { - $rootScope.current_exercice = exos[0]; + $rootScope.current_exercice = 0; } } else { $rootScope.current_exercice = 0; } } + $rootScope.current_exercice_my = $scope.themes[$scope.current_theme].exercices[$rootScope.current_exercice].id; $scope.hsubmit = function(hint) { hint.submitted = true; - $http({ url: "/openhint/" + $rootScope.current_exercice, method: "POST", data: { id: hint.id } }).then(function(response, status, header, config) { + $http({ url: "/openhint/" + $rootScope.current_exercice_my, method: "POST", data: { id: hint.id } }).then(function(response, status, header, config) { var checkDiffHint = function() { $http.get("/my.json").then(function(response) { var my = response.data; - angular.forEach(my.exercices[$rootScope.current_exercice].hints, function(h,hid){ + angular.forEach(my.exercices[$rootScope.current_exercice_my].hints, function(h,hid){ if (hint.id == h.id) { if (hint.content != h.content) { $rootScope.refresh(); @@ -216,24 +218,24 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"]) $rootScope.sberr = ""; var waitMy = function() { - if (!$scope.my || !$scope.my.exercices || !$scope.my.exercices[$rootScope.current_exercice]) { + if (!$scope.my || !$scope.my.exercices || !$scope.my.exercices[$rootScope.current_exercice_my]) { $timeout.cancel($scope.cbs); $scope.cbs = $timeout(waitMy, 420); } else { $scope.flags = []; - angular.forEach($scope.my.exercices[$rootScope.current_exercice].keys, function(key,kid) { + angular.forEach($scope.my.exercices[$rootScope.current_exercice_my].keys, function(key,kid) { var o = { id: kid, name: key, value: "" }; - if ($scope.my.exercices[$rootScope.current_exercice].solved_matrix != null) - o.found = $scope.my.exercices[$rootScope.current_exercice].solved_matrix[kid]; + if ($scope.my.exercices[$rootScope.current_exercice_my].solved_matrix != null) + o.found = $scope.my.exercices[$rootScope.current_exercice_my].solved_matrix[kid]; this.push(o); }, $scope.flags); $scope.mcqs = []; - angular.forEach($scope.my.exercices[$rootScope.current_exercice].mcqs, function(mcq,qid) { + angular.forEach($scope.my.exercices[$rootScope.current_exercice_my].mcqs, function(mcq,qid) { var o = { title: mcq.title, kind: mcq.kind, @@ -273,7 +275,7 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"]) }); } - $http({ url: "/submit/" + $rootScope.current_exercice, method: "POST", data: resp }).then(function(response, status, header, config) { + $http({ url: "/submit/" + $rootScope.current_exercice_my, method: "POST", data: resp }).then(function(response, status, header, config) { $rootScope.messageClass = {"text-success": true}; $rootScope.message = response.data.errmsg; $rootScope.sberr = ""; @@ -285,7 +287,7 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"]) var checkDiff = function() { $http.get("/my.json").then(function(response) { var my = response.data; - if ($scope.my.exercices[$rootScope.current_exercice].tries != my.exercices[$rootScope.current_exercice].tries || $scope.my.exercices[$rootScope.current_exercice].solved_time != my.exercices[$rootScope.current_exercice].solved_time) { + if ($scope.my.exercices[$rootScope.current_exercice_my].tries != my.exercices[$rootScope.current_exercice_my].tries || $scope.my.exercices[$rootScope.current_exercice_my].solved_time != my.exercices[$rootScope.current_exercice_my].solved_time) { $rootScope.refresh(); $scope.my = my; waitMy(); @@ -298,7 +300,7 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"]) checkDiff(); }, function(response, status, header, config) { if (status >= 500) { - $scope.my.exercices[$rootScope.current_exercice].submitted = false; + $scope.my.exercices[$rootScope.current_exercice_my].submitted = false; } $rootScope.messageClass = {"text-danger": true}; $rootScope.message = response.data.errmsg; @@ -306,12 +308,13 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"]) $rootScope.sberr = "Une erreur est survenue lors de l'envoi. Veuillez réessayer dans quelques instants."; } }); - $scope.my.exercices[$rootScope.current_exercice].submitted = true; + $scope.my.exercices[$rootScope.current_exercice_my].submitted = true; }; }) .controller("MyTeamController", function($scope, $http, $rootScope, $timeout) { $rootScope.current_theme = 0; $rootScope.current_exercice = 0; + $rootScope.current_exercice_my = 0; if ($scope.my) { $rootScope.title = $scope.my.name; $rootScope.authors = $scope.my.members.map(function (cur) { @@ -373,6 +376,7 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"]) .controller("RegisterController", function($scope, $rootScope, $location, $http) { $rootScope.current_theme = 0; $rootScope.current_exercice = 0; + $rootScope.current_exercice_my = 0; $rootScope.title = "Bienvenue au challenge forensic !"; $rootScope.authors = null; @@ -443,6 +447,7 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"]) .controller("RankController", function($scope, $rootScope) { $rootScope.current_theme = 0; $rootScope.current_exercice = 0; + $rootScope.current_exercice_my = 0; $rootScope.title = "Classement général"; $rootScope.authors = ""; @@ -461,12 +466,14 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"]) .controller("VideosController", function($scope, $rootScope) { $rootScope.current_theme = 0; $rootScope.current_exercice = 0; + $rootScope.current_exercice_my = 0; $rootScope.title = "Vidéos de résolution"; $rootScope.authors = ""; }) .controller("HomeController", function($scope, $rootScope) { $rootScope.current_theme = 0; $rootScope.current_exercice = 0; + $rootScope.current_exercice_my = 0; $rootScope.title = ""; $rootScope.authors = ""; }); diff --git a/frontend/static/views/theme.html b/frontend/static/views/theme.html index f9d1585b..7c5fa11c 100644 --- a/frontend/static/views/theme.html +++ b/frontend/static/views/theme.html @@ -12,15 +12,15 @@ -
+
Vous n'avez pas encore accès à cet exercice.
-
+

-
+

{{ themes[current_theme].exercices[current_exercice].title }}

-

+


- {{ my.score }} points – {{ teams[my.team_id].rank }}e sur {{ teams_count }} + {{ my.score | number }} points – {{ teams[my.team_id].rank }}e sur {{ teams_count }}

{{ my.name }} From 0075bdeb52ba697be9ee2da9e0956e09ab660512 Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Sun, 9 Dec 2018 22:46:17 +0100 Subject: [PATCH 0179/1903] admin: update public screen presets --- admin/static/js/app.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/admin/static/js/app.js b/admin/static/js/app.js index 8335a1c9..2096939d 100644 --- a/admin/static/js/app.js +++ b/admin/static/js/app.js @@ -609,8 +609,8 @@ angular.module("FICApp") params: { kind: "public" }, }, { - type: "themes", - params: { color: "light", title: "Présentation des entreprises ciblées"}, + type: "carousel", + params: { color: "info", kind: "themes", title: "Présentation des entreprises ciblées"}, }, ]; else if (scene == "start") @@ -628,11 +628,11 @@ angular.module("FICApp") $scope.scenes = [ { type: "table", - params: { kind: "levels", levels: [1,2,3,4,5,6,7,8,9,10], themes: $scope.themes.map(function(z, i) { return z.id; }), total: true }, + params: { kind: "levels", levels: [1,2,3,4,5], themes: $scope.themes.map(function(z, i) { return z.id; }), total: true }, }, { type: "rank", - params: { limit: 5, which: "general" }, + params: { limit: 10, which: "general" }, }, ]; } From 0d8505131e46159c5c4472fe4db452b007e83f30 Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Sun, 9 Dec 2018 23:59:20 +0100 Subject: [PATCH 0180/1903] sync: automatically add   before ponctuation --- admin/sync/exercice_hints.go | 4 +++- admin/sync/exercices.go | 8 +++++++- admin/sync/themes.go | 6 +++--- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/admin/sync/exercice_hints.go b/admin/sync/exercice_hints.go index 3afa1222..32ea9b7d 100644 --- a/admin/sync/exercice_hints.go +++ b/admin/sync/exercice_hints.go @@ -28,6 +28,8 @@ func SyncExerciceHints(i Importer, exercice fic.Exercice) (errs []string) { for n, hint := range params.Hints { if hint.Title != "" { hint.Title = fmt.Sprintf("Astuce #%d", n+1) + } else { + hint.Title = fixnbsp(hint.Title) } if hint.Cost <= 0 { hint.Cost = exercice.Gain / 4 @@ -72,7 +74,7 @@ func SyncExerciceHints(i Importer, exercice fic.Exercice) (errs []string) { } else if hint.Content == "" { errs = append(errs, fmt.Sprintf("%q: challenge.txt: hint %s (%d): content and filename can't be empty at the same time", path.Base(exercice.Path), hint.Title, n+1)) continue - } else if hint.Content, err = ProcessMarkdown(i, hint.Content, exercice.Path); err != nil{ + } else if hint.Content, err = ProcessMarkdown(i, fixnbsp(hint.Content), exercice.Path); err != nil{ errs = append(errs, fmt.Sprintf("%q: challenge.txt: hint %s (%d): error during markdown formating: %s", path.Base(exercice.Path), hint.Title, n+1, err)) } diff --git a/admin/sync/exercices.go b/admin/sync/exercices.go index b8a484fd..fb491cc9 100644 --- a/admin/sync/exercices.go +++ b/admin/sync/exercices.go @@ -11,6 +11,10 @@ import ( "gopkg.in/russross/blackfriday.v2" ) +func fixnbsp(s string) string { + return strings.Replace(strings.Replace(strings.Replace(s, " ?", " ?", -1), " !", " !", -1), " :", " :", -1) +} + // getExercices returns all exercice directories existing in a given theme, considering the given Importer. func getExercices(i Importer, theme fic.Theme) ([]string, error) { var exercices []string @@ -90,12 +94,14 @@ func SyncExercice(i Importer, theme fic.Theme, epath string, dmap *map[int64]fic } e.URLId = fic.ToURLid(e.Title) + e.Title = fixnbsp(e.Title) // Texts to format using Markdown e.Overview, err = getFileContent(i, path.Join(epath, "overview.txt")) if err != nil { errs = append(errs, fmt.Sprintf("%q: overview.txt: %s", edir, err)) } else { + e.Overview = fixnbsp(e.Overview) e.Headline = string(blackfriday.Run([]byte(strings.Split(e.Overview, "\n")[0]))) if e.Overview, err = ProcessMarkdown(i, e.Overview, epath); err != nil { errs = append(errs, fmt.Sprintf("%q: overview.txt: an error occurs during markdown formating: %s", edir, err)) @@ -106,7 +112,7 @@ func SyncExercice(i Importer, theme fic.Theme, epath string, dmap *map[int64]fic if err != nil { errs = append(errs, fmt.Sprintf("%q: statement.txt: %s", edir, err)) } else { - if e.Statement, err = ProcessMarkdown(i, e.Statement, epath); err != nil { + if e.Statement, err = ProcessMarkdown(i, fixnbsp(e.Statement), epath); err != nil { errs = append(errs, fmt.Sprintf("%q: statement.txt: an error occurs during markdown formating: %s", edir, err)) } } diff --git a/admin/sync/themes.go b/admin/sync/themes.go index f131f972..c511cdd0 100644 --- a/admin/sync/themes.go +++ b/admin/sync/themes.go @@ -71,9 +71,9 @@ func SyncThemes(i Importer) []string { // Extract theme's label if f := strings.Index(tdir, "-"); f >= 0 { - tname = tdir[f+1:] + tname = fixnbsp(tdir[f+1:]) } else { - tname = tdir + tname = fixnbsp(tdir) } if authors, err = getAuthors(i, tdir); err != nil { @@ -83,7 +83,7 @@ func SyncThemes(i Importer) []string { errs = append(errs, fmt.Sprintf("%q: unable to get theme's overview: %s", tname, err)) } else { // Split headline from intro - ovrvw := strings.Split(intro, "\n") + ovrvw := strings.Split(fixnbsp(intro), "\n") headline = ovrvw[0] if len(ovrvw) > 1 { intro = strings.Join(ovrvw[1:], "\n") From 6f5d7828dbc209ca9c4e213f20c6d3c626efbf86 Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Mon, 10 Dec 2018 00:00:07 +0100 Subject: [PATCH 0181/1903] frontend: in rank, hilight current team line --- frontend/static/views/rank.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/static/views/rank.html b/frontend/static/views/rank.html index e7c74c31..6e5a1e85 100644 --- a/frontend/static/views/rank.html +++ b/frontend/static/views/rank.html @@ -13,7 +13,7 @@ - + {{ team[field] }} From 03e3bb811836741596ffc0ac704b01d1685e22dd Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Mon, 10 Dec 2018 00:28:34 +0100 Subject: [PATCH 0182/1903] frontend: change exercice border coloration when solved or bonus are active --- frontend/static/views/home.html | 5 ++--- frontend/static/views/tag.html | 11 +++++++---- frontend/static/views/theme.html | 2 +- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/frontend/static/views/home.html b/frontend/static/views/home.html index 997928a9..134052b3 100644 --- a/frontend/static/views/home.html +++ b/frontend/static/views/home.html @@ -15,12 +15,11 @@

-
+
diff --git a/frontend/static/views/tag.html b/frontend/static/views/tag.html index 1b8f4730..6f606d28 100644 --- a/frontend/static/views/tag.html +++ b/frontend/static/views/tag.html @@ -1,13 +1,16 @@
- diff --git a/frontend/static/views/theme.html b/frontend/static/views/theme.html index 83d60986..c4597c38 100644 --- a/frontend/static/views/theme.html +++ b/frontend/static/views/theme.html @@ -11,8 +11,8 @@ {{ exercice.title }} - {{ exercice.title }} + {{ exercice.title }} #{{tag}} From d1e98fc4f9a3662017b68cebb4de016b6978a067 Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Mon, 10 Dec 2018 00:29:02 +0100 Subject: [PATCH 0183/1903] admin: fix bad location change after exercice deletion --- admin/static/js/app.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/admin/static/js/app.js b/admin/static/js/app.js index 2096939d..9ecac1a7 100644 --- a/admin/static/js/app.js +++ b/admin/static/js/app.js @@ -1094,9 +1094,10 @@ angular.module("FICApp") }; $scope.deleteExercice = function() { + var tid = $scope.exercice.id_theme; this.exercice.$remove(function() { $rootScope.staticFilesNeedUpdate++; - $location.url("/themes/" + $routeParams.themeId); + $location.url("/themes/" + tid); }, function(response) { $rootScope.newBox('danger', 'An error occurs when trying to delete exercice:', response.data.errmsg); }); From ba9bf4ef456ecd6904c131db9beeac7d1b94a074 Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Mon, 10 Dec 2018 00:30:02 +0100 Subject: [PATCH 0184/1903] sync: ignore bad named directory when looking for dependancies --- admin/sync/exercices.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/admin/sync/exercices.go b/admin/sync/exercices.go index fb491cc9..f62ffddc 100644 --- a/admin/sync/exercices.go +++ b/admin/sync/exercices.go @@ -46,7 +46,8 @@ func buildDependancyMap(i Importer, theme fic.Theme) (dmap map[int64]fic.Exercic var ename string eid, ename, err = parseExerciceDirname(edir) if err != nil { - return + err = nil + continue } var e fic.Exercice From 25b23e7ae0e8abcc4bc7eecb5af02f45ae20a9fd Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Mon, 10 Dec 2018 00:45:00 +0100 Subject: [PATCH 0185/1903] sync: fix message --- admin/sync/exercice_keys.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/admin/sync/exercice_keys.go b/admin/sync/exercice_keys.go index a5a3bae4..b4229331 100644 --- a/admin/sync/exercice_keys.go +++ b/admin/sync/exercice_keys.go @@ -119,7 +119,7 @@ func SyncExerciceFlags(i Importer, exercice fic.Exercice) (errs []string) { // Import dependency to flag for _, nf := range flag.NeedFlag { if rf, ok := kmap[nf.Id]; !ok { - errs = append(errs, fmt.Sprintf("%q: error flag #%d dependency to flag id=%s: id not defined, perhaps not available at time of processing", path.Base(exercice.Path), nline + 1, nf.Id)) + errs = append(errs, fmt.Sprintf("%q: error flag #%d dependency to flag id=%d: id not defined, perhaps not available at time of processing", path.Base(exercice.Path), nline + 1, nf.Id)) continue } else if err := k.AddDepend(rf); err != nil { errs = append(errs, fmt.Sprintf("%q: error flag #%d dependency to %s: %s", path.Base(exercice.Path), nline + 1, nf.Id, err)) From d60e9264e3f51ca794c9a611db09fab08a9bcbc0 Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Mon, 10 Dec 2018 02:10:01 +0100 Subject: [PATCH 0186/1903] dashboard: perfect view --- dashboard/static/index.html | 56 ++++++++++++++++++------------------- frontend/static/css/fic.css | 8 ++++-- 2 files changed, 34 insertions(+), 30 deletions(-) diff --git a/dashboard/static/index.html b/dashboard/static/index.html index 2cef2e66..c725437f 100644 --- a/dashboard/static/index.html +++ b/dashboard/static/index.html @@ -271,7 +271,7 @@
-
+
@@ -283,8 +283,8 @@
-
-
+
+
{{ time.hours | time }} : @@ -292,7 +292,7 @@ : {{ time.seconds | time }}
-
+
Temps restant du challenge forensic Le challenge forensic va bientôt commencer ! Le challenge forensic est terminé ! @@ -303,55 +303,55 @@
-
-