Skip to content

Commit f4568ae

Browse files
author
cg33
committed
fix form type add custom && add editable table field options attribute
1 parent 55b4e84 commit f4568ae

File tree

6 files changed

+76
-5
lines changed

6 files changed

+76
-5
lines changed

examples/datamodel/content.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func GetContent() (types.Panel, error) {
2626
SetText("CPU TRAFFIC").
2727
SetColor("#3583af").
2828
SetNumber("100").
29-
SetIcon(`<svg t="1568904058859" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2216" width="48" height="48"><path d="M864 64l-704 0C142.336 64 128 78.336 128 96l0 832C128 945.664 142.336 960 160 960l704 0c17.664 0 32-14.336 32-32l0-832C896 78.336 881.664 64 864 64zM832 896 192 896 192 128l640 0L832 896z" fill="#e6e6e6" p-id="2217"></path><path d="M353.92 320c17.6 0 32-14.336 32-32S371.584 256 353.92 256L353.28 256C335.616 256 321.6 270.336 321.6 288S336.256 320 353.92 320z" fill="#e6e6e6" p-id="2218"></path><path d="M353.92 512c17.6 0 32-14.336 32-32S371.584 448 353.92 448L353.28 448C335.616 448 321.6 462.336 321.6 480S336.256 512 353.92 512z" fill="#e6e6e6" p-id="2219"></path><path d="M353.92 704c17.6 0 32-14.336 32-32S371.584 640 353.92 640L353.28 640c-17.6 0-31.616 14.336-31.616 32S336.256 704 353.92 704z" fill="#e6e6e6" p-id="2220"></path><path d="M480 320l192 0C689.664 320 704 305.664 704 288S689.664 256 672 256l-192 0C462.336 256 448 270.336 448 288S462.336 320 480 320z" fill="#e6e6e6" p-id="2221"></path><path d="M480 512l192 0C689.664 512 704 497.664 704 480S689.664 448 672 448l-192 0C462.336 448 448 462.336 448 480S462.336 512 480 512z" fill="#e6e6e6" p-id="2222"></path><path d="M480 704l192 0c17.664 0 32-14.336 32-32S689.664 640 672 640l-192 0C462.336 640 448 654.336 448 672S462.336 704 480 704z" fill="#e6e6e6" p-id="2223"></path></svg>`).
29+
SetIcon("fa-tint").
3030
GetContent()
3131

3232
infobox2 := infobox.New().

examples/datamodel/user.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/GoAdminGroup/go-admin/template"
99
"github.com/GoAdminGroup/go-admin/template/types"
1010
"github.com/GoAdminGroup/go-admin/template/types/form"
11+
table2 "github.com/GoAdminGroup/go-admin/template/types/table"
1112
)
1213

1314
func GetUserTable() (userTable table.Table) {
@@ -44,8 +45,8 @@ func GetUserTable() (userTable table.Table) {
4445
SetSrc(`//quick.go-admin.cn/demo/assets/dist/img/gopher_avatar.png`).
4546
SetHeight("120").SetWidth("120").GetContent()
4647
})
47-
info.AddField("createdAt", "created_at", db.Timestamp)
48-
info.AddField("updatedAt", "updated_at", db.Timestamp)
48+
info.AddField("createdAt", "created_at", db.Timestamp).FieldEditAble(table2.Datetime)
49+
info.AddField("updatedAt", "updated_at", db.Timestamp).FieldEditAble(table2.Datetime)
4950

5051
info.SetTable("users").SetTitle("Users").SetDescription("Users")
5152

plugins/admin/modules/table/table.go

+2
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,7 @@ func (tb DefaultTable) GetDataFromDatabase(path string, params parameter.Paramet
343343
"field": headField,
344344
"hide": hide,
345345
"editable": editable,
346+
"edittype": tb.info.FieldList[i].EditType.String(),
346347
"width": strconv.Itoa(tb.info.FieldList[i].Width),
347348
})
348349
}
@@ -515,6 +516,7 @@ func (tb DefaultTable) GetDataFromDatabaseWithIds(path string, params parameter.
515516
"field": headField,
516517
"hide": hide,
517518
"editable": editable,
519+
"edittype": tb.info.FieldList[i].EditType.String(),
518520
"width": strconv.Itoa(tb.info.FieldList[i].Width),
519521
})
520522
}

