Parent
d6b018e029
révision
b3a8471ac4
5 fichiers modifiés avec 33 ajouts et 8 suppressions
|
@ -55,17 +55,16 @@ func UserProfileHandler(c *gin.Context) {
|
|||
c.Request.URL.RawQuery = query.Encode()
|
||||
var torrents []models.Torrent
|
||||
var err error
|
||||
nbTorrents := 0
|
||||
_, userProfile.Torrents, _, err = search.ByQuery(c, 1)
|
||||
if currentUser.CurrentOrAdmin(userProfile.ID) {
|
||||
_, torrents, nbTorrents, err = search.ByQuery(c, 1)
|
||||
userProfile.Splice(1, 20)
|
||||
} else {
|
||||
_, torrents, nbTorrents, err = search.ByQueryNoHidden(c, 1)
|
||||
userProfile.Splice(1, 20).Filter()
|
||||
}
|
||||
if err != nil {
|
||||
messages.AddErrorT("errors", "retrieve_torrents_error")
|
||||
}
|
||||
userProfile.Torrents = torrents
|
||||
templates.UserProfile(c, userProfile, nbTorrents)
|
||||
templates.UserProfile(c, userProfile)
|
||||
}
|
||||
} else {
|
||||
c.Status(http.StatusNotFound)
|
||||
|
|
|
@ -362,3 +362,31 @@ func (u *User) Delete(currentUser *User) (int, error) {
|
|||
func (u *User) toMap() map[string]interface{} {
|
||||
return structs.Map(u)
|
||||
}
|
||||
|
||||
// Splice : get a subset of torrents
|
||||
func (u *User) Splice(start int, length int) *User {
|
||||
if (len(u.Torrents) <= length && start == 0) || len(u.Torrents) == 0 {
|
||||
return u
|
||||
}
|
||||
if start > len(u.Torrents) {
|
||||
u.Torrents = []Torrent{}
|
||||
return u
|
||||
}
|
||||
if len(u.Torrents) < length {
|
||||
length = len(u.Torrents)
|
||||
}
|
||||
u.Torrents = u.Torrents[start:length]
|
||||
return u
|
||||
}
|
||||
|
||||
// Filter : filter the hidden torrents
|
||||
func (u *User) Filter() *User {
|
||||
torrents := []Torrent{}
|
||||
for _, t := range u.Torrents {
|
||||
if !t.Hidden {
|
||||
torrents = append(torrents, t)
|
||||
}
|
||||
}
|
||||
u.Torrents = torrents
|
||||
return u
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
<p class="profile-usertitle-job">
|
||||
{{UserProfile.GetRole()}}
|
||||
</p>
|
||||
<p class="profile-usertitle-uploadcount">{{ T("torrents_uploaded") }}:<span>{{ NbTorrents }}</span></p>
|
||||
<p class="profile-usertitle-uploadcount">{{ T("torrents_uploaded") }}:<span>{{ len(UserProfile.Torrents) }}</span></p>
|
||||
</div>
|
||||
<!-- END SIDEBAR USER TITLE -->
|
||||
<!-- SIDEBAR BUTTONS -->
|
||||
|
|
|
@ -167,7 +167,6 @@ func UserProfileEdit(c *gin.Context, userProfile *models.User, userForm userVali
|
|||
func UserProfile(c *gin.Context, userProfile *models.User, nbTorrents int) {
|
||||
variables := Commonvariables(c)
|
||||
variables.Set("UserProfile", userProfile)
|
||||
variables.Set("NbTorrents", nbTorrents)
|
||||
Render(c, path.Join(SiteDir, "user/torrents.jet.html"), variables)
|
||||
}
|
||||
|
||||
|
|
|
@ -211,7 +211,6 @@ func mockupCommonvariables(t *testing.T) jet.VarMap {
|
|||
variables.Set("Infos", make(map[string][]string))
|
||||
variables.Set("Errors", make(map[string][]string))
|
||||
variables.Set("UserProfile", &models.User{})
|
||||
variables.Set("NbTorrents", 0)
|
||||
variables = templateFunctions(variables)
|
||||
return variables
|
||||
}
|
||||
|
|
Référencer dans un nouveau ticket