diff --git a/model/torrent.go b/model/torrent.go
index 0d2dcde2..4393ad7d 100644
--- a/model/torrent.go
+++ b/model/torrent.go
@@ -35,7 +35,7 @@ type Torrent struct {
WebsiteLink string `gorm:"column:website_link"`
DeletedAt *time.Time
- Uploader *User `gorm:"ForeignKey:UploaderId"`
+ Uploader *User `gorm:"ForeignKey:uploader"`
OldUploader string `gorm:"-"` // ???????
OldComments []OldComment `gorm:"ForeignKey:torrent_id"`
Comments []Comment `gorm:"ForeignKey:torrent_id"`
diff --git a/router/modpanel.go b/router/modpanel.go
index 36182df5..a2bf5179 100644
--- a/router/modpanel.go
+++ b/router/modpanel.go
@@ -17,6 +17,7 @@ import (
"github.com/ewhal/nyaa/service/user/permission"
"github.com/ewhal/nyaa/util/languages"
"github.com/ewhal/nyaa/util/modelHelper"
+ "github.com/gorilla/mux"
)
var panelIndex, panelTorrentList, panelUserList, panelCommentList, panelTorrentEd *template.Template
@@ -34,11 +35,11 @@ func IndexModPanel(w http.ResponseWriter, r *http.Request) {
if userPermission.HasAdmin(currentUser) {
offset := 10
- torrents, _, _ := torrentService.GetAllTorrents(0, offset)
- users, _ := userService.RetrieveUsersForAdmin(0, offset)
- comments, _ := commentService.GetAllComments(0, offset, "", "")
+ torrents, _, _ := torrentService.GetAllTorrents(offset, 0)
+ users, _ := userService.RetrieveUsersForAdmin(offset, 0)
+ comments, _ := commentService.GetAllComments(offset, 0, "", "")
languages.SetTranslationFromRequest(panelIndex, r, "en-us")
- htv := PanelIndexVbs{torrents, users, comments}
+ htv := PanelIndexVbs{torrents, users, comments, r.URL}
_ = panelIndex.ExecuteTemplate(w, "admin_index.html", htv)
} else {
http.Error(w, "admins only", http.StatusForbidden)
@@ -47,12 +48,13 @@ func IndexModPanel(w http.ResponseWriter, r *http.Request) {
func TorrentsListPanel(w http.ResponseWriter, r *http.Request) {
currentUser := GetUser(r)
if userPermission.HasAdmin(currentUser) {
- page, _ := strconv.Atoi(r.URL.Query().Get("p"))
+ vars := mux.Vars(r)
+ page, _ := strconv.Atoi(vars["page"])
offset := 100
torrents, nbTorrents, _ := torrentService.GetAllTorrents(offset, page * offset)
languages.SetTranslationFromRequest(panelTorrentList, r, "en-us")
- htv := PanelTorrentListVbs{torrents, Navigation{nbTorrents, offset, page, "mod_tlist_page"}}
+ htv := PanelTorrentListVbs{torrents, Navigation{nbTorrents, offset, page, "mod_tlist_page"}, r.URL}
err := panelTorrentList.ExecuteTemplate(w, "admin_index.html", htv)
fmt.Println(err)
} else {
@@ -63,12 +65,13 @@ func TorrentsListPanel(w http.ResponseWriter, r *http.Request) {
func UsersListPanel(w http.ResponseWriter, r *http.Request) {
currentUser := GetUser(r)
if userPermission.HasAdmin(currentUser) {
- page, _ := strconv.Atoi(r.URL.Query().Get("p"))
+ vars := mux.Vars(r)
+ page, _ := strconv.Atoi(vars["page"])
offset := 100
users, nbUsers := userService.RetrieveUsersForAdmin(offset, page*offset)
languages.SetTranslationFromRequest(panelUserList, r, "en-us")
- htv := PanelUserListVbs{users, Navigation{nbUsers, offset, page, "mod_ulist_page"}}
+ htv := PanelUserListVbs{users, Navigation{nbUsers, offset, page, "mod_ulist_page"}, r.URL}
err := panelUserList.ExecuteTemplate(w, "admin_index.html", htv)
fmt.Println(err)
} else {
@@ -78,7 +81,8 @@ func UsersListPanel(w http.ResponseWriter, r *http.Request) {
func CommentsListPanel(w http.ResponseWriter, r *http.Request) {
currentUser := GetUser(r)
if userPermission.HasAdmin(currentUser) {
- page, _ := strconv.Atoi(r.URL.Query().Get("p"))
+ vars := mux.Vars(r)
+ page, _ := strconv.Atoi(vars["page"])
offset := 100
userid := r.URL.Query().Get("userid")
var conditions string
@@ -89,7 +93,7 @@ func CommentsListPanel(w http.ResponseWriter, r *http.Request) {
}
comments, nbComments := commentService.GetAllComments(offset, page * offset, conditions, values...)
languages.SetTranslationFromRequest(panelCommentList, r, "en-us")
- htv := PanelCommentListVbs{comments, Navigation{nbComments, offset, page, "mod_clist_page"}}
+ htv := PanelCommentListVbs{comments, Navigation{nbComments, offset, page, "mod_clist_page"}, r.URL}
err := panelCommentList.ExecuteTemplate(w, "admin_index.html", htv)
fmt.Println(err)
} else {
diff --git a/router/router.go b/router/router.go
index 3f9a3c39..16ce6e3c 100644
--- a/router/router.go
+++ b/router/router.go
@@ -87,7 +87,7 @@ func init() {
Router.Handle("/mod/torrents", gzipTorrentsListPanel).Name("mod_tlist")
Router.Handle("/mod/torrents/{page}", gzipTorrentsListPanel).Name("mod_tlist_page")
Router.Handle("/mod/users", gzipUsersListPanel).Name("mod_ulist")
- Router.Handle("/mod/users/{page}", gzipUsersListPanel).Name("mod_ulist")
+ Router.Handle("/mod/users/{page}", gzipUsersListPanel).Name("mod_ulist_page")
Router.Handle("/mod/comments", gzipCommentsListPanel).Name("mod_clist")
Router.Handle("/mod/comments/{page}", gzipCommentsListPanel).Name("mod_clist_page")
Router.Handle("/mod/comment", gzipCommentsListPanel).Name("mod_cedit") // TODO
diff --git a/router/templateFunctions.go b/router/templateFunctions.go
index 9f974f71..51e497ec 100644
--- a/router/templateFunctions.go
+++ b/router/templateFunctions.go
@@ -27,9 +27,10 @@ var FuncMap = template.FuncMap{
return "error"
},
"genNav": func(nav Navigation, currentUrl *url.URL, pagesSelectable int) template.HTML {
+ var ret = ""
+ if (nav.TotalItem > 0) {
maxPages := math.Ceil(float64(nav.TotalItem) / float64(nav.MaxItemPerPage))
- var ret = ""
if nav.CurrentPage-1 > 0 {
url, _ := Router.Get(nav.Route).URL("page", "1")
ret = ret + "
« "
@@ -57,6 +58,7 @@ var FuncMap = template.FuncMap{
url, _ := Router.Get(nav.Route).URL("page", strconv.Itoa(nav.CurrentPage+1))
ret = ret + "» "
}
+ }
return template.HTML(ret)
},
"T": i18n.IdentityTfunc,
diff --git a/router/templateVariables.go b/router/templateVariables.go
index b64ad14a..9f197be4 100644
--- a/router/templateVariables.go
+++ b/router/templateVariables.go
@@ -117,20 +117,23 @@ type PanelIndexVbs struct {
Torrents []model.Torrent
Users []model.User
Comments []model.Comment
+ URL *url.URL // For parsing Url in templates
}
type PanelTorrentListVbs struct {
Torrents []model.Torrent
Navigation Navigation
+ URL *url.URL // For parsing Url in templates
}
type PanelUserListVbs struct {
Users []model.User
Navigation Navigation
+ URL *url.URL // For parsing Url in templates
}
type PanelCommentListVbs struct {
Comments []model.Comment
Navigation Navigation
-
+ URL *url.URL // For parsing Url in templates
}
type PanelTorrentEdVbs struct {
Torrent model.Torrent
diff --git a/templates/admin/panelindex.html b/templates/admin/panelindex.html
index dc6d7953..5bf0f034 100644
--- a/templates/admin/panelindex.html
+++ b/templates/admin/panelindex.html
@@ -1,24 +1,33 @@
{{define "content"}}
-nigga this just be some links
-torrent list
-user list
-comments list
+Last Torrents
+
+
+
+Last Users
+
+
+
+
{{ range .Comments}}
@@ -26,4 +35,9 @@ nigga this just be some links
Delete
{{end}}
+
+
+
{{end}}
\ No newline at end of file
diff --git a/templates/admin/torrentlist.html b/templates/admin/torrentlist.html
index 1f61bd94..7c539d9f 100644
--- a/templates/admin/torrentlist.html
+++ b/templates/admin/torrentlist.html
@@ -2,7 +2,7 @@
diff --git a/templates/admin_index.html b/templates/admin_index.html
index 4ff1b519..b79e498f 100644
--- a/templates/admin_index.html
+++ b/templates/admin_index.html
@@ -27,10 +27,45 @@
+
+
+
+
+
+ {{block "badge_user" .}}{{end}}
+
+
+
+
+
+
{{block "content" .}}{{end}}
-
+
+ Powered by NyaaPantsu
+