Blame view

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