Fix paging cursor sort-direction flag
Fixes issue cortezaproject/corteza-webapp-compose#213
This commit is contained in:
@@ -651,7 +651,7 @@ func (s Store) internal{{ export $.Types.Singular }}Encoder(res *{{ $.Types.GoTy
|
||||
// undeleted items)
|
||||
func (s Store) collect{{ export $.Types.Singular }}CursorValues({{ template "extraArgsDef" $ }}res *{{ $.Types.GoType }}, cc ...*filter.SortExpr) *filter.PagingCursor {
|
||||
var (
|
||||
cursor = &filter.PagingCursor{}
|
||||
cursor = &filter.PagingCursor{LThen: filter.SortExprSet(cc).Reversed()}
|
||||
|
||||
hasUnique bool
|
||||
|
||||
|
||||
@@ -533,7 +533,7 @@ func (s Store) internalApplicationEncoder(res *types.Application) store.Payload
|
||||
// undeleted items)
|
||||
func (s Store) collectApplicationCursorValues(res *types.Application, cc ...*filter.SortExpr) *filter.PagingCursor {
|
||||
var (
|
||||
cursor = &filter.PagingCursor{}
|
||||
cursor = &filter.PagingCursor{LThen: filter.SortExprSet(cc).Reversed()}
|
||||
|
||||
hasUnique bool
|
||||
|
||||
|
||||
@@ -543,7 +543,7 @@ func (s Store) internalComposeChartEncoder(res *types.Chart) store.Payload {
|
||||
// undeleted items)
|
||||
func (s Store) collectComposeChartCursorValues(res *types.Chart, cc ...*filter.SortExpr) *filter.PagingCursor {
|
||||
var (
|
||||
cursor = &filter.PagingCursor{}
|
||||
cursor = &filter.PagingCursor{LThen: filter.SortExprSet(cc).Reversed()}
|
||||
|
||||
hasUnique bool
|
||||
|
||||
|
||||
@@ -553,7 +553,7 @@ func (s Store) internalComposeModuleEncoder(res *types.Module) store.Payload {
|
||||
// undeleted items)
|
||||
func (s Store) collectComposeModuleCursorValues(res *types.Module, cc ...*filter.SortExpr) *filter.PagingCursor {
|
||||
var (
|
||||
cursor = &filter.PagingCursor{}
|
||||
cursor = &filter.PagingCursor{LThen: filter.SortExprSet(cc).Reversed()}
|
||||
|
||||
hasUnique bool
|
||||
|
||||
|
||||
@@ -542,7 +542,7 @@ func (s Store) internalComposeNamespaceEncoder(res *types.Namespace) store.Paylo
|
||||
// undeleted items)
|
||||
func (s Store) collectComposeNamespaceCursorValues(res *types.Namespace, cc ...*filter.SortExpr) *filter.PagingCursor {
|
||||
var (
|
||||
cursor = &filter.PagingCursor{}
|
||||
cursor = &filter.PagingCursor{LThen: filter.SortExprSet(cc).Reversed()}
|
||||
|
||||
hasUnique bool
|
||||
|
||||
|
||||
@@ -568,7 +568,7 @@ func (s Store) internalComposePageEncoder(res *types.Page) store.Payload {
|
||||
// undeleted items)
|
||||
func (s Store) collectComposePageCursorValues(res *types.Page, cc ...*filter.SortExpr) *filter.PagingCursor {
|
||||
var (
|
||||
cursor = &filter.PagingCursor{}
|
||||
cursor = &filter.PagingCursor{LThen: filter.SortExprSet(cc).Reversed()}
|
||||
|
||||
hasUnique bool
|
||||
|
||||
|
||||
@@ -176,6 +176,7 @@ func (s Store) composeRecordsPageNavigation(
|
||||
// first page
|
||||
q = supPageQuery
|
||||
} else {
|
||||
//cursor.LThen = sort.Reversed()
|
||||
q = supPageQuery.Where(cursorCond(cursor))
|
||||
}
|
||||
|
||||
@@ -531,26 +532,26 @@ func (s Store) convertComposeRecordFilter(m *types.Module, f types.RecordFilter)
|
||||
return
|
||||
}
|
||||
|
||||
func (s Store) convertComposeRecordCursor(m *types.Module, from *filter.PagingCursor) (to *filter.PagingCursor) {
|
||||
if from != nil {
|
||||
to = &filter.PagingCursor{ROrder: from.ROrder, LThen: from.LThen}
|
||||
// convert cursor keys field names (if used)
|
||||
from.Walk(func(key string, val interface{}, desc bool) {
|
||||
if col, has := s.sortableComposeRecordColumns()[strings.ToLower(key)]; has {
|
||||
key = col
|
||||
} else if f := m.Fields.FindByName(key); f != nil {
|
||||
key, _ = s.config.CastModuleFieldToColumnType(f, key)
|
||||
} else {
|
||||
return
|
||||
}
|
||||
|
||||
to.Set(key, val, desc)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
return to
|
||||
}
|
||||
//func (s Store) convertComposeRecordCursor(m *types.Module, from *filter.PagingCursor) (to *filter.PagingCursor) {
|
||||
// if from != nil {
|
||||
// to = &filter.PagingCursor{ROrder: from.ROrder, LThen: from.LThen}
|
||||
// // convert cursor keys field names (if used)
|
||||
// from.Walk(func(key string, val interface{}, desc bool) {
|
||||
// if col, has := s.sortableComposeRecordColumns()[strings.ToLower(key)]; has {
|
||||
// key = col
|
||||
// } else if f := m.Fields.FindByName(key); f != nil {
|
||||
// key, _ = s.config.CastModuleFieldToColumnType(f, key)
|
||||
// } else {
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// to.Set(key, val, desc)
|
||||
// })
|
||||
//
|
||||
// }
|
||||
//
|
||||
// return to
|
||||
//}
|
||||
|
||||
func (s Store) composeRecordPostLoadProcessor(ctx context.Context, m *types.Module, set ...*types.Record) (err error) {
|
||||
if len(set) > 0 {
|
||||
@@ -604,7 +605,7 @@ func (s Store) composeRecordsSorter(m *types.Module, q squirrel.SelectBuilder, s
|
||||
// Custom implementation for collecting cursor values from compose records AND it's values!
|
||||
func (s Store) collectComposeRecordCursorValues(m *types.Module, res *types.Record, sort ...*filter.SortExpr) *filter.PagingCursor {
|
||||
var (
|
||||
cursor = &filter.PagingCursor{}
|
||||
cursor = &filter.PagingCursor{LThen: filter.SortExprSet(sort).Reversed()}
|
||||
|
||||
hasUnique bool
|
||||
pkID bool
|
||||
|
||||
@@ -543,7 +543,7 @@ func (s Store) internalFederationExposedModuleEncoder(res *types.ExposedModule)
|
||||
// undeleted items)
|
||||
func (s Store) collectFederationExposedModuleCursorValues(res *types.ExposedModule, cc ...*filter.SortExpr) *filter.PagingCursor {
|
||||
var (
|
||||
cursor = &filter.PagingCursor{}
|
||||
cursor = &filter.PagingCursor{LThen: filter.SortExprSet(cc).Reversed()}
|
||||
|
||||
hasUnique bool
|
||||
|
||||
|
||||
@@ -548,7 +548,7 @@ func (s Store) internalFederationModuleMappingEncoder(res *types.ModuleMapping)
|
||||
// undeleted items)
|
||||
func (s Store) collectFederationModuleMappingCursorValues(res *types.ModuleMapping, cc ...*filter.SortExpr) *filter.PagingCursor {
|
||||
var (
|
||||
cursor = &filter.PagingCursor{}
|
||||
cursor = &filter.PagingCursor{LThen: filter.SortExprSet(cc).Reversed()}
|
||||
|
||||
hasUnique bool
|
||||
|
||||
|
||||
@@ -534,7 +534,7 @@ func (s Store) internalFederationNodesSyncEncoder(res *types.NodeSync) store.Pay
|
||||
// undeleted items)
|
||||
func (s Store) collectFederationNodesSyncCursorValues(res *types.NodeSync, cc ...*filter.SortExpr) *filter.PagingCursor {
|
||||
var (
|
||||
cursor = &filter.PagingCursor{}
|
||||
cursor = &filter.PagingCursor{LThen: filter.SortExprSet(cc).Reversed()}
|
||||
|
||||
hasUnique bool
|
||||
|
||||
|
||||
@@ -540,7 +540,7 @@ func (s Store) internalFederationSharedModuleEncoder(res *types.SharedModule) st
|
||||
// undeleted items)
|
||||
func (s Store) collectFederationSharedModuleCursorValues(res *types.SharedModule, cc ...*filter.SortExpr) *filter.PagingCursor {
|
||||
var (
|
||||
cursor = &filter.PagingCursor{}
|
||||
cursor = &filter.PagingCursor{LThen: filter.SortExprSet(cc).Reversed()}
|
||||
|
||||
hasUnique bool
|
||||
|
||||
|
||||
@@ -540,7 +540,7 @@ func (s Store) internalMessagingChannelEncoder(res *types.Channel) store.Payload
|
||||
// undeleted items)
|
||||
func (s Store) collectMessagingChannelCursorValues(res *types.Channel, cc ...*filter.SortExpr) *filter.PagingCursor {
|
||||
var (
|
||||
cursor = &filter.PagingCursor{}
|
||||
cursor = &filter.PagingCursor{LThen: filter.SortExprSet(cc).Reversed()}
|
||||
|
||||
hasUnique bool
|
||||
|
||||
|
||||
@@ -550,7 +550,7 @@ func (s Store) internalReminderEncoder(res *types.Reminder) store.Payload {
|
||||
// undeleted items)
|
||||
func (s Store) collectReminderCursorValues(res *types.Reminder, cc ...*filter.SortExpr) *filter.PagingCursor {
|
||||
var (
|
||||
cursor = &filter.PagingCursor{}
|
||||
cursor = &filter.PagingCursor{LThen: filter.SortExprSet(cc).Reversed()}
|
||||
|
||||
hasUnique bool
|
||||
|
||||
|
||||
@@ -556,7 +556,7 @@ func (s Store) internalRoleEncoder(res *types.Role) store.Payload {
|
||||
// undeleted items)
|
||||
func (s Store) collectRoleCursorValues(res *types.Role, cc ...*filter.SortExpr) *filter.PagingCursor {
|
||||
var (
|
||||
cursor = &filter.PagingCursor{}
|
||||
cursor = &filter.PagingCursor{LThen: filter.SortExprSet(cc).Reversed()}
|
||||
|
||||
hasUnique bool
|
||||
|
||||
|
||||
@@ -580,7 +580,7 @@ func (s Store) internalUserEncoder(res *types.User) store.Payload {
|
||||
// undeleted items)
|
||||
func (s Store) collectUserCursorValues(res *types.User, cc ...*filter.SortExpr) *filter.PagingCursor {
|
||||
var (
|
||||
cursor = &filter.PagingCursor{}
|
||||
cursor = &filter.PagingCursor{LThen: filter.SortExprSet(cc).Reversed()}
|
||||
|
||||
hasUnique bool
|
||||
|
||||
|
||||
@@ -663,6 +663,8 @@ func testComposeRecords(t *testing.T, s store.ComposeRecords) {
|
||||
}
|
||||
)
|
||||
|
||||
// ascending
|
||||
|
||||
req.NoError(f.Sort.Set("str1"))
|
||||
f.Limit = 2
|
||||
f.IncPageNavigation = true
|
||||
@@ -690,6 +692,37 @@ func testComposeRecords(t *testing.T, s store.ComposeRecords) {
|
||||
req.NoError(err)
|
||||
req.NotNil(set)
|
||||
req.Equal("v9", stringifyValues(set, "str1"))
|
||||
|
||||
// descending
|
||||
|
||||
req.NoError(f.Sort.Set("str1 DESC"))
|
||||
f.Limit = 2
|
||||
f.PageCursor = nil
|
||||
f.IncPageNavigation = true
|
||||
f.IncTotal = true
|
||||
|
||||
set, f, err = s.SearchComposeRecords(ctx, mod, f)
|
||||
req.NoError(err)
|
||||
req.NotNil(set)
|
||||
req.NotNil(f.PageNavigation)
|
||||
req.Equal(uint(9), f.Total)
|
||||
req.Len(f.PageNavigation, 5)
|
||||
|
||||
f.PageCursor = f.PageNavigation[1].Cursor
|
||||
f.IncPageNavigation = false
|
||||
f.IncTotal = false
|
||||
set, _, err = s.SearchComposeRecords(ctx, mod, f)
|
||||
req.NoError(err)
|
||||
req.NotNil(set)
|
||||
req.Equal("v7;v6", stringifyValues(set, "str1"))
|
||||
|
||||
f.PageCursor = f.PageNavigation[4].Cursor
|
||||
f.IncPageNavigation = false
|
||||
f.IncTotal = false
|
||||
set, _, err = s.SearchComposeRecords(ctx, mod, f)
|
||||
req.NoError(err)
|
||||
req.NotNil(set)
|
||||
req.Equal("v1", stringifyValues(set, "str1"))
|
||||
})
|
||||
|
||||
t.Run("report", func(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user