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