dashboard: use last path item to handle TP number selection

This commit is contained in:
nemunaire 2020-02-28 13:23:11 +01:00
parent 6086b82181
commit 8d55ecc3af
3 changed files with 39 additions and 14 deletions

View File

@ -38,7 +38,13 @@ angular.module("AdLinApp", ["ngResource", "ngSanitize"])
angular.module("AdLinApp")
.run(function($rootScope, $location) {
$rootScope.tutoid = 0;
if (window.location.pathname.split("/").length >= 3) {
$rootScope.tutoid = parseInt(window.location.pathname.split("/")[2], 10);
}
if (!$rootScope.tutoid || isNaN($rootScope.tutoid)) {
$rootScope.tutoid = 1;
}
$rootScope.tutoid--;
})
.controller("StudentsController", function($scope, $interval, Student) {
$scope.students = Student.query();

View File

@ -8,6 +8,7 @@ import (
"os"
"path"
"path/filepath"
"strconv"
"strings"
"github.com/julienschmidt/httprouter"
@ -38,11 +39,14 @@ func init() {
Router().GET("/dashboard/", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
http.ServeFile(w, r, path.Join(StaticDir, "dashboard.html"))
})
Router().GET("/dashboard/css/*_", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
r.URL.Path = strings.TrimPrefix(r.URL.Path, "/dashboard")
serveStaticAsset(w, r)
Router().GET("/dashboard/:where", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
if _, err := strconv.ParseInt(string(ps.ByName("where")), 10, 64); err != nil {
http.NotFound(w, r)
} else {
http.ServeFile(w, r, path.Join(StaticDir, "dashboard.html"))
}
})
Router().GET("/dashboard/js/*_", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
Router().GET("/dashboard/:where/*_", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
r.URL.Path = strings.TrimPrefix(r.URL.Path, "/dashboard")
serveStaticAsset(w, r)
})

View File

@ -7,6 +7,7 @@ import (
"net/http"
"path"
"strings"
"strconv"
"github.com/julienschmidt/httprouter"
)
@ -61,20 +62,34 @@ func init() {
w.Write(data)
}
})
Router().GET("/dashboard/css/*_", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
w.Header().Set("Content-Type", "text/css")
if data, err := Asset(path.Join("htdocs", strings.TrimPrefix(r.URL.Path, "/dashboard"))); err != nil {
Router().GET("/dashboard/:where", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
if _, err := strconv.ParseInt(string(ps.ByName("where")), 10, 64); err != nil {
http.NotFound(w, r)
} else {
w.Write(data)
if data, err := Asset("htdocs/dashboard.html"); err != nil {
fmt.Fprintf(w, "{\"errmsg\":%q}", err)
} else {
w.Write(data)
}
}
})
Router().GET("/dashboard/js/*_", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
w.Header().Set("Content-Type", "text/javascript")
if data, err := Asset(path.Join("htdocs", strings.TrimPrefix(r.URL.Path, "/dashboard"))); err != nil {
http.NotFound(w, r)
Router().GET("/dashboard/:where/*_", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
if ps.ByName("where") == "css" {
w.Header().Set("Content-Type", "text/css")
if data, err := Asset(path.Join("htdocs", strings.TrimPrefix(r.URL.Path, "/dashboard"))); err != nil {
http.NotFound(w, r)
} else {
w.Write(data)
}
} else if ps.ByName("where") == "js" {
w.Header().Set("Content-Type", "text/javascript")
if data, err := Asset(path.Join("htdocs", strings.TrimPrefix(r.URL.Path, "/dashboard"))); err != nil {
http.NotFound(w, r)
} else {
w.Write(data)
}
} else {
w.Write(data)
http.NotFound(w, r)
}
})