Skip to content

Commit 85279ef

Browse files
committed
fix a bug with export and move apply btn
Signed-off-by: Doug Davis <[email protected]>
1 parent 1b5b19e commit 85279ef

File tree

3 files changed

+46
-29
lines changed

3 files changed

+46
-29
lines changed

Makefile

+15-11
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,18 @@ MAKEFLAGS += --no-print-directory
55
# Notes:
66
# export VERBOSE=[0-9]
77
# Override these env vars as needed:
8-
DBHOST ?= 127.0.0.1
9-
DBPORT ?= 3306
10-
DBUSER ?= root
11-
DBPASSWORD ?= password
12-
IMAGE ?= duglin/xreg-server
13-
XR_SPEC ?= $(HOME)/go/src/github.com/xregistry/spec
14-
GIT_COMMIT ?= $(shell git rev-list -1 HEAD)
15-
BUILDFLAGS := -ldflags -X=main.GitCommit=$(GIT_COMMIT)
8+
# DOCKERHUB must end with /, if it's set at all
9+
export GIT_ORG ?= duglin
10+
export GIT_REPO ?= $(shell basename `git rev-parse --show-toplevel`)
11+
export DOCKERHUB ?=
12+
export DBHOST ?= 127.0.0.1
13+
export DBPORT ?= 3306
14+
export DBUSER ?= root
15+
export DBPASSWORD ?= password
16+
export IMAGE ?= $(DOCKERHUB)xreg-server
17+
export XR_SPEC ?= $(HOME)/go/src/github.com/xregistry/spec
18+
export GIT_COMMIT ?= $(shell git rev-list -1 HEAD)
19+
export BUILDFLAGS := -ldflags -X=main.GitCommit=$(GIT_COMMIT)
1620

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

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

203207
clean:

registry/entity.go

+8-3
Original file line numberDiff line numberDiff line change
@@ -1012,7 +1012,9 @@ var OrderedSpecProps = []*Attribute{
10121012
}
10131013

10141014
if e.Type == ENTITY_RESOURCE || e.Type == ENTITY_VERSION {
1015-
meta := info != nil && (info.ShowStructure || info.ResourceUID == "" || len(info.Parts) == 5)
1015+
meta := info != nil && (info.ShowStructure ||
1016+
info.HasFlag("export") ||
1017+
info.ResourceUID == "" || len(info.Parts) == 5)
10161018
_, rm := e.GetModels()
10171019
if rm.GetHasDocument() == false {
10181020
meta = false
@@ -1045,7 +1047,9 @@ var OrderedSpecProps = []*Attribute{
10451047
base = info.BaseURL
10461048
}
10471049
if e.Type == ENTITY_RESOURCE || e.Type == ENTITY_VERSION {
1048-
meta := info != nil && (info.ShowStructure || info.ResourceUID == "" || len(info.Parts) == 5)
1050+
meta := info != nil && (info.ShowStructure ||
1051+
info.HasFlag("export") ||
1052+
info.ResourceUID == "" || len(info.Parts) == 5)
10491053
_, rm := e.GetModels()
10501054
if rm.GetHasDocument() == false {
10511055
meta = false
@@ -1451,7 +1455,8 @@ var OrderedSpecProps = []*Attribute{
14511455

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

1454-
meta := info != nil && (info.ShowStructure || info.ResourceUID == "")
1458+
meta := info != nil && (info.ShowStructure ||
1459+
info.HasFlag("export") || info.ResourceUID == "")
14551460
_, rm := e.GetModels()
14561461
if rm.GetHasDocument() == false {
14571462
meta = false

registry/httpStuff.go

+23-15
Original file line numberDiff line numberDiff line change
@@ -356,8 +356,8 @@ func (pw *PageWriter) Done() {
356356
if pw.Info.RootPath == r.u {
357357
name = "<b>" + name + "</b>"
358358
}
359-
roots += fmt.Sprintf(" <li><a href=\"%s?ui\">%s</a>\n",
360-
pw.Info.BaseURL+"/"+r.u+"</li>", name)
359+
roots += fmt.Sprintf(" <li><a href=\"%s?ui\">%s</a></li>\n",
360+
pw.Info.BaseURL+"/"+r.u, name)
361361
}
362362

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

535536
apply = `
536-
<hr style="width:100%% ; margin-top:15px ; margin-bottom:15px">
537-
<div style="display:ruby">
538-
<button onclick="apply()" style="font-weight:bold">Apply</button>` +
539-
structureButton + `
540-
</div>`
537+
` + structureButton
538+
}
539+
540+
applyBtn := ""
541+
if options != "" || filters != "" || inlines != "" {
542+
applyBtn = "<button id=applyBtn onclick='apply()'>Apply</button>"
541543
}
542544

543545
pw.OldWriter.Write([]byte(fmt.Sprintf(`<html>
@@ -592,6 +594,7 @@ func (pw *PageWriter) Done() {
592594
display: flex ;
593595
flex-direction: column ;
594596
align-items: start ;
597+
margin-top: -15 ;
595598
}
596599
#buttonBar {
597600
background-color: lightsteelblue;
@@ -602,8 +605,17 @@ func (pw *PageWriter) Done() {
602605
}
603606
#structure {
604607
display: inline ;
608+
margin-top: 10px ;
605609
margin-bottom: 10px ;
606610
}
611+
612+
#applyBtn {
613+
font-weight: bold ;
614+
align-self: end ;
615+
position: relative ;
616+
top: 20 ;
617+
}
618+
607619
#commit {
608620
background-color: lightsteelblue ;
609621
font-size: 12px ;
@@ -727,6 +739,7 @@ func (pw *PageWriter) Done() {
727739
<hr>
728740
`+roots+`
729741
<div id=buttonList>
742+
`+applyBtn+`
730743
`+options+`
731744
`+filters+`
732745
`+inlines+`
@@ -1171,16 +1184,11 @@ func HTTPGet(info *RequestInfo) error {
11711184
return SerializeQuery(info, nil, "Registry", info.Filters)
11721185
}
11731186

1174-
// Might need to check other flags, but if we're exporting, it makes
1175-
// no sense to show just the resource contents
1176-
if info.HasFlag("export") {
1177-
info.ShowStructure = true
1178-
}
1179-
11801187
// 'metaInBody' tells us whether xReg metadata should be in the http
11811188
// response body or not (meaning, the hasDoc doc)
11821189
metaInBody := (info.ResourceModel == nil) ||
11831190
(info.ResourceModel.GetHasDocument() == false || info.ShowStructure ||
1191+
info.HasFlag("export") ||
11841192
(len(info.Parts) == 5 && info.Parts[4] == "meta"))
11851193

11861194
// Return the Resource's document

0 commit comments

Comments
 (0)