-
Notifications
You must be signed in to change notification settings - Fork 329
/
custom_compose_page_layouts.go
61 lines (46 loc) · 1.19 KB
/
custom_compose_page_layouts.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package rdbms
import (
"context"
composeType "github.com/cortezaproject/corteza/server/compose/types"
"github.com/doug-martin/goqu/v9"
)
func (s Store) ReorderComposePageLayouts(ctx context.Context, namespaceID uint64, pageID uint64, pageLayoutLayoutIDs []uint64) (err error) {
var (
pageLayouts composeType.PageLayoutSet
pageLayoutMap = map[uint64]bool{}
weight = 1
f = composeType.PageLayoutFilter{PageID: pageID, NamespaceID: namespaceID}
query = func(id uint64, weight int) *goqu.UpdateDataset {
return s.Dialect.GOQU().
Update(composePageLayoutTable).
Set(goqu.Record{"weight": weight}).
Where(goqu.C("id").Eq(id))
}
)
if pageLayouts, _, err = s.SearchComposePageLayouts(ctx, f); err != nil {
return
}
for _, app := range pageLayouts {
pageLayoutMap[app.ID] = true
}
// honor parameter first
for _, id := range pageLayoutLayoutIDs {
if pageLayoutMap[id] {
pageLayoutMap[id] = false
if err = s.Exec(ctx, query(id, weight)); err != nil {
return
}
weight++
}
}
for id, update := range pageLayoutMap {
if !update {
continue
}
if err = s.Exec(ctx, query(id, weight)); err != nil {
return
}
weight++
}
return
}