-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(webui): login page is now styled
login page is now styled from a file, binpacked by pkger
- Loading branch information
Showing
8 changed files
with
239 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,3 +20,4 @@ dist/* | |
request.http | ||
bin/deploy | ||
ubby.toml | ||
pkged.go |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"html/template" | ||
"reflect" | ||
"time" | ||
) | ||
|
||
var templateFunctions = template.FuncMap{ | ||
"percent": func(a, b int) float64 { | ||
return float64(a) / float64(b) * 100 | ||
}, | ||
"safeHTML": func(s interface{}) template.HTML { | ||
return template.HTML(fmt.Sprint(s)) | ||
}, | ||
"crop": func(s string, i int) string { | ||
if len(s) > i { | ||
return s[0:(i-2)] + "..." | ||
} | ||
return s | ||
}, | ||
"add": func(b, a interface{}) (interface{}, error) { | ||
av := reflect.ValueOf(a) | ||
bv := reflect.ValueOf(b) | ||
|
||
switch av.Kind() { | ||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: | ||
switch bv.Kind() { | ||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: | ||
return av.Int() + bv.Int(), nil | ||
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: | ||
return av.Int() + int64(bv.Uint()), nil | ||
case reflect.Float32, reflect.Float64: | ||
return float64(av.Int()) + bv.Float(), nil | ||
default: | ||
return nil, fmt.Errorf("add: unknown type for %q (%T)", bv, b) | ||
} | ||
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: | ||
switch bv.Kind() { | ||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: | ||
return int64(av.Uint()) + bv.Int(), nil | ||
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: | ||
return av.Uint() + bv.Uint(), nil | ||
case reflect.Float32, reflect.Float64: | ||
return float64(av.Uint()) + bv.Float(), nil | ||
default: | ||
return nil, fmt.Errorf("add: unknown type for %q (%T)", bv, b) | ||
} | ||
case reflect.Float32, reflect.Float64: | ||
switch bv.Kind() { | ||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: | ||
return av.Float() + float64(bv.Int()), nil | ||
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: | ||
return av.Float() + float64(bv.Uint()), nil | ||
case reflect.Float32, reflect.Float64: | ||
return av.Float() + bv.Float(), nil | ||
default: | ||
return nil, fmt.Errorf("add: unknown type for %q (%T)", bv, b) | ||
} | ||
default: | ||
return nil, fmt.Errorf("add: unknown type for %q (%T)", av, a) | ||
} | ||
}, | ||
"prettyTime": func(s interface{}) template.HTML { | ||
t, ok := s.(time.Time) | ||
if !ok { | ||
return "" | ||
} | ||
if t.IsZero() { | ||
return template.HTML("never") | ||
} | ||
return template.HTML(t.Format("2006-01-02 15:04:05")) | ||
}, | ||
"json": func(s interface{}) template.HTML { | ||
json, _ := json.MarshalIndent(s, "", " ") | ||
return template.HTML(string(json)) | ||
}, | ||
"relativeTime": func(s interface{}) template.HTML { | ||
t, ok := s.(time.Time) | ||
if !ok { | ||
return "" | ||
} | ||
if t.IsZero() { | ||
return template.HTML("never") | ||
} | ||
tense := "ago" | ||
diff := time.Since(t) | ||
seconds := int64(diff.Seconds()) | ||
if seconds < 0 { | ||
tense = "from now" | ||
} | ||
var quantifier string | ||
|
||
if seconds < 60 { | ||
quantifier = "s" | ||
} else if seconds < 3600 { | ||
quantifier = "m" | ||
seconds /= 60 | ||
} else if seconds < 86400 { | ||
quantifier = "h" | ||
seconds /= 3600 | ||
} else if seconds < 604800 { | ||
quantifier = "d" | ||
seconds /= 86400 | ||
} else if seconds < 31556736 { | ||
quantifier = "w" | ||
seconds /= 604800 | ||
} else { | ||
quantifier = "y" | ||
seconds /= 31556736 | ||
} | ||
|
||
return template.HTML(fmt.Sprintf("%v%s %s", seconds, quantifier, tense)) | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package main | ||
|
||
import ( | ||
"html/template" | ||
"io/ioutil" | ||
"os" | ||
"strings" | ||
|
||
"github.com/markbates/pkger" | ||
) | ||
|
||
func loadTemplates() (*template.Template, error) { | ||
tpl := template.New("") | ||
tpl.Funcs(templateFunctions) | ||
|
||
err := pkger.Walk("/templates", func(path string, info os.FileInfo, err error) error { | ||
if strings.HasSuffix(path, ".html") { | ||
f, err := pkger.Open(path) | ||
if err != nil { | ||
return err | ||
} | ||
sl, err := ioutil.ReadAll(f) | ||
if err != nil { | ||
return err | ||
} | ||
_, err = tpl.Parse(string(sl)) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
}) | ||
|
||
return tpl, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
{{define "index.html"}} | ||
<!DOCTYPE html> | ||
<html> | ||
|
||
<head> | ||
<title>tobab</title> | ||
</head> | ||
|
||
<style> | ||
html, | ||
body { | ||
height: 100%; | ||
} | ||
|
||
body { | ||
margin: 0; | ||
background-color: rgb(15, 0, 36); | ||
} | ||
|
||
.flex-container { | ||
height: 100%; | ||
margin: 0; | ||
display: -webkit-box; | ||
display: -moz-box; | ||
display: -ms-flexbox; | ||
display: -webkit-flex; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
} | ||
|
||
.row { | ||
font-family: Helvetica, Arial, sans-serif; | ||
color: #FFFFFF; | ||
width: auto; | ||
background-color: rgb(58, 40, 61); | ||
padding: 50px; | ||
border-radius: 20px; | ||
} | ||
|
||
a, | ||
a:hover, | ||
a:visited, | ||
a:valid { | ||
color: rgb(247, 56, 253); | ||
text-decoration: none; | ||
font-weight: bold; | ||
font-size: 2em; | ||
} | ||
</style> | ||
|
||
<body> | ||
<div class="flex-container"> | ||
<div class="row"> | ||
<h1>Hi {{.User}}</h1><br /> | ||
{{range $key,$value:=.Providers}} | ||
<p><a href="/auth/{{$value}}">Log in with {{index $.ProvidersMap $value}}</a></p> | ||
{{end}} | ||
</div> | ||
</div> | ||
</body> | ||
|
||
</html> | ||
{{end}} |