Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0

Fixing Mod Panel (WIP)

Cette révision appartient à :
akuma06 2017-05-10 15:08:38 +02:00
Parent e1c4ba05cd
révision 46d65ba865
9 fichiers modifiés avec 77 ajouts et 19 suppressions

Voir le fichier

@ -35,8 +35,8 @@ func IndexModPanel(w http.ResponseWriter, r *http.Request) {
offset := 10
torrents, _, _ := torrentService.GetAllTorrents(0, offset)
users := userService.RetrieveUsersForAdmin(0, offset)
comments := commentService.GetAllComments(0, offset)
users, _ := userService.RetrieveUsersForAdmin(0, offset)
comments, _ := commentService.GetAllComments(0, offset, "", "")
languages.SetTranslationFromRequest(panelIndex, r, "en-us")
htv := PanelIndexVbs{torrents, users, comments}
_ = panelIndex.ExecuteTemplate(w, "admin_index.html", htv)
@ -50,9 +50,9 @@ func TorrentsListPanel(w http.ResponseWriter, r *http.Request) {
page, _ := strconv.Atoi(r.URL.Query().Get("p"))
offset := 100
torrents, _, _ := torrentService.GetAllTorrents(offset, page * offset)
torrents, nbTorrents, _ := torrentService.GetAllTorrents(offset, page * offset)
languages.SetTranslationFromRequest(panelTorrentList, r, "en-us")
htv := PanelTorrentListVbs{torrents}
htv := PanelTorrentListVbs{torrents, Navigation{nbTorrents, offset, page, "mod_tlist_page"}}
err := panelTorrentList.ExecuteTemplate(w, "admin_index.html", htv)
fmt.Println(err)
} else {
@ -66,9 +66,9 @@ func UsersListPanel(w http.ResponseWriter, r *http.Request) {
page, _ := strconv.Atoi(r.URL.Query().Get("p"))
offset := 100
users := userService.RetrieveUsersForAdmin(offset, page*offset)
users, nbUsers := userService.RetrieveUsersForAdmin(offset, page*offset)
languages.SetTranslationFromRequest(panelUserList, r, "en-us")
htv := PanelUserListVbs{users}
htv := PanelUserListVbs{users, Navigation{nbUsers, offset, page, "mod_ulist_page"}}
err := panelUserList.ExecuteTemplate(w, "admin_index.html", htv)
fmt.Println(err)
} else {
@ -80,10 +80,16 @@ func CommentsListPanel(w http.ResponseWriter, r *http.Request) {
if userPermission.HasAdmin(currentUser) {
page, _ := strconv.Atoi(r.URL.Query().Get("p"))
offset := 100
comments := commentService.GetAllComments(offset, page * offset)
userid := r.URL.Query().Get("userid")
var conditions string
var values []interface{}
if (userid != "") {
conditions = "user_id = ?"
values = append(values, userid)
}
comments, nbComments := commentService.GetAllComments(offset, page * offset, conditions, values...)
languages.SetTranslationFromRequest(panelCommentList, r, "en-us")
htv := PanelCommentListVbs{comments}
htv := PanelCommentListVbs{comments, Navigation{nbComments, offset, page, "mod_clist_page"}}
err := panelCommentList.ExecuteTemplate(w, "admin_index.html", htv)
fmt.Println(err)
} else {

Voir le fichier

@ -83,9 +83,12 @@ func init() {
Router.Handle("/mod/", gzipIndexModPanel).Name("mod_index")
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/comments", gzipCommentsListPanel).Name("mod_clist")
Router.Handle("/mod/comments", gzipCommentsListPanel).Name("mod_cedit") // TODO
Router.Handle("/mod/comments/{page}", gzipCommentsListPanel).Name("mod_clist_page")
Router.Handle("/mod/comment", gzipCommentsListPanel).Name("mod_cedit") // TODO
Router.Handle("/mod/torrent/", gzipTorrentEditModPanel).Name("mod_tedit")
Router.Handle("/mod/torrent/", gzipTorrentPostEditModPanel).Name("mod_ptedit")
Router.Handle("/mod/torrent/delete", gzipTorrentDeleteModPanel).Name("mod_tdelete")

Voir le fichier

@ -121,12 +121,15 @@ type PanelIndexVbs struct {
type PanelTorrentListVbs struct {
Torrents []model.Torrent
Navigation Navigation
}
type PanelUserListVbs struct {
Users []model.User
Navigation Navigation
}
type PanelCommentListVbs struct {
Comments []model.Comment
Navigation Navigation
}
type PanelTorrentEdVbs struct {
Torrent model.Torrent

Voir le fichier

@ -6,8 +6,10 @@ import (
)
func GetAllComments(limit int, offset int) []model.Comment{
func GetAllComments(limit int, offset int, conditions string, values ...interface{}) ([]model.Comment, int){
var comments []model.Comment
db.ORM.Limit(limit).Offset(offset).Preload("User").Find(&comments)
return comments
var nbComments int
db.ORM.Model(&comments).Where(conditions, values...).Count(&nbComments)
db.ORM.Preload("User").Limit(limit).Offset(offset).Where(conditions, values...).Find(&comments)
return comments, nbComments
}

Voir le fichier

@ -273,10 +273,12 @@ func RetrieveUserForAdmin(id string) (model.User, int, error) {
}
// RetrieveUsersForAdmin retrieves users for an administrator.
func RetrieveUsersForAdmin(limit int, offset int) []model.User {
func RetrieveUsersForAdmin(limit int, offset int) ([]model.User, int) {
var users []model.User
db.ORM.Preload("Torrents").Find(&users).Limit(limit).Offset(offset)
return users
var nbUsers int
db.ORM.Model(&users).Count(&nbUsers)
db.ORM.Preload("Torrents").Limit(limit).Offset(offset).Find(&users)
return users, nbUsers
}
// CreateUserAuthentication creates user authentication.

Voir le fichier

@ -2,7 +2,13 @@
<table>
{{ range .Comments}}
<tr><td><a href="{{ genRoute "mod_cedit" }}?id={{.ID}}">{{ .Content }}</a></td><td><a href="{{ genRoute "mod_cdelete" }}?id={{ .ID }}">Delete</a></td></tr>
<tr><td><a href="{{ genRoute "mod_cedit" }}?id={{.ID}}">{{ .Content }}</a></td><td><a href="{{ genRoute "mod_cedit" }}?id={{.ID}}">{{ .User.Username }}</a></td>
<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">
{{ genNav .Navigation .URL 5 }}
</ul>
</nav>
{{end}}

Voir le fichier

@ -3,5 +3,27 @@ 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>
<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>
<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>
<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>
</tr>
{{end}}
</table>
<table>
{{ range .Comments}}
<tr><td><a href="{{ genRoute "mod_cedit" }}?id={{.ID}}">{{ .Content }}</a></td><td><a href="{{ genRoute "mod_cedit" }}?id={{.ID}}">{{ .User.Username }}</a></td>
<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>
{{end}}

Voir le fichier

@ -2,7 +2,13 @@
<table>
{{ range .Torrents}}
<tr><td><a href="{{ genRoute "mod_tedit" }}?id={{.ID}}">{{ .Name }}</a></td><td><a href="{{ genRoute "mod_tdelete" }}?id={{ .ID }}">Delete</a></td></tr>
<tr><td><a href="{{ genRoute "mod_tedit" }}?id={{.ID}}">{{ .Name }}</a></td><td><a href="{{ genRoute "mod_tlist" }}?userid={{.UploaderID}}">{{ .Uploader.Username }}</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">
{{ genNav .Navigation .URL 5 }}
</ul>
</nav>
{{end}}

Voir le fichier

@ -2,7 +2,15 @@
<table>
{{ range .Users}}
<tr><td><a href="{{ genRoute "mod_tedit" }}?id={{.ID}}">{{ .Username }}</a></td><td><a href="{{ genRoute "mod_tdelete" }}?id{{ .ID }}">Delete</a></td></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 }}?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">
{{ genNav .Navigation .URL 5 }}
</ul>
</nav>
{{end}}