From 755a42693147c5d36d8a11d49031c5087a321c52 Mon Sep 17 00:00:00 2001 From: ayame-git Date: Wed, 10 May 2017 22:29:59 +0300 Subject: [PATCH 1/7] reports are deleted with torrents --- router/modpanel.go | 10 ++++++++++ service/report/report.go | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/router/modpanel.go b/router/modpanel.go index d48c5b5c..681e72b8 100644 --- a/router/modpanel.go +++ b/router/modpanel.go @@ -3,6 +3,7 @@ package router import ( + "fmt" "html" "html/template" "net/http" @@ -10,6 +11,7 @@ import ( "strconv" "github.com/ewhal/nyaa/model" + "github.com/ewhal/nyaa/service" "github.com/ewhal/nyaa/service/comment" "github.com/ewhal/nyaa/service/report" "github.com/ewhal/nyaa/service/torrent" @@ -50,6 +52,7 @@ func IndexModPanel(w http.ResponseWriter, r *http.Request) { users, _ := userService.RetrieveUsersForAdmin(offset, 0) 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} @@ -246,6 +249,13 @@ func TorrentDeleteModPanel(w http.ResponseWriter, r *http.Request) { if userPermission.HasAdmin(currentUser) { _ = form.NewErrors() _, _ = torrentService.DeleteTorrent(id) + + //delete reports of torrent + whereParams := serviceBase.CreateWhereParams("torrent_id = ?", id) + reports, _, _ := reportService.GetTorrentReportsOrderBy(&whereParams, "", 0, 0) + for _, report := range reports { + reportService.DeleteTorrentReport(report.ID) + } url, _ := Router.Get("mod_tlist").URL() http.Redirect(w, r, url.String()+"?deleted", http.StatusSeeOther) } else { diff --git a/service/report/report.go b/service/report/report.go index caf2e958..9b640625 100644 --- a/service/report/report.go +++ b/service/report/report.go @@ -19,7 +19,7 @@ func CreateTorrentReport(torrentReport model.TorrentReport) error { return nil } -func DeleteTorrentReport(id int) (error, int) { +func DeleteTorrentReport(id uint) (error, int) { var torrentReport model.TorrentReport if db.ORM.First(&torrentReport, id).RecordNotFound() { return errors.New("Trying to delete a torrent report that does not exists."), http.StatusNotFound From c84140964b82fa77906b726c6b026db4e2f80c08 Mon Sep 17 00:00:00 2001 From: Ramon Dantas Date: Wed, 10 May 2017 16:45:39 -0300 Subject: [PATCH 2/7] Add language selector (#298) --- router/templateVariables.go | 1 + router/userHandler.go | 6 ++++-- templates/_profile_edit.html | 5 ++++- util/languages/translation.go | 26 +++++++++++++++++++++++++- 4 files changed, 34 insertions(+), 4 deletions(-) diff --git a/router/templateVariables.go b/router/templateVariables.go index c1907ca6..20d852f5 100644 --- a/router/templateVariables.go +++ b/router/templateVariables.go @@ -59,6 +59,7 @@ type UserProfileEditVariables struct { UserForm userForms.UserForm FormErrors map[string][]string FormInfos map[string][]string + Languages map[string]string Search SearchForm Navigation Navigation User *model.User diff --git a/router/userHandler.go b/router/userHandler.go index 2e74b855..67a53d7b 100755 --- a/router/userHandler.go +++ b/router/userHandler.go @@ -115,7 +115,8 @@ func UserDetailsHandler(w http.ResponseWriter, r *http.Request) { languages.SetTranslationFromRequest(viewProfileEditTemplate, r, "en-us") searchForm := NewSearchForm() searchForm.HideAdvancedSearch = true - htv := UserProfileEditVariables{&userProfile, b, form.NewErrors(), form.NewInfos(), searchForm, Navigation{}, currentUser, r.URL, mux.CurrentRoute(r)} + availableLanguages := languages.GetAvailableLanguages() + htv := UserProfileEditVariables{&userProfile, b, form.NewErrors(), form.NewInfos(), availableLanguages, searchForm, Navigation{}, currentUser, r.URL, mux.CurrentRoute(r)} err := viewProfileEditTemplate.ExecuteTemplate(w, "index.html", htv) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) @@ -158,7 +159,8 @@ func UserProfileFormHandler(w http.ResponseWriter, r *http.Request) { } } } - htv := UserProfileEditVariables{&userProfile, b, err, infos, NewSearchForm(), Navigation{}, currentUser, r.URL, mux.CurrentRoute(r)} + availableLanguages := languages.GetAvailableLanguages() + htv := UserProfileEditVariables{&userProfile, b, err, infos, availableLanguages, NewSearchForm(), Navigation{}, currentUser, r.URL, mux.CurrentRoute(r)} errorTmpl := viewProfileEditTemplate.ExecuteTemplate(w, "index.html", htv) if errorTmpl != nil { http.Error(w, errorTmpl.Error(), http.StatusInternalServerError) diff --git a/templates/_profile_edit.html b/templates/_profile_edit.html index a3496f45..c5198f00 100644 --- a/templates/_profile_edit.html +++ b/templates/_profile_edit.html @@ -23,7 +23,10 @@
{{ range (index $.FormErrors "language")}} diff --git a/util/languages/translation.go b/util/languages/translation.go index d907a8d2..aa25588d 100644 --- a/util/languages/translation.go +++ b/util/languages/translation.go @@ -3,6 +3,7 @@ package languages import ( "fmt" "github.com/nicksnyder/go-i18n/i18n" + "github.com/ewhal/nyaa/service/user" "html/template" "net/http" ) @@ -33,6 +34,22 @@ func TfuncWithFallback(language string, languages ...string) (i18n.TranslateFunc }, nil } +func GetAvailableLanguages() (languages map[string]string) { + languages = make(map[string]string) + var T i18n.TranslateFunc + for _, languageTag := range i18n.LanguageTags() { + T, _ = i18n.Tfunc(languageTag) + /* Translation files should have an ID with the translated language name. + If they don't, just use the languageTag */ + if languageName := T("language_name"); languageName != "language_name" { + languages[languageTag] = languageName; + } else { + languages[languageTag] = languageTag + } + } + return +} + func SetTranslation(tmpl *template.Template, language string, languages ...string) i18n.TranslateFunc { T, _ := TfuncWithFallback(language, languages...) tmpl.Funcs(map[string]interface{}{ @@ -44,12 +61,19 @@ func SetTranslation(tmpl *template.Template, language string, languages ...strin } func SetTranslationFromRequest(tmpl *template.Template, r *http.Request, defaultLanguage string) i18n.TranslateFunc { + userLanguage := "" + user, _, err := userService.RetrieveCurrentUser(r) + if err == nil { + userLanguage = user.Language; + } + cookie, err := r.Cookie("lang") cookieLanguage := "" if err == nil { cookieLanguage = cookie.Value } + // go-i18n supports the format of the Accept-Language header, thankfully. headerLanguage := r.Header.Get("Accept-Language") - return SetTranslation(tmpl, cookieLanguage, headerLanguage, defaultLanguage) + return SetTranslation(tmpl, userLanguage, cookieLanguage, headerLanguage, defaultLanguage) } From 64b0af5db536c8249d119cf9afd28cbbed98dc4d Mon Sep 17 00:00:00 2001 From: Nutjob Date: Wed, 10 May 2017 21:45:50 +0200 Subject: [PATCH 3/7] Fixed minor typo. (#297) * Create it-it.all.json Created the initial italian translation * Copied the english version. * Initial Translation (uncomplete) * More stuff translated. * Correction. * Almost finished. * Quasi finito-parte 2. * Finished. * Added missing translation * Fixed typo. * Update it-it.all.json * Fixed minor typo. * Added the missing < --- translations/it-it.all.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/translations/it-it.all.json b/translations/it-it.all.json index a00317c8..787ab652 100644 --- a/translations/it-it.all.json +++ b/translations/it-it.all.json @@ -25,7 +25,7 @@ }, { "id":"signup_box_title", - "translation": "Iscriviti È gratuito e lo sara per sempre." + "translation": "Iscriviti È gratuito e lo sarà per sempre." }, { "id":"username", @@ -269,7 +269,7 @@ }, { "id": "answer_is_nyaa_db_lost", - "translation": "Abbiamo un database dei torrent di nyaa fino al 5 Aprile/s> 1° Maggio. Questo vuol dire che quasi niente è andato perduto." + "translation": "Abbiamo un database dei torrent di nyaa fino al 5 Aprile 1° Maggio. Questo vuol dire che quasi niente è andato perduto." }, { "id": "answer_is_sukebei_db_lost", From 8ce073a7a01dfba9af631a87c96170bd77197912 Mon Sep 17 00:00:00 2001 From: Furudo-Erika Date: Wed, 10 May 2017 21:46:21 +0200 Subject: [PATCH 4/7] a < was missing (#292) From 38ff2a6e28ee12e083e4fbf22882b56be8e07f2d Mon Sep 17 00:00:00 2001 From: Juan Navarro Date: Wed, 10 May 2017 14:46:34 -0500 Subject: [PATCH 5/7] Fixed New view template design. Changed Id to ID. Forced images inside description to fit container. (#289) --- public/css/style-night.css | 7 ++ public/css/style.css | 7 ++ templates/view.html | 175 ++++++++++++++++++------------------- 3 files changed, 100 insertions(+), 89 deletions(-) diff --git a/public/css/style-night.css b/public/css/style-night.css index 289d160e..f4ffb023 100644 --- a/public/css/style-night.css +++ b/public/css/style-night.css @@ -123,3 +123,10 @@ a:hover { #mainmenu a.nightswitch { background-image: url(/img/moon.png); } + +/* Force images on description to fit width */ +#description img { + display: block; + max-width: 100%; + height: auto; +} diff --git a/public/css/style.css b/public/css/style.css index 02cec37b..cd1a1595 100644 --- a/public/css/style.css +++ b/public/css/style.css @@ -339,3 +339,10 @@ footer { color: #616161; text-shadow: -1px -1px #999999; } + +/* Force images on description to fit width */ +#description img { + display: block; + max-width: 100%; + height: auto; +} diff --git a/templates/view.html b/templates/view.html index c3bd33b8..d03af3d9 100644 --- a/templates/view.html +++ b/templates/view.html @@ -1,96 +1,94 @@ {{define "title"}}{{.Torrent.Name}}{{end}} {{define "contclass"}}cont-view{{end}} {{define "content"}} -
- {{with .Torrent}} -
- - - - - - - - - - - - - - - - - - - - - {{if ne .WebsiteLink ""}} - - - - - {{end}} - - - - - - - - - - - - - - - - - {{ range $index, $element := .Comments }} - - - - - {{end}} -
{{T "name"}} - {{.Name}} - -
{{T "hash"}}{{.Hash}}
{{T "date"}}{{.Date}}
{{T "size"}}{{.Filesize}}
Uploader - {{.UploaderName}} - {{if ne .OldUploader ""}} - ({{.OldUploader}}) - {{end}} -
{{T "Link"}}{{.WebsiteLink}}
{{T "links"}} - - Download! - - - - Torrent file - - - Report! - -
{{T "description"}}{{.Description}}
{{T "comments"}}
- {{$index}} {{.Username}} - {{.Content}}
- {{end}} -
-
- {{/* There should be a better way to use translation on this... */}} - - +
+ {{with .Torrent}} +
+
+
+
+
+
+

{{.Name}}

+
+ +

Uploaded by {{.UploaderName}}

+
+
+
+
+
+
+ + Download! + + {{if ne .TorrentLink ""}} + + Torrent file + + + Report! + {{end}} +
+
+
+
+

{{T "hash"}}

+

{{.Hash}}

+
+

{{T "date"}}

+

{{.Date}}

+
+

{{T "size"}}

+

{{.Filesize}}

+
+ {{if ne .WebsiteLink ""}} +

{{T "Link"}}

+

{{.WebsiteLink}}

+
+ {{end}} +
- {{with .Captcha}} {{block "captcha" .}}{{end}} {{end}} - - +
+
+

{{T "description"}}

+
{{.Description}}
+
+
+
+
+

{{T "comments"}}

+ {{ range $index, $element := .Comments }} +
+
+ {{$index}} {{.Username}} +
+
+ {{.Content}} +
+
+ {{end}} +
+
+
+ {{end}} +
+
+
+
+ {{/* There should be a better way to use translation on this... */}} + + +
+ {{with .Captcha}} {{block "captcha" .}}{{end}} {{end}} + +
+
+
{{with .Torrent}} {{end}} From 963c2f4c3852e53e458ac54229267c4174e77d60 Mon Sep 17 00:00:00 2001 From: akuma06 Date: Wed, 10 May 2017 21:47:21 +0200 Subject: [PATCH 6/7] Revert "Delete button torrent view -- alucard" This reverts commit 134276b6ed63c3fe91db397f09aec3c1994c2e28. --- templates/view.html | 3 --- 1 file changed, 3 deletions(-) diff --git a/templates/view.html b/templates/view.html index 6ae9fe61..c3bd33b8 100644 --- a/templates/view.html +++ b/templates/view.html @@ -53,9 +53,6 @@ Report! - {{ if HasAdmin $.User}} - {{ T "delete" }} - {{end}} From dc5bd3991a7903e326e5e75a34d4137da3ed4437 Mon Sep 17 00:00:00 2001 From: triwa Date: Wed, 10 May 2017 14:49:16 -0500 Subject: [PATCH 7/7] unfuck comment section (#299) --- public/css/style.css | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/public/css/style.css b/public/css/style.css index cd1a1595..e6402444 100644 --- a/public/css/style.css +++ b/public/css/style.css @@ -104,7 +104,8 @@ td { .comment-row td:first-of-type { vertical-align: top; - text-align: right; + text-align: left; + color:#bbb; } /* Table style & fixes */