Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0
Cette révision appartient à :
akuma06 2017-05-10 16:43:50 +02:00
Parent 54991542cb
révision 032688f532
8 fichiers modifiés avec 81 ajouts et 23 suppressions

Voir le fichier

@ -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"`

Voir le fichier

@ -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 {

Voir le fichier

@ -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

Voir le fichier

@ -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 + "<li><a id=\"page-prev\" href=\"" + url.String() + "?" + currentUrl.RawQuery + "\" aria-label=\"Previous\"><span aria-hidden=\"true\">&laquo;</span></a></li>"
@ -57,6 +58,7 @@ var FuncMap = template.FuncMap{
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\">&raquo;</span></a></li>"
}
}
return template.HTML(ret)
},
"T": i18n.IdentityTfunc,

Voir le fichier

@ -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

Voir le fichier

@ -1,24 +1,33 @@
{{define "content"}}
nigga this just be some links
<a href="/mod/torrents">torrent list</a>
<a href="/mod/users">user list </a>
<a href="/mod/comments">comments list</a>
<h3 id="torrents">Last Torrents</h3>
<table>
{{ 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>
{{end}}
</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>
{{ range .Users}}
<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 }}?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 }}?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>
</tr>
{{end}}
</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>
{{ 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>
{{end}}
</table>
<nav class="torrentNav" aria-label="Page navigation">
<ul class="pagination">
<a href="{{ genRoute "mod_ulist" }}">More</a>
</ul>
</nav>
{{end}}

Voir le fichier

@ -2,7 +2,7 @@
<table>
{{ 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>
{{end}}
</table>

Voir le fichier

@ -27,10 +27,45 @@
<!-- Website CSS -->
</head>
<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">
{{block "content" .}}{{end}}
</div>
<footer>
Powered by NyaaPantsu
</footer>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<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 -->