bitvend/bitvend/templates/index.html

193 lines
7.6 KiB
HTML

{% extends "base.html" %}
{% from "_helpers.html" import format_currency, render_field, render_submit %}
{% block content %}
{% if not mdb_online or not proc_online %}
<div class="alert alert-warning">
<b>Some of the subsystems are misbehaving.</b> Please avoid making payments, unless in absolute need of Mate.
</div>
{% endif %}
{% if current_user.is_authenticated %}
<div class="row">
<div class="col-sm-4">
<div class="well text-right">
<h3><small class="pull-left">Balance</small> <small>{{ format_currency(current_user.amount_available) }} / </small> {{ format_currency(current_user.balance) }}</h3>
</div>
<div class="well text-right">
<h3><small class="pull-left">Transactions</small> {{ current_user.transactions.count() }}</h3>
</div>
<div class="well">
<p class="text-muted">Use the keypad to select a product.</p>
{% if current_transaction %}
<a href="{{ url_for('.cancel') }}" class="btn btn-danger btn-block btn-lg">Cancel transaction
{% if current_transaction.user != current_user %}
<small>(by {{ current_transaction.user }})</small>
{% endif %}
</a>
{% else %}
<a href="{{ url_for('.begin') }}" class="btn btn-primary btn-block btn-lg">Begin transaction</a>
{% endif %}
</div>
<form action="{{ url_for('.transfer') }}" method="POST" class="well">
{{ transfer_form.hidden_tag() }}
<div class="form-group">
<input type="input" class="form-control" name="target" placeholder="target username" />
</div>
<div class="form-group">
<div class="input-group">
<input type="number" class="form-control" min="0" name="amount" placeholder="0.00" step="any" />
<span class="input-group-btn">
<button class="btn btn-info">Transfer</button>
</span>
</div>
</div>
</form>
<h3 class="page-header">Hall of Shame</h3>
<table class="table table-hover table-striped">
<thead><tr>
<th>Name</th><th class="text-right">Balance</th>
</tr></thead>
{% for user, balance in hallofshame %}
<tr><td>{{ user }}</td><td class="text-right">{{ format_currency(balance) }}</td></tr>
{% else %}
<tr><td colspan=2 class="placeholder">Wow! Nobody's due!</td></tr>
{% endfor %}
</table>
<h3 class="page-header">Hall of Addicts</h3>
<table class="table table-hover table-striped">
<thead><tr>
<th>Name</th><th class="text-right">Amount</th><th>Purchases</th>
</tr></thead>
{% for user, purchase_amount, purchase_count in hallofaddicts %}
<tr><td>{{ user }}</td><td class="text-right">{{ format_currency(purchase_amount) }}</td><td>{{ purchase_count }}</td></tr>
{% else %}
<tr><td colspan=3 class="placeholder">Huh?</td></tr>
{% endfor %}
</table>
</div>
<div class="col-sm-8">
<h3 class="page-header">Latest transactions</h3>
<table class="table table-hover table-striped">
<thead>
<tr>
<th>Type</th>
<th class="text-right">Amount</th>
<th>Date</th>
</tr>
</thead>
{% for tx in transactions %}
<tr{% if not tx.finished %} style="opacity: 0.5"{% endif %}>
<td>
{{ tx.type }} {% if not tx.finished %}<i>(processing)</i>{% endif %}
<small>
{% if tx.type == 'transfer' and tx.amount > 0 %}
from <b>{{ tx.related }}</b>
{% elif tx.type == 'transfer' and tx.amount < 0 %}
to <b>{{ tx.related }}</b>
{% elif tx.type == 'purchase' and tx.product_id %}
of product <b>{{ tx.product_id }}</b>
{% endif %}
</small>
</td>
<td class="text-right">{{ format_currency(tx.amount) }}</td>
<td>{{ tx.created }}</td>
</tr>
{% else %}
<tr><td colspan=3 class="placeholder">Nothing to see here...</td></tr>
{% endfor %}
{% if transactions.count() == 10 %}
<tr><td colspan=3 class="placeholder">
<a href="{{ url_for('.transactions') }}" class="btn btn-block">See more...</a>
</td></tr>
{% endif %}
</table>
</div>
</div>
<hr>
{% endif %}
<h3 class="page-header">
Bitcoin payments
<small>Send suggested transaction and use the keypad to select a product</small>
</h3>
<div class="alert alert-info">
This is just a test deployment of Warsaw Hackerspace Vending Machine Bitcoin Payments System™.
<b>Please report any issues to <a href="mailto:informatic@hackerspace.pl" class="alert-link">informatic@hackerspace.pl</a>.</b>
</div>
<div class="row">
{% for item in items %}
<div class="col-md-6">
<div class="well vend-item">
<div class="row">
<div class="col-md-12">
<div class="pull-right">
<span class="label label-info">{{ format_currency(item.value) }}</span>
<span class="label label-primary">{{ format_btc(from_local_currency(item.value*1.03, True)) }}</span>
</div>
<h3>{{ item.name }}</h3>
</div>
<div class="col-xs-6">
<img src="{{ item.image }}" class="img-responsive center-block" />
</div>
<div class="col-xs-6 text-center">
{% with btc_uri = 'bitcoin:%s?amount=%s' % (config['INPUT_ADDRESS'], sat_to_btc(from_local_currency(item.value*1.03, True))) %}
<a href="{{ btc_uri }}">
<img src="{{ qrcode(btc_uri) }}" class="img-responsive center-block"/>
<code><small>{{ config['INPUT_ADDRESS'] }}</small></code>
</a>
{% endwith %}
</div>
</div>
</div>
</div>
{% endfor %}
</div>
<div class="row">
<div class="col-md-6 col-md-offset-2">
<div id="purchases"></div>
</div>
<div class="col-md-2">
<div class="well text-center">
<h3>{{ bottles_purchased * 105 }}mg</h3>
<small>Caffeine ingested</small>
</div>
<div class="well text-center">
<h3>{{ bottles_purchased }}</h3>
<small>Bottles purchased</small>
</div>
</div>
</div>
<blockquote class="blockquote-reverse">
<p>Kowalski czuje zapach pieniędzy.</p>
<small>Someone famous</small>
</blockquote>
{% endblock %}
{% block tail_js %}
<script>
d3.json('/api/1/history.json', function(data) {
data = MG.convert.date(data, 'date');
MG.data_graphic({
title: "Purchases",
data: data,
height: 200,
full_width: true,
target: document.getElementById('purchases'),
x_accessor: 'date',
y_accessor: 'purchases'
});
});
</script>
{% endblock %}