1
0
Fork 0

Add option to change the number of entries per page (fixes #40)

This commit is contained in:
logan 2020-07-09 01:24:54 +02:00 committed by Frédéric Guillot
parent e32fa059e5
commit 5f266319a3
35 changed files with 174 additions and 52 deletions

View file

@ -6,6 +6,7 @@ package form // import "miniflux.app/ui/form"
import (
"net/http"
"strconv"
"miniflux.app/errors"
"miniflux.app/model"
@ -20,6 +21,7 @@ type SettingsForm struct {
Language string
Timezone string
EntryDirection string
EntriesPerPage int
KeyboardShortcuts bool
CustomCSS string
}
@ -31,6 +33,7 @@ func (s *SettingsForm) Merge(user *model.User) *model.User {
user.Language = s.Language
user.Timezone = s.Timezone
user.EntryDirection = s.EntryDirection
user.EntriesPerPage = s.EntriesPerPage
user.KeyboardShortcuts = s.KeyboardShortcuts
user.Extra["custom_css"] = s.CustomCSS
@ -47,6 +50,10 @@ func (s *SettingsForm) Validate() error {
return errors.NewLocalizedError("error.settings_mandatory_fields")
}
if s.EntriesPerPage < 1 {
return errors.NewLocalizedError("error.entries_per_page_invalid")
}
if s.Confirmation == "" {
// Firefox insists on auto-completing the password field.
// If the confirmation field is blank, the user probably
@ -67,6 +74,10 @@ func (s *SettingsForm) Validate() error {
// NewSettingsForm returns a new SettingsForm.
func NewSettingsForm(r *http.Request) *SettingsForm {
entriesPerPage, err := strconv.ParseInt(r.FormValue("entries_per_page"), 10, 64)
if err != nil {
entriesPerPage = 0
}
return &SettingsForm{
Username: r.FormValue("username"),
Password: r.FormValue("password"),
@ -75,6 +86,7 @@ func NewSettingsForm(r *http.Request) *SettingsForm {
Language: r.FormValue("language"),
Timezone: r.FormValue("timezone"),
EntryDirection: r.FormValue("entry_direction"),
EntriesPerPage: int(entriesPerPage),
KeyboardShortcuts: r.FormValue("keyboard_shortcuts") == "1",
CustomCSS: r.FormValue("custom_css"),
}

View file

@ -13,6 +13,7 @@ func TestValid(t *testing.T) {
Language: "en_US",
Timezone: "UTC",
EntryDirection: "asc",
EntriesPerPage: 50,
}
err := settings.Validate()
@ -30,6 +31,7 @@ func TestConfirmationEmpty(t *testing.T) {
Language: "en_US",
Timezone: "UTC",
EntryDirection: "asc",
EntriesPerPage: 50,
}
err := settings.Validate()
@ -51,6 +53,25 @@ func TestConfirmationIncorrect(t *testing.T) {
Language: "en_US",
Timezone: "UTC",
EntryDirection: "asc",
EntriesPerPage: 50,
}
err := settings.Validate()
if err == nil {
t.Error("Validate should return an error")
}
}
func TestEntriesPerPageNotValid(t *testing.T) {
settings := &SettingsForm{
Username: "user",
Password: "hunter2",
Confirmation: "hunter2",
Theme: "default",
Language: "en_US",
Timezone: "UTC",
EntryDirection: "asc",
EntriesPerPage: 0,
}
err := settings.Validate()