Add: Page version list
This commit is contained in:
parent
150a652b34
commit
b7a581549b
1
TODO.md
1
TODO.md
@ -6,6 +6,7 @@
|
||||
- [x] Flag that sets the debug mode
|
||||
- [x] Flag to show the version
|
||||
- [x] Page versioning in a really basic way
|
||||
- [x] Version listing
|
||||
- [x] Makefile helper
|
||||
- [ ] CI (gofmt, golint, more)?
|
||||
|
||||
|
@ -8,4 +8,5 @@ type Store interface {
|
||||
GetPage(string) (Page, error)
|
||||
GetPageVersion(string, string) (Page, error)
|
||||
GetAllPages() ([]Page, error)
|
||||
GetPageHistory(name string) ([]Page, error)
|
||||
}
|
||||
|
@ -65,7 +65,16 @@ func (s *StoreGorm) GetPageVersion(name string, version string) (Page, error) {
|
||||
|
||||
func (s *StoreGorm) GetAllPages() ([]Page, error) {
|
||||
var pages []Page
|
||||
tx := s.db.Find(&pages)
|
||||
tx := s.db.Select("*, max(Version)").Group("Name").Find(&pages)
|
||||
if tx.Error != nil {
|
||||
return []Page{}, tx.Error
|
||||
}
|
||||
return pages, nil
|
||||
}
|
||||
|
||||
func (s *StoreGorm) GetPageHistory(name string) ([]Page, error) {
|
||||
var pages []Page
|
||||
tx := s.db.Debug().Where("Name = ?", name).Order("Version desc").Find(&pages)
|
||||
if tx.Error != nil {
|
||||
return []Page{}, tx.Error
|
||||
}
|
||||
|
@ -100,6 +100,20 @@ func WikiPagePostEdit(c echo.Context) error {
|
||||
return c.Redirect(http.StatusMovedPermanently, "/"+page.Name)
|
||||
}
|
||||
|
||||
func WikiPageHistory(c echo.Context) error {
|
||||
page_id := c.Param("page")
|
||||
pages, err := store.GetPageHistory(page_id)
|
||||
if err != nil {
|
||||
log.Panicln(err)
|
||||
}
|
||||
Debug.Printf("res: %T\n", pages)
|
||||
// Debug.Println(pages)
|
||||
return c.Render(http.StatusOK, "list.html", map[string]interface{}{
|
||||
"title": page_id,
|
||||
"pages": pages,
|
||||
})
|
||||
}
|
||||
|
||||
func WikiList(c echo.Context) error {
|
||||
pages, err := store.GetAllPages()
|
||||
if err != nil {
|
||||
|
@ -68,6 +68,7 @@ func Serve() {
|
||||
e.GET("/:page", WikiPage)
|
||||
e.GET("/:page/:version", WikiPage)
|
||||
e.GET("/:page/edit", WikiPageEdit)
|
||||
e.GET("/:page/history", WikiPageHistory)
|
||||
e.GET("/:page/:version/edit", WikiPageEdit)
|
||||
e.POST("/:page/edit", WikiPagePostEdit)
|
||||
e.POST("/:page/:version/edit", WikiPagePostEdit)
|
||||
|
@ -3,10 +3,14 @@
|
||||
{{end}}
|
||||
|
||||
{{define "body"}}
|
||||
{{ if .title }}
|
||||
<h1>{{ .title }}</h1>
|
||||
{{ else }}
|
||||
<h1>List</h1>
|
||||
{{ end }}
|
||||
<ul>
|
||||
{{ range .pages }}
|
||||
<li><a href="{{ .Name }}/{{ .Version }}">{{ .Name }}, v{{ .Version }}</a>.- {{ .Body }}</li>
|
||||
<li><a href="/{{ .Name }}/{{ .Version }}">{{ .Name }}, v{{ .Version }}</a>.- {{ .Body }}</li>
|
||||
{{ end }}
|
||||
</ul>
|
||||
{{end}}
|
||||
|
@ -7,6 +7,9 @@
|
||||
{{ .html | safeHTML }}
|
||||
<hr />
|
||||
<a href="/{{ .page.Name }}/{{ .page.Version }}/edit">Edit</a>
|
||||
{{ if gt .page.Version 1 }}
|
||||
<a href="/{{ .page.Name }}/history">History</a>
|
||||
{{ end }}
|
||||
<p style="float: right">Last modified: {{ .page.UpdatedAt }}</p>
|
||||
<p style="float: right">*{{ .page.Version }}*</p>
|
||||
{{end}}
|
||||
|
Loading…
Reference in New Issue
Block a user