diff --git a/.travis.yml b/.travis.yml
index 6648ea7e..a188d2fe 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -12,7 +12,6 @@ install:
- go get github.com/gorilla/securecookie
- go get golang.org/x/crypto/bcrypt
- go get github.com/nicksnyder/go-i18n/i18n
-- go get github.com/valyala/quicktemplate
- go build
deploy:
provider: releases
diff --git a/router/faqHandler.go b/router/faqHandler.go
index 92540af1..e4ab1768 100644
--- a/router/faqHandler.go
+++ b/router/faqHandler.go
@@ -4,16 +4,20 @@ import (
"html/template"
"net/http"
- "github.com/ewhal/nyaa/templates"
"github.com/gorilla/mux"
)
var faqTemplate = template.Must(template.New("FAQ").Funcs(FuncMap).ParseFiles("templates/index.html", "templates/FAQ.html"))
+func init() {
+ // common
+ template.Must(faqTemplate.ParseGlob("templates/_*.html"))
+}
+
func FaqHandler(w http.ResponseWriter, r *http.Request) {
- searchForm := templates.NewSearchForm()
+ searchForm := NewSearchForm()
searchForm.HideAdvancedSearch = true
- err := faqTemplate.ExecuteTemplate(w, "index.html", FaqTemplateVariables{templates.Navigation{}, searchForm, r.URL, mux.CurrentRoute(r)})
+ err := faqTemplate.ExecuteTemplate(w, "index.html", FaqTemplateVariables{Navigation{}, searchForm, r.URL, mux.CurrentRoute(r)})
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
diff --git a/router/homeHandler.go b/router/homeHandler.go
index f897111d..796cfc26 100644
--- a/router/homeHandler.go
+++ b/router/homeHandler.go
@@ -8,12 +8,15 @@ import (
"github.com/ewhal/nyaa/model"
"github.com/ewhal/nyaa/service/torrent"
- "github.com/ewhal/nyaa/templates"
"github.com/gorilla/mux"
)
var homeTemplate = template.Must(template.New("home").Funcs(FuncMap).ParseFiles("templates/index.html", "templates/home.html"))
+func init() {
+ template.Must(homeTemplate.ParseGlob("templates/_*.html")) // common
+}
+
func HomeHandler(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
page := vars["page"]
@@ -38,8 +41,8 @@ func HomeHandler(w http.ResponseWriter, r *http.Request) {
b = append(b, res)
}
- navigationTorrents := templates.Navigation{nbTorrents, maxPerPage, pagenum, "search_page"}
- htv := HomeTemplateVariables{b, templates.NewSearchForm(), navigationTorrents, r.URL, mux.CurrentRoute(r)}
+ navigationTorrents := Navigation{nbTorrents, maxPerPage, pagenum, "search_page"}
+ htv := HomeTemplateVariables{b, NewSearchForm(), navigationTorrents, r.URL, mux.CurrentRoute(r)}
err := homeTemplate.ExecuteTemplate(w, "index.html", htv)
if err != nil {
diff --git a/router/searchHandler.go b/router/searchHandler.go
index e0e08651..8b11db25 100644
--- a/router/searchHandler.go
+++ b/router/searchHandler.go
@@ -7,13 +7,16 @@ import (
"strconv"
"github.com/ewhal/nyaa/model"
- "github.com/ewhal/nyaa/templates"
"github.com/ewhal/nyaa/util/search"
"github.com/gorilla/mux"
)
var searchTemplate = template.Must(template.New("home").Funcs(FuncMap).ParseFiles("templates/index.html", "templates/home.html"))
+func init() {
+ template.Must(searchTemplate.ParseGlob("templates/_*.html")) // common
+}
+
func SearchHandler(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
page := vars["page"]
@@ -33,8 +36,8 @@ func SearchHandler(w http.ResponseWriter, r *http.Request) {
b = append(b, res)
}
- navigationTorrents := templates.Navigation{nbTorrents, search_param.Max, pagenum, "search_page"}
- searchForm := templates.SearchForm{
+ navigationTorrents := Navigation{nbTorrents, search_param.Max, pagenum, "search_page"}
+ searchForm := SearchForm{
search_param.Query,
search_param.Status,
search_param.Category,
diff --git a/router/templateFunctions.go b/router/templateFunctions.go
index a01e73e6..a2fad90f 100644
--- a/router/templateFunctions.go
+++ b/router/templateFunctions.go
@@ -6,8 +6,6 @@ import (
"math"
"net/url"
"strconv"
-
- "github.com/ewhal/nyaa/templates"
)
var FuncMap = template.FuncMap{
@@ -22,11 +20,11 @@ var FuncMap = template.FuncMap{
"genRouteWithQuery": func(name string, currentUrl *url.URL, params ...string) template.HTML {
url, err := Router.Get(name).URL(params...)
if err == nil {
- return template.HTML(url.String() + "?" + currentUrl.RawQuery)
+ return template.HTML(url.String()+ "?" + currentUrl.RawQuery)
}
return "error"
},
- "genNav": func(nav templates.Navigation, currentUrl *url.URL, pagesSelectable int) template.HTML {
+ "genNav": func(nav Navigation, currentUrl *url.URL, pagesSelectable int) template.HTML {
maxPages := math.Ceil(float64(nav.TotalItem) / float64(nav.MaxItemPerPage))
var ret = ""
@@ -59,13 +57,4 @@ var FuncMap = template.FuncMap{
}
return template.HTML(ret)
},
- "SearchCommon": func(s templates.SearchForm) template.HTML {
- return template.HTML(templates.SearchCommon(s))
- },
- "SearchButton": func(s templates.SearchForm) template.HTML {
- return template.HTML(templates.SearchButton(s))
- },
- "SearchAdvanced": func(nav templates.Navigation, s templates.SearchForm) template.HTML {
- return template.HTML(templates.SearchAdvanced(nav, s))
- },
}
diff --git a/router/templateVariables.go b/router/templateVariables.go
index 9b80e97c..27fc6994 100644
--- a/router/templateVariables.go
+++ b/router/templateVariables.go
@@ -4,7 +4,6 @@ import (
"net/url"
"github.com/ewhal/nyaa/model"
- "github.com/ewhal/nyaa/templates"
userForms "github.com/ewhal/nyaa/service/user/form"
"github.com/gorilla/mux"
)
@@ -16,40 +15,86 @@ import (
*/
type FaqTemplateVariables struct {
- Navigation templates.Navigation
- Search templates.SearchForm
+ Navigation Navigation
+ Search SearchForm
URL *url.URL // For parsing Url in templates
Route *mux.Route // For getting current route in templates
}
type ViewTemplateVariables struct {
Torrent model.TorrentsJson
- Search templates.SearchForm
- Navigation templates.Navigation
+ Search SearchForm
+ Navigation Navigation
URL *url.URL // For parsing Url in templates
Route *mux.Route // For getting current route in templates
}
type UserRegisterTemplateVariables struct {
- RegistrationForm userForms.RegistrationForm
- Search templates.SearchForm
- Navigation templates.Navigation
- URL *url.URL // For parsing Url in templates
- Route *mux.Route // For getting current route in templates
+ RegistrationForm userForms.RegistrationForm
+ Search SearchForm
+ Navigation Navigation
+ URL *url.URL // For parsing Url in templates
+ Route *mux.Route // For getting current route in templates
}
type HomeTemplateVariables struct {
- ListTorrents []model.TorrentsJson
- Search templates.SearchForm
- Navigation templates.Navigation
- URL *url.URL // For parsing Url in templates
- Route *mux.Route // For getting current route in templates
+ ListTorrents []model.TorrentsJson
+ Search SearchForm
+ Navigation Navigation
+ URL *url.URL // For parsing Url in templates
+ Route *mux.Route // For getting current route in templates
}
type UploadTemplateVariables struct {
Upload UploadForm
- Search templates.SearchForm
- Navigation templates.Navigation
+ Search SearchForm
+ Navigation Navigation
URL *url.URL
Route *mux.Route
}
+
+/*
+ * Variables used by the upper ones
+ */
+type Navigation struct {
+ TotalItem int
+ MaxItemPerPage int
+ CurrentPage int
+ Route string
+}
+
+type SearchForm struct {
+ Query string
+ Status string
+ Category string
+ Sort string
+ Order string
+ HideAdvancedSearch bool
+}
+
+// Some Default Values to ease things out
+func NewSearchForm(params ...string) (searchForm SearchForm) {
+ if len(params) > 1 {
+ searchForm.Category = params[0]
+ } else {
+ searchForm.Category = "_"
+ }
+ if len(params) > 2 {
+ searchForm.Sort = params[1]
+ } else {
+ searchForm.Sort = "torrent_id"
+ }
+ if len(params) > 3 {
+ order := params[2]
+ if order == "DESC" {
+ searchForm.Order = order
+ } else if order == "ASC" {
+ searchForm.Order = order
+ } else {
+ // TODO: handle invalid value (?)
+ }
+ } else {
+ searchForm.Order = "DESC"
+ }
+ return
+}
diff --git a/router/uploadHandler.go b/router/uploadHandler.go
index f40ae283..76b9d91c 100644
--- a/router/uploadHandler.go
+++ b/router/uploadHandler.go
@@ -4,12 +4,15 @@ import (
"html/template"
"net/http"
- "github.com/ewhal/nyaa/templates"
"github.com/gorilla/mux"
)
var uploadTemplate = template.Must(template.New("upload").Funcs(FuncMap).ParseFiles("templates/index.html", "templates/upload.html"))
+func init() {
+ template.Must(uploadTemplate.ParseGlob("templates/_*.html")) // common
+}
+
func UploadHandler(w http.ResponseWriter, r *http.Request) {
var err error
var uploadForm UploadForm
@@ -21,7 +24,7 @@ func UploadHandler(w http.ResponseWriter, r *http.Request) {
//add to db and redirect depending on result
}
} else if r.Method == "GET" {
- htv := UploadTemplateVariables{uploadForm, templates.NewSearchForm(), templates.Navigation{}, r.URL, mux.CurrentRoute(r)}
+ htv := UploadTemplateVariables{uploadForm, NewSearchForm(), Navigation{}, r.URL, mux.CurrentRoute(r)}
err = uploadTemplate.ExecuteTemplate(w, "index.html", htv)
} else {
w.WriteHeader(http.StatusMethodNotAllowed)
diff --git a/router/userHandler.go b/router/userHandler.go
index 4b8ec24b..78668e1f 100644
--- a/router/userHandler.go
+++ b/router/userHandler.go
@@ -1,26 +1,30 @@
package router
-import(
+import (
"html/template"
"net/http"
- "github.com/ewhal/nyaa/templates"
"github.com/ewhal/nyaa/service/user/form"
"github.com/ewhal/nyaa/util/modelHelper"
"github.com/gorilla/mux"
)
var viewRegisterTemplate = template.Must(template.New("view").Funcs(FuncMap).ParseFiles("templates/index.html", "templates/user/register.html"))
+
//var viewTemplate = template.Must(template.New("view").Funcs(FuncMap).ParseFiles("templates/index.html", "templates/view.html"))
//var viewTemplate = template.Must(template.New("view").Funcs(FuncMap).ParseFiles("templates/index.html", "templates/view.html"))
+func init() {
+ template.Must(viewRegisterTemplate.ParseGlob("templates/_*.html"))
+}
+
// Getting View User Registration
func UserRegisterFormHandler(w http.ResponseWriter, r *http.Request) {
b := form.RegistrationForm{}
modelHelper.BindValueForm(b, r)
- htv := UserRegisterTemplateVariables{b, templates.NewSearchForm(), templates.Navigation{}, r.URL, mux.CurrentRoute(r)}
+ htv := UserRegisterTemplateVariables{b, NewSearchForm(), Navigation{}, r.URL, mux.CurrentRoute(r)}
err := viewTemplate.ExecuteTemplate(w, "index.html", htv)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
@@ -37,7 +41,7 @@ func UserProfileHandler(w http.ResponseWriter, r *http.Request) {
}
-// Getting View User Profile Update
+// Getting View User Profile Update
func UserProfileFormHandler(w http.ResponseWriter, r *http.Request) {
}
@@ -56,4 +60,3 @@ func UserLoginPostHandler(w http.ResponseWriter, r *http.Request) {
func UserProfilePostHandler(w http.ResponseWriter, r *http.Request) {
}
-
diff --git a/router/viewTorrentHandler.go b/router/viewTorrentHandler.go
index 5d33f51a..ed1654c7 100644
--- a/router/viewTorrentHandler.go
+++ b/router/viewTorrentHandler.go
@@ -5,12 +5,15 @@ import (
"net/http"
"github.com/ewhal/nyaa/service/torrent"
- "github.com/ewhal/nyaa/templates"
"github.com/gorilla/mux"
)
var viewTemplate = template.Must(template.New("view").Funcs(FuncMap).ParseFiles("templates/index.html", "templates/view.html"))
+func init() {
+ template.Must(viewTemplate.ParseGlob("templates/_*.html")) // common
+}
+
func ViewHandler(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
id := vars["id"]
@@ -18,7 +21,7 @@ func ViewHandler(w http.ResponseWriter, r *http.Request) {
torrent, err := torrentService.GetTorrentById(id)
b := torrent.ToJson()
- htv := ViewTemplateVariables{b, templates.NewSearchForm(), templates.Navigation{}, r.URL, mux.CurrentRoute(r)}
+ htv := ViewTemplateVariables{b, NewSearchForm(), Navigation{}, r.URL, mux.CurrentRoute(r)}
err = viewTemplate.ExecuteTemplate(w, "index.html", htv)
if err != nil {
diff --git a/templates/_search.html b/templates/_search.html
new file mode 100644
index 00000000..b6baf37c
--- /dev/null
+++ b/templates/_search.html
@@ -0,0 +1,73 @@
+{{define "search_common"}}
+
+
+{{end}}
+{{define "search_advanced"}}
+
+
+
+{{end}}
+
+{{define "search_button"}}
+
+
+
+
+
+
+{{end}}
diff --git a/templates/index.html b/templates/index.html
index 6355a252..226ac194 100755
--- a/templates/index.html
+++ b/templates/index.html
@@ -50,8 +50,8 @@
@@ -67,9 +67,9 @@
Advanced Search
diff --git a/templates/search.html b/templates/search.html
deleted file mode 100644
index 3de2094d..00000000
--- a/templates/search.html
+++ /dev/null
@@ -1,94 +0,0 @@
-{% import "strconv" %}
-
-{% code type searchField struct{
- id, name string
-} %}
-
-Common seatch part of many pages
-{% func SearchCommon(search SearchForm) %}
-
-
-{% endfunc %}
-
-Options fields of a search