unborked report list
Cette révision appartient à :
Parent
4ada27a3cc
révision
8373bce02f
5 fichiers modifiés avec 43 ajouts et 23 suppressions
|
@ -5,25 +5,26 @@ package model
|
||||||
// INFO User can be null (anonymous reports)
|
// INFO User can be null (anonymous reports)
|
||||||
// FIXME can't preload field Torrents for model.TorrentReport
|
// FIXME can't preload field Torrents for model.TorrentReport
|
||||||
type TorrentReport struct {
|
type TorrentReport struct {
|
||||||
ID uint `gorm:"column:torrent_report_id;primary_key"`
|
ID uint `gorm:"column:torrent_report_id;primary_key"`
|
||||||
Description string `gorm:"column:type"`
|
Description string `gorm:"column:type"`
|
||||||
TorrentID uint `gorm:"column:torrent_id"`
|
TorrentID uint `gorm:"column:torrent_id"`
|
||||||
UserID uint `gorm:"column:user_id"`
|
UserID uint `gorm:"column:user_id"`
|
||||||
Torrent Torrent `gorm:"AssociationForeignKey:TorrentID;ForeignKey:torrent_id"`
|
|
||||||
User User `gorm:"AssociationForeignKey:UserID;ForeignKey:ID"`
|
Torrent Torrent `gorm:"AssociationForeignKey:TorrentID;ForeignKey:torrent_id"`
|
||||||
|
User User `gorm:"AssociationForeignKey:UserID;ForeignKey:ID"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type TorrentReportJson struct {
|
type TorrentReportJson struct {
|
||||||
ID uint `json:"id"`
|
ID uint `json:"id"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
Torrent TorrentJSON `json:"torrent"`
|
Torrent TorrentJSON `json:"torrent"`
|
||||||
User string
|
User UserJSON `json:"user"`
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Model Conversion to Json */
|
/* Model Conversion to Json */
|
||||||
|
|
||||||
func (report *TorrentReport) ToJson() TorrentReportJson {
|
func (report *TorrentReport) ToJson() TorrentReportJson {
|
||||||
json := TorrentReportJson{report.ID, report.Description, report.Torrent.ToJSON(), report.User.Username}
|
json := TorrentReportJson{report.ID, report.Description, report.Torrent.ToJSON(), report.User.ToJSON()}
|
||||||
return json
|
return json
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,15 @@ type User struct {
|
||||||
Torrents []Torrent `gorm:"ForeignKey:UploaderID"`
|
Torrents []Torrent `gorm:"ForeignKey:UploaderID"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type UserJSON struct {
|
||||||
|
ID uint `json:"user_id"`
|
||||||
|
Username string `json:"username"`
|
||||||
|
Status int `json:"status"`
|
||||||
|
CreatedAt string `json:"created_at"`
|
||||||
|
LikingCount int `json:"liking_count"`
|
||||||
|
LikedCount int `json:"liked_count"`
|
||||||
|
}
|
||||||
|
|
||||||
// Returns the total size of memory recursively allocated for this struct
|
// Returns the total size of memory recursively allocated for this struct
|
||||||
func (u User) Size() (s int) {
|
func (u User) Size() (s int) {
|
||||||
s += 4 + // ints
|
s += 4 + // ints
|
||||||
|
@ -60,3 +69,15 @@ func (c UserUploadsOld) TableName() string {
|
||||||
// TODO: rename this in db
|
// TODO: rename this in db
|
||||||
return "user_uploads_old"
|
return "user_uploads_old"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (u *User) ToJSON() UserJSON {
|
||||||
|
json := UserJSON{
|
||||||
|
ID: u.ID,
|
||||||
|
Username: u.Username,
|
||||||
|
Status: u.Status,
|
||||||
|
CreatedAt: u.CreatedAt.Format(time.RFC3339),
|
||||||
|
LikingCount: u.LikingCount,
|
||||||
|
LikedCount: u.LikedCount,
|
||||||
|
}
|
||||||
|
return json
|
||||||
|
}
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
package router
|
package router
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"html"
|
"html"
|
||||||
"html/template"
|
"html/template"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -52,7 +51,6 @@ func IndexModPanel(w http.ResponseWriter, r *http.Request) {
|
||||||
comments, _ := commentService.GetAllComments(offset, 0, "", "")
|
comments, _ := commentService.GetAllComments(offset, 0, "", "")
|
||||||
torrentReports, _, _ := reportService.GetAllTorrentReports(offset, 0)
|
torrentReports, _, _ := reportService.GetAllTorrentReports(offset, 0)
|
||||||
|
|
||||||
fmt.Println(torrentReports)
|
|
||||||
languages.SetTranslationFromRequest(panelIndex, r, "en-us")
|
languages.SetTranslationFromRequest(panelIndex, r, "en-us")
|
||||||
htv := PanelIndexVbs{torrents, torrentReports, users, comments, NewSearchForm(), currentUser, r.URL}
|
htv := PanelIndexVbs{torrents, torrentReports, users, comments, NewSearchForm(), currentUser, r.URL}
|
||||||
_ = panelIndex.ExecuteTemplate(w, "admin_index.html", htv)
|
_ = panelIndex.ExecuteTemplate(w, "admin_index.html", htv)
|
||||||
|
@ -88,7 +86,7 @@ func TorrentsListPanel(w http.ResponseWriter, r *http.Request) {
|
||||||
languages.SetTranslationFromRequest(panelTorrentList, r, "en-us")
|
languages.SetTranslationFromRequest(panelTorrentList, r, "en-us")
|
||||||
htv := PanelTorrentListVbs{torrents, searchForm, Navigation{int(searchParam.Max), offset, pagenum, "mod_tlist_page"}, currentUser, r.URL}
|
htv := PanelTorrentListVbs{torrents, searchForm, Navigation{int(searchParam.Max), offset, pagenum, "mod_tlist_page"}, currentUser, r.URL}
|
||||||
err = panelTorrentList.ExecuteTemplate(w, "admin_index.html", htv)
|
err = panelTorrentList.ExecuteTemplate(w, "admin_index.html", htv)
|
||||||
fmt.Println(err)
|
log.CheckError(err)
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
http.Error(w, "admins only", http.StatusForbidden)
|
http.Error(w, "admins only", http.StatusForbidden)
|
||||||
|
@ -115,10 +113,10 @@ func TorrentReportListPanel(w http.ResponseWriter, r *http.Request) {
|
||||||
torrentReports, nbReports, _ := reportService.GetAllTorrentReports(offset, (pagenum-1)*offset)
|
torrentReports, nbReports, _ := reportService.GetAllTorrentReports(offset, (pagenum-1)*offset)
|
||||||
|
|
||||||
reportJSON := model.TorrentReportsToJSON(torrentReports)
|
reportJSON := model.TorrentReportsToJSON(torrentReports)
|
||||||
languages.SetTranslationFromRequest(panelUserList, r, "en-us")
|
languages.SetTranslationFromRequest(panelTorrentReportList, r, "en-us")
|
||||||
htv := PanelTorrentReportListVbs{reportJSON, NewSearchForm(), Navigation{nbReports, offset, pagenum, "mod_trlist_page"}, currentUser, r.URL}
|
htv := PanelTorrentReportListVbs{reportJSON, NewSearchForm(), Navigation{nbReports, offset, pagenum, "mod_trlist_page"}, currentUser, r.URL}
|
||||||
err = panelTorrentReportList.ExecuteTemplate(w, "admin_index.html", htv)
|
err = panelTorrentReportList.ExecuteTemplate(w, "admin_index.html", htv)
|
||||||
fmt.Println(err)
|
log.CheckError(err)
|
||||||
} else {
|
} else {
|
||||||
http.Error(w, "admins only", http.StatusForbidden)
|
http.Error(w, "admins only", http.StatusForbidden)
|
||||||
}
|
}
|
||||||
|
@ -145,7 +143,7 @@ func UsersListPanel(w http.ResponseWriter, r *http.Request) {
|
||||||
languages.SetTranslationFromRequest(panelUserList, r, "en-us")
|
languages.SetTranslationFromRequest(panelUserList, r, "en-us")
|
||||||
htv := PanelUserListVbs{users, NewSearchForm(), Navigation{nbUsers, offset, pagenum, "mod_ulist_page"}, currentUser, r.URL}
|
htv := PanelUserListVbs{users, NewSearchForm(), Navigation{nbUsers, offset, pagenum, "mod_ulist_page"}, currentUser, r.URL}
|
||||||
err = panelUserList.ExecuteTemplate(w, "admin_index.html", htv)
|
err = panelUserList.ExecuteTemplate(w, "admin_index.html", htv)
|
||||||
fmt.Println(err)
|
log.CheckError(err)
|
||||||
} else {
|
} else {
|
||||||
http.Error(w, "admins only", http.StatusForbidden)
|
http.Error(w, "admins only", http.StatusForbidden)
|
||||||
}
|
}
|
||||||
|
@ -179,7 +177,7 @@ func CommentsListPanel(w http.ResponseWriter, r *http.Request) {
|
||||||
languages.SetTranslationFromRequest(panelCommentList, r, "en-us")
|
languages.SetTranslationFromRequest(panelCommentList, r, "en-us")
|
||||||
htv := PanelCommentListVbs{comments, NewSearchForm(), Navigation{nbComments, offset, pagenum, "mod_clist_page"}, currentUser, r.URL}
|
htv := PanelCommentListVbs{comments, NewSearchForm(), Navigation{nbComments, offset, pagenum, "mod_clist_page"}, currentUser, r.URL}
|
||||||
err = panelCommentList.ExecuteTemplate(w, "admin_index.html", htv)
|
err = panelCommentList.ExecuteTemplate(w, "admin_index.html", htv)
|
||||||
fmt.Println(err)
|
log.CheckError(err)
|
||||||
} else {
|
} else {
|
||||||
http.Error(w, "admins only", http.StatusForbidden)
|
http.Error(w, "admins only", http.StatusForbidden)
|
||||||
}
|
}
|
||||||
|
@ -193,7 +191,7 @@ func TorrentEditModPanel(w http.ResponseWriter, r *http.Request) {
|
||||||
languages.SetTranslationFromRequest(panelTorrentEd, r, "en-us")
|
languages.SetTranslationFromRequest(panelTorrentEd, r, "en-us")
|
||||||
htv := PanelTorrentEdVbs{torrent, NewSearchForm(), currentUser}
|
htv := PanelTorrentEdVbs{torrent, NewSearchForm(), currentUser}
|
||||||
err := panelTorrentEd.ExecuteTemplate(w, "admin_index.html", htv)
|
err := panelTorrentEd.ExecuteTemplate(w, "admin_index.html", htv)
|
||||||
fmt.Println(err)
|
log.CheckError(err)
|
||||||
} else {
|
} else {
|
||||||
http.Error(w, "admins only", http.StatusForbidden)
|
http.Error(w, "admins only", http.StatusForbidden)
|
||||||
}
|
}
|
||||||
|
|
|
@ -153,11 +153,11 @@ type PanelTorrentEdVbs struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type PanelTorrentReportListVbs struct {
|
type PanelTorrentReportListVbs struct {
|
||||||
Torrents []model.TorrentReportJson
|
TorrentReports []model.TorrentReportJson
|
||||||
Search SearchForm
|
Search SearchForm
|
||||||
Navigation Navigation
|
Navigation Navigation
|
||||||
User *model.User
|
User *model.User
|
||||||
URL *url.URL // For parsing Url in templates
|
URL *url.URL // For parsing Url in templates
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
{{define "title"}}Torrents Report{{end}}
|
{{define "title"}}Torrents Report{{end}}
|
||||||
{{define "content"}}
|
{{define "content"}}
|
||||||
<table class="table">
|
<table class="table">
|
||||||
{{ range .Torrents}}
|
{{ range .TorrentReports}}
|
||||||
<tr><td><a href="{{ genRoute "mod_tedit" }}?id={{.Torrent.ID}}">{{ .Torrent.Name }}</a></td><td>{{.User.Username}}</td><td>{{.Description}}</td><td><a href="{{ genRoute "mod_tdelete" }}?id={{ .Torrent.ID }}">Delete</a></td></tr>
|
<tr><td><a href="{{ genRoute "mod_tedit"}}?id={{.Torrent.ID}}">{{.Torrent.Name}}</a></td><td>{{.User.Username}}</td><td>{{.Description}}</td><td><a href="{{ genRoute "mod_tdelete" }}?id={{ .Torrent.ID }}">Delete</a></td></tr>
|
||||||
{{end}}
|
{{end}}
|
||||||
</table>
|
</table>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
Référencer dans un nouveau ticket