diff --git a/admin/api/exercice.go b/admin/api/exercice.go index c2554269..2c196153 100644 --- a/admin/api/exercice.go +++ b/admin/api/exercice.go @@ -20,6 +20,7 @@ import ( func declareGlobalExercicesRoutes(router *gin.RouterGroup) { router.GET("/resolutions.json", exportResolutionMovies) router.GET("/exercices_stats.json", getExercicesStats) + router.GET("/exercices_forge_bindings.json", getExercicesForgeLinks) router.GET("/tags", listTags) } @@ -487,6 +488,71 @@ func getExercicesStats(c *gin.Context) { c.JSON(http.StatusOK, ret) } +type themeForgeBinding struct { + ThemeName string `json:"name"` + ThemePath string `json:"path"` + ForgeLink string `json:"forge_link"` + Exercices []exerciceForgeBinding `json:"exercices"` +} + +type exerciceForgeBinding struct { + ExerciceName string `json:"name"` + ExercicePath string `json:"path"` + ForgeLink string `json:"forge_link"` +} + +func getExercicesForgeLinks(c *gin.Context) { + themes, err := fic.GetThemesExtended() + if err != nil { + log.Println("Unable to listThemes:", err.Error()) + c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "An error occurs during themes listing."}) + return + } + + fli, ok := sync.GlobalImporter.(sync.ForgeLinkedImporter) + if !ok { + c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": "Current importer is not compatible with ForgeLinkedImporter"}) + return + } + + ret := []themeForgeBinding{} + for _, theme := range themes { + exercices, err := theme.GetExercices() + if err != nil { + log.Println("Unable to listExercices:", err.Error()) + c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "An error occurs during exercice listing."}) + return + } + + var exlinks []exerciceForgeBinding + for _, exercice := range exercices { + var forgelink string + if u, _ := fli.GetExerciceLink(exercice); u != nil { + forgelink = u.String() + } + + exlinks = append(exlinks, exerciceForgeBinding{ + ExerciceName: exercice.Title, + ExercicePath: exercice.Path, + ForgeLink: forgelink, + }) + } + + var forgelink string + if u, _ := fli.GetThemeLink(theme); u != nil { + forgelink = u.String() + } + ret = append(ret, themeForgeBinding{ + ThemeName: theme.Name, + ThemePath: theme.Path, + ForgeLink: forgelink, + Exercices: exlinks, + }) + } + + c.JSON(http.StatusOK, ret) +} + func AssigneeCookieHandler(c *gin.Context) { myassignee, err := c.Cookie("myassignee") if err != nil { diff --git a/admin/static.go b/admin/static.go index 82772993..23ad6da6 100644 --- a/admin/static.go +++ b/admin/static.go @@ -80,6 +80,9 @@ func declareStaticRoutes(router *gin.RouterGroup, cfg *settings.Settings, baseUR router.GET("/files", func(c *gin.Context) { serveIndex(c) }) + router.GET("/forge-links", func(c *gin.Context) { + serveIndex(c) + }) router.GET("/public/*_", func(c *gin.Context) { serveIndex(c) }) diff --git a/admin/static/js/app.js b/admin/static/js/app.js index 915de87d..9b6fc13b 100644 --- a/admin/static/js/app.js +++ b/admin/static/js/app.js @@ -49,6 +49,10 @@ angular.module("FICApp", ["ngRoute", "ngResource", "ngSanitize"]) controller: "ExerciceController", templateUrl: "views/exercice-resolution.html" }) + .when("/forge-links", { + controller: "ForgeLinksController", + templateUrl: "views/exercices-forgelink.html" + }) .when("/tags", { controller: "TagsListController", templateUrl: "views/tags.html" @@ -2189,6 +2193,16 @@ angular.module("FICApp") }; }) + .controller("ForgeLinksController", function ($scope, $http) { + $http({ + url: "api/exercices_forge_bindings.json", + }).then(function (response) { + $scope.forge_links = response.data; + }, function (response) { + $scope.addToast('danger', 'An error occurs when generating exercice forge links: ', response.data.errmsg); + }); + }) + .controller("ExerciceTagsController", function ($scope, ExerciceTags, $routeParams, $rootScope) { $scope.tags = ExerciceTags.query({ exerciceId: $routeParams.exerciceId }); diff --git a/admin/static/views/exercices-forgelink.html b/admin/static/views/exercices-forgelink.html new file mode 100644 index 00000000..2588ebc4 --- /dev/null +++ b/admin/static/views/exercices-forgelink.html @@ -0,0 +1,12 @@ +

Accès rapide aux exercices

+ +
+

+ {{ theme.name }} : {{ theme.path }} +

+ +
diff --git a/admin/static/views/team-stats.html b/admin/static/views/team-stats.html index 7c264afb..4bb75eb1 100644 --- a/admin/static/views/team-stats.html +++ b/admin/static/views/team-stats.html @@ -37,7 +37,7 @@
diff --git a/admin/static/views/theme-list.html b/admin/static/views/theme-list.html index aed9b4ca..c5a292f7 100644 --- a/admin/static/views/theme-list.html +++ b/admin/static/views/theme-list.html @@ -2,6 +2,7 @@ Thèmes + Liens d'accès à la forge

diff --git a/admin/sync/importer_gitbin.go b/admin/sync/importer_gitbin.go index 4b4b0683..7d511265 100644 --- a/admin/sync/importer_gitbin.go +++ b/admin/sync/importer_gitbin.go @@ -205,7 +205,7 @@ func (i GitImporter) GetThemeLink(th *fic.Theme) (u *url.URL, err error) { return } - u.Path = path.Join(u.Path, "-", "tree", i.Branch, strings.TrimPrefix(th.Path, prefix)) + u.Path = path.Join(u.Path, "-", "tree", i.Branch, strings.TrimPrefix("/"+th.Path, prefix)) return } @@ -241,7 +241,7 @@ func (i GitImporter) GetExerciceLink(e *fic.Exercice) (u *url.URL, err error) { return } - u.Path = path.Join(u.Path, "-", "tree", i.Branch, strings.TrimPrefix(e.Path, prefix)) + u.Path = path.Join(u.Path, "-", "tree", i.Branch, strings.TrimPrefix("/"+e.Path, prefix)) return }