hledger-web-2.0: templates/default-layout.hamlet
$# The sidebar's button, like the s key, shows or hides the sidebar
$# (hledger.js), or on a narrow screen slides it in or out. It stays at the
$# top left either way: with the sidebar hidden, the spacer shrinks to fit it.
<div#spacer .col-xs-2.#{topShow}>
<h1>
$if elem ViewPermission perms
<button #sidebar-toggle .btn.btn-default.hidden-print type=button aria-controls=sidebar-menu aria-expanded=#{sidebarExpanded} aria-keyshortcuts=s title=_{HMsg "Show or hide the sidebar (s)"}>
<svg .sidebar-icon viewBox="0 0 16 16" width=18 height=18 aria-hidden=true>
<rect .sidebar-icon-pane x=2 y=3 width=4 height=10>
<rect x=1.5 y=2.5 width=13 height=11 rx=1.5 fill=none stroke=currentColor>
<line x1=6.5 y1=2.5 x2=6.5 y2=13.5 stroke=currentColor>
<div#topbar .col-md-8 .col-sm-8 .col-xs-10>
<h1>#{takeFileName (journalFilePath j)}
$if elem ViewPermission perms
<div#sidebar-menu .sidebar-offcanvas.#{sideShowmd}.#{sideShowsm} :balancesHidden:.balances-hidden>
<table .main-menu .table>
^{accounts}
$# Fold the sidebar's account tree as soon as its markup is parsed, ie
$# right here, inline (hledger.js loads at the end of the body), for the
$# same reason as the scroll restore below: folding at DOMContentLoaded
$# paints the tree in full first and then collapses it, a visible jump.
$# Folding first also gives the scroll restore the folded height.
$# The rows, which carry their indent and account name, get fold carets.
$# The tree is folded to a depth of its own, independent of the page's:
$# 1 at first, stepped by the - and + buttons above it, which open the
$# accounts above that depth (counting account name levels) and fold
$# the rest. The groups opened or closed by hand are remembered over
$# that ({folded, opened} account names), until a step resets them. The
$# depth and the choices are remembered in this browser, so the sidebar
$# stays as you left it from page to page. A caret clicked back to the
$# depth's fold is forgotten. At the shallowest or deepest depth, - or +
$# still folds or opens to that depth any groups opened or closed by hand.
<script nonce=#{nonce}>
(function () {
var menu = document.getElementById('sidebar-menu');
var rows = [];
menu.querySelectorAll('tr[data-indent]').forEach(function (tr) {
rows.push({tr: tr, indent: +tr.getAttribute('data-indent'),
acct: tr.getAttribute('data-acct'), expanded: true, parent: false});
});
if (!rows.length) { return; }
function level(r) { return r.acct.split(':').length; }
var deepest = Math.max.apply(null, rows.map(level));
var depth = 1, choice = {};
try {
depth = parseInt(localStorage.getItem('sidebarDepth'), 10) || 1;
var saved = JSON.parse(localStorage.getItem('sidebarFolds') || '{}');
(saved.folded || []).forEach(function (a) { choice[a] = false; });
(saved.opened || []).forEach(function (a) { choice[a] = true; });
} catch (e) {}
depth = Math.max(1, Math.min(depth, deepest));
function baseline(r) { return level(r) < depth; }
function apply() {
var stack = [];
rows.forEach(function (r) {
while (stack.length > r.indent) { stack.pop(); }
r.tr.classList.toggle('tree-fold-hide', !stack.every(function (open) { return open; }));
r.caret.textContent = r.parent ? (r.expanded ? '▾' : '▸') : '';
stack.push(r.expanded);
});
}
function saveChoices() {
try {
var folded = [], opened = [];
Object.keys(choice).forEach(function (a) { (choice[a] ? opened : folded).push(a); });
localStorage.setItem('sidebarFolds', JSON.stringify({folded: folded, opened: opened}));
} catch (e) {}
}
function save(r) {
if (r.expanded === baseline(r)) { delete choice[r.acct]; }
else { choice[r.acct] = r.expanded; }
saveChoices();
}
rows.forEach(function (r, i) {
r.parent = i + 1 < rows.length && rows[i + 1].indent > r.indent;
r.expanded = (r.parent && choice[r.acct] !== undefined) ? choice[r.acct] : baseline(r);
r.caret = document.createElement('span');
r.caret.className = 'tree-caret';
var name = r.tr.querySelector('.ff-wrapper a.acct-name');
if (name) { name.parentNode.insertBefore(r.caret, name); }
if (r.parent) {
r.caret.addEventListener('click', function () { r.expanded = !r.expanded; apply(); save(r); stepsUpdate(); });
}
});
// A step folds or opens the whole tree to the new depth, forgetting
// the carets' choices. At either end, it applies the depth it is at,
// while some group here was opened or closed by hand; otherwise there
// it does nothing. With only one level here, there is nothing to step.
var steps = menu.querySelectorAll('.depth-step');
function stepTo(b) {
return Math.max(1, Math.min(deepest, depth + parseInt(b.getAttribute('data-step'), 10)));
}
function changedByHand() {
return rows.some(function (r) { return r.parent && r.expanded !== baseline(r); });
}
function stepsUpdate() {
var changed = changedByHand();
steps.forEach(function (b) { b.disabled = stepTo(b) === depth && !changed; });
}
// Set the tree to a depth (within 1 and the deepest), as - and + do;
// also the shift-digit keys' action (hledger.js), so kept on the sidebar.
function depthTo(n) {
n = Math.max(1, Math.min(deepest, n));
if (n === depth && !changedByHand()) { return; }
depth = n;
choice = {};
rows.forEach(function (r) { r.expanded = baseline(r); });
apply();
saveChoices();
try { localStorage.setItem('sidebarDepth', depth); } catch (e) {}
stepsUpdate();
}
menu.hledgerDepthTo = depthTo;
steps.forEach(function (b) {
b.addEventListener('click', function () { depthTo(stepTo(b)); });
});
var stepper = menu.querySelector('.depth-stepper');
if (stepper && deepest < 2) { stepper.hidden = true; }
stepsUpdate();
apply();
})();
$# Restore the sidebar's scroll position (saved per-tab in sessionStorage)
$# as soon as its markup is parsed, ie right here, inline. Waiting for eg
$# DOMContentLoaded would be too late: on pages with a long journal/register
$# the browser paints the sidebar (at scroll position 0) well before the
$# rest of the document is parsed, and restoring then makes the sidebar
$# visibly jump. sessionStorage can throw (not just be absent) when storage
$# is blocked, eg in a sandboxed iframe, with cookies disabled, or in some
$# private-browsing modes; the try makes this convenience a no-op there.
<script nonce=#{nonce}>
(function () {
var sidebar = document.getElementById('sidebar-menu');
var key = 'hledgerSidebarScrollTop';
var ignoreNextScrollSave = false;
try {
var saved = parseInt(sessionStorage.getItem(key), 10);
if (!isNaN(saved)) {
sidebar.scrollTop = saved;
// Restoring fires a scroll event, but only if the position actually
// changed; on a page whose account list is shorter the value clamps,
// so skip saving that one event to avoid shrinking the remembered
// offset for later pages.
ignoreNextScrollSave = sidebar.scrollTop !== 0;
}
} catch (e) {}
sidebar.addEventListener('scroll', function () {
if (ignoreNextScrollSave) { ignoreNextScrollSave = false; return; }
try { sessionStorage.setItem(key, sidebar.scrollTop); } catch (e) {}
});
})();
$# Focusable (but not by tab), so that hledger.js can focus it and the
$# keyboard scrolls it (see focusPage). The c and d keys hide a report's
$# chart and its table, remembered in the showchart and showtable cookies
$# (hledger.js), so each page is born the way the last one was left;
$# likewise the N key shows the charts' total or net lines (shownet).
<div#main-content .col-xs-12.#{mainShowmd}.#{mainShowsm} :chartHidden:.chart-hidden :tableHidden:.table-hidden :netShown:.net-shown tabindex=-1>
$# Shown by hledger.js while the page can't reach the server.
$if browsemode
<div #server-stopped .alert.alert-warning role=alert hidden>
_{HMsg "hledger-web is no longer running. It exits after fifteen minutes with no browser window showing it, or when stopped. To continue, start it again and reload this page."}
$maybe m <- msg
<div #message .alert.alert-info>#{m}
$# Shown only in full window mode (the f key), for leaving it without the keyboard.
<button #fullwindow-exit .btn.btn-default.btn-sm.hidden-print type=button title=_{HMsg "Leave full window"}>
<span .glyphicon .glyphicon-resize-small>
$if elem ViewPermission perms
^{reportsRow}
<form#searchform.input-group method=GET>
<input .form-control name=q value=#{qparam} placeholder=_{HMsgc "search box" "Search"}
title=_{HMsg "Enter hledger search patterns to filter the data below"}>
$forall (name, value) <- keptParams
<input type=hidden name=#{name} value=#{value}>
<div .input-group-btn>
$if not (T.null qparam)
<a #search-clear href=@?{(here, keptParams)} .btn .btn-default title=_{HMsg "Clear search terms"}>
<span .glyphicon .glyphicon-remove-circle>
<button .btn .btn-default type=submit title=_{HMsg "Apply search terms"}>
<span .glyphicon .glyphicon-search>
$if elem EditPermission perms
<a href="@{ManageR}" .btn.btn-default title=_{HMsg "Manage journal files"}>
<span .glyphicon .glyphicon-wrench>
<button .btn .btn-default type=button data-toggle="modal" data-target="#helpmodal"
title=_{HMsg "Show search and general help"}>
<span .glyphicon .glyphicon-question-sign>
^{widget}
$# Reshaping a report keeps the reader's place: clicking a control link
$# saves the page's scroll position (hledger.js, controlsInit), restored
$# here, inline right after the page content's markup, so it lands
$# before paint. The controls and commodity disclosures need no script:
$# their state travels in cookies the server reads, so they are born
$# already open.
<script nonce=#{nonce}>
(function () {
try {
var st = sessionStorage.getItem('pageScrollTop');
if (st !== null) {
sessionStorage.removeItem('pageScrollTop');
document.documentElement.scrollTop = parseInt(st, 10) || 0;
}
} catch (e) {}
})();
$# The g key's menu of pages, each with the key that goes to it (hledger.js),
$# then the next and previous pages.
$# The keys are not translated, like the other keys.
$if elem ViewPermission perms
<div #gomenu hidden aria-labelledby="gomenuLabel">
<p #gomenuLabel>_{HMsg "Go to"}
<ul>
$forall (key, link, label, title) <- goItems
<li>
<a href=@?{link} data-gokey=#{key} title=#{title}><code>#{key}</code> #{label}
$# The next and previous pages, for the n and p keys.
<div #pagesteps hidden>
$forall (key, link) <- pageSteps
<a href=@?{link} data-stepkey=#{key}>
<dialog #helpmodal tabindex=-1 aria-labelledby="helpLabel">
<div .modal-header>
<button type="button" .close data-dismiss="modal" aria-label=_{HMsg "Close"}>×
<span .version>#{progname} #{packageversion}
<h3 .modal-title #helpLabel>_{HMsg "Help"}
$# The general keys, then the options' keys, which follow the options
$# panel row by row, under its own labels, so that a key can be found by
$# the control it acts on. Beside them the search syntax, then the
$# manual. The keys and query syntax stay outside the translatable text.
<div .modal-body>
<div .row>
<div .col-sm-6>
<h4>_{HMsg "Keyboard shortcuts"}
<table .help-keys>
<tr>
<th><kbd>h</kbd> _{HMsg "or"} <kbd>?</kbd>
<td>_{HMsg "view this help"}
<tr>
<th><kbd>g</kbd>
<td>_{HMsg "go to any screen"}
<tr>
<th><kbd>n</kbd> <kbd>p</kbd>
<td>_{HMsg "go to the next or previous screen"}
$if elem AddPermission perms
<tr>
<th><kbd>a</kbd>
<td>_{HMsg "add a transaction"}
<tr>
<th><kbd>s</kbd>
<td>_{HMsg "toggle sidebar"}
<tr>
<th><kbd>Shift</kbd>+<kbd>1</kbd>–<kbd>9</kbd>
$# TRANSLATORS: in the help, what shift with a digit key does: fold or open the sidebar's account tree to that many levels.
<td>_{HMsg "set the sidebar's account depth"}
<tr>
<th><kbd>b</kbd>
<td>_{HMsg "show or hide the sidebar's balances"}
<tr>
<th><kbd>o</kbd>
<td>_{HMsg "toggle report options"}
<tr>
<th><kbd>c</kbd>
<td>_{HMsg "toggle the report's chart"}
<tr>
<th><kbd>[</kbd> <kbd>]</kbd>
<td>_{HMsg "select the chart's commodity"}
<tr>
<th><kbd>N</kbd>
$# TRANSLATORS: in the help, what the N key does: show or hide the chart's net total line, the total of its bars; N is for net.
<td>_{HMsg "toggle the chart's net total line"}
<tr>
<th><kbd>d</kbd>
<td>_{HMsg "toggle the report's data"}
<tr>
<th><kbd>f</kbd>
<td>_{HMsg "toggle full window"}
<tr>
<th><kbd>/</kbd>
<td>_{HMsg "focus search form"}
<tr>
$# TRANSLATORS: in the help, what the Del key does: clear the search box, showing everything again.
<th><kbd>Del</kbd>
<td>_{HMsg "clear the search"}
<tr>
<th><kbd>Esc</kbd>
<td>_{HMsg "cancel"}
$# TRANSLATORS: in the help, the heading of the options' keys, listed under the options panel's own labels.
<h5>_{HMsg "Report options"}
<table .help-keys .help-options>
<tr>
<th>_{HMsg "Show:"}
<td>
<span><kbd>H</kbd> _{HMsg "historical end balances / balance changes"}
<tr>
<th>_{HMsg "Interval:"}
<td>
<span><kbd>Y</kbd> _{HMsg "yearly"}
<span><kbd>Q</kbd> _{HMsg "quarterly"}
<span><kbd>M</kbd> _{HMsg "monthly"}
<span><kbd>W</kbd> _{HMsg "weekly"}
<span><kbd>D</kbd> _{HMsg "daily"}
<tr>
<th>_{HMsg "Status:"}
<td>
<span><kbd>U</kbd> _{HMsg "unmarked"}
<span><kbd>P</kbd> _{HMsg "pending"}
<span><kbd>C</kbd> _{HMsg "cleared"}
<tr>
<th>_{HMsg "Postings:"}
<td>
<span><kbd>R</kbd> _{HMsg "real only / all"}
<tr>
<th>_{HMsg "Depth limit:"}
<td>
$# TRANSLATORS: in the help's Depth row: what the digit keys, and the - and + keys, do to the depth limit.
<span><kbd>0</kbd>–<kbd>9</kbd> _{HMsg "set it"}
<span><kbd>-</kbd> <kbd>+</kbd> _{HMsg "decrease or increase it"}
<tr>
<th>_{HMsg "Accounts:"}
<td>
<span><kbd>t</kbd> _{HMsgc "accounts" "tree / list"}
<tr>
<th>_{HMsg "Amounts:"}
<td>
<span><kbd>B</kbd> _{HMsg "at cost"}
<span><kbd>V</kbd> _{HMsg "at market value"}
<tr>
<th>_{HMsg "Zero balances:"}
<td>
<span><kbd>z</kbd> _{HMsg "show / hide zero balances"}
<tr>
<th>_{HMsg "Lots:"}
<td>
<span><kbd>L</kbd> _{HMsg "show / hide lot details"}
<tr>
<th>_{HMsg "Extra columns:"}
<td>
<span><kbd>T</kbd> _{HMsgc "column" "total"}
<span><kbd>A</kbd> _{HMsgc "column" "average"}
<tr>
<th>_{HMsg "Sort:"}
<td>
<span><kbd>S</kbd> _{HMsg "by amount / by account display order"}
$# TRANSLATORS: in the help, below the options' keys.
<p .help-note>_{HMsg "Pressed again, an option's key turns it back off."}
<div .col-sm-6>
<h4>_{HMsgc "help heading" "Search queries"}
<ul .help-list>
<li> _{HMsg "Search patterns with spaces should be enclosed in quotes."}
<li> <code>REGEX</code> - _{HMsg "match account names"}
<li> <code>type:TYPE</code> - _{HMsg "match account types (A, L, E, R, X, ...)"}
<li> <code>date:PERIODEXP</code> - _{HMsg "match dates"}
<li> <code>status:*</code>, <code>status:!</code>, <code>status:</code> - _{HMsg "match status"}
<li> <code>code:REGEX</code> - _{HMsg "match transaction codes"}
<li> <code>desc:REGEX</code> - _{HMsg "match transaction descriptions"}
<li> <code>payee:REGEX</code> - _{HMsg "match payee part of descriptions"}
<li> <code>note:REGEX</code> - _{HMsg "match note part of descriptions"}
<li> <code>amt:N</code>, <code>amt:<N</code>, <code>amt:>N</code> - _{HMsg "match unsigned magnitudes, or with signed N, signed amounts. N may have a commodity symbol."}
<li> <code>change:N</code>, <code>change:<N</code>, <code>balance:N</code>, <code>balance:>N</code> - _{HMsg "match report rows (accounts, periods, transactions) by their change or balance, like amt:. N may have a commodity symbol."}
<li> <code>cur:REGEX</code> - _{HMsg "match currencies/commodities. Must match the whole symbol/name. To match dollar sign, write"} <code>\$</code>
<li> <code>tag:NAME</code>, <code>tag:NAME=REGEX</code> - _{HMsg "match tags, or tag and value"}
<li> <code>real:BOOL</code> - _{HMsg "match postings' realness/virtualness"}
<li> <code>find:REGEX</code> _{HMsg "or"} <code>::REGEX</code> - _{HMsg "match any field (account, amount, comment, tag, description, code), or a date if REGEX is also a period expression"}
<li> <code>not:QTERM</code> - _{HMsg "prepend not: to negate a search term"}
<li> <code>expr:'QEXPR'</code> - _{HMsg "match with a boolean query (and, or, not, ())"}
<li> <code>any:'QEXPR'</code> - _{HMsg "match transactions where any posting matches"}
<li> <code>all:'QEXPR'</code> - _{HMsg "match transactions where all postings match"}
<li .gap-above> <code>depth:N</code> - _{HMsg "another way to set depth limit (can be per account)"}
$# <li> Description, account, status query terms are OR'ed, others are AND'ed.
<h4>_{HMsg "More help:"}
<ul .help-list>
<li>
<a href=#{webmanualurl} target=hledgerhelp>_{HMsg "hledger-web user manual"}