admin: New page to list tags

This commit is contained in:
nemunaire 2022-05-24 21:25:27 +02:00
parent a6adc1ac8c
commit 80917ae436
5 changed files with 84 additions and 0 deletions

View File

@ -17,6 +17,7 @@ import (
func declareGlobalExercicesRoutes(router *gin.RouterGroup) {
router.GET("/resolutions.json", exportResolutionMovies)
router.GET("/exercices_stats.json", getExercicesStats)
router.GET("/tags", listTags)
}
func declareExercicesRoutes(router *gin.RouterGroup) {
@ -225,6 +226,32 @@ func listExercices(c *gin.Context) {
}
}
func listTags(c *gin.Context) {
exercices, err := fic.GetExercices()
if err != nil {
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": err.Error()})
return
}
ret := map[string][]*fic.Exercice{}
for _, exercice := range exercices {
tags, err := exercice.GetTags()
if err != nil {
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": err.Error()})
return
}
for _, t := range tags {
if _, ok := ret[t]; !ok {
ret[t] = []*fic.Exercice{}
}
ret[t] = append(ret[t], exercice)
}
}
c.JSON(http.StatusOK, ret)
}
// Generate the csv to export with:
// curl -s http://127.0.0.1:8081/api/resolutions.json | jq -r ".[] | [ .theme,.title, @uri \"https://fic.srs.epita.fr/resolution/\\(.videoURI)\" ] | join(\";\")"
func exportResolutionMovies(c *gin.Context) {

View File

@ -74,6 +74,9 @@ func declareStaticRoutes(router *gin.RouterGroup, cfg *settings.Settings, baseUR
router.GET("/sync", func(c *gin.Context) {
serveIndex(c)
})
router.GET("/tags/*_", func(c *gin.Context) {
serveIndex(c)
})
router.GET("/teams/*_", func(c *gin.Context) {
serveIndex(c)
})

View File

@ -41,6 +41,10 @@ angular.module("FICApp", ["ngRoute", "ngResource", "ngSanitize"])
controller: "ExerciceController",
templateUrl: "views/exercice-resolution.html"
})
.when("/tags", {
controller: "TagsListController",
templateUrl: "views/tags.html"
})
.when("/teams", {
controller: "TeamsListController",
templateUrl: "views/team-list.html"
@ -1478,6 +1482,16 @@ angular.module("FICApp")
}
})
.controller("TagsListController", function($scope, $http) {
$scope.tags = [];
$http({
url: "api/tags",
method: "GET"
}).then(function(response) {
$scope.tags = response.data
});
})
.controller("AllExercicesListController", function($scope, Exercice, Theme, $routeParams, $location, $rootScope, $http, $filter) {
$http({
url: "api/themes.json",

View File

@ -1,6 +1,12 @@
<div class="d-flex justify-content-between">
<h2>Exercices</h2>
<div class="align-self-center">
<a
href="tags"
class="btn btn-sm btn-dark"
>
<span class="glyphicon glyphicon-th" aria-hidden="true"></span> Tags
</a>
<a
href="files"
class="btn btn-sm btn-info"

View File

@ -0,0 +1,34 @@
<div class="d-flex justify-content-between">
<h2>Tags</h2>
</div>
<table class="table table-hover table-bordered table-striped table-sm">
<thead class="thead-dark">
<tr>
<th>
Tag
</th>
<th>
Nb
</th>
<th>
Exercices
</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="(tag, exercices) in tags">
<td>
{{ tag }}
</td>
<td>
{{ exercices.length }}
</td>
<td ng-repeat="e in exercices">
<a ng-href="exercices/{{ e.id }}">
{{ e.title }}
</a>
</td>
</tr>
</tbody>
</table>