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