51 lines
1.4 KiB
Go
51 lines
1.4 KiB
Go
package view
|
|
|
|
import (
|
|
"api-cds-search/cmd/model"
|
|
"errors"
|
|
"net/http"
|
|
"net/url"
|
|
|
|
"code.achtarmig.org/pas/ui/element"
|
|
"code.achtarmig.org/pas/ui/element/boxedlist"
|
|
"code.achtarmig.org/pas/ui/element/boxedlist/expander"
|
|
"code.achtarmig.org/pas/ui/element/option"
|
|
"code.achtarmig.org/pas/ui/element/placeholder"
|
|
"code.achtarmig.org/pas/ui/element/view"
|
|
)
|
|
|
|
func results(v *view.Element, m *model.ResultsModel) element.ElementInterface {
|
|
cont := v.GetElement("SearchResultsContainer")
|
|
cont.DeleteAllChildren()
|
|
|
|
bl, _ := boxedlist.New(cont, "", func(p *boxedlist.Element) {
|
|
p.MaxWidth = 42
|
|
p.MinWidth = 20
|
|
for _, result := range m.Views {
|
|
expander.New(p, func(p *expander.Element) {
|
|
p.Title = result.DisplayName.String()
|
|
p.Subtitle = result.TechnicalName.String()
|
|
p.PlaceholderHeight = 21 * result.NumberOfFields
|
|
p.CallbackLazyLoad = func(e *expander.Element, w http.ResponseWriter, r *http.Request) error {
|
|
http.Redirect(w, r, "/cds?q="+url.QueryEscape(result.TechnicalName.String()), http.StatusSeeOther)
|
|
return errors.New("redirect")
|
|
}
|
|
})
|
|
}
|
|
})
|
|
return bl
|
|
}
|
|
|
|
func noResults(v *view.Element) element.ElementInterface {
|
|
cont := v.GetElement("SearchResultsContainer")
|
|
cont.DeleteAllChildren()
|
|
|
|
pl, _ := placeholder.New(cont, "", func(p *placeholder.Element) {
|
|
p.Icon = option.IconLoupe
|
|
p.Title = "No Results"
|
|
p.Subtitle = "Try refining your search term"
|
|
})
|
|
|
|
return pl
|
|
}
|