Functional web interface

This commit is contained in:
da
2017-01-19 22:49:17 +01:00
parent 0ffa002ba9
commit f0cff35bea
7 changed files with 81 additions and 98 deletions
-71
View File
@@ -1,71 +0,0 @@
/* http://meyerweb.com/eric/tools/css/reset/
v2.0 | 20110126
License: none (public domain)
*/
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup,
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure,
footer, header, hgroup, menu, nav, section {
display: block;
}
body {
line-height: 1;
}
ol, ul {
list-style: none;
}
blockquote, q {
quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
content: '';
content: none;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
a {
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
body {
font-size: 13px;
font-family: 'Open Sans', sans-serif;
padding: 0 30px;
}
header {
padding: 30px 0;
font-size: 15px;
}
header h1 {
font-size: 20px;
}
+11
View File
@@ -0,0 +1,11 @@
{{ define "footer" }}
</div>
</div>
<!-- /.container -->
</body>
</html>
{{ end }}
@@ -1,4 +1,4 @@
{{ define "base" }}
{{ define "header" }}
<html>
<head>
@@ -15,6 +15,11 @@
body {
padding-top: 50px;
}
.vcenter {
display: inline-block;
vertical-align: middle;
float: none;
}
</style>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
@@ -46,17 +51,9 @@
</nav>
<div class="container">
<div class="starter-template">
<div class="container-fluid">
<h1>Gidbig</h1>
<p class="lead">{{ template "content" . }}</p>
</div>
</div>
<!-- /.container -->
<p class="lead">{{ template "sessionHandler" . }}</p>
{{ end }}
</body>
</html>
{{ end }}
+1 -1
View File
@@ -1,3 +1,3 @@
{{ define "content" }}
{{ define "sessionHandler" }}
<a href="/discordLogin">Login with Discord</a>
{{ end }}
+5 -5
View File
@@ -1,12 +1,12 @@
{{ define "content" }}
{{ define "sessionHandler" }}
<script type="text/javascript">
function playSound() {
function playSound(cmd, sndnm) {
var data = {
command: "!bsth",
soundname: "unmoeglich"
command: cmd,
soundname: sndnm
};
$.post("/playsound", data, function(data, success) {});
}
</script>
<a href="/logout">Logout</a><br/>
<a href="javascript:playSound()">Play sound</a> {{ end }}
{{ end }}
+5
View File
@@ -0,0 +1,5 @@
<div class="row">
{{ range . }}
<div class="col-sm-3 text-center">{{ .Itemtext }}<br/><a class="btn btn-primary" href="javascript:playSound('{{ .Itemcommand }}', '{{ .Itemsoundname }}')" role="button">Play!</a></div>
{{ end }}
</div>
+49 -8
View File
@@ -14,8 +14,9 @@ import (
)
const (
defaultLayout = "templates/layout.html"
templateDir = "templates/"
header = "templates/header.html"
footer = "templates/footer.html"
templateDir = "templates/"
)
var (
@@ -37,10 +38,17 @@ var (
store *sessions.CookieStore
)
type SoundItem struct {
Itemcommand string
Itemsoundname string
Itemtext string
}
// startWebServer
func startWebServer(port string, ci string, cs string, redirectURL string) {
tmpls["home.html"] = template.Must(template.ParseFiles(templateDir+"home.html", defaultLayout))
tmpls["internal.html"] = template.Must(template.ParseFiles(templateDir+"internal.html", defaultLayout))
tmpls["home.html"] = template.Must(template.ParseFiles(templateDir+"home.html", header, footer))
tmpls["internal.html"] = template.Must(template.ParseFiles(templateDir+"internal.html", header, footer))
tmpls["itemrow.html"] = template.Must(template.ParseFiles(templateDir + "itemrow.html"))
store = sessions.NewCookieStore([]byte(cs))
discordOauthConfig.ClientID = ci
discordOauthConfig.ClientSecret = cs
@@ -52,8 +60,6 @@ func startWebServer(port string, ci string, cs string, redirectURL string) {
r.HandleFunc("/discordLogin", handlediscordLogin)
r.HandleFunc("/discordCallback", handlediscordCallback)
r.HandleFunc("/playsound", handlePlaySound)
http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static"))))
http.Handle("/", r)
http.ListenAndServe(":"+port, nil)
}
@@ -79,10 +85,45 @@ func handlePlaySound(w http.ResponseWriter, r *http.Request) {
func handleMain(w http.ResponseWriter, r *http.Request) {
session, _ := store.Get(r, "session-name")
if session.Values["discordUsername"] != nil {
tmpls["internal.html"].ExecuteTemplate(w, "base", map[string]interface{}{})
err := tmpls["internal.html"].ExecuteTemplate(w, "header", map[string]interface{}{})
if err != nil {
fmt.Println(err)
return
}
var si [4]SoundItem
cnt := 0
for _, sc := range COLLECTIONS {
for _, snd := range sc.Sounds {
si[cnt%4].Itemcommand = "!" + sc.Prefix
si[cnt%4].Itemsoundname = snd.Name
si[cnt%4].Itemtext = si[cnt%4].Itemcommand + " " + si[cnt%4].Itemsoundname
if cnt != 0 && cnt%4 == 3 {
err = tmpls["itemrow.html"].Execute(w, si)
if err != nil {
fmt.Println(err)
return
}
}
cnt++
}
}
if cnt%4 != 0 {
err = tmpls["itemrow.html"].Execute(w, si)
if err != nil {
fmt.Println(err)
return
}
}
err = tmpls["internal.html"].ExecuteTemplate(w, "footer", map[string]interface{}{})
if err != nil {
fmt.Println(err)
return
}
return
}
tmpls["home.html"].ExecuteTemplate(w, "base", map[string]interface{}{})
tmpls["home.html"].ExecuteTemplate(w, "header", map[string]interface{}{})
tmpls["home.html"].ExecuteTemplate(w, "footer", map[string]interface{}{})
}
func handleLogout(w http.ResponseWriter, r *http.Request) {
cookie := &http.Cookie{