Skip to content

Commit

Permalink
Merge pull request #51 from kintone-labs/SSR-2458-fix-order-columns
Browse files Browse the repository at this point in the history
SSR-2458 Update order field code
  • Loading branch information
nmanhit authored Jul 25, 2022
2 parents b3dba3b + 9895bbd commit bdfbf2c
Showing 1 changed file with 45 additions and 45 deletions.
90 changes: 45 additions & 45 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -985,7 +985,7 @@ type FieldInfo struct {
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"`
Index int `json:"index"`
}

// Work around code to handle "true"/"false" strings as booleans...
Expand All @@ -1009,8 +1009,7 @@ func (fi *FieldInfo) UnmarshalJSON(data []byte) error {
Medium string `json:"protocol"`
Format string `json:"format"`
Fields []FieldInfo `json:"fields"`
Index int `json:"index"`

Index int `json:"index"`
}
err := json.Unmarshal(data, &t)
if err != nil {
Expand All @@ -1024,14 +1023,14 @@ 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,
}
return nil
}

// Decode JSON from app/form/fields.json
func decodeFieldInfo(t AppFormFields, ret map[string]*FieldInfo) {
itemsMap := t.Properties.(map[string]interface{})
itemsMap := t.Properties.(map[string]interface{})
for k, v := range itemsMap {
fi := FieldInfo{}
for l, w := range v.(map[string]interface{}) {
Expand Down Expand Up @@ -1078,13 +1077,14 @@ func decodeFieldInfo(t AppFormFields, ret map[string]*FieldInfo) {
ret := make(map[string]*FieldInfo)
var y AppFormFields
y.Properties = w
decodeFieldInfo(y, ret)
var sb []FieldInfo
decodeFieldInfo(y, ret)
var sb []FieldInfo
for z, _ := range ret {
sb = append(sb, *ret[z])
}
fi.Fields = sb
default: break;
sb = append(sb, *ret[z])
}
fi.Fields = sb
default:
break
}
}
switch fi.Type {
Expand All @@ -1108,9 +1108,9 @@ func (app *App) Fields() (map[string]*FieldInfo, error) {
data, _ := json.Marshal(request_body{app.AppId})
req, err := app.newRequest("GET", "app/form/fields", bytes.NewReader(data))
if err != nil {
return nil, err
return nil, err
}
resp, err := app.do(req)
resp, err := app.do(req)
if err != nil {
return nil, err
}
Expand All @@ -1119,7 +1119,7 @@ func (app *App) Fields() (map[string]*FieldInfo, error) {
if err != nil {
fmt.Println("error:", err)
}

if err != nil {
return nil, err
}
Expand All @@ -1136,61 +1136,61 @@ func (app *App) Fields() (map[string]*FieldInfo, error) {
return ret, nil
}

func getFieldCodeFromFormField(formField []byte) []string {
result := []string{}
var tempByteString= "";
var fieldCode = "";
func getFieldCodeFromFormField(formField []byte) [][]byte {
result := [][]byte{}
var tempByteString = ""
fieldCode := []byte{}
fieldCodeIgnore := []string{"GROUP"}
for _,byteField:= range formField {
hasField := hasFieldCodeIgnore(byteField , tempByteString, fieldCodeIgnore)
for _, byteField := range formField {
hasField := hasFieldCodeIgnore(byteField, tempByteString, fieldCodeIgnore)
if strings.Contains(tempByteString, `"code":`) {
if string(byteField) == "," {
if hasField {
tempByteString = "";
fieldCode = "";
hasField= false;
continue;
tempByteString = ""
fieldCode = []byte{}
hasField = false
continue
}
tempByteString = "";
result = append(result, fieldCode);
fieldCode = "";
tempByteString = ""
result = append(result, fieldCode)
fieldCode = []byte{}
} else if string(byteField) != `"` {
fieldCode += string(byteField);
fieldCode = append(fieldCode, byteField)
}
continue;
continue
}
tempByteString += string(byteField);
tempByteString += string(byteField)
}
return result;
return result
}

func hasFieldCodeIgnore(byteField byte,tempFormFieldString string,fieldCodeIgnore []string) bool {
func hasFieldCodeIgnore(byteField byte, tempFormFieldString string, fieldCodeIgnore []string) bool {
hasField := false
if strings.Contains(tempFormFieldString, `"type":`) {
if string(byteField) == "," {
for _, type_1 := range fieldCodeIgnore {
if strings.Contains(tempFormFieldString, type_1) {
hasField= true
if strings.Contains(tempFormFieldString, fmt.Sprintf(`"type": %s"`, type_1)) {
hasField = true
}
}
}
}
return hasField
}

func updateIndexToField(fieldCode []string, fieldInfo map[string]*FieldInfo) {
i:=0
for _,initFieldCode:= range fieldCode {
for _,sortedFieldCode:= range fieldInfo {
if initFieldCode == sortedFieldCode.Code {
sortedFieldCode.Index = i;
i+=1
func updateIndexToField(fieldCode [][]byte, fieldInfo map[string]*FieldInfo) {
i := 0
for _, initFieldCode := range fieldCode {
for _, sortedFieldCode := range fieldInfo {
if bytes.Equal(initFieldCode, []byte(sortedFieldCode.Code)) {
sortedFieldCode.Index = i
i += 1
}

for k,subField := range sortedFieldCode.Fields {
if initFieldCode == subField.Code {
sortedFieldCode.Fields[k].Index = i;
i+=1
for k, subField := range sortedFieldCode.Fields {
if bytes.Equal(initFieldCode, []byte(subField.Code)) {
sortedFieldCode.Fields[k].Index = i
i += 1
}

}
Expand Down

0 comments on commit bdfbf2c

Please sign in to comment.