commit 00f0dc21975e7103bc46f8a29e22c29706d357b0
parent 403e7a723f3dfc55ae926d8b2bb4927ab5ffd747
Author: Peter Kosyh <p.kosyh@gmail.com>
Date: Fri, 4 Sep 2020 19:26:43 +0300
Error template
Diffstat:
7 files changed, 56 insertions(+), 22 deletions(-)
diff --git a/ii-node/lib/style.css b/ii-node/lib/style.css
@@ -35,7 +35,7 @@
text-decoration: none;
}
-#echolist, #topiclist, #profile, #login {
+#echolist, #topiclist, #profile, #login, #error {
margin: 0;
margin-left:auto;
margin-right:auto;
@@ -81,7 +81,14 @@
padding: 0;
margin: 0;
}
-#echolist .even {
+.alert {
+ background: #ea5555;
+ color: white;
+ font-weight: bold;
+ text-align: center;
+}
+
+.even {
background: #ffffea;
}
@@ -160,12 +167,11 @@
font-style: italic;
margin-top: 1em;
}
-#profile td, #login td{
+#profile td, #login td, #error td {
padding: 0.5em;
}
-#profile .links, #login .links {
+#profile .links, #login .links, #error .links {
text-align: center;
- margin: 10pt;
}
@media (max-width: 640px) {
.extra {
diff --git a/ii-node/main.go b/ii-node/main.go
@@ -57,11 +57,6 @@ type WWW struct {
db *ii.DB
}
-func handleErr(www WWW, w http.ResponseWriter, err error) {
- ctx := WebContext{ Error: err.Error() }
- www.tpl.ExecuteTemplate(w, "error.tpl", ctx)
-}
-
func main() {
var www WWW
ii.OpenLog(ioutil.Discard, os.Stdout, os.Stderr)
@@ -81,10 +76,7 @@ func main() {
http.Handle("/lib/", http.StripPrefix("/lib/", fs))
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
- err := handleWWW(www, w, r)
- if err != nil {
- handleErr(www, w, err)
- }
+ handleWWW(www, w, r)
})
http.HandleFunc("/list.txt", func(w http.ResponseWriter, r *http.Request) {
echoes := db.Echoes(nil)
diff --git a/ii-node/tpl/error.tpl b/ii-node/tpl/error.tpl
@@ -1,3 +1,9 @@
{{template "header.tpl" $}}
-{{.Error}}
+
+<table id="error" cellspacing=0 cellpadding=0>
+<tr class="alert"><td>Error!</td></tr>
+<tr class="even"><td>{{.Error}}</td></tr>
+<tr class="odd"><td class="links"><a href="/">Ok</a></td></tr>
+</table>
+
{{template "footer.tpl"}}
diff --git a/ii-node/tpl/header.tpl b/ii-node/tpl/header.tpl
@@ -14,7 +14,7 @@
<tr>
<td class="title">
<span class="logo"><a href="/">ii-go</a></span>
- <span class="info">II/IDEC networks {{ with .Echo }} :: {{.}}{{end}}
+ <span class="info">II/IDEC networks {{ with .Echo }} :: <a href="/{{.}}">{{.}}</a>{{end}}
</span>
</td>
<td class="links">
diff --git a/ii-node/tpl/login.tpl b/ii-node/tpl/login.tpl
@@ -11,7 +11,7 @@
<input type="password" name="password" class="passwd" placeholder="password">
</td></tr>
-<tr><td class="links odd" colspan="2">
+<tr class="odd"><td class="links" colspan="2">
<button>Login</button>
</td></tr>
diff --git a/ii-node/tpl/register.tpl b/ii-node/tpl/register.tpl
@@ -1,8 +1,24 @@
-{{template "header.tpl"}}
+{{template "header.tpl" $}}
<form method="post" enctype="application/x-www-form-urlencoded" action="/register">
+<table id="login" cellspacing=0 cellpadding=0>
+
+<tr class="odd"><td>
<input type="text" name="username" class="login" placeholder="username"><br>
+</td></tr>
+
+<tr class="even"><td>
<input type="password" name="password" class="passwd" placeholder="password"><br>
-<input type="text" name="email" class="email" placeholder="email"><br>
-<button class="form-button">Submit</button>
+</td></tr>
+
+<tr><td class="odd">
+<input type="text" name="email" class="email" placeholder="email">
+</td></tr>
+
+<tr class="even"><td class="links" colspan="2">
+<button class="form-button">Register</button>
+</td></tr>
+
+</table>
+
</form>
{{template "footer.tpl"}}
diff --git a/ii-node/web.go b/ii-node/web.go
@@ -11,6 +11,8 @@ import (
"time"
)
+const PAGE_SIZE = 100
+
type WebContext struct {
Echoes []*ii.Echo
Topics []*Topic
@@ -172,7 +174,6 @@ type Topic struct {
Tail *ii.Msg
}
-const PAGE_SIZE = 100
func makePager(ctx *WebContext, count int, page int) int {
ctx.Pages = count / PAGE_SIZE
if count % PAGE_SIZE != 0 {
@@ -253,6 +254,7 @@ func www_topic(user *ii.User, www WWW, w http.ResponseWriter, r *http.Request, i
if mi == nil {
return errors.New("No such message")
}
+ ctx.Echo = mi.Echo
mis := db.LookupIDS(db.SelectIDS(ii.Query{Echo: mi.Echo}))
topic := mi.Id
@@ -410,8 +412,20 @@ func WebInit(www *WWW, db *ii.DB) {
www.tpl = template.Must(template.New("main").Funcs(funcMap).ParseGlob("tpl/*.tpl"))
}
-func handleWWW(www WWW, w http.ResponseWriter, r *http.Request) error {
+func handleErr(user *ii.User, www WWW, w http.ResponseWriter, err error) {
+ ctx := WebContext{ Error: err.Error(), User: user }
+ www.tpl.ExecuteTemplate(w, "error.tpl", ctx)
+}
+
+func handleWWW(www WWW, w http.ResponseWriter, r *http.Request) {
var user *ii.User = &ii.User {}
+ err := _handleWWW(user, www, w, r)
+ if err != nil {
+ handleErr(user, www, w, err)
+ }
+}
+
+func _handleWWW(user *ii.User, www WWW, w http.ResponseWriter, r *http.Request) error {
cookie, err := r.Cookie("pauth")
if err == nil {
udb := ii.LoadUsers(*users_opt) /* per each request */