Skip to content

Commit

Permalink
added minimal required values only for website
Browse files Browse the repository at this point in the history
  • Loading branch information
Skarlso committed May 26, 2024
1 parent dc8336d commit ba36935
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 40 deletions.
6 changes: 3 additions & 3 deletions wasm/app-worker.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const cacheName = "app-" + "v0.6.4";
const cacheName = "app-" + "v0.6.5";
const resourcesToCache = ["/","/app.css","/app.js","/manifest.webmanifest","/wasm_exec.js","/web/app.wasm","/web/css/alert.css","/web/img/logo.png","https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js","https://cdn.jsdelivr.net/npm/[email protected]/css/cores/halfmoon.modern.css","https://cdn.jsdelivr.net/npm/[email protected]/css/halfmoon.min.css","https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.11/clipboard.min.js","https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css","https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/themes/prism-twilight.min.css"];

self.addEventListener("install", (event) => {
console.log("installing app worker v0.6.4");
console.log("installing app worker v0.6.5");

event.waitUntil(
caches
Expand All @@ -28,7 +28,7 @@ self.addEventListener("activate", (event) => {
);
})
);
console.log("app worker v0.6.4 is activated");
console.log("app worker v0.6.5 is activated");
});

self.addEventListener("fetch", (event) => {
Expand Down
21 changes: 14 additions & 7 deletions wasm/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type crdView struct {

content []byte
comment bool
minimal bool
}

// Version wraps a top level version resource which contains the underlying openAPIV3Schema.
Expand Down Expand Up @@ -103,9 +104,9 @@ func (h *crdView) Render() app.UI {
}

versions := make([]Version, 0)
parser := pkg.NewParser(crd.Spec.Group, crd.Spec.Names.Kind, h.comment, false)
parser := pkg.NewParser(crd.Spec.Group, crd.Spec.Names.Kind, h.comment, h.minimal)
for _, version := range crd.Spec.Versions {
out, err := parseCRD(version.Schema.OpenAPIV3Schema.Properties, version.Name, pkg.RootRequiredFields)
out, err := parseCRD(version.Schema.OpenAPIV3Schema.Properties, version.Name, pkg.RootRequiredFields, h.minimal)
if err != nil {
return h.buildError(err)
}
Expand Down Expand Up @@ -162,7 +163,6 @@ func (h *crdView) Render() app.UI {
),
)
div.Body(
&header{},
app.H1().Body(
app.P().Body(app.Text(fmt.Sprintf(
`Version: %s/%s`,
Expand All @@ -185,6 +185,7 @@ func (h *crdView) Render() app.UI {
return wrapper.Body(
app.Script().Src("https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/components/prism-core.min.js"),
app.Script().Src("https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/plugins/autoloader/prism-autoloader.min.js"),
&header{},
container,
)
}
Expand Down Expand Up @@ -275,7 +276,7 @@ func render(d app.UI, p []*Property, accordionID string) app.UI {

// parseCRD takes the properties and constructs a linked list out of the embedded properties that the recursive
// template can call and construct linked divs.
func parseCRD(properties map[string]v1beta1.JSONSchemaProps, version string, requiredList []string) ([]*Property, error) {
func parseCRD(properties map[string]v1beta1.JSONSchemaProps, version string, requiredList []string, minimal bool) ([]*Property, error) {
sortedKeys := make([]string, 0, len(properties))
output := make([]*Property, 0, len(properties))

Expand All @@ -299,6 +300,12 @@ func parseCRD(properties map[string]v1beta1.JSONSchemaProps, version string, req
break
}
}

// skip if only minimal is required
if minimal && !required {
continue
}

p := &Property{
Name: k,
Type: v.Type,
Expand All @@ -316,21 +323,21 @@ func parseCRD(properties map[string]v1beta1.JSONSchemaProps, version string, req
switch {
case len(properties[k].Properties) > 0 && properties[k].AdditionalProperties == nil:
requiredList = v.Required
out, err := parseCRD(properties[k].Properties, version, requiredList)
out, err := parseCRD(properties[k].Properties, version, requiredList, minimal)
if err != nil {
return nil, err
}
p.Properties = out
case properties[k].Type == "array" && properties[k].Items.Schema != nil && len(properties[k].Items.Schema.Properties) > 0:
requiredList = v.Required
out, err := parseCRD(properties[k].Items.Schema.Properties, version, requiredList)
out, err := parseCRD(properties[k].Items.Schema.Properties, version, requiredList, minimal)
if err != nil {
return nil, err
}
p.Properties = out
case properties[k].AdditionalProperties != nil:
requiredList = v.Required
out, err := parseCRD(properties[k].AdditionalProperties.Schema.Properties, version, requiredList)
out, err := parseCRD(properties[k].AdditionalProperties.Schema.Properties, version, requiredList, minimal)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion wasm/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var goappOnAppInstallChange = function () {
goappAppInstallChangedBeforeWasmLoaded = true;
};

const goappEnv = {"GOAPP_INTERNAL_URLS":"null","GOAPP_ROOT_PREFIX":"/","GOAPP_STATIC_RESOURCES_URL":"/web","GOAPP_VERSION":"v0.6.4"};
const goappEnv = {"GOAPP_INTERNAL_URLS":"null","GOAPP_ROOT_PREFIX":"/","GOAPP_STATIC_RESOURCES_URL":"/web","GOAPP_VERSION":"v0.6.5"};
const goappLoadingLabel = "{progress}%";
const goappWasmContentLength = "";
const goappWasmContentLengthHeader = "";
Expand Down
33 changes: 23 additions & 10 deletions wasm/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type index struct {
isMounted bool
err error
comments bool
minimal bool
}

func (i *index) buildError() app.UI {
Expand Down Expand Up @@ -98,16 +99,17 @@ func (i *input) Render() app.UI {
type form struct {
app.Compo

formHandler app.EventHandler
checkHandler app.EventHandler
formHandler app.EventHandler
checkHandlerMinimal app.EventHandler
checkHandlerComment app.EventHandler
}

func (f *form) Render() app.UI {
return app.Div().Body(
app.Div().Class("row mb-3").Body(
&textarea{},
&input{},
&checkBox{checkHandler: f.checkHandler},
&checkBox{checkHandlerComment: f.checkHandlerComment, checkHandlerMinimal: f.checkHandlerMinimal},
),
app.Div().Class("text-end").Body(app.Button().Class("btn btn-primary").Type("submit").Style("margin-top", "15px").Text("Submit").OnClick(f.formHandler)),
)
Expand Down Expand Up @@ -152,20 +154,31 @@ func (i *index) OnClick(_ app.Context, _ app.Event) {
type checkBox struct {
app.Compo

checkHandler app.EventHandler
checkHandlerComment app.EventHandler
checkHandlerMinimal app.EventHandler
}

func (c *checkBox) Render() app.UI {
return app.Div().Class("form-check").Body(
app.Label().Class("form-check-label").For("enable-comments").Body(app.Text("Enable comments on YAML output")),
app.Input().Class("form-check-input").Type("checkbox").ID("enable-comments").OnClick(c.checkHandler),
return app.Div().Body(
app.Div().Class("form-check").Body(
app.Label().Class("form-check-label").For("enable-comments").Body(app.Text("Enable comments on YAML output")),
app.Input().Class("form-check-input").Type("checkbox").ID("enable-comments").OnClick(c.checkHandlerComment),
),
app.Div().Class("form-check").Body(
app.Label().Class("form-check-label").For("enable-minimal").Body(app.Text("Enable minimal required YAML output")),
app.Input().Class("form-check-input").Type("checkbox").ID("enable-minimal").OnClick(c.checkHandlerMinimal),
),
)
}

func (i *index) OnCheck(_ app.Context, _ app.Event) {
func (i *index) OnCheckComment(_ app.Context, _ app.Event) {
i.comments = !i.comments
}

func (i *index) OnCheckMinimal(_ app.Context, _ app.Event) {
i.minimal = !i.minimal
}

func (i *index) OnMount(_ app.Context) {
i.isMounted = true
}
Expand All @@ -179,10 +192,10 @@ func (i *index) Render() app.UI {
}

if i.content != nil {
return &crdView{content: i.content, comment: i.comments}
return &crdView{content: i.content, comment: i.comments, minimal: i.minimal}
}

return app.Div().Class("container").Body(&header{}, &form{formHandler: i.OnClick, checkHandler: i.OnCheck})
return app.Div().Class("container").Body(&header{}, &form{formHandler: i.OnClick, checkHandlerComment: i.OnCheckComment, checkHandlerMinimal: i.OnCheckMinimal})
}()))
}

Expand Down
18 changes: 9 additions & 9 deletions wasm/index.html
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
<!DOCTYPE html>
<html data-bs-core="modern" data-bs-theme="dark" lang="en">
<html data-bs-theme="dark" lang="en" data-bs-core="modern">
<head>
<meta charset="UTF-8">
<meta name="author" content="Gergely Brautigam">
<meta name="description" content>
<meta name="theme-color" content="#2d2c2c">
<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0, viewport-fit=cover" name="viewport">
<meta content="https://" property="og:url">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0, viewport-fit=cover">
<meta property="og:url" content="https://">
<meta property="og:title" content="Preview CRDs">
<meta property="og:description" content>
<meta property="og:type" content="website">
<meta content="https://" property="og:image">
<meta property="og:image" content="https://">
<title>Preview CRDs</title>
<link rel="preload" as="style" href="/app.css" type="text/css">
<link as="style" href="/web/css/alert.css" type="text/css" rel="preload">
<link href="/web/css/alert.css" type="text/css" rel="preload" as="style">
<link href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/themes/prism-twilight.min.css" type="text/css" rel="preload" as="style">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/css/halfmoon.min.css" type="text/css" rel="preload" as="style">
<link rel="preload" as="style" href="https://cdn.jsdelivr.net/npm/[email protected]/css/halfmoon.min.css" type="text/css">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/css/cores/halfmoon.modern.css" type="text/css" rel="preload" as="style">
<link as="style" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" type="text/css" rel="preload">
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" type="text/css" rel="preload" as="style">
<link rel="icon" href="https://raw.githubusercontent.com/maxence-charriere/go-app/master/docs/web/icon.svg">
<link rel="apple-touch-icon" href="/web/img/logo.png">
<link rel="manifest" href="/manifest.webmanifest">
<link href="/app.css" type="text/css" rel="stylesheet">
<link rel="stylesheet" href="/app.css" type="text/css">
<link href="/web/css/alert.css" type="text/css" rel="stylesheet">
<link href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/themes/prism-twilight.min.css" type="text/css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/css/halfmoon.min.css" type="text/css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/css/cores/halfmoon.modern.css" type="text/css" rel="stylesheet">
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" type="text/css" rel="stylesheet">
<script defer src="/wasm_exec.js"></script>
<script src="/app.js" defer></script>
<script defer src="/app.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.11/clipboard.min.js"></script>
<meta charset="utf-8">
Expand Down
2 changes: 1 addition & 1 deletion wasm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func main() {
Name: "Preview CRDs",
Title: "Preview CRDs",
Author: "Gergely Brautigam",
Version: "v0.6.4",
Version: "v0.6.5",
HTML: func() app.HTMLHtml {
return app.Html().DataSet("bs-core", "modern").DataSet("bs-theme", "dark")
},
Expand Down
18 changes: 9 additions & 9 deletions wasm/share.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,30 @@
<meta charset="UTF-8">
<meta name="author" content="Gergely Brautigam">
<meta name="description" content>
<meta content="#2d2c2c" name="theme-color">
<meta name="theme-color" content="#2d2c2c">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0, viewport-fit=cover">
<meta property="og:url" content="https:///share">
<meta property="og:title" content="Preview CRDs">
<meta property="og:description" content>
<meta content property="og:description">
<meta property="og:type" content="website">
<meta property="og:image" content="https://">
<title>Preview CRDs</title>
<link href="/app.css" type="text/css" rel="preload" as="style">
<link href="/web/css/alert.css" type="text/css" rel="preload" as="style">
<link as="style" href="/web/css/alert.css" type="text/css" rel="preload">
<link href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/themes/prism-twilight.min.css" type="text/css" rel="preload" as="style">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/css/halfmoon.min.css" type="text/css" rel="preload" as="style">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/css/cores/halfmoon.modern.css" type="text/css" rel="preload" as="style">
<link rel="preload" as="style" href="https://cdn.jsdelivr.net/npm/[email protected]/css/halfmoon.min.css" type="text/css">
<link as="style" href="https://cdn.jsdelivr.net/npm/[email protected]/css/cores/halfmoon.modern.css" type="text/css" rel="preload">
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" type="text/css" rel="preload" as="style">
<link rel="icon" href="https://raw.githubusercontent.com/maxence-charriere/go-app/master/docs/web/icon.svg">
<link rel="apple-touch-icon" href="/web/img/logo.png">
<link rel="manifest" href="/manifest.webmanifest">
<link rel="stylesheet" href="/app.css" type="text/css">
<link rel="stylesheet" href="/web/css/alert.css" type="text/css">
<link href="/app.css" type="text/css" rel="stylesheet">
<link href="/web/css/alert.css" type="text/css" rel="stylesheet">
<link href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/themes/prism-twilight.min.css" type="text/css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/css/halfmoon.min.css" type="text/css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/css/cores/halfmoon.modern.css" type="text/css" rel="stylesheet">
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" type="text/css" rel="stylesheet">
<script defer src="/wasm_exec.js"></script>
<script src="/wasm_exec.js" defer></script>
<script defer src="/app.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.11/clipboard.min.js"></script>
Expand Down Expand Up @@ -67,7 +67,7 @@ <h4 class="alert-heading">Oops!</h4>
url parameter has to be define in the following format: /share?url=https://example.com/crd.yaml
</div>
<aside id="app-wasm-loader" class="goapp-app-info">
<img class="goapp-logo goapp-spin" alt="wasm loader icon" src="/web/img/logo.png" id="app-wasm-loader-icon">
<img id="app-wasm-loader-icon" class="goapp-logo goapp-spin" alt="wasm loader icon" src="/web/img/logo.png">
<p id="app-wasm-loader-label" class="goapp-label">0%</p>
</aside>
</body>
Expand Down
Binary file modified wasm/web/app.wasm
Binary file not shown.

0 comments on commit ba36935

Please sign in to comment.