admin: New page to list forge link per theme and exercice
This commit is contained in:
parent
b713eba2a5
commit
7d775fe26d
5 changed files with 98 additions and 0 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
Reference in a new issue