Update and rename datatables.go to filter.go

This commit is contained in:
Saúl Ortega 2018-03-01 14:45:09 -05:00 committed by GitHub
parent 0bc2aaa868
commit c83453f363
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -49,6 +49,10 @@ func MustParse(r *http.Request) Filter {
return f return f
} }
func (f *Filter) PrepareResponse() Response {
return Response{Draw: f.Draw}
}
func parse(r *http.Request) (Filter, error) { func parse(r *http.Request) (Filter, error) {
var E error var E error
var F = Filter{ var F = Filter{
@ -60,6 +64,27 @@ func parse(r *http.Request) (Filter, error) {
var mapColsTmp = make(map[int]map[string]string) var mapColsTmp = make(map[int]map[string]string)
var mapOrdsTmp = make(map[int]map[string]string) var mapOrdsTmp = make(map[int]map[string]string)
F.Draw, E = ptoi(r, "draw")
if E != nil {
errores = append(errores, E.Error())
}
F.Start, E = ptoi(r, "start")
if E != nil {
errores = append(errores, E.Error())
}
F.Length, E = ptoi(r, "length")
if E != nil {
errores = append(errores, E.Error())
}
F.SearchValue, E = ptos(r, "search[value]")
if E != nil {
errores = append(errores, E.Error())
}
F.SearchRegex, E = ptob(r, "search[regex]")
if E != nil {
errores = append(errores, E.Error())
}
for ll, v := range r.Form { for ll, v := range r.Form {
if regexp.MustCompile(`^columns\[`).MatchString(ll) { if regexp.MustCompile(`^columns\[`).MatchString(ll) {
a := regexp.MustCompile(`^columns\[([0-9]+)\]\[`).ReplaceAllString(ll, "$1-") a := regexp.MustCompile(`^columns\[([0-9]+)\]\[`).ReplaceAllString(ll, "$1-")
@ -90,28 +115,6 @@ func parse(r *http.Request) (Filter, error) {
mapOrdsTmp[i] = make(map[string]string) mapOrdsTmp[i] = make(map[string]string)
} }
mapOrdsTmp[i][p[1]] = v[0] mapOrdsTmp[i][p[1]] = v[0]
} else if ll == "search[value]" {
F.SearchValue = strings.TrimSpace(v[0])
} else if ll == "search[regex]" {
F.SearchRegex, E = strconv.ParseBool(v[0])
if E != nil {
errores = append(errores, E.Error())
}
} else if ll == "start" {
F.Start, E = strconv.Atoi(v[0])
if E != nil {
errores = append(errores, E.Error())
}
} else if ll == "length" {
F.Length, E = strconv.Atoi(v[0])
if E != nil {
errores = append(errores, E.Error())
}
} else if ll == "draw" {
F.Draw, E = strconv.Atoi(v[0])
if E != nil {
errores = append(errores, E.Error())
}
} }
} }