diff --git a/templates/base.html b/templates/base.html index 2b395c74cbfbf1488c433b281ceadcbcab09dc08..30c3661b8010356774e70b9852ee27d837a6f30c 100644 --- a/templates/base.html +++ b/templates/base.html @@ -50,6 +50,12 @@ }); </script> + <script type="text/javascript"> + $(function() { + $('.tooltip_link').tooltip(); + }); + </script> + {% block foot %}{% endblock %} </body> diff --git a/templates/wallets/base.html b/templates/wallets/base.html index 8c50ba32bd81a23152494cedb64e41ec070f7217..964f888e82e9716e1823d8b335f2aadd333c7ed6 100644 --- a/templates/wallets/base.html +++ b/templates/wallets/base.html @@ -11,12 +11,11 @@ <a id="list" href="{{ url_for('wallets') }}" class="list-group-item"><i class="glyphicon glyphicon-list-alt"></i> Wallet list</a> </div> - {% if key %} - <div class="list-group" style="background-color: #f7f5fa;"> - <a id="new" href="{{ url_for('new_wallet') }}" class="list-group-item"><i class="glyphicon glyphicon-plus-sign"></i> New</a> - <a id="list" href="{{ url_for('wallets') }}" class="list-group-item"><i class="glyphicon glyphicon-list-alt"></i> Wallet list</a> - </div> - {% endif %} + {% if key -%} + <div class="list-group" style="background-color: #f7f5fa;"> + <a id="history" href="{{ url_for('wallet_history', pgp_fingerprint=key.fingerprint) }}" class="list-group-item"><i class="glyphicon glyphicon-calendar"></i> History</a> + </div> + {% endif -%} </div> <div class="col-lg-9"> {% block sub_content %}{% endblock %} @@ -32,6 +31,11 @@ '/': 'list', '{{ url_for('new_wallet') }}': 'new', '{{ url_for('wallets') }}': 'list', + + {% if key -%} + '{{ url_for('wallet_history', pgp_fingerprint=key.fingerprint) }}': 'history', + '{{ url_for('wallet_history', pgp_fingerprint=key.fingerprint, type=type) }}': 'history', + {% endif -%} }; var matches = window.location.pathname.match(/^(\/[^?]*)/g); diff --git a/templates/wallets/history.html b/templates/wallets/history.html new file mode 100644 index 0000000000000000000000000000000000000000..ca4365cc3564b9cb08287db9ab1b001878f689f4 --- /dev/null +++ b/templates/wallets/history.html @@ -0,0 +1,65 @@ +{% extends "wallets/base.html" %} + +{% block sub_content %} +<h1><span class="label label-default">History</span> <span class="label label-primary">{{key.uids.0|truncate(50)}}</span></h1> + +<ul class="nav nav-tabs pull-right"> + {% for name, color in [("all", "default"), ("transfer", "info"), ("issuance", "success"), ("fusion", "warning")] -%} + <li {% if type == name %}class="active"{% endif %}><a href="{{ url_for('wallet_history', pgp_fingerprint=key.fingerprint, type=name) }}"><span class="label label-{{color}}">{{name|title}}</span></a></li> + {% endfor -%} +</ul> + +{% for label,data in [("Received", recipient), ("Sent", sender)] -%} + <h3>{{label}} transactions</h3> + + <table class="table table-bordered table-hover"> + <thead> + <tr> + <th class="col-md-1 text-left">#</th> + <th class="col-md-2 text-center">{{"Sender" if label == "Received" else "Recipient" }}</th> + <th class="col-md-8 text-center">Comment</th> + <th class="col-md-1 text-center">Amount</th> + </tr> + </thead> + <tbody> + {% for r in data -%} + {% with tx=r.value.transaction -%} + {% if type == "all" or tx.type|lower == type|lower -%} + <tr class="row1 {% if tx.type == 'TRANSFER' %}active{% elif tx.type == 'ISSUANCE' %}success{% else %}warning{% endif %}"> + <td>{{tx.number}}</td> + + <td> + {% with reference=tx.sender if label == "Received" else tx.recipient -%} + {% with name=settings.list_keys[reference].uids.0 if settings.list_keys[reference] else "", keyid=reference[-8:] -%} + <a class="tooltip_link" title="{{name}} ({{keyid}})"> + {% if reference == key.fingerprint -%} + <span class="label label-default">me</span> + {% else -%} + <span class="label label-info">{{name|truncate(25) if name else keyid}}</span> + {% endif -%} + </a> + {% endwith -%} + {% endwith -%} + </td> + + <td> + <span class="label label-{% if tx.type == 'TRANSFER' %}info{% elif tx.type == 'ISSUANCE' %}success{% else %}warning{% endif %}">{{tx.type|title}}</span> + <a class="tooltip_link" title="{{tx.comment|trim}}">{{tx.comment|trim|truncate(150)}}</a> + </td> + + <td class="text-right"> + {% with coins=tx.coins|map(attribute="id")|map("compute_coin")|list -%} + <span class="badge alert-{{'success' if label == 'Received' else 'danger'}} tooltip_link" title="{{coins|join(' + ')}}"> + {{coins|sum}} + </span> + {% endwith -%} + </td> + </tr> + {% endif -%} + {% endwith -%} + {% endfor -%} + </tbody> + </table> +{% endfor -%} + +{% endblock %} diff --git a/templates/wallets/index.html b/templates/wallets/index.html index 39c37577e9375c03f473e8e2d5cde59d8bb2c894..21d5d4e251936f010edce7990d7aca6d37ef8bc9 100644 --- a/templates/wallets/index.html +++ b/templates/wallets/index.html @@ -9,7 +9,7 @@ <div class="list-group"> {% for fp,k in settings.list_keys.items() %} - <a href="{{ url_for('wallet_detail', pgp_fingerprint=fp) }}" class="list-group-item {% if k.keyid == settings.keyid %}active{% endif %}"> + <a href="{{ url_for('wallet_history', pgp_fingerprint=fp) }}" class="list-group-item {% if k.keyid == settings.keyid %}active{% endif %}"> <h4 class="list-group-item-heading">{{k.uids.0}}</h4> <p class="list-group-item-text">{{fp}}</p> </a> diff --git a/templates/wallets/new.html b/templates/wallets/new.html index d59a7e9a1d72fb43f9e7995a5e5b5a1a56e85d4c..e1c1845185ddd3f7c8273b652a459836989edf5c 100644 --- a/templates/wallets/new.html +++ b/templates/wallets/new.html @@ -76,12 +76,14 @@ if (!(email.val())) { email.parent().addClass('has-error'); create.button('error'); + email.focus().select(); return false; } if (!(realm.val())) { realm.parent().addClass('has-error'); create.button('error'); + realm.focus().select(); return false; } diff --git a/webclient.py b/webclient.py index 6c2568e7164878274db66870c923f5c8b3e8a4b4..8b99b8a2324b1f05a9c90b278cf7dbaa62761c77 100755 --- a/webclient.py +++ b/webclient.py @@ -28,6 +28,15 @@ logger = logging.getLogger("cli") app = Flask(__name__) +@app.template_filter('split') +def split_filter(s, sep=' '): + return s.split(sep) + +@app.template_filter('compute_coin') +def compute_coin_filter(coin): + fpr, number, base, power, origin, origin_number = coin.split('-') + return int(base)*10**int(power) + def render_prettyprint(template_name, result): s = StringIO() pprint(result, s) @@ -67,9 +76,18 @@ VotersCount\t\t%(votersCount)s def wallets(): return render_template('wallets/index.html', settings=ucoin.settings) -@app.route('/wallets/<pgp_fingerprint>') -def wallet_detail(pgp_fingerprint): - return render_template('wallets/detail.html', settings=ucoin.settings, key=ucoin.settings['list_keys'].get(pgp_fingerprint)) +@app.route('/wallets/<pgp_fingerprint>/history') +@app.route('/wallets/<pgp_fingerprint>/history/<type>') +def wallet_history(pgp_fingerprint, type='all'): + sender = ucoin.hdc.transactions.Sender(pgp_fingerprint).get() + recipient = ucoin.hdc.transactions.Recipient(pgp_fingerprint).get() + + return render_template('wallets/history.html', + settings=ucoin.settings, + key=ucoin.settings['list_keys'].get(pgp_fingerprint), + sender=sender, + recipient=recipient, + type=type) @app.route('/wallets/new') def new_wallet():