Fixed
Cette révision appartient à :
Parent
54991542cb
révision
032688f532
8 fichiers modifiés avec 81 ajouts et 23 suppressions
|
@ -35,7 +35,7 @@ type Torrent struct {
|
||||||
WebsiteLink string `gorm:"column:website_link"`
|
WebsiteLink string `gorm:"column:website_link"`
|
||||||
DeletedAt *time.Time
|
DeletedAt *time.Time
|
||||||
|
|
||||||
Uploader *User `gorm:"ForeignKey:UploaderId"`
|
Uploader *User `gorm:"ForeignKey:uploader"`
|
||||||
OldUploader string `gorm:"-"` // ???????
|
OldUploader string `gorm:"-"` // ???????
|
||||||
OldComments []OldComment `gorm:"ForeignKey:torrent_id"`
|
OldComments []OldComment `gorm:"ForeignKey:torrent_id"`
|
||||||
Comments []Comment `gorm:"ForeignKey:torrent_id"`
|
Comments []Comment `gorm:"ForeignKey:torrent_id"`
|
||||||
|
|
|
@ -17,6 +17,7 @@ import (
|
||||||
"github.com/ewhal/nyaa/service/user/permission"
|
"github.com/ewhal/nyaa/service/user/permission"
|
||||||
"github.com/ewhal/nyaa/util/languages"
|
"github.com/ewhal/nyaa/util/languages"
|
||||||
"github.com/ewhal/nyaa/util/modelHelper"
|
"github.com/ewhal/nyaa/util/modelHelper"
|
||||||
|
"github.com/gorilla/mux"
|
||||||
)
|
)
|
||||||
|
|
||||||
var panelIndex, panelTorrentList, panelUserList, panelCommentList, panelTorrentEd *template.Template
|
var panelIndex, panelTorrentList, panelUserList, panelCommentList, panelTorrentEd *template.Template
|
||||||
|
@ -34,11 +35,11 @@ func IndexModPanel(w http.ResponseWriter, r *http.Request) {
|
||||||
if userPermission.HasAdmin(currentUser) {
|
if userPermission.HasAdmin(currentUser) {
|
||||||
offset := 10
|
offset := 10
|
||||||
|
|
||||||
torrents, _, _ := torrentService.GetAllTorrents(0, offset)
|
torrents, _, _ := torrentService.GetAllTorrents(offset, 0)
|
||||||
users, _ := userService.RetrieveUsersForAdmin(0, offset)
|
users, _ := userService.RetrieveUsersForAdmin(offset, 0)
|
||||||
comments, _ := commentService.GetAllComments(0, offset, "", "")
|
comments, _ := commentService.GetAllComments(offset, 0, "", "")
|
||||||
languages.SetTranslationFromRequest(panelIndex, r, "en-us")
|
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)
|
_ = panelIndex.ExecuteTemplate(w, "admin_index.html", htv)
|
||||||
} else {
|
} else {
|
||||||
http.Error(w, "admins only", http.StatusForbidden)
|
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) {
|
func TorrentsListPanel(w http.ResponseWriter, r *http.Request) {
|
||||||
currentUser := GetUser(r)
|
currentUser := GetUser(r)
|
||||||
if userPermission.HasAdmin(currentUser) {
|
if userPermission.HasAdmin(currentUser) {
|
||||||
page, _ := strconv.Atoi(r.URL.Query().Get("p"))
|
vars := mux.Vars(r)
|
||||||
|
page, _ := strconv.Atoi(vars["page"])
|
||||||
offset := 100
|
offset := 100
|
||||||
|
|
||||||
torrents, nbTorrents, _ := torrentService.GetAllTorrents(offset, page * offset)
|
torrents, nbTorrents, _ := torrentService.GetAllTorrents(offset, page * offset)
|
||||||
languages.SetTranslationFromRequest(panelTorrentList, r, "en-us")
|
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)
|
err := panelTorrentList.ExecuteTemplate(w, "admin_index.html", htv)
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
} else {
|
} else {
|
||||||
|
@ -63,12 +65,13 @@ func TorrentsListPanel(w http.ResponseWriter, r *http.Request) {
|
||||||
func UsersListPanel(w http.ResponseWriter, r *http.Request) {
|
func UsersListPanel(w http.ResponseWriter, r *http.Request) {
|
||||||
currentUser := GetUser(r)
|
currentUser := GetUser(r)
|
||||||
if userPermission.HasAdmin(currentUser) {
|
if userPermission.HasAdmin(currentUser) {
|
||||||
page, _ := strconv.Atoi(r.URL.Query().Get("p"))
|
vars := mux.Vars(r)
|
||||||
|
page, _ := strconv.Atoi(vars["page"])
|
||||||
offset := 100
|
offset := 100
|
||||||
|
|
||||||
users, nbUsers := userService.RetrieveUsersForAdmin(offset, page*offset)
|
users, nbUsers := userService.RetrieveUsersForAdmin(offset, page*offset)
|
||||||
languages.SetTranslationFromRequest(panelUserList, r, "en-us")
|
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)
|
err := panelUserList.ExecuteTemplate(w, "admin_index.html", htv)
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
} else {
|
} else {
|
||||||
|
@ -78,7 +81,8 @@ func UsersListPanel(w http.ResponseWriter, r *http.Request) {
|
||||||
func CommentsListPanel(w http.ResponseWriter, r *http.Request) {
|
func CommentsListPanel(w http.ResponseWriter, r *http.Request) {
|
||||||
currentUser := GetUser(r)
|
currentUser := GetUser(r)
|
||||||
if userPermission.HasAdmin(currentUser) {
|
if userPermission.HasAdmin(currentUser) {
|
||||||
page, _ := strconv.Atoi(r.URL.Query().Get("p"))
|
vars := mux.Vars(r)
|
||||||
|
page, _ := strconv.Atoi(vars["page"])
|
||||||
offset := 100
|
offset := 100
|
||||||
userid := r.URL.Query().Get("userid")
|
userid := r.URL.Query().Get("userid")
|
||||||
var conditions string
|
var conditions string
|
||||||
|
@ -89,7 +93,7 @@ func CommentsListPanel(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
comments, nbComments := commentService.GetAllComments(offset, page * offset, conditions, values...)
|
comments, nbComments := commentService.GetAllComments(offset, page * offset, conditions, values...)
|
||||||
languages.SetTranslationFromRequest(panelCommentList, r, "en-us")
|
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)
|
err := panelCommentList.ExecuteTemplate(w, "admin_index.html", htv)
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -87,7 +87,7 @@ func init() {
|
||||||
Router.Handle("/mod/torrents", gzipTorrentsListPanel).Name("mod_tlist")
|
Router.Handle("/mod/torrents", gzipTorrentsListPanel).Name("mod_tlist")
|
||||||
Router.Handle("/mod/torrents/{page}", gzipTorrentsListPanel).Name("mod_tlist_page")
|
Router.Handle("/mod/torrents/{page}", gzipTorrentsListPanel).Name("mod_tlist_page")
|
||||||
Router.Handle("/mod/users", gzipUsersListPanel).Name("mod_ulist")
|
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", gzipCommentsListPanel).Name("mod_clist")
|
||||||
Router.Handle("/mod/comments/{page}", gzipCommentsListPanel).Name("mod_clist_page")
|
Router.Handle("/mod/comments/{page}", gzipCommentsListPanel).Name("mod_clist_page")
|
||||||
Router.Handle("/mod/comment", gzipCommentsListPanel).Name("mod_cedit") // TODO
|
Router.Handle("/mod/comment", gzipCommentsListPanel).Name("mod_cedit") // TODO
|
||||||
|
|
|
@ -27,9 +27,10 @@ var FuncMap = template.FuncMap{
|
||||||
return "error"
|
return "error"
|
||||||
},
|
},
|
||||||
"genNav": func(nav Navigation, currentUrl *url.URL, pagesSelectable int) template.HTML {
|
"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))
|
maxPages := math.Ceil(float64(nav.TotalItem) / float64(nav.MaxItemPerPage))
|
||||||
|
|
||||||
var ret = ""
|
|
||||||
if nav.CurrentPage-1 > 0 {
|
if nav.CurrentPage-1 > 0 {
|
||||||
url, _ := Router.Get(nav.Route).URL("page", "1")
|
url, _ := Router.Get(nav.Route).URL("page", "1")
|
||||||
ret = ret + "<li><a id=\"page-prev\" href=\"" + url.String() + "?" + currentUrl.RawQuery + "\" aria-label=\"Previous\"><span aria-hidden=\"true\">«</span></a></li>"
|
ret = ret + "<li><a id=\"page-prev\" href=\"" + url.String() + "?" + currentUrl.RawQuery + "\" aria-label=\"Previous\"><span aria-hidden=\"true\">«</span></a></li>"
|
||||||
|
@ -57,6 +58,7 @@ var FuncMap = template.FuncMap{
|
||||||
url, _ := Router.Get(nav.Route).URL("page", strconv.Itoa(nav.CurrentPage+1))
|
url, _ := Router.Get(nav.Route).URL("page", strconv.Itoa(nav.CurrentPage+1))
|
||||||
ret = ret + "<li><a id=\"page-next\" href=\"" + url.String() + "?" + currentUrl.RawQuery + "\" aria-label=\"Next\"><span aria-hidden=\"true\">»</span></a></li>"
|
ret = ret + "<li><a id=\"page-next\" href=\"" + url.String() + "?" + currentUrl.RawQuery + "\" aria-label=\"Next\"><span aria-hidden=\"true\">»</span></a></li>"
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return template.HTML(ret)
|
return template.HTML(ret)
|
||||||
},
|
},
|
||||||
"T": i18n.IdentityTfunc,
|
"T": i18n.IdentityTfunc,
|
||||||
|
|
|
@ -117,20 +117,23 @@ type PanelIndexVbs struct {
|
||||||
Torrents []model.Torrent
|
Torrents []model.Torrent
|
||||||
Users []model.User
|
Users []model.User
|
||||||
Comments []model.Comment
|
Comments []model.Comment
|
||||||
|
URL *url.URL // For parsing Url in templates
|
||||||
}
|
}
|
||||||
|
|
||||||
type PanelTorrentListVbs struct {
|
type PanelTorrentListVbs struct {
|
||||||
Torrents []model.Torrent
|
Torrents []model.Torrent
|
||||||
Navigation Navigation
|
Navigation Navigation
|
||||||
|
URL *url.URL // For parsing Url in templates
|
||||||
}
|
}
|
||||||
type PanelUserListVbs struct {
|
type PanelUserListVbs struct {
|
||||||
Users []model.User
|
Users []model.User
|
||||||
Navigation Navigation
|
Navigation Navigation
|
||||||
|
URL *url.URL // For parsing Url in templates
|
||||||
}
|
}
|
||||||
type PanelCommentListVbs struct {
|
type PanelCommentListVbs struct {
|
||||||
Comments []model.Comment
|
Comments []model.Comment
|
||||||
Navigation Navigation
|
Navigation Navigation
|
||||||
|
URL *url.URL // For parsing Url in templates
|
||||||
}
|
}
|
||||||
type PanelTorrentEdVbs struct {
|
type PanelTorrentEdVbs struct {
|
||||||
Torrent model.Torrent
|
Torrent model.Torrent
|
||||||
|
|
|
@ -1,24 +1,33 @@
|
||||||
{{define "content"}}
|
{{define "content"}}
|
||||||
nigga this just be some links
|
<h3 id="torrents">Last Torrents</h3>
|
||||||
<a href="/mod/torrents">torrent list</a>
|
|
||||||
<a href="/mod/users">user list </a>
|
|
||||||
<a href="/mod/comments">comments list</a>
|
|
||||||
<table>
|
<table>
|
||||||
{{ range .Torrents}}
|
{{ range .Torrents}}
|
||||||
|
|
||||||
<tr><td><a href="{{ genRoute "mod_tedit" }}?id={{.ID}}">{{ .Name }}</a></td><td><a href="{{ genRoute "mod_tlist" }}?userid={{.UploaderID}}">{{ .Uploader.Username }}</a></td>
|
<tr><td><a href="{{ genRoute "mod_tedit" }}?id={{.ID}}">{{ .Name }}</a></td><td><a href="{{ genRoute "mod_tlist" }}?userid={{.UploaderID}}">{{ .UploaderID }}</a></td>
|
||||||
<td><a href="{{ genRoute "mod_tdelete" }}?id={{ .ID }}" class="btn btn-danger btn-lg" onclick="if (!confirm('Are you sure?')) return false;"><i class="glyphicon glyphicon-trash"></i>Delete</a></td></tr>
|
<td><a href="{{ genRoute "mod_tdelete" }}?id={{ .ID }}" class="btn btn-danger btn-lg" onclick="if (!confirm('Are you sure?')) return false;"><i class="glyphicon glyphicon-trash"></i>Delete</a></td></tr>
|
||||||
{{end}}
|
{{end}}
|
||||||
</table>
|
</table>
|
||||||
|
<nav class="torrentNav" aria-label="Page navigation">
|
||||||
|
<ul class="pagination">
|
||||||
|
<a href="{{ genRoute "mod_tlist" }}">More</a>
|
||||||
|
</ul>
|
||||||
|
</nav>
|
||||||
|
<h3 id="users">Last Users</h3>
|
||||||
<table>
|
<table>
|
||||||
{{ range .Users}}
|
{{ range .Users}}
|
||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<td><a href="{{ genRoute "user_profile" "id" ( print .ID ) "username" .Username }}?edit">{{ .Username }}</a></td>
|
<td><a href="{{ genRoute "user_profile" "id" (print .ID) "username" .Username }}?edit">{{ .Username }}</a></td>
|
||||||
<td><a href="{{ genRoute "user_profile" "id" ( print .ID ) "username" .Username }}?delete" class="btn btn-danger btn-lg" onclick="if (!confirm('Are you sure?')) return false;"><i class="glyphicon glyphicon-trash"></i>Delete</a></td>
|
<td><a href="{{ genRoute "user_profile" "id" (print .ID) "username" .Username }}?delete" class="btn btn-danger btn-lg" onclick="if (!confirm('Are you sure?')) return false;"><i class="glyphicon glyphicon-trash"></i>Delete</a></td>
|
||||||
</tr>
|
</tr>
|
||||||
{{end}}
|
{{end}}
|
||||||
</table>
|
</table>
|
||||||
|
<nav class="torrentNav" aria-label="Page navigation">
|
||||||
|
<ul class="pagination">
|
||||||
|
<a href="{{ genRoute "mod_ulist" }}">More </a>
|
||||||
|
</ul>
|
||||||
|
</nav>
|
||||||
|
<h3 id="comments">Last Comments</h3>
|
||||||
<table>
|
<table>
|
||||||
{{ range .Comments}}
|
{{ range .Comments}}
|
||||||
|
|
||||||
|
@ -26,4 +35,9 @@ nigga this just be some links
|
||||||
<td><a href="{{ genRoute "mod_cdelete" }}?id={{ .ID }}" class="btn btn-danger btn-lg" onclick="if (!confirm('Are you sure?')) return false;"><i class="glyphicon glyphicon-trash"></i>Delete</a></td></tr>
|
<td><a href="{{ genRoute "mod_cdelete" }}?id={{ .ID }}" class="btn btn-danger btn-lg" onclick="if (!confirm('Are you sure?')) return false;"><i class="glyphicon glyphicon-trash"></i>Delete</a></td></tr>
|
||||||
{{end}}
|
{{end}}
|
||||||
</table>
|
</table>
|
||||||
|
<nav class="torrentNav" aria-label="Page navigation">
|
||||||
|
<ul class="pagination">
|
||||||
|
<a href="{{ genRoute "mod_ulist" }}">More</a>
|
||||||
|
</ul>
|
||||||
|
</nav>
|
||||||
{{end}}
|
{{end}}
|
|
@ -2,7 +2,7 @@
|
||||||
<table>
|
<table>
|
||||||
{{ range .Torrents}}
|
{{ range .Torrents}}
|
||||||
|
|
||||||
<tr><td><a href="{{ genRoute "mod_tedit" }}?id={{.ID}}">{{ .Name }}</a></td><td><a href="{{ genRoute "mod_tlist" }}?userid={{.UploaderID}}">{{ .Uploader.Username }}</a></td>
|
<tr><td><a href="{{ genRoute "mod_tedit" }}?id={{.ID}}">{{ .Name }}</a></td><td><a href="{{ genRoute "mod_tlist" }}?userid={{.UploaderID}}">{{ .UploaderID }}</a></td>
|
||||||
<td><a href="{{ genRoute "mod_tdelete" }}?id={{ .ID }}" class="btn btn-danger btn-lg" onclick="if (!confirm('Are you sure?')) return false;"><i class="glyphicon glyphicon-trash"></i>Delete</a></td></tr>
|
<td><a href="{{ genRoute "mod_tdelete" }}?id={{ .ID }}" class="btn btn-danger btn-lg" onclick="if (!confirm('Are you sure?')) return false;"><i class="glyphicon glyphicon-trash"></i>Delete</a></td></tr>
|
||||||
{{end}}
|
{{end}}
|
||||||
</table>
|
</table>
|
||||||
|
|
|
@ -27,10 +27,45 @@
|
||||||
<!-- Website CSS -->
|
<!-- Website CSS -->
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
<nav class="navbar navbar-default" id="mainmenu">
|
||||||
|
<div class="container">
|
||||||
|
<div class="navbar-header">
|
||||||
|
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
|
||||||
|
<span class="sr-only">{{ T "toggle_navigation" }}</span>
|
||||||
|
<span class="icon-bar"></span>
|
||||||
|
<span class="icon-bar"></span>
|
||||||
|
<span class="icon-bar"></span>
|
||||||
|
</button>
|
||||||
|
<a class="navbar-brand" href="{{.URL.Parse "/"}}">Nyaa Pantsu Moderation</a>
|
||||||
|
<a class="navbar-brand hidden-md pull-right nightswitch" href="javascript:toggleNightMode();" ></a>
|
||||||
|
</div>
|
||||||
|
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
|
||||||
|
<ul class="nav navbar-nav">
|
||||||
|
<li><a href="{{.URL.Parse "/"}}">{{T "website"}}</a/></li>
|
||||||
|
<li><a href="{{ genRoute "mod_tlist"}}">{{T "torrents"}}</a></li>
|
||||||
|
<li><a href="{{ genRoute "mod_ulist"}}">{{T "users"}}</a></li>
|
||||||
|
<li><a href="{{ genRoute "mod_clist"}}">{{T "comments"}}</a></li>
|
||||||
|
</ul>
|
||||||
|
{{block "badge_user" .}}{{end}}
|
||||||
|
<form class="navbar-form navbar-right" role="search" action="/mod/torrents" method="get">
|
||||||
|
<div class="form-group">
|
||||||
|
{{block "search_common" .}}{{end}}
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
{{block "search_button" .}}{{end}}
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
|
||||||
<div class="container" id="container">
|
<div class="container" id="container">
|
||||||
{{block "content" .}}{{end}}
|
{{block "content" .}}{{end}}
|
||||||
</div>
|
</div>
|
||||||
|
<footer>
|
||||||
|
Powered by NyaaPantsu
|
||||||
|
</footer>
|
||||||
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
|
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
|
||||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
|
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
|
||||||
<!-- Include all compiled plugins (below), or include individual files as needed -->
|
<!-- Include all compiled plugins (below), or include individual files as needed -->
|
||||||
|
|
Référencer dans un nouveau ticket