Esempio n. 1
0
File: home.go Progetto: keep94/vsafe
func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	r.ParseForm()
	session := common.GetUserSession(r)
	sortBy := r.Form.Get("sort")
	id, _ := strconv.ParseInt(r.Form.Get("id"), 10, 64)
	entries, err := vsafedb.Entries(h.Store, session.Key().Id, r.Form.Get("q"))
	if err != nil {
		http_util.ReportError(w, "Error reading database", err)
		return
	}
	switch sortBy {
	case "newest":
		vsafedb.Reverse(entries)
	default:
		vsafedb.SortByTitle(entries)
	}
	http_util.WriteTemplate(
		w,
		kTemplate,
		&view{
			Values:  http_util.Values{r.Form},
			Name:    session.User.Name,
			Entries: entries,
			Url:     r.URL,
			Id:      id})
}
Esempio n. 2
0
func TestSortByTitle(t *testing.T) {
	entry1 := vsafe.Entry{Title: " First"}
	entry2 := vsafe.Entry{Title: "aGAiN  sEcond"}
	entry3 := vsafe.Entry{Title: "   Third", Desc: "foo bar"}
	entry4 := vsafe.Entry{Title: "fourth again", Desc: "foo bar"}
	s := []*vsafe.Entry{&entry1, &entry2, &entry3, &entry4}
	vsafedb.SortByTitle(s)
	if s[0] != &entry2 || s[1] != &entry1 || s[2] != &entry4 || s[3] != &entry3 {
		t.Error("Sort in wrong order.")
	}
}
Esempio n. 3
0
func TestSortByTitleEmpty(t *testing.T) {
	var s []*vsafe.Entry
	vsafedb.SortByTitle(s)
}