@@ -7,9 +7,76 @@ import (
77
88 "github.com/howeyc/ledger"
99
10+ "github.com/BurntSushi/toml"
1011 "github.com/go-martini/martini"
1112)
1213
14+ type quickviewAccountConfig struct {
15+ Name string
16+ ShortName string `toml:"short_name"`
17+ }
18+
19+ type quickviewConfigStruct struct {
20+ Accounts []quickviewAccountConfig `toml:"account"`
21+ }
22+
23+ func quickviewHandler (w http.ResponseWriter , r * http.Request ) {
24+ if len (quickviewConfigFileName ) == 0 {
25+ http .Redirect (w , r , "/accounts" , http .StatusFound )
26+ }
27+ var quickviewConfigData quickviewConfigStruct
28+ if _ , lerr := toml .DecodeFile (quickviewConfigFileName , & quickviewConfigData ); lerr != nil || len (quickviewConfigData .Accounts ) < 1 {
29+ http .Redirect (w , r , "/accounts" , http .StatusFound )
30+ }
31+
32+ shorten := func (accname string ) string {
33+ for _ , qvc := range quickviewConfigData .Accounts {
34+ if qvc .Name == accname {
35+ return qvc .ShortName
36+ }
37+ }
38+ return abbrev (accname )
39+ }
40+
41+ funcMap := template.FuncMap {
42+ "abbrev" : shorten ,
43+ }
44+
45+ t , err := parseAssetsWithFunc (funcMap , "templates/template.accounts.html" , "templates/template.nav.html" )
46+ if err != nil {
47+ http .Error (w , err .Error (), 500 )
48+ return
49+ }
50+
51+ trans , terr := getTransactions ()
52+ if terr != nil {
53+ http .Error (w , terr .Error (), 500 )
54+ return
55+ }
56+
57+ var pData pageData
58+ pData .Reports = reportConfigData .Reports
59+ pData .Portfolios = portfolioConfigData .Portfolios
60+ pData .Transactions = trans
61+
62+ includeNames := make (map [string ]bool )
63+ for _ , qvc := range quickviewConfigData .Accounts {
64+ includeNames [qvc .Name ] = true
65+ }
66+
67+ balances := ledger .GetBalances (trans , []string {})
68+ for _ , bal := range balances {
69+ if includeNames [bal .Name ] {
70+ pData .Accounts = append (pData .Accounts , bal )
71+ }
72+ }
73+
74+ err = t .Execute (w , pData )
75+ if err != nil {
76+ http .Error (w , err .Error (), 500 )
77+ }
78+ }
79+
1380func accountsHandler (w http.ResponseWriter , r * http.Request ) {
1481 funcMap := template.FuncMap {
1582 "abbrev" : abbrev ,
0 commit comments