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