mirror of
https://github.com/simonmichael/hledger.git
synced 2024-11-12 19:08:34 +03:00
0ab008ed5e
- api routes (but not /swagger.json) are now under /api/v1 - the api has changed a bit, more to come - files are served from the current directory by default, simplifying naming - the startup message is more informative - added some startup hints for the angular client
89 lines
1.7 KiB
HTML
89 lines
1.7 KiB
HTML
<html>
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<title>hledger-api example 02</title>
|
|
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
|
|
</head
|
|
|
|
<body>
|
|
<table border=0 width="100%">
|
|
<tr valign="top">
|
|
<td width="50%">
|
|
|
|
<h2>Commodities</h2>
|
|
<pre id="commodities"></pre>
|
|
|
|
<h2>Market Prices</h2>
|
|
<pre id="prices"></pre>
|
|
|
|
<h2>Account names</h2>
|
|
<pre id="accountnames"></pre>
|
|
|
|
</td>
|
|
<td width="50%">
|
|
|
|
<h2>Transactions</h2>
|
|
<pre id="transactions"></pre>
|
|
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
|
|
<script>
|
|
|
|
$(document).ready(function(){
|
|
|
|
get('commodities', id);
|
|
get('prices', showMarketPrice);
|
|
get('accountnames', id);
|
|
get('transactions', showTransaction);
|
|
|
|
});
|
|
|
|
function get(method, showfn) {
|
|
return $.ajax({
|
|
url: "http://localhost:8001/api/v1/"+method,
|
|
context: document.body,
|
|
success: function(data){
|
|
$('#'+method).text(data.map(showfn).join('\n'));
|
|
},
|
|
error: function(jqXHR, textStatus, errorThrown){
|
|
alert('error');
|
|
}
|
|
});
|
|
}
|
|
|
|
function id(x){ return x; }
|
|
|
|
function showAmount(a) {
|
|
return a.acommodity + a.aquantity;
|
|
}
|
|
|
|
function showMixedAmount(ma) {
|
|
return ma.map(showAmount).join(', ');
|
|
}
|
|
|
|
function showMarketPrice(mp) {
|
|
return mp.mpdate + ' ' + mp.mpcommodity + ' ' + showAmount(mp.mpamount);
|
|
}
|
|
|
|
function showPosting(p) {
|
|
return p.paccount + ' ' + showMixedAmount(p.pamount);
|
|
}
|
|
|
|
function showPostingLine(p) {
|
|
return ' ' + showPosting(p) + '\n';
|
|
}
|
|
|
|
function showTransaction(t) {
|
|
return (
|
|
t.tdate + ' ' + t.tdescription + '\n'
|
|
+ t.tpostings.map(showPostingLine).join('')
|
|
);
|
|
}
|
|
|
|
</script>
|
|
|
|
</body>
|
|
</html>
|