Skip to content

Commit

Permalink
fix a bug with export and move apply btn
Browse files Browse the repository at this point in the history
Signed-off-by: Doug Davis <[email protected]>
  • Loading branch information
duglin committed Jan 13, 2025
1 parent 1b5b19e commit 85279ef
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 29 deletions.
26 changes: 15 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@ MAKEFLAGS += --no-print-directory
# Notes:
# export VERBOSE=[0-9]
# Override these env vars as needed:
DBHOST ?= 127.0.0.1
DBPORT ?= 3306
DBUSER ?= root
DBPASSWORD ?= password
IMAGE ?= duglin/xreg-server
XR_SPEC ?= $(HOME)/go/src/github.com/xregistry/spec
GIT_COMMIT ?= $(shell git rev-list -1 HEAD)
BUILDFLAGS := -ldflags -X=main.GitCommit=$(GIT_COMMIT)
# DOCKERHUB must end with /, if it's set at all
export GIT_ORG ?= duglin
export GIT_REPO ?= $(shell basename `git rev-parse --show-toplevel`)
export DOCKERHUB ?=
export DBHOST ?= 127.0.0.1
export DBPORT ?= 3306
export DBUSER ?= root
export DBPASSWORD ?= password
export IMAGE ?= $(DOCKERHUB)xreg-server
export XR_SPEC ?= $(HOME)/go/src/github.com/xregistry/spec
export GIT_COMMIT ?= $(shell git rev-list -1 HEAD)
export BUILDFLAGS := -ldflags -X=main.GitCommit=$(GIT_COMMIT)

TESTDIRS := $(shell find . -name *_test.go -exec dirname {} \; | sort -u)
UTESTDIRS := $(shell find . -path ./tests -prune -o -name *_test.go -exec dirname {} \; | sort -u)
Expand Down Expand Up @@ -177,7 +181,7 @@ prof: server
@# May need to install: apt-get install graphviz
NO_DELETE_REGISTRY=1 \
go test -cpuprofile cpu.prof -memprofile mem.prof -bench . \
github.com/duglin/xreg-github/tests
github.com/$(GIT_ORG)/$(GIT_REPO)/tests
@# go tool pprof -http:0.0.0.0:9999 cpu.prof
@go tool pprof -top -cum cpu.prof | sed -n '0,/flat/p;/xreg/p' | more
@rm -f cpu.prof mem.prof tests.test
Expand All @@ -186,7 +190,7 @@ devimage:
@# See the misc/Dockerfile-dev for more info
@echo
@echo "# Build the dev image"
@misc/errOutput docker build -t duglin/xreg-dev --no-cache \
@misc/errOutput docker build -t $(DOCKERHUB)xreg-dev --no-cache \
--build-arg GIT_COMMIT=$(GIT_COMMIT) -f misc/Dockerfile-dev .

testdev: devimage
Expand All @@ -197,7 +201,7 @@ testdev: devimage
@echo
@echo "## Build, test and run the server all within the dev image"
docker run -ti -v /var/run/docker.sock:/var/run/docker.sock \
-e VERIFY=--verify --network host duglin/xreg-dev make clean all
-e VERIFY=--verify --network host $(DOCKERHUB)xreg-dev make clean all
@echo "## Done! Exit the dev image testing"

clean:
Expand Down
11 changes: 8 additions & 3 deletions registry/entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -1012,7 +1012,9 @@ var OrderedSpecProps = []*Attribute{
}

