diff --git a/ledger_pyreport/__init__.py b/ledger_pyreport/__init__.py index 9dd5f61..212b7a7 100644 --- a/ledger_pyreport/__init__.py +++ b/ledger_pyreport/__init__.py @@ -286,20 +286,20 @@ def filter_amount(amt, link=None): return flask.Markup('({})'.format(link, amt.tostr(False), amt_str)) else: if is_pos: - return flask.Markup('{} '.format(amt.tostr(False), amt_str)) + return flask.Markup('{} '.format(amt.tostr(False), amt_str)) else: - return flask.Markup('({})'.format(amt.tostr(False), amt_str)) + return flask.Markup('({})'.format(amt.tostr(False), amt_str)) @app.template_filter('b') def filter_amount_positive(amt): - return flask.Markup('{:,.2f}'.format(amt.tostr(False), amt.amount).replace(',', ' ')) + return flask.Markup('{:,.2f}'.format(amt.tostr(False), amt.amount).replace(',', ' ')) @app.template_filter('bc') def filter_commodity_positive(amt): if amt.commodity.is_prefix: - return flask.Markup('{}{:,.2f}'.format(amt.tostr(False), amt.commodity.name, amt.amount).replace(',', ' ')) + return flask.Markup('{}{:,.2f}'.format(amt.tostr(False), amt.commodity.name, amt.amount).replace(',', ' ')) else: - return flask.Markup('{:,.2f} {}'.format(amt.tostr(False), amt.amount, amt.commodity.name).replace(',', ' ')) + return flask.Markup('{:,.2f} {}'.format(amt.tostr(False), amt.amount, amt.commodity.name).replace(',', ' ')) @app.template_filter('bt') def filter_commodity_table_positive(amt, show_price, link=None): @@ -313,12 +313,12 @@ def filter_commodity_table_positive(amt, show_price, link=None): amt_full = amt.tostr(False) - result.append('{}'.format(link, amt_full, amt_str) if link else '{}'.format(amt_full, amt_str)) - result.append('{}'.format(amt_full, cur_str)) + result.append('{}'.format(link, amt_full, amt_str) if link else '{}'.format(amt_full, amt_str)) + result.append('{}'.format(amt_full, cur_str)) if show_price: if amt.commodity.price: - result.append('{{{}}}'.format(amt_full, filter_commodity_positive(amt.commodity.price))) + result.append('{{{}}}'.format(filter_commodity_positive(amt.commodity.price))) else: result.append('') diff --git a/ledger_pyreport/jinja2/base.html b/ledger_pyreport/jinja2/base.html index 6f66a01..69c273f 100644 --- a/ledger_pyreport/jinja2/base.html +++ b/ledger_pyreport/jinja2/base.html @@ -26,5 +26,9 @@ {% block body %}{% endblock %} + + + +
diff --git a/ledger_pyreport/static/copyAmounts.js b/ledger_pyreport/static/copyAmounts.js new file mode 100644 index 0000000..a3e6bb2 --- /dev/null +++ b/ledger_pyreport/static/copyAmounts.js @@ -0,0 +1,35 @@ +/* + ledger-pyreport + Copyright © 2020 Lee Yingtong Li (RunasSudo) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + +// Consider replacing this when the Clipboard API has better availability +function copyText(text) { + var ta = document.createElement('textarea'); + ta.value = text; + ta.style = 'position: fixed; top: 0; left: 0;'; // Avoid scrolling + document.body.appendChild(ta); + ta.select(); + document.execCommand('copy'); + document.body.removeChild(ta); +} + +document.querySelectorAll('.copyable-amount').forEach(function(el) { + el.addEventListener('click', function() { + copyText(el.getAttribute('title')); + showToast('Amount was copied to the clipboard'); + }); +}); diff --git a/ledger_pyreport/static/main.css b/ledger_pyreport/static/main.css index c4092dc..867ff0f 100644 --- a/ledger_pyreport/static/main.css +++ b/ledger_pyreport/static/main.css @@ -20,6 +20,8 @@ body { font-family: 'TeX Gyre Termes', 'Nimbus Roman', 'Times New Roman', 'Liberation Serif', Times, serif; } +/* Tables */ + h1 { text-align: center; font-size: x-large; @@ -73,6 +75,8 @@ table.ledger a:hover { text-decoration: underline; } +/* Navigation bar */ + .nav-header { color: #888; position: absolute; @@ -86,6 +90,8 @@ table.ledger a:hover { color: #666; } +/* Home page */ + .index-group { margin-bottom: 1em; line-height: 2; @@ -95,6 +101,26 @@ label { white-space: nowrap; } +/* Toasts */ + +.toast { + opacity: 0%; + transition: opacity 0.2s; + + position: fixed; + bottom: 2em; + left: 50%; + transform: translateX(-50%); + + background-color: #eee; + padding: 0.5em 1.5em; + border: 1px solid #666; +} +.toast.visible { + opacity: 100%; + transition: opacity 0s; +} + @media screen { body { padding: 2em; diff --git a/ledger_pyreport/static/toasts.js b/ledger_pyreport/static/toasts.js new file mode 100644 index 0000000..4bc1035 --- /dev/null +++ b/ledger_pyreport/static/toasts.js @@ -0,0 +1,29 @@ +/* + ledger-pyreport + Copyright © 2020 Lee Yingtong Li (RunasSudo) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + +var toastInterval; + +function showToast(toastText) { + document.querySelector('.toast').innerText = toastText; + document.querySelector('.toast').classList.add('visible'); + + clearInterval(toastInterval); + toastInterval = setInterval(function() { + document.querySelector('.toast').classList.remove('visible'); + }, 1000); +}