Skip to content

Commit

Permalink
Merge branch 'dev' into filelist-fetching
Browse files Browse the repository at this point in the history
  • Loading branch information
Kiloutre authored Nov 9, 2017
2 parents 95daf79 + 887ff5b commit 4bd364e
Show file tree
Hide file tree
Showing 13 changed files with 62 additions and 35 deletions.
2 changes: 1 addition & 1 deletion config/default_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ users:
default_notifications_settings: {"new_torrent": true, "new_torrent_email": false, "new_comment": true, "new_comment_email": false, "new_responses": false, "new_responses_email": false, "new_follower": false, "new_follower_email": false, "followed": false, "followed_email": false}
navigation:
torrents_per_page: 50
max_torrents_per_page: 300
max_torrents_per_page: 500
log:
# AccessLogFilePath : Path to logs access
access_log_filepath: log/access
Expand Down
2 changes: 1 addition & 1 deletion controllers/moderator/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
// IndexModPanel : Controller for showing index page of Mod Panel
func IndexModPanel(c *gin.Context) {
offset := 10
torrents, _, _ := torrents.FindAll(offset, 0)
torrents, _, _ := torrents.FindAllOrderBy("torrent_id DESC", offset, 0)
users, _ := users.FindUsersForAdmin(offset, 0)
comments, _ := comments.FindAll(offset, 0, "", "")
torrentReports, _, _ := reports.GetAll(offset, 0)
Expand Down
2 changes: 1 addition & 1 deletion controllers/settings/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func SeePublicSettingsHandler(c *gin.Context) {
// ChangePublicSettingsHandler : Controller for changing the current language and theme
func ChangePublicSettingsHandler(c *gin.Context) {
theme := c.PostForm("theme")
lang := c.PostForm("language")
lang := c.PostForm("lang")
mascot := c.PostForm("mascot")
mascotURL := c.PostForm("mascot_url")
altColors := c.PostForm("altColors")
Expand Down
6 changes: 3 additions & 3 deletions models/users/find.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func FindOldUploadsByUsername(username string) ([]uint, error) {
// FindByID retrieves a user by ID.
func FindByID(id uint) (*models.User, int, error) {
var user = &models.User{}
if models.ORM.Preload("Notifications", func(db *gorm.DB) *gorm.DB { return db.Order("id DESC") }).Last(user, id).RecordNotFound() {
if models.ORM.Preload("Notifications", func(db *gorm.DB) *gorm.DB { return db.Order("date DESC") }).Last(user, id).RecordNotFound() {
return user, http.StatusNotFound, errors.New("user_not_found")
}
var liked, likings []models.User
Expand All @@ -117,7 +117,7 @@ func FindRawByID(id uint) (*models.User, int, error) {

func SessionByID(id uint) (*models.User, int, error) {
var user = &models.User{}
if models.ORM.Preload("Notifications", func(db *gorm.DB) *gorm.DB { return db.Order("id DESC") }).Where("user_id = ?", id).First(user).RecordNotFound() { // We only load unread notifications
if models.ORM.Preload("Notifications", func(db *gorm.DB) *gorm.DB { return db.Order("date DESC") }).Where("user_id = ?", id).First(user).RecordNotFound() { // We only load unread notifications
return user, http.StatusBadRequest, errors.New("user_not_found")
}
return user, http.StatusOK, nil
Expand All @@ -126,7 +126,7 @@ func SessionByID(id uint) (*models.User, int, error) {
// FindForAdmin retrieves a user for an administrator, preloads torrents.
func FindForAdmin(id uint) (*models.User, int, error) {
var user = &models.User{}
if models.ORM.Preload("Notifications", func(db *gorm.DB) *gorm.DB { return db.Order("id DESC") }).Preload("Torrents").Last(user, id).RecordNotFound() {
if models.ORM.Preload("Notifications", func(db *gorm.DB) *gorm.DB { return db.Order("date DESC") }).Preload("Torrents").Last(user, id).RecordNotFound() {
return user, http.StatusNotFound, errors.New("user_not_found")
}
var liked, likings []models.User
Expand Down
6 changes: 3 additions & 3 deletions public/css/themes/classic.css
Original file line number Diff line number Diff line change
Expand Up @@ -265,10 +265,10 @@ select.form-input {
.website-nav .pagination span {
min-width: auto;
}
.website-nav #page-prev{
.website-nav .page-prev{
float: left;
}
.website-nav #page-next{
.website-nav .page-next{
float: right;
}

Expand Down Expand Up @@ -348,7 +348,7 @@ span.comment-user:hover {
margin: 1px 0;
}

#solution {
.solution {
margin-top: -3px;
}

Expand Down
30 changes: 24 additions & 6 deletions public/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,7 @@ function resetCookies() {
if(domain == hostName) {
//only execute if cookie are supposed to be shared between nyaa & sukebei, aka on host name without subdomain
var cookieValue = getCookieValue(cookieName)
document.cookie = cookieName + "=;expires=Thu, 01 Jan 1970 00:00:00 UTC;"
document.cookie = cookieName + "=;expires=Thu, 01 Jan 1970 00:00:00 UTC;domain=" + window.location.host
document.cookie = cookieName + "=;path=/;expires=Thu, 01 Jan 1970 00:00:00 UTC;"
deleteCookie(cookieName)
if(cookieName != "session")
document.cookie = cookieName + "=" + cookieValue + ";path=/;expires=" + farFutureString + ";domain=" + domain
else document.cookie = cookieName + "=" + cookieValue + ";path=/;expires=" + farFutureString
Expand All @@ -127,12 +125,12 @@ function resetCookies() {
}
continue
}
document.cookie = cookieName + "=;expires=Thu, 01 Jan 1970 00:00:00 UTC;"
document.cookie = cookieName + "=;path=/;expires=Thu, 01 Jan 1970 00:00:00 UTC;"
document.cookie = cookieName + "=;expires=Thu, 01 Jan 1970 00:00:00 UTC;domain=" + window.location.host
deleteCookie(cookieName)
}

//Set new version in cookie
deleteCookie("commit")
deleteCookie("version")
document.cookie = "commit=" + commitVersion + ";path=/;expires=" + farFutureString + ";domain=" + domain
document.cookie = "version=" + websiteVersion + ";path=/;expires=" + farFutureString + ";domain=" + domain

Expand Down Expand Up @@ -306,4 +304,24 @@ function getCookieValue(cookieName) {
return endPos == -1 ? document.cookie.substring(startPos) : document.cookie.substring(startPos, endPos + startPos)
}

function deleteCookie(cookieName) {
document.cookie = cookieName + "=;expires=Thu, 01 Jan 1970 00:00:00 UTC;"
document.cookie = cookieName + "=;path=/;expires=Thu, 01 Jan 1970 00:00:00 UTC;"
document.cookie = cookieName + "=;expires=Thu, 01 Jan 1970 00:00:00 UTC;domain=" + window.location.host
document.cookie = cookieName + "=;expires=Thu, 01 Jan 1970 00:00:00 UTC;domain=" + domain

//Also need to delete from current hostname without subdomain, which is what this accomplish
var hostName = window.location.host
var lastDotIndex = hostName.lastIndexOf(".")
var secondLast = -1

for(var index = 0; index < lastDotIndex; index++) {
if(hostName[index] == '.')
secondLast = index
}
hostName = hostName.substr(secondLast == -1 ? 0 : secondLast)

document.cookie = cookieName + "=;expires=Thu, 01 Jan 1970 00:00:00 UTC;domain=" + hostName
}

// @license-end
2 changes: 1 addition & 1 deletion templates/layouts/partials/helpers/captcha.jet.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ <h3>{{ T("captcha")}}</h3>
{{ T("captcha_audio") }}
</a>
</audio>
<input class="form-input up-input form-control" type="text" name="solution" id="solution" style="display:block;" placeholder="{{ T("captcha")}}" autocomplete="off" required />
<input class="form-input up-input form-control" type="text" name="solution" class="solution" style="display:block;" placeholder="{{ T("captcha")}}" autocomplete="off" required />
</div>
{{end}}
{{end}}
2 changes: 1 addition & 1 deletion templates/layouts/partials/helpers/oldNav.jet.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<tr>
{{ range _, cat := GetCategories(true, false) }}
<td>{{if Search.Category == cat.ID ||(len(Search.Category) > 2 && Search.Category[:2] == cat.ID)}}<b>{{ T(cat.Name) }}</b>{{else}}<a href="{{genSearchWithCategory(URL, cat.ID, Search.SearchURL)}}">{{ T(cat.Name) }}</a>{{end}}</td>
{{ if _ % 3 == 2}}
{{ if _ % 3 == 2 && _ + 1 != len(GetCategories(true, false)) }}
</tr>
<tr>
{{end}}
Expand Down
2 changes: 1 addition & 1 deletion templates/layouts/partials/helpers/search.jet.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ <h3>{{ T("refine_search") }}</h3>
<option value="3" {{if Search.Status == 3}}selected{{end}}>{{ T("trusted")}}</option>
<option value="4" {{if Search.Status == 4}}selected{{end}}>A+</option>
</select>
{{ T("limit_torrent_count")}}: <input type="number" name="limit" value="{{ Navigation.MaxItemPerPage }}" class="form-input spacing" min="1" max="300"/>
{{ T("limit_torrent_count")}}: <input type="number" name="limit" value="{{ Navigation.MaxItemPerPage }}" class="form-input spacing" min="1" max="500"/>
{{ T("from_user") }}: <input type="text" name="user" placeholder="Username/#ID" value="{{ Search.User == "" ? (Search.UserID == 0 ? "" : ("#" + Search.UserID)) : Search.User }}" class="form-input refine-user"/>
</span>
<span class="form-refine">
Expand Down
2 changes: 1 addition & 1 deletion templates/layouts/partials/helpers/treeview.jet.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{{ folderId := treeviewData.IdentifierChain+"_"+index }}
<tr class="tr-filelist tr-folder">
<td style="padding-left: {{ treeviewData.NestLevel * 2.5 }}%;"><label for="contents_{{folderId}}">{{folder.FolderName}}</label></td>
<td>{{ fileSize(folder.TotalSize(), T, false) }}</td>
<td>{{ fileSize(folder.TotalSize(), T, true) }}</td>
</tr>
<tr>
<td colspan="2">
Expand Down
2 changes: 1 addition & 1 deletion templates/site/torrents/view.jet.html
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ <h1 style="text-align: center;" class="torrent-hr">{{Torrent.Name}}</h1>
{{previousComment := ""}}
{{previousUser := 0}}
{{range index, element := Torrent.Comments}}
{{if previousComment != element.Content || previousUser != element.UserID}}
{{if previousComment != element.Content || previousUser != element.UserID || element.UserID == 0}}
<div class="torrent-info-box comment-box">
<span class="comment-index">
<a href="#comment_{{idx}}">{{idx}}</a>
Expand Down
35 changes: 22 additions & 13 deletions templates/site/user/public/settings.jet.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<div id="settings-container">
<span class="form-group">
<h3>{{ T("language")}}</h3>
<select id="language" name="language" class="form-input">
<select id="language" name="lang" class="form-input">
{{ range translatedName := Form.Languages }}
<option value="{{ translatedName[2] }}" {{ if Form.Current == translatedName[2] }}selected{{end}}>{{ translatedName[0] }}</option>
{{ end }}
Expand Down Expand Up @@ -67,21 +67,30 @@ <h3>{{ T("alternating_color") }}</h3>
{{ block footer_js()}}
<!-- JS Function for selecting multiple checkboxes -->
<script type="text/javascript">
var SaveButton = document.querySelector('button[type="submit"')
var SaveButton = document.querySelector('form[method="POST"] button[type="submit"]')

//Golang settings.go controller set cookies for the domain variable in config, if we are currently on a mirror this will mean that the cookie will not be set for the right website
if(UserID == 0 && Mirror)
//Doing this, we avoid having to do a query (which is unneeded for logged-in users) and can make sure that the cookies are set for the right domain name
if(UserID == 0)
SaveButton.addEventListener("click", function(e) {
var OptionSelected = document.getElementById("theme-selector").selectedIndex
document.cookie = "theme=" + document.querySelector("#theme-selector :nth-child(" + OptionSelected + ")").value + ";path=/;expires=" + farFutureString + ";domain=" + domain
//Set theme cookie

OptionSelected = document.getElementById("language").selectedIndex
document.cookie = "lang=" + document.querySelector("#language :nth-child(" + OptionSelected + ")").value + ";path=/;expires=" + farFutureString + ";domain=" + domain
//Set language cookie

//Will have to do the rest
var formInputs = document.querySelectorAll("form[method='POST'] input"),
formSelect = document.querySelectorAll("form[method='POST'] select")


for(var i = 0; i < formInputs.length; i++) {
var setting = formInputs[i]
if(setting.name == "csrf_token") continue
deleteCookie(setting.name)
document.cookie = setting.name + "=" + setting.value + ";path=/;expires=" + farFutureString + ";domain=" + domain
}

for(var i = 0; i < formSelect.length; i++) {
var setting = formSelect[i],
selectValues = setting.querySelectorAll("option")

deleteCookie(setting.name)
document.cookie = setting.name + "=" + selectValues[setting.selectedIndex].value + ";path=/;expires=" + farFutureString + ";domain=" + domain
}

window.location.replace("/")
e.preventDefault()
})
Expand Down
4 changes: 2 additions & 2 deletions templates/template_functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func genNav(nav Navigation, currentURL *url.URL, pagesSelectable int) template.H
display = ""
href = " href=\"" + "/" + nav.Route + "/1" + "?" + currentURL.RawQuery + "\""
}
ret = ret + "<a id=\"page-prev\"" + display + href + " aria-label=\"Previous\"><span aria-hidden=\"true\">&laquo;</span></a>"
ret = ret + "<a class=\"page-prev\"" + display + href + " aria-label=\"Previous\"><span aria-hidden=\"true\">&laquo;</span></a>"

startValue := 1
if nav.CurrentPage > pagesSelectable/2 {
Expand Down Expand Up @@ -178,7 +178,7 @@ func genNav(nav Navigation, currentURL *url.URL, pagesSelectable int) template.H
display = ""
href = " href=\"" + "/" + nav.Route + "/" + strconv.Itoa(int(maxPages)) + "?" + currentURL.RawQuery + "\""
}
ret = ret + "<a id=\"page-next\"" + display + href +" aria-label=\"Next\"><span aria-hidden=\"true\">&raquo;</span></a>"
ret = ret + "<a class=\"page-next\"" + display + href +" aria-label=\"Next\"><span aria-hidden=\"true\">&raquo;</span></a>"

itemsThisPageStart := nav.MaxItemPerPage*(nav.CurrentPage-1) + 1
itemsThisPageEnd := nav.MaxItemPerPage * nav.CurrentPage
Expand Down

0 comments on commit 4bd364e

Please sign in to comment.