From f8de340265ff37e4b0dda7779af640196eb720aa Mon Sep 17 00:00:00 2001 From: akuma06 Date: Mon, 10 Jul 2017 15:24:52 +0200 Subject: [PATCH] Added search refine on every pages + fixed kilo.js --- controllers/helpers.go | 2 +- controllers/search_handler.go | 4 +- public/js/main.js | 41 +++------ templates/admin/paneltorrentedit.jet.html | 3 - templates/layouts/index_admin.jet.html | 8 +- templates/layouts/index_site.jet.html | 7 +- templates/layouts/partials/base.jet.html | 6 +- .../layouts/partials/helpers/search.jet.html | 86 +++++++++++-------- templates/site/torrents/edit.jet.html | 3 - templates/site/torrents/listing.jet.html | 5 -- templates/site/torrents/upload.jet.html | 3 - templates/site/torrents/view.jet.html | 4 - templates/site/user/torrents.jet.html | 1 - 13 files changed, 84 insertions(+), 89 deletions(-) diff --git a/controllers/helpers.go b/controllers/helpers.go index 4a22fced..34468d20 100644 --- a/controllers/helpers.go +++ b/controllers/helpers.go @@ -39,7 +39,7 @@ func newSearchForm(c *gin.Context) searchForm { return searchForm{ Category: "_", ShowItemsPerPage: true, - ShowRefine: true, + ShowRefine: false, SizeType: sizeType, DateType: c.Query("dateType"), MinSize: c.Query("minSize"), // We need to overwrite the value here, since size are formatted diff --git a/controllers/search_handler.go b/controllers/search_handler.go index fffab02e..2b36d520 100644 --- a/controllers/search_handler.go +++ b/controllers/search_handler.go @@ -56,8 +56,8 @@ func SearchHandler(c *gin.Context) { searchForm := newSearchForm(c) searchForm.TorrentParam, searchForm.Category = searchParam, category - if c.Query("refine") == "" { - searchForm.ShowRefine = false + if c.Query("refine") == "1" { + searchForm.ShowRefine = true } modelList(c, "site/torrents/listing.jet.html", models.TorrentsToJSON(torrents), nav, searchForm) diff --git a/public/js/main.js b/public/js/main.js index aafcf04e..6a194914 100644 --- a/public/js/main.js +++ b/public/js/main.js @@ -1,8 +1,5 @@ // @source https://github.com/NyaaPantsu/nyaa/tree/dev/public/js // @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt Expat -var explosion = document.getElementById("explosion"); -var nyanpassu = document.getElementById("nyanpassu"); -var kawaii = document.getElementById("kawaii"); // Switches between themes when a new one is selected function switchThemes(){ @@ -69,35 +66,23 @@ document.addEventListener("DOMContentLoaded", function(event) { document.getElementsByClassName("search-box")[0].style.width = ""; document.getElementsByClassName("h-user")[0].style.display = "inline-block"; }); + }); function playVoice() { - if (explosion) { - explosion.volume = 0.2; - explosion.play(); - } - else if (kawaii) { - kawaii.volume = 0.2; - kawaii.play(); - } - else { - nyanpassu.volume = 0.2; - nyanpassu.play(); - } + var mascotAudio = document.getElementById("explosion") || document.getElementById("nyanpassu") || document.getElementById("kawaii"); + if (mascotAudio !== undefined) { + mascotAudio.volume = 0.2; + mascotAudio.play(); + } else { + console.log("Your mascot doesn't support yet audio files!") + } } -var refine_button = document.getElementsByClassName("box refine")[0]; -refine_button.click(function( event ) { - event.preventDefault(); - toggleRefine(); +document.getElementsByClassName("form-input refine")[0].addEventListener("click", function (e) { + document.getElementsByClassName("box refine")[0].style.display = document.getElementsByClassName("box refine")[0].style.display == "none" ? "block" : "none"; + if(document.getElementsByClassName("form-input refine-searchbox")[0].value != document.getElementsByClassName("form-input search-box")[0].value) + document.getElementsByClassName("form-input refine-searchbox")[0].value = document.getElementsByClassName("form-input search-box")[0].value; + e.preventDefault(); }); - -function toggleRefine() { - if(refine_button != "undefined") { - refine_button.style.display = refine_button.style.display == "none" ? "block" : "none"; - if(document.getElementsByClassName("form-input refine-searchbox")[0].value == "") - document.getElementsByClassName("form-input refine-searchbox")[0].value = document.getElementsByClassName("form-input search-box")[0].value; - } - else document.getElementById("header-form").submit(); -} // @license-end diff --git a/templates/admin/paneltorrentedit.jet.html b/templates/admin/paneltorrentedit.jet.html index e51d2711..e2e1f765 100644 --- a/templates/admin/paneltorrentedit.jet.html +++ b/templates/admin/paneltorrentedit.jet.html @@ -1,8 +1,5 @@ {{ extends "layouts/index_admin" }} {{block title()}}{{ T("torrent_edit_panel") }}{{end}} -{{block additional_header()}} - -{{end}} {{ block content_body()}}

{{ T("torrent_edit_panel") }}

diff --git a/templates/layouts/index_admin.jet.html b/templates/layouts/index_admin.jet.html index ea4560a5..eae60fbb 100644 --- a/templates/layouts/index_admin.jet.html +++ b/templates/layouts/index_admin.jet.html @@ -10,4 +10,10 @@ {{ block contclass()}}content-admin{{end}} {* We add the mod panel title and the title block *} -{{block titleBase()}}Moderation Panel - {{block title()}}{{end}}{{end}} \ No newline at end of file +{{block titleBase()}}Moderation Panel - {{block title()}}{{end}}{{end}} + +{* We add the mod panel search refine and the body block *} +{{ block content_body_base()}} +{{ yield search_refine(url=URL.Parse("/mod/torrents")) }} +{{ block content_body()}}{{end}} +{{end}} \ No newline at end of file diff --git a/templates/layouts/index_site.jet.html b/templates/layouts/index_site.jet.html index 9c78a46a..9638dbd8 100644 --- a/templates/layouts/index_site.jet.html +++ b/templates/layouts/index_site.jet.html @@ -6,4 +6,9 @@ {{include "partials/menu/site"}} {{end}} -{{block titleBase()}} - {{block title()}}{{end}}{{end}} \ No newline at end of file +{{block titleBase()}} - {{block title()}}{{end}}{{end}} + +{{ block content_body_base()}} +{{ yield search_refine(url=URL.Parse("/search")) }} +{{ block content_body()}}{{end}} +{{end}} \ No newline at end of file diff --git a/templates/layouts/partials/base.jet.html b/templates/layouts/partials/base.jet.html index f9ff00e6..8d8e6953 100644 --- a/templates/layouts/partials/base.jet.html +++ b/templates/layouts/partials/base.jet.html @@ -1,5 +1,6 @@ {{import "helpers/errors"}} {{import "helpers/infos"}} +{{import "helpers/search"}} @@ -37,6 +38,9 @@ {{else}} {{end}} + + + {{block additional_header()}}{{end}} @@ -49,7 +53,7 @@
{{ yield infos()}} {{ yield errors()}} - {{ block content_body() }}{{end}} + {{ block content_body_base() }}{{end}}
{{ block mascot() }} {{if Mascot != "hide"}} diff --git a/templates/layouts/partials/helpers/search.jet.html b/templates/layouts/partials/helpers/search.jet.html index 12934260..6b551c16 100644 --- a/templates/layouts/partials/helpers/search.jet.html +++ b/templates/layouts/partials/helpers/search.jet.html @@ -10,45 +10,59 @@ {{block search_button() }} - + {{end}} -{{block search_refine() }} -

{{ T("refine_search") }}

-
+{{block search_refine(url="") }} +
+

{{ T("refine_search") }}

+ - Search for: - Show: Limit: - {{ T("between")}} {{ T("and")}} - - {{ T("large")}} - - {{ T("between")}} {{ T("and")}} - - {{ T("old")}}. - -
- {{ range _, language := GetTorrentLanguages() }} - - - + Search for: + - {{ end }} -
- + Show: + + Limit: + + {{ T("between")}} + + {{ T("and")}} + + + {{ T("large")}} + + + {{ T("between")}} + + {{ T("and")}} + + + {{ T("old")}}. + +
+ {{ range _, language := GetTorrentLanguages() }} + + + + + {{ end }} +
+ +
{{end}} diff --git a/templates/site/torrents/edit.jet.html b/templates/site/torrents/edit.jet.html index 4fbd41f3..83568873 100644 --- a/templates/site/torrents/edit.jet.html +++ b/templates/site/torrents/edit.jet.html @@ -2,9 +2,6 @@ {{ import "layouts/partials/helpers/csrf" }} {{ import "layouts/partials/helpers/errors" }} {{block title()}}T("torrent_edit_panel"){{end}} -{{block additional_header()}} - -{{end}} {{block content_body()}}

{{ T("torrent_edit_panel") }}

diff --git a/templates/site/torrents/listing.jet.html b/templates/site/torrents/listing.jet.html index e84e4e87..5e71688d 100644 --- a/templates/site/torrents/listing.jet.html +++ b/templates/site/torrents/listing.jet.html @@ -2,13 +2,8 @@ {{ import "layouts/partials/helpers/search" }} {{block title()}}{{ T("home")}}{{end}} {{block contclass()}}{{if User.HasAdmin() }}content-admin{{end}}{{end}} -{{block additional_header()}} - - -{{end}} {{block content_body()}} -
{{ yield search_refine() }}
diff --git a/templates/site/torrents/upload.jet.html b/templates/site/torrents/upload.jet.html index bf7a51af..6a9bb29f 100644 --- a/templates/site/torrents/upload.jet.html +++ b/templates/site/torrents/upload.jet.html @@ -2,9 +2,6 @@ {{ import "layouts/partials/helpers/csrf" }} {{ import "layouts/partials/helpers/captcha" }} {{block title()}}{{ T("upload")}}{{end}} -{{block additional_header()}} - -{{end}} {{block content_body()}}
diff --git a/templates/site/torrents/view.jet.html b/templates/site/torrents/view.jet.html index 24a50aa6..605cf70d 100644 --- a/templates/site/torrents/view.jet.html +++ b/templates/site/torrents/view.jet.html @@ -3,10 +3,6 @@ {{ import "layouts/partials/helpers/captcha" }} {{ import "layouts/partials/helpers/treeview" }} {{block title()}}{{Torrent.Name}}{{end}} -{{block additional_header()}} - - -{{end}} {{block content_body()}}
diff --git a/templates/site/user/torrents.jet.html b/templates/site/user/torrents.jet.html index 214bf230..8b78c034 100644 --- a/templates/site/user/torrents.jet.html +++ b/templates/site/user/torrents.jet.html @@ -1,6 +1,5 @@ {{ extends "layouts/profile" }} {{ import "layouts/partials/menu/profile" }} -{{block additional_header()}}{{end}} {{ block profile_navigation()}}{{ yield profile_menu(route="profile") }}{{end}} {{block profile_content()}} {{ if len(UserProfile.Torrents) > 0 }}