From 18b78df40db7e48a7ba2b5b9494189f0da513d88 Mon Sep 17 00:00:00 2001 From: wataruiijima Date: Mon, 19 Jun 2023 20:19:11 +0900 Subject: [PATCH 1/5] Added lookup field with support for nil values --- app.go | 83 +++++++++++++++++++++++++++++++--------------------------- 1 file changed, 44 insertions(+), 39 deletions(-) diff --git a/app.go b/app.go index 68ea1f0..79bb2a6 100644 --- a/app.go +++ b/app.go @@ -982,49 +982,51 @@ func (app *App) DeleteComment(recordId uint64, commentId uint64) error { // FieldInfo is the meta data structure of a field. type FieldInfo struct { - Label string `json:"label"` // Label string - Code string `json:"code"` // Unique field code - Type string `json:"type"` // Field type. One of FT_* constant. - NoLabel bool `json:"noLabel"` // true to hide the label - Required bool `json:"required"` // true if this field must be filled - Unique bool `json:"unique"` // true if field values must be unique - MaxValue interface{} `json:"maxValue"` // nil or numeric string - MinValue interface{} `json:"minValue"` // nil or numeric string - MaxLength interface{} `json:"maxLength"` // nil or numeric string - MinLength interface{} `json:"minLength"` // nil or numeric string - Default interface{} `json:"defaultValue"` // anything - DefaultTime interface{} `json:"defaultExpression"` // nil or "NOW" - Options []string `json:"options"` // list of selectable values - Expression string `json:"expression"` // to calculate values - Separator bool `json:"digit"` // true to use thousand separator - Medium string `json:"protocol"` // "WEB", "CALL", or "MAIL" - Format string `json:"format"` // "NUMBER", "NUMBER_DIGIT", "DATETIME", "DATE", "TIME", "HOUR_MINUTE", "DAY_HOUR_MINUTE" - Fields []FieldInfo `json:"fields"` // Field list of this subtable - Index int `json:"index"` + Label string `json:"label"` // Label string + Code string `json:"code"` // Unique field code + Type string `json:"type"` // Field type. One of FT_* constant. + NoLabel bool `json:"noLabel"` // true to hide the label + Required bool `json:"required"` // true if this field must be filled + Unique bool `json:"unique"` // true if field values must be unique + MaxValue interface{} `json:"maxValue"` // nil or numeric string + MinValue interface{} `json:"minValue"` // nil or numeric string + MaxLength interface{} `json:"maxLength"` // nil or numeric string + MinLength interface{} `json:"minLength"` // nil or numeric string + Default interface{} `json:"defaultValue"` // anything + DefaultTime interface{} `json:"defaultExpression"` // nil or "NOW" + Options []string `json:"options"` // list of selectable values + Expression string `json:"expression"` // to calculate values + Separator bool `json:"digit"` // true to use thousand separator + Medium string `json:"protocol"` // "WEB", "CALL", or "MAIL" + Format string `json:"format"` // "NUMBER", "NUMBER_DIGIT", "DATETIME", "DATE", "TIME", "HOUR_MINUTE", "DAY_HOUR_MINUTE" + Fields []FieldInfo `json:"fields"` // Field list of this subtable + Index int `json:"index"` + Lookup *map[string]interface{} `json:"lookup,omitempty"` // lookup } // Work around code to handle "true"/"false" strings as booleans... func (fi *FieldInfo) UnmarshalJSON(data []byte) error { var t struct { - Label string `json:"label"` - Code string `json:"code"` - Type string `json:"type"` - NoLabel string `json:"noLabel"` - Required string `json:"required"` - Unique string `json:"unique"` - MaxValue interface{} `json:"maxValue"` - MinValue interface{} `json:"minValue"` - MaxLength interface{} `json:"maxLength"` - MinLength interface{} `json:"minLength"` - Default interface{} `json:"defaultValue"` - DefaultTime interface{} `json:"defaultExpression"` - Options []string `json:"options"` - Expression string `json:"expression"` - Separator string `json:"digit"` - Medium string `json:"protocol"` - Format string `json:"format"` - Fields []FieldInfo `json:"fields"` - Index int `json:"index"` + Label string `json:"label"` + Code string `json:"code"` + Type string `json:"type"` + NoLabel string `json:"noLabel"` + Required string `json:"required"` + Unique string `json:"unique"` + MaxValue interface{} `json:"maxValue"` + MinValue interface{} `json:"minValue"` + MaxLength interface{} `json:"maxLength"` + MinLength interface{} `json:"minLength"` + Default interface{} `json:"defaultValue"` + DefaultTime interface{} `json:"defaultExpression"` + Options []string `json:"options"` + Expression string `json:"expression"` + Separator string `json:"digit"` + Medium string `json:"protocol"` + Format string `json:"format"` + Fields []FieldInfo `json:"fields"` + Index int `json:"index"` + Lookup *map[string]interface{} `json:"lookup,omitempty"` } err := json.Unmarshal(data, &t) if err != nil { @@ -1038,7 +1040,7 @@ func (fi *FieldInfo) UnmarshalJSON(data []byte) error { t.MaxValue, t.MinValue, t.MaxLength, t.MinLength, t.Default, t.DefaultTime, t.Options, t.Expression, (t.Separator == "true"), - t.Medium, t.Format, t.Fields, t.Index, + t.Medium, t.Format, t.Fields, t.Index, t.Lookup, } return nil } @@ -1098,6 +1100,9 @@ func decodeFieldInfo(t AppFormFields, ret map[string]*FieldInfo) { sb = append(sb, *ret[z]) } fi.Fields = sb + case "lookup": + result, _ := (w).(map[string]interface{}) + fi.Lookup = &result default: break } From 9422c75f569f46fb5d44f887a8b986e727bf9b6b Mon Sep 17 00:00:00 2001 From: hoangtran2506 <117815925+hoangtran2506@users.noreply.github.com> Date: Wed, 16 Aug 2023 13:09:54 +0700 Subject: [PATCH 2/5] [feat]: test for lookup field --- app_test.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/app_test.go b/app_test.go index 6791547..71bc6de 100644 --- a/app_test.go +++ b/app_test.go @@ -496,3 +496,23 @@ func TestGetProcess(t *testing.T) { t.Error("TestGetProcess failed: ", err) } } + +func TestLookupFieldInFieldInfo(t *testing.T) { + app := newApp() + countLookup := 0 + fi, err := app.Fields() + if err != nil { + t.Error("Fields failed", err) + } + for _, f := range fi { + if f.Lookup != nil {countLookup++} + } + + if countLookup > 0 { + fmt.Printf("\nApp have %v Lookup field\n", countLookup); + } + + if countLookup == 0 { + fmt.Printf("\nApp have no Lookup field\n"); + } +} From e93e21c4dce5eeb33549c5dc1bc9d603eed4c346 Mon Sep 17 00:00:00 2001 From: hoangtran2506 <117815925+hoangtran2506@users.noreply.github.com> Date: Tue, 22 Aug 2023 11:36:00 +0700 Subject: [PATCH 3/5] Revert "[feat]: test for lookup field" This reverts commit 9422c75f569f46fb5d44f887a8b986e727bf9b6b. --- app_test.go | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/app_test.go b/app_test.go index 71bc6de..6791547 100644 --- a/app_test.go +++ b/app_test.go @@ -496,23 +496,3 @@ func TestGetProcess(t *testing.T) { t.Error("TestGetProcess failed: ", err) } } - -func TestLookupFieldInFieldInfo(t *testing.T) { - app := newApp() - countLookup := 0 - fi, err := app.Fields() - if err != nil { - t.Error("Fields failed", err) - } - for _, f := range fi { - if f.Lookup != nil {countLookup++} - } - - if countLookup > 0 { - fmt.Printf("\nApp have %v Lookup field\n", countLookup); - } - - if countLookup == 0 { - fmt.Printf("\nApp have no Lookup field\n"); - } -} From 9eb31a07ff8308fe000af688ac62217a110c7a47 Mon Sep 17 00:00:00 2001 From: hoangtran2506 <117815925+hoangtran2506@users.noreply.github.com> Date: Wed, 16 Aug 2023 13:09:54 +0700 Subject: [PATCH 4/5] [feat]: test for lookup field --- app_test.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/app_test.go b/app_test.go index 6791547..71bc6de 100644 --- a/app_test.go +++ b/app_test.go @@ -496,3 +496,23 @@ func TestGetProcess(t *testing.T) { t.Error("TestGetProcess failed: ", err) } } + +func TestLookupFieldInFieldInfo(t *testing.T) { + app := newApp() + countLookup := 0 + fi, err := app.Fields() + if err != nil { + t.Error("Fields failed", err) + } + for _, f := range fi { + if f.Lookup != nil {countLookup++} + } + + if countLookup > 0 { + fmt.Printf("\nApp have %v Lookup field\n", countLookup); + } + + if countLookup == 0 { + fmt.Printf("\nApp have no Lookup field\n"); + } +} From bd7ac847ad517333e3770cba52465ec1a373a456 Mon Sep 17 00:00:00 2001 From: hoangtran2506 <117815925+hoangtran2506@users.noreply.github.com> Date: Wed, 23 Aug 2023 10:46:13 +0700 Subject: [PATCH 5/5] v0.6.0_pre-release --- app.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.go b/app.go index 79bb2a6..780cb00 100644 --- a/app.go +++ b/app.go @@ -25,7 +25,7 @@ import ( const ( NAME = "go-kintone" - VERSION = "0.4.2" + VERSION = "0.6.0" DEFAULT_TIMEOUT = time.Second * 600 // Default value for App.Timeout )