Commit f1f300b13c74dac6cfd34d073a29d8ba9222e637
1 parent
da1d1d418f
Exists in
master
and in
1 other branch
Added nav node field
Showing
1 changed file
with
14 additions
and
11 deletions
Show diff stats
list_config.go
1 | package webutility | 1 | package webutility |
2 | 2 | ||
3 | import "gopkg.in/rana/ora.v3" | 3 | import "gopkg.in/rana/ora.v3" |
4 | 4 | ||
5 | type ListOptions struct { | 5 | type ListOptions struct { |
6 | GlobalFilter bool `json:"globalFilter"` | 6 | GlobalFilter bool `json:"globalFilter"` |
7 | LocalFilters bool `json:"localFilters"` | 7 | LocalFilters bool `json:"localFilters"` |
8 | RemoteFilters bool `json:"remoteFilters"` | 8 | RemoteFilters bool `json:"remoteFilters"` |
9 | Pagination bool `json:"pagination"` | 9 | Pagination bool `json:"pagination"` |
10 | PageSize uint64 `json:"pageSize"` | 10 | PageSize uint64 `json:"pageSize"` |
11 | Pivot bool `json:"pivot"` | 11 | Pivot bool `json:"pivot"` |
12 | Detail bool `json:"detail"` | 12 | Detail bool `json:"detail"` |
13 | Total bool `json:"total"` | 13 | Total bool `json:"total"` |
14 | } | 14 | } |
15 | 15 | ||
16 | type ListFilter struct { | 16 | type ListFilter struct { |
17 | Position uint32 `json:"-"` | 17 | Position uint32 `json:"-"` |
18 | ObjectType string `json:"-"` | 18 | ObjectType string `json:"-"` |
19 | FiltersField string `json:"filtersField"` | 19 | FiltersField string `json:"filtersField"` |
20 | DefaultValues string `json:"defaultValues"` | 20 | DefaultValues string `json:"defaultValues"` |
21 | FiltersType string `json:"filtersType"` | 21 | FiltersType string `json:"filtersType"` |
22 | FiltersLabel string `json:"filtersLabel"` | 22 | FiltersLabel string `json:"filtersLabel"` |
23 | DropdownConfig Dropdown `json:"dropdownConfig"` | 23 | DropdownConfig Dropdown `json:"dropdownConfig"` |
24 | } | 24 | } |
25 | 25 | ||
26 | type Dropdown struct { | 26 | type Dropdown struct { |
27 | ObjectType string `json:"objectType"` | 27 | ObjectType string `json:"objectType"` |
28 | FiltersField string `json:"filtersField"` | 28 | FiltersField string `json:"filtersField"` |
29 | IDField string `json:"idField"` | 29 | IDField string `json:"idField"` |
30 | LabelField string `json:"labelField"` | 30 | LabelField string `json:"labelField"` |
31 | 31 | ||
32 | } | 32 | } |
33 | 33 | ||
34 | type ListGraph struct { | 34 | type ListGraph struct { |
35 | ObjectType string `json:"objectType"` | 35 | ObjectType string `json:"objectType"` |
36 | X string `json:"xField"` | 36 | X string `json:"xField"` |
37 | Y string `json:"yField"` | 37 | Y string `json:"yField"` |
38 | GroupField string `json:"groupField"` | 38 | GroupField string `json:"groupField"` |
39 | Label string `json:"label"` | 39 | Label string `json:"label"` |
40 | } | 40 | } |
41 | 41 | ||
42 | type ListActions struct { | 42 | type ListActions struct { |
43 | Create bool `json:"create"` | 43 | Create bool `json:"create"` |
44 | Update bool `json:"update"` | 44 | Update bool `json:"update"` |
45 | Delete bool `json:"delete"` | 45 | Delete bool `json:"delete"` |
46 | Export bool `json:"export"` | 46 | Export bool `json:"export"` |
47 | Print bool `json:"print"` | 47 | Print bool `json:"print"` |
48 | Graph bool `json:"graph"` | 48 | Graph bool `json:"graph"` |
49 | } | 49 | } |
50 | 50 | ||
51 | type ListNavNode struct { | 51 | type ListNavNode struct { |
52 | ObjectType string `json:"objectType"` | 52 | ObjectType string `json:"objectType"` |
53 | LabelField string `json:"label"` | 53 | LabelField string `json:"label"` |
54 | Icon string `json:"icon"` | 54 | Icon string `json:"icon"` |
55 | ParentObjectType string `json:"parentObjectType"` | 55 | ParentObjectType string `json:"parentObjectType"` |
56 | ParentIDField string `json:"parentIdField"` | 56 | ParentIDField string `json:"parentIdField"` |
57 | ParentFilterField string `json:"parentFilterField"` | ||
57 | } | 58 | } |
58 | 59 | ||
59 | type ListParentNode struct { | 60 | type ListParentNode struct { |
60 | ObjectType string `json:"objectType"` | 61 | ObjectType string `json:"objectType"` |
61 | LabelField string `json:"labelField"` | 62 | LabelField string `json:"labelField"` |
62 | FilterField string `json:"filterField"` | 63 | FilterField string `json:"filterField"` |
63 | } | 64 | } |
64 | 65 | ||
65 | type ListPivot struct { | 66 | type ListPivot struct { |
66 | ObjectType string `json:"objectType"` | 67 | ObjectType string `json:"objectType"` |
67 | GroupField string `json:"groupField"` | 68 | GroupField string `json:"groupField"` |
68 | DistinctField string `json:"distinctField"` | 69 | DistinctField string `json:"distinctField"` |
69 | Value string `json:"valueField"` | 70 | Value string `json:"valueField"` |
70 | } | 71 | } |
71 | 72 | ||
72 | type ListDetails struct { | 73 | type ListDetails struct { |
73 | ObjectType string `json:"objectType"` | 74 | ObjectType string `json:"objectType"` |
74 | ParentObjectType string `json:"parentObjectType"` | 75 | ParentObjectType string `json:"parentObjectType"` |
75 | ParentFilterField string `json:"parentFilterField"` | 76 | ParentFilterField string `json:"parentFilterField"` |
76 | SingleDetail bool `json:"singleDetail"` | 77 | SingleDetail bool `json:"singleDetail"` |
77 | } | 78 | } |
78 | 79 | ||
79 | type ListConfig struct { | 80 | type ListConfig struct { |
80 | ObjectType string `json:"objectType"` | 81 | ObjectType string `json:"objectType"` |
81 | Title string `json:"title"` | 82 | Title string `json:"title"` |
82 | LazyLoad bool `json:"lazyLoad"` | 83 | LazyLoad bool `json:"lazyLoad"` |
83 | InlineEdit bool `json:"inlineEdit"` | 84 | InlineEdit bool `json:"inlineEdit"` |
84 | Options ListOptions `json:"options"` | 85 | Options ListOptions `json:"options"` |
85 | Filters []ListFilter `json:"defaultFilters"` | 86 | Filters []ListFilter `json:"defaultFilters"` |
86 | Graphs []ListGraph `json:"graphs"` | 87 | Graphs []ListGraph `json:"graphs"` |
87 | Actions ListActions `json:"actions"` | 88 | Actions ListActions `json:"actions"` |
88 | Parent []ListParentNode `json:"parent"` | 89 | Parent []ListParentNode `json:"parent"` |
89 | Navigation []ListNavNode `json:"navigation"` | 90 | Navigation []ListNavNode `json:"navigation"` |
90 | Pivots []ListPivot `json:"pivots"` | 91 | Pivots []ListPivot `json:"pivots"` |
91 | Details ListDetails `json:"details"` | 92 | Details ListDetails `json:"details"` |
92 | } | 93 | } |
93 | 94 | ||
94 | // GetListConfig returns list configuration for the provided object type for the front-end application | 95 | // GetListConfig returns list configuration for the provided object type for the front-end application |
95 | // or an error if it fails. | 96 | // or an error if it fails. |
96 | func GetListConfig(db *ora.Ses, objType string) (ListConfig, error) { | 97 | func GetListConfig(db *ora.Ses, objType string) (ListConfig, error) { |
97 | resp := newDefaultList(objType) | 98 | resp := newDefaultList(objType) |
98 | var err error | 99 | var err error |
99 | 100 | ||
100 | err = setListParams(db, &resp, objType) | 101 | err = setListParams(db, &resp, objType) |
101 | resp.Navigation, err = getListNavigation(db, objType) | 102 | resp.Navigation, err = getListNavigation(db, objType) |
102 | resp.Actions, err = getListActions(db, objType) | 103 | resp.Actions, err = getListActions(db, objType) |
103 | resp.Filters, err = getListFilters(db, objType) | 104 | resp.Filters, err = getListFilters(db, objType) |
104 | resp.Options, err = getListOptions(db, objType) | 105 | resp.Options, err = getListOptions(db, objType) |
105 | resp.Parent, err = getListParent(db, objType) | 106 | resp.Parent, err = getListParent(db, objType) |
106 | resp.Graphs, err = getListGraph(db, objType) | 107 | resp.Graphs, err = getListGraph(db, objType) |
107 | resp.Pivots, err = getListPivot(db, objType) | 108 | resp.Pivots, err = getListPivot(db, objType) |
108 | resp.Details, err = getListDetails(db, objType) | 109 | resp.Details, err = getListDetails(db, objType) |
109 | 110 | ||
110 | if err != nil { | 111 | if err != nil { |
111 | return ListConfig{}, err | 112 | return ListConfig{}, err |
112 | } | 113 | } |
113 | 114 | ||
114 | return resp, nil | 115 | return resp, nil |
115 | } | 116 | } |
116 | 117 | ||
117 | // GetListConfigObjectIDField takes in database connection and an object type and it returns the | 118 | // GetListConfigObjectIDField takes in database connection and an object type and it returns the |
118 | // ID field name for the provided object type. | 119 | // ID field name for the provided object type. |
119 | func GetListConfigObjectIDField(db *ora.Ses, otype string) string { | 120 | func GetListConfigObjectIDField(db *ora.Ses, otype string) string { |
120 | var resp string | 121 | var resp string |
121 | var err error | 122 | var err error |
122 | var stmt *ora.Stmt | 123 | var stmt *ora.Stmt |
123 | 124 | ||
124 | stmt, err = db.Prep(`SELECT | 125 | stmt, err = db.Prep(`SELECT |
125 | ID_FIELD | 126 | ID_FIELD |
126 | FROM LIST_CONFIG_ID_FIELD | 127 | FROM LIST_CONFIG_ID_FIELD |
127 | WHERE OBJECT_TYPE = '` + otype + `'`, | 128 | WHERE OBJECT_TYPE = '` + otype + `'`, |
128 | ora.S) | 129 | ora.S) |
129 | 130 | ||
130 | defer stmt.Close() | 131 | defer stmt.Close() |
131 | 132 | ||
132 | if err != nil { | 133 | if err != nil { |
133 | return "" | 134 | return "" |
134 | } | 135 | } |
135 | 136 | ||
136 | rset, err := stmt.Qry() | 137 | rset, err := stmt.Qry() |
137 | if rset.Next() { | 138 | if rset.Next() { |
138 | resp = rset.Row[0].(string) | 139 | resp = rset.Row[0].(string) |
139 | } | 140 | } |
140 | 141 | ||
141 | if rset.Err != nil { | 142 | if rset.Err != nil { |
142 | return "" | 143 | return "" |
143 | } | 144 | } |
144 | 145 | ||
145 | return resp | 146 | return resp |
146 | } | 147 | } |
147 | 148 | ||
148 | // newDefaultList returns default configuration for the provided object type. | 149 | // newDefaultList returns default configuration for the provided object type. |
149 | func newDefaultList(objType string) ListConfig { | 150 | func newDefaultList(objType string) ListConfig { |
150 | list := ListConfig{ | 151 | list := ListConfig{ |
151 | ObjectType: objType, | 152 | ObjectType: objType, |
152 | Title: objType, | 153 | Title: objType, |
153 | LazyLoad: false, | 154 | LazyLoad: false, |
154 | Options: ListOptions{ | 155 | Options: ListOptions{ |
155 | GlobalFilter: true, | 156 | GlobalFilter: true, |
156 | LocalFilters: true, | 157 | LocalFilters: true, |
157 | RemoteFilters: false, | 158 | RemoteFilters: false, |
158 | Pagination: true, | 159 | Pagination: true, |
159 | PageSize: 20, | 160 | PageSize: 20, |
160 | }, | 161 | }, |
161 | Filters: nil, | 162 | Filters: nil, |
162 | Actions: ListActions{ | 163 | Actions: ListActions{ |
163 | Create: false, | 164 | Create: false, |
164 | Update: false, | 165 | Update: false, |
165 | Delete: false, | 166 | Delete: false, |
166 | Export: false, | 167 | Export: false, |
167 | Print: false, | 168 | Print: false, |
168 | Graph: false, | 169 | Graph: false, |
169 | }, | 170 | }, |
170 | Parent: nil, | 171 | Parent: nil, |
171 | Navigation: nil, | 172 | Navigation: nil, |
172 | } | 173 | } |
173 | 174 | ||
174 | return list | 175 | return list |
175 | } | 176 | } |
176 | 177 | ||
177 | // setListParams sets the default parameters of the provided configuration list for the provided object type. | 178 | // setListParams sets the default parameters of the provided configuration list for the provided object type. |
178 | func setListParams(db *ora.Ses, list *ListConfig, objType string) error { | 179 | func setListParams(db *ora.Ses, list *ListConfig, objType string) error { |
179 | var err error | 180 | var err error |
180 | var stmt *ora.Stmt | 181 | var stmt *ora.Stmt |
181 | query := `SELECT | 182 | query := `SELECT |
182 | OBJECT_TYPE, TITLE, LAZY_LOAD, INLINE_EDIT | 183 | OBJECT_TYPE, TITLE, LAZY_LOAD, INLINE_EDIT |
183 | FROM LIST_CONFIG | 184 | FROM LIST_CONFIG |
184 | WHERE OBJECT_TYPE = '` + objType + `'` | 185 | WHERE OBJECT_TYPE = '` + objType + `'` |
185 | 186 | ||
186 | stmt, err = db.Prep(query, ora.S, ora.S, ora.U32, ora.U32) | 187 | stmt, err = db.Prep(query, ora.S, ora.S, ora.U32, ora.U32) |
187 | if err != nil { | 188 | if err != nil { |
188 | return err | 189 | return err |
189 | } | 190 | } |
190 | defer stmt.Close() | 191 | defer stmt.Close() |
191 | 192 | ||
192 | rset, err := stmt.Qry() | 193 | rset, err := stmt.Qry() |
193 | if err != nil { | 194 | if err != nil { |
194 | return err | 195 | return err |
195 | } | 196 | } |
196 | if rset.Next() { | 197 | if rset.Next() { |
197 | otype := rset.Row[0].(string) | 198 | otype := rset.Row[0].(string) |
198 | if otype != "" { | 199 | if otype != "" { |
199 | list.ObjectType = otype | 200 | list.ObjectType = otype |
200 | } | 201 | } |
201 | 202 | ||
202 | title := rset.Row[1].(string) | 203 | title := rset.Row[1].(string) |
203 | if title != "" { | 204 | if title != "" { |
204 | list.Title = title | 205 | list.Title = title |
205 | } | 206 | } |
206 | list.LazyLoad = rset.Row[2].(uint32) != 0 | 207 | list.LazyLoad = rset.Row[2].(uint32) != 0 |
207 | list.InlineEdit = rset.Row[3].(uint32) != 0 | 208 | list.InlineEdit = rset.Row[3].(uint32) != 0 |
208 | } | 209 | } |
209 | if rset.Err != nil { | 210 | if rset.Err != nil { |
210 | return rset.Err | 211 | return rset.Err |
211 | } | 212 | } |
212 | return nil | 213 | return nil |
213 | } | 214 | } |
214 | 215 | ||
215 | // getListNavigation returns list navigation node slice for the provided objectType. | 216 | // getListNavigation returns list navigation node slice for the provided objectType. |
216 | func getListNavigation(db *ora.Ses, listObjType string) ([]ListNavNode, error) { | 217 | func getListNavigation(db *ora.Ses, listObjType string) ([]ListNavNode, error) { |
217 | resp := make([]ListNavNode, 0) | 218 | resp := make([]ListNavNode, 0) |
218 | var err error | 219 | var err error |
219 | var stmt *ora.Stmt | 220 | var stmt *ora.Stmt |
220 | query := `SELECT | 221 | query := `SELECT |
221 | a.OBJECT_TYPE, a.PARENT_OBJECT_TYPE, a.LABEL, a.ICON, b.PARENT_ID_FIELD, b.RB | 222 | a.OBJECT_TYPE, a.PARENT_OBJECT_TYPE, a.LABEL, a.ICON, a.PARENT_FILTER_FIELD, b.PARENT_ID_FIELD, b.RB |
222 | FROM LIST_CONFIG_NAVIGATION b | 223 | FROM LIST_CONFIG_NAVIGATION b |
223 | JOIN LIST_CONFIG_CHILD a ON b.PARENT_CHILD_ID = a.PARENT_CHILD_ID | 224 | JOIN LIST_CONFIG_CHILD a ON b.PARENT_CHILD_ID = a.PARENT_CHILD_ID |
224 | WHERE b.LIST_OBJECT_TYPE = '`+listObjType+`' | 225 | WHERE b.LIST_OBJECT_TYPE = '`+listObjType+`' |
225 | ORDER BY b.RB ASC` | 226 | ORDER BY b.RB ASC` |
226 | 227 | ||
227 | stmt, err = db.Prep(query, ora.S, ora.S, ora.S, ora.S, ora.S) | 228 | stmt, err = db.Prep(query, ora.S, ora.S, ora.S, ora.S, ora.S) |
228 | if err != nil { | 229 | if err != nil { |
229 | return resp, err | 230 | return resp, err |
230 | } | 231 | } |
231 | defer stmt.Close() | 232 | defer stmt.Close() |
232 | 233 | ||
233 | rset, err := stmt.Qry() | 234 | rset, err := stmt.Qry() |
234 | if err != nil { | 235 | if err != nil { |
235 | return resp, err | 236 | return resp, err |
236 | } | 237 | } |
237 | for rset.Next() { | 238 | for rset.Next() { |
238 | resp = append(resp, ListNavNode{ | 239 | resp = append(resp, ListNavNode{ |
239 | ObjectType: rset.Row[0].(string), | 240 | ObjectType: rset.Row[0].(string), |
240 | ParentObjectType: rset.Row[1].(string), | 241 | ParentObjectType: rset.Row[1].(string), |
241 | LabelField: rset.Row[2].(string), | 242 | LabelField: rset.Row[2].(string), |
242 | Icon: rset.Row[3].(string), | 243 | Icon: rset.Row[3].(string), |
243 | ParentIDField: rset.Row[4].(string), | 244 | ParentFilterField: rset.Row[4].(string), |
245 | ParentIDField: rset.Row[5].(string), | ||
246 | // RB is ignored | ||
244 | }) | 247 | }) |
245 | } | 248 | } |
246 | if rset.Err != nil { | 249 | if rset.Err != nil { |
247 | return nil, rset.Err | 250 | return nil, rset.Err |
248 | } | 251 | } |
249 | 252 | ||
250 | return resp, nil | 253 | return resp, nil |
251 | } | 254 | } |
252 | 255 | ||
253 | // getListActions returns list actions for the provided object type. | 256 | // getListActions returns list actions for the provided object type. |
254 | func getListActions(db *ora.Ses, objType string) (ListActions, error) { | 257 | func getListActions(db *ora.Ses, objType string) (ListActions, error) { |
255 | var resp ListActions | 258 | var resp ListActions |
256 | var err error | 259 | var err error |
257 | var stmt *ora.Stmt | 260 | var stmt *ora.Stmt |
258 | query := `SELECT | 261 | query := `SELECT |
259 | ACTION_CREATE, ACTION_UPDATE, ACTION_DELETE, ACTION_EXPORT, | 262 | ACTION_CREATE, ACTION_UPDATE, ACTION_DELETE, ACTION_EXPORT, |
260 | ACTION_PRINT, ACTION_GRAPH | 263 | ACTION_PRINT, ACTION_GRAPH |
261 | FROM LIST_CONFIG | 264 | FROM LIST_CONFIG |
262 | WHERE OBJECT_TYPE = '` + objType + `'` | 265 | WHERE OBJECT_TYPE = '` + objType + `'` |
263 | 266 | ||
264 | stmt, err = db.Prep(query, ora.U32, ora.U32, ora.U32, ora.U32, | 267 | stmt, err = db.Prep(query, ora.U32, ora.U32, ora.U32, ora.U32, |
265 | ora.U32, ora.U32) | 268 | ora.U32, ora.U32) |
266 | if err != nil { | 269 | if err != nil { |
267 | return ListActions{}, err | 270 | return ListActions{}, err |
268 | } | 271 | } |
269 | defer stmt.Close() | 272 | defer stmt.Close() |
270 | 273 | ||
271 | rset, err := stmt.Qry() | 274 | rset, err := stmt.Qry() |
272 | if err != nil { | 275 | if err != nil { |
273 | return ListActions{}, err | 276 | return ListActions{}, err |
274 | } | 277 | } |
275 | if rset.Next() { | 278 | if rset.Next() { |
276 | resp.Create = rset.Row[0].(uint32) != 0 | 279 | resp.Create = rset.Row[0].(uint32) != 0 |
277 | resp.Update = rset.Row[1].(uint32) != 0 | 280 | resp.Update = rset.Row[1].(uint32) != 0 |
278 | resp.Delete = rset.Row[2].(uint32) != 0 | 281 | resp.Delete = rset.Row[2].(uint32) != 0 |
279 | resp.Export = rset.Row[3].(uint32) != 0 | 282 | resp.Export = rset.Row[3].(uint32) != 0 |
280 | resp.Print = rset.Row[4].(uint32) != 0 | 283 | resp.Print = rset.Row[4].(uint32) != 0 |
281 | resp.Graph = rset.Row[5].(uint32) != 0 | 284 | resp.Graph = rset.Row[5].(uint32) != 0 |
282 | } | 285 | } |
283 | if rset.Err != nil { | 286 | if rset.Err != nil { |
284 | return ListActions{}, rset.Err | 287 | return ListActions{}, rset.Err |
285 | } | 288 | } |
286 | return resp, nil | 289 | return resp, nil |
287 | } | 290 | } |
288 | 291 | ||
289 | // getListFiters returns list filter slice for the provided object type. | 292 | // getListFiters returns list filter slice for the provided object type. |
290 | func getListFilters(db *ora.Ses, objType string) ([]ListFilter, error) { | 293 | func getListFilters(db *ora.Ses, objType string) ([]ListFilter, error) { |
291 | resp := make([]ListFilter, 0) | 294 | resp := make([]ListFilter, 0) |
292 | filtersFields, err := getFilterFieldsAndPosition(db, objType) | 295 | filtersFields, err := getFilterFieldsAndPosition(db, objType) |
293 | if err != nil { | 296 | if err != nil { |
294 | return nil, err | 297 | return nil, err |
295 | } | 298 | } |
296 | for field, pos := range filtersFields { | 299 | for field, pos := range filtersFields { |
297 | filters, _ := getFiltersByFilterField(db, field) | 300 | filters, _ := getFiltersByFilterField(db, field) |
298 | for _, filter := range filters { | 301 | for _, filter := range filters { |
299 | var f ListFilter | 302 | var f ListFilter |
300 | f.Position = pos | 303 | f.Position = pos |
301 | f.ObjectType = objType | 304 | f.ObjectType = objType |
302 | f.FiltersField = field | 305 | f.FiltersField = field |
303 | f.DefaultValues = filter.DefaultValues | 306 | f.DefaultValues = filter.DefaultValues |
304 | f.FiltersLabel = filter.Label | 307 | f.FiltersLabel = filter.Label |
305 | f.FiltersType = filter.Type | 308 | f.FiltersType = filter.Type |
306 | if filter.Type == "dropdown" { | 309 | if filter.Type == "dropdown" { |
307 | f.DropdownConfig, err = getFilterDropdownConfig(db, field) | 310 | f.DropdownConfig, err = getFilterDropdownConfig(db, field) |
308 | if err != nil { | 311 | if err != nil { |
309 | return nil, err | 312 | return nil, err |
310 | } | 313 | } |
311 | } | 314 | } |
312 | resp = append(resp, f) | 315 | resp = append(resp, f) |
313 | } | 316 | } |
314 | } | 317 | } |
315 | 318 | ||
316 | sortFilters(resp) | 319 | sortFilters(resp) |
317 | 320 | ||
318 | return resp, nil | 321 | return resp, nil |
319 | } | 322 | } |
320 | 323 | ||
321 | // getFilterFieldsAndPosition returns a map of filter fields and their respective position in the menu. | 324 | // getFilterFieldsAndPosition returns a map of filter fields and their respective position in the menu. |
322 | func getFilterFieldsAndPosition(db *ora.Ses, objType string) (map[string]uint32, error) { | 325 | func getFilterFieldsAndPosition(db *ora.Ses, objType string) (map[string]uint32, error) { |
323 | filtersField := make(map[string]uint32, 0) | 326 | filtersField := make(map[string]uint32, 0) |
324 | var err error | 327 | var err error |
325 | var stmt *ora.Stmt | 328 | var stmt *ora.Stmt |
326 | query := `SELECT | 329 | query := `SELECT |
327 | FILTERS_FIELD, RB | 330 | FILTERS_FIELD, RB |
328 | FROM LIST_CONFIG_FILTERS | 331 | FROM LIST_CONFIG_FILTERS |
329 | WHERE OBJECT_TYPE = '` + objType + `'` | 332 | WHERE OBJECT_TYPE = '` + objType + `'` |
330 | 333 | ||
331 | stmt, err = db.Prep(query, ora.S, ora.U32) | 334 | stmt, err = db.Prep(query, ora.S, ora.U32) |
332 | if err != nil { | 335 | if err != nil { |
333 | return nil, err | 336 | return nil, err |
334 | } | 337 | } |
335 | defer stmt.Close() | 338 | defer stmt.Close() |
336 | 339 | ||
337 | rset, err := stmt.Qry() | 340 | rset, err := stmt.Qry() |
338 | if err != nil { | 341 | if err != nil { |
339 | return nil, err | 342 | return nil, err |
340 | } | 343 | } |
341 | for rset.Next() { | 344 | for rset.Next() { |
342 | filtersField[rset.Row[0].(string)] = rset.Row[1].(uint32) | 345 | filtersField[rset.Row[0].(string)] = rset.Row[1].(uint32) |
343 | } | 346 | } |
344 | if rset.Err != nil { | 347 | if rset.Err != nil { |
345 | return nil, rset.Err | 348 | return nil, rset.Err |
346 | } | 349 | } |
347 | return filtersField, nil | 350 | return filtersField, nil |
348 | } | 351 | } |
349 | 352 | ||
350 | type _filter struct { | 353 | type _filter struct { |
351 | DefaultValues string | 354 | DefaultValues string |
352 | Label string | 355 | Label string |
353 | Type string | 356 | Type string |
354 | } | 357 | } |
355 | 358 | ||
356 | // getFiltersByFilterField returns filter slice for the provided filter field. | 359 | // getFiltersByFilterField returns filter slice for the provided filter field. |
357 | func getFiltersByFilterField(db *ora.Ses, filtersField string) ([]_filter, error) { | 360 | func getFiltersByFilterField(db *ora.Ses, filtersField string) ([]_filter, error) { |
358 | resp := make([]_filter, 0) | 361 | resp := make([]_filter, 0) |
359 | var err error | 362 | var err error |
360 | var stmt *ora.Stmt | 363 | var stmt *ora.Stmt |
361 | query := `SELECT | 364 | query := `SELECT |
362 | FILTERS_TYPE, FILTERS_LABEL, DEFAULT_VALUES | 365 | FILTERS_TYPE, FILTERS_LABEL, DEFAULT_VALUES |
363 | FROM LIST_FILTERS_FIELD | 366 | FROM LIST_FILTERS_FIELD |
364 | WHERE FILTERS_FIELD = '` + filtersField + `'` | 367 | WHERE FILTERS_FIELD = '` + filtersField + `'` |
365 | 368 | ||
366 | stmt, err = db.Prep(query, ora.S, ora.S, ora.S) | 369 | stmt, err = db.Prep(query, ora.S, ora.S, ora.S) |
367 | if err != nil { | 370 | if err != nil { |
368 | return resp, err | 371 | return resp, err |
369 | } | 372 | } |
370 | defer stmt.Close() | 373 | defer stmt.Close() |
371 | 374 | ||
372 | rset, err := stmt.Qry() | 375 | rset, err := stmt.Qry() |
373 | if err != nil { | 376 | if err != nil { |
374 | return resp, err | 377 | return resp, err |
375 | } | 378 | } |
376 | for rset.Next() { | 379 | for rset.Next() { |
377 | resp = append(resp, _filter{ | 380 | resp = append(resp, _filter{ |
378 | Type: rset.Row[0].(string), | 381 | Type: rset.Row[0].(string), |
379 | Label: rset.Row[1].(string), | 382 | Label: rset.Row[1].(string), |
380 | DefaultValues: rset.Row[2].(string), | 383 | DefaultValues: rset.Row[2].(string), |
381 | }) | 384 | }) |
382 | } | 385 | } |
383 | if rset.Err != nil { | 386 | if rset.Err != nil { |
384 | return resp, rset.Err | 387 | return resp, rset.Err |
385 | } | 388 | } |
386 | return resp, nil | 389 | return resp, nil |
387 | } | 390 | } |
388 | 391 | ||
389 | // getFilterDropdownConfig returns dropdown menu for the provided filter field. | 392 | // getFilterDropdownConfig returns dropdown menu for the provided filter field. |
390 | func getFilterDropdownConfig(db *ora.Ses, filtersField string) (Dropdown, error) { | 393 | func getFilterDropdownConfig(db *ora.Ses, filtersField string) (Dropdown, error) { |
391 | var resp Dropdown | 394 | var resp Dropdown |
392 | var err error | 395 | var err error |
393 | var stmt *ora.Stmt | 396 | var stmt *ora.Stmt |
394 | query := `SELECT | 397 | query := `SELECT |
395 | FILTERS_FIELD, OBJECT_TYPE, ID_FIELD, LABEL_FIELD | 398 | FILTERS_FIELD, OBJECT_TYPE, ID_FIELD, LABEL_FIELD |
396 | FROM LIST_DROPDOWN_FILTER | 399 | FROM LIST_DROPDOWN_FILTER |
397 | WHERE FILTERS_FIELD = '` + filtersField + `'` | 400 | WHERE FILTERS_FIELD = '` + filtersField + `'` |
398 | 401 | ||
399 | stmt, err = db.Prep(query, ora.S, ora.S, ora.S, ora.S) | 402 | stmt, err = db.Prep(query, ora.S, ora.S, ora.S, ora.S) |
400 | if err != nil { | 403 | if err != nil { |
401 | return resp, err | 404 | return resp, err |
402 | } | 405 | } |
403 | defer stmt.Close() | 406 | defer stmt.Close() |
404 | 407 | ||
405 | rset, err := stmt.Qry() | 408 | rset, err := stmt.Qry() |
406 | if err != nil { | 409 | if err != nil { |
407 | return resp, err | 410 | return resp, err |
408 | } | 411 | } |
409 | if rset.Next() { | 412 | if rset.Next() { |
410 | resp.FiltersField = rset.Row[0].(string) | 413 | resp.FiltersField = rset.Row[0].(string) |
411 | resp.ObjectType = rset.Row[1].(string) | 414 | resp.ObjectType = rset.Row[1].(string) |
412 | resp.IDField = rset.Row[2].(string) | 415 | resp.IDField = rset.Row[2].(string) |
413 | resp.LabelField = rset.Row[3].(string) | 416 | resp.LabelField = rset.Row[3].(string) |
414 | } | 417 | } |
415 | if rset.Err != nil { | 418 | if rset.Err != nil { |
416 | return resp, rset.Err | 419 | return resp, rset.Err |
417 | } | 420 | } |
418 | return resp, nil | 421 | return resp, nil |
419 | } | 422 | } |
420 | 423 | ||
421 | // sortFilters bubble sorts provided filters slice by position field. | 424 | // sortFilters bubble sorts provided filters slice by position field. |
422 | func sortFilters(filters []ListFilter) { | 425 | func sortFilters(filters []ListFilter) { |
423 | done := false | 426 | done := false |
424 | var temp ListFilter | 427 | var temp ListFilter |
425 | for !done { | 428 | for !done { |
426 | done = true | 429 | done = true |
427 | for i := 0; i < len(filters) - 1; i++ { | 430 | for i := 0; i < len(filters) - 1; i++ { |
428 | if filters[i].Position > filters[i+1].Position { | 431 | if filters[i].Position > filters[i+1].Position { |
429 | done = false | 432 | done = false |
430 | temp = filters[i] | 433 | temp = filters[i] |
431 | filters[i] = filters[i+1] | 434 | filters[i] = filters[i+1] |
432 | filters[i+1] = temp | 435 | filters[i+1] = temp |
433 | } | 436 | } |
434 | } | 437 | } |
435 | } | 438 | } |
436 | } | 439 | } |
437 | 440 | ||
438 | // getListGraph return list graph slice for the provided object type. | 441 | // getListGraph return list graph slice for the provided object type. |
439 | func getListGraph(db *ora.Ses, objType string) ([]ListGraph, error) { | 442 | func getListGraph(db *ora.Ses, objType string) ([]ListGraph, error) { |
440 | resp := make([]ListGraph, 0) | 443 | resp := make([]ListGraph, 0) |
441 | var err error | 444 | var err error |
442 | var stmt *ora.Stmt | 445 | var stmt *ora.Stmt |
443 | query := `SELECT | 446 | query := `SELECT |
444 | OBJECT_TYPE, X_FIELD, Y_FIELD, GROUP_FIELD, LABEL | 447 | OBJECT_TYPE, X_FIELD, Y_FIELD, GROUP_FIELD, LABEL |
445 | FROM LIST_GRAPHS | 448 | FROM LIST_GRAPHS |
446 | WHERE OBJECT_TYPE = '` + objType + `'` | 449 | WHERE OBJECT_TYPE = '` + objType + `'` |
447 | 450 | ||
448 | stmt, err = db.Prep(query, ora.S, ora.S, ora.S, ora.S) | 451 | stmt, err = db.Prep(query, ora.S, ora.S, ora.S, ora.S) |
449 | if err != nil { | 452 | if err != nil { |
450 | return resp, err | 453 | return resp, err |
451 | } | 454 | } |
452 | defer stmt.Close() | 455 | defer stmt.Close() |
453 | 456 | ||
454 | rset, err := stmt.Qry() | 457 | rset, err := stmt.Qry() |
455 | if err != nil { | 458 | if err != nil { |
456 | return resp, err | 459 | return resp, err |
457 | } | 460 | } |
458 | for rset.Next() { | 461 | for rset.Next() { |
459 | resp = append(resp, ListGraph{ | 462 | resp = append(resp, ListGraph{ |
460 | ObjectType: rset.Row[0].(string), | 463 | ObjectType: rset.Row[0].(string), |
461 | X: rset.Row[1].(string), | 464 | X: rset.Row[1].(string), |
462 | Y: rset.Row[2].(string), | 465 | Y: rset.Row[2].(string), |
463 | GroupField: rset.Row[3].(string), | 466 | GroupField: rset.Row[3].(string), |
464 | Label: rset.Row[4].(string), | 467 | Label: rset.Row[4].(string), |
465 | }) | 468 | }) |
466 | } | 469 | } |
467 | if rset.Err != nil { | 470 | if rset.Err != nil { |
468 | return resp, rset.Err | 471 | return resp, rset.Err |
469 | } | 472 | } |
470 | return resp, nil | 473 | return resp, nil |
471 | } | 474 | } |
472 | 475 | ||
473 | // getListOptions returns list options for the provided object type. | 476 | // getListOptions returns list options for the provided object type. |
474 | func getListOptions(db *ora.Ses, objType string) (ListOptions, error) { | 477 | func getListOptions(db *ora.Ses, objType string) (ListOptions, error) { |
475 | var resp ListOptions | 478 | var resp ListOptions |
476 | var err error | 479 | var err error |
477 | var stmt *ora.Stmt | 480 | var stmt *ora.Stmt |
478 | query := `SELECT | 481 | query := `SELECT |
479 | GLOBAL_FILTER, LOCAL_FILTER, REMOTE_FILTER, PAGINATION, | 482 | GLOBAL_FILTER, LOCAL_FILTER, REMOTE_FILTER, PAGINATION, |
480 | PAGE_SIZE, PIVOT, DETAIL, TOTAL | 483 | PAGE_SIZE, PIVOT, DETAIL, TOTAL |
481 | FROM LIST_CONFIG | 484 | FROM LIST_CONFIG |
482 | WHERE OBJECT_TYPE = '` + objType + `'` | 485 | WHERE OBJECT_TYPE = '` + objType + `'` |
483 | 486 | ||
484 | stmt, err = db.Prep(query, ora.U32, ora.U32, ora.U32, ora.U32, | 487 | stmt, err = db.Prep(query, ora.U32, ora.U32, ora.U32, ora.U32, |
485 | ora.U64, ora.U64, ora.U32, ora.U32) | 488 | ora.U64, ora.U64, ora.U32, ora.U32) |
486 | if err != nil { | 489 | if err != nil { |
487 | return ListOptions{}, err | 490 | return ListOptions{}, err |
488 | } | 491 | } |
489 | defer stmt.Close() | 492 | defer stmt.Close() |
490 | 493 | ||
491 | rset, err := stmt.Qry() | 494 | rset, err := stmt.Qry() |
492 | if err != nil { | 495 | if err != nil { |
493 | return ListOptions{}, err | 496 | return ListOptions{}, err |
494 | } | 497 | } |
495 | if rset.Next() { | 498 | if rset.Next() { |
496 | resp.GlobalFilter = rset.Row[0].(uint32) != 0 | 499 | resp.GlobalFilter = rset.Row[0].(uint32) != 0 |
497 | resp.LocalFilters = rset.Row[1].(uint32) != 0 | 500 | resp.LocalFilters = rset.Row[1].(uint32) != 0 |
498 | resp.RemoteFilters = rset.Row[2].(uint32) != 0 | 501 | resp.RemoteFilters = rset.Row[2].(uint32) != 0 |
499 | resp.Pagination = rset.Row[3].(uint32) != 0 | 502 | resp.Pagination = rset.Row[3].(uint32) != 0 |
500 | resp.PageSize = rset.Row[4].(uint64) | 503 | resp.PageSize = rset.Row[4].(uint64) |
501 | resp.Pivot = rset.Row[5].(uint64) != 0 | 504 | resp.Pivot = rset.Row[5].(uint64) != 0 |
502 | resp.Detail = rset.Row[6].(uint32) != 0 | 505 | resp.Detail = rset.Row[6].(uint32) != 0 |
503 | resp.Total = rset.Row[7].(uint32) != 0 | 506 | resp.Total = rset.Row[7].(uint32) != 0 |
504 | } | 507 | } |
505 | if rset.Err != nil { | 508 | if rset.Err != nil { |
506 | return ListOptions{}, rset.Err | 509 | return ListOptions{}, rset.Err |
507 | } | 510 | } |
508 | return resp, nil | 511 | return resp, nil |
509 | } | 512 | } |
510 | 513 | ||
511 | // getListParent returns list parent node slice for the provided object type. | 514 | // getListParent returns list parent node slice for the provided object type. |
512 | func getListParent(db *ora.Ses, objType string) ([]ListParentNode, error) { | 515 | func getListParent(db *ora.Ses, objType string) ([]ListParentNode, error) { |
513 | resp := make([]ListParentNode, 0) | 516 | resp := make([]ListParentNode, 0) |
514 | var err error | 517 | var err error |
515 | var stmt *ora.Stmt | 518 | var stmt *ora.Stmt |
516 | query := `SELECT | 519 | query := `SELECT |
517 | PARENT_OBJECT_TYPE, PARENT_LABEL_FIELD, PARENT_FILTER_FIELD | 520 | PARENT_OBJECT_TYPE, PARENT_LABEL_FIELD, PARENT_FILTER_FIELD |
518 | FROM LIST_CONFIG_CHILD | 521 | FROM LIST_CONFIG_CHILD |
519 | WHERE OBJECT_TYPE = '` + objType + `'` | 522 | WHERE OBJECT_TYPE = '` + objType + `'` |
520 | 523 | ||
521 | stmt, err = db.Prep(query, ora.S, ora.S, ora.S) | 524 | stmt, err = db.Prep(query, ora.S, ora.S, ora.S) |
522 | if err != nil { | 525 | if err != nil { |
523 | return resp, err | 526 | return resp, err |
524 | } | 527 | } |
525 | defer stmt.Close() | 528 | defer stmt.Close() |
526 | 529 | ||
527 | rset, err := stmt.Qry() | 530 | rset, err := stmt.Qry() |
528 | if err != nil { | 531 | if err != nil { |
529 | return resp, err | 532 | return resp, err |
530 | } | 533 | } |
531 | for rset.Next() { | 534 | for rset.Next() { |
532 | resp = append(resp, ListParentNode{ | 535 | resp = append(resp, ListParentNode{ |
533 | ObjectType: rset.Row[0].(string), | 536 | ObjectType: rset.Row[0].(string), |
534 | LabelField: rset.Row[1].(string), | 537 | LabelField: rset.Row[1].(string), |
535 | FilterField: rset.Row[2].(string), | 538 | FilterField: rset.Row[2].(string), |
536 | }) | 539 | }) |
537 | } | 540 | } |
538 | if rset.Err != nil { | 541 | if rset.Err != nil { |
539 | return nil, rset.Err | 542 | return nil, rset.Err |
540 | } | 543 | } |
541 | 544 | ||
542 | return resp, nil | 545 | return resp, nil |
543 | } | 546 | } |
544 | 547 | ||
545 | // getListPivot list pivot slice for the provided object type. | 548 | // getListPivot list pivot slice for the provided object type. |
546 | func getListPivot(db *ora.Ses, objType string) ([]ListPivot, error) { | 549 | func getListPivot(db *ora.Ses, objType string) ([]ListPivot, error) { |
547 | resp := make([]ListPivot, 0) | 550 | resp := make([]ListPivot, 0) |
548 | var err error | 551 | var err error |
549 | var stmt *ora.Stmt | 552 | var stmt *ora.Stmt |
550 | query := `SELECT | 553 | query := `SELECT |
551 | OBJECT_TYPE, GROUP_FIELD, DISTINCT_FIELD, VALUE_FIELD | 554 | OBJECT_TYPE, GROUP_FIELD, DISTINCT_FIELD, VALUE_FIELD |
552 | FROM LIST_PIVOTS | 555 | FROM LIST_PIVOTS |
553 | WHERE OBJECT_TYPE = '` + objType + `'` | 556 | WHERE OBJECT_TYPE = '` + objType + `'` |
554 | 557 | ||
555 | stmt, err = db.Prep(query, ora.S, ora.S, ora.S, ora.S) | 558 | stmt, err = db.Prep(query, ora.S, ora.S, ora.S, ora.S) |
556 | if err != nil { | 559 | if err != nil { |
557 | return resp, err | 560 | return resp, err |
558 | } | 561 | } |
559 | defer stmt.Close() | 562 | defer stmt.Close() |
560 | 563 | ||
561 | rset, err := stmt.Qry() | 564 | rset, err := stmt.Qry() |
562 | if err != nil { | 565 | if err != nil { |
563 | return resp, err | 566 | return resp, err |
564 | } | 567 | } |
565 | for rset.Next() { | 568 | for rset.Next() { |
566 | resp = append(resp, ListPivot{ | 569 | resp = append(resp, ListPivot{ |
567 | ObjectType: rset.Row[0].(string), | 570 | ObjectType: rset.Row[0].(string), |
568 | GroupField: rset.Row[1].(string), | 571 | GroupField: rset.Row[1].(string), |
569 | DistinctField: rset.Row[2].(string), | 572 | DistinctField: rset.Row[2].(string), |
570 | Value: rset.Row[3].(string), | 573 | Value: rset.Row[3].(string), |
571 | }) | 574 | }) |
572 | } | 575 | } |
573 | if rset.Err != nil { | 576 | if rset.Err != nil { |
574 | return nil, rset.Err | 577 | return nil, rset.Err |
575 | } | 578 | } |
576 | 579 | ||
577 | return resp, nil | 580 | return resp, nil |
578 | } | 581 | } |
579 | 582 | ||
580 | // getListDetails returns list details for the provided object type. | 583 | // getListDetails returns list details for the provided object type. |
581 | func getListDetails(db *ora.Ses, objType string) (ListDetails, error) { | 584 | func getListDetails(db *ora.Ses, objType string) (ListDetails, error) { |
582 | var resp ListDetails | 585 | var resp ListDetails |
583 | var err error | 586 | var err error |
584 | var stmt *ora.Stmt | 587 | var stmt *ora.Stmt |
585 | query := `SELECT | 588 | query := `SELECT |
586 | OBJECT_TYPE, PARENT_OBJECT_TYPE, PARENT_FILTER_FIELD, SINGLE_DETAIL | 589 | OBJECT_TYPE, PARENT_OBJECT_TYPE, PARENT_FILTER_FIELD, SINGLE_DETAIL |
587 | FROM LIST_CONFIG_DETAIL | 590 | FROM LIST_CONFIG_DETAIL |
588 | WHERE PARENT_OBJECT_TYPE = '` + objType + `'` | 591 | WHERE PARENT_OBJECT_TYPE = '` + objType + `'` |
589 | 592 | ||
590 | stmt, err = db.Prep(query, ora.S, ora.S, ora.S, ora.U32) | 593 | stmt, err = db.Prep(query, ora.S, ora.S, ora.S, ora.U32) |
591 | if err != nil { | 594 | if err != nil { |
592 | return resp, err | 595 | return resp, err |
593 | } | 596 | } |
594 | defer stmt.Close() | 597 | defer stmt.Close() |
595 | 598 | ||
596 | rset, err := stmt.Qry() | 599 | rset, err := stmt.Qry() |
597 | if err != nil { | 600 | if err != nil { |
598 | return resp, err | 601 | return resp, err |
599 | } | 602 | } |
600 | if rset.Next() { | 603 | if rset.Next() { |
601 | resp.ObjectType = rset.Row[0].(string) | 604 | resp.ObjectType = rset.Row[0].(string) |
602 | resp.ParentObjectType = rset.Row[1].(string) | 605 | resp.ParentObjectType = rset.Row[1].(string) |
603 | resp.ParentFilterField = rset.Row[2].(string) | 606 | resp.ParentFilterField = rset.Row[2].(string) |
604 | resp.SingleDetail = rset.Row[3].(uint32) != 0 | 607 | resp.SingleDetail = rset.Row[3].(uint32) != 0 |
605 | } | 608 | } |
606 | if rset.Err != nil { | 609 | if rset.Err != nil { |
607 | return resp, rset.Err | 610 | return resp, rset.Err |
608 | } | 611 | } |
609 | 612 | ||
610 | return resp, nil | 613 | return resp, nil |
611 | } | 614 | } |
612 | 615 |