From 0a8e352622b2071297423cfcdd208ccb9fc1fc51 Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Sat, 2 Nov 2019 16:30:41 +0100 Subject: [PATCH 1/7] go format --- main.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 3796ce8..8ce5285 100644 --- a/main.go +++ b/main.go @@ -136,7 +136,7 @@ func genStudent(login string) map[string]*Submission { ret[dir.Name()] = new(Submission) ret[dir.Name()].Date = fi.ModTime() if lnk, err := os.Readlink(p); err == nil { - ret[dir.Name()].Hash = strings.TrimPrefix(lnk, login + ".") + ret[dir.Name()].Hash = strings.TrimPrefix(lnk, login+".") } } else { ret[dir.Name()] = nil @@ -211,7 +211,7 @@ func main() { http.HandleFunc("/", Serve) http.HandleFunc("/rendus.json", ServeJSON) for _, student := range students { - http.HandleFunc("/" + student[2] + ".json", ServeJSONStudent) + http.HandleFunc("/"+student[2]+".json", ServeJSONStudent) } log.Println(fmt.Sprintf("Ready, listening on %s", *bind)) if err := http.ListenAndServe(*bind, nil); err != nil { From b2d2cd860c89dc68974dd3adc99fd739ddfad338 Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Sat, 2 Nov 2019 16:31:13 +0100 Subject: [PATCH 2/7] Update to latest bootstrap 3 --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index 8ce5285..d1597e1 100644 --- a/main.go +++ b/main.go @@ -30,7 +30,7 @@ func Serve(w http.ResponseWriter, r *http.Request) { ` + title + ` - + From 364124db351c97fc53f249910fd8ecc46c93058f Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Sun, 3 Nov 2019 00:35:27 +0100 Subject: [PATCH 3/7] Add a page for each student --- main.go | 53 ++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 46 insertions(+), 7 deletions(-) diff --git a/main.go b/main.go index d1597e1..8df516c 100644 --- a/main.go +++ b/main.go @@ -68,6 +68,35 @@ function disp(rendus) { document.getElementById("head").appendChild(col); }); } + +function disp_std(rendus, login) { + Object.keys(rendus).map(function(label) { + var work = rendus[label]; + + var row = document.createElement("tr"); + + var col = document.createElement("th"); + col.innerHTML = label; + row.appendChild(col); + + if (work) { + var col = document.createElement("td"); + col.className = "success"; + col.innerHTML = work["date"] + "
" + work["hash"]; + row.appendChild(col); + } else { + var col = document.createElement("td"); + col.className = "danger"; + col.innerHTML = ""; + row.appendChild(col); + } + + document.getElementById("students").appendChild(row); +}); + var col = document.createElement("th"); + col.innerHTML = login; + document.getElementById("head").appendChild(col); +} @@ -80,13 +109,23 @@ function disp(rendus) { From e9cc2e1331bf138863d0a5e7bd62fdfd05af9ed1 Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Fri, 24 Sep 2021 09:44:26 +0200 Subject: [PATCH 4/7] Add go.mod --- go.mod | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 go.mod diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..7f21d4b --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module git.nemunai.re/shemu + +go 1.10 From e486ad0c1b9be174442783324612f1488186363b Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Fri, 24 Sep 2021 09:54:25 +0200 Subject: [PATCH 5/7] Can pass multiple students files (concatenate them) --- main.go | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/main.go b/main.go index 8df516c..cf8c080 100644 --- a/main.go +++ b/main.go @@ -205,11 +205,22 @@ func ServeJSONStudent(w http.ResponseWriter, r *http.Request) { } } +type arrayFlags []string + +func (i *arrayFlags) String() string { + return fmt.Sprintf("%v", *i) +} + +func (i *arrayFlags) Set(value string) error { + *i = append(*i, value) + return nil +} + func main() { - var studentsFile string + var studentsFiles arrayFlags var bind = flag.String("bind", "0.0.0.0:8081", "Bind port/socket") - flag.StringVar(&studentsFile, "students", "./students.csv", "Path to a CSV file containing in the third column the name of the directory to look for") + flag.Var(&studentsFiles, "students", "Path to a CSV file containing in the third column the name of the directory to look for (can be repeated multiple times)") flag.StringVar(&rendusDir, "path", "./rendu/", "Path to the submissions directory (each subdirectory is a project)") flag.StringVar(&title, "title", "Rendus VIRLI", "Title of the page") flag.Parse() @@ -234,14 +245,21 @@ func main() { // Read and parse students list log.Println("Reading students files...") - if studentsFile, err = filepath.Abs(studentsFile); err != nil { - log.Fatal(err) - } else if fi, err := os.Open(studentsFile); err != nil { - log.Fatal(err) - } else { - r := csv.NewReader(bufio.NewReader(fi)) - if students, err = r.ReadAll(); err != nil { + for _, studentsFile := range studentsFiles { + log.Println("Reading", studentsFile, "...") + if studentsFile, err = filepath.Abs(studentsFile); err != nil { log.Fatal(err) + } else if fi, err := os.Open(studentsFile); err != nil { + log.Fatal(err) + } else { + var nstudents [][]string + + r := csv.NewReader(bufio.NewReader(fi)) + if nstudents, err = r.ReadAll(); err != nil { + log.Fatal(err) + } + + students = append(students, nstudents...) } } log.Println(len(students), "students loaded.") From bf556753b38cfc6db50c390bad1d9ec36a6760e6 Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Fri, 24 Sep 2021 09:54:55 +0200 Subject: [PATCH 6/7] Rework ui to try to fit into screen --- main.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index cf8c080..0b00bab 100644 --- a/main.go +++ b/main.go @@ -33,6 +33,7 @@ func Serve(w http.ResponseWriter, r *http.Request) {