mirror of
https://github.com/rjNemo/go-wiki
synced 2026-06-12 13:36:38 +00:00
homeHandler, new page form and handler
This commit is contained in:
parent
1082d81963
commit
c184591bc9
6 changed files with 54 additions and 21 deletions
|
|
@ -20,11 +20,10 @@ func (hh HomeHandler) home(w http.ResponseWriter, r *http.Request) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
views.Template(w, "home", struct{ Wikis []models.Page }{index})
|
views.Template(w, "home", struct{ Wikis []models.Page }{index})
|
||||||
}
|
}
|
||||||
|
|
||||||
func contactHandler(w http.ResponseWriter, r *http.Request) {
|
func (hh HomeHandler) contact(w http.ResponseWriter, r *http.Request) {
|
||||||
if r.Method != http.MethodPost {
|
if r.Method != http.MethodPost {
|
||||||
views.Template(w, "contact", nil)
|
views.Template(w, "contact", nil)
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -52,3 +52,9 @@ func (ph PageHandler) save(w http.ResponseWriter, r *http.Request, title string)
|
||||||
// checkError(err, w)
|
// checkError(err, w)
|
||||||
http.Redirect(w, r, "/view/"+title, http.StatusFound)
|
http.Redirect(w, r, "/view/"+title, http.StatusFound)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ph PageHandler) new(w http.ResponseWriter, r *http.Request) {
|
||||||
|
title := r.FormValue("newPage")
|
||||||
|
http.Redirect(w, r, "/edit/"+title, http.StatusFound)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,8 @@ func Router(ph PageHandler, hh HomeHandler) {
|
||||||
http.HandleFunc("/view/", makeHandler(ph.view))
|
http.HandleFunc("/view/", makeHandler(ph.view))
|
||||||
http.HandleFunc("/edit/", makeHandler(ph.edit))
|
http.HandleFunc("/edit/", makeHandler(ph.edit))
|
||||||
http.HandleFunc("/save/", makeHandler(ph.save))
|
http.HandleFunc("/save/", makeHandler(ph.save))
|
||||||
http.HandleFunc("/contact/", contactHandler)
|
http.HandleFunc("/new/", ph.new)
|
||||||
|
http.HandleFunc("/contact/", hh.contact)
|
||||||
http.HandleFunc("/", hh.home)
|
http.HandleFunc("/", hh.home)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ const (
|
||||||
|
|
||||||
// GetAllPages is the SQL command used to retrieve all pages from the database.
|
// GetAllPages is the SQL command used to retrieve all pages from the database.
|
||||||
GetAllPages = `
|
GetAllPages = `
|
||||||
SELECT * FROM pages ORDER BY id;
|
SELECT * FROM pages ORDER BY title;
|
||||||
`
|
`
|
||||||
|
|
||||||
// FindPages is the SQL command used to retrieve all pages from the table
|
// FindPages is the SQL command used to retrieve all pages from the table
|
||||||
|
|
|
||||||
|
|
@ -40,20 +40,22 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="collapse navbar-collapse" id="navbarSupportedContent">
|
<div class="collapse navbar-collapse" id="navbarSupportedContent">
|
||||||
<form class="form-inline my-2 my-lg-0">
|
<form class="form-inline my-2 my-lg-0" action="/new">
|
||||||
|
<div class="form-group">
|
||||||
<input
|
<input
|
||||||
class="form-control mr-sm-2"
|
class="form-control mr-sm-2"
|
||||||
type="search"
|
type="text"
|
||||||
placeholder="Search"
|
name="newPage"
|
||||||
aria-label="Search"
|
placeholder="New Wiki Entry"
|
||||||
/>
|
/>
|
||||||
<button
|
</div>
|
||||||
class="btn btn-outline-success my-2 my-sm-0"
|
<div class="form-group">
|
||||||
|
<input
|
||||||
type="submit"
|
type="submit"
|
||||||
action="/view/"
|
value="New"
|
||||||
>
|
class="btn btn-outline-primary my-2 my-sm-0"
|
||||||
Search
|
/>
|
||||||
</button>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -14,9 +14,8 @@
|
||||||
>Documentation</a
|
>Documentation</a
|
||||||
>
|
>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
|
||||||
<h2>Index</h2>
|
<!-- <div>
|
||||||
<p>Some description</p>
|
|
||||||
<ul>
|
<ul>
|
||||||
{{ range $index, $entry := .Wikis }}
|
{{ range $index, $entry := .Wikis }}
|
||||||
<li>
|
<li>
|
||||||
|
|
@ -24,6 +23,32 @@
|
||||||
</li>
|
</li>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</ul>
|
</ul>
|
||||||
|
</div> -->
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<h2>Go-Wiki Index</h2>
|
||||||
|
<p>Some description</p>
|
||||||
|
|
||||||
|
<table class="table table-hover">
|
||||||
|
<thead class="thead-light">
|
||||||
|
<tr>
|
||||||
|
<th scope="col">Title</th>
|
||||||
|
<th scope="col"></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{{ range $index, $entry := .Wikis }}
|
||||||
|
<tr>
|
||||||
|
<td><a href="/view/{{ $entry.Title }}">{{ $entry.Title }}</a></td>
|
||||||
|
<th scope="row">
|
||||||
|
<a class="badge-pill badge-primary" href="/edit/{{ $entry.Title }}"
|
||||||
|
>Edit</a
|
||||||
|
>
|
||||||
|
</th>
|
||||||
|
</tr>
|
||||||
|
{{ end }}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue