Compare commits

..

5 Commits

Author SHA1 Message Date
8b70447e2a Update TODO 2022-04-04 22:16:26 +02:00
b7a581549b Add: Page version list 2022-04-04 22:16:07 +02:00
150a652b34 WIP: Generate changelog 2022-03-28 22:10:39 +02:00
5686f748a8 Update: TODO 2022-03-28 22:10:24 +02:00
66a5a25a7f Add: CONTRIBUTING file 2022-03-28 22:00:13 +02:00
9 changed files with 68 additions and 6 deletions

11
CONTRIBUTING.md Normal file
View File

@ -0,0 +1,11 @@
# Contributing
Contributions are welcome, and they are greatly appreciated! Every
little bit helps, and credit will always be given.
Types of contributions:
- **Report bugs**: If you think you've found a bug please submit a bug report with some information as operating system, details about your local setup and detailed steps to reproduce the bug.
- **Fix bugs**: Look through the GitHub issues for bugs. Anything tagged with "bug"
is open to whoever wants to implement it.
- **Implement features**: Take in account that features always involves PR and code review.

View File

@ -9,3 +9,6 @@ build:
clean: clean:
rm -f bin/wikingo rm -f bin/wikingo
changelog:
git log --oneline --decorate --pretty=format:'* %s' >> CHANGELOG.md

24
TODO.md
View File

@ -6,10 +6,8 @@
- [x] Flag that sets the debug mode - [x] Flag that sets the debug mode
- [x] Flag to show the version - [x] Flag to show the version
- [x] Page versioning in a really basic way - [x] Page versioning in a really basic way
- [ ] Flag to select store - [x] Version listing
- [ ] Config file (to select store and some other future options)
- [x] Makefile helper - [x] Makefile helper
- [ ] Reload if files changes [idea](https://medium.com/@olebedev/live-code-reloading-for-golang-web-projects-in-19-lines-8b2e8777b1ea#.gok9azrg4)
- [ ] CI (gofmt, golint, more)? - [ ] CI (gofmt, golint, more)?
## Bootstrap ## Bootstrap
@ -18,5 +16,23 @@
- [x] Sample Model - [x] Sample Model
- [x] Store interface (gorm, file...) - [x] Store interface (gorm, file...)
- [x] Open db store - [x] Open db store
- [ ] Open file store
- [x] Templates - [x] Templates
## Must
> Must have things (as tasks)
- [ ] List history (in every detail page, a link to the history should be included)
- [ ] Deal with static content (images, attachments...)
- [ ] If you're about to save not the latest version, button: save -> restore
- [ ] Delete any page or version
- [ ] Not allow to create a kind of forbidden-words list (edit, list, version...)
- [ ] Redirect page/ -> page
## Enhacements
> Things that would be awesome to have, but not necessary for now
- [ ] Config file (to select store and some other future options)
- [ ] Flag to select store
- [ ] Open file store
- [ ] Reload if files changes [idea](https://medium.com/@olebedev/live-code-reloading-for-golang-web-projects-in-19-lines-8b2e8777b1ea#.gok9azrg4)
- [ ] Add a `make release` Makefile command
- [idea](https://github.com/miekg/dns/blob/master/Makefile.fuzz)
- [idea](https://github.com/miekg/dns/blob/master/Makefile.release)

View File

@ -8,4 +8,5 @@ type Store interface {
GetPage(string) (Page, error) GetPage(string) (Page, error)
GetPageVersion(string, string) (Page, error) GetPageVersion(string, string) (Page, error)
GetAllPages() ([]Page, error) GetAllPages() ([]Page, error)
GetPageHistory(name string) ([]Page, error)
} }

View File

@ -65,7 +65,16 @@ func (s *StoreGorm) GetPageVersion(name string, version string) (Page, error) {
func (s *StoreGorm) GetAllPages() ([]Page, error) { func (s *StoreGorm) GetAllPages() ([]Page, error) {
var pages []Page 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 { if tx.Error != nil {
return []Page{}, tx.Error return []Page{}, tx.Error
} }

View File

@ -100,6 +100,20 @@ func WikiPagePostEdit(c echo.Context) error {
return c.Redirect(http.StatusMovedPermanently, "/"+page.Name) 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 { func WikiList(c echo.Context) error {
pages, err := store.GetAllPages() pages, err := store.GetAllPages()
if err != nil { if err != nil {

View File

@ -68,6 +68,7 @@ func Serve() {
e.GET("/:page", WikiPage) e.GET("/:page", WikiPage)
e.GET("/:page/:version", WikiPage) e.GET("/:page/:version", WikiPage)
e.GET("/:page/edit", WikiPageEdit) e.GET("/:page/edit", WikiPageEdit)
e.GET("/:page/history", WikiPageHistory)
e.GET("/:page/:version/edit", WikiPageEdit) e.GET("/:page/:version/edit", WikiPageEdit)
e.POST("/:page/edit", WikiPagePostEdit) e.POST("/:page/edit", WikiPagePostEdit)
e.POST("/:page/:version/edit", WikiPagePostEdit) e.POST("/:page/:version/edit", WikiPagePostEdit)

View File

@ -3,10 +3,14 @@
{{end}} {{end}}
{{define "body"}} {{define "body"}}
{{ if .title }}
<h1>{{ .title }}</h1>
{{ else }}
<h1>List</h1> <h1>List</h1>
{{ end }}
<ul> <ul>
{{ range .pages }} {{ 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 }} {{ end }}
</ul> </ul>
{{end}} {{end}}

View File

@ -7,6 +7,9 @@
{{ .html | safeHTML }} {{ .html | safeHTML }}
<hr /> <hr />
<a href="/{{ .page.Name }}/{{ .page.Version }}/edit">Edit</a> <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">Last modified: {{ .page.UpdatedAt }}</p>
<p style="float: right">*{{ .page.Version }}*</p> <p style="float: right">*{{ .page.Version }}*</p>
{{end}} {{end}}