From c19a47c5927559aebf81c28f0543d56708d857c6 Mon Sep 17 00:00:00 2001 From: Claudio Maggioni Date: Fri, 26 May 2017 17:54:45 +0200 Subject: [PATCH] Caricamento ajax della tabella --- html.go | 27 +++++++++++-------- template/Interfaccia.html | 56 +++++++++++++++++++-------------------- template/tabella.html | 17 ++++++++++++ 3 files changed, 61 insertions(+), 39 deletions(-) create mode 100644 template/tabella.html diff --git a/html.go b/html.go index daf1169..6246df6 100644 --- a/html.go +++ b/html.go @@ -5,22 +5,27 @@ import ( "net/http" ) +var varmap map[string]interface{} + // ServiHTML fa partire il server html func ServiHTML() { - http.HandleFunc("/", handlerRoot) - http.ListenAndServe(":3000", nil) -} - -func handlerRoot(w http.ResponseWriter, r *http.Request) { - templ, err := template.ParseFiles("template/Interfaccia.html") - if err != nil { - panic(err.Error()) - } - varmap := map[string]interface{}{ + varmap = map[string]interface{}{ "matrice": Matrix, "tempoAggiorna": Clock, "larghezza": Larghezza, "altezza": Altezza, } - templ.Execute(w, varmap) + http.HandleFunc("/tabella", handlerRoot("template/tabella.html")) + http.HandleFunc("/", handlerRoot("template/Interfaccia.html")) + http.ListenAndServe(":3000", nil) +} + +func handlerRoot(path string) func(w http.ResponseWriter, r *http.Request) { + return func(w http.ResponseWriter, r *http.Request) { + templ, err := template.ParseFiles(path) + if err != nil { + panic(err.Error()) + } + templ.Execute(w, varmap) + } } diff --git a/template/Interfaccia.html b/template/Interfaccia.html index 8c7dde7..1819401 100644 --- a/template/Interfaccia.html +++ b/template/Interfaccia.html @@ -1,7 +1,6 @@ GoBug - + -

Go bug

-
-
- - {{range $riga := .matrice}} - - {{range $cella := $riga}} - - {{ else }} - {{ if $cella.IsFood }} - class="cibo" - {{ else }} - class="razza1" - {{ end }}>{{ $cella.Health }} - {{ end }} - {{ end }} - - {{ end }} -
-
+

Go bug

+
+

legenda

-
-
Cibo
-
-
Razza1
-
-
Razza2
+
 Cibo
+
 Razza 1
+
 Razza 2
diff --git a/template/tabella.html b/template/tabella.html new file mode 100644 index 0000000..773fae2 --- /dev/null +++ b/template/tabella.html @@ -0,0 +1,17 @@ + +{{range $riga := .matrice}} + + {{range $cella := $riga}} + + {{ else }} + {{ if $cella.IsFood }} + class="cibo" + {{ else }} + class="razza1" + {{ end }}>{{ $cella.Health }} + {{ end }} + {{ end }} + +{{ end }} +