mirror of
https://github.com/rjNemo/go-wiki
synced 2026-06-06 02:36:40 +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 {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
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 {
|
||||
views.Template(w, "contact", nil)
|
||||
return
|
||||
|
|
|
|||
|
|
@ -52,3 +52,9 @@ func (ph PageHandler) save(w http.ResponseWriter, r *http.Request, title string)
|
|||
// checkError(err, w)
|
||||
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("/edit/", makeHandler(ph.edit))
|
||||
http.HandleFunc("/save/", makeHandler(ph.save))
|
||||
http.HandleFunc("/contact/", contactHandler)
|
||||
http.HandleFunc("/new/", ph.new)
|
||||
http.HandleFunc("/contact/", hh.contact)
|
||||
http.HandleFunc("/", hh.home)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ const (
|
|||
|
||||
// GetAllPages is the SQL command used to retrieve all pages from the database.
|
||||
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
|
||||
|
|
|
|||
|
|
@ -40,20 +40,22 @@
|
|||
</div>
|
||||
|
||||
<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
|
||||
class="form-control mr-sm-2"
|
||||
type="search"
|
||||
placeholder="Search"
|
||||
aria-label="Search"
|
||||
type="text"
|
||||
name="newPage"
|
||||
placeholder="New Wiki Entry"
|
||||
/>
|
||||
<button
|
||||
class="btn btn-outline-success my-2 my-sm-0"
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<input
|
||||
type="submit"
|
||||
action="/view/"
|
||||
>
|
||||
Search
|
||||
</button>
|
||||
value="New"
|
||||
class="btn btn-outline-primary my-2 my-sm-0"
|
||||
/>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -14,9 +14,8 @@
|
|||
>Documentation</a
|
||||
>
|
||||
</div>
|
||||
<div>
|
||||
<h2>Index</h2>
|
||||
<p>Some description</p>
|
||||
|
||||
<!-- <div>
|
||||
<ul>
|
||||
{{ range $index, $entry := .Wikis }}
|
||||
<li>
|
||||
|
|
@ -24,6 +23,32 @@
|
|||
</li>
|
||||
{{ end }}
|
||||
</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>
|
||||
{{end}}
|
||||
|
|
|
|||
Loading…
Reference in a new issue