template/types/form/form.go

+3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const (
2525
Currency
2626
Number
2727
TextArea
28+
Custom
2829
)
2930

3031
func (t Type) String() string {
@@ -65,6 +66,8 @@ func (t Type) String() string {
6566
return "number"
6667
case TextArea:
6768
return "textarea"
69+
case Custom:
70+
return "custom"
6871
default:
6972
panic("wrong form type")
7073
}

template/types/table/table.go

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package table
2+
3+
type Type uint8
4+
5+
const (
6+
Text Type = iota
7+
Textarea
8+
Select
9+
Date
10+
Datetime
11+
Dateui
12+
Combodate
13+
Html5types
14+
Checklist
15+
Wysihtml5
16+
Typeahead
17+
Typeaheadjs
18+
Select2
19+
)
20+
21+
func (t Type) String() string {
22+
switch t {
23+
case Text:
24+
return "text"
25+
case Select:
26+
return "select"
27+
case Textarea:
28+
return "textarea"
29+
case Date:
30+
return "date"
31+
case Datetime:
32+
return "datetime"
33+
case Dateui:
34+
return "dateui"
35+
case Combodate:
36+
return "combodate"
37+
case Html5types:
38+
return "html5types"
39+
case Checklist:
40+
return "checklist"
41+
case Wysihtml5:
42+
return "wysihtml5"
43+
case Typeahead:
44+
return "typeahead"
45+
case Typeaheadjs:
46+
return "typeaheadjs"
47+
case Select2:
48+
return "select2"
49+
default:
50+
panic("wrong form type")
51+
}
52+
}

template/types/types.go

+15-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/GoAdminGroup/go-admin/plugins/admin/modules"
1414
form2 "github.com/GoAdminGroup/go-admin/plugins/admin/modules/form"
1515
"github.com/GoAdminGroup/go-admin/template/types/form"
16+
"github.com/GoAdminGroup/go-admin/template/types/table"
1617
"html"
1718
"html/template"
1819
"strconv"
@@ -325,6 +326,9 @@ type Field struct {
325326
Filterable bool
326327
Hide bool
327328

329+
EditType table.Type
330+
EditOptions []map[string]string
331+
328332
FieldDisplay
329333
}
330334

@@ -409,6 +413,7 @@ func (i *InfoPanel) AddField(head, field string, typeName db.DatabaseType) *Info
409413
TypeName: typeName,
410414
Sortable: false,
411415
EditAble: false,
416+
EditType: table.Text,
412417
FieldDisplay: FieldDisplay{
413418
Display: func(value FieldModel) interface{} {
414419
return value.Value
@@ -438,8 +443,16 @@ func (i *InfoPanel) FieldSortable() *InfoPanel {
438443
return i
439444
}
440445

441-
func (i *InfoPanel) FieldEditAble() *InfoPanel {
446+
func (i *InfoPanel) FieldEditOptions(options []map[string]string) *InfoPanel {
447+
i.FieldList[i.curFieldListIndex].EditOptions = options
448+
return i
449+
}
450+
451+
func (i *InfoPanel) FieldEditAble(editType ...table.Type) *InfoPanel {
442452
i.FieldList[i.curFieldListIndex].EditAble = true
453+
if len(editType) > 0 {
454+
i.FieldList[i.curFieldListIndex].EditType = editType[0]
455+
}
443456
return i
444457
}
445458

@@ -762,7 +775,7 @@ func (f *FormPanel) FieldSubstr(start int, end int) *FormPanel {
762775
return f
763776
}
764777

765-
func (f *FormPanel) FieldToTitle() *FormPanel {
778+
func (f *FormPanel) FieldToTitlCustomJse() *FormPanel {
766779
f.FieldList[f.curFieldListIndex].DisplayProcessChains = f.FieldList[f.curFieldListIndex].AddToTitle()
767780
return f
768781
}

0 commit comments

Comments
 (0)