From 170acda64fdef95fda90c42bf8bbb5fbfd8b6144 Mon Sep 17 00:00:00 2001 From: Peter Stuifzand Date: Sun, 15 Aug 2021 13:47:13 +0200 Subject: [PATCH] Add next and previous actions for calendar --- editor/src/index.js | 10 ++++++++++ editor/src/styles.scss | 20 ++++++++++++++++++++ list-editor/index.js | 16 ++++++++++------ main.go | 32 +++++++++++++++++++++++++++++++- templates/calendar.html | 27 +++++++++++++++++++++++++++ templates/sidebar-right.html | 23 ++--------------------- 6 files changed, 100 insertions(+), 28 deletions(-) create mode 100644 templates/calendar.html diff --git a/editor/src/index.js b/editor/src/index.js index 3b100a3..9d0314a 100644 --- a/editor/src/index.js +++ b/editor/src/index.js @@ -84,3 +84,13 @@ document.querySelectorAll(".page-loader") } }) }) + +$(document).on('click', '.calendar-update', function (event) { + const cal = $(this).data('calendar') + fetch('/api/calendar/' + cal) + .then(res => res.text()) + .then(calendar => { + $('.calendar').html(calendar) + }) + return false +}) diff --git a/editor/src/styles.scss b/editor/src/styles.scss index 66e116f..545a4c5 100644 --- a/editor/src/styles.scss +++ b/editor/src/styles.scss @@ -252,6 +252,26 @@ mark { } } +.calendar-buttons { + width: 257px; + display: flex; + justify-content: space-between; + align-items: center; + font-weight: bold; + padding: 3px; + + .calendar-update { + display: block; + width: 32px; + height: 32px; + text-align: center; + } + .calendar-update:active { + border: 3px solid #aaa; + border-radius: 4px; + } +} + .calendar-grid { display: grid; width: 257px; diff --git a/list-editor/index.js b/list-editor/index.js index 9b620c2..1f6d4d5 100644 --- a/list-editor/index.js +++ b/list-editor/index.js @@ -140,12 +140,16 @@ function editor(root, inputData, options) { function start() { root.focus(); - disableDragging(drake) - render(root, store); - drake = enableDragging(root) - + $(root).on('click', '.marker', function (event) { + if (event.ctrlKey) { + zoomin(this).then(id => { + location.href = '/edit/' + id; + }) + } + return true; + }) cursor.set(0) - trigger('change') + renderUpdate() } function getChildren(id) { @@ -754,7 +758,7 @@ function editor(root, inputData, options) { $(root).on('click', '.marker', function () { stopEditing(root, store, $(this).next('textarea')); - return false; + return true; }); $(root).on('click', '.content a', function (event) { diff --git a/main.go b/main.go index 215d93a..881d794 100644 --- a/main.go +++ b/main.go @@ -127,6 +127,9 @@ type pageBaseInfo struct { RedirectURI string Days []Day Month string + Year int + PrevMonth string + NextMonth string } type indexPage struct { @@ -197,7 +200,7 @@ type recentPage struct { Recent []Change } -var baseTemplate = []string{"templates/layout.html", "templates/sidebar.html", "templates/sidebar-right.html"} +var baseTemplate = []string{"templates/layout.html", "templates/sidebar.html", "templates/sidebar-right.html", "templates/calendar.html"} type indexHandler struct{} type graphHandler struct{} @@ -483,7 +486,12 @@ func getPageBase(repo PagesRepository, t time.Time) pageBaseInfo { RedirectURI: redirectURI, Days: prepareDays(mp, t), Month: t.Month().String(), + Year: t.Year(), } + + pageBase.PrevMonth = t.AddDate(0, -1, -t.Day()+1).Format("2006-01-02") + pageBase.NextMonth = t.AddDate(0, 1, -t.Day()+1).Format("2006-01-02") + return pageBase } @@ -1192,6 +1200,28 @@ func main() { return } }) + http.HandleFunc("/api/calendar/", func(w http.ResponseWriter, r *http.Request) { + dateString := r.URL.Path[len("/api/calendar/"):] + curDate, err := time.Parse("2006-01-02", dateString) + if err != nil { + curDate = time.Now() + } + pageBase := getPageBase(mp, curDate) + + t, err := template.ParseFiles("templates/calendar.html") + if err != nil { + http.Error(w, err.Error(), 500) + return + } + w.Header().Set("Content-Type", "text/html; charset=utf-8") + w.Header().Set("Cache-Control", "public, max-age=600") + err = t.ExecuteTemplate(w, "calendar", pageBase) + if err != nil { + log.Println(err) + http.Error(w, err.Error(), 500) + return + } + }) http.Handle("/search/", sh) http.Handle("/public/", http.StripPrefix("/public/", http.FileServer(http.Dir("./dist")))) http.Handle("/save/", &saveHandler{}) diff --git a/templates/calendar.html b/templates/calendar.html new file mode 100644 index 0000000..1ff51ed --- /dev/null +++ b/templates/calendar.html @@ -0,0 +1,27 @@ +{{ define "calendar" }} +
+
+ < +

{{ .Month }} {{ .Year }}

+ > +
+
+
+
m
+
d
+
w
+
d
+
v
+
z
+
z
+ {{ range .Days }} + + {{ end }} +
+
+{{ end }} diff --git a/templates/sidebar-right.html b/templates/sidebar-right.html index f3bfe2c..3956a76 100644 --- a/templates/sidebar-right.html +++ b/templates/sidebar-right.html @@ -1,25 +1,6 @@ {{ define "sidebar-right" }} {{ end }}