aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix Hanley <felix@userspace.com.au>2020-03-13 02:27:46 +0000
committerFelix Hanley <felix@userspace.com.au>2020-03-13 02:27:46 +0000
commite345d142136c1416e73dc0f5dc9993af785d845b (patch)
treee3d8de2b02ca1d5f769cd76c002b62bbaa0de42a
parentcf612c764090581f840baef20f1d3a42ae48ebcd (diff)
downloadsws-e345d142136c1416e73dc0f5dc9993af785d845b.tar.gz
sws-e345d142136c1416e73dc0f5dc9993af785d845b.tar.bz2
Trial alternative menu
-rw-r--r--Makefile4
-rw-r--r--cmd/server/hits.go1
-rw-r--r--cmd/server/routes.go13
-rw-r--r--counter/sws.js4
-rw-r--r--hit.go2
-rw-r--r--static/default.css41
-rw-r--r--tmpl/404.tmpl5
-rw-r--r--tmpl/layout.tmpl34
-rw-r--r--tmpl/layouts/base.tmpl22
-rw-r--r--tmpl/layouts/public.tmpl16
-rw-r--r--tmpl/navbar.tmpl12
-rw-r--r--tmpl/site.tmpl6
12 files changed, 88 insertions, 72 deletions
diff --git a/Makefile b/Makefile
index 6d44224..7497c48 100644
--- a/Makefile
+++ b/Makefile
@@ -23,9 +23,9 @@ cmd/server/migrations.go: $(SQL)
go generate ./sql >$@
cmd/server/counter.go: counter/sws.min.js
- printf "package main\n\nconst counter = \`" >$@
+ printf "package main\n\nfunc getCounter() string { return \`" >$@
cat $< >>$@
- printf "\`\n" >>$@
+ printf "\`}\n" >>$@
%.min.js: %.js node_modules
yarn run -s uglifyjs -c -m -o $@ $<
diff --git a/cmd/server/hits.go b/cmd/server/hits.go
index 36a1e83..a1f07e3 100644
--- a/cmd/server/hits.go
+++ b/cmd/server/hits.go
@@ -61,6 +61,7 @@ func handleHitCounter(db sws.CounterStore) http.HandlerFunc {
}
func handleCounter(addr string) http.HandlerFunc {
+ counter := getCounter()
tmpl, err := template.New("counter").Parse(counter)
if err != nil || tmpl == nil {
panic(err)
diff --git a/cmd/server/routes.go b/cmd/server/routes.go
index 1828664..7ac147f 100644
--- a/cmd/server/routes.go
+++ b/cmd/server/routes.go
@@ -24,8 +24,8 @@ func init() {
func createRouter(db sws.Store) (chi.Router, error) {
tmplsCommon := []string{"flash.tmpl", "navbar.tmpl"}
- tmplsAuthed := append(tmplsCommon, []string{"layouts/base.tmpl", "charts.tmpl", "timerange.tmpl"}...)
- tmplsPublic := append(tmplsCommon, "layouts/public.tmpl")
+ tmplsAuthed := append(tmplsCommon, []string{"layout.tmpl", "charts.tmpl", "timerange.tmpl"}...)
+ tmplsPublic := append(tmplsCommon, "layout.tmpl")
if override != "" {
log("using overrider", override)
@@ -40,6 +40,7 @@ func createRouter(db sws.Store) (chi.Router, error) {
"home": append([]string{"home.tmpl"}, tmplsPublic...),
"login": append([]string{"login.tmpl"}, tmplsPublic...),
"user": append([]string{"user.tmpl"}, tmplsAuthed...),
+ "404": append([]string{"404.tmpl"}, tmplsPublic...),
"example": []string{"example.tmpl"},
}, funcMap)
if err != nil {
@@ -137,6 +138,14 @@ func createRouter(db sws.Store) (chi.Router, error) {
})
})
+ r.NotFound(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ payload := newTemplateData(r)
+ if err := rndr.Render(w, "404", payload); err != nil {
+ httpError(w, 500, err.Error())
+ return
+ }
+ }))
+
// Example
r.Get("/test.html", handleExample(rndr))
return r, nil
diff --git a/counter/sws.js b/counter/sws.js
index 5145cee..5011b9a 100644
--- a/counter/sws.js
+++ b/counter/sws.js
@@ -8,7 +8,7 @@ var me = d.currentScript
var _sws = w._sws || {noauto: false, local: false}
_sws.d = _sws.d || me.src
-_sws.site = _sws.site || me.dataset.site
+_sws.id = _sws.id || me.dataset.id
function count (p, obj) {
if (!_sws.local && l.hostname.match(/(localhost$|^127\.|^10\.|^172\.16\.|^192\.168\.)/))
@@ -47,7 +47,7 @@ ready(function () {
if (!_sws.noauto) {
var ep = new URL(_sws.d)
count('{{ .Endpoint }}', {
- i: _sws.site,
+ id: _sws.id,
s: l.protocol,
h: l.host,
p: l.pathname,
diff --git a/hit.go b/hit.go
index 4e19307..4cf1a49 100644
--- a/hit.go
+++ b/hit.go
@@ -66,7 +66,7 @@ func HitFromRequest(r *http.Request) (*Hit, error) {
}
q := r.URL.Query()
- siteIDs := q.Get("i")
+ siteIDs := q.Get("id")
if siteIDs == "" {
if siteIDs = q.Get("site"); siteIDs == "" {
return nil, fmt.Errorf("missing site")
diff --git a/static/default.css b/static/default.css
index 8fd486a..7e456f5 100644
--- a/static/default.css
+++ b/static/default.css
@@ -18,39 +18,40 @@ ul {
list-style: none;
padding: 0;
}
-.page {
- display: flex;
- flex-direction: column;
- outline: 1px solid red;
-}
-.sidebar {
- background-color: #2A3F54;
- flex: 0 0 13em;
- order: -1;
- outline: 1px solid green;
-}
.navbar {
+ align-items: center;
background: #ededed;
border-bottom: 1px solid #d9dee4;
+ display: flex;
height: 2.5em;
+ justify-content: flex-end;
}
-
-.sitenav {
+.nav {
+ display: flex;
+ justify-content: left;
}
-.sitenav__link {
- color: #e7e7e7;
+.nav__link {
display: block;
font-weight: 500;
text-decoration: none;
+ text-transform: lowercase;
padding: 13px 15px 12px;
}
+.nav__link:first-child {
+ flex: 1;
+}
+.nav__link--close {
+}
+.nav__link--logo {
+ flex: 1;
+}
+
main {
background-color: #f7f7f7;
flex: 1;
- outline: 1px solid red;
- padding-left: 1em;
- padding-right: 1em;
+ padding-left: 16px;
+ padding-right: 16px;
position: relative;
}
@@ -62,7 +63,7 @@ main {
main {
flex: 1;
}
- .sidebar {
+ .navmain {
/* 12em is the width of the columns */
flex: 0 0 12em;
}
@@ -140,7 +141,7 @@ main {
position: absolute;
right: 0;
text-align: center;
- top: 50px;
+ top: 0;
transition: opacity 3s ease-in-out;
}
diff --git a/tmpl/404.tmpl b/tmpl/404.tmpl
new file mode 100644
index 0000000..0d025b0
--- /dev/null
+++ b/tmpl/404.tmpl
@@ -0,0 +1,5 @@
+{{ define "content" }}
+ <main>
+ <p>Not found</p>
+ </main>
+{{ end }}
diff --git a/tmpl/layout.tmpl b/tmpl/layout.tmpl
new file mode 100644
index 0000000..af0630c
--- /dev/null
+++ b/tmpl/layout.tmpl
@@ -0,0 +1,34 @@
+<!DOCTYPE html>
+<html lang="en-au">
+ <head>
+ <meta name="viewport" content="width=device-width, initial-scale=1">
+ <title>Simple Web Stats</title>
+ <link rel="stylesheet" href="/default.css">
+ </head>
+ <body>
+ {{ template "navbar" . }}
+ <header class="mainnav">
+ {{ if .Site }}
+ <nav class="nav nav--site">
+ <span class="nav__link nav__link--name">{{ .Site.Name }}</span>
+ {{ if .Site.ID }}
+ <a class="nav__link" href="/sites/{{ .Site.ID }}">Summary</a>
+ <a class="nav__link" href="/sites/{{ .Site.ID }}/pages">Pages</a>
+ <a class="nav__link" href="/sites/{{ .Site.ID }}/browsers">Browsers</a>
+ <a class="nav__link" href="/sites/{{ .Site.ID }}/locations">Locations</a>
+ <a class="nav__link" href="/sites/{{ .Site.ID }}/edit">Configure</a>
+ {{ end }}
+ <a class="nav__link nav__link--close" href="/sites/">&times;</a>
+ </nav>
+ {{ else }}
+ <nav class="nav nav--sites">
+ <a class="nav__link" href="/sites">Sites</a>
+ <a class="nav__link" href="/sites/new"><i class="plus">&#43;</i> New site</a>
+ </nav>
+ {{ end }}
+ </header>
+ {{ template "flash" . }}
+ {{ template "content" . }}
+ <footer></footer>
+ </body>
+</html>
diff --git a/tmpl/layouts/base.tmpl b/tmpl/layouts/base.tmpl
deleted file mode 100644
index 13f5247..0000000
--- a/tmpl/layouts/base.tmpl
+++ /dev/null
@@ -1,22 +0,0 @@
-<!DOCTYPE html>
-<html lang="en-au">
- <head>
- <meta name="viewport" content="width=device-width, initial-scale=1">
- <title>Simple Web Stats</title>
- <link rel="stylesheet" href="/default.css">
- </head>
- <body>
- {{ template "navbar" . }}
- <div class="page">
- <div class="sidebar">
- <nav>
- <a class="sitenav__link" href="/sites">Sites</a>
- <a class="sitenav__link" href="/sites/new">New site</a>
- </nav>
- </div>
- {{ template "flash" . }}
- {{ template "content" . }}
- </div>
- <footer></footer>
- </body>
-</html>
diff --git a/tmpl/layouts/public.tmpl b/tmpl/layouts/public.tmpl
deleted file mode 100644
index eb3e64a..0000000
--- a/tmpl/layouts/public.tmpl
+++ /dev/null
@@ -1,16 +0,0 @@
-<!DOCTYPE html>
-<html lang="en-au">
- <head>
- <meta name="viewport" content="width=device-width, initial-scale=1">
- <title>Simple Web Stats</title>
- <link rel="stylesheet" href="/default.css">
- </head>
- <body>
- {{ template "navbar" . }}
- <div class="page">
- {{ template "flash" . }}
- {{ template "content" . }}
- </div>
- <footer></footer>
- </body>
-</html>
diff --git a/tmpl/navbar.tmpl b/tmpl/navbar.tmpl
index a67d0a3..1b6230c 100644
--- a/tmpl/navbar.tmpl
+++ b/tmpl/navbar.tmpl
@@ -1,11 +1,11 @@
{{ define "navbar" }}
- <header class="navbar">
- <a class="logo" href="/">Logo</a>
+ <nav class="nav navbar">
+ <a class="nav__link nav__link--logo" href="/">Logo</a>
{{ if .User }}
- <a href="/sites">Sites</a>
- <a class="logout" href="/logout">Logout</a>
+ <a class="nav__link" href="/sites">Sites</a>
+ <a class="nav__link nav__link--logout" href="/logout">Logout</a>
{{ else }}
- <a class="login" href="/login">Login</a>
+ <a class="nav__link nav__link--login" href="/login">Login</a>
{{ end }}
- </header>
+ </nav>
{{ end }}
diff --git a/tmpl/site.tmpl b/tmpl/site.tmpl
index 0762b2b..722bb61 100644
--- a/tmpl/site.tmpl
+++ b/tmpl/site.tmpl
@@ -25,7 +25,9 @@
<input type="submit" />
</div>
</form>
- {{ template "siteConfig" . }}
+ {{ if .Site.ID }}
+ {{ template "siteConfig" . }}
+ {{ end }}
{{ end }}
</main>
{{ end }}
@@ -78,6 +80,7 @@
{{ template "barChartHorizontal" .PageSet }}
</fig>
+ <!--
<ul class="pages">
{{ $pages := .PageSet }}
{{ range .PageSet }}
@@ -88,6 +91,7 @@
</fig>
{{ end }}
</ul>
+ -->
{{ else }}
<p>No page views yet</p>
{{ end }}