Documentation
¶
Overview ¶
Package common provides routines common to all handlers in the ledger webapp.
Index ¶
- Variables
- func ActiveCatDetails(cds categories.CatDetailStore, catPopularity fin.CatPopularity, ...) []categories.CatDetail
- func EntryMutation(values url.Values) (mutation fin.EntryUpdater, err error)
- func InitializeForm(paymentId int64) url.Values
- func Is21stCentury(year int) bool
- func NewGorillaSession(sessionStore sessions.Store, r *http.Request) (*sessions.Session, error)
- func NewTemplate(name, templateStr string) *template.Template
- func NewXsrfToken(r *http.Request, action string) string
- func NormalizeYMDStr(dateStr string) string
- func VerifyXsrfToken(r *http.Request, action string) bool
- func VerifyXsrfTokenExplicit(xsrf string, r *http.Request, action string) bool
- type AccountLinker
- type CatDisplayer
- type CatLinker
- type EntryLinker
- type EntrySplitType
- type Global
- type LeftNav
- type LinkText
- type RecurringEntryLinker
- type RecurringUnitComboBoxType
- type Selecter
- func ParseSelecter(s string) (Selecter, error)
- func SelectAccount(id int64) Selecter
- func SelectChpasswd() Selecter
- func SelectEnvelopes() Selecter
- func SelectExport() Selecter
- func SelectManage() Selecter
- func SelectNone() Selecter
- func SelectRecurring() Selecter
- func SelectReports() Selecter
- func SelectSearch() Selecter
- func SelectTotals() Selecter
- func SelectTrends() Selecter
- func SelectUnreviewed() Selecter
- type SingleEntryView
- type UserSession
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrXsrf = errors.New("Page had grown stale. Please resubmit.") ErrInvalidYear = errors.New("Year must be in the 21st century") )
var ( // Error for date being wrong when adding an entry. ErrDateMayBeWrong = errors.New("Date may be wrong, proceed anyway?") ErrConcurrentModification = errors.New( "Someone else already updated this entry. Click cancel and try again.") )
var ( // Represents the combo box for recurring units. // Implements http_util.SelectionModel RecurringUnitComboBox = RecurringUnitComboBoxType{ fin.Months, fin.Years, fin.Days, fin.Weeks} )
Functions ¶
func ActiveCatDetails ¶
func ActiveCatDetails( cds categories.CatDetailStore, catPopularity fin.CatPopularity, showAccounts bool) []categories.CatDetail
ActiveCatDetails returns the active cat details prepended with the most popular ones. catPopularity is the popularity of the categories. If showAccounts is true, ActiveCatDetails returns values for accounts too. If catPopularity is nil, ActiveCatDetails simply returns the active cat details without prepending the most popular ones.
func EntryMutation ¶
func EntryMutation(values url.Values) ( mutation fin.EntryUpdater, err error)
EntryMutation converts the form values from a single entry page into a mutation and returns that mutation or an error if the form values were invalid. Returned filter always returns true.
func InitializeForm ¶
InitializeForm initializes an empty form for creating a brand new entry. If paymentId is non-zero, sets type payment combo box to the specified paymentId.
func Is21stCentury ¶
Is21stCentury returns true if year is in the 21st century.
func NewGorillaSession ¶
NewGorillaSession creates a gorilla session for the finance app
func NewTemplate ¶
NewTemplate returns a new template instance. name is the name of the template; templateStr is the template string. Returned template has FormatDate and FormatUSD defined.
func NewXsrfToken ¶
NewXsrfToken creates a new xsrf token for given action.
func NormalizeYMDStr ¶
NormalizeYMDStr normalizes a date string.
Example ¶
package main import ( "fmt" "github.com/keep94/finances/apps/ledger/common" ) func main() { fmt.Printf("%s %s %s\n", common.NormalizeYMDStr("2012"), common.NormalizeYMDStr("201203"), common.NormalizeYMDStr("20120305")) }
Output: 20120101 20120301 20120305
func VerifyXsrfToken ¶
VerifyXsrfToken verifies the xsrf token for given action. VerifyXsrfToken looks for the token under "xsrf" in request.
Types ¶
type AccountLinker ¶
type AccountLinker struct { }
AccountLinker creates URLs to account pages
func (AccountLinker) AccountLink ¶
func (a AccountLinker) AccountLink(id int64) *url.URL
AccountLink returns a URL to the account page with given account Id.
func (AccountLinker) RecurringLink ¶
func (a AccountLinker) RecurringLink(id int64) *url.URL
RecurringLink returns a URL to the recurring entries page for a given account Id.
func (AccountLinker) UnreconciledLink ¶
func (a AccountLinker) UnreconciledLink(id int64) *url.URL
UnreconiledLink returns a URL to the unreconciled page with given account Id.
func (AccountLinker) UploadLink ¶
func (a AccountLinker) UploadLink(id int64) *url.URL
UploadLink returns a URL to the upload page for a given account Id.
type CatDisplayer ¶
type CatDisplayer struct {
categories.CatDetailStore
}
CatDisplayer is used to display categories.
func (CatDisplayer) AccountSelectModel ¶
func (c CatDisplayer) AccountSelectModel() http_util.SelectModel
AccountSelectModel returns the model for account dropdowns.
func (CatDisplayer) AcctName ¶
func (c CatDisplayer) AcctName(cp *fin.CatPayment) string
Returns the account name to display for an entry. cp is the CatPayment record in the entry.
func (CatDisplayer) CatName ¶
func (c CatDisplayer) CatName(cp *fin.CatPayment) string
Returns the category name to display for an entry. cp is the CatPayment record in the entry.
func (CatDisplayer) CatSelectModel ¶
func (c CatDisplayer) CatSelectModel() http_util.SelectModel
CatSelectModel returns the model for category dropdowns.
type CatLinker ¶
type CatLinker struct { ListEntries *url.URL Cds categories.CatDetailStore }
CatLinker displays categories as a series of hyperlinks
func (*CatLinker) AccountNameLink ¶
func (c *CatLinker) AccountNameLink(cp *fin.CatPayment) LinkText
AccountNameLink returns the account name as a link. If c.ListEntries is nil, returns account name as plain text.
type EntryLinker ¶
type EntryLinker struct { // The current URL URL *url.URL // Item selected in left navigation Sel Selecter }
EntryLinker creates URLs to the edit entry page.
func (*EntryLinker) EntryLink ¶
func (e *EntryLinker) EntryLink(id int64) *url.URL
EntryLink returns a URL to the edit entry page. id is the id of the entry to be edited.
func (*EntryLinker) NewEntryLink ¶
func (e *EntryLinker) NewEntryLink(paymentId int64) *url.URL
NewEntryLink returns a URL to the edit entry page for creating a new entry. paymentId is the account ID of the default payment type. Passing 0 or a negative number means that user will have to select payment in the edit entry page.
type EntrySplitType ¶
type EntrySplitType int
EntrySplitType represents the display for a single split of an entry.
func (EntrySplitType) AmountParam ¶
func (s EntrySplitType) AmountParam() string
AmountParam returns the name of the amount parameter for this split
func (EntrySplitType) CatParam ¶
func (s EntrySplitType) CatParam() string
CatParam returns the name of the category parameter for this split
func (EntrySplitType) ReconcileParam ¶
func (s EntrySplitType) ReconcileParam() string
ReconcileParam returns the name of the reconciled parameter for this split
type Global ¶
type Global struct { // The title of the website Title string // True if website has an icon at /images/favicon.ico Icon bool }
Global contains static information global to all pages in website.
type LeftNav ¶
type LeftNav struct {}
LeftNav is for creating the left navigation bar.
func (*LeftNav) Generate ¶
Generate generates the html for the left navigation bar including the div tags. sel indicates which item in the left navigation bar will be selected. If Generate can't generate the html, it returns the empty string, writes an error message to w, and writes the error to stderr.
type RecurringEntryLinker ¶
RecurringEntryLinker creates URLs to the edit recurring entry page.
func (RecurringEntryLinker) EntryLink ¶
func (e RecurringEntryLinker) EntryLink(id int64) *url.URL
EntryLink returns a URL to the edit recurring entry page. id is the id of the recurring entry to be edited.
func (RecurringEntryLinker) NewEntryLink ¶
func (e RecurringEntryLinker) NewEntryLink(paymentId int64) *url.URL
NewEntryLink returns a URL to the edit recurring entry page for creating a new recurring entry. paymentId is the account ID of the default payment type. Passing 0 or a negative number means that user will have to select payment in the edit recurring entry page.
type RecurringUnitComboBoxType ¶
type RecurringUnitComboBoxType []fin.RecurringUnit
func (RecurringUnitComboBoxType) ToSelection ¶
func (r RecurringUnitComboBoxType) ToSelection(s string) *http_util.Selection
type Selecter ¶
type Selecter struct {
// contains filtered or unexported fields
}
Selecter indicates the item to be selected in the left navigation bar.
func ParseSelecter ¶
func SelectAccount ¶
func SelectChpasswd ¶
func SelectChpasswd() Selecter
func SelectEnvelopes ¶
func SelectEnvelopes() Selecter
func SelectExport ¶
func SelectExport() Selecter
func SelectManage ¶
func SelectManage() Selecter
func SelectNone ¶
func SelectNone() Selecter
func SelectRecurring ¶
func SelectRecurring() Selecter
func SelectReports ¶
func SelectReports() Selecter
func SelectSearch ¶
func SelectSearch() Selecter
func SelectTotals ¶
func SelectTotals() Selecter
func SelectTrends ¶
func SelectTrends() Selecter
func SelectUnreviewed ¶
func SelectUnreviewed() Selecter
type SingleEntryView ¶
type SingleEntryView struct { http_util.Values CatDisplayer Splits []EntrySplitType Error error Xsrf string ExistingEntry bool Global *Global // contains filtered or unexported fields }
View for single entry pages.
func ToSingleEntryView ¶
func ToSingleEntryView( entry *fin.Entry, xsrf string, cds categories.CatDetailStore, catPopularity fin.CatPopularity, global *Global, leftnav template.HTML) *SingleEntryView
ToSingleEntryView creates a view from a particular entry. The caller may safely add additional name value pairs to the Values field of returned view. The caller must refrain from making other types of changes to returned view.
func ToSingleEntryViewFromForm ¶
func ToSingleEntryViewFromForm( existingEntry bool, values url.Values, xsrf string, cds categories.CatDetailStore, catPopularity fin.CatPopularity, global *Global, leftnav template.HTML, err error) *SingleEntryView
ToSingleEntryViewFromForm creates a view from form data. existingEntry is true if the form data represents an existing entry or false if it represents a brand new entry. values are the form values. xsrf is the cross site request forgery token cds is the category detail store. catPopularity is the popularity of the categories. May be nil. global is the non changing global content of view. leftnav is the left navigation content err is the error from the form submission or nil if no error.
func (*SingleEntryView) ActiveCatDetails ¶
func (v *SingleEntryView) ActiveCatDetails( showAccounts bool) []categories.CatDetail
func (*SingleEntryView) DateMayBeWrong ¶
func (v *SingleEntryView) DateMayBeWrong() bool
DateMayBeWrong returns true if and only if the error for this view is ErrDateMayBeWrong.
type UserSession ¶
type UserSession struct { session_util.UserIdSession *sessions.Session // User is the logged in user or nil if no user logged in User *fin.User // Main store for accessing entries, accounts, and users Store interface{} // The category cache Cache categoriesdb.Getter // Loads QFX files Uploaders map[string]autoimport.Loader }
UserSession represents a session where user is logged in.
func CreateUserSession ¶
func CreateUserSession(s *sessions.Session) *UserSession
CreateUserSession creates a UserSession instance from a gorilla session but does not populate the user field of the returned session.
func GetUserSession ¶
func GetUserSession(r *http.Request) *UserSession
GetUserSession gets the UserSession associated with the request. It can only be called after successful completion of NewUserSession.
func NewUserSession ¶
func NewUserSession( store findb.UserByIdRunner, sessionStore sessions.Store, r *http.Request) (*UserSession, error)
NewUserSession creates a UserSession and associates it with the request instance. If user not logged in, the User field in returned UserSession is nil. Caller must call context.Clear with request instance.
func (*UserSession) Batch ¶
func (s *UserSession) Batch(acctId int64) autoimport.Batch
Batch returns the uploaded batch for a particular account ID. Batch returns nil if there is no pending batch.
func (*UserSession) CatPopularity ¶
func (s *UserSession) CatPopularity() fin.CatPopularity
CatPopularity returns the category popularities
func (*UserSession) SetBatch ¶
func (s *UserSession) SetBatch(acctId int64, batch autoimport.Batch)
SetBatch stores a batch in the session under a particular account ID. Passing nil for batch indicates there is no batch for the given account ID.
func (*UserSession) SetCatPopularity ¶
func (s *UserSession) SetCatPopularity(cp fin.CatPopularity)
SetCatPopularity stores the category popularities in the session. Passing nil for cp indicates there are no category popularities.
func (*UserSession) SetUser ¶
func (s *UserSession) SetUser(userPtr interface{})