[ledger] support filter by date

This commit is contained in:
Anantha Kumaran 2022-08-28 12:12:08 +05:30
parent 64deaecf3e
commit 60fef80904
2 changed files with 8 additions and 4 deletions

View File

@ -35,6 +35,7 @@ function renderTransactions(postings: Posting[]) {
const rows = _.map(postings, (p) => { const rows = _.map(postings, (p) => {
const purchase = formatCurrency(p.amount); const purchase = formatCurrency(p.amount);
let market = "", let market = "",
date = p.timestamp.format("DD MMM YYYY"),
change = "", change = "",
changePercentage = "", changePercentage = "",
changeClass = "", changeClass = "",
@ -61,7 +62,7 @@ function renderTransactions(postings: Posting[]) {
} }
const markup = ` const markup = `
<tr class="${p.timestamp.month() % 2 == 0 ? "has-background-white-ter" : ""}"> <tr class="${p.timestamp.month() % 2 == 0 ? "has-background-white-ter" : ""}">
<td>${p.timestamp.format("DD MMM YYYY")}</td> <td>${date}</td>
<td>${p.payee}</td> <td>${p.payee}</td>
<td>${p.account}</td> <td>${p.account}</td>
<td class='has-text-right'>${purchase}</td> <td class='has-text-right'>${purchase}</td>
@ -73,6 +74,7 @@ function renderTransactions(postings: Posting[]) {
</tr> </tr>
`; `;
return { return {
date: date,
markup: markup, markup: markup,
posting: p posting: p
}; };
@ -89,7 +91,7 @@ function renderTransactions(postings: Posting[]) {
} }
function filterTransactions( function filterTransactions(
rows: { posting: Posting; markup: string }[], rows: { date: string; posting: Posting; markup: string }[],
filter: string filter: string
) { ) {
let filterRegex = new RegExp(".*", "i"); let filterRegex = new RegExp(".*", "i");
@ -100,7 +102,9 @@ function filterTransactions(
return _.filter( return _.filter(
rows, rows,
(r) => (r) =>
filterRegex.test(r.posting.account) || filterRegex.test(r.posting.payee) filterRegex.test(r.posting.account) ||
filterRegex.test(r.posting.payee) ||
filterRegex.test(r.date)
); );
} }

View File

@ -287,7 +287,7 @@
<div class="level-item"> <div class="level-item">
<div class="field"> <div class="field">
<p class="control"> <p class="control">
<input class="d3-posting-filter input" style="width: 440px" type="text" placeholder="filter by account or description"> <input class="d3-posting-filter input" style="width: 440px" type="text" placeholder="filter by account or description or date">
</p> </p>
</div> </div>
</div> </div>