mirror of
https://github.com/rystaf/mlmym.git
synced 2024-11-25 06:25:46 +00:00
search all, url
This commit is contained in:
parent
8dcbb2665e
commit
4a862b4e03
|
@ -947,14 +947,19 @@ func Search(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||||
state.GetSite()
|
state.GetSite()
|
||||||
}
|
}
|
||||||
m, _ := url.ParseQuery(r.URL.RawQuery)
|
m, _ := url.ParseQuery(r.URL.RawQuery)
|
||||||
state.SearchType = "Posts"
|
state.SearchType = "All"
|
||||||
if len(m["searchtype"]) > 0 {
|
if len(m["searchtype"]) > 0 {
|
||||||
switch m["searchtype"][0] {
|
switch m["searchtype"][0] {
|
||||||
|
case "Posts":
|
||||||
|
state.SearchType = "Posts"
|
||||||
case "Comments":
|
case "Comments":
|
||||||
state.SearchType = "Comments"
|
state.SearchType = "Comments"
|
||||||
case "Communities":
|
case "Communities":
|
||||||
state.SearchType = "Communities"
|
state.SearchType = "Communities"
|
||||||
|
case "Url":
|
||||||
|
state.SearchType = "Url"
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
state.Search(state.SearchType)
|
state.Search(state.SearchType)
|
||||||
Render(w, "index.html", state)
|
Render(w, "index.html", state)
|
||||||
|
|
13
state.go
13
state.go
|
@ -157,14 +157,14 @@ func (s State) Unknown() string {
|
||||||
func (p State) SortBy(v string) string {
|
func (p State) SortBy(v string) string {
|
||||||
var q string
|
var q string
|
||||||
if p.Query != "" || p.SearchType == "Communities" {
|
if p.Query != "" || p.SearchType == "Communities" {
|
||||||
q = "q=" + p.Query + "&communityname=" + p.CommunityName + "&username=" + p.UserName + "&searchtype=" + p.SearchType + "&"
|
q = "q=" + url.QueryEscape(p.Query) + "&communityname=" + p.CommunityName + "&username=" + p.UserName + "&searchtype=" + p.SearchType + "&"
|
||||||
}
|
}
|
||||||
return "?" + q + "sort=" + v + "&listingType=" + p.Listing
|
return "?" + q + "sort=" + v + "&listingType=" + p.Listing
|
||||||
}
|
}
|
||||||
func (p State) ListBy(v string) string {
|
func (p State) ListBy(v string) string {
|
||||||
var q string
|
var q string
|
||||||
if p.Query != "" || p.SearchType == "Communities" {
|
if p.Query != "" || p.SearchType == "Communities" {
|
||||||
q = "q=" + p.Query + "&communityname=" + p.CommunityName + "&username=" + p.UserName + "&searchtype=" + p.SearchType + "&"
|
q = "q=" + url.QueryEscape(p.Query) + "&communityname=" + p.CommunityName + "&username=" + p.UserName + "&searchtype=" + p.SearchType + "&"
|
||||||
}
|
}
|
||||||
return "?" + q + "sort=" + p.Sort + "&listingType=" + v
|
return "?" + q + "sort=" + p.Sort + "&listingType=" + v
|
||||||
}
|
}
|
||||||
|
@ -625,10 +625,14 @@ func (state *State) Search(searchtype string) {
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
for i, p := range resp.Posts {
|
for i, p := range resp.Posts {
|
||||||
state.Posts = append(state.Posts, Post{
|
post := Post{
|
||||||
PostView: p,
|
PostView: p,
|
||||||
Rank: (state.Page-1)*25 + i + 1,
|
Rank: (state.Page-1)*25 + i + 1,
|
||||||
State: state,
|
State: state,
|
||||||
|
}
|
||||||
|
state.Activities = append(state.Activities, Activity{
|
||||||
|
Timestamp: p.Post.Published,
|
||||||
|
Post: &post,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
for _, c := range resp.Comments {
|
for _, c := range resp.Comments {
|
||||||
|
@ -641,6 +645,9 @@ func (state *State) Search(searchtype string) {
|
||||||
Comment: &comment,
|
Comment: &comment,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
sort.Slice(state.Activities, func(i, j int) bool {
|
||||||
|
return state.Activities[i].Timestamp.After(state.Activities[j].Timestamp.Time)
|
||||||
|
})
|
||||||
state.Communities = resp.Communities
|
state.Communities = resp.Communities
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,8 +34,10 @@
|
||||||
{{ if ne .SearchType "Communities" }}
|
{{ if ne .SearchType "Communities" }}
|
||||||
<div>
|
<div>
|
||||||
<select name="searchtype">
|
<select name="searchtype">
|
||||||
|
<option value="All"{{ if eq .SearchType "All" }} selected{{ end }}>all</option>
|
||||||
<option value="Posts"{{ if eq .SearchType "Posts" }} selected{{ end }}>posts</option>
|
<option value="Posts"{{ if eq .SearchType "Posts" }} selected{{ end }}>posts</option>
|
||||||
<option value="Comments"{{ if eq .SearchType "Comments" }} selected{{ end }}>comments</option>
|
<option value="Comments"{{ if eq .SearchType "Comments" }} selected{{ end }}>comments</option>
|
||||||
|
<option value="Url"{{ if eq .SearchType "Url" }} selected{{ end }}>url</option>
|
||||||
</select>
|
</select>
|
||||||
<label>from
|
<label>from
|
||||||
<input type="text" placeholder="everywhere" name="communityname" value="{{.CommunityName}}"></label>
|
<input type="text" placeholder="everywhere" name="communityname" value="{{.CommunityName}}"></label>
|
||||||
|
|
Loading…
Reference in a new issue