Commit a392b07b622910712a627ee15bb17218d8058c0c

Authored by Marko Tikvić
1 parent 7d3deb50df
Exists in master and in 1 other branch v2

navigation

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