diff --git a/pkg/envoy/resource/compose_page.go b/pkg/envoy/resource/compose_page.go index fba73c4d5..0040a0049 100644 --- a/pkg/envoy/resource/compose_page.go +++ b/pkg/envoy/resource/compose_page.go @@ -53,6 +53,17 @@ func NewComposePage(pg *types.Page, nsRef, modRef, parentRef string) *ComposePag r.ChartRefs = append(r.ChartRefs, r.AddRef(COMPOSE_CHART_RESOURCE_TYPE, id)) } + case "Calendar": + ff, _ := b.Options["feeds"].([]interface{}) + for _, f := range ff { + feed, _ := f.(map[string]interface{}) + fOpts, _ := (feed["options"]).(map[string]interface{}) + id, _ := fOpts["module"].(string) + if id != "" { + r.ModRefs = append(r.ModRefs, r.AddRef(COMPOSE_MODULE_RESOURCE_TYPE, id)) + } + } + case "Metric": mm, _ := b.Options["metrics"].([]interface{}) for _, m := range mm { diff --git a/pkg/envoy/store/compose_module.go b/pkg/envoy/store/compose_module.go index b9cfe80d7..e44591696 100644 --- a/pkg/envoy/store/compose_module.go +++ b/pkg/envoy/store/compose_module.go @@ -3,6 +3,7 @@ package store import ( "context" "fmt" + "strconv" "time" "github.com/cortezaproject/corteza-server/compose/types" @@ -154,7 +155,8 @@ func (n *composeModuleState) Encode(ctx context.Context, s store.Storer, state * mID = mod.ID } - f.Options["module"] = mID + f.Options["moduleID"] = strconv.FormatUint(mID, 10) + delete(f.Options, "module") } } diff --git a/pkg/envoy/store/compose_page.go b/pkg/envoy/store/compose_page.go index 16caa145d..c850475fd 100644 --- a/pkg/envoy/store/compose_page.go +++ b/pkg/envoy/store/compose_page.go @@ -3,6 +3,7 @@ package store import ( "context" "fmt" + "strconv" "time" "github.com/cortezaproject/corteza-server/compose/types" @@ -185,7 +186,25 @@ func (n *composePageState) Encode(ctx context.Context, s store.Storer, state *en if mID <= 0 { return composeModuleErrUnresolved(resource.MakeIdentifiers(id)) } - b.Options["module"] = mID + b.Options["moduleID"] = strconv.FormatUint(mID, 10) + delete(b.Options, "module") + + case "Calendar": + ff, _ := b.Options["feeds"].([]interface{}) + for _, f := range ff { + feed, _ := f.(map[string]interface{}) + fOpts, _ := (feed["options"]).(map[string]interface{}) + id, _ := fOpts["module"].(string) + if id == "" { + continue + } + mID := getModID(id) + if mID <= 0 { + return composeModuleErrUnresolved(resource.MakeIdentifiers(id)) + } + fOpts["moduleID"] = strconv.FormatUint(mID, 10) + delete(fOpts, "module") + } case "Chart": id, _ := b.Options["chart"].(string) @@ -200,7 +219,8 @@ func (n *composePageState) Encode(ctx context.Context, s store.Storer, state *en return composeChartErrUnresolved(ii) } } - b.Options["chart"] = chr.ID + b.Options["chartID"] = strconv.FormatUint(chr.ID, 10) + delete(b.Options, "chart") case "Metric": mm, _ := b.Options["metrics"].([]interface{}) @@ -214,7 +234,8 @@ func (n *composePageState) Encode(ctx context.Context, s store.Storer, state *en if mID <= 0 { return composeModuleErrUnresolved(resource.MakeIdentifiers(id)) } - mops["module"] = mID + mops["moduleID"] = strconv.FormatUint(mID, 10) + delete(mops, "module") } } diff --git a/pkg/envoy/yaml/compose_page.go b/pkg/envoy/yaml/compose_page.go index f21cda00e..bd2a60c8c 100644 --- a/pkg/envoy/yaml/compose_page.go +++ b/pkg/envoy/yaml/compose_page.go @@ -27,9 +27,15 @@ type ( ) func (wset *composePageSet) UnmarshalYAML(n *yaml.Node) error { + wx := make(map[uint64]int) + return each(n, func(k, v *yaml.Node) (err error) { var ( - wrap = &composePage{} + wrap = &composePage{ + // Set this to something negative so we have an easier time determining + // if we should fix the pages weight + res: &types.Page{Weight: -1}, + } ) if v == nil { @@ -49,6 +55,11 @@ func (wset *composePageSet) UnmarshalYAML(n *yaml.Node) error { wrap.res.Title = wrap.res.Handle } + if wrap.res.Weight < 0 { + wrap.res.Weight = wx[wrap.res.SelfID] + } + wx[wrap.res.SelfID]++ + *wset = append(*wset, wrap) return }) diff --git a/tests/envoy/mod_rel_test.go b/tests/envoy/mod_rel_test.go index 39ba3bc85..6a6390285 100644 --- a/tests/envoy/mod_rel_test.go +++ b/tests/envoy/mod_rel_test.go @@ -3,6 +3,7 @@ package envoy import ( "context" "fmt" + "strconv" "testing" "github.com/cortezaproject/corteza-server/compose/types" @@ -62,7 +63,7 @@ func TestModuleRels(t *testing.T) { ff := mod.Fields req.Len(ff, 1) req.Equal("Record", ff[0].Kind) - req.Equal(mod.ID, uint64(ff[0].Options.Int64("module"))) + req.Equal(strconv.FormatUint(mod.ID, 10), ff[0].Options.String("moduleID")) }, }, @@ -97,7 +98,7 @@ func TestModuleRels(t *testing.T) { ff := mod.Fields req.Len(ff, 1) req.Equal("Record", ff[0].Kind) - req.Equal(pmod.ID, uint64(ff[0].Options.Int64("module"))) + req.Equal(strconv.FormatUint(pmod.ID, 10), ff[0].Options.String("moduleID")) }, }, @@ -133,7 +134,7 @@ func TestModuleRels(t *testing.T) { ff := mod.Fields req.Len(ff, 1) req.Equal("Record", ff[0].Kind) - req.Equal(smod.ID, uint64(ff[0].Options.Int64("module"))) + req.Equal(strconv.FormatUint(smod.ID, 10), ff[0].Options.String("moduleID")) }, }, } diff --git a/tests/envoy/provision_test.go b/tests/envoy/provision_test.go index f0d7bf276..e99f89c74 100644 --- a/tests/envoy/provision_test.go +++ b/tests/envoy/provision_test.go @@ -2,6 +2,7 @@ package envoy import ( "context" + "strconv" "testing" "github.com/cortezaproject/corteza-server/compose/types" @@ -117,7 +118,7 @@ func TestProvision(t *testing.T) { req.Equal([]interface{}{"☆☆☆☆☆", "★☆☆☆☆"}, opt) req.Equal("Record", m1.Fields[3].Kind) - req.Equal(m2.ID, uint64(m1.Fields[3].Options.Int64("module"))) + req.Equal(strconv.FormatUint(m2.ID, 10), m1.Fields[3].Options.String("moduleID")) opt = getOptSlice(req, "queryFields", m1.Fields[3]) req.Equal([]interface{}{"f1"}, opt) @@ -125,12 +126,12 @@ func TestProvision(t *testing.T) { req.Len(m1.Fields, 4) req.Equal("Record", m2.Fields[1].Kind) - req.Equal(m2.ID, uint64(m2.Fields[1].Options.Int64("module"))) + req.Equal(strconv.FormatUint(m2.ID, 10), m2.Fields[1].Options.String("moduleID")) opt = getOptSlice(req, "queryFields", m2.Fields[1]) req.Equal([]interface{}{"f1"}, opt) req.Equal("Record", m2.Fields[3].Kind) - req.Equal(m3.ID, uint64(m2.Fields[3].Options.Int64("module"))) + req.Equal(strconv.FormatUint(m3.ID, 10), m2.Fields[3].Options.String("moduleID")) opt = getOptSlice(req, "queryFields", m2.Fields[3]) req.Equal([]interface{}{"f1"}, opt) }) @@ -162,10 +163,10 @@ func TestProvision(t *testing.T) { req.Equal("pg1 b1 content body", pg1.Blocks[0].Options["body"]) req.Equal("RecordList", pg1.Blocks[1].Kind) - req.Equal(m1.ID, uint64((pg1.Blocks[1].Options["module"]).(float64))) + req.Equal(strconv.FormatUint(m1.ID, 10), (pg1.Blocks[1].Options["moduleID"].(string))) req.Equal("Chart", pg1.Blocks[2].Kind) - req.Equal(ch1.ID, uint64((pg1.Blocks[2].Options["chart"]).(float64))) + req.Equal(strconv.FormatUint(ch1.ID, 10), (pg1.Blocks[2].Options["chartID"].(string))) // pg2 req.Equal(m1.ID, pg2.ModuleID)