admin: New page to list tags
This commit is contained in:
parent
a6adc1ac8c
commit
80917ae436
|
@ -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) {
|
||||
|
|
|
@ -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)
|
||||
})
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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>
|
Loading…
Reference in New Issue