4 Commits
v0.1 ... v0.3

Author SHA1 Message Date
bel
4c3a508b84 dont proxy to settings.php as its dead 2020-01-26 18:36:38 +00:00
bel
6733ccd4b8 fix tags and duedates 2020-01-26 18:34:41 +00:00
bel
2f0c09ff72 fix search I htink 2020-01-26 18:13:51 +00:00
bel
ff3ed3a57e gzip 2020-01-26 18:07:28 +00:00
6 changed files with 57 additions and 66 deletions

View File

@@ -61,6 +61,18 @@ func ToStrArr(k string) []string {
} }
func ToTime(s string) time.Time { func ToTime(s string) time.Time {
v, _ := time.Parse("2006-01-02 15:04:05", s) v, err := time.Parse("2006-01-02 15:04:05", s)
if err != nil || v.IsZero() {
v, err = time.Parse("2006-01-02", s)
}
if err != nil || v.IsZero() {
v, err = time.Parse("1/2/06", s)
}
if err != nil || v.IsZero() {
v, err = time.Parse("02 Jan 2006 3:04 PM", s)
}
if err != nil || v.IsZero() {
v, err = time.Parse("02 Jan 2006 3:04 PM", strings.ReplaceAll(s, "+", " "))
}
return v return v
} }

View File

@@ -79,6 +79,18 @@ func TestToTime(t *testing.T) {
in: "5", in: "5",
out: "0001-01-01 00:00:00", out: "0001-01-01 00:00:00",
}, },
{
in: "1/2/03",
out: "2003-01-02 00:00:00",
},
{
in: "11/12/03",
out: "2003-11-12 00:00:00",
},
{
in: "01+Jan+2020+12:00+PM",
out: "2020-01-01 12:00:00",
},
} }
for _, c := range cases { for _, c := range cases {

View File

@@ -94,6 +94,7 @@ func (a *Ajax) storageListTasks(listID string, filters ...func(t *task.Task) boo
} }
} }
if filtered { if filtered {
//task.Title = fmt.Sprintf("[%d] %s", task.Index, task.Title)
tasks = append(tasks, task) tasks = append(tasks, task)
} }
} }

View File

@@ -54,7 +54,8 @@ func filterTags(tags []string) func(t *task.Task) bool {
func filterSubstr(substr string) func(t *task.Task) bool { func filterSubstr(substr string) func(t *task.Task) bool {
return func(t *task.Task) bool { return func(t *task.Task) bool {
return substr == "" || strings.Contains(fmt.Sprintf("%+v", t), substr) found := substr == "" || strings.Contains(fmt.Sprintf("%+v %+v", t.Title, t.Tags), substr)
return found
} }
} }

View File

@@ -39,7 +39,7 @@ func New(r *http.Request) (*Task, error) {
UUID: form.NewUUID(), UUID: form.NewUUID(),
Title: form.Get(r, "title"), Title: form.Get(r, "title"),
Priority: form.ToInt(form.Get(r, "prio")), Priority: form.ToInt(form.Get(r, "prio")),
Tags: StrList(form.ToStrArr(form.Get(r, "tags"))), Tags: append(StrList(form.ToStrArr(form.Get(r, "tag"))), StrList(form.ToStrArr(form.Get(r, "tags")))...),
Created: time.Now(), Created: time.Now(),
Edited: time.Now(), Edited: time.Now(),
@@ -110,6 +110,13 @@ func (t *Task) MarshalJSON() ([]byte, error) {
"dueInt": t.Due.Unix(), "dueInt": t.Due.Unix(),
"dueTitle": "Due ", "dueTitle": "Due ",
} }
if t.Due.IsZero() {
for k := range m {
if strings.HasPrefix(k, "due") {
delete(m, k)
}
}
}
if t.Complete { if t.Complete {
m["dateCompleted"] = t.Completed.Format(fullFormat) m["dateCompleted"] = t.Completed.Format(fullFormat)
m["dateCompletedInline"] = t.Completed.Format(shortFormat) m["dateCompletedInline"] = t.Completed.Format(shortFormat)

View File

@@ -3,6 +3,7 @@ package server
import ( import (
"fmt" "fmt"
"io" "io"
"local/gziphttp"
"local/router" "local/router"
"local/todo-server/config" "local/todo-server/config"
"log" "log"
@@ -20,78 +21,20 @@ func (s *Server) Routes() error {
}{ }{
{ {
path: "/", path: "/",
handler: s.index, handler: s.gzip(s.index),
}, },
{ {
path: "/mytinytodo_lang.php", path: "/mytinytodo_lang.php",
handler: s.lang, handler: s.gzip(s.lang),
}, },
{ {
path: fmt.Sprintf("%s%s", router.Wildcard, router.Wildcard), path: fmt.Sprintf("%s%s", router.Wildcard, router.Wildcard),
handler: s.phpProxy, handler: s.gzip(s.phpProxy),
}, },
{ {
path: "/ajax.php", path: "/ajax.php",
handler: s.HandleAjax, handler: s.gzip(s.HandleAjax),
}, },
/*
{
path: "db/index.html",
handler: s.static,
},
{
path: "jquery/index.html",
handler: s.static,
},
{
path: "lang/index.html",
handler: s.static,
},
{
path: "themes/index.html",
handler: s.static,
},
{
path: "tmp/index.html",
handler: s.static,
},
{
path: "jquery/jquery-1.4.4.min.js",
handler: s.static,
},
{
path: "jquery/jquery-ui-1.8.7.custom.min.js",
handler: s.static,
},
{
path: "jquery/jquery.autocomplete-1.1.js",
handler: s.static,
},
{
path: "mytinytodo.js",
handler: s.static,
},
{
path: "mytinytodo_ajax_storage.js",
handler: s.static,
},
{
path: "testdata/mytinytodo2/themes/default/pda.css",
handler: s.static,
},
{
path: "testdata/mytinytodo2/themes/default/print.css",
handler: s.static,
},
{
path: "testdata/mytinytodo2/themes/default/style.css",
handler: s.static,
},
{
path: "testdata/mytinytodo2/themes/default/style_rtl.css",
handler: s.static,
},
*/
} }
for _, route := range routes { for _, route := range routes {
@@ -152,7 +95,8 @@ func (s *Server) phpProxy(w http.ResponseWriter, r *http.Request) {
if err != nil { if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError) http.Error(w, err.Error(), http.StatusInternalServerError)
} else { } else {
log.Println("proxying", url.String(), r.URL.Path) log.Println("WOULD proxy", url.String(), r.URL.Path)
s.index(w, r)
//proxy := httputil.NewSingleHostReverseProxy(url) //proxy := httputil.NewSingleHostReverseProxy(url)
//proxy.ServeHTTP(w, r) //proxy.ServeHTTP(w, r)
} }
@@ -161,3 +105,17 @@ func (s *Server) phpProxy(w http.ResponseWriter, r *http.Request) {
func (s *Server) static(w http.ResponseWriter, r *http.Request) { func (s *Server) static(w http.ResponseWriter, r *http.Request) {
s.fileServer.ServeHTTP(w, r) s.fileServer.ServeHTTP(w, r)
} }
func (s *Server) gzip(h http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
if gziphttp.Can(r) {
gz := gziphttp.New(w)
defer gz.Close()
w = gz
}
if filepath.Ext(r.URL.Path) == ".css" {
w.Header().Set("Content-Type", "text/css; charset=utf-8")
}
h(w, r)
}
}