unborked report list
Cette révision appartient à :
Parent
4ada27a3cc
révision
8373bce02f
5 fichiers modifiés avec 43 ajouts et 23 suppressions
|
@ -9,6 +9,7 @@ type TorrentReport struct {
|
|||
Description string `gorm:"column:type"`
|
||||
TorrentID uint `gorm:"column:torrent_id"`
|
||||
UserID uint `gorm:"column:user_id"`
|
||||
|
||||
Torrent Torrent `gorm:"AssociationForeignKey:TorrentID;ForeignKey:torrent_id"`
|
||||
User User `gorm:"AssociationForeignKey:UserID;ForeignKey:ID"`
|
||||
}
|
||||
|
@ -17,13 +18,13 @@ type TorrentReportJson struct {
|
|||
ID uint `json:"id"`
|
||||
Description string `json:"description"`
|
||||
Torrent TorrentJSON `json:"torrent"`
|
||||
User string
|
||||
User UserJSON `json:"user"`
|
||||
}
|
||||
|
||||
/* Model Conversion to Json */
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
|
|
|
@ -26,6 +26,15 @@ type User struct {
|
|||
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
|
||||
func (u User) Size() (s int) {
|
||||
s += 4 + // ints
|
||||
|
@ -60,3 +69,15 @@ func (c UserUploadsOld) TableName() string {
|
|||
// TODO: rename this in db
|
||||
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
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"html"
|
||||
"html/template"
|
||||
"net/http"
|
||||
|
@ -52,7 +51,6 @@ func IndexModPanel(w http.ResponseWriter, r *http.Request) {
|
|||
comments, _ := commentService.GetAllComments(offset, 0, "", "")
|
||||
torrentReports, _, _ := reportService.GetAllTorrentReports(offset, 0)
|
||||
|
||||
fmt.Println(torrentReports)
|
||||
languages.SetTranslationFromRequest(panelIndex, r, "en-us")
|
||||
htv := PanelIndexVbs{torrents, torrentReports, users, comments, NewSearchForm(), currentUser, r.URL}
|
||||
_ = 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")
|
||||
htv := PanelTorrentListVbs{torrents, searchForm, Navigation{int(searchParam.Max), offset, pagenum, "mod_tlist_page"}, currentUser, r.URL}
|
||||
err = panelTorrentList.ExecuteTemplate(w, "admin_index.html", htv)
|
||||
fmt.Println(err)
|
||||
log.CheckError(err)
|
||||
} else {
|
||||
|
||||
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)
|
||||
|
||||
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}
|
||||
err = panelTorrentReportList.ExecuteTemplate(w, "admin_index.html", htv)
|
||||
fmt.Println(err)
|
||||
log.CheckError(err)
|
||||
} else {
|
||||
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")
|
||||
htv := PanelUserListVbs{users, NewSearchForm(), Navigation{nbUsers, offset, pagenum, "mod_ulist_page"}, currentUser, r.URL}
|
||||
err = panelUserList.ExecuteTemplate(w, "admin_index.html", htv)
|
||||
fmt.Println(err)
|
||||
log.CheckError(err)
|
||||
} else {
|
||||
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")
|
||||
htv := PanelCommentListVbs{comments, NewSearchForm(), Navigation{nbComments, offset, pagenum, "mod_clist_page"}, currentUser, r.URL}
|
||||
err = panelCommentList.ExecuteTemplate(w, "admin_index.html", htv)
|
||||
fmt.Println(err)
|
||||
log.CheckError(err)
|
||||
} else {
|
||||
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")
|
||||
htv := PanelTorrentEdVbs{torrent, NewSearchForm(), currentUser}
|
||||
err := panelTorrentEd.ExecuteTemplate(w, "admin_index.html", htv)
|
||||
fmt.Println(err)
|
||||
log.CheckError(err)
|
||||
} else {
|
||||
http.Error(w, "admins only", http.StatusForbidden)
|
||||
}
|
||||
|
|
|
@ -153,7 +153,7 @@ type PanelTorrentEdVbs struct {
|
|||
}
|
||||
|
||||
type PanelTorrentReportListVbs struct {
|
||||
Torrents []model.TorrentReportJson
|
||||
TorrentReports []model.TorrentReportJson
|
||||
Search SearchForm
|
||||
Navigation Navigation
|
||||
User *model.User
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{{define "title"}}Torrents Report{{end}}
|
||||
{{define "content"}}
|
||||
<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>
|
||||
{{end}}
|
||||
</table>
|
||||
|
|
Référencer dans un nouveau ticket