;web: transaction fragments: use numeric identifiers for journal files
This saves us from any escaping issues.
This commit is contained in:
		
							parent
							
								
									e9792bfd42
								
							
						
					
					
						commit
						c35d0a8b44
					
				| @ -13,7 +13,7 @@ import Hledger.Web.Import | |||||||
| import Hledger.Web.WebOptions | import Hledger.Web.WebOptions | ||||||
| import Hledger.Web.Widget.AddForm (addModal) | import Hledger.Web.Widget.AddForm (addModal) | ||||||
| import Hledger.Web.Widget.Common | import Hledger.Web.Widget.Common | ||||||
|             (accountQuery, mixedAmountAsHtml, transactionFrag) |             (accountQuery, mixedAmountAsHtml, transactionFragment) | ||||||
| 
 | 
 | ||||||
| -- | The formatted journal view, with sidebar. | -- | The formatted journal view, with sidebar. | ||||||
| getJournalR :: Handler Html | getJournalR :: Handler Html | ||||||
| @ -27,6 +27,7 @@ getJournalR = do | |||||||
|       title' = title <> if m /= Any then ", filtered" else "" |       title' = title <> if m /= Any then ", filtered" else "" | ||||||
|       acctlink a = (RegisterR, [("q", accountQuery a)]) |       acctlink a = (RegisterR, [("q", accountQuery a)]) | ||||||
|       (_, items) = transactionsReport (reportopts_ $ cliopts_ opts) j m |       (_, items) = transactionsReport (reportopts_ $ cliopts_ opts) j m | ||||||
|  |       transactionFrag = transactionFragment j | ||||||
| 
 | 
 | ||||||
|   defaultLayout $ do |   defaultLayout $ do | ||||||
|     setTitle "journal - hledger-web" |     setTitle "journal - hledger-web" | ||||||
|  | |||||||
| @ -18,7 +18,7 @@ import Hledger.Web.Import | |||||||
| import Hledger.Web.WebOptions | import Hledger.Web.WebOptions | ||||||
| import Hledger.Web.Widget.AddForm (addModal) | import Hledger.Web.Widget.AddForm (addModal) | ||||||
| import Hledger.Web.Widget.Common | import Hledger.Web.Widget.Common | ||||||
|              (accountQuery, mixedAmountAsHtml, transactionFrag) |              (accountQuery, mixedAmountAsHtml, transactionFragment) | ||||||
| 
 | 
 | ||||||
| -- | The main journal/account register view, with accounts sidebar. | -- | The main journal/account register view, with accounts sidebar. | ||||||
| getRegisterR :: Handler Html | getRegisterR :: Handler Html | ||||||
| @ -45,6 +45,7 @@ getRegisterR = do | |||||||
|           tail $ (", "<$xs) ++ [""] |           tail $ (", "<$xs) ++ [""] | ||||||
|       r@(balancelabel,items) = accountTransactionsReport ropts j m acctQuery |       r@(balancelabel,items) = accountTransactionsReport ropts j m acctQuery | ||||||
|       balancelabel' = if isJust (inAccount qopts) then balancelabel else "Total" |       balancelabel' = if isJust (inAccount qopts) then balancelabel else "Total" | ||||||
|  |       transactionFrag = transactionFragment j | ||||||
|   defaultLayout $ do |   defaultLayout $ do | ||||||
|     setTitle "register - hledger-web" |     setTitle "register - hledger-web" | ||||||
|     $(widgetFile "register") |     $(widgetFile "register") | ||||||
|  | |||||||
| @ -14,7 +14,7 @@ module Hledger.Web.Widget.Common | |||||||
|   , fromFormSuccess |   , fromFormSuccess | ||||||
|   , writeJournalTextIfValidAndChanged |   , writeJournalTextIfValidAndChanged | ||||||
|   , journalFile404 |   , journalFile404 | ||||||
|   , transactionFrag |   , transactionFragment | ||||||
|   ) where |   ) where | ||||||
| 
 | 
 | ||||||
| import Data.Default (def) | import Data.Default (def) | ||||||
| @ -24,6 +24,7 @@ import Data.Semigroup ((<>)) | |||||||
| #endif | #endif | ||||||
| import Data.Text (Text) | import Data.Text (Text) | ||||||
| import qualified Data.Text as T | import qualified Data.Text as T | ||||||
|  | import qualified Data.HashMap.Strict as HashMap | ||||||
| import System.FilePath (takeFileName) | import System.FilePath (takeFileName) | ||||||
| import Text.Blaze ((!), textValue) | import Text.Blaze ((!), textValue) | ||||||
| import qualified Text.Blaze.Html5 as H | import qualified Text.Blaze.Html5 as H | ||||||
| @ -106,6 +107,9 @@ mixedAmountAsHtml b _ = | |||||||
|       Just True -> "negative amount" |       Just True -> "negative amount" | ||||||
|       _ -> "positive amount" |       _ -> "positive amount" | ||||||
| 
 | 
 | ||||||
| transactionFrag :: Transaction -> String | transactionFragment :: Journal -> Transaction -> String | ||||||
| transactionFrag t = | transactionFragment j = | ||||||
|     printf "transaction-%s-%d" (sourceFilePath $ tsourcepos t) (tindex t) |     let hm = HashMap.fromList $ zip (map fst $ jfiles j) [(1::Integer) ..] | ||||||
|  |     in  \t -> | ||||||
|  |             printf "transaction-%d-%d" | ||||||
|  |                 (hm HashMap.! sourceFilePath (tsourcepos t)) (tindex t) | ||||||
|  | |||||||
| @ -185,6 +185,7 @@ library | |||||||
|     , time >=1.5 |     , time >=1.5 | ||||||
|     , transformers |     , transformers | ||||||
|     , unix-compat |     , unix-compat | ||||||
|  |     , unordered-containers | ||||||
|     , utf8-string |     , utf8-string | ||||||
|     , wai |     , wai | ||||||
|     , wai-cors |     , wai-cors | ||||||
|  | |||||||
| @ -130,6 +130,7 @@ library: | |||||||
|   - time >=1.5 |   - time >=1.5 | ||||||
|   - transformers |   - transformers | ||||||
|   - unix-compat |   - unix-compat | ||||||
|  |   - unordered-containers | ||||||
|   - utf8-string |   - utf8-string | ||||||
|   - wai |   - wai | ||||||
|   - wai-extra |   - wai-extra | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user