Skip to content

Commit

Permalink
Improves sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
tjayrush committed Nov 28, 2024
1 parent 303d632 commit 98be3f8
Show file tree
Hide file tree
Showing 15 changed files with 71 additions and 38 deletions.
11 changes: 1 addition & 10 deletions code_gen/templates/generators/types/app_data+type.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
{{ $embedType := .EmbedType }}
{{ $members := .Members }}

{{ $hasSorts := .HasSorts }}
{{ $hasEmbed := and (gt (len .EmbedName) 0) true }}

{{ $isHistory := eq $class "History" }}
Expand All @@ -26,14 +25,6 @@
{{ $appData = $routeLower }}
{{ end }}

{{ $sorts := "" }}
{{ if $hasSorts }}
{{ $sorts = print ` if err := sdk.Sort` $routeName `(` $appData `.Items, ` $appData `.Sorts); err != nil {
a.emitErrorMsg(err, nil)
}
`}}
{{ end }}

{{ $param1 := ""}}
{{ if $isHistory }}
{{ $param1 = "address" }}
Expand Down Expand Up @@ -130,7 +121,7 @@ func (a *App) load{{$routeName}}(wg *sync.WaitGroup, errorChan chan error) error
if err := {{$appData}}.Sort(); err != nil {
a.emitErrorMsg(err, nil)
}
{{ $sorts }} a.emitLoadingMsg(messages.Loaded, "{{$routeLower}}")
a.emitLoadingMsg(messages.Loaded, "{{$routeLower}}")
}

return nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,5 +194,11 @@ func (s *{{$class}}Container) ForEveryItem(process Every{{$itemName}}Fn, data an
return true
}

func (s *{{$class}}Container) Sort() (err error) {
// EXISTING_CODE
// EXISTING_CODE
return
}

// EXISTING_CODE
// EXISTING_CODE
7 changes: 5 additions & 2 deletions pkg/types/types_containerabi.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,11 @@ func (s *AbiContainer) ForEveryItem(process EveryAbiFn, data any) bool {
return true
}

