Add next and previous actions for calendar
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
3022be7e66
commit
170acda64f
|
@ -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
|
||||
})
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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) {
|
||||
|
|
32
main.go
32
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{})
|
||||
|
|
27
templates/calendar.html
Normal file
27
templates/calendar.html
Normal file
|
@ -0,0 +1,27 @@
|
|||
{{ define "calendar" }}
|
||||
<div class="calendar">
|
||||
<div class="calendar-buttons">
|
||||
<a href="" class="calendar-update" data-calendar="{{ .PrevMonth }}"><</a>
|
||||
<h3>{{ .Month }} {{ .Year }}</h3>
|
||||
<a href="" class="calendar-update" data-calendar="{{ .NextMonth }}">></a>
|
||||
</div>
|
||||
<div class="calendar-grid">
|
||||
<div class="day"></div>
|
||||
<div class="day">m</div>
|
||||
<div class="day">d</div>
|
||||
<div class="day">w</div>
|
||||
<div class="day">d</div>
|
||||
<div class="day">v</div>
|
||||
<div class="day">z</div>
|
||||
<div class="day">z</div>
|
||||
{{ range .Days }}
|
||||
<div class="{{ .Class }}">
|
||||
<a href="{{ .URL }}">
|
||||
<span class="day-text">{{ .Text }}</span>
|
||||
<span class="day-count">{{ .Count }}</span>
|
||||
</a>
|
||||
</div>
|
||||
{{ end }}
|
||||
</div>
|
||||
</div>
|
||||
{{ end }}
|
|
@ -1,25 +1,6 @@
|
|||
{{ define "sidebar-right" }}
|
||||
<div class="sidebar-right">
|
||||
<div class="calendar">
|
||||
<h3>{{ .Month }}</h3>
|
||||
<div class="calendar-grid">
|
||||
<div class="day"></div>
|
||||
<div class="day">m</div>
|
||||
<div class="day">d</div>
|
||||
<div class="day">w</div>
|
||||
<div class="day">d</div>
|
||||
<div class="day">v</div>
|
||||
<div class="day">z</div>
|
||||
<div class="day">z</div>
|
||||
{{ range .Days }}
|
||||
<div class="{{ .Class }}">
|
||||
<a href="{{ .URL }}">
|
||||
<span class="day-text">{{ .Text }}</span>
|
||||
<span class="day-count">{{ .Count }}</span>
|
||||
</a>
|
||||
</div>
|
||||
{{ end }}
|
||||
</div>
|
||||
</div>
|
||||
{{block "calendar" .}}
|
||||
{{end}}
|
||||
</div>
|
||||
{{ end }}
|
||||
|
|
Loading…
Reference in New Issue
Block a user