-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
102 lines (96 loc) · 2.51 KB
/
options.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// Defines SearchForm
package main
import (
"github.com/gorilla/schema"
"github.com/icwells/compOncDB/src/codbutils"
"net/http"
"strconv"
"strings"
)
type Options struct {
Agecol bool
AllTaxa bool
Cancerrate bool
Infant bool
Keepall bool
Lifehistory bool
Location string
Min int
Necropsy string
Operation string
Pathology bool
Print bool
Sexcol bool
Source string
Taxa string
Taxacol bool
Tissue string
TumorType string
Value string
Wild bool
}
func setOptions(r *http.Request) *Options {
// Returns commonly used options
opt := new(Options)
decoder := schema.NewDecoder()
decoder.Decode(opt, r.PostForm)
return opt
}
func setEvaluation(r *http.Request, columns map[string]string, search, n string) (codbutils.Evaluation, string, bool) {
// Populates evalutaiton struct if matching term is found
pass := false
var e codbutils.Evaluation
var msg string
e.Table = strings.TrimSpace(r.PostForm.Get(search + "Table" + n))
e.Column = strings.TrimSpace(r.PostForm.Get(search + "Column" + n))
e.Operator = strings.TrimSpace(r.PostForm.Get(search + "Operator" + n))
e.Value = strings.TrimSpace(r.PostForm.Get(search + "Value" + n))
slct := strings.TrimSpace(r.PostForm.Get(search + "Select" + n))
if e.Table == "Accounts" {
msg = "Cannot access Accounts table."
} else {
for _, i := range []string{e.Table, e.Column, e.Operator} {
if len(i) >= 2 && i != "Empty" {
pass = true
}
}
if pass {
if e.Value == "" && slct != "" {
// Assign selected value to input value
e.Value = slct
}
e.SetIDType(columns)
} else {
msg = "Please supply valid table, column, and value."
}
}
return e, msg, pass
}
func checkEvaluations(r *http.Request, columns map[string]string) ([][]codbutils.Evaluation, string) {
// Reads in variable number of search parameters
var ret [][]codbutils.Evaluation
var msg string
var e codbutils.Evaluation
eval := make(map[string][]codbutils.Evaluation)
for i := 0; i < 10; i++ {
// Loop through all possible searches since deletions might disrupt numerical order
found := true
count := 0
for found == true {
// Keep checking until count exceeds number of fields
var m string
search := strconv.Itoa(i)
e, m, found = setEvaluation(r, columns, search, strconv.Itoa(count))
if found {
eval[search] = append(eval[search], e)
count++
} else if len(eval) == 0 {
msg = m
}
}
}
for _, v := range eval {
ret = append(ret, v)
}
return ret, msg
}