-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
info.go
984 lines (812 loc) · 22.7 KB
/
info.go
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
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
package types
import (
"encoding/json"
"fmt"
"github.com/GoAdminGroup/go-admin/context"
"github.com/GoAdminGroup/go-admin/modules/db"
"github.com/GoAdminGroup/go-admin/modules/utils"
"github.com/GoAdminGroup/go-admin/template/types/form"
"github.com/GoAdminGroup/go-admin/template/types/table"
"html"
"html/template"
"strconv"
"strings"
)
// FieldModel is the single query result.
type FieldModel struct {
// The primaryKey of the table.
ID string
// The value of the single query result.
Value string
// The current row data.
Row map[string]interface{}
}
// PostFieldModel contains ID and value of the single query result and the current row data.
type PostFieldModel struct {
ID string
Value FieldModelValue
Row map[string]interface{}
}
type Callbacks []context.Node
func (c Callbacks) AddCallback(node context.Node) Callbacks {
if node.Path != "" && node.Method != "" && len(node.Handlers) > 0 {
return append(c, node)
}
return c
}
type FieldModelValue []string
func (r FieldModelValue) Value() string {
return r.First()
}
func (r FieldModelValue) First() string {
return r[0]
}
// FieldDisplay is filter function of data.
type FieldFilterFn func(value FieldModel) interface{}
// PostFieldFilterFn is filter function of data.
type PostFieldFilterFn func(value PostFieldModel) string
type DisplayProcessFn func(string) string
type DisplayProcessFnChains []DisplayProcessFn
func (d DisplayProcessFnChains) Valid() bool {
return len(d) > 0
}
func (d DisplayProcessFnChains) Add(f DisplayProcessFn) DisplayProcessFnChains {
return append(d, f)
}
func (d DisplayProcessFnChains) Append(f DisplayProcessFnChains) DisplayProcessFnChains {
return append(d, f...)
}
func (d DisplayProcessFnChains) Copy() DisplayProcessFnChains {
if len(d) == 0 {
return make(DisplayProcessFnChains, 0)
} else {
var newDisplayProcessFnChains = make(DisplayProcessFnChains, len(d))
copy(newDisplayProcessFnChains, d)
return newDisplayProcessFnChains
}
}
func chooseDisplayProcessChains(internal DisplayProcessFnChains) DisplayProcessFnChains {
if len(internal) > 0 {
return internal
}
return globalDisplayProcessChains.Copy()
}
var globalDisplayProcessChains = make(DisplayProcessFnChains, 0)
func AddGlobalDisplayProcessFn(f DisplayProcessFn) {
globalDisplayProcessChains = globalDisplayProcessChains.Add(f)
}
func AddLimit(limit int) DisplayProcessFnChains {
return addLimit(limit, globalDisplayProcessChains)
}
func AddTrimSpace() DisplayProcessFnChains {
return addTrimSpace(globalDisplayProcessChains)
}
func AddSubstr(start int, end int) DisplayProcessFnChains {
return addSubstr(start, end, globalDisplayProcessChains)
}
func AddToTitle() DisplayProcessFnChains {
return addToTitle(globalDisplayProcessChains)
}
func AddToUpper() DisplayProcessFnChains {
return addToUpper(globalDisplayProcessChains)
}
func AddToLower() DisplayProcessFnChains {
return addToLower(globalDisplayProcessChains)
}
func AddXssFilter() DisplayProcessFnChains {
return addXssFilter(globalDisplayProcessChains)
}
func AddXssJsFilter() DisplayProcessFnChains {
return addXssJsFilter(globalDisplayProcessChains)
}
func addLimit(limit int, chains DisplayProcessFnChains) DisplayProcessFnChains {
chains = chains.Add(func(value string) string {
if limit > len(value) {
return value
} else if limit < 0 {
return ""
} else {
return value[:limit]
}
})
return chains
}
func addTrimSpace(chains DisplayProcessFnChains) DisplayProcessFnChains {
chains = chains.Add(func(value string) string {
return strings.TrimSpace(value)
})
return chains
}
func addSubstr(start int, end int, chains DisplayProcessFnChains) DisplayProcessFnChains {
chains = chains.Add(func(value string) string {
if start > end || start > len(value) || end < 0 {
return ""
}
if start < 0 {
start = 0
}
if end > len(value) {
end = len(value)
}
return value[start:end]
})
return chains
}
func addToTitle(chains DisplayProcessFnChains) DisplayProcessFnChains {
chains = chains.Add(func(value string) string {
return strings.Title(value)
})
return chains
}
func addToUpper(chains DisplayProcessFnChains) DisplayProcessFnChains {
chains = chains.Add(func(value string) string {
return strings.ToUpper(value)
})
return chains
}
func addToLower(chains DisplayProcessFnChains) DisplayProcessFnChains {
chains = chains.Add(func(value string) string {
return strings.ToLower(value)
})
return chains
}
func addXssFilter(chains DisplayProcessFnChains) DisplayProcessFnChains {
chains = chains.Add(func(value string) string {
return html.EscapeString(value)
})
return chains
}
func addXssJsFilter(chains DisplayProcessFnChains) DisplayProcessFnChains {
chains = chains.Add(func(value string) string {
s := strings.Replace(value, "<script>", "<script>", -1)
return strings.Replace(s, "</script>", "</script>", -1)
})
return chains
}
type FieldDisplay struct {
Display FieldFilterFn
DisplayProcessChains DisplayProcessFnChains
}
func (f FieldDisplay) ToDisplay(value FieldModel) interface{} {
val := f.Display(value)
if _, ok := val.(template.HTML); !ok {
if _, ok2 := val.([]string); !ok2 {
valStr := fmt.Sprintf("%v", val)
for _, process := range f.DisplayProcessChains {
valStr = process(valStr)
}
return valStr
}
}
return val
}
func (f FieldDisplay) AddLimit(limit int) DisplayProcessFnChains {
return f.DisplayProcessChains.Add(func(value string) string {
if limit > len(value) {
return value
} else if limit < 0 {
return ""
} else {
return value[:limit]
}
})
}
func (f FieldDisplay) AddTrimSpace() DisplayProcessFnChains {
return f.DisplayProcessChains.Add(func(value string) string {
return strings.TrimSpace(value)
})
}
func (f FieldDisplay) AddSubstr(start int, end int) DisplayProcessFnChains {
return f.DisplayProcessChains.Add(func(value string) string {
if start > end || start > len(value) || end < 0 {
return ""
}
if start < 0 {
start = 0
}
if end > len(value) {
end = len(value)
}
return value[start:end]
})
}
func (f FieldDisplay) AddToTitle() DisplayProcessFnChains {
return f.DisplayProcessChains.Add(func(value string) string {
return strings.Title(value)
})
}
func (f FieldDisplay) AddToUpper() DisplayProcessFnChains {
return f.DisplayProcessChains.Add(func(value string) string {
return strings.ToUpper(value)
})
}
func (f FieldDisplay) AddToLower() DisplayProcessFnChains {
return f.DisplayProcessChains.Add(func(value string) string {
return strings.ToLower(value)
})
}
// Field is the table field.
type Field struct {
Head string
Field string
TypeName db.DatabaseType
Join Join
Width int
Sortable bool
EditAble bool
Fixed bool
Filterable bool
Hide bool
EditType table.Type
EditOptions []map[string]string
FilterType form.Type
FilterOptions FieldOptions
FilterOperator FilterOperator
FilterOptionExt template.JS
FilterHead string
FilterHelpMsg template.HTML
FieldDisplay
}
func (f Field) GetEditOptions() string {
if len(f.EditOptions) == 0 {
return ""
}
eo, err := json.Marshal(f.EditOptions)
if err != nil {
return ""
}
return string(eo)
}
func (f Field) Exist() bool {
return f.Field != ""
}
type FieldList []Field
func (f FieldList) GetFieldByFieldName(name string) Field {
for _, field := range f {
if field.Field == name {
return field
}
}
return Field{}
}
type Join struct {
Table string
Field string
JoinField string
}
func (j Join) Valid() bool {
return j.Table != "" && j.Field != "" && j.JoinField != ""
}
var JoinFieldValueDelimiter = utils.Uuid(8)
type TabGroups [][]string
func (t TabGroups) Valid() bool {
return len(t) > 0
}
func NewTabGroups(items ...string) TabGroups {
var t = make(TabGroups, 0)
return append(t, items)
}
func (t TabGroups) AddGroup(items ...string) TabGroups {
return append(t, items)
}
type TabHeaders []string
func (t TabHeaders) Add(header string) TabHeaders {
return append(t, header)
}
type DeleteFn func(ids []string) error
type Sort uint8
const (
SortDesc Sort = iota
SortAsc
)
// InfoPanel
type InfoPanel struct {
FieldList FieldList
curFieldListIndex int
Table string
Title string
Description string
// Warn: may be deprecated future.
TabGroups TabGroups
TabHeaders TabHeaders
Sort Sort
PageSizeList []int
DefaultPageSize int
IsHideNewButton bool
IsHideExportButton bool
IsHideEditButton bool
IsHideDeleteButton bool
IsHideDetailButton bool
IsHideFilterButton bool
IsHideRowSelector bool
IsHidePagination bool
IsHideFilterArea bool
FilterFormLayout form.Layout
Wheres []Where
Callbacks Callbacks
Buttons Buttons
DeleteHook DeleteFn
PreDeleteFn DeleteFn
DeleteFn DeleteFn
processChains DisplayProcessFnChains
ActionButtons Buttons
Action template.HTML
HeaderHtml template.HTML
FooterHtml template.HTML
}
type Where struct {
Field string
Operator string
Arg interface{}
}
type Action interface {
Js() template.JS
BtnAttribute() template.HTML
ExtContent() template.HTML
SetBtnId(btnId string)
GetCallbacks() context.Node
}
type DefaultAction struct {
Attr template.HTML
JS template.JS
Ext template.HTML
}
func NewDefaultAction(attr, ext template.HTML, js template.JS) *DefaultAction {
return &DefaultAction{Attr: attr, Ext: ext, JS: js}
}
func (def *DefaultAction) SetBtnId(btnId string) {}
func (def *DefaultAction) Js() template.JS { return def.JS }
func (def *DefaultAction) BtnAttribute() template.HTML { return def.Attr }
func (def *DefaultAction) ExtContent() template.HTML { return def.Ext }
func (def *DefaultAction) GetCallbacks() context.Node { return context.Node{} }
type Button interface {
Content() (template.HTML, template.JS)
}
type DefaultButton struct {
Id string
Title template.HTML
Color template.HTML
TextColor template.HTML
Action Action
Icon string
}
func (b DefaultButton) Content() (template.HTML, template.JS) {
color := template.HTML("")
if b.Color != template.HTML("") {
color = template.HTML(`background-color:`) + b.Color + template.HTML(`;`)
}
textColor := template.HTML("")
if b.TextColor != template.HTML("") {
textColor = template.HTML(`color:`) + b.TextColor + template.HTML(`;`)
}
style := template.HTML("")
addColor := color + textColor
if addColor != template.HTML("") {
style = template.HTML(`style="`) + addColor + template.HTML(`"`)
}
h := `<div class="btn-group pull-right" style="margin-right: 10px">
<a id="` + template.HTML(b.Id) + `" ` + style + `class="btn btn-sm btn-default" ` + b.Action.BtnAttribute() + `>
<i class="fa ` + template.HTML(b.Icon) + `"></i> ` + b.Title + `
</a>
</div>` + b.Action.ExtContent()
return h, b.Action.Js()
}
type ActionButton struct {
Id string
Title template.HTML
Action Action
}
func (b ActionButton) Content() (template.HTML, template.JS) {
h := template.HTML(`<li><a class="`+template.HTML(b.Id)+`" `+b.Action.BtnAttribute()+`>`+b.Title+`</a></li>`) + b.Action.ExtContent()
return h, b.Action.Js()
}
type Buttons []Button
func (b Buttons) Content() (template.HTML, template.JS) {
h := template.HTML("")
j := template.JS("")
for _, btn := range b {
hh, jj := btn.Content()
h += hh
j += jj
}
return h, j
}
var DefaultPageSizeList = []int{10, 20, 30, 50, 100}
const DefaultPageSize = 10
func NewInfoPanel() *InfoPanel {
return &InfoPanel{
curFieldListIndex: -1,
PageSizeList: DefaultPageSizeList,
DefaultPageSize: DefaultPageSize,
processChains: make(DisplayProcessFnChains, 0),
Buttons: make(Buttons, 0),
Callbacks: make(Callbacks, 0),
Wheres: make([]Where, 0),
}
}
func (i *InfoPanel) Where(field string, operator string, arg interface{}) *InfoPanel {
i.Wheres = append(i.Wheres, Where{Field: field, Operator: operator, Arg: arg})
return i
}
func (i *InfoPanel) AddButton(title template.HTML, icon string, action Action, color ...template.HTML) *InfoPanel {
id := "info-btn-" + utils.Uuid(10)
action.SetBtnId(id)
if len(color) == 0 {
i.Buttons = append(i.Buttons, DefaultButton{Title: title, Id: id, Action: action, Icon: icon})
}
if len(color) == 1 {
i.Buttons = append(i.Buttons, DefaultButton{Title: title, Color: color[0], Id: id, Action: action, Icon: icon})
}
if len(color) >= 2 {
i.Buttons = append(i.Buttons, DefaultButton{Title: title, Color: color[0], TextColor: color[1], Id: id, Action: action, Icon: icon})
}
i.Callbacks = i.Callbacks.AddCallback(action.GetCallbacks())
return i
}
func (i *InfoPanel) AddActionButton(title template.HTML, action Action, ids ...string) *InfoPanel {
id := ""
if len(ids) > 0 {
id = ids[0]
} else {
id = "action-info-btn-" + utils.Uuid(10)
}
action.SetBtnId(id)
i.ActionButtons = append(i.ActionButtons, ActionButton{Title: title, Id: id, Action: action})
i.Callbacks = i.Callbacks.AddCallback(action.GetCallbacks())
return i
}
func (i *InfoPanel) AddActionButtonFront(title template.HTML, action Action, ids ...string) *InfoPanel {
id := ""
if len(ids) > 0 {
id = ids[0]
} else {
id = "action-info-btn-" + utils.Uuid(10)
}
action.SetBtnId(id)
i.ActionButtons = append([]Button{ActionButton{Title: title, Id: id, Action: action}}, i.ActionButtons...)
i.Callbacks = i.Callbacks.AddCallback(action.GetCallbacks())
return i
}
func (i *InfoPanel) AddLimitFilter(limit int) *InfoPanel {
i.processChains = addLimit(limit, i.processChains)
return i
}
func (i *InfoPanel) AddTrimSpaceFilter() *InfoPanel {
i.processChains = addTrimSpace(i.processChains)
return i
}
func (i *InfoPanel) AddSubstrFilter(start int, end int) *InfoPanel {
i.processChains = addSubstr(start, end, i.processChains)
return i
}
func (i *InfoPanel) AddToTitleFilter() *InfoPanel {
i.processChains = addToTitle(i.processChains)
return i
}
func (i *InfoPanel) AddToUpperFilter() *InfoPanel {
i.processChains = addToUpper(i.processChains)
return i
}
func (i *InfoPanel) AddToLowerFilter() *InfoPanel {
i.processChains = addToLower(i.processChains)
return i
}
func (i *InfoPanel) AddXssFilter() *InfoPanel {
i.processChains = addXssFilter(i.processChains)
return i
}
func (i *InfoPanel) AddXssJsFilter() *InfoPanel {
i.processChains = addXssJsFilter(i.processChains)
return i
}
func (i *InfoPanel) SetDeleteHook(fn DeleteFn) *InfoPanel {
i.DeleteHook = fn
return i
}
func (i *InfoPanel) SetPreDeleteFn(fn DeleteFn) *InfoPanel {
i.PreDeleteFn = fn
return i
}
func (i *InfoPanel) SetDeleteFn(fn DeleteFn) *InfoPanel {
i.DeleteFn = fn
return i
}
func (i *InfoPanel) AddField(head, field string, typeName db.DatabaseType) *InfoPanel {
i.FieldList = append(i.FieldList, Field{
Head: head,
Field: field,
TypeName: typeName,
Sortable: false,
EditAble: false,
EditType: table.Text,
FieldDisplay: FieldDisplay{
Display: func(value FieldModel) interface{} {
return value.Value
},
DisplayProcessChains: chooseDisplayProcessChains(i.processChains),
},
})
i.curFieldListIndex++
return i
}
// Field attribute setting functions
// ====================================================
func (i *InfoPanel) FieldDisplay(filter FieldFilterFn) *InfoPanel {
i.FieldList[i.curFieldListIndex].Display = filter
return i
}
func (i *InfoPanel) FieldWidth(width int) *InfoPanel {
i.FieldList[i.curFieldListIndex].Width = width
return i
}
func (i *InfoPanel) FieldSortable() *InfoPanel {
i.FieldList[i.curFieldListIndex].Sortable = true
return i
}
func (i *InfoPanel) FieldEditOptions(options []map[string]string) *InfoPanel {
i.FieldList[i.curFieldListIndex].EditOptions = options
return i
}
func (i *InfoPanel) FieldEditAble(editType ...table.Type) *InfoPanel {
i.FieldList[i.curFieldListIndex].EditAble = true
if len(editType) > 0 {
i.FieldList[i.curFieldListIndex].EditType = editType[0]
}
return i
}
func (i *InfoPanel) FieldFixed() *InfoPanel {
i.FieldList[i.curFieldListIndex].Fixed = true
return i
}
type FilterType struct {
FormType form.Type
Operator FilterOperator
Head string
HelpMsg template.HTML
}
type FilterOperator string
const (
FilterOperatorLike FilterOperator = "like"
FilterOperatorGreater FilterOperator = ">"
FilterOperatorGreaterOrEqual FilterOperator = ">="
FilterOperatorEqual FilterOperator = "="
FilterOperatorNotEqual FilterOperator = "!="
FilterOperatorLess FilterOperator = "<"
FilterOperatorLessOrEqual FilterOperator = "<="
FilterOperatorFree FilterOperator = "free"
)
func GetOperatorFromValue(value string) FilterOperator {
switch value {
case "like":
return FilterOperatorLike
case "gr":
return FilterOperatorGreater
case "gq":
return FilterOperatorGreaterOrEqual
case "eq":
return FilterOperatorEqual
case "ne":
return FilterOperatorNotEqual
case "le":
return FilterOperatorLess
case "lq":
return FilterOperatorLessOrEqual
case "free":
return FilterOperatorFree
default:
return FilterOperatorEqual
}
}
func (o FilterOperator) Value() string {
switch o {
case FilterOperatorLike:
return "like"
case FilterOperatorGreater:
return "gr"
case FilterOperatorGreaterOrEqual:
return "gq"
case FilterOperatorEqual:
return "eq"
case FilterOperatorNotEqual:
return "ne"
case FilterOperatorLess:
return "le"
case FilterOperatorLessOrEqual:
return "lq"
case FilterOperatorFree:
return "free"
default:
return "eq"
}
}
func (o FilterOperator) String() string {
return string(o)
}
func (o FilterOperator) Label() template.HTML {
if o == FilterOperatorLike {
return ""
}
return template.HTML(o)
}
func (o FilterOperator) AddOrNot() bool {
return string(o) != "" && o != FilterOperatorFree
}
func (o FilterOperator) Valid() bool {
switch o {
case FilterOperatorLike, FilterOperatorGreater, FilterOperatorGreaterOrEqual,
FilterOperatorLess, FilterOperatorLessOrEqual, FilterOperatorFree:
return true
default:
return false
}
}
func (i *InfoPanel) FieldFilterable(filterType ...FilterType) *InfoPanel {
i.FieldList[i.curFieldListIndex].Filterable = true
if len(filterType) > 0 {
i.FieldList[i.curFieldListIndex].FilterOperator = filterType[0].Operator
if uint8(filterType[0].FormType) == 0 {
i.FieldList[i.curFieldListIndex].FilterType = form.Text
} else {
i.FieldList[i.curFieldListIndex].FilterType = filterType[0].FormType
}
i.FieldList[i.curFieldListIndex].FilterHead = filterType[0].Head
i.FieldList[i.curFieldListIndex].FilterHelpMsg = filterType[0].HelpMsg
} else {
i.FieldList[i.curFieldListIndex].FilterType = form.Text
}
return i
}
func (i *InfoPanel) FieldFilterOptions(options []map[string]string) *InfoPanel {
i.FieldList[i.curFieldListIndex].FilterOptions = options
i.FieldList[i.curFieldListIndex].FilterOptionExt = `{"allowClear": "true"}`
return i
}
func (i *InfoPanel) FieldFilterOptionExt(m map[string]interface{}) *InfoPanel {
s, _ := json.Marshal(m)
i.FieldList[i.curFieldListIndex].FilterOptionExt = template.JS(s)
return i
}
func (i *InfoPanel) FieldHide() *InfoPanel {
i.FieldList[i.curFieldListIndex].Hide = true
return i
}
func (i *InfoPanel) FieldJoin(join Join) *InfoPanel {
i.FieldList[i.curFieldListIndex].Join = join
return i
}
func (i *InfoPanel) FieldLimit(limit int) *InfoPanel {
i.FieldList[i.curFieldListIndex].DisplayProcessChains = i.FieldList[i.curFieldListIndex].AddLimit(limit)
return i
}
func (i *InfoPanel) FieldTrimSpace() *InfoPanel {
i.FieldList[i.curFieldListIndex].DisplayProcessChains = i.FieldList[i.curFieldListIndex].AddTrimSpace()
return i
}
func (i *InfoPanel) FieldSubstr(start int, end int) *InfoPanel {
i.FieldList[i.curFieldListIndex].DisplayProcessChains = i.FieldList[i.curFieldListIndex].AddSubstr(start, end)
return i
}
func (i *InfoPanel) FieldToTitle() *InfoPanel {
i.FieldList[i.curFieldListIndex].DisplayProcessChains = i.FieldList[i.curFieldListIndex].AddToTitle()
return i
}
func (i *InfoPanel) FieldToUpper() *InfoPanel {
i.FieldList[i.curFieldListIndex].DisplayProcessChains = i.FieldList[i.curFieldListIndex].AddToUpper()
return i
}
func (i *InfoPanel) FieldToLower() *InfoPanel {
i.FieldList[i.curFieldListIndex].DisplayProcessChains = i.FieldList[i.curFieldListIndex].AddToLower()
return i
}
func (i *InfoPanel) FieldXssFilter() *InfoPanel {
i.FieldList[i.curFieldListIndex].DisplayProcessChains = i.FieldList[i.curFieldListIndex].DisplayProcessChains.
Add(func(s string) string {
return html.EscapeString(s)
})
return i
}
// InfoPanel attribute setting functions
// ====================================================
func (i *InfoPanel) SetTable(table string) *InfoPanel {
i.Table = table
return i
}
func (i *InfoPanel) SetPageSizeList(pageSizeList []int) *InfoPanel {
i.PageSizeList = pageSizeList
return i
}
func (i *InfoPanel) SetDefaultPageSize(defaultPageSize int) *InfoPanel {
i.DefaultPageSize = defaultPageSize
return i
}
func (i *InfoPanel) GetPageSizeList() []string {
var pageSizeList = make([]string, len(i.PageSizeList))
for j := 0; j < len(i.PageSizeList); j++ {
pageSizeList[j] = strconv.Itoa(i.PageSizeList[j])
}
return pageSizeList
}
func (i *InfoPanel) GetSort() string {
switch i.Sort {
case SortAsc:
return "asc"
default:
return "desc"
}
}
func (i *InfoPanel) SetTitle(title string) *InfoPanel {
i.Title = title
return i
}
func (i *InfoPanel) SetTabGroups(groups TabGroups) *InfoPanel {
i.TabGroups = groups
return i
}
func (i *InfoPanel) SetTabHeaders(headers ...string) *InfoPanel {
i.TabHeaders = headers
return i
}
func (i *InfoPanel) SetDescription(desc string) *InfoPanel {
i.Description = desc
return i
}
func (i *InfoPanel) SetFilterFormLayout(layout form.Layout) *InfoPanel {
i.FilterFormLayout = layout
return i
}
func (i *InfoPanel) SetSortAsc() *InfoPanel {
i.Sort = SortAsc
return i
}
func (i *InfoPanel) SetSortDesc() *InfoPanel {
i.Sort = SortDesc
return i
}
func (i *InfoPanel) SetAction(action template.HTML) *InfoPanel {
i.Action = action
return i
}
func (i *InfoPanel) SetHeaderHtml(header template.HTML) *InfoPanel {
i.HeaderHtml = header
return i
}
func (i *InfoPanel) SetFooterHtml(footer template.HTML) *InfoPanel {
i.FooterHtml = footer
return i
}
func (i *InfoPanel) HideNewButton() *InfoPanel {
i.IsHideNewButton = true
return i
}
func (i *InfoPanel) HideExportButton() *InfoPanel {
i.IsHideExportButton = true
return i
}
func (i *InfoPanel) HideFilterButton() *InfoPanel {
i.IsHideFilterButton = true
return i
}
func (i *InfoPanel) HideRowSelector() *InfoPanel {
i.IsHideRowSelector = true
return i
}
func (i *InfoPanel) HidePagination() *InfoPanel {
i.IsHidePagination = true
return i
}
func (i *InfoPanel) HideFilterArea() *InfoPanel {
i.IsHideFilterArea = true
return i
}
func (i *InfoPanel) HideEditButton() *InfoPanel {
i.IsHideEditButton = true
return i
}
func (i *InfoPanel) HideDeleteButton() *InfoPanel {
i.IsHideDeleteButton = true
return i
}
func (i *InfoPanel) HideDetailButton() *InfoPanel {
i.IsHideDetailButton = true
return i
}