dashboard: use last path item to handle TP number selection
This commit is contained in:
parent
6086b82181
commit
8d55ecc3af
@ -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();
|
||||
|
@ -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)
|
||||
})
|
||||
|
@ -7,6 +7,7 @@ import (
|
||||
"net/http"
|
||||
"path"
|
||||
"strings"
|
||||
"strconv"
|
||||
|
||||
"github.com/julienschmidt/httprouter"
|
||||
)
|
||||
@ -61,21 +62,35 @@ func init() {
|
||||
w.Write(data)
|
||||
}
|
||||
})
|
||||
Router().GET("/dashboard/css/*_", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||
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 {
|
||||
if data, err := Asset("htdocs/dashboard.html"); err != nil {
|
||||
fmt.Fprintf(w, "{\"errmsg\":%q}", err)
|
||||
} else {
|
||||
w.Write(data)
|
||||
}
|
||||
}
|
||||
})
|
||||
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)
|
||||
}
|
||||
})
|
||||
Router().GET("/dashboard/js/*_", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||
} 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 {
|
||||
http.NotFound(w, r)
|
||||
}
|
||||
})
|
||||
|
||||
Router().GET("/maatma/", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||
|
Reference in New Issue
Block a user