if e.Type == ENTITY_RESOURCE || e.Type == ENTITY_VERSION {
meta := info != nil && (info.ShowStructure || info.ResourceUID == "" || len(info.Parts) == 5)
meta := info != nil && (info.ShowStructure ||
info.HasFlag("export") ||
info.ResourceUID == "" || len(info.Parts) == 5)
_, rm := e.GetModels()
if rm.GetHasDocument() == false {
meta = false
Expand Down Expand Up @@ -1045,7 +1047,9 @@ var OrderedSpecProps = []*Attribute{
base = info.BaseURL
}
if e.Type == ENTITY_RESOURCE || e.Type == ENTITY_VERSION {
meta := info != nil && (info.ShowStructure || info.ResourceUID == "" || len(info.Parts) == 5)
meta := info != nil && (info.ShowStructure ||
info.HasFlag("export") ||
info.ResourceUID == "" || len(info.Parts) == 5)
_, rm := e.GetModels()
if rm.GetHasDocument() == false {
meta = false
Expand Down Expand Up @@ -1451,7 +1455,8 @@ var OrderedSpecProps = []*Attribute{

tmp := base + "/" + rPath + "/versions/" + val.(string)

meta := info != nil && (info.ShowStructure || info.ResourceUID == "")
meta := info != nil && (info.ShowStructure ||
info.HasFlag("export") || info.ResourceUID == "")
_, rm := e.GetModels()
if rm.GetHasDocument() == false {
meta = false
Expand Down
38 changes: 23 additions & 15 deletions registry/httpStuff.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,8 @@ func (pw *PageWriter) Done() {
if pw.Info.RootPath == r.u {
name = "<b>" + name + "</b>"
}
roots += fmt.Sprintf(" <li><a href=\"%s?ui\">%s</a>\n",
pw.Info.BaseURL+"/"+r.u+"</li>", name)
roots += fmt.Sprintf(" <li><a href=\"%s?ui\">%s</a></li>\n",
pw.Info.BaseURL+"/"+r.u, name)
}

if pw.Info.RootPath == "" {
Expand Down Expand Up @@ -527,17 +527,19 @@ func (pw *PageWriter) Done() {
structuretext = "Show structure"
}
if pw.Info.ResourceUID != "" && pw.Info.What == "Entity" {
structureButton = fmt.Sprintf(`
<div><button id=structure onclick='structureswitch=!structureswitch ; apply()' style="font-weight:bold">%s</button></div>
structureButton = fmt.Sprintf(`<div>
<button id=structure onclick='structureswitch=!structureswitch ; apply()' style="font-weight:bold">%s</button>
</div>
`, structuretext)
}

apply = `
<hr style="width:100%% ; margin-top:15px ; margin-bottom:15px">
<div style="display:ruby">
<button onclick="apply()" style="font-weight:bold">Apply</button>` +
structureButton + `
</div>`
` + structureButton
}

applyBtn := ""
if options != "" || filters != "" || inlines != "" {
applyBtn = "<button id=applyBtn onclick='apply()'>Apply</button>"
}

pw.OldWriter.Write([]byte(fmt.Sprintf(`<html>
Expand Down Expand Up @@ -592,6 +594,7 @@ func (pw *PageWriter) Done() {
display: flex ;
flex-direction: column ;
align-items: start ;
margin-top: -15 ;
}
#buttonBar {
background-color: lightsteelblue;
Expand All @@ -602,8 +605,17 @@ func (pw *PageWriter) Done() {
}
#structure {
display: inline ;
margin-top: 10px ;
margin-bottom: 10px ;
}
#applyBtn {
font-weight: bold ;
align-self: end ;
position: relative ;
top: 20 ;
}
#commit {
background-color: lightsteelblue ;
font-size: 12px ;
Expand Down Expand Up @@ -727,6 +739,7 @@ func (pw *PageWriter) Done() {
<hr>
`+roots+`
<div id=buttonList>
`+applyBtn+`
`+options+`
`+filters+`
`+inlines+`
Expand Down Expand Up @@ -1171,16 +1184,11 @@ func HTTPGet(info *RequestInfo) error {
return SerializeQuery(info, nil, "Registry", info.Filters)
}

// Might need to check other flags, but if we're exporting, it makes
// no sense to show just the resource contents
if info.HasFlag("export") {
info.ShowStructure = true
}

// 'metaInBody' tells us whether xReg metadata should be in the http
// response body or not (meaning, the hasDoc doc)
metaInBody := (info.ResourceModel == nil) ||
(info.ResourceModel.GetHasDocument() == false || info.ShowStructure ||
info.HasFlag("export") ||
(len(info.Parts) == 5 && info.Parts[4] == "meta"))

// Return the Resource's document
Expand Down

0 comments on commit 85279ef

Please sign in to comment.