-
Notifications
You must be signed in to change notification settings - Fork 1
/
page.go
56 lines (50 loc) · 1.14 KB
/
page.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
package page
import (
"encoding/json"
"github.com/webx-top/com"
"github.com/webx-top/db"
"github.com/webx-top/echo"
"github.com/admpub/webx/application/dbschema"
)
func New(ctx echo.Context) *Page {
m := &Page{
OfficialPage: dbschema.NewOfficialPage(ctx),
}
return m
}
type Page struct {
*dbschema.OfficialPage
}
func (f *Page) LayoutList() ([]*LayoutWithBlock, error) {
m := dbschema.NewOfficialPageLayout(f.Context())
list := []*LayoutWithBlock{}
_, err := m.ListByOffset(&list, func(r db.Result) db.Result {
return r.OrderBy(`sort`, `id`)
}, 0, -1, db.And(
db.Cond{`disabled`: `N`},
db.Cond{`page_id`: f.Id},
))
if err != nil {
return list, err
}
for k, v := range list {
v.Configs = echo.H{}
v.ItemConfigs = echo.H{}
if len(v.OfficialPageLayout.Configs) > 0 {
err = json.Unmarshal(com.Str2bytes(v.OfficialPageLayout.Configs), &v.Configs)
if err != nil {
return list, err
}
}
if v.Block != nil {
if len(v.Block.ItemConfigs) > 0 {
err = json.Unmarshal(com.Str2bytes(v.Block.ItemConfigs), &v.ItemConfigs)
if err != nil {
return list, err
}
}
}
list[k] = v
}
return list, err
}