New field added for works to store gradation repository
Some checks are pending
continuous-integration/drone/push Build is running
Some checks are pending
continuous-integration/drone/push Build is running
This commit is contained in:
parent
e8d34869cc
commit
6def3de983
1
api.go
1
api.go
@ -54,6 +54,7 @@ func declareAPIRoutes(router *gin.Engine) {
|
||||
declareAPIAdminAsksRoutes(apiAdminRoutes)
|
||||
declareAPIAdminCategoriesRoutes(apiRoutes)
|
||||
declareAPIAuthGradesRoutes(apiAdminRoutes)
|
||||
declareAPIAdminGradationRoutes(apiAdminRoutes)
|
||||
declareAPIAdminHelpRoutes(apiAdminRoutes)
|
||||
declareAPIAdminQuestionsRoutes(apiAdminRoutes)
|
||||
declareAPIAuthRepositoriesRoutes(apiAdminRoutes)
|
||||
|
1
db.go
1
db.go
@ -210,6 +210,7 @@ CREATE TABLE IF NOT EXISTS works(
|
||||
description TEXT NOT NULL,
|
||||
tag VARCHAR(255) NOT NULL,
|
||||
submission_URL VARCHAR(255) NULL,
|
||||
gradation_repo VARCHAR(255) NULL,
|
||||
corrected BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
start_availability TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
end_availability TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
|
32
gradation.go
Normal file
32
gradation.go
Normal file
@ -0,0 +1,32 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"github.com/drone/drone-go/drone"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func declareAPIAdminGradationRoutes(router *gin.RouterGroup) {
|
||||
router.GET("/gradation_repositories", func(c *gin.Context) {
|
||||
client := drone.NewClient(droneEndpoint, droneConfig)
|
||||
result, err := client.RepoList()
|
||||
if err != nil {
|
||||
log.Println("Unable to retrieve the repository list:", err.Error())
|
||||
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "Unable to retrieve the repository list."})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, result)
|
||||
})
|
||||
router.POST("/gradation_repositories/sync", func(c *gin.Context) {
|
||||
client := drone.NewClient(droneEndpoint, droneConfig)
|
||||
result, err := client.RepoListSync()
|
||||
if err != nil {
|
||||
log.Println("Unable to retrieve the repository list:", err.Error())
|
||||
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "Unable to retrieve the repository list."})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, result)
|
||||
})
|
||||
}
|
@ -3,6 +3,7 @@
|
||||
import { goto } from '$app/navigation';
|
||||
|
||||
import { getCategories } from '$lib/categories';
|
||||
import { getGradationRepositories, syncGradationRepositories } from '$lib/gradation';
|
||||
import DateTimeInput from './DateTimeInput.svelte';
|
||||
import { ToastsStore } from '$lib/stores/toasts';
|
||||
|
||||
@ -39,6 +40,7 @@
|
||||
})
|
||||
}
|
||||
|
||||
let grepositoriesP = getGradationRepositories();
|
||||
</script>
|
||||
|
||||
<form on:submit|preventDefault={saveWork}>
|
||||
@ -109,11 +111,41 @@
|
||||
<div class="col-sm-3 text-sm-end">
|
||||
<label for="submissionurl" class="col-form-label col-form-label-sm">URL validation la soumission</label>
|
||||
</div>
|
||||
<div class="col-sm-8 col-md-4 col-lg-2">
|
||||
<div class="col-sm-10 col-md-8 col-lg-4">
|
||||
<input class="form-control form-control-sm" id="submissionurl" bind:value={work.submission_url}>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-3 text-sm-end">
|
||||
<label for="gradationrepo" class="col-form-label col-form-label-sm">Dépôt des tests automatiques</label>
|
||||
</div>
|
||||
<div class="col-sm-10 col-md-8 col-lg-4 d-flex align-items-center">
|
||||
{#await grepositoriesP}
|
||||
<div class="spinner-border spinner-border-sm" role="status">
|
||||
<span class="visually-hidden">Loading...</span>
|
||||
</div>
|
||||
{:then grepositories}
|
||||
<div class="input-group">
|
||||
<select class="form-select form-select-sm" id="gradationrepo" bind:value={work.gradation_repo}>
|
||||
<option value={null}>-</option>
|
||||
{#each grepositories as r}
|
||||
<option value={r.slug}>{r.slug}</option>
|
||||
{/each}
|
||||
</select>
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-light btn-sm"
|
||||
title="Synchroniser les dépôts"
|
||||
on:click={() => grepositoriesP = syncGradationRepositories()}
|
||||
>
|
||||
<i class="bi bi-arrow-repeat"></i>
|
||||
</button>
|
||||
</div>
|
||||
{/await}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-3 text-sm-end">
|
||||
<label for="start_availability" class="col-form-label col-form-label-sm">Date de début</label>
|
||||
|
19
ui/src/lib/gradation.js
Normal file
19
ui/src/lib/gradation.js
Normal file
@ -0,0 +1,19 @@
|
||||
export async function getGradationRepositories() {
|
||||
let url = '/api/gradation_repositories';
|
||||
const res = await fetch(url, {headers: {'Accept': 'application/json'}})
|
||||
if (res.status == 200) {
|
||||
return await res.json();
|
||||
} else {
|
||||
throw new Error((await res.json()).errmsg);
|
||||
}
|
||||
}
|
||||
|
||||
export async function syncGradationRepositories() {
|
||||
let url = '/api/gradation_repositories/sync';
|
||||
const res = await fetch(url, {method: 'post', headers: {'Accept': 'application/json'}})
|
||||
if (res.status == 200) {
|
||||
return await res.json();
|
||||
} else {
|
||||
throw new Error((await res.json()).errmsg);
|
||||
}
|
||||
}
|
@ -6,7 +6,7 @@ export class Work {
|
||||
}
|
||||
}
|
||||
|
||||
update({ id, id_category, title, promo, group, shown, tag, description, descr_raw, submission_url, corrected, start_availability, end_availability }) {
|
||||
update({ id, id_category, title, promo, group, shown, tag, description, descr_raw, submission_url, gradation_repo, corrected, start_availability, end_availability }) {
|
||||
this.id = id;
|
||||
this.id_category = id_category;
|
||||
this.title = title;
|
||||
@ -17,6 +17,7 @@ export class Work {
|
||||
this.description = description;
|
||||
this.descr_raw = descr_raw;
|
||||
this.submission_url = submission_url;
|
||||
this.gradation_repo = gradation_repo;
|
||||
this.corrected = corrected;
|
||||
if (this.start_availability != start_availability) {
|
||||
this.start_availability = start_availability;
|
||||
|
17
works.go
17
works.go
@ -108,7 +108,7 @@ func declareAPIAdminWorksRoutes(router *gin.RouterGroup) {
|
||||
new.Promo = currentPromo
|
||||
}
|
||||
|
||||
work, err := NewWork(new.IdCategory, new.Title, new.Promo, new.Group, new.Shown, new.DescriptionRaw, new.Tag, new.SubmissionURL, new.StartAvailability, new.EndAvailability)
|
||||
work, err := NewWork(new.IdCategory, new.Title, new.Promo, new.Group, new.Shown, new.DescriptionRaw, new.Tag, new.SubmissionURL, new.GradationRepo, new.StartAvailability, new.EndAvailability)
|
||||
if err != nil {
|
||||
log.Println("Unable to NewWork:", err)
|
||||
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "An error occurs during work creation"})
|
||||
@ -304,20 +304,21 @@ type Work struct {
|
||||
DescriptionRaw string `json:"descr_raw,omitempty"`
|
||||
Tag string `json:"tag,omitempty"`
|
||||
SubmissionURL *string `json:"submission_url,omitempty"`
|
||||
GradationRepo *string `json:"gradation_repo"`
|
||||
Corrected bool `json:"corrected,omitempty"`
|
||||
StartAvailability time.Time `json:"start_availability"`
|
||||
EndAvailability time.Time `json:"end_availability"`
|
||||
}
|
||||
|
||||
func getWorks(cnd string, param ...interface{}) (items []*Work, err error) {
|
||||
if rows, errr := DBQuery("SELECT id_work, id_category, title, promo, grp, shown, description, tag, submission_url, corrected, start_availability, end_availability FROM works "+cnd, param...); errr != nil {
|
||||
if rows, errr := DBQuery("SELECT id_work, id_category, title, promo, grp, shown, description, tag, submission_url, gradation_repo, corrected, start_availability, end_availability FROM works "+cnd, param...); errr != nil {
|
||||
return nil, errr
|
||||
} else {
|
||||
defer rows.Close()
|
||||
|
||||
for rows.Next() {
|
||||
var w Work
|
||||
if err = rows.Scan(&w.Id, &w.IdCategory, &w.Title, &w.Promo, &w.Group, &w.Shown, &w.DescriptionRaw, &w.Tag, &w.SubmissionURL, &w.Corrected, &w.StartAvailability, &w.EndAvailability); err != nil {
|
||||
if err = rows.Scan(&w.Id, &w.IdCategory, &w.Title, &w.Promo, &w.Group, &w.Shown, &w.DescriptionRaw, &w.Tag, &w.SubmissionURL, &w.GradationRepo, &w.Corrected, &w.StartAvailability, &w.EndAvailability); err != nil {
|
||||
return
|
||||
}
|
||||
items = append(items, &w)
|
||||
@ -332,23 +333,23 @@ func getWorks(cnd string, param ...interface{}) (items []*Work, err error) {
|
||||
|
||||
func getWork(id int) (w *Work, err error) {
|
||||
w = new(Work)
|
||||
err = DBQueryRow("SELECT id_work, id_category, title, promo, grp, shown, description, tag, submission_url, corrected, start_availability, end_availability FROM works WHERE id_work=?", id).Scan(&w.Id, &w.IdCategory, &w.Title, &w.Promo, &w.Group, &w.Shown, &w.DescriptionRaw, &w.Tag, &w.SubmissionURL, &w.Corrected, &w.StartAvailability, &w.EndAvailability)
|
||||
err = DBQueryRow("SELECT id_work, id_category, title, promo, grp, shown, description, tag, submission_url, gradation_repo, corrected, start_availability, end_availability FROM works WHERE id_work=?", id).Scan(&w.Id, &w.IdCategory, &w.Title, &w.Promo, &w.Group, &w.Shown, &w.DescriptionRaw, &w.Tag, &w.SubmissionURL, &w.GradationRepo, &w.Corrected, &w.StartAvailability, &w.EndAvailability)
|
||||
w.Description = string(blackfriday.Run([]byte(w.DescriptionRaw)))
|
||||
return
|
||||
}
|
||||
|
||||
func NewWork(id_category int64, title string, promo uint, group string, shown bool, description string, tag string, submissionurl *string, startAvailability time.Time, endAvailability time.Time) (*Work, error) {
|
||||
if res, err := DBExec("INSERT INTO works (id_category, title, promo, grp, shown, description, tag, submission_url, start_availability, end_availability) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", id_category, title, promo, group, shown, description, tag, submissionurl, startAvailability, endAvailability); err != nil {
|
||||
func NewWork(id_category int64, title string, promo uint, group string, shown bool, description string, tag string, submissionurl *string, gradation_repo *string, startAvailability time.Time, endAvailability time.Time) (*Work, error) {
|
||||
if res, err := DBExec("INSERT INTO works (id_category, title, promo, grp, shown, description, tag, submission_url, gradation_repo, start_availability, end_availability) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", id_category, title, promo, group, shown, description, tag, submissionurl, gradation_repo, startAvailability, endAvailability); err != nil {
|
||||
return nil, err
|
||||
} else if wid, err := res.LastInsertId(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return &Work{wid, id_category, title, promo, group, shown, description, description, tag, submissionurl, false, startAvailability, endAvailability}, nil
|
||||
return &Work{wid, id_category, title, promo, group, shown, description, description, tag, submissionurl, gradation_repo, false, startAvailability, endAvailability}, nil
|
||||
}
|
||||
}
|
||||
|
||||
func (w *Work) Update() (*Work, error) {
|
||||
if _, err := DBExec("UPDATE works SET id_category = ?, title = ?, promo = ?, grp = ?, shown = ?, description = ?, tag = ?, submission_url = ?, corrected = ?, start_availability = ?, end_availability = ? WHERE id_work = ?", w.IdCategory, w.Title, w.Promo, w.Group, w.Shown, w.DescriptionRaw, w.Tag, w.SubmissionURL, w.Corrected, w.StartAvailability, w.EndAvailability, w.Id); err != nil {
|
||||
if _, err := DBExec("UPDATE works SET id_category = ?, title = ?, promo = ?, grp = ?, shown = ?, description = ?, tag = ?, submission_url = ?, gradation_repo = ?, corrected = ?, start_availability = ?, end_availability = ? WHERE id_work = ?", w.IdCategory, w.Title, w.Promo, w.Group, w.Shown, w.DescriptionRaw, w.Tag, w.SubmissionURL, w.GradationRepo, w.Corrected, w.StartAvailability, w.EndAvailability, w.Id); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
w.Description = string(blackfriday.Run([]byte(w.DescriptionRaw)))
|
||||
|
Reference in New Issue
Block a user