From c84e798ce7e9c62ee9ea41af878dc8c9de98965a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C5=BEe=20Fortun?= Date: Tue, 19 May 2020 12:52:24 +0200 Subject: [PATCH] Add weight to page create --- api/compose/spec.json | 6 ++++++ api/compose/spec/page.json | 6 ++++++ compose/rest/page.go | 1 + compose/rest/request/page.go | 24 ++++++++++++++++++++++++ 4 files changed, 37 insertions(+) diff --git a/api/compose/spec.json b/api/compose/spec.json index 30286ec97..9d4fbdbf4 100644 --- a/api/compose/spec.json +++ b/api/compose/spec.json @@ -276,6 +276,12 @@ "required": false, "title": "Description" }, + { + "type": "int", + "name": "weight", + "required": false, + "title": "Page tree weight" + }, { "type": "bool", "name": "visible", diff --git a/api/compose/spec/page.json b/api/compose/spec/page.json index 9228b8bcb..58657b0b1 100644 --- a/api/compose/spec/page.json +++ b/api/compose/spec/page.json @@ -113,6 +113,12 @@ "title": "Description", "type": "string" }, + { + "name": "weight", + "required": false, + "title": "Page tree weight", + "type": "int" + }, { "name": "visible", "required": false, diff --git a/compose/rest/page.go b/compose/rest/page.go index 25e292e95..146b73183 100644 --- a/compose/rest/page.go +++ b/compose/rest/page.go @@ -87,6 +87,7 @@ func (ctrl *Page) Create(ctx context.Context, r *request.PageCreate) (interface{ Handle: r.Handle, Description: r.Description, Visible: r.Visible, + Weight: r.Weight, } ) diff --git a/compose/rest/request/page.go b/compose/rest/request/page.go index 6b1220653..eef91a839 100644 --- a/compose/rest/request/page.go +++ b/compose/rest/request/page.go @@ -192,6 +192,10 @@ type PageCreate struct { rawDescription string Description string + hasWeight bool + rawWeight string + Weight int + hasVisible bool rawVisible string Visible bool @@ -279,6 +283,11 @@ func (r *PageCreate) Fill(req *http.Request) (err error) { r.rawDescription = val r.Description = val } + if val, ok := post["weight"]; ok { + r.hasWeight = true + r.rawWeight = val + r.Weight = parseInt(val) + } if val, ok := post["visible"]; ok { r.hasVisible = true r.rawVisible = val @@ -1078,6 +1087,21 @@ func (r *PageCreate) GetDescription() string { return r.Description } +// HasWeight returns true if weight was set +func (r *PageCreate) HasWeight() bool { + return r.hasWeight +} + +// RawWeight returns raw value of weight parameter +func (r *PageCreate) RawWeight() string { + return r.rawWeight +} + +// GetWeight returns casted value of weight parameter +func (r *PageCreate) GetWeight() int { + return r.Weight +} + // HasVisible returns true if visible was set func (r *PageCreate) HasVisible() bool { return r.hasVisible