func (s *AbiContainer) Sort() error {
return sdk.SortAbis(s.Items, s.Sorts)
func (s *AbiContainer) Sort() (err error) {
// EXISTING_CODE
err = sdk.SortAbis(s.Items, s.Sorts)
// EXISTING_CODE
return
}

// EXISTING_CODE
Expand Down
7 changes: 5 additions & 2 deletions pkg/types/types_containerconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,11 @@ func (s *ConfigContainer) ForEveryItem(process EveryChainFn, data any) bool {
return true
}

func (s *ConfigContainer) Sort() error {
return sdk.SortChains(s.Items, s.Sorts)
func (s *ConfigContainer) Sort() (err error) {
// EXISTING_CODE
err = sdk.SortChains(s.Items, s.Sorts)
// EXISTING_CODE
return
}

// EXISTING_CODE
Expand Down
6 changes: 4 additions & 2 deletions pkg/types/types_containerdaemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,11 @@ func (s *DaemonContainer) ForEveryItem(process EveryNothingFn, data any) bool {
return true
}

func (s *DaemonContainer) Sort() error {
func (s *DaemonContainer) Sort() (err error) {
// EXISTING_CODE
// TODO: Is there anything to sort for daemons?
return nil
// EXISTING_CODE
return
}

// EXISTING_CODE
Expand Down
6 changes: 4 additions & 2 deletions pkg/types/types_containerhistory.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,11 @@ func (s *HistoryContainer) ForEveryItem(process EveryTransactionFn, data any) bo
return true
}

func (s *HistoryContainer) Sort() error {
func (s *HistoryContainer) Sort() (err error) {
// EXISTING_CODE
// TODO: Is there anything to sort for history?
return nil
// EXISTING_CODE
return
}

// EXISTING_CODE
Expand Down
7 changes: 5 additions & 2 deletions pkg/types/types_containerindex.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,11 @@ func (s *IndexContainer) ForEveryItem(process EveryChunkStatsFn, data any) bool
return true
}

func (s *IndexContainer) Sort() error {
return sdk.SortChunkStats(s.Items, s.Sorts)
func (s *IndexContainer) Sort() (err error) {
// EXISTING_CODE
err = sdk.SortChunkStats(s.Items, s.Sorts)
// EXISTING_CODE
return
}

// EXISTING_CODE
Expand Down
7 changes: 5 additions & 2 deletions pkg/types/types_containermanifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,11 @@ func (s *ManifestContainer) ForEveryItem(process EveryChunkRecordFn, data any) b
return true
}

func (s *ManifestContainer) Sort() error {
return sdk.SortChunkRecords(s.Items, s.Sorts)
func (s *ManifestContainer) Sort() (err error) {
// EXISTING_CODE
err = sdk.SortChunkRecords(s.Items, s.Sorts)
// EXISTING_CODE
return
}

// EXISTING_CODE
Expand Down
7 changes: 5 additions & 2 deletions pkg/types/types_containermonitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,11 @@ func (s *MonitorContainer) ForEveryItem(process EveryMonitorFn, data any) bool {
return true
}

func (s *MonitorContainer) Sort() error {
return sdk.SortMonitors(s.Items, s.Sorts)
func (s *MonitorContainer) Sort() (err error) {
// EXISTING_CODE
err = sdk.SortMonitors(s.Items, s.Sorts)
// EXISTING_CODE
return
}

// EXISTING_CODE
Expand Down
7 changes: 5 additions & 2 deletions pkg/types/types_containername.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,12 +225,15 @@ func (s *NameContainer) ForEveryItem(process EveryNameFn, data any) bool {
return true
}

func (s *NameContainer) Sort() error {
func (s *NameContainer) Sort() (err error) {
// EXISTING_CODE
sort.Slice(s.Items, func(i, j int) bool {
return compare(s.Items[i], s.Items[j])
})
// TODO: Sorting?
// return sdk.SortNames(s.Items, s.Sorts)
return nil
// EXISTING_CODE
return
}

// EXISTING_CODE
Expand Down
11 changes: 7 additions & 4 deletions pkg/types/types_containerproject.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ func NewProjectContainer(chain string, itemsIn []HistoryContainer) ProjectContai
Items: itemsIn,
NItems: uint64(len(itemsIn)),
Sorts: sdk.SortSpec{
Fields: []string{},
Order: []sdk.SortOrder{},
Fields: []string{"address"},
Order: []sdk.SortOrder{"Asc},
},
Updater: NewProjectUpdater(chain, itemsIn),
}
Expand Down Expand Up @@ -176,12 +176,15 @@ func (s *ProjectContainer) ForEveryItem(process EveryHistoryContainerFn, data an
return true
}

func (s *ProjectContainer) Sort() error {
func (s *ProjectContainer) Sort() (err error) {
// EXISTING_CODE
sort.Slice(s.Items, func(i, j int) bool {
return s.Items[i].Address.Hex() < s.Items[j].Address.Hex()
})
// TODO: Sorting?
// return sdk.SortHistoryContainers(s.Items, s.Sorts)
return nil
// EXISTING_CODE
return
}

// EXISTING_CODE
Expand Down
7 changes: 5 additions & 2 deletions pkg/types/types_containersession.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,11 @@ func (s *SessionContainer) ForEveryItem(process EveryNothingFn, data any) bool {
return true
}

func (s *SessionContainer) Sort() error {
return nil
func (s *SessionContainer) Sort() (err error) {
// EXISTING_CODE
// TODO: Sorting?
// EXISTING_CODE
return
}

// EXISTING_CODE
Expand Down
7 changes: 5 additions & 2 deletions pkg/types/types_containersettings.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,11 @@ func (s *SettingsContainer) ForEveryItem(process EveryCacheItemFn, data any) boo
return true
}

func (s *SettingsContainer) Sort() error {
return nil
func (s *SettingsContainer) Sort() (err error) {
// EXISTING_CODE
// TODO: Sorting?
// EXISTING_CODE
return
}

// EXISTING_CODE
Expand Down
7 changes: 5 additions & 2 deletions pkg/types/types_containerstatus.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,11 @@ func (s *StatusContainer) ForEveryItem(process EveryCacheItemFn, data any) bool
return true
}

func (s *StatusContainer) Sort() error {
return sdk.SortCacheItems(s.Items, s.Sorts)
func (s *StatusContainer) Sort() (err error) {
// EXISTING_CODE
err = sdk.SortCacheItems(s.Items, s.Sorts)
// EXISTING_CODE
return
}

// EXISTING_CODE
Expand Down
6 changes: 4 additions & 2 deletions pkg/types/types_containerwizard.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,11 @@ func (s *WizardContainer) ForEveryItem(process EveryWizErrorFn, data any) bool {
return true
}

func (s *WizardContainer) Sort() error {
func (s *WizardContainer) Sort() (err error) {
// EXISTING_CODE
// TODO: Sorting?
return nil
// EXISTING_CODE
return
}

// EXISTING_CODE
Expand Down

0 comments on commit 98be3f8

Please sign in to comment.