stable sort for model.go
This commit is contained in:
parent
153d46d830
commit
ca9325b93a
|
@ -142,6 +142,7 @@ func CreateMetadata(a *AnalyzeData) (*Metadata, error) {
|
|||
Typed: a.Fields[k+PATH_SEPARATOR+"type"] != nil,
|
||||
SubTypes: getSubtypes(a, k),
|
||||
SubTypeOf: getSubtypeOf(k),
|
||||
SubType: getSubtype(k),
|
||||
Fields: objFields,
|
||||
}
|
||||
}
|
||||
|
@ -196,6 +197,17 @@ func getSubtypeOf(k string) *string {
|
|||
return nil
|
||||
}
|
||||
|
||||
func getSubtype(k string) *string {
|
||||
if strings.Contains(k, PATH_SEPARATOR) {
|
||||
last := k[strings.LastIndex(k, PATH_SEPARATOR)+1:]
|
||||
if strings.Contains(last, "+") {
|
||||
base := strcase.ToDelimited(last[strings.Index(last, "+")+1:], ' ')
|
||||
return &base
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func isArray(typ string, types []string) (bool, string) {
|
||||
fc := 0
|
||||
elements := ""
|
||||
|
|
|
@ -13,6 +13,7 @@ type Object struct {
|
|||
Typed bool `json:"typed,omitempty"`
|
||||
SubTypes *[]Subtype `json:"subtypes,omitempty"`
|
||||
SubTypeOf *string `json:"subtypeof,omitempty"`
|
||||
SubType *string `json:"subtype,omitempty"`
|
||||
Fields map[string]Field `json:"fields"`
|
||||
}
|
||||
|
||||
|
@ -77,6 +78,9 @@ func (f Object) ActiveSubTypes(plus bool) []*ActiveSubType {
|
|||
}
|
||||
|
||||
list := util.Values(subs)
|
||||
for _, a := range list {
|
||||
sort.Strings(a.Options)
|
||||
}
|
||||
sort.SliceStable(list, func(i, j int) bool {
|
||||
return list[i].Case < list[j].Case
|
||||
})
|
||||
|
|
|
@ -110,6 +110,9 @@ func (x *{{ $obj.Name }}) Id() int { return x.Id_ }
|
|||
{{- if $obj.Named }}
|
||||
func (x *{{ $obj.Name }}) Name() string { return x.Name_ }
|
||||
{{- end }}
|
||||
{{- if $obj.SubType }}
|
||||
func (x *{{ $obj.Name }}) Type() string { return "{{ $obj.SubType }}" }
|
||||
{{- end }}
|
||||
func (x *{{ $obj.Name }}) RelatedToEntity(id int) bool { return {{ $obj.Related "civId,civ_id,entity_id,entity" }} }
|
||||
func (x *{{ $obj.Name }}) RelatedToHf(id int) bool { return {{ $obj.Related "hfid,hf_id,_hf,hist_figure_id,Hfid,histfig_id,histfig,bodies" }} }
|
||||
|
||||
|
@ -408,6 +411,7 @@ func (obj Object) Related(fields string) string {
|
|||
}
|
||||
}
|
||||
}
|
||||
sort.Strings(list)
|
||||
if len(list) > 0 {
|
||||
return strings.Join(list, " || ")
|
||||
}
|
||||
|
@ -421,6 +425,7 @@ func (obj Object) LegendFields(t string) []Field {
|
|||
list = append(list, f)
|
||||
}
|
||||
}
|
||||
sort.Slice(list, func(i, j int) bool { return list[i].Name < list[j].Name })
|
||||
return list
|
||||
}
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue